Mercurial > hg > CbC > old > device
changeset 176:3a7b45f62c66
enum
author | kono |
---|---|
date | Fri, 28 Nov 2003 13:58:39 +0900 |
parents | f4dcfb3e2c2c |
children | 352feeae4b0a |
files | Makefile mc-parse.c mc.h |
diffstat | 3 files changed, 40 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Wed Nov 26 22:08:44 2003 +0900 +++ b/Makefile Fri Nov 28 13:58:39 2003 +0900 @@ -62,6 +62,7 @@ make check TARGET=test/tmp7 # make check TARGET=test/tmp8 make check TARGET=test/tmp9 + make check TARGET=test/enum #MK =-make MK= check-all-code:
--- a/mc-parse.c Wed Nov 26 22:08:44 2003 +0900 +++ b/mc-parse.c Fri Nov 28 13:58:39 2003 +0900 @@ -49,7 +49,7 @@ static int postequ(int s1, int s2); static int rvalue(int e); static int sdecl(int s); -static int edecl(int s); +static int edecl(); static int skipspc(void); static int strop(int e); static int typeid(int s); @@ -484,7 +484,7 @@ getsym(); break; case ENUM: - t=edecl(sym); + t=edecl(); break; case STRUCT: case UNION: @@ -748,6 +748,7 @@ if(t==DOUBLE) return size_of_double; if(t==LONGLONG) return size_of_longlong; if(t==ULONGLONG) return size_of_longlong; + if(t==ENUM) return size_of_int; error(DCERR); } if(car(t)==STRUCT||car(t)==UNION) { @@ -1178,17 +1179,37 @@ } static int -edecl(int s) +edecl() { - int smode; + int smode=mode; + int sdisp=disp; + NMTBL *nptr0; smode=mode; + if (mode==GDECL || mode==GEDECL) + mode=GEDECL; + else + mode=LEDECL; if (getsym() == IDENT) { - if (getsym() == LC) { - } else { + nptr->sc = TAG; + getsym(); + } + if(sym==LC) { + while (getsym() == IDENT) { + nptr->sc = ENUM; + nptr->ty = INT; + nptr0 = nptr; + if (getsym() == ASS) { + getsym(); + disp = cexpr(expr1()); + } + nptr0->dsp = disp; + if (sym!=COMMA) break; + disp++; } - } else if(sym==LC) { + checksym(RC); } - else error(DCERR); + type = ENUM; + disp=sdisp; mode=smode; return type; } @@ -1384,7 +1405,7 @@ int integral(int t) { - return(t==INT||t==CHAR||t==UNSIGNED||t==UCHAR||t==SHORT||t==USHORT); + return(t==INT||t==CHAR||t==UNSIGNED||t==UCHAR||t==SHORT||t==USHORT||t==ENUM); } static void @@ -2426,6 +2447,11 @@ type=nptr->ty; getsym(); break; + case ENUM: + e1=list2(CONST,nptr->dsp); + type=INT; + getsym(); + break; case EMPTY: if(getsym()==LPAR) { nptr->sc = EXTRN1; @@ -3024,7 +3050,7 @@ typeid(int s) { return (integral(s) || s==CODE || s==SHORT || - s==LONG || s==STRUCT || s==UNION || + s==LONG || s==STRUCT || s==UNION || s==ENUM || s==LONGLONG || s==FLOAT || s==DOUBLE || (s==IDENT && nptr->sc==TYPE)); } @@ -3162,7 +3188,7 @@ gnptr=nptr=nptr0; if (mode==ADECL && nptr0->sc ==TYPE) return sym; if (mode==GDECL || mode==GSDECL || mode==GUDECL || - mode==GTDECL || mode==TOP) { + mode==GTDECL || mode==TOP || GEDECL) { return sym; } nptr1=lsearch(nptr0->nm);