diff options
author | Arnaud Versini <arnaud.versini@gmail.com> | 2016-02-13 20:17:41 +0100 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-02-17 07:08:59 +0000 |
commit | f17a4694b07856292804c23b80ce92967d401bb8 (patch) | |
tree | 1f70cbd4826f3583769b2ba759a6284c0f56ad36 /basic | |
parent | 7b7ffedfa6357b902a5e354d986dac39a3b2f462 (diff) |
BASIC : use std::unique_ptr for storing SbiExprList
Change-Id: I37f2a1c837c6742cf6d403962d2730b5e80004ec
Reviewed-on: https://gerrit.libreoffice.org/22345
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/comp/dim.cxx | 27 | ||||
-rw-r--r-- | basic/source/comp/exprnode.cxx | 12 | ||||
-rw-r--r-- | basic/source/comp/exprtree.cxx | 34 | ||||
-rw-r--r-- | basic/source/inc/expr.hxx | 11 | ||||
-rw-r--r-- | basic/source/inc/parser.hxx | 2 |
5 files changed, 37 insertions, 49 deletions
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 2f9fefac9b5a..ffd7174f26e7 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 77c1aa53c209..d5d9cb6b5a9e 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 d0cb9dbd8d73..99f1f57a18bd 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 61a5f6b6f7bb..8f17e8b0c8b7 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 21e697181658..96683f56a3f5 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 |