From f5cf5725026ecb2fa63d729fb6745b4da15e69d8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 22 Aug 2006 15:12:20 +0000 Subject: Started on the crazy process of building the stage one compiled data. It's going pretty quickly, we'll see how the targets go, they'll be the only tricky part. --- src/action.cpp | 9 ++++ src/action.h | 22 ++++++++++ src/build.cpp | 9 ++++ src/build.h | 17 ++++++++ src/build.y | 71 ++++++++++++++++++++++++------- src/builder.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++- src/builder.h | 25 ++++++++++- src/function.cpp | 6 +++ src/function.h | 6 ++- src/functioncommandtolist.cpp | 5 +++ src/functioncommandtolist.h | 2 + src/functiondirectoriesin.cpp | 5 +++ src/functiondirectoriesin.h | 2 + src/functionfilesin.cpp | 5 +++ src/functionfilesin.h | 2 + src/functionregexp.cpp | 5 +++ src/functionregexp.h | 2 + src/functiontostring.cpp | 5 +++ src/functiontostring.h | 2 + src/main.cpp | 6 +-- 20 files changed, 284 insertions(+), 20 deletions(-) create mode 100644 src/action.cpp create mode 100644 src/action.h create mode 100644 src/build.cpp create mode 100644 src/build.h (limited to 'src') diff --git a/src/action.cpp b/src/action.cpp new file mode 100644 index 0000000..cdf50e8 --- /dev/null +++ b/src/action.cpp @@ -0,0 +1,9 @@ +#include "action.h" + +Action::Action() +{ +} + +Action::~Action() +{ +} diff --git a/src/action.h b/src/action.h new file mode 100644 index 0000000..4ec3b4a --- /dev/null +++ b/src/action.h @@ -0,0 +1,22 @@ +#ifndef ACTION_H +#define ACTION_H + +#include + +class Action +{ +public: + enum eAction + { + actCheck, + actClean + }; +public: + Action(); + virtual ~Action(); + +private: + +}; + +#endif diff --git a/src/build.cpp b/src/build.cpp new file mode 100644 index 0000000..d3bd960 --- /dev/null +++ b/src/build.cpp @@ -0,0 +1,9 @@ +#include "build.h" + +Build::Build() +{ +} + +Build::~Build() +{ +} diff --git a/src/build.h b/src/build.h new file mode 100644 index 0000000..a2bf3ed --- /dev/null +++ b/src/build.h @@ -0,0 +1,17 @@ +#ifndef BUILD_H +#define BUILD_H + +#include + + +class Build +{ +public: + Build(); + virtual ~Build(); + +private: + +}; + +#endif diff --git a/src/build.y b/src/build.y index 1424867..40f8d34 100644 --- a/src/build.y +++ b/src/build.y @@ -3,6 +3,7 @@ # include # include "builder.h" # include "build.tab.h" +# include "action.h" void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); %} @@ -69,21 +70,37 @@ rulecmd: TOK_MATCHES { printf(" Matches: " ); } func { printf("\n"); } ; // Action interpretation -action: TOK_DEFAULT TOK_ACTION ':' { printf("Default action:\n"); } actioncmds - | STRING TOK_ACTION ':' { printf("\"%s\" action:\n", $1 ); } actioncmds +action: TOK_DEFAULT TOK_ACTION ':' + { + bld.addAction(); + } + actioncmds + | STRING TOK_ACTION ':' + { + if( $1[0] == '\0' ) + bld.error( + &yylloc, + "You cannot use an empty string as the name of an action." + ); + bld.addAction( $1 ); + } + actioncmds ; actioncmds: actioncmd | actioncmds ',' actioncmd ; -actioncmd: { printf(" "); } actioncmdtype list {printf("\n");} +actioncmd: TOK_CHECK list + { + bld.addCommand( Action::actCheck ); + } + | TOK_CLEAN list + { + bld.addCommand( Action::actClean ); + } ; -actioncmdtype: TOK_CHECK { printf("check "); } - | TOK_CLEAN { printf("clean "); } - ; - // Target interpretation target: list ':' { printf(" are targets:\n"); } targetcmds ; @@ -114,8 +131,12 @@ setwhat: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); } ; // list goo -list: listitem listfilter - | '[' { printf("["); } listitems ']' { printf("]"); } listfilter +list: singlelistitem listfilter + | '[' + { + bld.newList(); + } + listitems ']' listfilter ; listfilter: @@ -123,20 +144,42 @@ listfilter: ; listitems: listitem - | listitems ',' { printf(", "); } listitem + | listitems ',' listitem ; -listitem: STRING { printf("%s", $1 ); } +listitem: STRING + { + bld.addListString( $1 ); + } | func + { + bld.addListFunc(); + } ; +singlelistitem: STRING + { + bld.newList(); + bld.addListString( $1 ); + } + | func + { + bld.newList(); + bld.addListFunc(); + } + ; + // Function -func: FUNCTION { printf("%s(", $1 ); } '(' funcparams ')' { printf(")"); } +func: FUNCTION + { + bld.newFunctionCall( $1 ); + } + '(' funcparams ')' ; funcparams: - | STRING { printf("%s", $1 ); } - | funcparams ',' STRING { printf(", %s", $3 ); } + | STRING { bld.addFunctionParam( $1 ); } + | funcparams ',' STRING { bld.addFunctionParam( $3 ); } ; // Perform diff --git a/src/builder.cpp b/src/builder.cpp index e8cd6e2..70be725 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -2,6 +2,7 @@ #include "functionfactory.h" #include "performfactory.h" #include "targetfactory.h" +#include "action.h" subExceptionDef( BuildException ); @@ -62,11 +63,46 @@ bool Builder::isFunction( const char *sFunc ) void Builder::newFunctionCall( const char *sName ) { - + pTmpFunc = fFunction.instantiate( sName ); } void Builder::addFunctionParam( const char *sParam ) { + pTmpFunc->addParam( sParam ); +} + +void Builder::newList() +{ + lTmp.clear(); +} + +void Builder::addListString( const char *str ) +{ + lTmp.push_back( BuildListItem(str, NULL) ); +} + +void Builder::addListFunc() +{ + lTmp.push_back( BuildListItem("", pTmpFunc ) ); +} + +StringList Builder::buildToStringList( Builder::BuildList &lSrc, StringList &lIn ) +{ + StringList lOut; + + for( BuildList::iterator i = lSrc.begin(); i != lSrc.end(); i++ ) + { + if( (*i).second ) + { + (*i).second->execute( lIn, lOut ); + } + else + { + lOut.push_back( (*i).first ); + } + } + + return lOut; } // @@ -85,3 +121,63 @@ void Builder::addPerformParam( const char *sParam ) { } +// +// Functions for dealing with actions +// +void Builder::addAction() +{ + lActions.push_back( ActionTmp("", ActionTmpCmdList()) ); +} + +void Builder::addAction( const char *sName ) +{ + lActions.push_back( ActionTmp(sName, ActionTmpCmdList()) ); +} + +void Builder::addCommand( int nType ) +{ + lActions.back().second.push_back( ActionTmpCmd( nType, lTmp ) ); +} + +// +// Debug +// +void Builder::debugDump() +{ + printf("Actions:\n"); + for( ActionTmpList::iterator i = lActions.begin(); + i != lActions.end(); i++ ) + { + if( (*i).first == "" ) + { + printf(" default:\n"); + } + else + { + printf(" \"%s\":\n", (*i).first.c_str() ); + } + for( ActionTmpCmdList::iterator j = (*i).second.begin(); + j != (*i).second.end(); j++ ) + { + printf(" %d [", (*j).first ); + for( BuildList::iterator k = (*j).second.begin(); + k != (*j).second.end(); k++ ) + { + if( k != (*j).second.begin() ) + { + printf(", "); + } + if( (*k).second ) + { + printf("func()"); + } + else + { + printf("\"%s\"", (*k).first.c_str() ); + } + } + printf("]\n"); + } + } +} + diff --git a/src/builder.h b/src/builder.h index a6f88f4..1d126dc 100644 --- a/src/builder.h +++ b/src/builder.h @@ -3,6 +3,8 @@ #include #include +#include +#include #include "build.tab.h" #include "exceptions.h" @@ -19,6 +21,8 @@ YY_DECL; subExceptionDecl( BuildException ); +typedef std::list StringList; + class Builder { public: @@ -30,7 +34,6 @@ public: void load( const std::string &sFile ); - private: std::string file; void scanBegin(); @@ -66,10 +69,30 @@ public: // List functions void addListString( const char *str ); void addListFunc(); + typedef std::pair BuildListItem; + typedef std::list BuildList; + + StringList buildToStringList( BuildList &lSrc, StringList &lIn ); + +private: + BuildList lTmp; + public: // Functions for dealing with rules + +public: // Functions for dealing with actions void addAction(); void addAction( const char *sName ); void addCommand( int nType ); + +private: // Action variables + typedef std::pair ActionTmpCmd; + typedef std::list ActionTmpCmdList; + typedef std::pair ActionTmp; + typedef std::list ActionTmpList; + ActionTmpList lActions; + +public: // Debug + void debugDump(); }; #endif diff --git a/src/function.cpp b/src/function.cpp index 5eeac97..e7554e1 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -7,3 +7,9 @@ Function::Function() Function::~Function() { } + +void Function::addParam( const char *str ) +{ + lParams.push_back( str ); +} + diff --git a/src/function.h b/src/function.h index 44a894d..c840922 100644 --- a/src/function.h +++ b/src/function.h @@ -2,7 +2,7 @@ #define FUNCTION_H #include - +#include "builder.h" class Function { @@ -10,7 +10,11 @@ public: Function(); virtual ~Function(); + void addParam( const char *str ); + virtual void execute( StringList &lInput, StringList &lOutput )=0; + private: + StringList lParams; }; diff --git a/src/functioncommandtolist.cpp b/src/functioncommandtolist.cpp index 8d18870..6299f6f 100644 --- a/src/functioncommandtolist.cpp +++ b/src/functioncommandtolist.cpp @@ -10,3 +10,8 @@ FunctionCommandToList::FunctionCommandToList() FunctionCommandToList::~FunctionCommandToList() { } + +void FunctionCommandToList::execute( StringList &lInput, StringList &lOutput ) +{ +} + diff --git a/src/functioncommandtolist.h b/src/functioncommandtolist.h index 90b4bf3..5bebe16 100644 --- a/src/functioncommandtolist.h +++ b/src/functioncommandtolist.h @@ -10,6 +10,8 @@ class FunctionCommandToList : public Function public: FunctionCommandToList(); virtual ~FunctionCommandToList(); + + virtual void execute( StringList &lInput, StringList &lOutput ); private: diff --git a/src/functiondirectoriesin.cpp b/src/functiondirectoriesin.cpp index f847e13..a22e5d7 100644 --- a/src/functiondirectoriesin.cpp +++ b/src/functiondirectoriesin.cpp @@ -10,3 +10,8 @@ FunctionDirectoriesIn::FunctionDirectoriesIn() FunctionDirectoriesIn::~FunctionDirectoriesIn() { } + +void FunctionDirectoriesIn::execute( StringList &lInput, StringList &lOutput ) +{ +} + diff --git a/src/functiondirectoriesin.h b/src/functiondirectoriesin.h index 5f6ee42..d769a0d 100644 --- a/src/functiondirectoriesin.h +++ b/src/functiondirectoriesin.h @@ -10,6 +10,8 @@ class FunctionDirectoriesIn : public Function public: FunctionDirectoriesIn(); virtual ~FunctionDirectoriesIn(); + + virtual void execute( StringList &lInput, StringList &lOutput ); private: diff --git a/src/functionfilesin.cpp b/src/functionfilesin.cpp index 3a9d163..7dc073b 100644 --- a/src/functionfilesin.cpp +++ b/src/functionfilesin.cpp @@ -10,3 +10,8 @@ FunctionFilesIn::FunctionFilesIn() FunctionFilesIn::~FunctionFilesIn() { } + +void FunctionFilesIn::execute( StringList &lInput, StringList &lOutput ) +{ +} + diff --git a/src/functionfilesin.h b/src/functionfilesin.h index 070f508..2ad23f9 100644 --- a/src/functionfilesin.h +++ b/src/functionfilesin.h @@ -10,6 +10,8 @@ class FunctionFilesIn : public Function public: FunctionFilesIn(); virtual ~FunctionFilesIn(); + + virtual void execute( StringList &lInput, StringList &lOutput ); private: diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp index fd632ae..045f745 100644 --- a/src/functionregexp.cpp +++ b/src/functionregexp.cpp @@ -10,3 +10,8 @@ FunctionRegexp::FunctionRegexp() FunctionRegexp::~FunctionRegexp() { } + +void FunctionRegexp::execute( StringList &lInput, StringList &lOutput ) +{ +} + diff --git a/src/functionregexp.h b/src/functionregexp.h index 0adaf97..80a8220 100644 --- a/src/functionregexp.h +++ b/src/functionregexp.h @@ -10,6 +10,8 @@ class FunctionRegexp : public Function public: FunctionRegexp(); virtual ~FunctionRegexp(); + + virtual void execute( StringList &lInput, StringList &lOutput ); private: diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp index 93a8b56..f5f43b2 100644 --- a/src/functiontostring.cpp +++ b/src/functiontostring.cpp @@ -10,3 +10,8 @@ FunctionToString::FunctionToString() FunctionToString::~FunctionToString() { } + +void FunctionToString::execute( StringList &lInput, StringList &lOutput ) +{ +} + diff --git a/src/functiontostring.h b/src/functiontostring.h index 08baadd..93bc20f 100644 --- a/src/functiontostring.h +++ b/src/functiontostring.h @@ -10,6 +10,8 @@ class FunctionToString : public Function public: FunctionToString(); virtual ~FunctionToString(); + + virtual void execute( StringList &lInput, StringList &lOutput ); private: diff --git a/src/main.cpp b/src/main.cpp index 9168df7..97c2708 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,12 +85,12 @@ int main( int argc, char *argv[] ) // return 1; //} - if( prm.bDebug ) + //if( prm.bDebug ) { printf("\n\n----------\nDebug dump\n----------\n"); - //bld.debug(); + bld.debugDump(); } - else + //else { //if( prm.sAction > 0 ) // bld.build( prm.sAction ); -- cgit v1.2.3