aboutsummaryrefslogtreecommitdiff
path: root/src/buildparser.h
blob: 2e1924cc4ad5ad7d568f235291ed5abf6e3e4d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef BUILDER_H
#define BUILDER_H

#include <stdint.h>
#include <string>
#include <list>
#include <utility>
#include "build.tab.h"
#include "parser.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<std::string> StringList;
typedef std::list<Function *> FunctionList;
typedef std::list<Perform *> PerformList;

template<class tx, class ty, class tz>
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 : public Parser
{
	typedef std::pair<std::string, Function *> BuildListItem;
	typedef std::list<BuildListItem> BuildList;
	typedef Triplet<std::string, std::string, int> SetVar;
	typedef std::list<SetVar> SetVarList;
public:
	BuildParser();
	virtual ~BuildParser();

	Build *load( const std::string &sFile );

private:
	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<BuildList,TargetInfo> TargetTmp;
	typedef std::list<TargetTmp> 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<RuleInfo> RuleTmpList;
	RuleTmpList lRuleTmp;

public: // Action functions
	void addAction();
	void addAction( const char *sName );
	void addCommand( int nType );

private: // Action variables
	typedef std::pair<int, BuildList> ActionTmpCmd;
	typedef std::list<ActionTmpCmd> ActionTmpCmdList;
	typedef std::pair<std::string, ActionTmpCmdList> ActionTmp;
	typedef std::list<ActionTmp> 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