static void enumdecl(int glob) { int v = 0; char name[NAMELEN+1]; Token = scan(); if (IDENT == Token) Token = scan(); lbrace(); while (RBRACE != Token) { copyname(name, Text); ident(); if (ASSIGN == Token) { Token = scan(); v = constexpr(); } if (glob) addglob(name, PINT, TCONSTANT, 0, 0, v++, NULL, 0); else addloc(name, PINT, TCONSTANT, 0, 0, v++, 0); if (Token != COMMA) break; Token = scan(); if (eofcheck()) return; }
newfunc () { char n[NAMESIZE], *ptr; fexitlab = getlabel(); if (!symname (n) ) { error ("illegal function or declaration"); kill (); return; } if (ptr = findglb (n)) { if (ptr[IDENT] != FUNCTION) multidef (n); else if (ptr[OFFSET] == FUNCTION) multidef (n); else ptr[OFFSET] = FUNCTION; } else addglb (n, FUNCTION, CINT, FUNCTION, PUBLIC); prologue (); if (!match ("(")) error ("missing open paren"); prefix (); outstr (n); col (); nl (); locptr = STARTLOC; argstk = 0; while (!match (")")) { if (symname (n)) { if (findloc (n)) multidef (n); else { addloc (n, 0, 0, argstk, AUTO); argstk = argstk + intsize(); } } else { error ("illegal argument name"); junk (); } blanks (); if (!streq (line + lptr, ")")) { if (!match (",")) error ("expected comma"); } if (endst ()) break; } stkp = 0; argtop = argstk; while (argstk) { if (amatch ("register", 8)) { if (amatch("char", 4)) getarg(CCHAR); else if (amatch ("int", 3)) getarg(CINT); else getarg(CINT); ns(); } else if (amatch ("char", 4)) { getarg (CCHAR); ns (); } else if (amatch ("int", 3)) { getarg (CINT); ns (); } else { error ("wrong number args"); break; } } statement(YES); printlabel(fexitlab); col(); nl(); modstk (0); gret (); stkp = 0; locptr = STARTLOC; }
SYMBOL * #endif dofnansi(SYMBOL *currfn, long *addr) { SYMBOL *prevarg; /* ptr to symbol table entry of most recent argument */ SYMBOL *argptr; /* Temporary holder.. */ TAG_SYMBOL *otag ; /* structure tag for structure argument */ struct varid var; char proto; locptr=STARTLOC; prevarg=0; Zsp=0; /* Reset stack pointer */ undeclared=1; proto=YES; swallow("__TD__"); /* kludge to get round typedef problem */ /* Master loop, checking for end of function */ while ( cmatch(')') == 0 ) { if (amatch("...") ) { /* * Found some ellipses, so, add it to the local symbol table and * then return..(after breaking, and checking for ; & , ) */ if (proto == 1 ) warning(W_ELLIP); needchar(')'); argptr=addloc("ellp",0,ELLIPSES,0,0); argptr->offset.p = prevarg; prevarg=argptr; break; } otag=GetVarID(&var,STATIK); if (var.type==STRUCT) { prevarg=getarg(STRUCT, otag,YES,prevarg,0, var.zfar,proto) ; } else if (var.type) { prevarg=getarg(var.type,NULL_TAG,YES,prevarg,var.sign,var.zfar,proto); } else { warning(W_EXPARG); break; } proto++; /* Now check for comma */ if (ch() !=')' && cmatch(',') == 0) { warning(W_EXPCOM); break; } } /* * Check for semicolon - I think this should be enough, just * have to have prototypes on separate lines - good practice * in anycase!! */ if (cmatch('@') ) { constexpr(addr,1); } if (cmatch(';') ) return (prevarg); setlocvar(prevarg,currfn); return (0); }
SYMBOL * #endif getarg( int typ , /* typ = CCHAR, CINT, DOUBLE or STRUCT */ TAG_SYMBOL *otag , /* structure tag for STRUCT type objects */ int deftype, /* YES=ANSI -> addloc NO=K&R -> findloc */ SYMBOL *prevarg, /* ptr to previous argument, only of use to ANSI */ char issigned, /* YES=unsigned NO=signed */ char zfar, /* FARPTR=far NO=near */ char proto) /* YES=prototyping -> names not needed */ { char n[NAMESIZE] ; SYMBOL *argptr ; int legalname, ident, more ; int brkflag; /* Needed to correctly break out for K&R*/ /* * This is of dubious need since prototyping came about, we could * inadvertently include fp packages if the user includes <math.h> but * didn't actually use them, we'll save the incfloat business for * static doubles and definitions of local doubles * * if (typ == DOUBLE) * incfloat=1; */ argptr = NULL; /* Only need while loop if K&R defs */ while ( undeclared) { ident = get_ident() ; more =0; if ( (legalname=symname(n)) == 0 ) { if (!proto) { illname(n); } else { /* * Obligatory silly fake name */ sprintf(n,"sg6p_%d",proto); legalname=1; } } if ( ident == FUNCTIONP ) { needtoken(")()"); /* function returning pointer needs dummy symbol */ more = dummy_idx(typ, otag) ; typ = (zfar ? CPTR : CINT ); } else if ( ident == PTR_TO_FN ) { needtoken(")()") ; ident = POINTER ; } if ( cmatch('[') ) { /* pointer ? */ ptrerror(ident) ; /* it is a pointer, so skip all */ /* stuff between "[]" */ while ( inbyte() != ']' ) if ( endst() ) break; /* add entry as pointer */ ident = (ident == POINTER) ? PTR_TO_PTR : POINTER ; } if ( legalname ) { /* * For ANSI we need to add symbol name to local table - this CINT is * temporary */ if (deftype) { argptr=addloc(n,0,CINT,0,0); argptr->offset.p = prevarg; } /* * If prototyping, then we can't find the name, but if we're prototyping * we have been defined as ANSI, therefore argptr already holds * the correct pointer - kinda neat! */ if ( proto || (argptr=findloc(n)) ) { argptr->flags=(zfar&FARPTR)|(issigned&UNSIGNED); /* add in details of the type of the name */ if ( ident == PTR_TO_PTR ) { /* djm mods will be here for long pointer */ // argptr->flags = UNSIGNED |FARPTR ; /*unsigned*/ argptr->ident = POINTER ; argptr->type = typ; // argptr->type = ( (zfar&FARPTR) ? CPTR : CINT ); argptr->more = dummy_idx(typ, otag) ; } else { argptr->more = more; argptr->ident = ident ; argptr->type = typ ; } } else warning(W_EXPARG); if ( otag ) { argptr->tag_idx = otag - tagtab ; argptr->ident = POINTER ; argptr->type = STRUCT ; } } brkflag=0; if (!deftype) { --undeclared; /* cnt down */ if ( endst() ) { brkflag=1; break; } if ( cmatch(',') == 0 ) warning(W_EXPCOM) ; } if (brkflag || deftype) break; } if (deftype) return(argptr); ns(); return(0); }
void DoFnKR( SYMBOL *currfn, char simple) { char n[NAMESIZE]; SYMBOL *prevarg; /* ptr to symbol table entry of most recent argument */ SYMBOL *cptr; TAG_SYMBOL *otag ; /* structure tag for structure argument */ struct varid var; prevarg=0; Zsp=0; /* Reset stack pointer */ undeclared=0; infunc=1; while ( !simple && cmatch(')') == 0 ) { /* then count args */ /* any legal name bumps arg count */ if ( symname(n) ) { /* add link to argument chain */ if ( (cptr=addloc(n,0,CINT,0,0)) ) cptr->offset.p = prevarg ; prevarg = cptr ; ++undeclared ; } else { error(E_ARGNAME); junk(); } blanks(); /* if not closing paren, should be comma */ if ( ch() != ')' && cmatch(',') == 0 ) { warning(W_EXPCOM); } if ( endst() ) break ; } Zsp = 0 ; /* preset stack ptr */ while ( undeclared ) { char regit=NO; if (amatch("register") ) regit=YES; /* Auto is be default in function defns, but someone might * try it on... */ if (amatch("auto") ) warning(W_AUTO); otag=GetVarID(&var,STATIK); if (var.type==STRUCT) { getarg(STRUCT, otag,NO,0,0, var.zfar,NO) ; } else if (var.type || regit) { if (regit && var.type == NO ) var.type=CINT; getarg(var.type,NULL_TAG,NO,0,var.sign,var.zfar,NO); } else { error(E_BADARG) ; break ; } } /* Have finished K&R parsing */ setlocvar(prevarg,currfn); }