#ifndef __Cname__ #define __Cname__ #include #include #include #include #include "symbol.h" #include "gc_cpp.h" //Garbage collector struct Cstar; struct gc_enum_id; #include "gc_stl.h" struct Cstar : public gc_cleanup { enum ConstAttr { DEFAULT,CONSTATTR }; ConstAttr const_attr; Cstar(enum ConstAttr x=DEFAULT) : const_attr(x) {} Cstar(Cstar &op) { const_attr=op.const_attr; } }; //The Cname class --keeps info about C names... e.g *(*(*a)[10])[100] // represents as (in LISPish) //(1,NULL,1,NULL,false,(1,NULL,1,NULL,false,(1,"a",0,NULL,false,NULL))) //Each symbol in the symbol table "carries" one struct Cname :public gc_cleanup { gc_Cstar_list *star_list; //The well known 'stars' bool constant; //true in case of e.g. char const a[] //where there are no 'stars' to carry //the 'const' info char name[80]; //if next==NULL then name else NULL gc_int_list *array_sizes; //the array sizes... int width; //optional width :-) gc_type_id_list *parameters; //parameters if function bool function; Cname *next; //pointer to deeper level ostream& Print(ostream&); friend ostream& operator<<(ostream& out,Cname &a); void RemoveArgs(bool all=false); void RemoveArgNames(void); bool ReplaceName(char *na); Cname(gc_Cstar_list *st,char *na,int wi,gc_int_list *ar,Cname *ne,bool cons); Cname(Cname &op); }; char *clean_Cname(Cname*ptr); //This one represents the full C type (without a symbolic name) //each symbol in the symbol table "carries" one! //For functions it represents the return type...(Simplicity!) :-) //For all the others the actual type struct Ctype : public gc_cleanup { enum Sign { SIGNED,UNSIGNED,DEFSIGN}; enum Modifier { SHORT,LONG,LONGLONG,DEFMOD }; enum DefStyle { STRUCTDEF,UNIONDEF,ENUMDEF,SIMPLEDEF,DEFTYPED }; enum DurationStyle { CONSTLIFE,VOLATILELIFE,DEFLIFE }; TypeEntry *type_attr; Sign sign_attr; Modifier mod_attr; DefStyle style_attr; DurationStyle duration_attr; Scope *scope; //This is only used when Ctype is a member of TypeEntry /* static char* MangleDefStyle(enum DefStyle s) { switch(s) { case STRUCTDEF: return "c"; case UNIONDEF: return "u"; case ENUMDEF: return "e"; case SIMPLEDEF: return "b"; case DEFTYPE: return "t"; default: assert(0==1); } return NULL; } static char* MangleSign(enum Sign s) { switch(s) { case SIGNED: return "d"; case UNSIGNED: return "g"; case DEFSIGN: return ""; default: assert(0==1); } return NULL; } static char* MangleModifier(enum Modifier m) { switch(m) { case SHORT: return "h"; case LONG: return "l"; case LONGLONG: return "ll"; case DEFMOD: return ""; default: assert(0==1); } return NULL; } // The mangling function for ctypes is: // Mangle the following of the ctype: // Modifier , Sign , DefStyle // And then mangle the TypeEntry (if any ) void Mangle(char *buf) { char type_mangle[255]; if(type_attr!=NULL) type_attr->Mangle(type_mangle); else type_mangle=""; sprintf(buf,"%s%s%s%s",MangleModifier(mod_attr),MangleSign(sign_attr) ,MangleDefStyle(style_attr),type_mangle); } */ static char* Duration2Str(DurationStyle s); static char* Modifier2Str(Modifier m); static char* Sign2Str(Sign s); static char* Style2Str(DefStyle st); friend ostream& operator<<(ostream& out,Ctype &a); Scope* GetScope(); bool IsSimple(); Ctype(TypeEntry *tt,Modifier m=DEFMOD,Sign s=DEFSIGN,DefStyle st=SIMPLEDEF,Scope *sc=NULL); Ctype(Ctype &op); void SetLife(DurationStyle s); }; struct gc_enum_id : public gc_cleanup { char name[80]; bool has_value; int value; gc_enum_id(); gc_enum_id(char*str); gc_enum_id(char*str,int val); void SetValue(int val); }; #endif