From 85539c8c262c0c9e227c87fd1de02c53c163b7d8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 20 Sep 2006 18:56:49 +0000 Subject: Changed the api for variable replacement contexts. There can now be multiple levels of contextual inheritance, so now sub-targets automatically get their parent target's context variables, if they need them. --- src/build.cpp | 33 ++++++++++++++++++++++----------- src/build.h | 4 ++-- src/buildparser.cpp | 4 +++- src/function.cpp | 2 +- src/function.h | 4 ++-- src/functioncommandtolist.cpp | 2 +- src/functioncommandtolist.h | 2 +- src/functiondirectoriesin.cpp | 2 +- src/functiondirectoriesin.h | 2 +- src/functionfilesin.cpp | 2 +- src/functionfilesin.h | 2 +- src/functionregexp.cpp | 2 +- src/functionregexp.h | 2 +- src/functiontargets.cpp | 2 +- src/functiontargets.h | 2 +- src/functiontostring.cpp | 2 +- src/functiontostring.h | 2 +- src/perform.cpp | 2 +- src/perform.h | 5 +++-- src/performcommand.cpp | 2 +- src/performcommand.h | 2 +- src/rule.cpp | 15 +++++++++++---- src/stringproc.h | 4 +++- src/stringprocbuild.cpp | 4 ++-- src/stringprocbuild.h | 2 +- 25 files changed, 65 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/build.cpp b/src/build.cpp index 89366f9..b48e9f1 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -54,14 +54,14 @@ void Build::setStringProc( StringProc *pStrProc ) this->pStrProc = pStrProc; } -std::string Build::replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ) +std::string Build::replVars( const std::string &sSrc, const StringList *pCont, VarMap *mExtra ) { if( pStrProc == NULL ) throw BuildException( "No valid string processor was registered with the Build object." ); - return pStrProc->replVars( sSrc, sCont, mExtra ); + return pStrProc->replVars( sSrc, pCont, mExtra ); } void Build::execAction( const std::string &sWhat ) @@ -144,11 +144,13 @@ void Build::set( const std::string &cont, const std::string &var, const std::str { if( cont == "" ) { - mVars[var] = replVars( val, cont, NULL ); + mVars[var] = replVars( val, NULL, NULL ); } else { - mContVars[cont][var] = replVars( val, cont, NULL ); + StringList cl; + cl.push_front( cont ); + mContVars[cont][var] = replVars( val, &cl, NULL ); } } @@ -156,15 +158,17 @@ void Build::setAdd( const std::string &cont, const std::string &var, const std:: { if( cont == "" ) { - mVars[var] = getVar( cont, var, NULL ) + " " + replVars( val, cont, NULL ); + mVars[var] = getVar( NULL, var, NULL ) + " " + replVars( val, NULL, NULL ); } else { - mContVars[cont][var] = getVar( cont, var, NULL ) + " " + replVars( val, cont, NULL ); + StringList cl; + cl.push_front( cont ); + mContVars[cont][var] = getVar( &cl, var, NULL ) + " " + replVars( val, &cl, NULL ); } } -std::string Build::getVar( const std::string &cont, const std::string &var, VarMap *mExtra ) +std::string Build::getVar( const StringList *cont, const std::string &var, VarMap *mExtra ) { if( mExtra != NULL ) { @@ -175,7 +179,7 @@ std::string Build::getVar( const std::string &cont, const std::string &var, VarM return (*mExtra)[var]; } - if( cont == "" ) + if( cont == NULL ) { if( mVars.find(var) == mVars.end() ) { @@ -192,11 +196,18 @@ std::string Build::getVar( const std::string &cont, const std::string &var, VarM } else { - if( mContVars[cont].find(var) == mContVars[cont].end() ) + if( cont->empty() ) + { + return getVar( NULL, var, NULL ); + } + std::string sTop = cont->front(); + if( mContVars[sTop].find(var) == mContVars[sTop].end() ) { - mContVars[cont][var] = getVar( "", var, NULL ); + ((StringList *)cont)->pop_front(); + mContVars[sTop][var] = getVar( cont, var, NULL ); + ((StringList *)cont)->push_front( sTop ); } - return mContVars[cont][var]; + return mContVars[sTop][var]; } } diff --git a/src/build.h b/src/build.h index e0f60ec..82e4998 100644 --- a/src/build.h +++ b/src/build.h @@ -46,14 +46,14 @@ public: void set( const std::string &cont, const std::string &var, const std::string &val ); void setAdd( const std::string &cont, const std::string &var, const std::string &val ); - std::string getVar( const std::string &cont, const std::string &var, VarMap *mExtra ); + std::string getVar( const StringList *cont, const std::string &var, VarMap *mExtra ); Rule *getRule( const std::string &name ); void debugDump(); void setStringProc( StringProc *pStrProc ); - std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ); + std::string replVars( const std::string &sSrc, const StringList *pCont, VarMap *mExtra ); RuleList findChainRules( Rule *pHead ); StringList &getRequires( std::string sName ); diff --git a/src/buildparser.cpp b/src/buildparser.cpp index 0aa409f..f5b87c7 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -185,7 +185,9 @@ StringList BuildParser::buildToStringListDup( const BuildList &lSrc, const Strin { if( (*i).second ) { - Function *pTmp = (*i).second->duplicate( bld, sCont, mExtra ); + StringList l; + l.push_back( sCont ); + Function *pTmp = (*i).second->duplicate( bld, &l, mExtra ); pTmp->execute( pPass, lIn, lOut ); delete pTmp; } diff --git a/src/function.cpp b/src/function.cpp index 8debbe9..6e4f1d7 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -13,7 +13,7 @@ void Function::addParam( const char *str ) lParams.push_back( str ); } -void Function::copyData( Function *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ) +void Function::copyData( Function *pSrc, Build &bld, const StringList *cont, VarMap *mExtra ) { lParams.clear(); for( std::list::iterator i = pSrc->lParams.begin(); diff --git a/src/function.h b/src/function.h index 7035d2f..af0d3fc 100644 --- a/src/function.h +++ b/src/function.h @@ -12,8 +12,8 @@ public: void addParam( const char *str ); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput )=0; - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) = 0; - void copyData( Function *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) = 0; + void copyData( Function *pSrc, Build &bld, const StringList *cont, VarMap *mExtra ); protected: StringList lParams; diff --git a/src/functioncommandtolist.cpp b/src/functioncommandtolist.cpp index 708db5b..3653135 100644 --- a/src/functioncommandtolist.cpp +++ b/src/functioncommandtolist.cpp @@ -59,7 +59,7 @@ void FunctionCommandToList::execute( Build *bld, const StringList &lInput, Strin //rView.endExtraRequiresCheck(); } -Function *FunctionCommandToList::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Function *FunctionCommandToList::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Function *pRet = new FunctionCommandToList(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/functioncommandtolist.h b/src/functioncommandtolist.h index c74ce29..05bc393 100644 --- a/src/functioncommandtolist.h +++ b/src/functioncommandtolist.h @@ -12,7 +12,7 @@ public: virtual ~FunctionCommandToList(); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); private: diff --git a/src/functiondirectoriesin.cpp b/src/functiondirectoriesin.cpp index cafea81..052125e 100644 --- a/src/functiondirectoriesin.cpp +++ b/src/functiondirectoriesin.cpp @@ -39,7 +39,7 @@ void FunctionDirectoriesIn::execute( Build *bld, const StringList &lInput, Strin closedir( d ); } -Function *FunctionDirectoriesIn::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Function *FunctionDirectoriesIn::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Function *pRet = new FunctionDirectoriesIn(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/functiondirectoriesin.h b/src/functiondirectoriesin.h index c387577..7ec86e3 100644 --- a/src/functiondirectoriesin.h +++ b/src/functiondirectoriesin.h @@ -12,7 +12,7 @@ public: virtual ~FunctionDirectoriesIn(); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); private: diff --git a/src/functionfilesin.cpp b/src/functionfilesin.cpp index 6b47f9f..e1a4c2b 100644 --- a/src/functionfilesin.cpp +++ b/src/functionfilesin.cpp @@ -39,7 +39,7 @@ void FunctionFilesIn::execute( Build *bld, const StringList &lInput, StringList closedir( d ); } -Function *FunctionFilesIn::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Function *FunctionFilesIn::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Function *pRet = new FunctionFilesIn(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/functionfilesin.h b/src/functionfilesin.h index dc504b9..904837f 100644 --- a/src/functionfilesin.h +++ b/src/functionfilesin.h @@ -12,7 +12,7 @@ public: virtual ~FunctionFilesIn(); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); private: diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp index 57a1725..74c19ee 100644 --- a/src/functionregexp.cpp +++ b/src/functionregexp.cpp @@ -42,7 +42,7 @@ void FunctionRegexp::execute( Build *bld, const StringList &lInput, StringList & } } -Function *FunctionRegexp::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Function *FunctionRegexp::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Function *pRet = new FunctionRegexp(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/functionregexp.h b/src/functionregexp.h index 1dfd91e..42fe811 100644 --- a/src/functionregexp.h +++ b/src/functionregexp.h @@ -12,7 +12,7 @@ public: virtual ~FunctionRegexp(); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); private: diff --git a/src/functiontargets.cpp b/src/functiontargets.cpp index 253b585..29a92d3 100644 --- a/src/functiontargets.cpp +++ b/src/functiontargets.cpp @@ -26,7 +26,7 @@ void FunctionTargets::execute( Build *bld, const StringList &lInput, StringList } } -Function *FunctionTargets::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Function *FunctionTargets::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Function *pRet = new FunctionTargets(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/functiontargets.h b/src/functiontargets.h index 8d3a0ed..f42ce96 100644 --- a/src/functiontargets.h +++ b/src/functiontargets.h @@ -12,7 +12,7 @@ public: virtual ~FunctionTargets(); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); private: diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp index 0a7bb48..81ea77d 100644 --- a/src/functiontostring.cpp +++ b/src/functiontostring.cpp @@ -24,7 +24,7 @@ void FunctionToString::execute( Build *bld, const StringList &lInput, StringList lOutput.push_back( sOut ); } -Function *FunctionToString::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Function *FunctionToString::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Function *pRet = new FunctionToString(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/functiontostring.h b/src/functiontostring.h index 4779712..d9c5af7 100644 --- a/src/functiontostring.h +++ b/src/functiontostring.h @@ -12,7 +12,7 @@ public: virtual ~FunctionToString(); virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); - virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Function *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); private: diff --git a/src/perform.cpp b/src/perform.cpp index 64e6bab..25d54c7 100644 --- a/src/perform.cpp +++ b/src/perform.cpp @@ -14,7 +14,7 @@ void Perform::addParam( const char *sParam ) lParam.push_back( sParam ); } -void Perform::copyData( Perform *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ) +void Perform::copyData( Perform *pSrc, Build &bld, const StringList *cont, VarMap *mExtra ) { lParam.clear(); for( std::list::iterator i = pSrc->lParam.begin(); diff --git a/src/perform.h b/src/perform.h index ea8d5e3..031e007 100644 --- a/src/perform.h +++ b/src/perform.h @@ -7,6 +7,7 @@ #include typedef std::map VarMap; +typedef std::list StringList; class Build; @@ -17,9 +18,9 @@ public: virtual ~Perform(); void addParam( const char *sParam ); - virtual Perform *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) = 0; + virtual Perform *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) = 0; virtual void execute( Build &bld ) = 0; - void copyData( Perform *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ); + void copyData( Perform *pSrc, Build &bld, const StringList *cont, VarMap *mExtra ); std::string getTarget() { return sTarget; diff --git a/src/performcommand.cpp b/src/performcommand.cpp index e901b0e..46ac05a 100644 --- a/src/performcommand.cpp +++ b/src/performcommand.cpp @@ -13,7 +13,7 @@ PerformCommand::~PerformCommand() { } -Perform *PerformCommand::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +Perform *PerformCommand::duplicate( Build &bld, const StringList *cont, VarMap *mExtra ) { Perform *pRet = new PerformCommand(); pRet->copyData( this, bld, cont, mExtra ); diff --git a/src/performcommand.h b/src/performcommand.h index d128845..62bf61e 100644 --- a/src/performcommand.h +++ b/src/performcommand.h @@ -11,7 +11,7 @@ public: PerformCommand(); virtual ~PerformCommand(); - virtual Perform *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual Perform *duplicate( Build &bld, const StringList *cont, VarMap *mExtra ); virtual void execute( Build &bld ); private: diff --git a/src/rule.cpp b/src/rule.cpp index dcf62d4..f1b0317 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -70,7 +70,9 @@ StringList Rule::execute( Build &bld, StringList &lInput, PerformList &lPerf ) for( PerformList::iterator k = lPerform.begin(); k != lPerform.end(); k++ ) { - Perform *p = (*k)->duplicate( bld, target, &mTmp ); + StringList cont; + cont.push_front( target ); + Perform *p = (*k)->duplicate( bld, &cont, &mTmp ); p->setTarget( target ); p->setRule( sName ); //p->setReqFuncs( &lReqFuncs ); @@ -86,7 +88,9 @@ StringList Rule::execute( Build &bld, StringList &lInput, PerformList &lPerf ) StringList::iterator j = lProduces.begin(); { VarMap mTmp; - std::string target = bld.replVars( (*j), (*i), NULL ); + StringList cont; + cont.push_front( (*i) ); + std::string target = bld.replVars( (*j), &cont, NULL ); mTmp["target"] = target; lNewOut.push_back( target ); mTmp["match"] = (*i); @@ -99,14 +103,17 @@ StringList Rule::execute( Build &bld, StringList &lInput, PerformList &lPerf ) for( PerformList::iterator k = lPerform.begin(); k != lPerform.end(); k++ ) { - Perform *p = (*k)->duplicate( bld, target, &mTmp ); + StringList cont2; + cont2.push_front( (*i) ); + cont2.push_front( target ); + Perform *p = (*k)->duplicate( bld, &cont2, &mTmp ); p->setTarget( target ); p->setRule( sName ); for( FunctionList::iterator f = lReqFuncs.begin(); f != lReqFuncs.end(); f++ ) { p->getReqFuncs().push_back( - (*f)->duplicate( bld, target, &mTmp ) + (*f)->duplicate( bld, &cont2, &mTmp ) ); } lPerf.push_back( p ); diff --git a/src/stringproc.h b/src/stringproc.h index 860579f..d408601 100644 --- a/src/stringproc.h +++ b/src/stringproc.h @@ -4,10 +4,12 @@ #include #include #include +#include class Build; typedef std::map VarMap; +typedef std::list StringList; class StringProc { @@ -15,7 +17,7 @@ public: StringProc( Build *pBld ); virtual ~StringProc(); - virtual std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra )=0; + virtual std::string replVars( const std::string &sSrc, const StringList *pCont, VarMap *mExtra )=0; protected: Build *getBuild() diff --git a/src/stringprocbuild.cpp b/src/stringprocbuild.cpp index 071e941..419d819 100644 --- a/src/stringprocbuild.cpp +++ b/src/stringprocbuild.cpp @@ -10,7 +10,7 @@ StringProcBuild::~StringProcBuild() { } -std::string StringProcBuild::replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ) +std::string StringProcBuild::replVars( const std::string &sSrc, const StringList *pCont, VarMap *mExtra ) { std::string sDes, sBuf; int nMode = 0; @@ -31,7 +31,7 @@ std::string StringProcBuild::replVars( const std::string &sSrc, const std::strin { if( sSrc[j] == '}' ) { - sDes += getBuild()->getVar( sCont, sBuf, mExtra ); + sDes += getBuild()->getVar( pCont, sBuf, mExtra ); nMode = 0; } else diff --git a/src/stringprocbuild.h b/src/stringprocbuild.h index d940507..f3cf3b4 100644 --- a/src/stringprocbuild.h +++ b/src/stringprocbuild.h @@ -11,7 +11,7 @@ public: StringProcBuild( Build *pBld ); virtual ~StringProcBuild(); - virtual std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ); + virtual std::string replVars( const std::string &sSrc, const StringList *pCont, VarMap *mExtra ); private: -- cgit v1.2.3