/* * parse top level declarations */ long dodcls (long stclass, TAG_SYMBOL *mtag, int is_struct) { long err; struct type t; blanks(); if (match_type(&t, NO, YES)) { if (t.type == CSTRUCT && t.otag == -1) t.otag = define_struct(t.sname, stclass, !!(t.flags & F_STRUCT)); else if (t.type == CENUM) { if (t.otag == -1) t.otag = define_enum(t.sname, stclass); t.type = enum_types[t.otag].base; } err = declglb(t.type, stclass, mtag, t.otag, is_struct); } else if (stclass == PUBLIC) return (0); else err = declglb(CINT, stclass, mtag, NULL_TAG, is_struct); if (err == 2) /* function */ return (1); else if (err) { kill(); return (0); } else ns(); return (1); }
/** * parse top level declarations * @param stclass storage * @param mtag * @param is_struct * @return */ int do_declarations(int stclass, TAG_SYMBOL *mtag, int is_struct) { int type; int otag; // tag of struct object being declared int sflag; // TRUE for struct definition, zero for union char sname[NAMESIZE]; int ns = 0; blanks(); if ((sflag=amatch("struct", 6)) || amatch("union", 5)) { if (symname(sname) == 0) { // legal name ? illname(); } if ((otag=find_tag(sname)) == -1) { // structure not previously defined otag = define_struct(sname, stclass, sflag); } declare_global(STRUCT, stclass, mtag, otag, is_struct); } else if ((type = get_type()) != 1) { ns = declare_global(type, stclass, mtag, 0, is_struct); } else if (stclass == PUBLIC) { return (0); } else { ns = declare_global(CINT, stclass, mtag, 0, is_struct); } if (!ns) need_semicolon(); return (1); }
/** * local declarations * @param stclass * @return */ int do_local_declares(int stclass) { int type = 0; int otag; // tag of struct object being declared int sflag; // TRUE for struct definition, zero for union char sname[NAMESIZE]; blanks(); if ((sflag=amatch("struct", 6)) || amatch("union", 5)) { if (symname(sname) == 0) { // legal name ? illname(); } if ((otag=find_tag(sname)) == -1) { // structure not previously defined otag = define_struct(sname, stclass, sflag); } declare_local(STRUCT, stclass, otag); } else if ((type = get_type()) != 0) { declare_local(type, stclass, -1); } else if (stclass == LSTATIC || stclass == DEFAUTO) { declare_local(CINT, stclass, -1); } else { return(0); } need_semicolon(); return(1); }