static void CreateDepFile (const char* Name, InputType Types) /* Create a dependency file with the given name and place dependencies for * all files with the given types there. */ { /* Open the file */ FILE* F = fopen (Name, "w"); if (F == 0) { Fatal ("Cannot open dependency file `%s': %s", Name, strerror (errno)); } /* If a dependency target was given, use it, otherwise use the output * file name as target, followed by a tab character. */ if (SB_IsEmpty (&DepTarget)) { WriteEscaped (F, OutputFilename); } else { WriteEscaped (F, SB_GetConstBuf (&DepTarget)); } fputs (":\t", F); /* Write out the dependencies for the output file */ WriteDep (F, Types); fputs ("\n\n", F); /* Write out a phony dependency for the included files */ WriteDep (F, Types); fputs (":\n\n", F); /* Close the file, check for errors */ if (fclose (F) != 0) { remove (Name); Fatal ("Cannot write to dependeny file (disk full?)"); } }
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; }
SymTable* ParseScopedSymTable (void) /* Parse a (possibly scoped) symbol table (scope) name, search for it in the * symbol space and return the symbol table struct. */ { StrBuf ScopeName = STATIC_STRBUF_INITIALIZER; StrBuf Name = STATIC_STRBUF_INITIALIZER; int NoScope; /* Parse the scoped symbol name */ SymTable* Scope = ParseScopedIdent (&Name, &ScopeName); /* If ScopeName is empty, no scope was specified */ NoScope = SB_IsEmpty (&ScopeName); /* We don't need FullName any longer */ SB_Done (&ScopeName); /* If we got no error, search for the child scope withint the enclosing one. * Beware: If no explicit parent scope was specified, search in all upper * levels. */ if (Scope) { /* Search for the last scope */ if (NoScope) { Scope = SymFindAnyScope (Scope, &Name); } else { Scope = SymFindScope (Scope, &Name, SYM_FIND_EXISTING); } } /* Free memory for name */ SB_Done (&Name); /* Return the scope found */ return Scope; }