From f7809b1a74da9a653b475b6fa499b078cad48c74 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 28 Aug 2006 18:26:07 +0000 Subject: Renamed Builder to BuildParser, soon I'll add the Parser base class and make the whole thing official. --- src/build.l | 6 +- src/build.y | 11 +- src/builder.cpp | 432 ---------------------------------------------------- src/builder.h | 172 --------------------- src/buildparser.cpp | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/buildparser.h | 172 +++++++++++++++++++++ src/function.h | 2 +- src/main.cpp | 4 +- 8 files changed, 615 insertions(+), 616 deletions(-) delete mode 100644 src/builder.cpp delete mode 100644 src/builder.h create mode 100644 src/buildparser.cpp create mode 100644 src/buildparser.h (limited to 'src') diff --git a/src/build.l b/src/build.l index 3e95132..41abaf4 100644 --- a/src/build.l +++ b/src/build.l @@ -1,6 +1,6 @@ %{ # include -# include "builder.h" +# include "buildparser.h" # include "build.tab.h" # include "stringrep.h" @@ -116,7 +116,7 @@ std::string strbuf; %% -void Builder::scanBegin() +void BuildParser::scanBegin() { yy_flex_debug = false; if( !(yyin = fopen( file.c_str(), "r" )) ) @@ -125,7 +125,7 @@ void Builder::scanBegin() } } -void Builder::scanEnd() +void BuildParser::scanEnd() { fclose( yyin ); } diff --git a/src/build.y b/src/build.y index e9c0083..bb30d84 100644 --- a/src/build.y +++ b/src/build.y @@ -1,14 +1,14 @@ %defines %{ # include -# include "builder.h" +# include "buildparser.h" # include "build.tab.h" # include "action.h" -void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); +void yyerror( YYLTYPE *locp, BuildParser &bld, char const *msg ); %} -%parse-param { Builder &bld } -%lex-param { Builder &bld } +%parse-param { BuildParser &bld } +%lex-param { BuildParser &bld } %pure-parser %locations @@ -254,8 +254,7 @@ perfparams: ; %% -void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ) +void yyerror( YYLTYPE *locp, BuildParser &bld, char const *msg ) { bld.error( locp, msg ); } - diff --git a/src/builder.cpp b/src/builder.cpp deleted file mode 100644 index 1e916ab..0000000 --- a/src/builder.cpp +++ /dev/null @@ -1,432 +0,0 @@ -#include "builder.h" -#include "functionfactory.h" -#include "performfactory.h" -#include "targetfactory.h" -#include "action.h" -#include "build.h" -#include "rule.h" - -Builder::Builder() : - fFunction( FunctionFactory::getInstance() ), - fPerform( PerformFactory::getInstance() ), - fTarget( TargetFactory::getInstance() ) -{ -} - -Builder::~Builder() -{ -} - -void yyparse( Builder &bld ); -extern int yydebug; - -Build *Builder::load( const std::string &sFile ) -{ - file = sFile; - scanBegin(); - //yydebug = 1; - yyparse( *this ); - scanEnd(); - - return genBuild(); -} - -void Builder::error( YYLTYPE *locp, const char *msg ) -{ - fflush( stdout ); - throw BuildException("%s: %d.%d-%d.%d: %s", - file.c_str(), - locp->first_line, locp->first_column, - locp->last_line, locp->last_column, - msg ); -} - -void Builder::error( const std::string &msg ) -{ - fflush( stdout ); - throw BuildException("%s", msg.c_str() ); -} - -// -// Target functions -// -bool Builder::isTarget( const char *sType ) -{ - return fTarget.hasPlugin( sType ); -} - -void Builder::newTarget() -{ - lTargetTmp.push_back( TargetTmp(lTmp, TargetInfo()) ); -} - -void Builder::setTargetRule( const char *sRule ) -{ - lTargetTmp.back().second.sRule = sRule; -} - -void Builder::setTargetPrefix( const char *sPrefix ) -{ - lTargetTmp.back().second.sPrefix = sPrefix; -} - -void Builder::setTargetType( const char *sType ) -{ - lTargetTmp.back().second.sType = sType; -} - -void Builder::addTargetInput() -{ - lTargetTmp.back().second.lInput.insert( - lTargetTmp.back().second.lInput.end(), - lTmp.begin(), lTmp.end() - ); -} - -void Builder::addTargetRequires() -{ - lTargetTmp.back().second.lRequires.insert( - lTargetTmp.back().second.lRequires.end(), - lTmp.begin(), lTmp.end() - ); -} - -void Builder::addTargetSet( const char *sVar, const char *sVal, int nHow ) -{ - lTargetTmp.back().second.lVar.push_back( SetVar( sVar, sVal, nHow ) ); -} - -// -// Function functions -// -bool Builder::isFunction( const char *sFunc ) -{ - return fFunction.hasPlugin( sFunc ); -} - -void Builder::newFunctionCall( const char *sName ) -{ - pTmpFunc = fFunction.instantiate( sName ); -} - -void Builder::addFunctionParam( const char *sParam ) -{ - pTmpFunc->addParam( sParam ); -} - -// -// List functions -// -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 ) ); -} - -void Builder::filterList() -{ - StringList lTmp2; - StringList lIn = buildToStringList( lTmp, StringList() ); - pTmpFunc->execute( lIn, lTmp2 ); - lTmp.clear(); - for( StringList::iterator i = lTmp2.begin(); i != lTmp2.end(); i++ ) - { - lTmp.push_back( BuildListItem( *i, NULL ) ); - } -} - -StringList Builder::buildToStringList( const BuildList &lSrc, const StringList &lIn ) -{ - StringList lOut; - - for( BuildList::const_iterator i = lSrc.begin(); i != lSrc.end(); i++ ) - { - if( (*i).second ) - { - (*i).second->execute( lIn, lOut ); - } - else - { - lOut.push_back( (*i).first ); - } - } - - return lOut; -} - -// -// Rule functions -// -void Builder::addRule( const char *sName ) -{ - lRuleTmp.push_back( RuleInfo() ); - lRuleTmp.back().sName = sName; -} - -void Builder::addRuleMatches() -{ - lRuleTmp.back().pMatches = pTmpFunc; -} - -void Builder::addRuleProduces() -{ - lRuleTmp.back().lProduces.insert( - lRuleTmp.back().lProduces.end(), - lTmp.begin(), lTmp.end() - ); -} - -void Builder::addRuleRequires() -{ - lRuleTmp.back().lRequires.insert( - lRuleTmp.back().lRequires.end(), - lTmp.begin(), lTmp.end() - ); -} - -void Builder::addRuleInputFilter() -{ - lRuleTmp.back().lFilter.push_back( pTmpFunc ); -} - -void Builder::addRulePerform() -{ - lRuleTmp.back().lPerform.push_back( pTmpPerform ); -} - -// -// Perform functions -// -bool Builder::isPerform( const char *sPerf ) -{ - return fPerform.hasPlugin( sPerf ); -} - -void Builder::newPerform( const char *sName ) -{ - pTmpPerform = fPerform.instantiate( sName ); -} - -void Builder::addPerformParam( const char *sParam ) -{ - pTmpPerform->addParam( 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 ) ); -} - -// -// Global variable functions -// -void Builder::addGlobalSet( const char *sVar, const char *sValue, int nHow ) -{ - lGlobalVars.push_back( SetVar( sVar, sValue, nHow ) ); -} - -// -// 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 ); - printBuildList( (*j).second ); - printf("\n"); - } - } - - printf("\nTargets:\n"); - for( TargetTmpList::iterator i = lTargetTmp.begin(); - i != lTargetTmp.end(); i++ ) - { - printf(" "); - printBuildList( (*i).first ); - printf(":\n"); - - printf(" Rule: %s\n", (*i).second.sRule.c_str() ); - printf(" Prefix: %s\n", (*i).second.sPrefix.c_str() ); - printf(" Type: %s\n", (*i).second.sType.c_str() ); - printf(" Input: "); - printBuildList( (*i).second.lInput ); - printf("\n Requires: "); - printBuildList( (*i).second.lRequires ); - printf("\n Vars:\n"); - - for( SetVarList::iterator j = (*i).second.lVar.begin(); - j != (*i).second.lVar.end(); j++ ) - { - char *op; - switch( (*j).third ) - { - case setSet: op = "="; break; - case setAdd: op = "+="; break; - } - printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() ); - } - } - - printf("\nGlobals:\n"); - for( SetVarList::iterator j = lGlobalVars.begin(); - j != lGlobalVars.end(); j++ ) - { - char *op; - switch( (*j).third ) - { - case setSet: op = "="; break; - case setAdd: op = "+="; break; - } - printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() ); - } - - printf("\nRules:\n"); - for( RuleTmpList::iterator i = lRuleTmp.begin(); - i != lRuleTmp.end(); i++ ) - { - printf(" %s:\n", (*i).sName.c_str() ); - printf(" Matches: func()\n"); - printf(" Produces: "); - printBuildList( (*i).lProduces ); - printf("\n Requires: "); - printBuildList( (*i).lRequires ); - printf("\n Filters: %d\n", (*i).lFilter.size() ); - printf(" Performs: %d\n", (*i).lPerform.size() ); - } -} - -void Builder::printBuildList( const BuildList &lst ) -{ - printf("["); - for( BuildList::const_iterator k = lst.begin(); - k != lst.end(); k++ ) - { - if( k != lst.begin() ) - { - printf(", "); - } - if( (*k).second ) - { - printf("func()"); - } - else - { - printf("\"%s\"", (*k).first.c_str() ); - } - } - printf("]"); -} - -// -// Actually make a build object -// -Build *Builder::genBuild() -{ - Build *bld = new Build; - - for( SetVarList::iterator i = lGlobalVars.begin(); - i != lGlobalVars.end(); i++ ) - { - switch( (*i).third ) - { - case setSet: - bld->set( "", (*i).first, (*i).second ); - break; - - case setAdd: - bld->setAdd( "", (*i).first, (*i).second ); - break; - } - } - - for( TargetTmpList::iterator i = lTargetTmp.begin(); - i != lTargetTmp.end(); i++ ) - { - StringList lTargetNames = buildToStringList( - (*i).first, StringList() - ); - for( StringList::iterator j = lTargetNames.begin(); - j != lTargetNames.end(); j++ ) - { - if( (*i).second.sType != "" ) - { - Target *pTarget = fTarget.instantiate( - (*i).second.sType.c_str() - ); - pTarget->setName( *j ); - pTarget->setRule( (*i).second.sRule ); - - StringList lInputs = buildToStringList( - (*i).second.lInput, StringList() - ); - pTarget->getInput().insert( - pTarget->getInput().end(), - lInputs.begin(), lInputs.end() - ); - - bld->addTarget( pTarget ); - } - StringList lReqs = buildToStringList( - (*i).second.lRequires, StringList() - ); - for( StringList::iterator k = lReqs.begin(); - k != lReqs.end(); k++ ) - { - bld->addRequires( (*j), (*k) ); - } - for( SetVarList::iterator k = (*i).second.lVar.begin(); - k != (*i).second.lVar.end(); k++ ) - { - switch( (*k).third ) - { - case setSet: - bld->set( *j, (*k).first, (*k).second ); - break; - - case setAdd: - bld->setAdd( *j, (*k).first, (*k).second ); - break; - } - } - } - } - - return bld; -} - diff --git a/src/builder.h b/src/builder.h deleted file mode 100644 index 367769f..0000000 --- a/src/builder.h +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef BUILDER_H -#define BUILDER_H - -#include -#include -#include -#include -#include "build.tab.h" - -class Build; -class Builder; -class Function; -class FunctionFactory; -class Perform; -class PerformFactory; -class Target; -class TargetFactory; - -#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) -YY_DECL; - -typedef std::list StringList; -typedef std::list FunctionList; -typedef std::list PerformList; - -template -class Triplet -{ -public: - Triplet( const tx &x, const ty &y, const tz &z ) : - first( x ), second( y ), third( z ) - {} - - Triplet( const Triplet &src ) : - first( src.first ), second( src.second ), third( src.third ) - {} - - tx first; - ty second; - tz third; -}; - -enum eSetHow -{ - setSet, - setAdd -}; - -class Builder -{ - typedef std::pair BuildListItem; - typedef std::list BuildList; - typedef Triplet SetVar; - typedef std::list SetVarList; -public: - Builder(); - virtual ~Builder(); - - void error( YYLTYPE *locp, const char *msg ); - void error( const std::string &msg ); - - Build *load( const std::string &sFile ); - -private: - std::string file; - void scanBegin(); - void scanEnd(); - - Build *genBuild(); - -public: // Target functions - bool isTarget( const char *sType ); - void newTarget(); - void setTargetRule( const char *sRule ); - void setTargetPrefix( const char *sPrefix ); - void setTargetType( const char *sType ); - void addTargetInput(); - void addTargetRequires(); - void addTargetSet( const char *sVar, const char *sVal, int nHow ); - -private: // Target variables - TargetFactory &fTarget; - class TargetInfo - { - public: - std::string sRule; - std::string sPrefix; - std::string sType; - BuildList lInput; - BuildList lRequires; - SetVarList lVar; - }; - typedef std::pair TargetTmp; - typedef std::list TargetTmpList; - TargetTmpList lTargetTmp; - -public: // Function functions - bool isFunction( const char *sFunc ); - void newFunctionCall( const char *sName ); - void addFunctionParam( const char *sParam ); - -private: // Function variables - Function *pTmpFunc; - FunctionFactory &fFunction; - -public: // Perform functions - bool isPerform( const char *sPerf ); - void newPerform( const char *sName ); - void addPerformParam( const char *sParam ); - -private: // Perform variables - Perform *pTmpPerform; - PerformFactory &fPerform; - -public: // List functions - void newList(); - void addListString( const char *str ); - void addListFunc(); - void filterList(); - - StringList buildToStringList( const BuildList &lSrc, const StringList &lIn ); - -private: // List variables - BuildList lTmp; - -public: // Rules functions - void addRule( const char *sName ); - void addRuleMatches(); - void addRuleProduces(); - void addRuleRequires(); - void addRuleInputFilter(); - void addRulePerform(); - -private: // Rule variables - class RuleInfo - { - public: - std::string sName; - Function *pMatches; - BuildList lProduces; - BuildList lRequires; - FunctionList lFilter; - PerformList lPerform; - }; - - typedef std::list RuleTmpList; - RuleTmpList lRuleTmp; - -public: // Action functions - 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: // Global variable functions - void addGlobalSet( const char *sVar, const char *sValue, int nHow ); - -private: // Global variable variables - SetVarList lGlobalVars; - -public: // Debug - void debugDump(); - void printBuildList( const BuildList &lst ); -}; - -#endif diff --git a/src/buildparser.cpp b/src/buildparser.cpp new file mode 100644 index 0000000..cb285d4 --- /dev/null +++ b/src/buildparser.cpp @@ -0,0 +1,432 @@ +#include "buildparser.h" +#include "functionfactory.h" +#include "performfactory.h" +#include "targetfactory.h" +#include "action.h" +#include "build.h" +#include "rule.h" + +BuildParser::BuildParser() : + fFunction( FunctionFactory::getInstance() ), + fPerform( PerformFactory::getInstance() ), + fTarget( TargetFactory::getInstance() ) +{ +} + +BuildParser::~BuildParser() +{ +} + +void yyparse( BuildParser &bld ); +extern int yydebug; + +Build *BuildParser::load( const std::string &sFile ) +{ + file = sFile; + scanBegin(); + //yydebug = 1; + yyparse( *this ); + scanEnd(); + + return genBuild(); +} + +void BuildParser::error( YYLTYPE *locp, const char *msg ) +{ + fflush( stdout ); + throw BuildException("%s: %d.%d-%d.%d: %s", + file.c_str(), + locp->first_line, locp->first_column, + locp->last_line, locp->last_column, + msg ); +} + +void BuildParser::error( const std::string &msg ) +{ + fflush( stdout ); + throw BuildException("%s", msg.c_str() ); +} + +// +// Target functions +// +bool BuildParser::isTarget( const char *sType ) +{ + return fTarget.hasPlugin( sType ); +} + +void BuildParser::newTarget() +{ + lTargetTmp.push_back( TargetTmp(lTmp, TargetInfo()) ); +} + +void BuildParser::setTargetRule( const char *sRule ) +{ + lTargetTmp.back().second.sRule = sRule; +} + +void BuildParser::setTargetPrefix( const char *sPrefix ) +{ + lTargetTmp.back().second.sPrefix = sPrefix; +} + +void BuildParser::setTargetType( const char *sType ) +{ + lTargetTmp.back().second.sType = sType; +} + +void BuildParser::addTargetInput() +{ + lTargetTmp.back().second.lInput.insert( + lTargetTmp.back().second.lInput.end(), + lTmp.begin(), lTmp.end() + ); +} + +void BuildParser::addTargetRequires() +{ + lTargetTmp.back().second.lRequires.insert( + lTargetTmp.back().second.lRequires.end(), + lTmp.begin(), lTmp.end() + ); +} + +void BuildParser::addTargetSet( const char *sVar, const char *sVal, int nHow ) +{ + lTargetTmp.back().second.lVar.push_back( SetVar( sVar, sVal, nHow ) ); +} + +// +// Function functions +// +bool BuildParser::isFunction( const char *sFunc ) +{ + return fFunction.hasPlugin( sFunc ); +} + +void BuildParser::newFunctionCall( const char *sName ) +{ + pTmpFunc = fFunction.instantiate( sName ); +} + +void BuildParser::addFunctionParam( const char *sParam ) +{ + pTmpFunc->addParam( sParam ); +} + +// +// List functions +// +void BuildParser::newList() +{ + lTmp.clear(); +} + +void BuildParser::addListString( const char *str ) +{ + lTmp.push_back( BuildListItem(str, NULL) ); +} + +void BuildParser::addListFunc() +{ + lTmp.push_back( BuildListItem("", pTmpFunc ) ); +} + +void BuildParser::filterList() +{ + StringList lTmp2; + StringList lIn = buildToStringList( lTmp, StringList() ); + pTmpFunc->execute( lIn, lTmp2 ); + lTmp.clear(); + for( StringList::iterator i = lTmp2.begin(); i != lTmp2.end(); i++ ) + { + lTmp.push_back( BuildListItem( *i, NULL ) ); + } +} + +StringList BuildParser::buildToStringList( const BuildList &lSrc, const StringList &lIn ) +{ + StringList lOut; + + for( BuildList::const_iterator i = lSrc.begin(); i != lSrc.end(); i++ ) + { + if( (*i).second ) + { + (*i).second->execute( lIn, lOut ); + } + else + { + lOut.push_back( (*i).first ); + } + } + + return lOut; +} + +// +// Rule functions +// +void BuildParser::addRule( const char *sName ) +{ + lRuleTmp.push_back( RuleInfo() ); + lRuleTmp.back().sName = sName; +} + +void BuildParser::addRuleMatches() +{ + lRuleTmp.back().pMatches = pTmpFunc; +} + +void BuildParser::addRuleProduces() +{ + lRuleTmp.back().lProduces.insert( + lRuleTmp.back().lProduces.end(), + lTmp.begin(), lTmp.end() + ); +} + +void BuildParser::addRuleRequires() +{ + lRuleTmp.back().lRequires.insert( + lRuleTmp.back().lRequires.end(), + lTmp.begin(), lTmp.end() + ); +} + +void BuildParser::addRuleInputFilter() +{ + lRuleTmp.back().lFilter.push_back( pTmpFunc ); +} + +void BuildParser::addRulePerform() +{ + lRuleTmp.back().lPerform.push_back( pTmpPerform ); +} + +// +// Perform functions +// +bool BuildParser::isPerform( const char *sPerf ) +{ + return fPerform.hasPlugin( sPerf ); +} + +void BuildParser::newPerform( const char *sName ) +{ + pTmpPerform = fPerform.instantiate( sName ); +} + +void BuildParser::addPerformParam( const char *sParam ) +{ + pTmpPerform->addParam( sParam ); +} + +// +// Functions for dealing with actions +// +void BuildParser::addAction() +{ + lActions.push_back( ActionTmp("", ActionTmpCmdList()) ); +} + +void BuildParser::addAction( const char *sName ) +{ + lActions.push_back( ActionTmp(sName, ActionTmpCmdList()) ); +} + +void BuildParser::addCommand( int nType ) +{ + lActions.back().second.push_back( ActionTmpCmd( nType, lTmp ) ); +} + +// +// Global variable functions +// +void BuildParser::addGlobalSet( const char *sVar, const char *sValue, int nHow ) +{ + lGlobalVars.push_back( SetVar( sVar, sValue, nHow ) ); +} + +// +// Debug +// +void BuildParser::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 ); + printBuildList( (*j).second ); + printf("\n"); + } + } + + printf("\nTargets:\n"); + for( TargetTmpList::iterator i = lTargetTmp.begin(); + i != lTargetTmp.end(); i++ ) + { + printf(" "); + printBuildList( (*i).first ); + printf(":\n"); + + printf(" Rule: %s\n", (*i).second.sRule.c_str() ); + printf(" Prefix: %s\n", (*i).second.sPrefix.c_str() ); + printf(" Type: %s\n", (*i).second.sType.c_str() ); + printf(" Input: "); + printBuildList( (*i).second.lInput ); + printf("\n Requires: "); + printBuildList( (*i).second.lRequires ); + printf("\n Vars:\n"); + + for( SetVarList::iterator j = (*i).second.lVar.begin(); + j != (*i).second.lVar.end(); j++ ) + { + char *op; + switch( (*j).third ) + { + case setSet: op = "="; break; + case setAdd: op = "+="; break; + } + printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() ); + } + } + + printf("\nGlobals:\n"); + for( SetVarList::iterator j = lGlobalVars.begin(); + j != lGlobalVars.end(); j++ ) + { + char *op; + switch( (*j).third ) + { + case setSet: op = "="; break; + case setAdd: op = "+="; break; + } + printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() ); + } + + printf("\nRules:\n"); + for( RuleTmpList::iterator i = lRuleTmp.begin(); + i != lRuleTmp.end(); i++ ) + { + printf(" %s:\n", (*i).sName.c_str() ); + printf(" Matches: func()\n"); + printf(" Produces: "); + printBuildList( (*i).lProduces ); + printf("\n Requires: "); + printBuildList( (*i).lRequires ); + printf("\n Filters: %d\n", (*i).lFilter.size() ); + printf(" Performs: %d\n", (*i).lPerform.size() ); + } +} + +void BuildParser::printBuildList( const BuildList &lst ) +{ + printf("["); + for( BuildList::const_iterator k = lst.begin(); + k != lst.end(); k++ ) + { + if( k != lst.begin() ) + { + printf(", "); + } + if( (*k).second ) + { + printf("func()"); + } + else + { + printf("\"%s\"", (*k).first.c_str() ); + } + } + printf("]"); +} + +// +// Actually make a build object +// +Build *BuildParser::genBuild() +{ + Build *bld = new Build; + + for( SetVarList::iterator i = lGlobalVars.begin(); + i != lGlobalVars.end(); i++ ) + { + switch( (*i).third ) + { + case setSet: + bld->set( "", (*i).first, (*i).second ); + break; + + case setAdd: + bld->setAdd( "", (*i).first, (*i).second ); + break; + } + } + + for( TargetTmpList::iterator i = lTargetTmp.begin(); + i != lTargetTmp.end(); i++ ) + { + StringList lTargetNames = buildToStringList( + (*i).first, StringList() + ); + for( StringList::iterator j = lTargetNames.begin(); + j != lTargetNames.end(); j++ ) + { + if( (*i).second.sType != "" ) + { + Target *pTarget = fTarget.instantiate( + (*i).second.sType.c_str() + ); + pTarget->setName( *j ); + pTarget->setRule( (*i).second.sRule ); + + StringList lInputs = buildToStringList( + (*i).second.lInput, StringList() + ); + pTarget->getInput().insert( + pTarget->getInput().end(), + lInputs.begin(), lInputs.end() + ); + + bld->addTarget( pTarget ); + } + StringList lReqs = buildToStringList( + (*i).second.lRequires, StringList() + ); + for( StringList::iterator k = lReqs.begin(); + k != lReqs.end(); k++ ) + { + bld->addRequires( (*j), (*k) ); + } + for( SetVarList::iterator k = (*i).second.lVar.begin(); + k != (*i).second.lVar.end(); k++ ) + { + switch( (*k).third ) + { + case setSet: + bld->set( *j, (*k).first, (*k).second ); + break; + + case setAdd: + bld->setAdd( *j, (*k).first, (*k).second ); + break; + } + } + } + } + + return bld; +} + diff --git a/src/buildparser.h b/src/buildparser.h new file mode 100644 index 0000000..642cc73 --- /dev/null +++ b/src/buildparser.h @@ -0,0 +1,172 @@ +#ifndef BUILDER_H +#define BUILDER_H + +#include +#include +#include +#include +#include "build.tab.h" + +class Build; +class BuildParser; +class Function; +class FunctionFactory; +class Perform; +class PerformFactory; +class Target; +class TargetFactory; + +#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, BuildParser &bld ) +YY_DECL; + +typedef std::list StringList; +typedef std::list FunctionList; +typedef std::list PerformList; + +template +class Triplet +{ +public: + Triplet( const tx &x, const ty &y, const tz &z ) : + first( x ), second( y ), third( z ) + {} + + Triplet( const Triplet &src ) : + first( src.first ), second( src.second ), third( src.third ) + {} + + tx first; + ty second; + tz third; +}; + +enum eSetHow +{ + setSet, + setAdd +}; + +class BuildParser +{ + typedef std::pair BuildListItem; + typedef std::list BuildList; + typedef Triplet SetVar; + typedef std::list SetVarList; +public: + BuildParser(); + virtual ~BuildParser(); + + void error( YYLTYPE *locp, const char *msg ); + void error( const std::string &msg ); + + Build *load( const std::string &sFile ); + +private: + std::string file; + void scanBegin(); + void scanEnd(); + + Build *genBuild(); + +public: // Target functions + bool isTarget( const char *sType ); + void newTarget(); + void setTargetRule( const char *sRule ); + void setTargetPrefix( const char *sPrefix ); + void setTargetType( const char *sType ); + void addTargetInput(); + void addTargetRequires(); + void addTargetSet( const char *sVar, const char *sVal, int nHow ); + +private: // Target variables + TargetFactory &fTarget; + class TargetInfo + { + public: + std::string sRule; + std::string sPrefix; + std::string sType; + BuildList lInput; + BuildList lRequires; + SetVarList lVar; + }; + typedef std::pair TargetTmp; + typedef std::list TargetTmpList; + TargetTmpList lTargetTmp; + +public: // Function functions + bool isFunction( const char *sFunc ); + void newFunctionCall( const char *sName ); + void addFunctionParam( const char *sParam ); + +private: // Function variables + Function *pTmpFunc; + FunctionFactory &fFunction; + +public: // Perform functions + bool isPerform( const char *sPerf ); + void newPerform( const char *sName ); + void addPerformParam( const char *sParam ); + +private: // Perform variables + Perform *pTmpPerform; + PerformFactory &fPerform; + +public: // List functions + void newList(); + void addListString( const char *str ); + void addListFunc(); + void filterList(); + + StringList buildToStringList( const BuildList &lSrc, const StringList &lIn ); + +private: // List variables + BuildList lTmp; + +public: // Rules functions + void addRule( const char *sName ); + void addRuleMatches(); + void addRuleProduces(); + void addRuleRequires(); + void addRuleInputFilter(); + void addRulePerform(); + +private: // Rule variables + class RuleInfo + { + public: + std::string sName; + Function *pMatches; + BuildList lProduces; + BuildList lRequires; + FunctionList lFilter; + PerformList lPerform; + }; + + typedef std::list RuleTmpList; + RuleTmpList lRuleTmp; + +public: // Action functions + 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: // Global variable functions + void addGlobalSet( const char *sVar, const char *sValue, int nHow ); + +private: // Global variable variables + SetVarList lGlobalVars; + +public: // Debug + void debugDump(); + void printBuildList( const BuildList &lst ); +}; + +#endif diff --git a/src/function.h b/src/function.h index 0e8f49e..73dcb01 100644 --- a/src/function.h +++ b/src/function.h @@ -2,7 +2,7 @@ #define FUNCTION_H #include -#include "builder.h" +#include "build.h" class Function { diff --git a/src/main.cpp b/src/main.cpp index be95f07..9dbf046 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "builder.h" +#include "buildparser.h" //#include "viewerplain.h" //#include "viewerpercent.h" //#include "viewermake.h" @@ -72,7 +72,7 @@ int main( int argc, char *argv[] ) Param prm; prm.process( argc, argv ); - Builder bld;//*prm.pViewer ); + BuildParser bld;//*prm.pViewer ); //bld.setCache( prm.sCache ); //try -- cgit v1.2.3