/* * Test driver to exercise sym.{h.c} standalone. */ #include "std-macros.h" #include "parse-tree.h" #include "sym.h" main() { SymtabEntry *TestEntry, *s; int t; InitSymtab(); /* Symbol Foo is defined both globaly and locally */ Enter(TestEntry = HashAllocSymtabEntry("Foo", C_Proc, NIL, 1)); TestLook("Foo", 1); /* Symbol Foo_Parent is defined only globally */ Enter(TestEntry = HashAllocSymtabEntry("Foo_Parent", C_Proc, NIL, 1)); TestEntry->Info.Proc.Parms = NIL; TestLook("Foo_Parent", 1); /* Define a new local scope */ NewLevel(TestEntry, 64, 0, null); /* Symbols Foo_Child1 and 2 are defined only locally */ Enter(TestEntry = HashAllocSymtabEntry("Foo_Child1", C_Proc, NIL, 2)); Enter(TestEntry = HashAllocSymtabEntry("Foo_Child2", C_Proc, NIL, 2)); TestLook("Foo_Child1", 2); TestLook("Foo_Child2", 2); /* Global symbol Foo is redefined locally */ t = Enter(TestEntry = HashAllocSymtabEntry("Foo", C_Proc, NIL, 2)); printf ("Return val from Enter, should be 0: %d\n", t); TestLook("Foo", 2); /* Do some additional test lookups */ TestLook("Foo_Parent", 1); TestLook(CurSymtab->ParentEntry->Symbol, 1); printf("Should be NILSYM: %s\n", LookupString("x") == NILSYM ? "NILSYM" : "ERROR"); /* Check that Enter now returns 1 */ t = Enter(TestEntry = HashAllocSymtabEntry("Foo", C_Proc, NIL, 2)); printf ("Return val from Enter, should be 1: %d\n", t); /* * Run the generator, and run it again after reset. This should test that * a bucket is fully traversed, since "Foo" was entered twice (but enter it * thrice just for kicks). */ Enter(HashAllocSymtabEntry("Foo", C_Proc, NIL, 2)); printf("Generated entries are:\n"); for (s = NextEntry(); s; ) { printf(" %s\n", s->Symbol); s = NextEntry(); } printf("And again:\n"); ResetNext(); for (s = NextEntry(); s; s = NextEntry()) { printf(" %s\n", s->Symbol); } /* * Run the generator 1 more time, now on the level 0 symtab. */ CurSymtab = CurSymtab->ParentTab; printf("And more time, now on level 0:\n"); ResetNext(); for (s = NextEntry(); s; s = NextEntry()) { printf(" %s\n", s->Symbol); } } TestLook(Symbol, Level) char *Symbol; int Level; { printf("Should be %s at level %d: %s at level %d\n", Symbol, Level, LookupString(Symbol)->Symbol, LookupString(Symbol)->Level); } /* * Stubs to avoid having to link the whole world (just about). */ InstallBuiltInSyms() {} NumLexInFiles() {return 0;}