From 97d529fac68105f0d3d34c699a4ac10489c705e8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 10 Sep 2006 22:27:37 +0000 Subject: Almost done tweaking the variable system, it needed support for local, or "extra" variables. --- build.conf | 1 + src/build.cpp | 21 +++++++++++++++------ src/build.h | 6 +++--- src/perform.cpp | 4 ++-- src/perform.h | 5 ++++- src/performcommand.cpp | 2 +- src/rule.cpp | 5 ++++- src/rule.h | 4 +++- src/stringproc.h | 5 ++++- src/stringprocbuild.cpp | 4 ++-- src/stringprocbuild.h | 2 +- src/targetfile.cpp | 18 +++++++++++++++++- 12 files changed, 57 insertions(+), 20 deletions(-) diff --git a/build.conf b/build.conf index 32ce750..640fbff 100644 --- a/build.conf +++ b/build.conf @@ -33,3 +33,4 @@ rule "flex": matches regexp("(.*)\\.l$"), produces "{re:1}.yy.c", perform command("flex --bison-bridge --bison-locations -o {target} {match}") + diff --git a/src/build.cpp b/src/build.cpp index 372e607..255cbd3 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -17,14 +17,14 @@ void Build::setStringProc( StringProc *pStrProc ) this->pStrProc = pStrProc; } -std::string Build::replVars( const std::string &sSrc, const std::string &sCont ) +std::string Build::replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ) { if( pStrProc == NULL ) throw BuildException( "No valid string processor was registered with the Build object." ); - return pStrProc->replVars( sSrc, sCont ); + return pStrProc->replVars( sSrc, sCont, mExtra ); } void Build::execAction( const std::string &sWhat ) @@ -113,16 +113,25 @@ void Build::setAdd( const std::string &cont, const std::string &var, const std:: { if( cont == "" ) { - mVars[var] = getVar( cont, var ) + " " + val; + mVars[var] = getVar( cont, var, NULL ) + " " + val; } else { - mContVars[cont][var] = getVar( cont, var ) + " " + val; + mContVars[cont][var] = getVar( cont, var, NULL ) + " " + val; } } -std::string Build::getVar( const std::string &cont, const std::string &var ) +std::string Build::getVar( const std::string &cont, const std::string &var, VarMap *mExtra ) { + if( mExtra != NULL ) + { + if( mExtra->find(var) == mExtra->end() ) + { + return getVar( cont, var, NULL ); + } + return (*mExtra)[var]; + } + if( cont == "" ) { if( mVars.find(var) == mVars.end() ) @@ -142,7 +151,7 @@ std::string Build::getVar( const std::string &cont, const std::string &var ) { if( mContVars[cont].find(var) == mContVars[cont].end() ) { - mContVars[cont][var] = getVar( "", var ); + mContVars[cont][var] = getVar( "", var, NULL ); } return mContVars[cont][var]; } diff --git a/src/build.h b/src/build.h index d5e6604..080304b 100644 --- a/src/build.h +++ b/src/build.h @@ -13,6 +13,7 @@ #include "stringproc.h" subExceptionDecl( BuildException ); +typedef std::map VarMap; class Build { @@ -35,20 +36,19 @@ 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 ); + std::string getVar( const std::string &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 ); + std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ); private: typedef std::map TargetMap; typedef std::list StringList; typedef std::map ReqMap; - typedef std::map VarMap; typedef std::map ContextMap; typedef std::map RuleMap; typedef std::map ActionMap; diff --git a/src/perform.cpp b/src/perform.cpp index 20ad51a..64e6bab 100644 --- a/src/perform.cpp +++ b/src/perform.cpp @@ -14,13 +14,13 @@ void Perform::addParam( const char *sParam ) lParam.push_back( sParam ); } -void Perform::copyData( Perform *pSrc, Build &bld, const std::string &cont ) +void Perform::copyData( Perform *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ) { lParam.clear(); for( std::list::iterator i = pSrc->lParam.begin(); i != pSrc->lParam.end(); i++ ) { - lParam.push_back( bld.replVars( *i, cont ) ); + lParam.push_back( bld.replVars( *i, cont, mExtra ) ); } } diff --git a/src/perform.h b/src/perform.h index add5a09..93c8b9a 100644 --- a/src/perform.h +++ b/src/perform.h @@ -4,6 +4,9 @@ #include #include #include +#include + +typedef std::map VarMap; class Build; @@ -15,7 +18,7 @@ public: void addParam( const char *sParam ); virtual Perform *duplicate( Build &bld, const std::string &cont ) = 0; - void copyData( Perform *pSrc, Build &bld, const std::string &cont ); + void copyData( Perform *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ); std::string getTarget() { return sTarget; diff --git a/src/performcommand.cpp b/src/performcommand.cpp index 7505061..6963022 100644 --- a/src/performcommand.cpp +++ b/src/performcommand.cpp @@ -14,7 +14,7 @@ PerformCommand::~PerformCommand() Perform *PerformCommand::duplicate( Build &bld, const std::string &cont ) { Perform *pRet = new PerformCommand(); - pRet->copyData( this, bld, cont ); + pRet->copyData( this, bld, cont, NULL ); return pRet; } diff --git a/src/rule.cpp b/src/rule.cpp index 4426575..4919eef 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -8,7 +8,10 @@ Rule::~Rule() { } -void Rule::execute() +StringList Rule::execute( Build &bld, StringList &lInput, PerformList &lPerf ) { + StringList lOutput; + + return lOutput; } diff --git a/src/rule.h b/src/rule.h index 73d7738..5b2bbfd 100644 --- a/src/rule.h +++ b/src/rule.h @@ -7,9 +7,11 @@ class Function; class Perform; +class Build; typedef std::list FunctionList; typedef std::list PerformList; +typedef std::list StringList; class Rule { @@ -17,7 +19,7 @@ public: Rule(); virtual ~Rule(); - void execute(); + StringList execute( Build &bld, StringList &lInput, PerformList &lPerf ); std::string getName() { diff --git a/src/stringproc.h b/src/stringproc.h index 237ad6f..860579f 100644 --- a/src/stringproc.h +++ b/src/stringproc.h @@ -3,16 +3,19 @@ #include #include +#include class Build; +typedef std::map VarMap; + class StringProc { public: StringProc( Build *pBld ); virtual ~StringProc(); - virtual std::string replVars( const std::string &sSrc, const std::string &sCont )=0; + virtual std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra )=0; protected: Build *getBuild() diff --git a/src/stringprocbuild.cpp b/src/stringprocbuild.cpp index d0a5951..071e941 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 ) +std::string StringProcBuild::replVars( const std::string &sSrc, const std::string &sCont, 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 ); + sDes += getBuild()->getVar( sCont, sBuf, mExtra ); nMode = 0; } else diff --git a/src/stringprocbuild.h b/src/stringprocbuild.h index 13dd4f6..d940507 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 ); + virtual std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ); private: diff --git a/src/targetfile.cpp b/src/targetfile.cpp index 8f6651e..dc9e597 100644 --- a/src/targetfile.cpp +++ b/src/targetfile.cpp @@ -18,7 +18,23 @@ void TargetFile::check( Build &bld ) printf("Target file checking: %s\n", getName().c_str() ); Rule *pRule = bld.getRule( getRule() ); - pRule->execute(); + PerformList lPerf; + StringList lFinal = pRule->execute( bld, getInput(), lPerf ); + + printf("Input: "); + for( StringList::iterator i = getInput().begin(); + i != getInput().end(); i++ ) + { + if( i != getInput().begin() ) printf(", "); + printf("%s", (*i).c_str() ); + } + printf("\nFinal: "); + for( StringList::iterator i = lFinal.begin(); i != lFinal.end(); i++ ) + { + if( i != lFinal.begin() ) printf(", "); + printf("%s", (*i).c_str() ); + } + printf("\n"); } void TargetFile::clean( Build &bld ) -- cgit v1.2.3