From 9139f1df4cda80b91ab68e5de27e85eaa4c54682 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 31 Jul 2006 08:07:12 +0000 Subject: I still can't get the pymake file to auto-make the bison and flex .c files, but besides that everything is looking great. There's only one thing left to parse and interpret before we can try actually building something. --- src/builder.cpp | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) (limited to 'src/builder.cpp') diff --git a/src/builder.cpp b/src/builder.cpp index 2de6f5c..e5017e2 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -3,13 +3,17 @@ #include "builder.h" #include "action.h" #include "command.h" +#include "target.h" #include "build.tab.h" +#include "rule.h" subExceptionDef( BuildException ) Builder::Builder() : pDefaultAction( NULL ), - pLastAddedAction( NULL ) + pLastAddedAction( NULL ), + sTmp(""), + sContext("") { } @@ -51,13 +55,159 @@ void Builder::add( Command *pCmd ) } } +void Builder::add( Rule *pRule ) +{ + pLastAddedRule = pRule; + mRule[pRule->getName()] = pRule; +} + +void Builder::add( Target *pTarg ) +{ + pLastAddedTarget = pTarg; + mTarget[pTarg->getName()] = pTarg; +} + void Builder::debug() { + printf("Actions:\n"); pDefaultAction->debug(); for( std::map::iterator i = mAction.begin(); i != mAction.end(); i++ ) { (*i).second->debug(); } + + printf("Targets:\n"); + for( std::map::iterator i = mTarget.begin(); + i != mTarget.end(); i++ ) + { + (*i).second->debug(); + } + + printf("Rules:\n"); + for( std::map::iterator i = mRule.begin(); + i != mRule.end(); i++ ) + { + (*i).second->debug(); + } + + printf("Variables:\n"); + for( varmap::iterator i = mVar.begin(); i != mVar.end(); i++ ) + { + printf(" %s = \"%s\"\n", (*i).first.c_str(), (*i).second.c_str() ); + } + + printf("Variables (by context):\n"); + for( std::map::iterator j = mContVar.begin(); + j != mContVar.end(); j++ ) + { + printf(" %s:\n", (*j).first.c_str() ); + for( varmap::iterator i = (*j).second.begin(); + i != (*j).second.end(); i++ ) + { + printf(" %s = \"%s\"\n", + (*i).first.c_str(), (*i).second.c_str() ); + } + } + + printf("Additional dependancies:\n"); + for( std::map *>::iterator i = + mRequires.begin(); i != mRequires.end(); i++ ) + { + printf(" %s: ", (*i).first.c_str() ); + std::list *pList = (*i).second; + for( std::list::iterator j = pList->begin(); + j != pList->end(); j++ ) + { + if( j != pList->begin() ) + printf(", "); + printf("%s", (*j).c_str() ); + } + printf("\n"); + } +} + +void Builder::checkVar( const char *cont, const char *sName ) +{ + if( cont[0] != '\0' ) + { + varmap &mmVar = mContVar[cont]; + if( mmVar.find( sName ) == mmVar.end() ) + { + checkVar( "", sName ); + mmVar[sName] = mVar[sName]; + } + } + else + { + if( mVar.find( sName ) == mVar.end() ) + { + char *env = getenv( sName ); + if( env ) + mVar[sName] = env; + else + mVar[sName] = ""; + } + } +} + +void Builder::varSet( const char *sName, const char *sValue ) +{ + checkVar( sContext, sName ); + + if( sContext[0] == '\0' ) + { + mVar[sName] = sValue; + } + else + { + mContVar[sContext.getString()][sName] = sValue; + } +} + +void Builder::varAddSet( const char *sName, const char *sValue ) +{ + checkVar( sContext, sName ); + + if( sContext[0] == '\0' ) + { + std::string s = mVar[sName]; + s += " "; + s += sValue; + mVar[sName] = s; + } + else + { + std::string s = mContVar[sContext.getString()][sName]; + s += " "; + s += sValue; + mContVar[sContext.getString()][sName] = s; + } +} + +void Builder::requires( const char *sBase, const char *sReq ) +{ + std::list *pList = NULL; + if( mRequires.find(sBase) == mRequires.end() ) + { + pList = new std::list; + mRequires[sBase] = pList; + } + else + { + pList = mRequires[sBase]; + } + + pList->push_back( sReq ); +} + +void Builder::setContext( const char *sCont ) +{ + sContext = sCont; +} + +void Builder::setContext() +{ + setContext(""); } -- cgit v1.2.3