void main () { int id, *XXX; char *YYY; void *ZZZ; struct { int a, b; } *AAA; Symbol s; fprintf (stderr, "#####\n"); id = NewSymTbl (7); s = AddSym (id, "aaa", 1); pr (s); s = FindSym (id, "aaa", 2); pr (s); s = AddSym (id, "bbb", 2); pr (s); s = FindSym (id, "bbb", 2); pr (s); s = AddSym (id, "ccc", 2); pr (s); s = AddSym (id, "ddd", 2); pr (s); s->ptr = XXX; s = AddSym (id, "ddd", 2); pr (s); s = AddSym (id, "eee", 2); pr (s); s = FindSym (id, "eee", 1); pr (s); s = AddSym (id, "fff", 2); pr (s); s->ptr = (Symbol) YYY; s = AddSym (id, "fff", 2); pr (s); s->ptr = (Symbol) ZZZ; s = AddSym (id, "fff", 2); pr (s); s->ptr = (Symbol) AAA; s = FindSym (id, "fff", 2); pr (s); s = AddSym (id, "ggg", 2); pr (s); s = AddSym (id, "hhh", 2); pr (s); fprintf (stderr, "#####\n"); }
static void AliasAttr (const Declaration* D, DeclAttr* A) /* Handle the "alias" attribute */ { SymEntry* Sym; /* Comma expected */ ConsumeComma (); /* The next identifier is the name of the alias symbol */ if (CurTok.Tok != TOK_IDENT) { Error ("Identifier expected"); return; } /* Lookup the symbol for this name, it must exist */ Sym = FindSym (CurTok.Ident); if (Sym == 0) { Error ("Unknown identifier: `%s'", CurTok.Ident); NextToken (); return; } /* Since we have the symbol entry now, skip the name */ NextToken (); /* Check if the types of the symbols are identical */ if (TypeCmp (D->Type, Sym->Type) < TC_EQUAL) { /* Types are not identical */ Error ("Incompatible types"); return; } /* Attribute is verified, set the stuff in the attribute description */ A->AttrType = atAlias; A->V.Sym = Sym; }
//========================================================================== // // // //========================================================================== int FParseContext::GetToken (char *&sourcep, FParseToken *yylval) { char token[80]; int toksize; int c; loop: while (isspace (c = *sourcep++) && c != 0) { if (c == '\n') SourceLine++; } if (c == 0) { return 0; } if (isdigit (c)) { int buildup = c - '0'; if (c == '0') { c = *sourcep++; if (c == 'x' || c == 'X') { yylval->val = (int)strtol(sourcep, &sourcep, 16); return TokenTrans[NUM]; } else { sourcep--; } } char *endp; sourcep--; yylval->val = (int)strtol(sourcep, &endp, 10); if (*endp == '.') { // It's a float yylval->fval = strtod(sourcep, &sourcep); return TokenTrans[FLOATVAL]; } else { sourcep = endp; return TokenTrans[NUM]; } } if (isalpha (c)) { int buildup = 0; token[0] = c; toksize = 1; while (toksize < 79 && (isalnum (c = *sourcep++) || c == '_')) { token[toksize++] = c; } token[toksize] = 0; if (toksize == 79 && isalnum (c)) { while (isalnum (c = *sourcep++)) ; } sourcep--; if (FindToken (token, &buildup)) { return buildup; } if (FindSym (token, &yylval->symval)) { yylval->val = yylval->symval->Value; return TokenTrans[NUM]; } if ((yylval->val = P_FindLineSpecial(token)) != 0) { return TokenTrans[NUM]; } strcpy (yylval->sym, token); return TokenTrans[SYM]; } if (c == '/') { c = *sourcep++; if (c == '*') { for (;;) { while ((c = *sourcep++) != '*' && c != 0) { if (c == '\n') SourceLine++; } if (c == 0) return 0; if ((c = *sourcep++) == '/') goto loop; if (c == 0) return 0; sourcep--; } } else if (c == '/') { while ((c = *sourcep++) != '\n' && c != 0) ; if (c == '\n') SourceLine++; else if (c == EOF) return 0; goto loop; } else { sourcep--; return TokenTrans[DIVIDE]; } } if (c == '"') { int tokensize = 0; while ((c = *sourcep++) != '"' && c != 0) { yylval->string[tokensize++] = c; } yylval->string[tokensize] = 0; return TokenTrans[STRING]; } if (c == '|') { c = *sourcep++; if (c == '=') return TokenTrans[OR_EQUAL]; sourcep--; return TokenTrans[OR]; } if (c == '<') { c = *sourcep++; if (c == '<') { c = *sourcep++; if (c == '=') { return TokenTrans[LSHASSIGN]; } sourcep--; return 0; } c--; return 0; } if (c == '>') { c = *sourcep++; if (c == '>') { c = *sourcep++; if (c == '=') { return TokenTrans[RSHASSIGN]; } sourcep--; return 0; } c--; return 0; } if (c == '#') { if (!strnicmp(sourcep, "include", 7)) { sourcep+=7; return TokenTrans[INCLUDE]; } if (!strnicmp(sourcep, "define", 6)) { sourcep+=6; return TokenTrans[DEFINE]; } } switch (c) { case '^': return TokenTrans[XOR]; case '&': return TokenTrans[AND]; case '-': return TokenTrans[MINUS]; case '+': return TokenTrans[PLUS]; case '*': return TokenTrans[MULTIPLY]; case '%': return TokenTrans[MODULUS]; case '(': return TokenTrans[LPAREN]; case ')': return TokenTrans[RPAREN]; case ',': return TokenTrans[COMMA]; case '{': return TokenTrans[LBRACE]; case '}': return TokenTrans[RBRACE]; case '=': return TokenTrans[EQUALS]; case ';': return TokenTrans[SEMICOLON]; case ':': return TokenTrans[COLON]; case '[': return TokenTrans[LBRACKET]; case ']': return TokenTrans[RBRACKET]; default: return 0; } }
static void WrappedCallPragma (StrBuf* B) /* Handle the wrapped-call pragma */ { StrBuf S = AUTO_STRBUF_INITIALIZER; const char *Name; long Val; SymEntry *Entry; /* Check for the "push" or "pop" keywords */ switch (ParsePushPop (B)) { case PP_NONE: Error ("Push or pop required"); break; case PP_PUSH: break; case PP_POP: PopWrappedCall(); /* Done */ goto ExitPoint; case PP_ERROR: /* Bail out */ goto ExitPoint; default: Internal ("Invalid result from ParsePushPop"); } /* A symbol argument must follow */ if (!SB_GetSym (B, &S, NULL)) { goto ExitPoint; } /* Skip the following comma */ if (!GetComma (B)) { /* Error already flagged by GetComma */ Error ("Value required for wrapped-call identifier"); goto ExitPoint; } if (!GetNumber (B, &Val)) { Error ("Value required for wrapped-call identifier"); goto ExitPoint; } if (Val < 0 || Val > 255) { Error ("Identifier must be between 0-255"); goto ExitPoint; } /* Get the string */ Name = SB_GetConstBuf (&S); Entry = FindSym(Name); /* Check if the name is valid */ if (Entry && Entry->Flags & SC_FUNC) { PushWrappedCall(Entry, (unsigned char) Val); Entry->Flags |= SC_REF; Entry->V.F.Func->Flags |= FD_CALL_WRAPPER; } else { /* Segment name is invalid */ Error ("Wrapped-call target does not exist or is not a function"); } ExitPoint: /* Call the string buf destructor */ SB_Done (&S); }