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. --- Makefile | 143 ++++++++++++++++++++++++++++++------------ build.conf | 1 + 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 +- 22 files changed, 389 insertions(+), 59 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 diff --git a/Makefile b/Makefile index 0be9792..9cba6a0 100644 --- a/Makefile +++ b/Makefile @@ -1,54 +1,119 @@ -SRC:=$(wildcard src/*.cpp) -OBJS:=$(patsubst %.cpp,%.o,$(SRC)) -VER:=r$(shell svn info | grep "Revision" | cut -d\ -f2) -LIBS:=bu++ -LIBDIRS:=$(patsubst %,lib%,$(LIBS)) -LIBFILES:=$(foreach dir,$(LIBDIRS),$(dir)/$(dir).a) -DEPFILES:=$(patsubst %.o,%.d,$(OBJS)) +.PHONY: all clean parser-header lexer-header build-header -.PHONY: all clean dist checklibs +.SILENT: all clean parser-header src/build.tab.c src/build.tab.o parser lexer-header src/build.yy.c src/build.yy.o lexer build-header src/builder.o src/main.o src/perform.o src/performfactory.o src/functionregexp.o src/functioncommandtolist.o src/performcommand.o src/functionfilesin.o src/functionfactory.o src/function.o src/functiontostring.o src/viewer.o src/functiondirectoriesin.o build -all: checklibs src/version.h build +all: parser-header parser lexer-header lexer build-header build -checklibs: - for ldir in $(LIBDIRS); do make -C $$ldir; done +parser-header: + echo "--- parser ---" --include $(DEPFILES) +src/build.tab.c: src/build.y + echo " comp: src/build.tab.c" + cd src; bison ../src/build.y; cd .. -src/version.h: .svn - echo "#define SVNREV \"$(VER)\"" > src/version.h +src/build.tab.o: src/build.tab.c + echo " comp: src/build.tab.o" + g++ -c src/build.tab.c -ggdb -Ilibbu++/src -Isrc -o src/build.tab.o -%.o: %.cpp %.d - g++ -ggdb $(CXXFLAGS) -Isrc $(patsubst %,-I%/src,$(LIBDIRS)) -c -o $@ $< +parser: src/build.tab.o + echo " stupid: parser" + -clean: - -rm $(foreach dir,src,$(wildcard $(dir)/*.o)) build src/version.h +lexer-header: + echo + echo "--- lexer ---" + +src/build.yy.c: src/build.l + echo " comp: src/build.yy.c" + flex --bison-bridge --bison-locations -o src/build.yy.c src/build.l + +src/build.yy.o: src/build.yy.c + echo " comp: src/build.yy.o" + g++ -c src/build.yy.c -ggdb -Ilibbu++/src -Isrc -o src/build.yy.o + +lexer: src/build.yy.o + echo " stupid: lexer" + + +build-header: + echo + echo "--- build ---" + +src/builder.o: src/builder.cpp + echo " comp: src/builder.o" + g++ -c src/builder.cpp -ggdb -Ilibbu++/src -Isrc -o src/builder.o + +src/main.o: src/main.cpp + echo " comp: src/main.o" + g++ -c src/main.cpp -ggdb -Ilibbu++/src -Isrc -o src/main.o -depclean: - -rm $(foreach dir,src src/lib $(TOOLDIRS),$(wildcard $(dir)/*.d)) +src/perform.o: src/perform.cpp + echo " comp: src/perform.o" + g++ -c src/perform.cpp -ggdb -Ilibbu++/src -Isrc -o src/perform.o -%.d: %.cpp - g++ -Isrc -Isrc/lib $(CXXFLAGS) $(patsubst %,-I%/src,$(LIBDIRS)) -M $(CPPFLAGS) $< | sed 's,\($(patsubst src/%,%,$*)\)\.o[:]*,src/\1.o $@:,g' > $@ +src/performfactory.o: src/performfactory.cpp + echo " comp: src/performfactory.o" + g++ -c src/performfactory.cpp -ggdb -Ilibbu++/src -Isrc -o src/performfactory.o -$(LIBFILES): - make -C $(dir $@) $(notdir $@) +src/functionregexp.o: src/functionregexp.cpp + echo " comp: src/functionregexp.o" + g++ -c src/functionregexp.cpp -ggdb -Ilibbu++/src -Isrc -o src/functionregexp.o -test: - -build +src/functioncommandtolist.o: src/functioncommandtolist.cpp + echo " comp: src/functioncommandtolist.o" + g++ -c src/functioncommandtolist.cpp -ggdb -Ilibbu++/src -Isrc -o src/functioncommandtolist.o -build: $(LIBFILES) $(OBJS) - g++ -ggdb $(OBJS) -o build $(patsubst %,-L%,$(LIBDIRS)) $(patsubst %,-l%,$(LIBS)) +src/performcommand.o: src/performcommand.cpp + echo " comp: src/performcommand.o" + g++ -c src/performcommand.cpp -ggdb -Ilibbu++/src -Isrc -o src/performcommand.o -api: $(LIBSRC) $(TOOLSRC) - sed 's/PROJECT_NUMBER.*/PROJECT_NUMBER = $(VER)/' < Doxyfile > Doxyfile.tmp - doxygen Doxyfile.tmp - rm Doxyfile.tmp - make -C api/latex +src/functionfilesin.o: src/functionfilesin.cpp + echo " comp: src/functionfilesin.o" + g++ -c src/functionfilesin.cpp -ggdb -Ilibbu++/src -Isrc -o src/functionfilesin.o -dist: clean src/version.h - mkdir build-$(VER) - cp -a --target-directory=build-$(VER) Makefile src - tar --exclude=\.svn -c build-$(VER) | bzip2 -9 > build-$(VER).tar.bz2 - rm -Rf build-$(VER) - -for dir in $(LIBDIRS); do make -C $$dir dist; done +src/functionfactory.o: src/functionfactory.cpp + echo " comp: src/functionfactory.o" + g++ -c src/functionfactory.cpp -ggdb -Ilibbu++/src -Isrc -o src/functionfactory.o + +src/function.o: src/function.cpp + echo " comp: src/function.o" + g++ -c src/function.cpp -ggdb -Ilibbu++/src -Isrc -o src/function.o + +src/functiontostring.o: src/functiontostring.cpp + echo " comp: src/functiontostring.o" + g++ -c src/functiontostring.cpp -ggdb -Ilibbu++/src -Isrc -o src/functiontostring.o + +src/viewer.o: src/viewer.cpp + echo " comp: src/viewer.o" + g++ -c src/viewer.cpp -ggdb -Ilibbu++/src -Isrc -o src/viewer.o + +src/functiondirectoriesin.o: src/functiondirectoriesin.cpp + echo " comp: src/functiondirectoriesin.o" + g++ -c src/functiondirectoriesin.cpp -ggdb -Ilibbu++/src -Isrc -o src/functiondirectoriesin.o + +build: src/functionfactory.o src/functiontostring.o src/perform.o src/functiondirectoriesin.o src/viewer.o src/main.o src/performcommand.o src/functionregexp.o src/builder.o src/build.yy.o src/functionfilesin.o src/function.o src/performfactory.o src/functioncommandtolist.o src/build.tab.o + echo " exe: build" + g++ src/functionfactory.o src/functiontostring.o src/perform.o src/functiondirectoriesin.o src/viewer.o src/main.o src/performcommand.o src/functionregexp.o src/builder.o src/build.yy.o src/functionfilesin.o src/function.o src/performfactory.o src/functioncommandtolist.o src/build.tab.o -Llibbu++ -lbu++ -ldl -o build + +clean: + -if [ -f src/build.tab.c ] ; then echo " rm: src/build.tab.c" ; rm src/build.tab.c ; fi + -if [ -f src/build.tab.o ] ; then echo " rm: src/build.tab.o" ; rm src/build.tab.o ; fi + -if [ -f parser ] ; then echo " rm: parser" ; rm parser ; fi + -if [ -f src/build.yy.c ] ; then echo " rm: src/build.yy.c" ; rm src/build.yy.c ; fi + -if [ -f src/build.yy.o ] ; then echo " rm: src/build.yy.o" ; rm src/build.yy.o ; fi + -if [ -f lexer ] ; then echo " rm: lexer" ; rm lexer ; fi + -if [ -f src/builder.o ] ; then echo " rm: src/builder.o" ; rm src/builder.o ; fi + -if [ -f src/main.o ] ; then echo " rm: src/main.o" ; rm src/main.o ; fi + -if [ -f src/perform.o ] ; then echo " rm: src/perform.o" ; rm src/perform.o ; fi + -if [ -f src/performfactory.o ] ; then echo " rm: src/performfactory.o" ; rm src/performfactory.o ; fi + -if [ -f src/functionregexp.o ] ; then echo " rm: src/functionregexp.o" ; rm src/functionregexp.o ; fi + -if [ -f src/functioncommandtolist.o ] ; then echo " rm: src/functioncommandtolist.o" ; rm src/functioncommandtolist.o ; fi + -if [ -f src/performcommand.o ] ; then echo " rm: src/performcommand.o" ; rm src/performcommand.o ; fi + -if [ -f src/functionfilesin.o ] ; then echo " rm: src/functionfilesin.o" ; rm src/functionfilesin.o ; fi + -if [ -f src/functionfactory.o ] ; then echo " rm: src/functionfactory.o" ; rm src/functionfactory.o ; fi + -if [ -f src/function.o ] ; then echo " rm: src/function.o" ; rm src/function.o ; fi + -if [ -f src/functiontostring.o ] ; then echo " rm: src/functiontostring.o" ; rm src/functiontostring.o ; fi + -if [ -f src/viewer.o ] ; then echo " rm: src/viewer.o" ; rm src/viewer.o ; fi + -if [ -f src/functiondirectoriesin.o ] ; then echo " rm: src/functiondirectoriesin.o" ; rm src/functiondirectoriesin.o ; fi + -if [ -f build ] ; then echo " rm: build" ; rm build ; fi diff --git a/build.conf b/build.conf index d05ef3f..4d2e61b 100644 --- a/build.conf +++ b/build.conf @@ -1,6 +1,7 @@ # build.conf for build, kind of whacky, eh? default action: check "build", check "cleanup" +"clean" action: clean ["build", "cleanup"] set "CXXFLAGS" += "-ggdb" 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