forked from dbunker/SABR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arch.h
189 lines (153 loc) · 5.38 KB
/
arch.h
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*************************************************************************
@copyright Copyright (c) 2011 David Bunker
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*************************************************************************/
// this file stores AST structure information
#ifndef ARCH_H
#define ARCH_H
#include "../utils/linkedlist.h"
// for unnamed DesObj, Req, etc. name invention
int inventNameNum;
// indicates if the end of file has been reached
int endFile;
// the symbol table produced by lex
linkedList symTable;
// the user gives the number of stages they are willing to test up to
int numStages;
// potential command line argument
#define COMMAND_NONE 0 // prog.tbl =compile=> dimin.in =cnf=> dimout.out =postproc=> result.out
#define COMMAND_INITIAL 1 // prog.tbl =compile=> dimin.in
#define COMMAND_DEBUG 2 // prog.tbl =compile=> debug.out
#define COMMAND_RESULT 3 // prog.tbl =compile=> =nothing=> dimout.out =postproc=> result.out
#define COMMAND_ALL 4 // prog.tbl =compile=> debug.out, dimin.in =cnf=> dimout.out =postproc=> result.out
int command;
// line number
int curLineNum;
// each corresponds to a node type
typedef enum { rootType, symType, boardType, startType, endType, transType, transSimType,
tempSetType, objType, desObjType, reqType, optType,
charType, manyType, elabType } nodeType;
// all nodes on the tree
// data is rootData (root), setData (board,start,end), nameData (obj,desobj,opt,req), or transData (trans,transsim)
// spaces is a linkedList of int* indicating number of . after each board cell
// stages is for elab (trans,req,opt) to indicate stages they are valid
typedef struct {
nodeType type;
void *data;
void *spaces;
void *stages;
} treeNode;
// when generating cells in linkedlist, an endline
// is represented by this (NULL cannot be stored in list)
#define ENDLINE ((void*)(-1))
typedef struct {
linkedList symbols;
int nameId;
} symListInfo;
// this is if an elab
// exists for specific stages, not all stages
typedef struct {
int start;
int end;
} nodeStages;
// the one root node
typedef struct {
// contains list of symListInfo
linkedList symLists;
treeNode *boardNode;
treeNode *startNode;
treeNode *endNode;
// contain treeNodes
linkedList objNodes;
linkedList desObjNodes;
linkedList transNodes;
linkedList reqNodes;
linkedList optNodes;
} rootData;
typedef struct {
linkedList symList;
int symListName;
int cellName;
// this is for determining placement of . in output
int numSpaceBef;
} cellData;
typedef struct {
// this is the stand alone portion (i.e. tempVarName:(negVars and posVars))
int tempVarName;
// this indicates it is any (?)
int isAny;
// contains int* which refer to values in the symlist in the
// corresponding DesObj manyData (or perhaps a tempVar)
// these lists can be set to NULL
linkedList negVars;
linkedList posVars;
} elabData;
typedef struct {
// contains symList associated with this DesObj cell
linkedList symList;
// contains board cells names (int*)
linkedList brackVars;
} manyData;
// this is the 2 dimensional set indexed by [y*width + x]
// this is the only part of sym, board, start, end
// for extra values, these are 0s at end of each line
// type can be:
// charType setVars is (int**) the single variable
// manyType setVars is (manyData**) the list of variables in the brackets
// elabType setVars is (elabData**) list of negative and positive variables in parens
// and name of temporary variable
// boardType setVars is (cellData**) list of board cells or obj cells and their associated symlist by name
typedef struct {
int height;
int width;
void *setVars;
} setData;
// obj desObj req desReq have more info than just the set
typedef struct {
int nameId;
int objId;
// used if it is an opt and so part of an opt group
int elabNum;
setData *set;
} nameData;
// as the set is being built it is stored in here
// set contains int* of text found
typedef struct {
int numLines;
int maxWidth;
int curWidth;
linkedList set;
} startSetData;
// transform
typedef struct {
int transId;
int objId;
setData *startData;
setData *endData;
} transData;
int initSym();
int addSymbol(char*);
void yyerror(char*);
void *Malloc(size_t);
void Free(void*);
void execute(treeNode*);
treeNode *symNode(treeNode *newSymList,treeNode *symLists);
treeNode *statementNodes(treeNode *symbols,treeNode *board,treeNode *start,treeNode *end,treeNode *root);
treeNode *setStages(int varId1,int varId2);
treeNode *choiceNode(int tok,treeNode *choice,treeNode *root);
treeNode *storeNode(int tok,treeNode *set);
treeNode *nameNode(int tok,treeNode *stagesNode,int nameId,int objId,treeNode *set);
treeNode *transNode(int type,treeNode *stagesNode,int transId,int objId,treeNode *startSet,treeNode *endSet);
treeNode *setNode(int tok,treeNode *var,treeNode *set);
treeNode *setCommaNode(int tok,int varId,treeNode *varList);
treeNode *setVarNode(int tok,int varId,treeNode *varList);
treeNode *setBoardVarNode(int tok,int varId,int sym);
#endif