#include #include /* #include */ /*extern "C" char* index(char* s, char c);*/ /* supposed to be in */ #include "std-macros++.h" #include "parse-tree++.h" #include "sym++.h" #include "browser-hooks++.h" #include "strlist.h" #include "main++.h" extern "C" void translator(int argc, char *argv[]); void DumpBrowsingStuff(); void DumpCY(); main(int argc, char** argv) { translator(argc, argv); /* printf("Should be \"Main\": %s\n", LookupString("Main")->Symbol); DumpCY(); */ /* DumpBrowsingStuff(); */ } /* * For testing, make a sorted list of all browsable names and print it out * along with src loc info. */ void DumpBrowsingStuff() { SymtabEntry* e, *e1, *preve; StrList* l = new StrList; List* locs = new List; StrListElem* n; int i; char *s, *sp, s1[300], *s2, *s3; bool pp; /* {Symtab* st; SymtabEntry* sym; st = LookupStringIn("ControlYaw", Level0Symtab)->Info.Module.Symtab; sym = LookupStringIn("MakeManualVsAutoFlightModeDecision", st); printf("TESTING: %s\n", sym->Symbol); } */ MoveToBrowserSymtab(); pp = false; preve = NextEntry(); while (e = NextEntry()) { if (e->Symbol == preve->Symbol) { s = BuildDisambiguatedStr(preve); pp = true; } else if (pp) { s = BuildDisambiguatedStr(preve); pp = false; } else { s = preve->Symbol; } l->Put(new StrListElem(s, (void*) preve)); preve = e; } if (pp) s = BuildDisambiguatedStr(preve); else if (preve) s = preve->Symbol; l->Put(new StrListElem(s, preve)); l->Sort(); for (n = l->Enum(); n; n = l->Enum()) { s = n->GetData()->Convert(); /* * The grab-straight-from-the-list approach. */ e = (SymtabEntry*) n->GetAuxData(); if (e) { printf("Name: %s\n Line: %d\n Col: %d\n File: %s\n", s, e->Loc.line, e->Loc.col, e->Loc.file); } /* * The lookup-in-module approach. */ /* * Skip over " (in Module )" */ /* * The mother-f---ing index function is gone in Solaris, and there's no * suitable replacement that I can find. F--- Solaris hard. * * OK, I found it. But F--- Solaris anyway. */ if (strchr(s, ' ')) { strcpy(s1, s); s2 = strtok(s1, " "); /* 1st token = */ strtok(0, " "); /* 2nd token = "(in" */ strtok(0, " "); /* 3rd token = "Module" */ s3 = strtok(0, ")"); /* 4th token = */ e1 = LookupStringIn(s2, LookupStringIn(s3, Level0Symtab)->Info.Module.Symtab); } else { e1 = LookupString(s); } if (e1) { printf("Name: %s\n Line: %d\n Col: %d\n File: %s\n", s, e1->Loc.line, e1->Loc.col, e1->Loc.file); } } } char* BuildDisambiguatedStr(SymtabEntry* e) { SymtabEntry* parentSym; /* return strcpy(malloc(strlen(e->Symbol) + 1), e->Symbol); */ switch (e->Class) { case C_Obj: parentSym = e->Info.Obj.parent; break; case C_Op: parentSym = e->Info.Op.parent; break; } char* s = new char[strlen(e->Symbol) + strlen(parentSym->Symbol) + strlen(" (in Module )") + 1]; sprintf(s, "%s (in Module %s)%c", e->Symbol, parentSym->Symbol, '\0'); return s; } /* TESTING void DumpCY() { Symtab* st; SymtabEntry* sym; st = LookupStringIn("ControlYaw", Level0Symtab)->Info.Module.Symtab; PushSymtab(); MoveToSymtab(st); for (sym = NextEntry(); sym; sym = NextEntry()) { printf("Next ControlYaw sym = %s\n", sym->Symbol); } PopSymtab(); } */