SymEntry* ParseScopedSymName (SymFindAction Action) /* Parse a (possibly scoped) symbol name, search for it in the symbol table * and return the symbol table entry. */ { StrBuf ScopeName = STATIC_STRBUF_INITIALIZER; StrBuf Ident = STATIC_STRBUF_INITIALIZER; int NoScope; SymEntry* Sym; /* Parse the scoped symbol name */ SymTable* Scope = ParseScopedIdent (&Ident, &ScopeName); /* If ScopeName is empty, no scope was specified */ NoScope = SB_IsEmpty (&ScopeName); /* We don't need ScopeName any longer */ SB_Done (&ScopeName); /* Check if the scope is valid. Errors have already been diagnosed by * the routine, so just exit. */ if (Scope) { /* Search for the symbol and return it. If no scope was specified, * search also in the upper levels. */ if (NoScope && (Action & SYM_ALLOC_NEW) == 0) { Sym = SymFindAny (Scope, &Ident); } else { Sym = SymFind (Scope, &Ident, Action); } } else { /* No scope ==> no symbol. To avoid errors in the calling routine that * may not expect NULL to be returned if Action contains SYM_ALLOC_NEW, * create a new symbol. */ if (Action & SYM_ALLOC_NEW) { Sym = NewSymEntry (&Ident, SF_NONE); } else { Sym = 0; } } /* Deallocate memory for ident */ SB_Done (&Ident); /* Return the symbol found */ return Sym; }
void DbgInfoCheck (void) /* Do checks on all hll debug info symbols when assembly is complete */ { /* When parsing the debug statements for HLL symbols, we have already ** tagged the functions to their asm counterparts. This wasn't done for ** C symbols, since we will allow forward declarations. So we have to ** resolve the normal C symbols now. */ unsigned I; for (I = 0; I < CollCount (&HLLDbgSyms); ++I) { /* Get the next symbol */ HLLDbgSym* S = CollAtUnchecked (&HLLDbgSyms, I); /* Ignore functions and auto symbols, because the later live on the ** stack and don't have corresponding asm symbols. */ if (HLL_IS_FUNC (S->Flags) || HLL_GET_SC (S->Flags) == HLL_SC_AUTO) { continue; } /* Safety */ CHECK (S->Sym == 0 && S->Scope != 0); /* Search for the symbol name */ S->Sym = SymFindAny (S->Scope, GetStrBuf (S->AsmName)); if (S->Sym == 0) { PError (&S->Pos, "Assembler symbol '%s' not found", GetString (S->AsmName)); } else { /* Set the backlink */ S->Sym->HLLSym = S; } } }