[Libreoffice-commits] core.git: basic/source

Arnaud Versini arnaud.versini at gmail.com
Wed Feb 17 07:09:26 UTC 2016


 basic/source/comp/dim.cxx      |   27 ++++++++++-----------------
 basic/source/comp/exprnode.cxx |   12 +++---------
 basic/source/comp/exprtree.cxx |   34 +++++++++++++++++-----------------
 basic/source/inc/expr.hxx      |   11 ++++++-----
 basic/source/inc/parser.hxx    |    2 +-
 5 files changed, 37 insertions(+), 49 deletions(-)

New commits:
commit f17a4694b07856292804c23b80ce92967d401bb8
Author: Arnaud Versini <arnaud.versini at gmail.com>
Date:   Sat Feb 13 20:17:41 2016 +0100

    BASIC : use std::unique_ptr for storing SbiExprList
    
    Change-Id: I37f2a1c837c6742cf6d403962d2730b5e80004ec
    Reviewed-on: https://gerrit.libreoffice.org/22345
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
    Tested-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index 2f9fefa..ffd7174f 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -39,7 +39,7 @@ using namespace ::com::sun::star::uno;
 // Return-value: a new instance, which were inserted and then deleted.
 // Array-Index were returned as SbiExprList
 
-SbiSymDef* SbiParser::VarDecl( SbiExprList** ppDim, bool bStatic, bool bConst )
+SbiSymDef* SbiParser::VarDecl( SbiExprListPtr* ppDim, bool bStatic, bool bConst )
 {
     bool bWithEvents = false;
     if( Peek() == WITHEVENTS )
@@ -50,7 +50,7 @@ SbiSymDef* SbiParser::VarDecl( SbiExprList** ppDim, bool bStatic, bool bConst )
     if( !TestSymbol() ) return nullptr;
     SbxDataType t = eScanType;
     SbiSymDef* pDef = bConst ? new SbiConstDef( aSym ) : new SbiSymDef( aSym );
-    SbiExprList* pDim = nullptr;
+    SbiExprListPtr pDim;
     // Brackets?
     if( Peek() == LPAREN )
     {
@@ -68,10 +68,9 @@ SbiSymDef* SbiParser::VarDecl( SbiExprList** ppDim, bool bStatic, bool bConst )
     {
         if(pDim->GetDims() )
             Error( ERRCODE_BASIC_EXPECTED, "()" );
-        delete pDim;
     }
     else if( ppDim )
-        *ppDim = pDim;
+        *ppDim = std::move(pDim);
     return pDef;
 }
 
@@ -294,7 +293,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
             Error( ERRCODE_BASIC_UNEXPECTED, eCurTok );
     }
     SbiSymDef* pDef;
-    SbiExprList* pDim;
+    SbiExprListPtr pDim;
 
     // #40689, Statics -> Modul-Initialising, skip in Sub
     sal_uInt32 nEndOfStaticLbl = 0;
@@ -430,14 +429,14 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
                     aGen.Gen( _REDIMP_ERASE );
 
                     pDef->SetDims( pDim->GetDims() );
-                    SbiExpression aExpr2( this, *pDef, pDim );
+                    SbiExpression aExpr2( this, *pDef, std::move(pDim) );
                     aExpr2.Gen();
                     aGen.Gen( _DCREATE_REDIMP, pDef->GetId(), pDef->GetTypeId() );
                 }
                 else
                 {
                     pDef->SetDims( pDim->GetDims() );
-                    SbiExpression aExpr( this, *pDef, pDim );
+                    SbiExpression aExpr( this, *pDef, std::move(pDim) );
                     aExpr.Gen();
                     aGen.Gen( _DCREATE, pDef->GetId(), pDef->GetTypeId() );
                 }
@@ -462,7 +461,6 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
                 if( pDim )
                 {
                     Error( ERRCODE_BASIC_SYNTAX );
-                    delete pDim;
                 }
                 SbiExpression aVar( this, *pDef );
                 if( !TestToken( EQ ) )
@@ -510,7 +508,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
                 pDef->SetDims( pDim->GetDims() );
                 if( bPersistantGlobal )
                     pDef->SetGlobal( true );
-                SbiExpression aExpr( this, *pDef, pDim );
+                SbiExpression aExpr( this, *pDef, std::move(pDim) );
                 aExpr.Gen();
                 pDef->SetGlobal( false );
                 aGen.Gen( (eOp == _STATIC) ? _DIM : eOp );
@@ -588,12 +586,12 @@ void SbiParser::DefType( bool bPrivate )
 
     SbxObject *pType = new SbxObject(aSym);
 
-    std::unique_ptr<SbiSymDef> pElem;
-    SbiExprList* pDim = nullptr;
     bool bDone = false;
 
     while( !bDone && !IsEof() )
     {
+        std::unique_ptr<SbiSymDef> pElem;
+        SbiExprListPtr pDim;
         switch( Peek() )
         {
             case ENDTYPE :
@@ -675,8 +673,6 @@ void SbiParser::DefType( bool bPrivate )
                 }
                 pTypeMembers->Insert( pTypeElem, pTypeMembers->Count() );
             }
-            delete pDim, pDim = nullptr;
-            pElem.reset();
         }
     }
 
@@ -713,7 +709,6 @@ void SbiParser::DefEnum( bool bPrivate )
         pEnum->SetFlag( SbxFlagBits::Private );
     }
     SbiSymDef* pElem;
-    SbiExprList* pDim;
     bool bDone = false;
 
     // Starting with -1 to make first default value 0 after ++
@@ -736,8 +731,7 @@ void SbiParser::DefEnum( bool bPrivate )
 
             default:
             {
-                // TODO: Check existing!
-                pDim = nullptr;
+                SbiExprListPtr pDim;
                 pElem = VarDecl( &pDim, false, true );
                 if( !pElem )
                 {
@@ -746,7 +740,6 @@ void SbiParser::DefEnum( bool bPrivate )
                 }
                 else if( pDim )
                 {
-                    delete pDim;
                     Error( ERRCODE_BASIC_SYNTAX );
                     bDone = true;   // Error occurred
                     break;
diff --git a/basic/source/comp/exprnode.cxx b/basic/source/comp/exprnode.cxx
index 77c1aa5..d5d9cb6 100644
--- a/basic/source/comp/exprnode.cxx
+++ b/basic/source/comp/exprnode.cxx
@@ -58,7 +58,7 @@ SbiExprNode::SbiExprNode( const OUString& rVal ):
 {
 }
 
-SbiExprNode::SbiExprNode( const SbiSymDef& r, SbxDataType t, SbiExprList* l ) :
+SbiExprNode::SbiExprNode( const SbiSymDef& r, SbxDataType t, SbiExprListPtr l ) :
     pWithParent(nullptr),
     eNodeType(SbxVARVAL),
     eTok(NIL),
@@ -66,7 +66,7 @@ SbiExprNode::SbiExprNode( const SbiSymDef& r, SbxDataType t, SbiExprList* l ) :
 {
     eType     = ( t == SbxVARIANT ) ? r.GetType() : t;
     aVar.pDef = const_cast<SbiSymDef*>(&r);
-    aVar.pPar = l;
+    aVar.pPar = l.release();
     aVar.pvMorePar = nullptr;
     aVar.pNext= nullptr;
 }
@@ -109,13 +109,7 @@ SbiExprNode::~SbiExprNode()
     {
         delete aVar.pPar;
         delete aVar.pNext;
-        SbiExprListVector* pvMorePar = aVar.pvMorePar;
-        if( pvMorePar )
-        {
-            for( const auto& pParam : *pvMorePar )
-                delete pParam;
-            delete pvMorePar;
-        }
+        delete aVar.pvMorePar;
     }
 }
 
diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx
index d0cb9db..99f1f57 100644
--- a/basic/source/comp/exprtree.cxx
+++ b/basic/source/comp/exprtree.cxx
@@ -63,14 +63,14 @@ SbiExpression::SbiExpression( SbiParser* p, double n, SbxDataType t )
     pExpr->Optimize(pParser);
 }
 
-SbiExpression::SbiExpression( SbiParser* p, const SbiSymDef& r, SbiExprList* pPar )
+SbiExpression::SbiExpression( SbiParser* p, const SbiSymDef& r, SbiExprListPtr pPar )
 {
     pParser = p;
     bBased = bError = bByVal = bBracket = false;
     nParenLevel = 0;
     eCurExpr = SbOPERAND;
     m_eMode = EXPRMODE_STANDARD;
-    pExpr = o3tl::make_unique<SbiExprNode>( r, SbxVARIANT, pPar );
+    pExpr = o3tl::make_unique<SbiExprNode>( r, SbxVARIANT, std::move(pPar) );
 }
 
 SbiExpression::~SbiExpression() { }
@@ -197,7 +197,7 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo )
     pParser->LockColumn();
     OUString aSym( (pKeywordSymbolInfo == nullptr) ? pParser->GetSym() : pKeywordSymbolInfo->m_aKeywordSymbol );
     SbxDataType eType = (pKeywordSymbolInfo == nullptr) ? pParser->GetType() : pKeywordSymbolInfo->m_eSbxDataType;
-    SbiExprList* pPar = nullptr;
+    SbiExprListPtr pPar;
     SbiExprListVector* pvMoreParLcl = nullptr;
     // are there parameters following?
     SbiToken eNextTok = pParser->Peek();
@@ -233,8 +233,8 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo )
             {
                 pvMoreParLcl = new SbiExprListVector();
             }
-            SbiExprList* pAddPar = SbiExprList::ParseParameters( pParser );
-            pvMoreParLcl->push_back( pAddPar );
+            SbiExprListPtr pAddPar = SbiExprList::ParseParameters( pParser );
+            pvMoreParLcl->push_back( std::move(pAddPar) );
             bError = bError || !pAddPar->IsValid();
             eTok = pParser->Peek();
         }
@@ -281,7 +281,7 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo )
         {
             eType = SbxOBJECT;
         }
-        pDef = AddSym( eTok, *pParser->pPool, eCurExpr, aSym, eType, pPar );
+        pDef = AddSym( eTok, *pParser->pPool, eCurExpr, aSym, eType, pPar.get() );
         // Looks like this is a local ( but undefined variable )
         // if it is in a static procedure then make this Symbol
         // static
@@ -296,7 +296,7 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo )
         SbiConstDef* pConst = pDef->GetConstDef();
         if( pConst )
         {
-            delete pPar;
+            pPar = nullptr;
             delete pvMoreParLcl;
             if( pConst->GetType() == SbxSTRING )
             {
@@ -360,7 +360,7 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo )
     {
         pPar = SbiExprList::ParseParameters( pParser,false,false );
     }
-    pNd->aVar.pPar = pPar;
+    pNd->aVar.pPar = pPar.release();
     pNd->aVar.pvMorePar = pvMoreParLcl;
     if( bObj )
     {
@@ -413,7 +413,7 @@ SbiExprNode* SbiExpression::ObjTerm( SbiSymDef& rObj )
     }
     OUString aSym( pParser->GetSym() );
     SbxDataType eType = pParser->GetType();
-    SbiExprList* pPar = nullptr;
+    SbiExprListPtr pPar;
     SbiExprListVector* pvMoreParLcl = nullptr;
     eTok = pParser->Peek();
 
@@ -431,8 +431,8 @@ SbiExprNode* SbiExpression::ObjTerm( SbiSymDef& rObj )
             {
                 pvMoreParLcl = new SbiExprListVector();
             }
-            SbiExprList* pAddPar = SbiExprList::ParseParameters( pParser );
-            pvMoreParLcl->push_back( pAddPar );
+            SbiExprListPtr pAddPar = SbiExprList::ParseParameters( pParser );
+            pvMoreParLcl->push_back( std::move(pAddPar) );
             bError = bError || !pPar->IsValid();
             eTok = pParser->Peek();
         }
@@ -458,12 +458,12 @@ SbiExprNode* SbiExpression::ObjTerm( SbiSymDef& rObj )
     SbiSymDef* pDef = rPool.Find( aSym );
     if( !pDef )
     {
-        pDef = AddSym( eTok, rPool, eCurExpr, aSym, eType, pPar );
+        pDef = AddSym( eTok, rPool, eCurExpr, aSym, eType, pPar.get() );
         pDef->SetType( eType );
     }
 
     SbiExprNode* pNd = new SbiExprNode( *pDef, eType );
-    pNd->aVar.pPar = pPar;
+    pNd->aVar.pPar = pPar.release();
     pNd->aVar.pvMorePar = pvMoreParLcl;
     if( bObj )
     {
@@ -941,9 +941,9 @@ void SbiExprList::addExpression( std::unique_ptr<SbiExpression>&& pExpr )
 // #i79918/#i80532: bConst has never been set to true
 // -> reused as bStandaloneExpression
 //SbiParameters::SbiParameters( SbiParser* p, sal_Bool bConst, sal_Bool bPar) :
-SbiExprList* SbiExprList::ParseParameters( SbiParser* pParser, bool bStandaloneExpression, bool bPar)
+SbiExprListPtr SbiExprList::ParseParameters( SbiParser* pParser, bool bStandaloneExpression, bool bPar)
 {
-    SbiExprList* pExprList = new SbiExprList;
+    auto pExprList = o3tl::make_unique<SbiExprList>();
     if( !bPar )
     {
         return pExprList;
@@ -1087,9 +1087,9 @@ SbiExprList* SbiExprList::ParseParameters( SbiParser* pParser, bool bStandaloneE
 
 // A list of array dimensions is parsed.
 
-SbiExprList* SbiExprList::ParseDimList( SbiParser* pParser )
+SbiExprListPtr SbiExprList::ParseDimList( SbiParser* pParser )
 {
-    SbiExprList* pExprList = new SbiExprList;
+    auto pExprList = o3tl::make_unique<SbiExprList>();
 
     if( pParser->Next() != LPAREN )
     {
diff --git a/basic/source/inc/expr.hxx b/basic/source/inc/expr.hxx
index 61a5f6b..8f17e8b 100644
--- a/basic/source/inc/expr.hxx
+++ b/basic/source/inc/expr.hxx
@@ -35,7 +35,8 @@ class SbiProcDef;
 
 
 #include <vector>
-typedef ::std::vector<SbiExprList*> SbiExprListVector;
+typedef ::std::unique_ptr<SbiExprList> SbiExprListPtr;
+typedef ::std::vector<SbiExprListPtr> SbiExprListVector;
 
 struct SbVar {
     SbiExprNode*        pNext;      // next element (for structures)
@@ -120,7 +121,7 @@ public:
     SbiExprNode();
     SbiExprNode( double, SbxDataType );
     SbiExprNode( const OUString& );
-    SbiExprNode( const SbiSymDef&, SbxDataType, SbiExprList* = nullptr );
+    SbiExprNode( const SbiSymDef&, SbxDataType, SbiExprListPtr = nullptr );
     SbiExprNode( SbiExprNode*, SbiToken, SbiExprNode* );
     SbiExprNode( SbiExprNode*, sal_uInt16 );    // #120061 TypeOf
     SbiExprNode( sal_uInt16 );                  // new <type>
@@ -186,7 +187,7 @@ public:
     SbiExpression( SbiParser*, SbiExprType = SbSTDEXPR,
         SbiExprMode eMode = EXPRMODE_STANDARD, const KeywordSymbolInfo* pKeywordSymbolInfo = nullptr ); // parsing Ctor
     SbiExpression( SbiParser*, double, SbxDataType = SbxDOUBLE );
-    SbiExpression( SbiParser*, const SbiSymDef&, SbiExprList* = nullptr );
+    SbiExpression( SbiParser*, const SbiSymDef&, SbiExprListPtr = nullptr );
    ~SbiExpression();
     OUString& GetName()             { return aArgName;            }
     void SetBased()                 { bBased = true;              }
@@ -224,8 +225,8 @@ class SbiExprList final {            // class for parameters and dims
 public:
     SbiExprList();
     ~SbiExprList();
-    static SbiExprList* ParseParameters(SbiParser*, bool bStandaloneExpression = false, bool bPar = true);
-    static SbiExprList* ParseDimList( SbiParser* );
+    static SbiExprListPtr ParseParameters(SbiParser*, bool bStandaloneExpression = false, bool bPar = true);
+    static SbiExprListPtr ParseDimList( SbiParser* );
     bool  IsBracket()               { return bBracket;        }
     bool  IsValid()                 { return !bError; }
     short GetSize()                 { return aData.size();    }
diff --git a/basic/source/inc/parser.hxx b/basic/source/inc/parser.hxx
index 21e6971..96683f5 100644
--- a/basic/source/inc/parser.hxx
+++ b/basic/source/inc/parser.hxx
@@ -44,7 +44,7 @@ class SbiParser : public SbiTokenizer
     bool        bSingleLineIf;
     bool        bCodeCompleting;
 
-    SbiSymDef*  VarDecl( SbiExprList**, bool, bool );
+    SbiSymDef*  VarDecl( SbiExprListPtr*, bool, bool );
     SbiProcDef* ProcDecl(bool bDecl);
     void DefStatic( bool bPrivate );
     void DefProc( bool bStatic, bool bPrivate ); // read in procedure


More information about the Libreoffice-commits mailing list