#include "lclintMacros.nf"#include "llbasic.h"#include "gram.h"#include "lclscan.h"#include "lclsyntable.h"#include "lslparse.h"Go to the source code of this file.
Compounds | |
| struct | _idTable |
| struct | _symtableStruct |
| struct | idTableEntry |
Defines | |
| #define | MAXBUFFLEN 512 |
| #define | DELTA 100 |
Typedefs | |
| typedef struct _idTable | idTable |
| typedef fctInfo | o_fctInfo |
Enumerations | |
| enum | symKind { SYMK_FCN, SYMK_SCOPE, SYMK_TYPE, SYMK_VAR } |
Functions | |
| void | varInfo_free ( varInfo v) |
| void | symtable_free (symtable stable) |
| symtable | symtable_new (void) |
| void | symtable_enterOp (symtable st, nameNode n, sigNode oi) |
| bool | symtable_enterTag (symtable st, tagInfo ti) |
| bool | symtable_enterTagForce (symtable st, tagInfo ti) |
| opInfo | symtable_opInfo (symtable st, nameNode n) |
| tagInfo | symtable_tagInfo (symtable st, lsymbol i) |
| void | symtable_enterScope (symtable stable, scopeInfo si) |
| void | symtable_exitScope (symtable stable) |
| bool | symtable_enterFct (symtable stable, fctInfo fi) |
| void | symtable_enterType (symtable stable, typeInfo ti) |
| lsymbol | lsymbol_sortFromType (symtable s, lsymbol typename) |
| bool | symtable_enterVar (symtable stable, varInfo vi) |
| bool | symtable_exists (symtable stable, lsymbol i) |
| typeInfo | symtable_typeInfo (symtable stable, lsymbol i) |
| varInfo | symtable_varInfo (symtable stable, lsymbol i) |
| varInfo | symtable_varInfoInScope (symtable stable, lsymbol id) |
| void | symtable_export (symtable stable, bool yesNo) |
| void | symtable_dump (symtable stable, FILE * f, bool lco) |
| lsymbol | lsymbol_translateSort (mapping * m, lsymbol s) |
| void | symtable_import (tsource *imported, ltoken tok, mapping * map) |
| void | symtable_printStats (symtable s) |
| cstring | tagKind_unparse (tagKind k) |
| sigNodeSet | symtable_possibleOps (symtable tab, nameNode n) |
| bool | symtable_opExistsWithArity (symtable tab, nameNode n, int arity) |
| lslOpSet | symtable_opsWithLegalDomain (symtable tab, nameNode n, sortSetList argSorts, sort qual) |
|
|
Definition at line 58 of file symtable.c. |
|
|
Definition at line 56 of file symtable.c. |
|
|
|
|
|
Definition at line 958 of file symtable.c. |
|
|
Definition at line 68 of file symtable.c. 00069 {
00070 SYMK_FCN, SYMK_SCOPE, SYMK_TYPE, SYMK_VAR
00071 }
|
|
|
Definition at line 565 of file symtable.c. Referenced by processTraitSortId(). 00566 {
00567 lsymbol inter;
00568 lsymbol out;
00569 ltoken tok;
00570 /* check the synonym table first */
00571 if (LCLIsSyn (typename))
00572 {
00573 tok = LCLGetTokenForSyn (typename);
00574 inter = ltoken_getText (tok);
00575 /* printf ("In lsymbol_sortFromType: %s -> %s\n",
00576 lsymbol_toChars (typename), lsymbol_toChars (inter)); */
00577 }
00578 else
00579 {
00580 inter = typename;
00581 }
00582
00583 /* now map LCL type to sort */
00584 out = mapping_find (s->type2sort, inter);
00585
00586 if (out == lsymbol_undefined)
00587 {
00588 return inter;
00589 }
00590
00591 return out;
00592 }
|
|
|
Definition at line 825 of file symtable.c. 00826 {
00827 lsymbol res = mapping_find (m, s);
00828 if (res == lsymbol_undefined)
00829 return s;
00830 return res;
00831 }
|
|
|
Definition at line 810 of file symtable.c. Referenced by outputLCSFile(). 00811 {
00812 symHashTable *ht = stable->hTable;
00813
00814
00815 fprintf (f, "%s\n", BEGINSYMTABLE);
00816
00817 symHashTable_dump (ht, f, lco);
00818
00819 symtable_dumpId (stable, f, lco);
00820
00821 fprintf (f, "%s\n", SYMTABLEEND);
00822 }
|
|
|
Definition at line 489 of file symtable.c. Referenced by enteringFcnScope(), and o_fctInfo(). 00490 {
00491 idTable *st = stable->idTable;
00492 idTableEntry *e;
00493 bool redecl = FALSE;
00494
00495 if (!allowed_redeclaration &&
00496 symtable_lookup (st, ltoken_getText (fi->id)) != (idTableEntry *) 0)
00497 {
00498 lclRedeclarationError (fi->id);
00499 redecl = TRUE;
00500 }
00501
00502 e = nextFree (st);
00503 e->kind = SYMK_FCN;
00504 fi->export = st->exporting; /* && !fi->private; */
00505 (e->info).fct = fi;
00506
00507 return redecl;
00508 }
|
|
|
Definition at line 304 of file symtable.c. Referenced by abstract_init(), makeLiteralTermNode(), makelslOpNode(), and o_fctInfo(). 00306 {
00307 /*
00308 ** Operators are overloaded, we allow entering opInfo more than once,
00309 ** even if it's the same signature.
00310 **
00311 ** Assumes all sorts are already entered into the symbol table
00312 */
00313
00314 symHashTable *ht = st->hTable;
00315 htData *d;
00316 lsymbol id;
00317
00318
00319
00320 id = nameNode2key (n);
00321
00322 d = symHashTable_get (ht, id, IK_OP, n);
00323
00324 if (d == (htData *) 0)
00325 { /* first signature of this operator */
00326 opInfo op = (opInfo) dmalloc (sizeof (*op));
00327 htData *nd = (htData *) dmalloc (sizeof (*nd));
00328
00329 op->name = n;
00330
00331 if (oi != (sigNode) 0)
00332 {
00333 op->signatures = sigNodeSet_singleton (oi);
00334 ht->count++;
00335 }
00336 else
00337 {
00338 op->signatures = sigNodeSet_new ();
00339 sigNode_markOwned (oi);
00340 }
00341
00342 nd->kind = IK_OP;
00343 nd->content.op = op;
00344 (void) symHashTable_put (ht, nd);
00345 }
00346 else
00347 {
00348
00349 nameNode_free (n); /*<<<??? */
00350
00351 if (htData_insertSignature (d, oi))
00352 {
00353 ht->count++;
00354 }
00355 }
00356 }
|
|
|
Definition at line 456 of file symtable.c. Referenced by enteringClaimScope(), and enteringFcnScope(). 00457 {
00458 idTable *st = stable->idTable;
00459 idTableEntry *e = nextFree (st);
00460 if (si->kind == SPE_GLOBAL)
00461 llbuglit ("symtable_enterScope: SPE_GLOBAL");
00462 e->kind = SYMK_SCOPE;
00463 (e->info).scope = si;
00464 }
|
|
|
Definition at line 359 of file symtable.c. Referenced by checkAndEnterTag(), and makeEnumSpecNode(). 00360 {
00361 /* put ti only if it is not already in symtable */
00362 symHashTable *ht = st->hTable;
00363 htData *d;
00364 symbolKey key = ltoken_getText (ti->id);
00365
00366 d = symHashTable_get (ht, key, IK_TAG, (nameNode) 0);
00367 if (d == (htData *) 0)
00368 {
00369 d = (htData *) dmalloc (sizeof (*d));
00370 d->kind = IK_TAG;
00371 d->content.tag = ti;
00372 d->content.tag->imported = context_inImport ();
00373 (void) symHashTable_put (ht, d);
00374 return TRUE;
00375 }
00376 else
00377 {
00378 if (d->content.tag->imported)
00379 {
00380 d->content.tag = ti;
00381 d->content.tag->imported = context_inImport ();
00382 return TRUE;
00383 }
00384 else
00385 {
00386 tagInfo_free (ti);
00387 return FALSE;
00388 }
00389 }
00390 }
|
|
|
Definition at line 393 of file symtable.c. Referenced by makestrOrUnionNode(). 00394 {
00395 /* put ti, force-put if necessary */
00396 symHashTable *ht = st->hTable;
00397 htData *d;
00398 symbolKey key = ltoken_getText (ti->id);
00399
00400 d = symHashTable_get (ht, key, IK_TAG, (nameNode) 0);
00401
00402 if (d == (htData *) 0)
00403 {
00404 d = (htData *) dmalloc (sizeof (*d));
00405
00406 d->kind = IK_TAG;
00407 d->content.tag = ti;
00408 d->content.tag->imported = context_inImport ();
00409 (void) symHashTable_put (ht, d);
00410 return TRUE;
00411 }
00412 else
00413 {
00414
00415 d->kind = IK_TAG;
00416 d->content.tag = ti;
00417 d->content.tag->imported = context_inImport ();
00418 /* interpret return data later, htData * */
00419 /*@i@*/ (void) symHashTable_forcePut (ht, d);
00420 return FALSE;
00421 }
00422 }
|
|
|
Definition at line 511 of file symtable.c. Referenced by LCLBuiltins(), abstract_init(), declareForwardType(), makeAbstractNode(), and o_fctInfo(). 00512 {
00513 idTable *st = stable->idTable;
00514 idTableEntry *e;
00515 bool insertp = TRUE;
00516 scopeKind k = (symtable_scopeInfo (stable))->kind;
00517
00518 /* symtable_disp (stable); */
00519
00520 if (k != SPE_GLOBAL && k != SPE_INVALID) /* fixed for LCLint */
00521 {
00522 llbug (message ("%q: symtable_enterType: expect global scope. (type: %s)",
00523 ltoken_unparseLoc (ti->id),
00524 ltoken_getRawString (ti->id)));
00525 }
00526
00527 if (!allowed_redeclaration &&
00528 symtable_lookup (st, ltoken_getText (ti->id)) != (idTableEntry *) 0)
00529 {
00530 /* ignore if Bool is re-entered */
00531 if (ltoken_getText (ti->id) == lsymbol_getBool () ||
00532 ltoken_getText (ti->id) == lsymbol_getbool ())
00533 {
00534 insertp = FALSE;
00535 }
00536 else
00537 {
00538 lclRedeclarationError (ti->id);
00539 }
00540 }
00541 if (insertp)
00542 {
00543 /* make sure it is a type TYPEDEF_NAME; */
00544
00545 if (ltoken_getCode (ti->id) != LLT_TYPEDEF_NAME)
00546 {
00547 lclbug (message ("symtable_enterType: gets a simpleId, expect a type: %s",
00548 ltoken_getRawString (ti->id)));
00549 }
00550
00551 e = nextFree (st);
00552 e->kind = SYMK_TYPE;
00553 ti->export = st->exporting;/* && !ti->private; */
00554 (e->info).type = ti;
00555 mapping_bind (stable->type2sort, ltoken_getText (ti->id),
00556 sort_getLsymbol (sort_makeVal (sort_getUnderlying (ti->basedOn))));
00557 }
00558 else
00559 {
00560 typeInfo_free (ti);
00561 }
00562 }
|
|
|
Definition at line 601 of file symtable.c. Referenced by LCLBuiltins(), enteringClaimScope(), enteringFcnScope(), makeConstDeclarationNode(), makeEnumSpecNode(), makeLetDeclNode(), makeVarDeclarationNode(), makeVarNode(), o_fctInfo(), and sort_import(). 00602 {
00603 idTable *st = stable->idTable;
00604 bool insertp = TRUE;
00605 bool redecl = FALSE;
00606
00607
00608 /* symtable_disp (symtab); */
00609
00610 if (!allowed_redeclaration &&
00611 (symtable_lookupInScope (st, ltoken_getText (vi->id)) != (idTableEntry *) 0))
00612 {
00613 if (ltoken_getText (vi->id) == lsymbol_getTRUE () ||
00614 ltoken_getText (vi->id) == lsymbol_getFALSE ())
00615 {
00616 insertp = FALSE;
00617 }
00618 else
00619 {
00620 if (usymtab_existsEither (ltoken_getRawString (vi->id)))
00621 {
00622 lclRedeclarationError (vi->id);
00623 redecl = TRUE;
00624 }
00625 else
00626 {
00627 llbuglit ("redeclared somethingerother?!");
00628 }
00629 }
00630 }
00631
00632 if (insertp)
00633 {
00634 idTableEntry *e = nextFree (st);
00635
00636 e->kind = SYMK_VAR;
00637 vi->export = st->exporting && /* !vi.private && */
00638 (vi->kind == VRK_VAR || vi->kind == VRK_CONST || vi->kind == VRK_ENUM);
00639 (e->info).var = varInfo_copy (vi);
00640 }
00641
00642 return (redecl);
00643 }
|
|
|
Definition at line 646 of file symtable.c. Referenced by yllex(). 00647 {
00648 idTable *st = stable->idTable;
00649 return symtable_lookup (st, i) != (idTableEntry *) 0;
00650 }
|
|
|
Definition at line 467 of file symtable.c. 00468 {
00469 idTable *st = stable->idTable;
00470 int n;
00471
00472 if (st->entries != NULL)
00473 {
00474 for (n = st->size - 1; (st->entries[n]).kind != SYMK_SCOPE; n--)
00475 {
00476 ;
00477 }
00478 }
00479 else
00480 {
00481 llcontbuglit ("symtable_exitScope: no scope to exit");
00482 n = 0;
00483 }
00484
00485 st->size = n;
00486 }
|
|
|
Definition at line 734 of file symtable.c. 00735 {
00736 idTable *st = stable->idTable;
00737 st->exporting = yesNo;
00738 (void) sort_setExporting (yesNo);
00739 }
|
|
|
Definition at line 142 of file symtable.c. 00143 {
00144 /* symtable_printStats (stable); */
00145
00146 idTable_free (stable->idTable);
00147 symHashTable_free (stable->hTable);
00148 mapping_free (stable->type2sort);
00149 sfree (stable);
00150 }
|
|
|
Definition at line 1375 of file symtable.c. Referenced by processImport(). 01376 {
01377 char *buf, *importfile;
01378 tsource *lclsource;
01379 int old_lsldebug;
01380 bool old_inImport = inImport;
01381
01382 buf = tsource_nextLine (imported);
01383 importfile = tsource_fileName (imported);
01384
01385 llassert (buf != NULL);
01386
01387 if (!firstWord (buf, "%LCLSymbolTable"))
01388 {
01389 lclsource = LCLScanSource ();
01390 lclfatalerror (tok,
01391 message ("Expecting '%%LCLSymbolTable' line in import file %s:\n%s\n",
01392 cstring_fromChars (importfile),
01393 cstring_fromChars (buf)));
01394 }
01395
01396 old_lsldebug = lsldebug;
01397 lsldebug = 0;
01398 allowed_redeclaration = TRUE;
01399 inImport = TRUE;
01400
01401 for (;;)
01402 {
01403 buf = tsource_nextLine (imported);
01404 llassert (buf != NULL);
01405
01406
01407 if (firstWord (buf, "%LCLSymbolTableEnd"))
01408 {
01409 break;
01410 }
01411 else
01412 { /* a good line, remove %LCL from line first */
01413 if (firstWord (buf, "%LCL"))
01414 {
01415 parseLine (buf + 4, imported, map);
01416 }
01417 else
01418 {
01419 lclsource = LCLScanSource ();
01420 lclfatalerror
01421 (tok,
01422 message ("Expecting '%%LCL' prefix in import file %s:\n%s\n",
01423 cstring_fromChars (importfile),
01424 cstring_fromChars (buf)));
01425 }
01426 }
01427 }
01428
01429 /* restore old value */
01430 inImport = old_inImport;
01431 lsldebug = old_lsldebug;
01432 allowed_redeclaration = FALSE;
01433 }
|
|
|
Definition at line 220 of file symtable.c. 00221 {
00222 symtable stable = (symtable) dmalloc (sizeof (*stable));
00223 idTableEntry *e;
00224
00225 stable->idTable = symtable_newIdTable ();
00226 stable->hTable = symHashTable_create (HT_MAXINDEX);
00227 stable->type2sort = mapping_create ();
00228
00229 /* add builtin synonym: Bool -> bool */
00230
00231 mapping_bind (stable->type2sort, lsymbol_getBool (), lsymbol_getbool ());
00232
00233 /*
00234 ** done by symtable_newIdTable
00235 ** st->allocated = 0;
00236 ** st->entries = (idTableEntry *) 0;
00237 ** st->exporting = TRUE;
00238 */
00239
00240 /* this is global scope */
00241 e = nextFree (stable->idTable);
00242 e->kind = SYMK_SCOPE;
00243 (e->info).scope = (scopeInfo) dmalloc (sizeof (*((e->info).scope)));
00244 (e->info).scope->kind = SPE_GLOBAL;
00245
00246 return stable;
00247 }
|
|
|
Definition at line 2039 of file symtable.c. Referenced by computePossibleSorts(). 02040 {
02041 opInfo oi = symtable_opInfo (tab, n);
02042
02043 if (opInfo_exists (oi))
02044 {
02045 sigNodeSet sigs = oi->signatures;
02046 sigNodeSet_elements (sigs, sig)
02047 {
02048 if (ltokenList_size (sig->domain) == arity)
02049 return TRUE;
02050 } end_sigNodeSet_elements;
02051 }
02052 return FALSE;
02053 }
|
|
|
Definition at line 425 of file symtable.c. Referenced by makeLiteralTermNode(), makeSimpleTermNode(), symtable_opExistsWithArity(), symtable_opsWithLegalDomain(), and symtable_possibleOps(). 00426 {
00427 symHashTable *ht = st->hTable;
00428 lsymbol i = nameNode2key (n);
00429
00430 htData *d;
00431 d = symHashTable_get (ht, i, IK_OP, n);
00432 if (d == (htData *) 0)
00433 {
00434 return (opInfo)NULL;
00435 }
00436
00437 return (d->content.op);
00438 }
|
|
|
Definition at line 2082 of file symtable.c. Referenced by computePossibleSorts(). 02084 {
02085 /* handles nil qual */
02086 lslOpSet ops = lslOpSet_new ();
02087 lslOp op;
02088 sort rangeSort;
02089 opInfo oi;
02090
02091 llassert (n != NULL);
02092 oi = symtable_opInfo (tab, n);
02093
02094 if (opInfo_exists (oi))
02095 {
02096 sigNodeSet sigs = oi->signatures;
02097
02098 sigNodeSet_elements (sigs, sig)
02099 {
02100 if (ltokenList_size (sig->domain) == sortSetList_size (argSorts))
02101 {
02102 rangeSort = sigNode_rangeSort (sig);
02103
02104 if ((qual == 0) || (sort_equal (&rangeSort, &qual)))
02105 {
02106 if (domainMatches (sig->domain, argSorts))
02107 {
02108 op = (lslOp) dmalloc (sizeof (*op));
02109
02110 /* each domain sort in op must be an element of
02111 the corresponding set in argSorts. */
02112 op->signature = sig;
02113 op->name = nameNode_copy (n);
02114 (void) lslOpSet_insert (ops, op);
02115 }
02116 }
02117 }
02118 } end_sigNodeSet_elements;
02119 }
02120 return ops;
02121 }
|
|
|
Definition at line 2026 of file symtable.c. Referenced by computePossibleSorts(). 02027 {
02028 opInfo oi = symtable_opInfo (tab, n);
02029
02030 if (opInfo_exists (oi))
02031 {
02032 return (oi->signatures);
02033 }
02034
02035 return sigNodeSet_undefined;
02036 }
|
|
|
Definition at line 1995 of file symtable.c. 01996 {
01997 symHashTable_printStats (s->hTable);
01998 /* for debugging only */
01999 printf ("idTable size = %d; allocated = %d\n",
02000 s->idTable->size, s->idTable->allocated);
02001 }
|
|
|
Definition at line 441 of file symtable.c. Referenced by checkAndEnterTag(), makeEnumSpecNode(), makeEnumSpecNode2(), makeForwardstrOrUnionNode(), and makestrOrUnionNode(). 00442 {
00443 symHashTable *ht = st->hTable;
00444 htData *d;
00445 d = symHashTable_get (ht, i, IK_TAG, 0);
00446
00447 if (d == (htData *) 0)
00448 {
00449 return (tagInfo) NULL;
00450 }
00451
00452 return (d->content.tag);
00453 }
|
|
|
Definition at line 653 of file symtable.c. Referenced by makeTypeSpecifier(). 00654 {
00655 idTable *st;
00656 idTableEntry *e;
00657
00658 st = stable->idTable;
00659 e = symtable_lookup (st, i);
00660
00661 if (e == (idTableEntry *) 0 || e->kind != SYMK_TYPE)
00662 {
00663 return (typeInfo) NULL;
00664 }
00665
00666 return (e->info).type;
00667 }
|
|
|
Definition at line 670 of file symtable.c. Referenced by makeSimpleTermNode(), makeVarDeclarationNode(), and sort_import(). 00671 {
00672 idTable *st = stable->idTable;
00673 idTableEntry *e;
00674
00675 e = symtable_lookup (st, i);
00676
00677 if (e == (idTableEntry *) 0 || e->kind != SYMK_VAR)
00678 {
00679 return (varInfo) NULL;
00680 }
00681
00682 return (e->info).var;
00683 }
|
|
|
Definition at line 686 of file symtable.c. Referenced by makeSimpleTermNode(). 00687 {
00688 /* if current scope is a SPE_QUANT, can go beyond current scope */
00689 idTable *st = stable->idTable;
00690 idTableEntry *e2 = (idTableEntry *) 0;
00691 int n;
00692
00693 for (n = st->size - 1; n >= 0; n--)
00694 {
00695 ltoken tok;
00696
00697 e2 = &(st->entries[n]);
00698
00699 if (e2->kind == SYMK_SCOPE && e2->info.scope->kind != SPE_QUANT)
00700 {
00701 return (varInfo) NULL;
00702 }
00703
00704 tok = idTableEntry_getId (e2);
00705
00706 if (e2->kind == SYMK_VAR && ltoken_getText (tok) == id)
00707 {
00708 return (e2->info).var;
00709 }
00710 }
00711
00712 return (varInfo) NULL;
00713 }
|
|
|
Definition at line 2004 of file symtable.c. Referenced by makeEnumSpecNode(), makeEnumSpecNode2(), makeForwardstrOrUnionNode(), and makestrOrUnionNode(). 02005 {
02006 switch (k)
02007 {
02008 case TAG_STRUCT:
02009 case TAG_FWDSTRUCT:
02010 return cstring_makeLiteral ("struct");
02011 case TAG_UNION:
02012 case TAG_FWDUNION:
02013 return cstring_makeLiteral ("union");
02014 case TAG_ENUM:
02015 return cstring_makeLiteral ("enum");
02016 }
02017 BADEXIT;
02018 }
|
|
|
Definition at line 125 of file symtable.c. Referenced by LCLBuiltins(), enteringClaimScope(), enteringFcnScope(), makeConstDeclarationNode(), makeEnumSpecNode(), makeLetDeclNode(), makeVarDeclarationNode(), makeVarNode(), o_fctInfo(), and sort_import(). 00126 {
00127 sfree (v);
00128 }
|
1.2.3 written by Dimitri van Heesch,
© 1997-2000