16 #ifndef __CPUI_GRAMMAR__
17 #define __CPUI_GRAMMAR__
55 void set(uint4 tp,
char *ptr,int4 len);
56 void setPosition(int4 file,int4 line,int4 col) { filenum=file; lineno=line; colno=col; }
59 uint4 getType(
void)
const {
return type; }
60 uintb getInteger(
void)
const {
return value.integer; }
61 string *getString(
void)
const {
return value.stringval; }
62 int4 getLineNo(
void)
const {
return lineno; }
63 int4 getColNo(
void)
const {
return colno; }
64 int4 getFileNum(
void)
const {
return filenum; }
68 map<int4,string> filenamemap;
69 map<int4,istream *> streammap;
70 vector<int4> filestack;
98 uint4 moveState(
char lookahead);
100 void setError(
const string &err) { error = err; }
105 istream *getCurStream(
void) {
return in; }
106 void pushFile(
const string &filename,istream *i);
109 void writeLocation(ostream &s,int4 line,int4 filenum);
110 void writeTokenLocation(ostream &s,int4 line,int4 colno);
111 const string &getError(
void)
const {
return error; }
126 virtual uint4 getType(
void)
const=0;
127 virtual bool isValid(
void)
const=0;
135 virtual uint4 getType(
void)
const {
return pointer_mod; }
136 virtual bool isValid(
void)
const {
return true; }
144 ArrayModifier(uint4 fl,int4 as) { flags=fl; arraysize = as; }
145 virtual uint4 getType(
void)
const {
return array_mod; }
146 virtual bool isValid(
void)
const {
return (arraysize>0); }
151 vector<TypeDeclarator *> paramlist;
155 void getInTypes(vector<Datatype *> &intypes,
Architecture *glb)
const;
156 void getInNames(vector<string> &innames)
const;
157 bool isDotdotdot(
void)
const {
return dotdotdot; }
158 virtual uint4 getType(
void)
const {
return function_mod; }
159 virtual bool isValid(
void)
const;
165 vector<TypeModifier *> mods;
174 Datatype *getBaseType(
void)
const {
return basetype; }
175 int4 numModifiers(
void)
const {
return mods.
size(); }
176 const string &getIdentifier(
void)
const {
return ident; }
179 bool hasProperty(uint4 mask) {
return ((flags&mask)!=0); }
181 bool isValid(
void)
const;
186 string function_specifier;
193 bool constantassigned;
195 Enumerator(
const string &nm) { constantassigned =
false; enumconstant = nm; }
196 Enumerator(
const string &nm,uintb val) { constantassigned =
true; enumconstant=nm; value=val; }
217 doc_parameter_declaration
221 map<string,uint4> keywords;
223 int4 lineno,colno,filenum;
224 list<TypeDeclarator *> typedec_alloc;
225 list<TypeSpecifiers *> typespec_alloc;
226 list<vector<uint4> *> vecuint4_alloc;
227 list<vector<TypeDeclarator *> *> vecdec_alloc;
228 list<string *> string_alloc;
229 list<uintb *> num_alloc;
230 list<Enumerator *> enum_alloc;
231 list<vector<Enumerator *> *> vecenum_alloc;
233 vector<TypeDeclarator *> *lastdecls;
236 void setError(
const string &msg);
237 int4 lookupIdentifier(
const string &nm);
238 bool runParse(uint4 doctype);
244 vector<TypeDeclarator *> *mergeSpecDecVec(
TypeSpecifiers *spec,vector<TypeDeclarator *> *declist);
254 vector<TypeDeclarator *> *newVecDeclarator(
void);
255 vector<uint4> *newPointer(
void);
258 Datatype *newStruct(
const string &ident,vector<TypeDeclarator *> *declist);
259 Datatype *oldStruct(
const string &ident);
260 Datatype *newUnion(
const string &ident,vector<TypeDeclarator *> *declist);
261 Datatype *oldUnion(
const string &ident);
262 Enumerator *newEnumerator(
const string &ident);
263 Enumerator *newEnumerator(
const string &ident,uintb val);
264 vector<Enumerator *> *newVecEnumerator(
void);
265 Datatype *newEnum(
const string &ident,vector<Enumerator *> *vecenum);
266 Datatype *oldEnum(
const string &ident);
267 uint4 convertFlag(
string *str);
269 void clearAllocation(
void);
272 bool parseFile(
const string &filename,uint4 doctype);
273 bool parseStream(istream &s,uint4 doctype);
275 const string &getError(
void)
const {
return lasterror; }
276 void setResultDeclarations(vector<TypeDeclarator *> *val) { lastdecls = val; }
277 vector<TypeDeclarator *> *getResultDeclarations(
void) {
return lastdecls; }
286 extern void parse_toseparator(istream &s,
string &name);
287 extern Address parse_machaddr(istream &s,int4 &defaultsize,
const TypeFactory &typegrp,
bool ignorecolon=
false);