aboutsummaryrefslogtreecommitdiff
path: root/src/buildparser.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-28 18:26:07 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-28 18:26:07 +0000
commitf7809b1a74da9a653b475b6fa499b078cad48c74 (patch)
tree612bed8a7e6303889f32e97ef984885841a8e819 /src/buildparser.h
parentd2fe7edb2bfea20987a1f69935179fa5fc9f3b37 (diff)
downloadbuild-f7809b1a74da9a653b475b6fa499b078cad48c74.tar.gz
build-f7809b1a74da9a653b475b6fa499b078cad48c74.tar.bz2
build-f7809b1a74da9a653b475b6fa499b078cad48c74.tar.xz
build-f7809b1a74da9a653b475b6fa499b078cad48c74.zip
Renamed Builder to BuildParser, soon I'll add the Parser base class and make
the whole thing official.
Diffstat (limited to 'src/buildparser.h')
-rw-r--r--src/buildparser.h172
1 files changed, 172 insertions, 0 deletions
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 @@
1#ifndef BUILDER_H
2#define BUILDER_H
3
4#include <stdint.h>
5#include <string>
6#include <list>
7#include <utility>
8#include "build.tab.h"
9
10class Build;
11class BuildParser;
12class Function;
13class FunctionFactory;
14class Perform;
15class PerformFactory;
16class Target;
17class TargetFactory;
18
19#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, BuildParser &bld )
20YY_DECL;
21
22typedef std::list<std::string> StringList;
23typedef std::list<Function *> FunctionList;
24typedef std::list<Perform *> PerformList;
25
26template<class tx, class ty, class tz>
27class Triplet
28{
29public:
30 Triplet( const tx &x, const ty &y, const tz &z ) :
31 first( x ), second( y ), third( z )
32 {}
33
34 Triplet( const Triplet &src ) :
35 first( src.first ), second( src.second ), third( src.third )
36 {}
37
38 tx first;
39 ty second;
40 tz third;
41};
42
43enum eSetHow
44{
45 setSet,
46 setAdd
47};
48
49class BuildParser
50{
51 typedef std::pair<std::string, Function *> BuildListItem;
52 typedef std::list<BuildListItem> BuildList;
53 typedef Triplet<std::string, std::string, int> SetVar;
54 typedef std::list<SetVar> SetVarList;
55public:
56 BuildParser();
57 virtual ~BuildParser();
58
59 void error( YYLTYPE *locp, const char *msg );
60 void error( const std::string &msg );
61
62 Build *load( const std::string &sFile );
63
64private:
65 std::string file;
66 void scanBegin();
67 void scanEnd();
68
69 Build *genBuild();
70
71public: // Target functions
72 bool isTarget( const char *sType );
73 void newTarget();
74 void setTargetRule( const char *sRule );
75 void setTargetPrefix( const char *sPrefix );
76 void setTargetType( const char *sType );
77 void addTargetInput();
78 void addTargetRequires();
79 void addTargetSet( const char *sVar, const char *sVal, int nHow );
80
81private: // Target variables
82 TargetFactory &fTarget;
83 class TargetInfo
84 {
85 public:
86 std::string sRule;
87 std::string sPrefix;
88 std::string sType;
89 BuildList lInput;
90 BuildList lRequires;
91 SetVarList lVar;
92 };
93 typedef std::pair<BuildList,TargetInfo> TargetTmp;
94 typedef std::list<TargetTmp> TargetTmpList;
95 TargetTmpList lTargetTmp;
96
97public: // Function functions
98 bool isFunction( const char *sFunc );
99 void newFunctionCall( const char *sName );
100 void addFunctionParam( const char *sParam );
101
102private: // Function variables
103 Function *pTmpFunc;
104 FunctionFactory &fFunction;
105
106public: // Perform functions
107 bool isPerform( const char *sPerf );
108 void newPerform( const char *sName );
109 void addPerformParam( const char *sParam );
110
111private: // Perform variables
112 Perform *pTmpPerform;
113 PerformFactory &fPerform;
114
115public: // List functions
116 void newList();
117 void addListString( const char *str );
118 void addListFunc();
119 void filterList();
120
121 StringList buildToStringList( const BuildList &lSrc, const StringList &lIn );
122
123private: // List variables
124 BuildList lTmp;
125
126public: // Rules functions
127 void addRule( const char *sName );
128 void addRuleMatches();
129 void addRuleProduces();
130 void addRuleRequires();
131 void addRuleInputFilter();
132 void addRulePerform();
133
134private: // Rule variables
135 class RuleInfo
136 {
137 public:
138 std::string sName;
139 Function *pMatches;
140 BuildList lProduces;
141 BuildList lRequires;
142 FunctionList lFilter;
143 PerformList lPerform;
144 };
145
146 typedef std::list<RuleInfo> RuleTmpList;
147 RuleTmpList lRuleTmp;
148
149public: // Action functions
150 void addAction();
151 void addAction( const char *sName );
152 void addCommand( int nType );
153
154private: // Action variables
155 typedef std::pair<int, BuildList> ActionTmpCmd;
156 typedef std::list<ActionTmpCmd> ActionTmpCmdList;
157 typedef std::pair<std::string, ActionTmpCmdList> ActionTmp;
158 typedef std::list<ActionTmp> ActionTmpList;
159 ActionTmpList lActions;
160
161public: // Global variable functions
162 void addGlobalSet( const char *sVar, const char *sValue, int nHow );
163
164private: // Global variable variables
165 SetVarList lGlobalVars;
166
167public: // Debug
168 void debugDump();
169 void printBuildList( const BuildList &lst );
170};
171
172#endif