2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
27 ** Module for building abstract syntax trees for LCL.
29 ** This module is too close to the surface syntax of LCL.
34 ** Massachusetts Institute of Technology
37 # include "lclintMacros.nf"
39 # include "lslparse.h"
40 # include "llgrammar.h" /* need simpleOp, MULOP and logicalOp in makeInfixTermNode */
45 static lsymbol lsymbol_Bool;
46 static lsymbol lsymbol_bool;
47 static lsymbol lsymbol_TRUE;
48 static lsymbol lsymbol_FALSE;
50 static void lclPredicateNode_free (/*@only@*/ /*@null@*/ lclPredicateNode p_x) ;
51 static void exposedNode_free (/*@only@*/ /*@null@*/ exposedNode p_x) ;
52 static void CTypesNode_free (/*@null@*/ /*@only@*/ CTypesNode p_x);
53 static /*@null@*/ CTypesNode CTypesNode_copy (/*@null@*/ CTypesNode p_x) /*@*/ ;
55 constDeclarationNode_free (/*@only@*/ /*@null@*/ constDeclarationNode p_x);
56 static void claimNode_free (/*@only@*/ /*@null@*/ claimNode p_x);
57 static void iterNode_free (/*@only@*/ /*@null@*/ iterNode p_x);
58 static void abstBodyNode_free (/*@only@*/ /*@null@*/ abstBodyNode p_n);
59 static void abstractNode_free (/*@only@*/ /*@null@*/ abstractNode p_x);
60 static void taggedUnionNode_free (/*@only@*/ /*@null@*/ taggedUnionNode p_x);
61 static void typeNode_free (/*@only@*/ /*@null@*/ typeNode p_t);
62 static /*@null@*/ strOrUnionNode
63 strOrUnionNode_copy (/*@null@*/ strOrUnionNode p_n) /*@*/ ;
64 static void strOrUnionNode_free (/*@null@*/ /*@only@*/ strOrUnionNode p_n)
65 /*@modifies *p_n @*/ ;
67 static void enumSpecNode_free (/*@null@*/ /*@only@*/ enumSpecNode p_x);
68 static /*@only@*/ /*@null@*/ enumSpecNode
69 enumSpecNode_copy (/*@null@*/ enumSpecNode p_x) /*@*/ ;
70 static /*@only@*/ lclTypeSpecNode
71 lclTypeSpecNode_copySafe (lclTypeSpecNode p_n) /*@*/ ;
72 static void lclTypeSpecNode_free (/*@null@*/ /*@only@*/ lclTypeSpecNode p_n);
73 static void typeNamePack_free (/*@only@*/ /*@null@*/ typeNamePack p_x);
74 static void opFormNode_free (/*@only@*/ /*@null@*/ opFormNode p_op);
75 static quantifiedTermNode quantifiedTermNode_copy (quantifiedTermNode p_q) /*@*/ ;
76 static void nameAndReplaceNode_free (/*@only@*/ /*@null@*/ nameAndReplaceNode p_x);
77 static void renamingNode_free (/*@only@*/ /*@null@*/ renamingNode p_x);
78 static void exportNode_free (/*@null@*/ /*@only@*/ exportNode p_x);
79 static void privateNode_free (/*@only@*/ /*@null@*/ privateNode p_x);
80 static /*@null@*/ termNode termNode_copy (/*@null@*/ termNode p_t) /*@*/ ;
82 stmtNode_free (/*@only@*/ /*@null@*/ stmtNode p_x) /*@modifies *p_x@*/ ;
83 static /*@null@*/ typeExpr typeExpr_copy (/*@null@*/ typeExpr p_x) /*@*/ ;
85 static lsymbol ConditionalSymbol;
86 static lsymbol equalSymbol;
87 static lsymbol eqSymbol;
88 static lclTypeSpecNode exposedType;
90 static /*@only@*/ cstring abstDeclaratorNode_unparse (abstDeclaratorNode p_x);
91 static pairNodeList extractParams (/*@null@*/ typeExpr p_te);
92 static sort extractReturnSort (lclTypeSpecNode p_t, declaratorNode p_d);
93 static void checkAssociativity (termNode p_x, ltoken p_op);
94 static void LCLBootstrap (void);
95 static cstring printMiddle (int p_j);
96 static void paramNode_checkQualifiers (lclTypeSpecNode p_t, typeExpr p_d);
99 resetImports (cstring current)
101 lsymbolSet_free (g_currentImports);
103 g_currentImports = lsymbolSet_new (); /* equal_symbol; */
104 (void) lsymbolSet_insert (g_currentImports,
105 lsymbol_fromChars (cstring_toCharsSafe (current)));
111 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
116 ltokenList domain = ltokenList_new ();
119 equalSymbol = lsymbol_fromChars ("=");
120 eqSymbol = lsymbol_fromChars ("\\eq");
123 ** not: cstring_toCharsSafe (context_getBoolName ())
124 ** we use the hard wired "bool" name.
127 lsymbol_bool = lsymbol_fromChars ("bool");
128 lsymbol_Bool = lsymbol_fromChars ("Bool");
130 lsymbol_TRUE = lsymbol_fromChars ("TRUE");
131 lsymbol_FALSE = lsymbol_fromChars ("FALSE");
133 ConditionalSymbol = lsymbol_fromChars ("if__then__else__");
135 /* generate operators for
136 ** __ \not, __ \implies __ , __ \and __, __ \or __
139 range = ltoken_create (simpleId, lsymbol_bool);
140 dom = ltoken_create (simpleId, lsymbol_bool);
142 ltokenList_addh (domain, ltoken_copy (dom));
144 domain2 = ltokenList_copy (domain); /* moved this here (before release) */
146 sign = makesigNode (ltoken_undefined, domain, ltoken_copy (range));
148 opform = makeOpFormNode (ltoken_undefined, OPF_ANYOPM,
149 opFormUnion_createAnyOp (ltoken_not),
151 nn = makeNameNodeForm (opform);
152 symtable_enterOp (g_symtab, nn, sign);
154 ltokenList_addh (domain2, dom);
156 sign = makesigNode (ltoken_undefined, domain2, range);
158 opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM,
159 opFormUnion_createAnyOp (ltoken_and),
162 nn = makeNameNodeForm (opform);
163 symtable_enterOp (g_symtab, nn, sigNode_copy (sign));
165 opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM,
166 opFormUnion_createAnyOp (ltoken_or),
169 nn = makeNameNodeForm (opform);
170 symtable_enterOp (g_symtab, nn, sigNode_copy (sign));
172 opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM,
173 opFormUnion_createAnyOp (ltoken_implies),
175 nn = makeNameNodeForm (opform);
176 symtable_enterOp (g_symtab, nn, sign);
178 /* from lclscanline.c's init procedure */
179 /* comment out so we can add in lclinit.lci: synonym double float */
180 /* ReserveToken (FLOAT, "float"); */
181 /* But we need to make the scanner parse "float" not as a simpleId, but
182 as a TYPEDEF_NAME. This is done later in abstract_init */
184 ti->id = ltoken_createType (LLT_TYPEDEF_NAME, SID_TYPE, lsymbol_fromChars ("float"));
186 ti->modifiable = FALSE;
187 ti->abstract = FALSE;
188 ti->export = FALSE; /* this is implicit, not exported */
189 ti->basedOn = sort_float;
190 symtable_enterType (g_symtab, ti);
194 declareForwardType (declaratorNode declare)
196 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
200 typedefname = ltoken_getText (declare->id);
201 ti->id = ltoken_copy (declare->id);
203 ltoken_setCode (ti->id, LLT_TYPEDEF_NAME);
204 ltoken_setIdType (ti->id, SID_TYPE);
206 ti->modifiable = FALSE;
207 ti->abstract = FALSE;
208 tsort = lclTypeSpecNode2sort (exposedType);
209 handle = typeExpr2ptrSort (tsort, declare->type);
210 ti->basedOn = sort_makeSyn (declare->id, handle, typedefname);
213 symtable_enterType (g_symtab, ti);
216 void LCLBuiltins (void)
218 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
219 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
221 /* immutable type bool;
223 constant bool FALSE = false;
224 constant bool TRUE = true; */
226 /* the following defines the builtin LSL sorts and operators */
229 /* now LCL builtin proper */
230 /* do "immutable type bool;" */
232 ti->id = ltoken_copy (ltoken_bool);
234 ltoken_setCode (ti->id, LLT_TYPEDEF_NAME);
235 ltoken_setIdType (ti->id, SID_TYPE);
237 ti->modifiable = FALSE;
239 ti->basedOn = sort_bool;
240 ti->export = FALSE; /* this wasn't set (detected by lclint) */
241 symtable_enterType (g_symtab, ti);
243 /* do "constant bool FALSE = false;" */
244 vi->id = ltoken_createType (simpleId, SID_VAR, lsymbol_fromChars ("FALSE"));
246 vi->kind = VRK_CONST;
247 vi->sort = sort_bool;
250 (void) symtable_enterVar (g_symtab, vi);
252 /* do "constant bool TRUE = true;" */
253 /* vi->id = ltoken_copy (vi->id); */
254 ltoken_setText (vi->id, lsymbol_fromChars ("TRUE"));
255 (void) symtable_enterVar (g_symtab, vi);
271 ** Minimal we need to bootstrap is to provide the sort
272 ** "bool" and 2 bool constants "true" and "false".
273 ** sort_init should already have been called, and hence
274 ** the bool and Bool sorts defined.
277 s = sort_makeImmutable (ltoken_undefined, lsymbol_bool);
278 range = ltoken_create (simpleId, lsymbol_bool);
279 sign = makesigNode (ltoken_undefined, ltokenList_new (), range);
281 nn1 = (nameNode) dmalloc (sizeof (*nn1));
284 nn1->content.opid = ltoken_create (simpleId, lsymbol_fromChars ("true"));
286 symtable_enterOp (g_symtab, nn1, sign);
288 nn2 = (nameNode) dmalloc (sizeof (*nn2));
290 nn2->content.opid = ltoken_create (simpleId, lsymbol_fromChars ("false"));
292 symtable_enterOp (g_symtab, nn2, sigNode_copy (sign));
296 consInterfaceNode (/*@only@*/ interfaceNode n, /*@returned@*/ interfaceNodeList ns)
298 /* n is never empty, but ns may be empty */
299 interfaceNodeList_addl (ns, n);
303 /*@only@*/ interfaceNode
304 makeInterfaceNodeImports (/*@only@*/ importNodeList x)
306 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
307 lsymbol importSymbol;
309 i->kind = INF_IMPORTS;
310 i->content.imports = x; /* an importNodeList */
312 importNodeList_elements (x, imp)
314 importSymbol = ltoken_getRawText (imp->val);
316 if (lsymbolSet_member (g_currentImports, importSymbol))
319 message ("Circular imports: %s",
320 cstring_fromChars (lsymbol_toChars (importSymbol))));
324 processImport (importSymbol, imp->val, imp->kind);
326 } end_importNodeList_elements;
328 lhOutLine (cstring_undefined);
332 /*@only@*/ interfaceNode
333 makeInterfaceNodeUses (/*@only@*/ traitRefNodeList x)
335 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
339 /* read in LSL traits */
344 /*@only@*/ interfaceNode
345 interfaceNode_makeConst (/*@only@*/ constDeclarationNode x)
347 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
348 exportNode e = (exportNode) dmalloc (sizeof (*e));
351 e->content.constdeclaration = x;
352 i->kind = INF_EXPORT;
353 i->content.export = e;
358 /*@only@*/ interfaceNode
359 interfaceNode_makeVar (/*@only@*/ varDeclarationNode x)
361 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
362 exportNode e = (exportNode) dmalloc (sizeof (*e));
365 e->content.vardeclaration = x;
366 i->kind = INF_EXPORT;
367 i->content.export = e;
369 if (context_msgLh ())
371 lhOutLine (lhVarDecl (x->type, x->decls, x->qualifier));
377 /*@only@*/ interfaceNode
378 interfaceNode_makeType (/*@only@*/ typeNode x)
380 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
381 exportNode e = (exportNode) dmalloc (sizeof (*e));
384 i->kind = INF_EXPORT;
385 i->content.export = e;
387 if (context_msgLh ())
390 lhOutLine (lhType (x));
396 /*@only@*/ interfaceNode
397 interfaceNode_makeFcn (/*@only@*/ fcnNode x)
399 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
400 exportNode e = (exportNode) dmalloc (sizeof (*e));
404 i->kind = INF_EXPORT;
405 i->content.export = e;
407 if (context_msgLh ())
409 llassert (x->typespec != NULL);
410 llassert (x->declarator != NULL);
412 lhOutLine (lhFunction (x->typespec, x->declarator));
418 /*@only@*/ interfaceNode
419 interfaceNode_makeClaim (/*@only@*/ claimNode x)
421 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
422 exportNode e = (exportNode) dmalloc (sizeof (*e));
425 e->content.claim = x;
426 i->kind = INF_EXPORT;
427 i->content.export = e;
431 /*@only@*/ interfaceNode
432 interfaceNode_makeIter (/*@only@*/ iterNode x)
434 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
435 exportNode e = (exportNode) dmalloc (sizeof (*e));
439 i->kind = INF_EXPORT;
440 i->content.export = e;
444 /*@only@*/ interfaceNode
445 interfaceNode_makePrivConst (/*@only@*/ constDeclarationNode x)
447 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
448 privateNode e = (privateNode) dmalloc (sizeof (*e));
450 e->kind = PRIV_CONST;
451 e->content.constdeclaration = x;
452 i->kind = INF_PRIVATE;
453 i->content.private = e;
457 /*@only@*/ interfaceNode
458 interfaceNode_makePrivVar (/*@only@*/ varDeclarationNode x)
460 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
461 privateNode e = (privateNode) dmalloc (sizeof (*e));
464 e->content.vardeclaration = x;
465 i->kind = INF_PRIVATE;
466 i->content.private = e;
470 /*@only@*/ interfaceNode
471 interfaceNode_makePrivType (/*@only@*/ typeNode x)
473 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
474 privateNode e = (privateNode) dmalloc (sizeof (*e));
478 i->kind = INF_PRIVATE;
479 i->content.private = e;
483 /*@only@*/ interfaceNode
484 interfaceNode_makePrivFcn (/*@only@*/ fcnNode x)
486 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
487 privateNode e = (privateNode) dmalloc (sizeof (*e));
490 ** bug detected by lclint enum checking
491 ** e->kind = XPK_FCN;
494 e->kind = PRIV_FUNCTION;
496 i->kind = INF_PRIVATE;
497 i->content.private = e;
502 exportNode_unparse (exportNode n)
504 if (n != (exportNode) 0)
511 constDeclarationNode_unparse (n->content.constdeclaration)));
515 varDeclarationNode_unparse (n->content.vardeclaration)));
517 return (message ("%q\n", typeNode_unparse (n->content.type)));
519 return (fcnNode_unparse (n->content.fcn));
521 return (claimNode_unparse (n->content.claim));
523 return (iterNode_unparse (n->content.iter));
525 llfatalbug (message ("exportNode_unparse: unknown kind: %d", (int) n->kind));
528 return cstring_undefined;
532 privateNode_unparse (privateNode n)
534 if (n != (privateNode) 0)
539 return (constDeclarationNode_unparse (n->content.constdeclaration));
541 return (varDeclarationNode_unparse (n->content.vardeclaration));
543 return (typeNode_unparse (n->content.type));
545 return (fcnNode_unparse (n->content.fcn));
547 llfatalbug (message ("privateNode_unparse: unknown kind: %d",
551 return cstring_undefined;
554 void lclPredicateNode_free (/*@null@*/ /*@only@*/ lclPredicateNode x)
558 termNode_free (x->predicate);
559 ltoken_free (x->tok);
564 static /*@only@*/ cstring
565 lclPredicateNode_unparse (/*@null@*/ lclPredicateNode p) /*@*/
567 if (p != (lclPredicateNode) 0)
569 cstring st = cstring_undefined;
574 st = cstring_makeLiteral (" requires ");
577 st = cstring_makeLiteral (" checks ");
580 st = cstring_makeLiteral (" ensures ");
583 st = cstring_makeLiteral (" claims ");
586 st = cstring_makeLiteral ("constraint ");
589 st = cstring_makeLiteral ("initially ");
594 llfatalbug (message ("lclPredicateNode_unparse: unknown kind: %d",
597 return (message ("%q%q;\n", st, termNode_unparse (p->predicate)));
599 return cstring_undefined;
603 ltoken_similar (ltoken t1, ltoken t2)
605 lsymbol sym1 = ltoken_getText (t1);
606 lsymbol sym2 = ltoken_getText (t2);
613 if ((sym1 == eqSymbol && sym2 == equalSymbol) ||
614 (sym2 == eqSymbol && sym1 == equalSymbol))
619 if ((sym1 == lsymbol_bool && sym2 == lsymbol_Bool) ||
620 (sym2 == lsymbol_bool && sym1 == lsymbol_Bool))
629 iterNode_unparse (/*@null@*/ iterNode i)
631 if (i != (iterNode) 0)
633 return (message ("iter %s %q", ltoken_unparse (i->name),
634 paramNodeList_unparse (i->params)));
636 return cstring_undefined;
641 fcnNode_unparse (/*@null@*/ fcnNode f)
643 if (f != (fcnNode) 0)
645 return (message ("%q %q%q{\n%q%q%q%q%q%q}\n",
646 lclTypeSpecNode_unparse (f->typespec),
647 declaratorNode_unparse (f->declarator),
648 varDeclarationNodeList_unparse (f->globals),
649 varDeclarationNodeList_unparse (f->inits),
650 letDeclNodeList_unparse (f->lets),
651 lclPredicateNode_unparse (f->require),
652 modifyNode_unparse (f->modify),
653 lclPredicateNode_unparse (f->ensures),
654 lclPredicateNode_unparse (f->claim)));
656 return cstring_undefined;
660 varDeclarationNode_unparse (/*@null@*/ varDeclarationNode x)
662 if (x != (varDeclarationNode) 0)
668 return (sRef_unparse (x->sref));
672 switch (x->qualifier)
675 st = cstring_undefined;
678 st = cstring_makeLiteral ("const ");
681 st = cstring_makeLiteral ("volatile ");
686 st = message ("%q%q %q", st, lclTypeSpecNode_unparse (x->type),
687 initDeclNodeList_unparse (x->decls));
692 return cstring_undefined;
696 typeNode_unparse (/*@null@*/ typeNode t)
698 if (t != (typeNode) 0)
703 return (abstractNode_unparse (t->content.abstract));
705 return (exposedNode_unparse (t->content.exposed));
707 return (taggedUnionNode_unparse (t->content.taggedunion));
709 llfatalbug (message ("typeNode_unparse: unknown kind: %d", (int)t->kind));
712 return cstring_undefined;
716 constDeclarationNode_unparse (/*@null@*/ constDeclarationNode x)
718 if (x != (constDeclarationNode) 0)
720 return (message ("constant %q %q", lclTypeSpecNode_unparse (x->type),
721 initDeclNodeList_unparse (x->decls)));
724 return cstring_undefined;
727 /*@only@*/ storeRefNode
728 makeStoreRefNodeTerm (/*@only@*/ termNode t)
730 storeRefNode x = (storeRefNode) dmalloc (sizeof (*x));
737 /*@only@*/ storeRefNode
738 makeStoreRefNodeType (/*@only@*/ lclTypeSpecNode t, bool isObj)
740 storeRefNode x = (storeRefNode) dmalloc (sizeof (*x));
742 x->kind = isObj ? SRN_OBJ : SRN_TYPE;
748 makeStoreRefNodeInternal (void)
750 storeRefNode x = (storeRefNode) dmalloc (sizeof (*x));
752 x->kind = SRN_SPECIAL;
753 x->content.ref = sRef_makeInternalState ();
758 makeStoreRefNodeSystem (void)
760 storeRefNode x = (storeRefNode) dmalloc (sizeof (*x));
762 x->kind = SRN_SPECIAL;
763 x->content.ref = sRef_makeSystemState ();
767 /*@only@*/ modifyNode
768 makeModifyNodeSpecial (/*@only@*/ ltoken t, bool modifiesNothing)
770 modifyNode x = (modifyNode) dmalloc (sizeof (*x));
773 x->modifiesNothing = modifiesNothing;
774 x->hasStoreRefList = FALSE;
778 /*@only@*/ modifyNode
779 makeModifyNodeRef (/*@only@*/ ltoken t, /*@only@*/ storeRefNodeList y)
781 modifyNode x = (modifyNode) dmalloc (sizeof (*x));
785 x->hasStoreRefList = TRUE;
786 x->modifiesNothing = FALSE;
788 /* check that all storeRef's are modifiable */
790 storeRefNodeList_elements (y, sr)
792 if (storeRefNode_isTerm (sr))
794 sort = sr->content.term->sort;
796 if (!sort_mutable (sort) && sort_isValidSort (sort))
798 ltoken errtok = termNode_errorToken (sr->content.term);
800 message ("Term denoting immutable object used in modifies list: %q",
801 termNode_unparse (sr->content.term)));
806 if (!storeRefNode_isSpecial (sr))
808 sort = lclTypeSpecNode2sort (sr->content.type);
810 if (storeRefNode_isObj (sr))
812 sort = sort_makeObj (sort);
815 if (!sort_mutable (sort))
817 ltoken errtok = lclTypeSpecNode_errorToken (sr->content.type);
819 message ("Immutable type used in modifies list: %q",
820 sort_unparse (sort)));
824 } end_storeRefNodeList_elements;
828 /*@observer@*/ ltoken
829 termNode_errorToken (/*@null@*/ termNode n)
831 if (n != (termNode) 0)
836 case TRM_UNCHANGEDALL:
837 case TRM_UNCHANGEDOTHERS:
841 case TRM_ZEROARY: /* also the default kind, when no in symbol table */
844 return n->quantified->open;
845 case TRM_APPLICATION:
850 return n->name->content.opid;
854 llassert (n->name->content.opform != NULL);
855 return n->name->content.opform->tok;
860 return ltoken_undefined;
864 return ltoken_undefined;
867 /*@observer@*/ ltoken
868 nameNode_errorToken (/*@null@*/ nameNode nn)
870 if (nn != (nameNode) 0)
874 return nn->content.opid;
878 if (nn->content.opform != NULL)
880 return nn->content.opform->tok;
885 return ltoken_undefined;
888 /*@observer@*/ ltoken
889 lclTypeSpecNode_errorToken (/*@null@*/ lclTypeSpecNode t)
891 if (t != (lclTypeSpecNode) 0)
897 llassert (t->content.type != NULL);
899 if (ltokenList_empty (t->content.type->ctypes))
902 return (ltokenList_head (t->content.type->ctypes));
904 case LTS_STRUCTUNION:
905 llassert (t->content.structorunion != NULL);
906 return t->content.structorunion->tok;
908 llassert (t->content.enumspec != NULL);
909 return t->content.enumspec->tok;
911 return (lclTypeSpecNode_errorToken (t->content.conj->a));
915 return ltoken_undefined;
919 sort_member_modulo_cstring (sort s, /*@null@*/ termNode t)
922 if (t != (termNode) 0)
924 if (t->kind == TRM_LITERAL)
925 { /* allow multiple types */
928 sortSet_elements (t->possibleSorts, el)
930 if (sort_compatible_modulo_cstring (s, el))
934 } end_sortSet_elements;
936 sn = sort_lookup (s);
938 if (sn.kind == SRT_PTR)
940 char *lit = lsymbol_toChars (ltoken_getText (t->literal));
946 if (sscanf (lit, "%ld", &val) == 1)
948 if (val == 0) return TRUE;
957 return sort_compatible_modulo_cstring (s, t->sort);
963 /*@only@*/ letDeclNode
964 makeLetDeclNode (ltoken varid, /*@only@*/ /*@null@*/ lclTypeSpecNode t,
965 /*@only@*/ termNode term)
967 letDeclNode x = (letDeclNode) dmalloc (sizeof (*x));
968 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
972 if (t != (lclTypeSpecNode) 0)
974 /* check varid has the same sort as term */
975 s = lclTypeSpecNode2sort (t);
976 termsort = term->sort;
977 /* should keep the arguments in order */
978 if (!sort_member_modulo_cstring (s, term) &&
979 !term->error_reported)
981 errtok = termNode_errorToken (term);
983 /* errorShowPoint (tsource_thisLine (lclsource), ltoken_getCol (errtok)); */
984 /* sprintf (ERRMSG, "expect `%s' type but given term has `%s' type",
985 sort_unparse (s), sort_unparse (termsort)); */
988 message ("Let declaration expects type %q", sort_unparse (s)));
989 /* evs --- don't know how to generated this message or what it means? */
996 /* assign variable its type and sort, store in symbol table */
997 vi->id = ltoken_copy (varid);
1002 (void) symtable_enterVar (g_symtab, vi);
1008 x->sort = sort_makeNoSort ();
1013 /*@only@*/ programNode
1014 makeProgramNodeAction (/*@only@*/ programNodeList x, actionKind k)
1016 programNode n = (programNode) dmalloc (sizeof (*n));
1019 n->content.args = x;
1023 /*@only@*/ programNode
1024 makeProgramNode (/*@only@*/ stmtNode x)
1026 programNode n = (programNode) dmalloc (sizeof (*n));
1030 n->content.self = x;
1035 makeAbstractTypeNode (/*@only@*/ abstractNode x)
1037 typeNode n = (typeNode) dmalloc (sizeof (*n));
1039 n->kind = TK_ABSTRACT;
1040 n->content.abstract = x;
1046 makeExposedTypeNode (/*@only@*/ exposedNode x)
1048 typeNode n = (typeNode) dmalloc (sizeof (*n));
1050 n->kind = TK_EXPOSED;
1051 n->content.exposed = x;
1056 ** evs added 8 Sept 1993
1059 /*@only@*/ importNode
1060 importNode_makePlain (/*@only@*/ ltoken t)
1062 importNode imp = (importNode) dmalloc (sizeof (*imp));
1064 imp->kind = IMPPLAIN;
1069 /*@only@*/ importNode
1070 importNode_makeBracketed (/*@only@*/ ltoken t)
1072 importNode imp = (importNode) dmalloc (sizeof (*imp));
1074 imp->kind = IMPBRACKET;
1079 static cstring extractQuote (/*@only@*/ cstring s)
1081 int len = cstring_length (s);
1082 char *sc = cstring_toCharsSafe (s);
1086 *(sc + len - 1) = '\0';
1087 t = cstring_fromChars (mstring_copy (sc + 1));
1092 /*@only@*/ importNode
1093 importNode_makeQuoted (/*@only@*/ ltoken t)
1095 importNode imp = (importNode) dmalloc (sizeof (*imp));
1096 cstring q = extractQuote (cstring_copy (ltoken_getRawString (t)));
1098 imp->kind = IMPQUOTE;
1100 ltoken_setRawText (t, lsymbol_fromChars (cstring_toCharsSafe (q)));
1109 ** check that is it '<' and '>'
1110 ** should probably be in a different file?
1113 static void cylerror (/*@only@*/ char *s)
1120 checkBrackets (ltoken lb, ltoken rb)
1122 /* no attempt at error recovery...not really necessary */
1125 tname = ltoken_getRawString (lb);
1127 if (!cstring_equalLit (tname, "<"))
1129 cylerror (cstring_toCharsSafeO (message ("Invalid import token: %s", tname)));
1132 tname = ltoken_getRawString (rb);
1134 if (!cstring_equalLit (tname, ">"))
1136 cylerror (cstring_toCharsSafeO (message ("Invalid import token: %s", tname)));
1140 /*@only@*/ traitRefNode
1141 makeTraitRefNode (/*@only@*/ ltokenList fl, /*@only@*/ renamingNode r)
1143 traitRefNode n = (traitRefNode) dmalloc (sizeof (*n));
1151 ** printLeaves: no commas
1154 static /*@only@*/ cstring
1155 printLeaves (ltokenList f)
1157 bool firstone = TRUE;
1158 cstring s = cstring_undefined;
1160 ltokenList_elements (f, i)
1164 s = cstring_copy (ltoken_unparse (i));
1169 s = message ("%q %s", s, ltoken_unparse (i));
1171 } end_ltokenList_elements;
1178 printLeaves2 (ltokenList f)
1180 return (ltokenList_unparse (f));
1184 printRawLeaves2 (ltokenList f)
1187 cstring s = cstring_undefined;
1189 ltokenList_elements (f, i)
1193 s = message ("%s", ltoken_getRawString (i));
1197 s = message ("%q, %s", s, ltoken_getRawString (i));
1198 } end_ltokenList_elements;
1203 /*@only@*/ renamingNode
1204 makeRenamingNode (/*@only@*/ typeNameNodeList n, /*@only@*/ replaceNodeList r)
1206 renamingNode ren = (renamingNode) dmalloc (sizeof (*ren));
1208 if (typeNameNodeList_empty (n))
1210 ren->is_replace = TRUE;
1211 ren->content.replace = r;
1212 typeNameNodeList_free (n);
1216 nameAndReplaceNode nr = (nameAndReplaceNode) dmalloc (sizeof (*nr));
1217 nr->replacelist = r;
1219 ren->is_replace = FALSE;
1220 ren->content.name = nr;
1227 renamingNode_unparse (/*@null@*/ renamingNode x)
1229 if (x != (renamingNode) 0)
1233 return (replaceNodeList_unparse (x->content.replace));
1237 return (message ("%q%q", typeNameNodeList_unparse (x->content.name->namelist),
1238 replaceNodeList_unparse (x->content.name->replacelist)));
1241 return cstring_undefined;
1244 /*@only@*/ replaceNode
1245 makeReplaceNameNode (ltoken t, typeNameNode tn, nameNode nn)
1247 replaceNode r = (replaceNode) dmalloc (sizeof (*r));
1252 r->content.renamesortname.name = nn;
1253 r->content.renamesortname.signature = (sigNode)NULL;
1258 /*@only@*/ replaceNode
1259 makeReplaceNode (ltoken t, typeNameNode tn,
1260 bool is_ctype, ltoken ct,
1261 nameNode nn, sigNode sn)
1263 replaceNode r = (replaceNode) dmalloc (sizeof (*r));
1266 r->isCType = is_ctype;
1271 r->content.ctype = ct;
1277 r->content.renamesortname.name = nn;
1278 r->content.renamesortname.signature = sn;
1286 replaceNode_unparse (/*@null@*/ replaceNode x)
1288 if (x != (replaceNode) 0)
1292 st = message ("%q for ", typeNameNode_unparse (x->typename));
1296 st = message ("%q%s", st, ltoken_getRawString (x->content.ctype));
1300 st = message ("%q%q%q", st, nameNode_unparse (x->content.renamesortname.name),
1301 sigNode_unparse (x->content.renamesortname.signature));
1305 return cstring_undefined;
1309 makeNameNodeForm (/*@only@*/ /*@null@*/ opFormNode opform)
1311 nameNode nn = (nameNode) dmalloc (sizeof (*nn));
1314 nn->content.opform = opform;
1320 makeNameNodeId (/*@only@*/ ltoken opid)
1322 nameNode nn = (nameNode) dmalloc (sizeof (*nn));
1325 ** current LSL -syms output bug produces "if_then_else_" rather
1326 ** than 6 separate tokens
1329 if (ltoken_getText (opid) == ConditionalSymbol)
1331 opFormNode opform = makeOpFormNode (ltoken_undefined, OPF_IF,
1332 opFormUnion_createMiddle (0),
1335 nn->content.opform = opform;
1341 nn->content.opid = opid;
1348 nameNode_unparse (/*@null@*/ nameNode n)
1350 if (n != (nameNode) 0)
1354 return (cstring_copy (ltoken_getRawString (n->content.opid))); /*!!!*/
1358 return (opFormNode_unparse (n->content.opform));
1361 return cstring_undefined;
1365 makesigNode (ltoken t, /*@only@*/ ltokenList domain, ltoken range)
1367 sigNode s = (sigNode) dmalloc (sizeof (*s));
1371 ** Assign a hash key here to speed up lookup of operators.
1377 key = MASH (0, ltoken_getText (range));
1379 ltokenList_elements (domain, id)
1381 lsymbol sym = ltoken_getText (id);
1382 key = MASH (key, sym);
1383 } end_ltokenList_elements;
1389 cstring sigNode_unparse (/*@null@*/ sigNode n)
1391 if (n != (sigNode) 0)
1393 return (message (":%q -> %s", printLeaves2 (n->domain),
1394 ltoken_unparse (n->range)));
1397 return cstring_undefined;
1400 void sigNode_markOwned (sigNode n)
1402 sfreeEventually (n);
1406 sigNode_unparseText (/*@null@*/ sigNode n)
1408 if (n != (sigNode) 0)
1410 return (message ("%q -> %s", printLeaves2 (n->domain),
1411 ltoken_unparse (n->range)));
1413 return cstring_undefined;
1417 opFormNode2key (opFormNode op, opFormKind k)
1424 /* OPF_IF is the first enum, so it's 0 */
1427 key = MASH (k, k + 1);
1435 { /* treat eq and = the same */
1436 lsymbol sym = ltoken_getText (op->content.anyop);
1438 if (sym == equalSymbol)
1440 key = MASH (k, eqSymbol);
1444 key = MASH (k, ltoken_getText (op->content.anyop));
1456 key = MASH (k, op->content.middle);
1457 key = MASH (key, ltoken_getRawText (op->tok));
1463 key = MASH (k, ltoken_getRawText (op->content.id));
1472 /*@only@*/ opFormNode
1473 makeOpFormNode (ltoken t, opFormKind k, opFormUnion u,
1476 opFormNode n = (opFormNode) dmalloc (sizeof (*n));
1477 unsigned int key = 0;
1480 ** Assign a hash key here to speed up lookup of operators.
1491 n->content.middle = 0;
1492 /* OPF_IF is the first enum, so it's 0 */
1493 key = MASH /*@+enumint@*/ (k, k + 1) /*@=enumint@*/;
1499 { /* treat eq and = the same */
1500 lsymbol sym = ltoken_getText (u.anyop);
1502 if (sym == equalSymbol)
1504 key = MASH (k, eqSymbol);
1508 key = MASH (k, ltoken_getText (u.anyop));
1523 key = MASH (k, u.middle);
1524 key = MASH (key, ltoken_getRawText (t));
1530 key = MASH (k, ltoken_getRawText (u.id));
1535 llbug (message ("makeOpFormNode: unknown opFormKind: %d", (int) k));
1542 static cstring printMiddle (int j)
1545 char *s = mstring_createEmpty ();
1547 for (i = j; i >= 1; i--)
1549 s = mstring_concatFree1 (s, "__");
1553 s = mstring_concatFree1 (s, ", ");
1557 return cstring_fromCharsO (s);
1561 opFormNode_unparse (/*@null@*/ opFormNode n)
1563 if (n != (opFormNode) 0)
1568 return (cstring_makeLiteral ("if __ then __ else __ "));
1570 return (cstring_copy (ltoken_getRawString (n->content.anyop)));
1572 return (message ("__ %s", ltoken_getRawString (n->content.anyop)));
1574 return (message ("%s __ ", ltoken_getRawString (n->content.anyop)));
1576 return (message ("__ %s __ ", ltoken_getRawString (n->content.anyop)));
1578 return (message ("%s %q %s",
1579 ltoken_getRawString (n->tok),
1580 printMiddle (n->content.middle),
1581 ltoken_getRawString (n->close)));
1583 return (message ("__ %s %q %s",
1584 ltoken_getRawString (n->tok),
1585 printMiddle (n->content.middle),
1586 ltoken_getRawString (n->close)));
1588 return (message ("%s %q %s __",
1589 ltoken_getRawString (n->tok),
1590 printMiddle (n->content.middle),
1591 ltoken_getRawString (n->close)));
1593 return (message ("__ %s%q %s __",
1594 ltoken_getRawString (n->tok),
1595 printMiddle (n->content.middle),
1596 ltoken_getRawString (n->close)));
1598 return (message ("[%q]", printMiddle (n->content.middle)));
1600 return (message ("__ [%q]", printMiddle (n->content.middle)));
1602 return (message ("[%q] __", printMiddle (n->content.middle)));
1604 return (message ("__ [%q] __", printMiddle (n->content.middle)));
1606 return (message (" \\select %s", ltoken_getRawString (n->content.id)));
1608 return (message (" \\field_arrow%s", ltoken_getRawString (n->content.id)));
1610 return (message ("__ \\select %s", ltoken_getRawString (n->content.id)));
1612 return (message ("__ \\field_arrow %s", ltoken_getRawString (n->content.id)));
1614 llfatalbug (message ("opFormNodeUnparse: unknown kind: %d",
1618 return cstring_undefined;
1621 /*@only@*/ typeNameNode
1622 makeTypeNameNode (bool isObj, lclTypeSpecNode t, abstDeclaratorNode n)
1624 typeNameNode tn = (typeNameNode) dmalloc (sizeof (*tn));
1625 typeNamePack p = (typeNamePack) dmalloc (sizeof (*p));
1627 tn->isTypeName = TRUE;
1631 tn->opform = (opFormNode) 0;
1636 /*@only@*/ typeNameNode
1637 makeTypeNameNodeOp (opFormNode n)
1639 typeNameNode t = (typeNameNode) dmalloc (sizeof (*t));
1640 t->typename = (typeNamePack) 0;
1642 t->isTypeName = FALSE;
1647 typeNameNode_unparse (/*@null@*/ typeNameNode n)
1649 if (n != (typeNameNode) 0)
1653 cstring st = cstring_undefined;
1654 typeNamePack p = n->typename;
1656 llassert (p != NULL);
1659 st = cstring_makeLiteral ("obj ");
1661 return (message ("%q%q%q", st, lclTypeSpecNode_unparse (p->type),
1662 abstDeclaratorNode_unparse (p->abst)));
1666 return (opFormNode_unparse (n->opform));
1668 return cstring_undefined;
1671 /*@only@*/ lclTypeSpecNode
1672 makeLclTypeSpecNodeConj (/*@null@*/ lclTypeSpecNode a, /*@null@*/ lclTypeSpecNode b)
1674 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1678 n->quals = qualList_new ();
1679 n->content.conj = (lclconj) dmalloc (sizeof (*n->content.conj));
1680 n->content.conj->a = a;
1681 n->content.conj->b = b;
1686 /*@only@*/ lclTypeSpecNode
1687 makeLclTypeSpecNodeType (/*@null@*/ CTypesNode x)
1689 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1693 n->content.type = x;
1694 n->quals = qualList_new ();
1698 /*@only@*/ lclTypeSpecNode
1699 makeLclTypeSpecNodeSU (/*@null@*/ strOrUnionNode x)
1701 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1703 n->kind = LTS_STRUCTUNION;
1705 n->content.structorunion = x;
1706 n->quals = qualList_new ();
1710 /*@only@*/ lclTypeSpecNode
1711 makeLclTypeSpecNodeEnum (/*@null@*/ enumSpecNode x)
1713 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1715 n->quals = qualList_new ();
1718 n->content.enumspec = x;
1723 lclTypeSpecNode_addQual (lclTypeSpecNode n, qual q)
1725 llassert (lclTypeSpecNode_isDefined (n));
1726 n->quals = qualList_add (n->quals, q);
1731 lclTypeSpecNode_unparse (/*@null@*/ lclTypeSpecNode n)
1733 if (n != (lclTypeSpecNode) 0)
1738 llassert (n->content.type != NULL);
1739 return (printLeaves (n->content.type->ctypes));
1740 case LTS_STRUCTUNION:
1741 return (strOrUnionNode_unparse (n->content.structorunion));
1743 return (enumSpecNode_unparse (n->content.enumspec));
1745 return (lclTypeSpecNode_unparse (n->content.conj->a));
1747 llfatalbug (message ("lclTypeSpecNode_unparse: unknown lclTypeSpec kind: %d",
1751 return cstring_undefined;
1754 /*@only@*/ enumSpecNode
1755 makeEnumSpecNode (ltoken t, ltoken optTagId,
1756 /*@owned@*/ ltokenList enums)
1758 enumSpecNode n = (enumSpecNode) dmalloc (sizeof (*n));
1760 smemberInfo *top = smemberInfo_undefined;
1763 n->opttagid = ltoken_copy (optTagId);
1766 /* generate sort for this LCL type */
1767 n->sort = sort_makeEnum (optTagId);
1769 if (!ltoken_isUndefined (optTagId))
1771 /* First, check to see if tag is already defined */
1772 ti = symtable_tagInfo (g_symtab, ltoken_getText (optTagId));
1774 if (tagInfo_exists (ti))
1776 if (ti->kind == TAG_ENUM)
1778 /* 23 Sep 1995 --- had been noting here...is this right? */
1780 ti->content.enums = enums;
1782 ti->imported = context_inImport ();
1787 message ("Tag %s previously defined as %q, redefined as enum",
1788 ltoken_getRawString (optTagId),
1789 tagKind_unparse (ti->kind)));
1791 /* evs --- shouldn't they be in different name spaces? */
1794 ltoken_free (optTagId);
1798 ti = (tagInfo) dmalloc (sizeof (*ti));
1800 ti->kind = TAG_ENUM;
1802 ti->content.enums = enums;
1804 ti->imported = context_inImport ();
1805 /* First, store tag info in symbol table */
1806 (void) symtable_enterTag (g_symtab, ti);
1810 /* check that enumeration constants are unique */
1812 ltokenList_reset (enums);
1814 while (!ltokenList_isFinished (enums))
1816 ltoken c = ltokenList_current (enums);
1817 smemberInfo *ei = (smemberInfo *) dmalloc (sizeof (*ei));
1819 ei->name = ltoken_getText (c);
1824 if (!varInfo_exists (symtable_varInfo (g_symtab, ltoken_getText (c))))
1825 { /* put info into symbol table */
1826 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
1828 vi->id = ltoken_copy (c);
1829 vi->kind = VRK_ENUM;
1833 (void) symtable_enterVar (g_symtab, vi);
1838 lclerror (c, message ("Enumerated value redeclared: %s",
1839 ltoken_getRawString (c)));
1840 ltokenList_removeCurrent (enums);
1842 ltokenList_advance (enums);
1847 (void) sort_updateEnum (n->sort, top);
1851 /*@only@*/ enumSpecNode
1852 makeEnumSpecNode2 (ltoken t, ltoken tagid)
1854 /* a reference, not a definition */
1855 enumSpecNode n = (enumSpecNode) dmalloc (sizeof (*n));
1856 tagInfo ti = symtable_tagInfo (g_symtab, ltoken_getText (tagid));
1859 n->opttagid = tagid;
1860 n->enums = ltokenList_new ();
1862 if (tagInfo_exists (ti))
1864 if (ti->kind == TAG_ENUM)
1870 n->sort = sort_makeNoSort ();
1871 lclerror (tagid, message ("Tag %s defined as %q, used as enum",
1872 ltoken_getRawString (tagid),
1873 tagKind_unparse (ti->kind)));
1878 n->sort = sort_makeNoSort ();
1879 lclerror (t, message ("Undefined type: enum %s",
1880 ltoken_getRawString (tagid)));
1887 enumSpecNode_unparse (/*@null@*/ enumSpecNode n)
1889 if (n != (enumSpecNode) 0)
1891 cstring s = cstring_makeLiteral ("enum ");
1893 if (!ltoken_isUndefined (n->opttagid))
1895 s = message ("%q%s ", s, ltoken_getRawString (n->opttagid));
1898 s = message ("%q{%q}", s, printLeaves2 (n->enums));
1901 return cstring_undefined;
1904 /*@only@*/ strOrUnionNode
1905 makestrOrUnionNode (ltoken str, suKind k, ltoken opttagid,
1906 /*@only@*/ stDeclNodeList x)
1908 strOrUnionNode n = (strOrUnionNode) dmalloc (sizeof (*n));
1909 lsymbolSet set = lsymbolSet_new ();
1910 declaratorNodeList declarators;
1911 sort fieldsort, tsort1, tsort2;
1912 smemberInfo *mi, *top = smemberInfo_undefined;
1914 bool isStruct = (k == SU_STRUCT);
1920 n->opttagid = ltoken_copy (opttagid);
1922 n->sort = isStruct ? sort_makeStr (opttagid) : sort_makeUnion (opttagid);
1924 if (!ltoken_isUndefined (opttagid))
1926 /* First, check to see if tag is already defined */
1927 t = symtable_tagInfo (g_symtab, ltoken_getText (opttagid));
1929 if (tagInfo_exists (t))
1931 if ((t->kind == TAG_FWDUNION && k == SU_UNION) ||
1932 (t->kind == TAG_FWDSTRUCT && k == SU_STRUCT))
1934 /* to allow self-recursive types and forward tag declarations */
1935 t->content.decls = stDeclNodeList_copy (x); /* update tag info */
1941 message ("Tag %s previously defined as %q, used as %q",
1942 ltoken_getRawString (opttagid),
1943 tagKind_unparse (t->kind),
1944 cstring_makeLiteral (isStruct ? "struct" : "union")));
1957 if (doTag && !ltoken_isUndefined (opttagid))
1959 t = (tagInfo) dmalloc (sizeof (*t));
1961 /* can either override prev defn or use prev defn */
1962 /* override it so as to detect more errors */
1964 t->kind = (k == SU_STRUCT) ? TAG_STRUCT : TAG_UNION;
1966 t->content.decls = stDeclNodeList_copy (x);
1968 t->imported = FALSE;
1970 /* Next, update tag info in symbol table */
1971 (void) symtable_enterTagForce (g_symtab, t);
1974 /* check no duplicate field names */
1976 stDeclNodeList_elements (x, i)
1978 fieldsort = lclTypeSpecNode2sort (i->lcltypespec);
1980 /* need the locations, not values */
1981 /* fieldsort = sort_makeObj (fieldsort); */
1983 fieldsort = sort_makeGlobal (fieldsort); */
1985 declarators = i->declarators;
1987 declaratorNodeList_elements (declarators, decl)
1990 mi = (smemberInfo *) dmalloc (sizeof (*mi));
1991 /* need to make dynamic copies */
1992 fieldname = ltoken_getText (decl->id);
1994 /* 2/19/93, added */
1995 tsort1 = typeExpr2ptrSort (fieldsort, decl->type);
1996 tsort2 = sort_makeGlobal (tsort1);
1998 mi->name = fieldname;
1999 mi->sort = tsort2; /* fieldsort; */
2003 if (lsymbolSet_member (set, fieldname))
2006 message ("Field name reused: %s",
2007 ltoken_getRawString (decl->id)));
2011 (void) lsymbolSet_insert (set, fieldname);
2014 } end_declaratorNodeList_elements;
2016 } end_stDeclNodeList_elements;
2020 (void) sort_updateStr (n->sort, top);
2024 (void) sort_updateUnion (n->sort, top);
2027 /* We shall keep the info with both tags and types if any
2028 of them are present. */
2030 lsymbolSet_free (set);
2035 /*@only@*/ strOrUnionNode
2036 makeForwardstrOrUnionNode (ltoken str, suKind k,
2039 strOrUnionNode n = (strOrUnionNode) dmalloc (sizeof (*n));
2040 sort sort = sort_makeNoSort ();
2043 /* a reference, not a definition */
2047 n->opttagid = tagid;
2048 n->structdecls = stDeclNodeList_new ();
2050 /* get sort for this LCL type */
2051 t = symtable_tagInfo (g_symtab, ltoken_getText (tagid));
2053 if (tagInfo_exists (t))
2057 if (!(((t->kind == TAG_STRUCT || t->kind == TAG_FWDSTRUCT) && k == SU_STRUCT)
2058 || ((t->kind == TAG_UNION || t->kind == TAG_FWDUNION) && k == SU_UNION)))
2061 message ("Tag %s previously defined as %q, used as %q",
2062 ltoken_getRawString (tagid),
2063 tagKind_unparse (t->kind),
2064 cstring_makeLiteral ((k == SU_STRUCT) ? "struct" : "union")));
2070 ** changed from error: 31 Mar 1994
2072 ** lclerror (str, message ("Undefined type: %s %s", s, ltoken_getRawString (tagid));
2076 /* forward struct's and union's are ok... */
2080 (void) checkAndEnterTag (TAG_FWDSTRUCT, ltoken_copy (tagid));
2081 lhForwardStruct (tagid);
2082 sort = sort_makeStr (tagid);
2086 (void) checkAndEnterTag (TAG_FWDUNION, ltoken_copy (tagid));
2087 lhForwardUnion (tagid);
2088 sort = sort_makeUnion (tagid);
2097 strOrUnionNode_unparse (/*@null@*/ strOrUnionNode n)
2099 if (n != (strOrUnionNode) 0)
2105 s = cstring_makeLiteral ("struct ");
2108 s = cstring_makeLiteral ("union ");
2113 if (!ltoken_isUndefined (n->opttagid))
2115 s = message ("%q%s ", s, ltoken_getRawString (n->opttagid));
2117 s = message ("%q{%q}", s, stDeclNodeList_unparse (n->structdecls));
2120 return cstring_undefined;
2123 /*@only@*/ stDeclNode
2124 makestDeclNode (lclTypeSpecNode s,
2125 declaratorNodeList x)
2127 stDeclNode n = (stDeclNode) dmalloc (sizeof (*n));
2135 makeFunctionNode (typeExpr x, paramNodeList p)
2137 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2140 y->kind = TEXPR_FCN;
2141 y->content.function.returntype = x;
2142 y->content.function.args = p;
2143 y->sort = sort_makeNoSort ();
2148 static /*@observer@*/ ltoken
2149 extractDeclarator (/*@null@*/ typeExpr t)
2151 if (t != (typeExpr) 0)
2156 return t->content.base;
2158 return (extractDeclarator (t->content.pointer));
2160 return (extractDeclarator (t->content.array.elementtype));
2162 return (extractDeclarator (t->content.function.returntype));
2166 return ltoken_undefined;
2170 makeTypeExpr (ltoken t)
2172 typeExpr x = (typeExpr) dmalloc (sizeof (*x));
2176 x->kind = TEXPR_BASE;
2177 x->content.base = t;
2178 x->sort = sort_makeNoSort ();
2184 /*@only@*/ declaratorNode
2185 makeDeclaratorNode (typeExpr t)
2187 declaratorNode x = (declaratorNode) dmalloc (sizeof (*x));
2189 x->id = ltoken_copy (extractDeclarator (t));
2191 x->isRedecl = FALSE;
2196 static /*@only@*/ declaratorNode
2197 makeUnknownDeclaratorNode (/*@only@*/ ltoken t)
2199 declaratorNode x = (declaratorNode) dmalloc (sizeof (*x));
2202 x->type = (typeExpr) 0;
2203 x->isRedecl = FALSE;
2208 static /*@only@*/ cstring
2209 printTypeExpr2 (/*@null@*/ typeExpr x)
2211 paramNodeList params;
2213 if (x != (typeExpr) 0)
2215 cstring s; /* print out types in reverse order */
2220 return (message ("%s ", ltoken_getRawString (x->content.base)));
2222 return (message ("%qptr to ", printTypeExpr2 (x->content.pointer)));
2224 return (message ("array[%q] of %q",
2225 termNode_unparse (x->content.array.size),
2226 printTypeExpr2 (x->content.array.elementtype)));
2228 s = printTypeExpr2 (x->content.function.returntype);
2229 params = x->content.function.args;
2230 if (!paramNodeList_empty (params))
2232 s = message ("%qfcn with args: (%q)", s,
2233 paramNodeList_unparse (x->content.function.args));
2236 s = message ("%qfcn with no args", s);
2239 llfatalbug (message ("printTypeExpr2: unknown typeExprKind: %d", (int) x->kind));
2242 return cstring_undefined;
2246 declaratorNode_unparse (declaratorNode x)
2248 return (typeExpr_unparse (x->type));
2251 /*@only@*/ declaratorNode
2252 declaratorNode_copy (declaratorNode x)
2254 declaratorNode ret = (declaratorNode) dmalloc (sizeof (*ret));
2256 ret->type = typeExpr_copy (x->type);
2257 ret->id = ltoken_copy (x->id);
2258 ret->isRedecl = x->isRedecl;
2263 static /*@null@*/ typeExpr typeExpr_copy (/*@null@*/ typeExpr x)
2271 typeExpr ret = (typeExpr) dmalloc (sizeof (*ret));
2273 ret->wrapped = x->wrapped;
2274 ret->kind = x->kind;
2279 ret->content.base = ltoken_copy (x->content.base);
2282 ret->content.pointer = typeExpr_copy (x->content.pointer);
2285 ret->content.array.elementtype = typeExpr_copy (x->content.array.elementtype);
2286 ret->content.array.size = termNode_copy (x->content.array.size);
2289 ret->content.function.returntype = typeExpr_copy (x->content.function.returntype);
2290 ret->content.function.args = paramNodeList_copy (x->content.function.args);
2294 ret->sort = x->sort;
2299 static /*@only@*/ cstring
2300 typeExpr_unparseCode (/*@null@*/ typeExpr x)
2302 /* print out types in order of appearance in source */
2303 cstring s = cstring_undefined;
2305 if (x != (typeExpr) 0)
2310 return (cstring_copy (ltoken_getRawString (x->content.base)));
2312 return (typeExpr_unparseCode (x->content.pointer));
2314 return (typeExpr_unparseCode (x->content.array.elementtype));
2316 return (typeExpr_unparseCode (x->content.function.returntype));
2322 void typeExpr_free (/*@only@*/ /*@null@*/ typeExpr x)
2324 if (x != (typeExpr) 0)
2331 typeExpr_free (x->content.pointer);
2334 typeExpr_free (x->content.array.elementtype);
2335 termNode_free (x->content.array.size);
2338 typeExpr_free (x->content.function.returntype);
2339 paramNodeList_free (x->content.function.args);
2351 declaratorNode_unparseCode (declaratorNode x)
2353 return (typeExpr_unparseCode (x->type));
2357 typeExpr_unparse (/*@null@*/ typeExpr x)
2359 cstring s = cstring_undefined; /* print out types in order of appearance in source */
2360 paramNodeList params;
2363 if (x != (typeExpr) 0)
2365 cstring front = cstring_undefined;
2366 cstring back = cstring_undefined;
2368 llassert (x->wrapped < 100);
2370 for (i = x->wrapped; i >= 1; i--)
2372 front = cstring_appendChar (front, '(');
2373 back = cstring_appendChar (back, ')');
2379 s = message ("%q%s", s, ltoken_getRawString (x->content.base));
2382 s = message ("%q*%q", s, typeExpr_unparse (x->content.pointer));
2385 s = message ("%q%q[%q]", s,
2386 typeExpr_unparse (x->content.array.elementtype),
2387 termNode_unparse (x->content.array.size));
2390 s = message ("%q%q (", s,
2391 typeExpr_unparse (x->content.function.returntype));
2392 params = x->content.function.args;
2394 if (!paramNodeList_empty (params))
2396 s = message ("%q%q", s,
2397 paramNodeList_unparse (x->content.function.args));
2400 s = message ("%q)", s);
2403 s = message ("%q%q%q", front, s, back);
2407 s = cstring_makeLiteral ("?");
2414 typeExpr_unparseNoBase (/*@null@*/ typeExpr x)
2416 cstring s = cstring_undefined; /* print out types in order of appearance in source */
2417 paramNodeList params;
2420 if (x != (typeExpr) 0)
2422 cstring front = cstring_undefined;
2423 cstring back = cstring_undefined;
2425 llassert (x->wrapped < 100);
2427 for (i = x->wrapped; i >= 1; i--)
2429 front = cstring_appendChar (front, '(');
2430 back = cstring_appendChar (back, ')');
2436 s = message ("%q /* %s */", s, ltoken_getRawString (x->content.base));
2439 s = message ("%q*%q", s, typeExpr_unparseNoBase (x->content.pointer));
2442 s = message ("%q%q[%q]", s,
2443 typeExpr_unparseNoBase (x->content.array.elementtype),
2444 termNode_unparse (x->content.array.size));
2447 s = message ("%q%q (", s,
2448 typeExpr_unparseNoBase (x->content.function.returntype));
2449 params = x->content.function.args;
2451 if (!paramNodeList_empty (params))
2453 s = message ("%q%q", s,
2454 paramNodeList_unparse (x->content.function.args));
2457 s = message ("%q)", s);
2460 s = message ("%q%q%q", front, s, back);
2464 s = cstring_makeLiteral ("?");
2471 typeExpr_name (/*@null@*/ typeExpr x)
2473 if (x != (typeExpr) 0)
2478 return (cstring_copy (ltoken_getRawString (x->content.base)));
2480 return (typeExpr_name (x->content.pointer));
2482 return (typeExpr_name (x->content.array.elementtype));
2484 return (typeExpr_name (x->content.function.returntype));
2488 /* evs --- 14 Mar 1995
2489 ** not a bug: its okay to have empty parameter names
2490 ** llbug ("typeExpr_name: null");
2493 return cstring_undefined;
2497 makePointerNode (ltoken star, /*@only@*/ /*@returned@*/ typeExpr x)
2499 if (x != (typeExpr)0 && (x->kind == TEXPR_FCN && (x->wrapped == 0)))
2501 x->content.function.returntype = makePointerNode (star, x->content.function.returntype);
2506 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2509 y->kind = TEXPR_PTR;
2510 y->content.pointer = x;
2511 y->sort = sort_makeNoSort ();
2518 typeExpr makeArrayNode (/*@returned@*/ typeExpr x,
2519 /*@only@*/ arrayQualNode a)
2521 if (x != (typeExpr)0 && (x->kind == TEXPR_FCN && (x->wrapped == 0)))
2524 ** Spurious errors reported here, because of referencing
2525 ** in makeArrayNode.
2528 /*@i3@*/ x->content.function.returntype = makeArrayNode (x, a);
2533 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2535 y->kind = TEXPR_ARRAY;
2537 if (a == (arrayQualNode) 0)
2539 y->content.array.size = (termNode) 0;
2543 y->content.array.size = a->term;
2544 ltoken_free (a->tok);
2548 y->content.array.elementtype = x;
2549 y->sort = sort_makeNoSort ();
2555 /*@only@*/ constDeclarationNode
2556 makeConstDeclarationNode (lclTypeSpecNode t, initDeclNodeList decls)
2558 constDeclarationNode n = (constDeclarationNode) dmalloc (sizeof (*n));
2559 sort s, s2, initValueSort;
2560 ltoken varid, errtok;
2563 s = lclTypeSpecNode2sort (t);
2565 initDeclNodeList_elements (decls, init)
2567 declaratorNode vdnode = init->declarator;
2568 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
2570 varid = ltoken_copy (vdnode->id);
2571 s2 = typeExpr2ptrSort (s, vdnode->type);
2572 initValue = init->value;
2574 if (termNode_isDefined (initValue) && !initValue->error_reported)
2576 initValueSort = initValue->sort;
2578 /* should keep the arguments in order */
2579 if (!sort_member_modulo_cstring (s2, initValue)
2580 && !initValue->error_reported)
2582 errtok = termNode_errorToken (initValue);
2586 message ("Constant %s declared type %q, initialized to %q: %q",
2587 ltoken_unparse (varid),
2589 sort_unparse (initValueSort),
2590 termNode_unparse (initValue)));
2595 vi->kind = VRK_CONST;
2599 (void) symtable_enterVar (g_symtab, vi);
2602 } end_initDeclNodeList_elements;
2610 varDeclarationNode makeInternalStateNode (void)
2612 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2614 n->isSpecial = TRUE;
2615 n->sref = sRef_makeInternalState ();
2617 /*@-compdef@*/ return n; /*@=compdef@*/
2620 varDeclarationNode makeFileSystemNode (void)
2622 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2624 n->isSpecial = TRUE;
2625 n->sref = sRef_makeSystemState ();
2627 /*@-compdef@*/ return n; /*@=compdef@*/
2630 /*@only@*/ varDeclarationNode
2631 makeVarDeclarationNode (lclTypeSpecNode t, initDeclNodeList x,
2632 bool isGlobal, bool isPrivate)
2634 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2635 sort s, s2, initValueSort;
2636 ltoken varid, errtok;
2638 declaratorNode vdnode;
2640 n->isSpecial = FALSE;
2641 n->qualifier = QLF_NONE;
2642 n->isGlobal = isGlobal;
2643 n->isPrivate = isPrivate;
2646 s = lclTypeSpecNode2sort (t);
2648 /* t is an lclTypeSpec, its sort may not be assigned yet */
2650 initDeclNodeList_elements (x, init)
2652 vdnode = init->declarator;
2654 s2 = typeExpr2ptrSort (s, vdnode->type);
2655 initValue = init->value;
2657 if (termNode_isDefined (initValue) && !initValue->error_reported)
2659 initValueSort = initValue->sort;
2660 /* should keep the arguments in order */
2661 if (!sort_member_modulo_cstring (s2, initValue)
2662 && !initValue->error_reported)
2664 errtok = termNode_errorToken (initValue);
2667 message ("Variable %s declared type %q, initialized to %q",
2668 ltoken_unparse (varid),
2670 sort_unparse (initValueSort)));
2675 ** If global, check that it has been declared already, don't push
2676 ** onto symbol table yet (wrong scope, done in enteringFcnScope
2681 varInfo vi = symtable_varInfo (g_symtab, ltoken_getText (varid));
2683 if (!varInfo_exists (vi))
2686 message ("Undeclared global variable: %s",
2687 ltoken_getRawString (varid)));
2691 if (vi->kind == VRK_CONST)
2694 message ("Constant used in global list: %s",
2695 ltoken_getRawString (varid)));
2701 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
2703 vi->id = ltoken_copy (varid);
2706 vi->kind = VRK_PRIVATE;
2707 /* check that initValue is not empty */
2708 if (initValue == (termNode) 0)
2711 message ("Private variable must have initialization: %s",
2712 ltoken_getRawString (varid)));
2720 vi->sort = sort_makeGlobal (s2);
2723 vdnode->isRedecl = symtable_enterVar (g_symtab, vi);
2726 } end_initDeclNodeList_elements;
2733 /*@only@*/ initDeclNode
2734 makeInitDeclNode (declaratorNode d, termNode x)
2736 initDeclNode n = (initDeclNode) dmalloc (sizeof (*n));
2743 /*@only@*/ abstractNode
2744 makeAbstractNode (ltoken t, ltoken name,
2745 bool isMutable, bool isRefCounted, abstBodyNode a)
2747 abstractNode n = (abstractNode) dmalloc (sizeof (*n));
2749 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
2752 n->isMutable = isMutable;
2755 n->isRefCounted = isRefCounted;
2758 handle = sort_makeMutable (name, ltoken_getText (name));
2760 handle = sort_makeImmutable (name, ltoken_getText (name));
2763 ti->id = ltoken_createType (ltoken_getCode (ltoken_typename), SID_TYPE,
2764 ltoken_getText (name));
2765 ti->modifiable = isMutable;
2766 ti->abstract = TRUE;
2767 ti->basedOn = handle;
2770 symtable_enterType (g_symtab, ti);
2777 abstractNode_unparse (abstractNode n)
2779 if (n != (abstractNode) 0)
2784 s = cstring_makeLiteral ("mutable");
2786 s = cstring_makeLiteral ("immutable");
2788 return (message ("%q type %s%q;", s, ltoken_getRawString (n->name),
2789 abstBodyNode_unparse (n->body)));
2791 return cstring_undefined;
2795 setExposedType (lclTypeSpecNode s)
2800 /*@only@*/ exposedNode
2801 makeExposedNode (ltoken t, lclTypeSpecNode s,
2802 declaratorInvNodeList d)
2804 exposedNode n = (exposedNode) dmalloc (sizeof (*n));
2814 exposedNode_unparse (exposedNode n)
2816 if (n != (exposedNode) 0)
2818 return (message ("typedef %q %q;",
2819 lclTypeSpecNode_unparse (n->type),
2820 declaratorInvNodeList_unparse (n->decls)));
2822 return cstring_undefined;
2825 /*@only@*/ declaratorInvNode
2826 makeDeclaratorInvNode (declaratorNode d, abstBodyNode b)
2828 declaratorInvNode n = (declaratorInvNode) dmalloc (sizeof (*n));
2836 declaratorInvNode_unparse (declaratorInvNode d)
2838 return (message ("%q%q", declaratorNode_unparse (d->declarator),
2839 abstBodyNode_unparseExposed (d->body)));
2843 abstBodyNode_unparse (abstBodyNode n)
2845 if (n != (abstBodyNode) 0)
2847 return (lclPredicateNode_unparse (n->typeinv));
2849 return cstring_undefined;
2853 abstBodyNode_unparseExposed (abstBodyNode n)
2855 if (n != (abstBodyNode) 0)
2857 return (message ("%q", lclPredicateNode_unparse (n->typeinv)));
2859 return cstring_undefined;
2863 taggedUnionNode_unparse (taggedUnionNode n)
2865 if (n != (taggedUnionNode) 0)
2867 return (message ("tagged union {%q}%q;\n",
2868 stDeclNodeList_unparse (n->structdecls),
2869 declaratorNode_unparse (n->declarator)));
2871 return cstring_undefined;
2874 static /*@observer@*/ paramNodeList
2875 typeExpr_toParamNodeList (/*@null@*/ typeExpr te)
2877 if (te != (typeExpr) 0)
2882 return te->content.function.args;
2884 return typeExpr_toParamNodeList (te->content.pointer);
2886 /* return typeExpr_toParamNodeList (te->content.array.elementtype); */
2888 return paramNodeList_undefined;
2891 return paramNodeList_undefined;
2895 fcnNode_fromDeclarator (/*@only@*/ /*@null@*/ lclTypeSpecNode t,
2896 /*@only@*/ declaratorNode d)
2898 return (makeFcnNode (QU_UNKNOWN, t, d,
2899 varDeclarationNodeList_new (),
2900 varDeclarationNodeList_new (),
2901 letDeclNodeList_new (),
2902 (lclPredicateNode) 0,
2903 (lclPredicateNode) 0,
2905 (lclPredicateNode) 0,
2906 (lclPredicateNode) 0));
2910 makeIterNode (ltoken id, paramNodeList p)
2912 iterNode x = (iterNode) dmalloc (sizeof (*x));
2913 bool hasYield = FALSE;
2918 /* check there is at least one yield param */
2920 paramNodeList_elements (p, pe)
2922 if (paramNode_isYield (pe))
2927 } end_paramNodeList_elements
2931 lclerror (id, message ("Iterator has no yield parameters: %s",
2932 ltoken_getRawString (id)));
2939 makeFcnNode (qual specQual,
2940 /*@null@*/ lclTypeSpecNode t,
2942 /*@null@*/ globalList g,
2943 /*@null@*/ varDeclarationNodeList privateinits,
2944 /*@null@*/ letDeclNodeList lets,
2945 /*@null@*/ lclPredicateNode checks,
2946 /*@null@*/ lclPredicateNode requires,
2947 /*@null@*/ modifyNode m,
2948 /*@null@*/ lclPredicateNode ensures,
2949 /*@null@*/ lclPredicateNode claims)
2951 fcnNode x = (fcnNode) dmalloc (sizeof (*x));
2953 if (d->type != (typeExpr)0 && (d->type)->kind != TEXPR_FCN)
2955 lclerror (d->id, cstring_makeLiteral
2956 ("Attempt to specify function without parameter list"));
2957 d->type = makeFunctionNode (d->type, paramNodeList_new ());
2961 x->special = specQual;
2965 x->inits = privateinits;
2968 x->require = requires;
2970 x->ensures = ensures;
2973 /* extract info to fill in x->name =; x->signature =; */
2974 x->name = ltoken_copy (d->id);
2979 /*@only@*/ claimNode
2980 makeClaimNode (ltoken id, paramNodeList p,
2981 globalList g, letDeclNodeList lets, lclPredicateNode requires,
2982 programNode b, lclPredicateNode ensures)
2984 claimNode x = (claimNode) dmalloc (sizeof (*x));
2991 x->require = requires;
2993 x->ensures = ensures;
2997 /*@only@*/ lclPredicateNode
2998 makeIntraClaimNode (ltoken t, lclPredicateNode n)
3000 ltoken_free (n->tok);
3002 n->kind = LPD_INTRACLAIM;
3006 /*@only@*/ lclPredicateNode
3007 makeRequiresNode (ltoken t, lclPredicateNode n)
3009 ltoken_free (n->tok);
3011 n->kind = LPD_REQUIRES;
3015 /*@only@*/ lclPredicateNode
3016 makeChecksNode (ltoken t, lclPredicateNode n)
3018 ltoken_free (n->tok);
3020 n->kind = LPD_CHECKS;
3024 /*@only@*/ lclPredicateNode
3025 makeEnsuresNode (ltoken t, lclPredicateNode n)
3027 ltoken_free (n->tok);
3029 n->kind = LPD_ENSURES;
3033 /*@only@*/ lclPredicateNode
3034 makeLclPredicateNode (ltoken t, termNode n,
3037 lclPredicateNode x = (lclPredicateNode) dmalloc (sizeof (*x));
3045 /*@only@*/ quantifierNode
3046 makeQuantifierNode (varNodeList v, ltoken quant)
3048 quantifierNode x = (quantifierNode) dmalloc (sizeof (*x));
3052 x->isForall = cstring_equalLit (ltoken_unparse (quant), "\forall");
3057 /*@only@*/ arrayQualNode
3058 makeArrayQualNode (ltoken t, termNode term)
3060 arrayQualNode x = (arrayQualNode) dmalloc (sizeof (*x));
3068 makeVarNode (/*@only@*/ ltoken varid, bool isObj, lclTypeSpecNode t)
3070 varNode x = (varNode) dmalloc (sizeof (*x));
3071 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
3074 vi->id = ltoken_copy (varid);
3075 sort = lclTypeSpecNode2sort (t);
3077 /* 9/3/93, The following is needed because we want value sorts to be
3078 the default, object sort is generated only if there is "obj" qualifier.
3079 There are 2 cases: (1) for immutable types (including C primitive types),
3080 we need to generate the object sort if qualifier is present; (2) for
3081 array, struct and union types, they are already in their object sorts.
3084 sort = sort_makeVal (sort); /* both cases are now value sorts */
3088 sort = sort_makeObj (sort);
3093 vi->kind = VRK_QUANT;
3096 (void) symtable_enterVar (g_symtab, vi);
3102 x->sort = sort_makeNoSort ();
3107 /*@only@*/ abstBodyNode
3108 makeAbstBodyNode (ltoken t, fcnNodeList f)
3110 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3113 x->typeinv = (lclPredicateNode)0;
3118 /*@only@*/ abstBodyNode
3119 makeExposedBodyNode (ltoken t, lclPredicateNode inv)
3121 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3125 x->fcns = fcnNodeList_undefined;
3129 /*@only@*/ abstBodyNode
3130 makeAbstBodyNode2 (ltoken t, ltokenList ops)
3132 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3135 x->typeinv = (lclPredicateNode) 0;
3137 x->fcns = fcnNodeList_new ();
3139 ltokenList_elements (ops, op)
3141 x->fcns = fcnNodeList_add
3143 fcnNode_fromDeclarator (lclTypeSpecNode_undefined,
3144 makeUnknownDeclaratorNode (ltoken_copy (op))));
3145 } end_ltokenList_elements;
3147 ltokenList_free (ops);
3153 makeStmtNode (ltoken varId, ltoken fcnId, /*@only@*/ termNodeList v)
3155 stmtNode n = (stmtNode) dmalloc (sizeof (*n));
3158 n->operator = fcnId;
3163 /* printDeclarators -> declaratorNodeList_unparse */
3165 static cstring abstDeclaratorNode_unparse (abstDeclaratorNode x)
3167 return (typeExpr_unparse ((typeExpr) x));
3170 /*@only@*/ paramNode
3171 makeParamNode (lclTypeSpecNode t, typeExpr d)
3173 paramNode x = (paramNode) dmalloc (sizeof (*x));
3175 paramNode_checkQualifiers (t, d);
3179 x->kind = PNORMAL; /*< forgot this! >*/
3184 /*@only@*/ paramNode
3185 paramNode_elipsis (void)
3187 paramNode x = (paramNode) dmalloc (sizeof (*x));
3189 x->type = (lclTypeSpecNode) 0;
3190 x->paramdecl = (typeExpr) 0;
3196 static /*@observer@*/ ltoken typeExpr_getTok (typeExpr d)
3198 while (d != (typeExpr)0)
3200 if (d->kind == TEXPR_BASE)
3202 return (d->content.base);
3206 if (d->kind == TEXPR_PTR)
3208 d = d->content.pointer;
3210 else if (d->kind == TEXPR_ARRAY)
3212 d = d->content.array.elementtype;
3214 else if (d->kind == TEXPR_FCN)
3216 d = d->content.function.returntype;
3225 llfatalerror (cstring_makeLiteral ("typeExpr_getTok: unreachable code"));
3230 paramNode_checkQualifiers (lclTypeSpecNode t, typeExpr d)
3232 bool isPointer = FALSE;
3233 bool isUser = FALSE;
3234 bool hasAlloc = FALSE;
3235 bool hasAlias = FALSE;
3237 llassert (lclTypeSpecNode_isDefined (t));
3239 if (t->pointers == 0
3240 && (d != (typeExpr)0 && d->kind != TEXPR_PTR) && d->kind != TEXPR_ARRAY)
3242 if (t->kind == LTS_TYPE)
3246 llassert (t->content.type != NULL);
3248 sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
3250 if (sn.kind == SRT_PTR || sn.kind == SRT_ARRAY
3251 || sn.kind == SRT_HOF || sn.kind == SRT_NONE)
3262 if (d != (typeExpr)0 && d->kind != TEXPR_BASE)
3264 if (t->kind == LTS_TYPE)
3268 llassert (t->content.type != NULL);
3269 sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
3271 if (sn.kind == SRT_PTR || sn.kind == SRT_ARRAY
3272 || sn.kind == SRT_HOF || sn.kind == SRT_NONE)
3283 if (d != (typeExpr)NULL)
3285 qualList_elements (t->quals, q)
3287 if (qual_isAllocQual (q))
3291 ltoken tok = typeExpr_getTok (d);
3292 lclerror (tok, message ("Parameter declared with multiple allocation "
3293 "qualifiers: %q", typeExpr_unparse (d)));
3299 ltoken tok = typeExpr_getTok (d);
3300 lclerror (tok, message ("Non-pointer declared as %s parameter: %q",
3302 typeExpr_unparse (d)));
3305 if (qual_isAliasQual (q))
3309 ltoken tok = typeExpr_getTok (d);
3310 lclerror (tok, message ("Parameter declared with multiple alias qualifiers: %q",
3311 typeExpr_unparse (d)));
3315 if (!(isPointer || isUser))
3317 ltoken tok = typeExpr_getTok (d);
3318 lclerror (tok, message ("Unsharable type declared as %s parameter: %q",
3320 typeExpr_unparse (d)));
3323 } end_qualList_elements;
3328 paramNode_unparse (paramNode x)
3330 if (x != (paramNode) 0)
3332 if (x->kind == PELIPSIS)
3334 return (cstring_makeLiteral ("..."));
3337 if (x->paramdecl != (typeExpr) 0)
3338 { /* handle (void) */
3339 return (message ("%q %q", lclTypeSpecNode_unparse (x->type),
3340 typeExpr_unparse (x->paramdecl)));
3344 return (lclTypeSpecNode_unparse (x->type));
3347 return cstring_undefined;
3351 lclTypeSpecNode_unparseAltComments (/*@null@*/ lclTypeSpecNode typespec) /*@*/
3353 if (typespec != (lclTypeSpecNode) 0)
3355 cstring s = qualList_toCComments (typespec->quals);
3357 switch (typespec->kind)
3361 llassert (typespec->content.type != NULL);
3363 return (cstring_concatFree
3364 (s, printLeaves (typespec->content.type->ctypes)));
3369 enumSpecNode n = typespec->content.enumspec;
3371 s = cstring_concatFree (s, cstring_makeLiteral ("enum"));
3372 llassert (n != NULL);
3374 if (!ltoken_isUndefined (n->opttagid))
3376 s = message ("%q %s", s, ltoken_unparse (n->opttagid));
3378 s = message ("%q {", s);
3380 ltokenList_elements (n->enums, e)
3385 s = message ("%q%s", s, ltoken_getRawString (e));
3388 s = message ("%q, %s", s, ltoken_getRawString (e));
3389 } end_ltokenList_elements;
3391 return (message ("%q}", s));
3393 case LTS_STRUCTUNION:
3395 strOrUnionNode n = typespec->content.structorunion;
3396 stDeclNodeList decls;
3398 llassert (n != NULL);
3403 s = cstring_concatFree (s, cstring_makeLiteral ("struct "));
3404 /*@switchbreak@*/ break;
3406 s = cstring_concatFree (s, cstring_makeLiteral ("union "));
3407 /*@switchbreak@*/ break;
3410 if (!ltoken_isUndefined (n->opttagid))
3412 if (stDeclNodeList_size (n->structdecls) == 0)
3414 return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
3417 s = message ("%q%s {\n\2\1", s, ltoken_unparse (n->opttagid));
3421 s = message ("%q{\n\2\1", s);
3424 decls = n->structdecls;
3426 stDeclNodeList_elements (decls, f)
3428 s = message ("%q%q\1%q;\n\1", s,
3429 lclTypeSpecNode_unparseAltComments (f->lcltypespec),
3430 declaratorNodeList_unparse (f->declarators));
3431 } end_stDeclNodeList_elements;
3433 return (message ("%q\3}", s));
3442 lclTypeSpecNode_unparseAltComments (typespec->content.conj->a),
3443 lclTypeSpecNode_unparseAltComments (typespec->content.conj->b)));
3450 llcontbuglit ("lclTypeSpecNode_unparseComments: null typespec");
3452 return cstring_undefined;
3458 cstring lclTypeSpecNode_unparseComments (/*@null@*/ lclTypeSpecNode typespec)
3460 if (typespec != (lclTypeSpecNode) 0)
3462 cstring s = qualList_toCComments (typespec->quals);
3464 switch (typespec->kind)
3468 llassert (typespec->content.type != NULL);
3470 return (cstring_concatFree
3471 (s, printLeaves (typespec->content.type->ctypes)));
3476 enumSpecNode n = typespec->content.enumspec;
3478 s = cstring_concatFree (s, cstring_makeLiteral ("enum"));
3479 llassert (n != NULL);
3481 if (!ltoken_isUndefined (n->opttagid))
3483 s = message ("%q %s", s, ltoken_unparse (n->opttagid));
3485 s = message ("%q {", s);
3487 ltokenList_elements (n->enums, e)
3492 s = message ("%q%s", s, ltoken_getRawString (e));
3495 s = message ("%q, %s", s, ltoken_getRawString (e));
3496 } end_ltokenList_elements;
3498 return (message ("%q}", s));
3500 case LTS_STRUCTUNION:
3502 strOrUnionNode n = typespec->content.structorunion;
3503 stDeclNodeList decls;
3505 llassert (n != NULL);
3510 s = cstring_concatFree (s, cstring_makeLiteral ("struct "));
3511 /*@switchbreak@*/ break;
3513 s = cstring_concatFree (s, cstring_makeLiteral ("union "));
3514 /*@switchbreak@*/ break;
3517 if (!ltoken_isUndefined (n->opttagid))
3519 if (stDeclNodeList_size (n->structdecls) == 0)
3521 return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
3524 s = message ("%q%s {\n\2\1", s, ltoken_unparse (n->opttagid));
3528 s = message ("%q{\n\2\1", s);
3531 decls = n->structdecls;
3533 stDeclNodeList_elements (decls, f)
3535 s = message ("%q%q\1%q;\n\1", s,
3536 lclTypeSpecNode_unparseComments (f->lcltypespec),
3537 declaratorNodeList_unparse (f->declarators));
3538 } end_stDeclNodeList_elements;
3540 return (message ("%q\3}", s));
3549 lclTypeSpecNode_unparseComments (typespec->content.conj->a),
3550 lclTypeSpecNode_unparseAltComments (typespec->content.conj->b)));
3557 llcontbuglit ("lclTypeSpecNode_unparseComments: null typespec");
3559 return cstring_undefined;
3566 paramNode_unparseComments (paramNode x)
3568 if (x != (paramNode) 0)
3570 if (x->kind == PELIPSIS)
3572 return (cstring_makeLiteral ("..."));
3575 if (x->paramdecl != (typeExpr) 0)
3576 { /* handle (void) */
3577 return (message ("%q %q",
3578 lclTypeSpecNode_unparseComments (x->type),
3579 typeExpr_unparseNoBase (x->paramdecl)));
3583 return (lclTypeSpecNode_unparseComments (x->type));
3586 return cstring_undefined;
3590 makeIfTermNode (ltoken ift, termNode ifn, ltoken thent,
3591 termNode thenn, ltoken elset,
3594 termNode t = (termNode) dmalloc (sizeof (*t));
3595 opFormNode opform = makeOpFormNode (ift, OPF_IF, opFormUnion_createMiddle (0),
3597 nameNode nn = makeNameNodeForm (opform);
3598 termNodeList args = termNodeList_new ();
3600 t->error_reported = FALSE;
3602 termNodeList_addh (args, ifn);
3603 termNodeList_addh (args, thenn);
3604 termNodeList_addh (args, elsen);
3607 t->kind = TRM_APPLICATION;
3608 t->sort = sort_makeNoSort ();
3610 t->possibleSorts = sortSet_new ();
3611 t->possibleOps = lslOpSet_new ();
3613 ltoken_free (thent);
3614 ltoken_free (elset);
3619 static /*@observer@*/ ltoken
3620 nameNode2anyOp (nameNode n)
3622 if (n != (nameNode) 0)
3624 opFormNode opnode = n->content.opform;
3627 llassert (opnode != NULL);
3629 kind = opnode->kind;
3631 if (kind == OPF_MANYOPM || kind == OPF_ANYOP ||
3632 kind == OPF_MANYOP || kind == OPF_ANYOPM)
3636 u = opnode->content;
3640 return ltoken_undefined;
3644 makeInfixTermNode (termNode x, ltoken op, termNode y)
3646 termNode t = (termNode) dmalloc (sizeof (*t));
3649 termNodeList args = termNodeList_new ();
3651 checkAssociativity (x, op);
3653 opform = makeOpFormNode (op, OPF_MANYOPM,
3654 opFormUnion_createAnyOp (op),
3657 nn = makeNameNodeForm (opform);
3659 t->error_reported = FALSE;
3661 termNodeList_addh (args, x);
3662 termNodeList_addh (args, y);
3665 t->kind = TRM_APPLICATION;
3666 t->sort = sort_makeNoSort ();
3668 t->possibleSorts = sortSet_new (); /* sort_equal */
3669 t->possibleOps = lslOpSet_new ();
3673 /*@only@*/ quantifiedTermNode
3674 quantifiedTermNode_copy (quantifiedTermNode q)
3676 quantifiedTermNode ret = (quantifiedTermNode) dmalloc (sizeof (*ret));
3678 ret->quantifiers = quantifierNodeList_copy (q->quantifiers);
3679 ret->open = ltoken_copy (q->open);
3680 ret->close = ltoken_copy (q->close);
3681 ret->body = termNode_copySafe (q->body);
3687 makeQuantifiedTermNode (quantifierNodeList qn, ltoken open,
3688 termNode t, ltoken close)
3691 termNode n = (termNode) dmalloc (sizeof (*n));
3692 quantifiedTermNode q = (quantifiedTermNode) dmalloc (sizeof (*q));
3694 n->name = NULL; /*> missing this --- detected by lclint <*/
3695 n->error_reported = FALSE;
3697 n->error_reported = FALSE;
3698 n->kind = TRM_QUANTIFIER;
3699 n->possibleSorts = sortSet_new ();
3700 n->possibleOps = lslOpSet_new ();
3701 n->kind = TRM_UNCHANGEDALL;
3702 n->args = termNodeList_new (); /*< forgot this >*/
3704 termNodeList_free (t->args);
3705 t->args = termNodeList_new ();
3709 (void) sortSet_insert (n->possibleSorts, sort);
3711 q->quantifiers = qn;
3721 makePostfixTermNode (/*@returned@*/ /*@only@*/ termNode secondary, ltokenList postfixops)
3723 termNode top = secondary;
3725 ltokenList_elements (postfixops, op)
3727 top = makePostfixTermNode2 (top, ltoken_copy (op));
3728 /*@i@*/ } end_ltokenList_elements;
3730 ltokenList_free (postfixops);
3732 return (top); /* dep as only? */
3736 ** secondary is returned in the args list
3740 makePostfixTermNode2 (/*@returned@*/ /*@only@*/ termNode secondary,
3741 /*@only@*/ ltoken postfixop)
3743 termNode t = (termNode) dmalloc (sizeof (*t));
3745 opFormNode opform = makeOpFormNode (postfixop,
3746 OPF_MANYOP, opFormUnion_createAnyOp (postfixop),
3748 nameNode nn = makeNameNodeForm (opform);
3749 termNodeList args = termNodeList_new ();
3751 t->error_reported = FALSE;
3753 termNodeList_addh (args, secondary);
3756 t->kind = TRM_APPLICATION;
3757 t->sort = sort_makeNoSort ();
3759 t->possibleSorts = sortSet_new ();
3760 t->possibleOps = lslOpSet_new ();
3765 makePrefixTermNode (ltoken op, termNode arg)
3767 termNode t = (termNode) dmalloc (sizeof (*t));
3768 termNodeList args = termNodeList_new ();
3769 opFormNode opform = makeOpFormNode (op, OPF_ANYOPM, opFormUnion_createAnyOp (op),
3771 nameNode nn = makeNameNodeForm (opform);
3773 t->error_reported = FALSE;
3776 termNodeList_addh (args, arg);
3778 t->kind = TRM_APPLICATION;
3779 t->sort = sort_makeNoSort ();
3781 t->possibleSorts = sortSet_new ();
3782 t->possibleOps = lslOpSet_new ();
3787 makeOpCallTermNode (ltoken op, ltoken open,
3788 termNodeList args, ltoken close)
3790 /* like prefixTerm, but with opId LPAR termNodeList RPAR */
3791 termNode t = (termNode) dmalloc (sizeof (*t));
3792 nameNode nn = makeNameNodeId (op);
3794 t->error_reported = FALSE;
3798 t->kind = TRM_APPLICATION;
3799 t->sort = sort_makeNoSort ();
3801 t->possibleSorts = sortSet_new ();
3802 t->possibleOps = lslOpSet_new ();
3805 ltoken_free (close);
3810 /*@exposed@*/ termNode
3811 CollapseInfixTermNode (/*@returned@*/ termNode secondary, termNodeList infix)
3813 termNode left = secondary;
3815 termNodeList_elements (infix, node)
3817 termNodeList_addl (node->args, termNode_copySafe (left));
3819 /* computePossibleSorts (left); */
3820 } end_termNodeList_elements;
3826 checkAssociativity (termNode x, ltoken op)
3830 if (x->wrapped == 0 && /* no parentheses */
3831 x->kind == TRM_APPLICATION && x->name != (nameNode) 0 &&
3834 lastOpToken = nameNode2anyOp (x->name);
3836 if ((ltoken_getCode (lastOpToken) == logicalOp &&
3837 ltoken_getCode (op) == logicalOp) ||
3838 ((ltoken_getCode (lastOpToken) == simpleOp ||
3839 ltoken_getCode (lastOpToken) == LLT_MULOP) &&
3840 (ltoken_getCode (op) == simpleOp ||
3841 ltoken_getCode (op) == LLT_MULOP)))
3842 if (ltoken_getText (lastOpToken) != ltoken_getText (op))
3846 ("Parentheses needed to specify associativity of %s and %s",
3847 cstring_fromChars (lsymbol_toChars (ltoken_getText (lastOpToken))),
3848 cstring_fromChars (lsymbol_toChars (ltoken_getText (op)))));
3854 pushInfixOpPartNode (/*@returned@*/ termNodeList x, ltoken op,
3855 /*@only@*/ termNode secondary)
3857 termNode lastLeftTerm;
3858 termNodeList args = termNodeList_new ();
3859 termNode t = (termNode) dmalloc (sizeof (*t));
3863 termNodeList_addh (args, secondary);
3865 if (!termNodeList_empty (x))
3867 termNodeList_reset (x);
3868 lastLeftTerm = termNodeList_current (x);
3869 checkAssociativity (lastLeftTerm, op);
3872 opform = makeOpFormNode (op, OPF_MANYOPM,
3873 opFormUnion_createAnyOp (op), ltoken_undefined);
3875 nn = makeNameNodeForm (opform);
3877 t->error_reported = FALSE;
3880 t->kind = TRM_APPLICATION;
3882 t->sort = sort_makeNoSort ();
3884 t->possibleSorts = sortSet_new ();
3885 t->possibleOps = lslOpSet_new ();
3886 termNodeList_addh (x, t);
3887 /* don't compute sort yet, do it in CollapseInfixTermNode */
3892 updateMatchedNode (/*@only@*/ termNode left, /*@returned@*/ termNode t,
3893 /*@only@*/ termNode right)
3897 if ((t == (termNode) 0) || (t->name == NULL) || t->name->isOpId)
3899 llbugexitlit ("updateMatchedNode: expect opForm in nameNode");
3902 op = t->name->content.opform;
3903 llassert (op != NULL);
3905 if (left == (termNode) 0)
3907 if (right == (termNode) 0)
3909 /* op->kind is not changed */
3910 termNode_free (right);
3914 op->kind = OPF_MIDDLEM;
3915 op->key = opFormNode2key (op, OPF_MIDDLEM);
3916 termNodeList_addh (t->args, right);
3921 termNodeList_addl (t->args, left);
3922 if (right == (termNode) 0)
3924 op->kind = OPF_MMIDDLE;
3925 op->key = opFormNode2key (op, OPF_MMIDDLE);
3929 op->kind = OPF_MMIDDLEM;
3930 op->key = opFormNode2key (op, OPF_MMIDDLEM);
3931 termNodeList_addh (t->args, right);
3938 updateSqBracketedNode (/*@only@*/ termNode left,
3939 /*@only@*/ /*@returned@*/ termNode t,
3940 /*@only@*/ termNode right)
3944 if ((t == (termNode) 0) || (t->name == NULL) || (t->name->isOpId))
3946 llbugexitlit ("updateSqBracketededNode: expect opForm in nameNode");
3949 op = t->name->content.opform;
3950 llassert (op != NULL);
3952 if (left == (termNode) 0)
3954 if (right == (termNode) 0)
3956 /* op->kind is not changed */
3960 op->kind = OPF_BMIDDLEM;
3961 op->key = opFormNode2key (op, OPF_BMIDDLEM);
3962 termNodeList_addh (t->args, right);
3967 termNodeList_addl (t->args, left);
3969 if (right == (termNode) 0)
3971 op->kind = OPF_BMMIDDLE;
3972 op->key = opFormNode2key (op, OPF_BMMIDDLE);
3976 op->kind = OPF_BMMIDDLEM;
3977 op->key = opFormNode2key (op, OPF_BMMIDDLEM);
3978 termNodeList_addh (t->args, right);
3985 makeSqBracketedNode (ltoken lbracket,
3986 termNodeList args, ltoken rbracket)
3988 termNode t = (termNode) dmalloc (sizeof (*t));
3993 t->error_reported = FALSE;
3996 size = termNodeList_size (args);
3997 opform = makeOpFormNode (lbracket, OPF_BMIDDLE, opFormUnion_createMiddle (size),
3999 nn = makeNameNodeForm (opform);
4001 t->kind = TRM_APPLICATION;
4003 t->sort = sort_makeNoSort ();
4005 t->possibleSorts = sortSet_new ();
4006 t->possibleOps = lslOpSet_new ();
4007 /* do sort checking later, not here, incomplete parse */
4012 makeMatchedNode (ltoken open, termNodeList args, ltoken close)
4014 /* matched : open args close */
4015 termNode t = (termNode) dmalloc (sizeof (*t));
4020 t->error_reported = FALSE;
4023 size = termNodeList_size (args);
4024 opform = makeOpFormNode (open, OPF_MIDDLE, opFormUnion_createMiddle (size), close);
4025 nn = makeNameNodeForm (opform);
4027 t->kind = TRM_APPLICATION;
4029 t->sort = sort_makeNoSort ();
4031 t->possibleSorts = sortSet_new ();
4032 t->possibleOps = lslOpSet_new ();
4033 /* do sort checking later, not here, incomplete parse */
4038 makeSimpleTermNode (ltoken varid)
4040 sort theSort = sort_makeNoSort ();
4044 termNode n = (termNode) dmalloc (sizeof (*n));
4046 n->error_reported = FALSE;
4048 n->name = (nameNode) 0;
4050 n->args = termNodeList_new ();
4051 n->possibleSorts = sortSet_new ();
4052 n->possibleOps = lslOpSet_new ();
4054 sym = ltoken_getText (varid);
4056 /* lookup current scope */
4057 vi = symtable_varInfoInScope (g_symtab, sym);
4059 if (varInfo_exists (vi))
4065 (void) sortSet_insert (n->possibleSorts, theSort);
4068 { /* need to handle LCL constants */
4069 vi = symtable_varInfo (g_symtab, sym);
4071 if (varInfo_exists (vi) && vi->kind == VRK_CONST)
4074 n->kind = TRM_CONST;
4077 (void) sortSet_insert (n->possibleSorts, theSort);
4080 { /* and LSL operators (true, false, new, nil, etc) */
4081 nameNode nn = makeNameNodeId (ltoken_copy (varid));
4082 oi = symtable_opInfo (g_symtab, nn);
4084 if (opInfo_exists (oi) && (oi->name->isOpId) &&
4085 !sigNodeSet_isEmpty (oi->signatures))
4087 sigNodeSet_elements (oi->signatures, x)
4089 if (ltokenList_empty (x->domain))
4090 /* yes, it really is empty, not not empty */
4092 lslOp op = (lslOp) dmalloc (sizeof (*op));
4094 op->name = nameNode_copy (nn);
4096 (void) sortSet_insert (n->possibleSorts, sigNode_rangeSort (x));
4097 (void) lslOpSet_insert (n->possibleOps, op);
4099 } end_sigNodeSet_elements;
4104 if (sortSet_size (n->possibleSorts) == 0)
4108 message ("Unrecognized identifier (constant, variable or operator): %s",
4109 ltoken_getRawString (varid)));
4113 n->sort = sort_makeNoSort ();
4115 n->kind = TRM_ZEROARY;
4123 makeSelectTermNode (termNode pri, ltoken select, /*@dependent@*/ ltoken id)
4125 termNode t = (termNode) dmalloc (sizeof (*t));
4126 opFormNode opform = makeOpFormNode (select,
4127 OPF_MSELECT, opFormUnion_createAnyOp (id),
4129 nameNode nn = makeNameNodeForm (opform);
4130 termNodeList args = termNodeList_new ();
4132 t->error_reported = FALSE;
4135 t->kind = TRM_APPLICATION;
4136 termNodeList_addh (args, pri);
4138 t->kind = TRM_APPLICATION;
4139 t->sort = sort_makeNoSort ();
4141 t->possibleSorts = sortSet_new ();
4142 t->possibleOps = lslOpSet_new ();
4148 makeMapTermNode (termNode pri, ltoken map, /*@dependent@*/ ltoken id)
4150 termNode t = (termNode) dmalloc (sizeof (*t));
4151 opFormNode opform = makeOpFormNode (map, OPF_MMAP, opFormUnion_createAnyOp (id),
4153 nameNode nn = makeNameNodeForm (opform);
4154 termNodeList args = termNodeList_new ();
4156 t->error_reported = FALSE;
4158 t->kind = TRM_APPLICATION;
4160 termNodeList_addh (args, pri);
4162 t->kind = TRM_APPLICATION;
4163 t->sort = sort_makeNoSort ();
4165 t->possibleSorts = sortSet_new ();
4166 t->possibleOps = lslOpSet_new ();
4171 makeLiteralTermNode (ltoken tok, sort s)
4173 nameNode nn = makeNameNodeId (ltoken_copy (tok));
4174 opInfo oi = symtable_opInfo (g_symtab, nn);
4175 lslOp op = (lslOp) dmalloc (sizeof (*op));
4176 termNode n = (termNode) dmalloc (sizeof (*n));
4181 n->error_reported = FALSE;
4183 n->kind = TRM_LITERAL;
4185 n->given = sort_makeNoSort ();
4187 n->args = termNodeList_new ();
4188 n->possibleSorts = sortSet_new ();
4189 n->possibleOps = lslOpSet_new ();
4191 /* look up signatures for this operator too */
4193 range = ltoken_create (simpleId, sort_getLsymbol (s));
4194 sign = makesigNode (ltoken_undefined, ltokenList_new (),
4195 ltoken_copy (range));
4197 if (opInfo_exists (oi) && (oi->name->isOpId)
4198 && (sigNodeSet_size (oi->signatures) > 0))
4200 sigNodeSet_elements (oi->signatures, x)
4202 if (ltokenList_empty (x->domain))
4204 lslOp opn = (lslOp) dmalloc (sizeof (*opn));
4207 opn->name = nameNode_copy (nn);
4209 sort = sigNode_rangeSort (x);
4210 (void) sortSet_insert (n->possibleSorts, sort);
4211 (void) lslOpSet_insert (n->possibleOps, opn);
4213 } end_sigNodeSet_elements;
4216 /* insert into literal term */
4217 (void) sortSet_insert (n->possibleSorts, s);
4219 op->name = nameNode_copy (nn);
4220 op->signature = sign;
4221 (void) lslOpSet_insert (n->possibleOps, op);
4223 /* enter the literal as an operator into the operator table */
4224 /* 8/9/93. C's char constant 'c' syntax conflicts
4225 with LSL's lslinit.lsi table. Throw out, because it's not
4227 /* symtable_enterOp (g_symtab, nn, sign); */
4232 lslOp opn = (lslOp) dmalloc (sizeof (*opn));
4234 /* if it is a C int, we should overload it as double too because
4235 C allows you to say "x > 2". */
4237 (void) sortSet_insert (n->possibleSorts, sort_double);
4239 ltoken_setText (range, lsymbol_fromChars ("double"));
4240 osign = makesigNode (ltoken_undefined, ltokenList_new (), range);
4241 opn->name = nameNode_copy (nn);
4242 opn->signature = osign;
4243 (void) lslOpSet_insert (n->possibleOps, opn);
4245 symtable_enterOp (g_symtab, nameNode_copySafe (nn), sigNode_copy (osign));
4249 ltoken_free (range);
4252 /* future: could overload cstrings to be both char_Vec as well as
4260 makeUnchangedTermNode1 (ltoken op, /*@unused@*/ ltoken all)
4262 termNode t = (termNode) dmalloc (sizeof (*t));
4264 t->error_reported = FALSE;
4266 t->kind = TRM_UNCHANGEDALL;
4267 t->sort = sort_bool;
4269 t->given = sort_makeNoSort ();
4270 t->name = NULL; /*< missing this >*/
4271 t->args = termNodeList_new ();
4272 t->possibleSorts = sortSet_new ();
4273 t->possibleOps = lslOpSet_new ();
4274 (void) sortSet_insert (t->possibleSorts, t->sort);
4282 makeUnchangedTermNode2 (ltoken op, storeRefNodeList x)
4284 termNode t = (termNode) dmalloc (sizeof (*t));
4288 t->name = NULL; /*< missing this >*/
4289 t->error_reported = FALSE;
4291 t->kind = TRM_UNCHANGEDOTHERS;
4292 t->sort = sort_bool;
4295 t->given = sort_makeNoSort ();
4296 t->possibleSorts = sortSet_new ();
4297 t->possibleOps = lslOpSet_new ();
4298 t->args = termNodeList_new ();
4300 (void) sortSet_insert (t->possibleSorts, t->sort);
4301 /* check storeRefNode's are mutable, uses sort of term */
4303 storeRefNodeList_elements (x, sto)
4305 if (storeRefNode_isTerm (sto))
4307 sort = sto->content.term->sort;
4308 if (!sort_mutable (sort))
4310 errtok = termNode_errorToken (sto->content.term);
4312 message ("Term denoting immutable object used in unchanged list: %q",
4313 termNode_unparse (sto->content.term)));
4318 if (storeRefNode_isType (sto))
4320 lclTypeSpecNode type = sto->content.type;
4321 sort = lclTypeSpecNode2sort (type);
4322 if (!sort_mutable (sort))
4324 errtok = lclTypeSpecNode_errorToken (type);
4325 lclerror (errtok, message ("Immutable type used in unchanged list: %q",
4326 sort_unparse (sort)));
4330 } end_storeRefNodeList_elements;
4336 makeSizeofTermNode (ltoken op, lclTypeSpecNode type)
4338 termNode t = (termNode) dmalloc (sizeof (*t));
4340 t->name = NULL; /*< missing this >*/
4341 t->error_reported = FALSE;
4343 t->kind = TRM_SIZEOF;
4346 t->sizeofField = type;
4347 t->given = sort_makeNoSort ();
4348 t->possibleSorts = sortSet_new ();
4349 t->possibleOps = lslOpSet_new ();
4350 t->args = termNodeList_new ();
4352 (void) sortSet_insert (t->possibleSorts, t->sort);
4353 /* nothing to check */
4358 claimNode_unparse (claimNode c)
4360 if (c != (claimNode) 0)
4362 cstring s = message ("claims (%q)%q{\n%q",
4363 paramNodeList_unparse (c->params),
4364 varDeclarationNodeList_unparse (c->globals),
4365 lclPredicateNode_unparse (c->require));
4367 if (c->body != NULL)
4369 s = message ("%qbody {%q}\n", s, programNode_unparse (c->body));
4371 s = message ("%q%q}\n", s, lclPredicateNode_unparse (c->ensures));
4374 return cstring_undefined;
4378 WrongArity (ltoken tok, int expect, int size)
4380 lclerror (tok, message ("Expecting %d arguments but given %d", expect, size));
4384 printTermNode2 (/*@null@*/ opFormNode op, termNodeList args, sort sort)
4386 if (op != (opFormNode) 0)
4388 cstring s = cstring_undefined;
4392 if (sort != sort_makeNoSort ())
4394 sortText = message (": %s", cstring_fromChars (lsymbol_toChars (sort_getLsymbol (sort))));
4395 sortSpace = cstring_makeLiteral (" ");
4399 sortText = cstring_undefined;
4400 sortSpace = cstring_undefined;
4407 int size = termNodeList_size (args);
4411 s = message ("if %q then %q else %q\n",
4412 termNode_unparse (termNodeList_getN (args, 0)),
4413 termNode_unparse (termNodeList_getN (args, 1)),
4414 termNode_unparse (termNodeList_getN (args, 2)));
4418 WrongArity (op->tok, 3, size);
4419 s = cstring_makeLiteral ("if __ then __ else __");
4421 s = message ("%q%s", s, sortText);
4426 s = message ("%s %s",
4427 ltoken_getRawString (op->content.anyop),
4433 int size = termNodeList_size (args);
4437 s = message ("%q ", termNode_unparse (termNodeList_head (args)));
4441 WrongArity (op->content.anyop, 1, size);
4442 s = cstring_makeLiteral ("__ ");
4444 s = message ("%q%s%s", s, ltoken_getRawString (op->content.anyop),
4450 int size = termNodeList_size (args);
4452 s = message ("%s ", ltoken_getRawString (op->content.anyop));
4456 s = message ("%q%q", s, termNode_unparse (termNodeList_head (args)));
4460 WrongArity (op->content.anyop, 1, size);
4461 s = message ("%q__", s);
4463 s = message ("%q%s", s, sortText);
4468 int size = termNodeList_size (args);
4472 s = message ("%q %s %q",
4473 termNode_unparse (termNodeList_getN (args, 0)),
4474 ltoken_getRawString (op->content.anyop),
4475 termNode_unparse (termNodeList_getN (args, 1)));
4479 WrongArity (op->content.anyop, 2, size);
4480 s = message ("__ %s __", ltoken_getRawString (op->content.anyop));
4482 s = message ("%q%s", s, sortText);
4487 int size = termNodeList_size (args);
4488 int expect = op->content.middle;
4490 /* ymtan ? use { or openSym token ? */
4494 s = message ("{%q}", termNodeList_unparse (args));
4498 WrongArity (op->tok, expect, size);
4499 s = cstring_makeLiteral ("{ * }");
4502 s = message ("%q%s", s, sortText);
4503 break; /*** <<<--- bug detected by LCLint ***/
4507 int size = termNodeList_size (args);
4508 int expect = op->content.middle + 1;
4512 s = message ("%q{%q}",
4513 termNode_unparse (termNodeList_head (args)),
4514 termNodeList_unparseTail (args));
4518 WrongArity (op->tok, expect, size);
4519 s = cstring_makeLiteral ("__ { * }");
4522 s = message ("%q%s", s, sortText);
4527 int size = termNodeList_size (args);
4528 int expect = op->content.middle + 1;
4532 termNodeList_finish (args);
4534 s = message ("{%q}%s%s%q",
4535 termNodeList_unparseToCurrent (args),
4536 sortText, sortSpace,
4537 termNode_unparse (termNodeList_current (args)));
4541 WrongArity (op->tok, expect, size);
4543 s = message ("{ * }%s __", sortText);
4545 /* used to put in extra space! evs 94-01-05 */
4551 int size = termNodeList_size (args);
4552 int expect = op->content.middle + 2;
4556 termNodeList_finish (args);
4558 s = message ("%q {%q} %s%s%q",
4559 termNode_unparse (termNodeList_head (args)),
4560 termNodeList_unparseSecondToCurrent (args),
4561 sortText, sortSpace,
4562 termNode_unparse (termNodeList_current (args)));
4566 WrongArity (op->tok, expect, size);
4567 s = message ("__ { * } %s __", sortText);
4569 /* also had extra space? */
4575 int size = termNodeList_size (args);
4576 int expect = op->content.middle;
4580 s = message ("[%q]", termNodeList_unparse (args));
4584 WrongArity (op->tok, expect, size);
4585 s = cstring_makeLiteral ("[ * ]");
4587 s = message ("%q%s", s, sortText);
4592 int size = termNodeList_size (args);
4593 int expect = op->content.middle + 1;
4597 s = message ("%q[%q]",
4598 termNode_unparse (termNodeList_head (args)),
4599 termNodeList_unparseTail (args));
4603 WrongArity (op->tok, expect, size);
4604 s = cstring_makeLiteral ("__ [ * ]");
4607 s = message ("%q%s", s, sortText);
4612 int size = termNodeList_size (args);
4613 int expect = op->content.middle + 1;
4617 s = message ("%q[%q] __",
4618 termNode_unparse (termNodeList_head (args)),
4619 termNodeList_unparseTail (args));
4623 WrongArity (op->tok, expect, size);
4624 s = cstring_makeLiteral ("__ [ * ] __");
4626 s = message ("%q%s", s, sortText);
4631 int size = termNodeList_size (args);
4632 int expect = op->content.middle + 1;
4636 termNodeList_finish (args);
4638 s = message ("[%q]%s%s%q",
4639 termNodeList_unparseToCurrent (args),
4640 sortText, sortSpace,
4641 termNode_unparse (termNodeList_current (args)));
4645 WrongArity (op->tok, expect, size);
4646 s = cstring_makeLiteral ("[ * ] __");
4652 { /* ymtan constant, check args ? */
4653 s = cstring_prependChar ('.', ltoken_getRawString (op->content.id));
4657 s = cstring_concat (cstring_makeLiteralTemp ("->"),
4658 ltoken_getRawString (op->content.id));
4662 int size = termNodeList_size (args);
4666 s = message ("%q.%s", termNode_unparse (termNodeList_head (args)),
4667 ltoken_getRawString (op->content.id));
4671 WrongArity (op->content.id, 1, size);
4672 s = cstring_concat (cstring_makeLiteralTemp ("__."),
4673 ltoken_getRawString (op->content.id));
4679 int size = termNodeList_size (args);
4683 s = message ("%q->%s", termNode_unparse (termNodeList_head (args)),
4684 ltoken_getRawString (op->content.id));
4688 WrongArity (op->content.id, 1, size);
4689 s = cstring_concat (cstring_makeLiteralTemp ("__->"),
4690 ltoken_getRawString (op->content.id));
4696 cstring_free (sortSpace);
4697 cstring_free (sortText);
4700 return cstring_undefined;
4704 termNode_unparse (/*@null@*/ termNode n)
4706 cstring s = cstring_undefined;
4707 cstring back = cstring_undefined;
4708 cstring front = cstring_undefined;
4711 if (n != (termNode) 0)
4713 for (count = n->wrapped; count > 0; count--)
4715 front = cstring_appendChar (front, '(');
4716 back = cstring_appendChar (back, ')');
4725 s = cstring_copy (ltoken_getRawString (n->literal));
4727 case TRM_APPLICATION:
4729 nameNode nn = n->name;
4730 if (nn != (nameNode) 0)
4734 s = message ("%s (%q) ",
4735 ltoken_getRawString (nn->content.opid),
4736 termNodeList_unparse (n->args));
4737 /* must we handle n->given ? skip for now */
4741 s = message ("%q ", printTermNode2 (nn->content.opform, n->args, n->given));
4747 (message ("termNode_unparse: expect non-empty nameNode: TRM_APPLICATION: %q",
4748 nameNode_unparse (nn)));
4752 case TRM_UNCHANGEDALL:
4753 s = cstring_makeLiteral ("unchanged (all)");
4755 case TRM_UNCHANGEDOTHERS:
4756 s = message ("unchanged (%q)", storeRefNodeList_unparse (n->unchanged));
4759 s = message ("sizeof (%q)", lclTypeSpecNode_unparse (n->sizeofField));
4761 case TRM_QUANTIFIER:
4763 quantifiedTermNode x = n->quantified;
4764 s = message ("%q%s%q%s",
4765 quantifierNodeList_unparse (x->quantifiers),
4766 ltoken_getRawString (x->open),
4767 termNode_unparse (x->body),
4768 ltoken_getRawString (x->close));
4773 return (message ("%q%q%q", front, s, back));
4776 static void modifyNode_free (/*@null@*/ /*@only@*/ modifyNode m)
4778 if (m != (modifyNode) 0)
4781 if (m->hasStoreRefList)
4783 storeRefNodeList_free (m->list);
4788 ltoken_free (m->tok);
4794 modifyNode_unparse (/*@null@*/ modifyNode m)
4796 if (m != (modifyNode) 0)
4798 if (m->hasStoreRefList)
4800 return (message (" modifies %q; \n", storeRefNodeList_unparse (m->list)));
4804 if (m->modifiesNothing)
4806 return (cstring_makeLiteral ("modifies nothing; \n"));
4810 return (cstring_makeLiteral ("modifies anything; \n"));
4814 return cstring_undefined;
4818 programNode_unparse (programNode p)
4820 if (p != (programNode) 0)
4822 cstring s = cstring_undefined;
4829 cstring back = cstring_undefined;
4831 for (count = p->wrapped; count > 0; count--)
4833 s = cstring_appendChar (s, '(');
4834 back = cstring_appendChar (back, ')');
4836 s = message ("%q%q%q", s, stmtNode_unparse (p->content.self), back);
4840 s = message ("*(%q)", programNodeList_unparse (p->content.args));
4843 s = message ("|(%q)", programNodeList_unparse (p->content.args));
4846 s = programNodeList_unparse (p->content.args);
4852 return cstring_undefined;
4856 stmtNode_unparse (stmtNode x)
4858 cstring s = cstring_undefined;
4860 if (x != (stmtNode) 0)
4862 if (ltoken_isValid (x->lhs))
4864 s = cstring_concat (ltoken_getRawString (x->lhs),
4865 cstring_makeLiteralTemp (" = "));
4868 s = message ("%q%s (%q)", s,
4869 ltoken_getRawString (x->operator),
4870 termNodeList_unparse (x->args));
4877 makelslOpNode (/*@only@*/ /*@null@*/ nameNode name,
4878 /*@dependent@*/ sigNode s)
4880 lslOp x = (lslOp) dmalloc (sizeof (*x));
4885 /* enter operator info into symtab */
4886 /* if not, they may need to be renamed in LCL imports */
4888 if (g_lslParsingTraits)
4892 symtable_enterOp (g_symtab, nameNode_copySafe (name), sigNode_copy (s));
4897 /* nameNode_free (name); */ /* YIKES! */
4904 lslOp_unparse (lslOp x)
4906 char *s = mstring_createEmpty ();
4910 s = mstring_concatFree (s, cstring_toCharsSafe (nameNode_unparse (x->name)));
4912 if (x->signature != (sigNode) 0)
4914 s = mstring_concatFree (s, cstring_toCharsSafe (sigNode_unparse (x->signature)));
4918 return cstring_fromCharsO (s);
4922 sameOpFormNode (/*@null@*/ opFormNode n1, /*@null@*/ opFormNode n2)
4933 if (n1->kind == n2->kind)
4942 return (ltoken_similar (n1->content.anyop, n2->content.anyop));
4945 /* want to treat eq and = the same */
4946 return ltoken_similar (n1->content.anyop, n2->content.anyop);
4952 /* need to check the rawText of openSym and closeSym */
4953 if ((int) n1->content.middle == (int) n2->content.middle)
4955 if (lsymbol_equal (ltoken_getRawText (n1->tok),
4956 ltoken_getRawText (n2->tok)) &&
4957 lsymbol_equal (ltoken_getRawText (n1->close),
4958 ltoken_getRawText (n2->close)))
4966 return ((int) n1->content.middle == (int) n2->content.middle);
4971 return (ltoken_similar (n1->content.id, n2->content.id));
4978 sameNameNode (/*@null@*/ nameNode n1, /*@null@*/ nameNode n2)
4982 if (n1 != (nameNode) 0 && n2 != (nameNode) 0)
4984 if (bool_equal (n1->isOpId, n2->isOpId))
4987 return (ltoken_similar (n1->content.opid, n2->content.opid));
4989 return sameOpFormNode (n1->content.opform,
4990 n2->content.opform);
4996 void CTypesNode_free (/*@only@*/ /*@null@*/ CTypesNode x)
5000 ltokenList_free (x->ctypes);
5005 /*@null@*/ CTypesNode CTypesNode_copy (/*@null@*/ CTypesNode x)
5009 CTypesNode newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5010 newnode->intfield = x->intfield;
5011 newnode->ctypes = ltokenList_copy (x->ctypes);
5012 newnode->sort = x->sort;
5022 /*@only@*/ CTypesNode
5023 makeCTypesNode (/*@only@*/ CTypesNode ctypes, ltoken ct)
5025 /*@only@*/ CTypesNode newnode;
5029 if (ctypes == (CTypesNode) NULL)
5031 newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5032 newnode->intfield = 0;
5033 newnode->ctypes = ltokenList_new ();
5034 newnode->sort = sort_makeNoSort ();
5041 if ((ltoken_getIntField (ct) & newnode->intfield) != 0)
5045 ("Duplicate type specifier ignored: %s",
5048 (lclctype_toSortDebug (ltoken_getIntField (ct))))));
5050 /* evs --- don't know how to generator this error */
5052 /* Use previous value, to keep things consistent */
5057 sortbits = newnode->intfield | ltoken_getIntField (ct);
5058 sortname = lclctype_toSort (sortbits);
5060 if (sortname == lsymbol_fromChars ("error"))
5062 lclerror (ct, cstring_makeLiteral ("Invalid combination of type specifiers"));
5066 newnode->intfield = sortbits;
5069 ltokenList_addh (newnode->ctypes, ct);
5072 ** Sorts are assigned after CTypesNode is created during parsing,
5073 ** see bison grammar.
5079 /*@only@*/ CTypesNode
5080 makeTypeSpecifier (ltoken typedefname)
5082 CTypesNode newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5083 typeInfo ti = symtable_typeInfo (g_symtab, ltoken_getText (typedefname));
5085 newnode->intfield = 0;
5086 newnode->ctypes = ltokenList_singleton (ltoken_copy (typedefname));
5088 /* if we see "bool" include bool.h header file */
5090 if (ltoken_getText (typedefname) == lsymbol_bool)
5095 if (typeInfo_exists (ti))
5097 /* must we be concern about whether this type is exported by module?
5098 No. Because all typedef's are exported. No hiding supported. */
5099 /* Later, may want to keep types around too */
5100 /* 3/2/93, use underlying sort */
5101 newnode->sort = sort_getUnderlying (ti->basedOn);
5105 lclerror (typedefname, message ("Unrecognized type: %s",
5106 ltoken_getRawString (typedefname)));
5107 /* evs --- Don't know how to get this message */
5109 newnode->sort = sort_makeNoSort ();
5112 ltoken_free (typedefname);
5116 bool sigNode_equal (sigNode n1, sigNode n2)
5118 /* n1 and n2 are never 0 */
5120 return ((n1 == n2) ||
5121 (n1->key == n2->key &&
5122 ltoken_similar (n1->range, n2->range) &&
5123 ltokenList_equal (n1->domain, n2->domain)));
5127 typeExpr2ptrSort (sort base, /*@null@*/ typeExpr t)
5129 if (t != (typeExpr) 0)
5136 return typeExpr2ptrSort (sort_makePtr (ltoken_undefined, base),
5137 t->content.pointer);
5139 return typeExpr2ptrSort (sort_makeArr (ltoken_undefined, base),
5140 t->content.array.elementtype);
5142 /* map all hof types to some sort of SRT_HOF */
5143 return sort_makeHOFSort (base);
5150 typeExpr2returnSort (sort base, /*@null@*/ typeExpr t)
5152 if (t != (typeExpr) 0)
5159 return typeExpr2returnSort (sort_makePtr (ltoken_undefined, base),
5160 t->content.pointer);
5162 return typeExpr2returnSort (sort_makeArr (ltoken_undefined, base),
5163 t->content.array.elementtype);
5165 return typeExpr2returnSort (base, t->content.function.returntype);
5172 lclTypeSpecNode2sort (lclTypeSpecNode type)
5174 if (type != (lclTypeSpecNode) 0)
5179 llassert (type->content.type != NULL);
5180 return sort_makePtrN (type->content.type->sort, type->pointers);
5181 case LTS_STRUCTUNION:
5182 llassert (type->content.structorunion != NULL);
5183 return sort_makePtrN (type->content.structorunion->sort,
5186 llassert (type->content.enumspec != NULL);
5187 return sort_makePtrN (type->content.enumspec->sort,
5190 return (lclTypeSpecNode2sort (type->content.conj->a));
5193 return (sort_makeNoSort ());
5197 checkAndEnterTag (tagKind k, ltoken opttagid)
5199 /* should be tagKind, instead of int */
5201 sort sort = sort_makeNoSort ();
5203 if (!ltoken_isUndefined (opttagid))
5209 sort = sort_makeStr (opttagid);
5213 sort = sort_makeUnion (opttagid);
5216 sort = sort_makeEnum (opttagid);
5220 /* see if it is already in symbol table */
5221 t = symtable_tagInfo (g_symtab, ltoken_getText (opttagid));
5223 if (tagInfo_exists (t))
5225 if (t->kind == TAG_FWDUNION || t->kind == TAG_FWDSTRUCT)
5227 /* this is fine, for mutually recursive types */
5230 { /* this is not good, complain later */
5236 s = cstring_makeLiteral ("Enum");
5240 s = cstring_makeLiteral ("Struct");
5244 s = cstring_makeLiteral ("Union");
5251 message ("Tag redefined: %q %s", s,
5252 ltoken_getRawString (opttagid)));
5256 ltoken_free (opttagid);
5260 tagInfo newnode = (tagInfo) dmalloc (sizeof (*newnode));
5262 newnode->sort = sort;
5264 newnode->id = opttagid;
5265 newnode->imported = FALSE;
5266 newnode->content.decls = stDeclNodeList_new ();
5268 (void) symtable_enterTag (g_symtab, newnode);
5272 return sort_getLsymbol (sort);
5276 extractReturnSort (lclTypeSpecNode t, declaratorNode d)
5279 sort = lclTypeSpecNode2sort (t);
5280 sort = typeExpr2returnSort (sort, d->type);
5285 signNode_free (/*@only@*/ signNode sn)
5287 sortList_free (sn->domain);
5288 ltoken_free (sn->tok);
5293 signNode_unparse (signNode sn)
5295 cstring s = cstring_undefined;
5297 if (sn != (signNode) 0)
5299 s = message (": %q -> %s", sortList_unparse (sn->domain),
5300 sort_unparseName (sn->range));
5305 static /*@only@*/ pairNodeList
5306 globalList_toPairNodeList (globalList g)
5308 /* expect list to be globals, drop private ones */
5309 pairNodeList result = pairNodeList_new ();
5311 declaratorNode vdnode;
5312 lclTypeSpecNode type;
5315 initDeclNodeList decls;
5317 varDeclarationNodeList_elements (g, x)
5325 if (x->isGlobal && !x->isPrivate)
5330 initDeclNodeList_elements (decls, init)
5332 p = (pairNode) dmalloc (sizeof (*p));
5334 vdnode = init->declarator;
5335 sym = ltoken_getText (vdnode->id);
5336 /* 2/21/93, not sure if it should be extractReturnSort,
5337 or some call to typeExpr2ptrSort */
5338 sort = extractReturnSort (type, vdnode);
5339 p->sort = sort_makeGlobal (sort);
5340 /* if (!sort_isArrayKind (sort)) p->sort = sort_makeObj (sort);
5341 else p->sort = sort; */
5342 /* p->name = sym; */
5343 p->tok = ltoken_copy (vdnode->id);
5344 pairNodeList_addh (result, p);
5345 } end_initDeclNodeList_elements;
5348 } end_varDeclarationNodeList_elements;
5353 enteringFcnScope (lclTypeSpecNode t, declaratorNode d, globalList g)
5355 scopeInfo si = (scopeInfo) dmalloc (sizeof (*si));
5356 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5358 ltoken result = ltoken_copy (ltoken_id);
5359 pairNodeList paramPairs, globals;
5360 fctInfo fi = (fctInfo) dmalloc (sizeof (*fi));
5361 signNode sign = (signNode) dmalloc (sizeof (*sign));
5362 sortList domain = sortList_new ();
5365 paramPairs = extractParams (d->type);
5366 returnSort = extractReturnSort (t, d);
5367 globals = globalList_toPairNodeList (g);
5369 sign->tok = ltoken_undefined;
5370 sign->range = returnSort;
5372 key = MASH (0, sort_getLsymbol (returnSort));
5374 pairNodeList_elements (paramPairs, p)
5376 sortList_addh (domain, p->sort);
5377 key = MASH (key, sort_getLsymbol (p->sort));
5378 } end_pairNodeList_elements;
5380 sign->domain = domain;
5383 /* push fcn onto symbol table stack first */
5384 fi->id = ltoken_copy (d->id);
5386 fi->signature = sign;
5387 fi->globals = globals;
5389 (void) symtable_enterFct (g_symtab, fi);
5391 /* push new fcn scope */
5393 symtable_enterScope (g_symtab, si);
5395 /* add "result" with return type to current scope */
5396 ltoken_setText (result, lsymbol_fromChars ("result"));
5399 vi->sort = sort_makeFormal (returnSort); /* make appropriate values */
5400 vi->kind = VRK_PARAM;
5403 (void) symtable_enterVar (g_symtab, vi);
5407 ** pust globals first (they are in outer scope)
5410 /* push onto symbol table the global variables declared in this function,
5411 together with their respective sorts */
5413 pairNodeList_elements (globals, gl)
5415 ltoken_free (vi->id);
5416 vi->id = ltoken_copy (gl->tok);
5417 vi->kind = VRK_GLOBAL;
5418 vi->sort = gl->sort;
5419 (void) symtable_enterVar (g_symtab, vi);
5420 } end_pairNodeList_elements;
5423 ** could enter a new scope; instead, warn when variable shadows global
5428 ** push onto symbol table the formal parameters of this function,
5429 ** together with their respective sorts
5432 pairNodeList_elements (paramPairs, pair)
5434 ltoken_free (vi->id);
5435 vi->id = ltoken_copy (pair->tok);
5436 vi->sort = pair->sort;
5437 vi->kind = VRK_PARAM;
5438 (void) symtable_enterVar (g_symtab, vi);
5439 } end_pairNodeList_elements;
5441 pairNodeList_free (paramPairs);
5446 enteringClaimScope (paramNodeList params, globalList g)
5448 scopeInfo si = (scopeInfo) dmalloc (sizeof (*si));
5449 pairNodeList globals;
5450 lclTypeSpecNode paramtype;
5454 globals = globalList_toPairNodeList (g);
5455 /* push new claim scope */
5456 si->kind = SPE_CLAIM;
5458 symtable_enterScope (g_symtab, si);
5460 /* push onto symbol table the formal parameters of this function,
5461 together with their respective sorts */
5463 paramNodeList_elements (params, param)
5465 paramdecl = param->paramdecl;
5466 paramtype = param->type;
5467 if (paramdecl != (typeExpr) 0 && paramtype != (lclTypeSpecNode) 0)
5469 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5471 sort = lclTypeSpecNode2sort (paramtype);
5472 sort = sort_makeFormal (sort);
5473 vi->sort = typeExpr2ptrSort (sort, paramdecl);
5474 vi->id = ltoken_copy (extractDeclarator (paramdecl));
5475 vi->kind = VRK_PARAM;
5478 (void) symtable_enterVar (g_symtab, vi);
5481 } end_paramNodeList_elements;
5483 /* push onto symbol table the global variables declared in this function,
5484 together with their respective sorts */
5486 pairNodeList_elements (globals, g2)
5488 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5490 vi->id = ltoken_copy (g2->tok);
5491 vi->kind = VRK_GLOBAL;
5492 vi->sort = g2->sort;
5495 /* should catch duplicates in formals */
5496 (void) symtable_enterVar (g_symtab, vi);
5498 } end_pairNodeList_elements;
5500 pairNodeList_free (globals);
5501 /* should not free it here! ltoken_free (claimId); @*/
5504 static /*@only@*/ pairNodeList
5505 extractParams (/*@null@*/ typeExpr te)
5507 /* extract the parameters from a function header declarator's typeExpr */
5510 paramNodeList params;
5511 lclTypeSpecNode paramtype;
5512 pairNodeList head = pairNodeList_new ();
5515 if (te != (typeExpr) 0)
5517 params = typeExpr_toParamNodeList (te);
5518 if (paramNodeList_isDefined (params))
5520 paramNodeList_elements (params, param)
5522 paramdecl = param->paramdecl;
5523 paramtype = param->type;
5524 if (paramdecl != (typeExpr) 0 && paramtype != (lclTypeSpecNode) 0)
5526 pair = (pairNode) dmalloc (sizeof (*pair));
5527 sort = lclTypeSpecNode2sort (paramtype);
5528 /* 2/17/93, was sort_makeVal (sort) */
5529 sort = sort_makeFormal (sort);
5530 pair->sort = typeExpr2ptrSort (sort, paramdecl);
5531 /* pair->name = ltoken_getText (extractDeclarator (paramdecl)); */
5532 pair->tok = ltoken_copy (extractDeclarator (paramdecl));
5533 pairNodeList_addh (head, pair);
5535 } end_paramNodeList_elements;
5542 sigNode_rangeSort (sigNode sig)
5544 if (sig == (sigNode) 0)
5546 return sort_makeNoSort ();
5550 return sort_fromLsymbol (ltoken_getText (sig->range));
5555 sigNode_domain (sigNode sig)
5557 sortList domain = sortList_new ();
5559 if (sig == (sigNode) 0)
5565 ltokenList dom = sig->domain;
5567 ltokenList_elements (dom, tok)
5569 sortList_addh (domain, sort_fromLsymbol (ltoken_getText (tok)));
5570 } end_ltokenList_elements;
5577 opFormUnion_createAnyOp (/*@temp@*/ ltoken t)
5581 /* do not distinguish between .anyop and .id */
5587 opFormUnion_createMiddle (int middle)
5596 markYieldParamNode (paramNode p)
5600 llassert (p->type != NULL);
5601 p->type->quals = qualList_add (p->type->quals, qual_createYield ());
5606 /*@only@*/ lclTypeSpecNode
5607 lclTypeSpecNode_copySafe (lclTypeSpecNode n)
5609 lclTypeSpecNode ret = lclTypeSpecNode_copy (n);
5611 llassert (ret != NULL);
5615 /*@null@*/ /*@only@*/ lclTypeSpecNode
5616 lclTypeSpecNode_copy (/*@null@*/ lclTypeSpecNode n)
5623 return (makeLclTypeSpecNodeConj (lclTypeSpecNode_copy (n->content.conj->a),
5624 lclTypeSpecNode_copy (n->content.conj->b)));
5626 return (makeLclTypeSpecNodeType (CTypesNode_copy (n->content.type)));
5627 case LTS_STRUCTUNION:
5628 return (makeLclTypeSpecNodeSU (strOrUnionNode_copy (n->content.structorunion)));
5630 return (makeLclTypeSpecNodeEnum (enumSpecNode_copy (n->content.enumspec)));
5637 void lclTypeSpecNode_free (/*@null@*/ /*@only@*/ lclTypeSpecNode n)
5644 lclTypeSpecNode_free (n->content.conj->a);
5645 lclTypeSpecNode_free (n->content.conj->b);
5648 CTypesNode_free (n->content.type);
5650 case LTS_STRUCTUNION:
5651 strOrUnionNode_free (n->content.structorunion);
5654 enumSpecNode_free (n->content.enumspec);
5658 qualList_free (n->quals);
5663 static /*@null@*/ opFormNode opFormNode_copy (/*@null@*/ opFormNode op)
5667 opFormNode ret = (opFormNode) dmalloc (sizeof (*ret));
5669 ret->tok = ltoken_copy (op->tok);
5670 ret->kind = op->kind;
5671 ret->content = op->content;
5673 ret->close = ltoken_copy (op->close);
5683 void opFormNode_free (/*@null@*/ opFormNode op)
5688 void nameNode_free (nameNode n)
5695 opFormNode_free (n->content.opform);
5703 lslOp_equal (lslOp x, lslOp y)
5706 ((x != 0) && (y != 0) &&
5707 sameNameNode (x->name, y->name) &&
5708 sigNode_equal (x->signature, y->signature)));
5711 void lslOp_free (lslOp x)
5713 nameNode_free (x->name);
5717 void sigNode_free (sigNode x)
5721 ltokenList_free (x->domain);
5722 ltoken_free (x->tok);
5723 ltoken_free (x->range);
5728 void declaratorNode_free (/*@null@*/ /*@only@*/ declaratorNode x)
5732 typeExpr_free (x->type);
5733 ltoken_free (x->id);
5738 void abstBodyNode_free (/*@null@*/ /*@only@*/ abstBodyNode n)
5742 lclPredicateNode_free (n->typeinv);
5743 fcnNodeList_free (n->fcns);
5744 ltoken_free (n->tok);
5749 void fcnNode_free (/*@null@*/ /*@only@*/ fcnNode f)
5753 lclTypeSpecNode_free (f->typespec);
5754 declaratorNode_free (f->declarator);
5755 globalList_free (f->globals);
5756 varDeclarationNodeList_free (f->inits);
5757 letDeclNodeList_free (f->lets);
5758 lclPredicateNode_free (f->checks);
5759 lclPredicateNode_free (f->require);
5760 lclPredicateNode_free (f->claim);
5761 lclPredicateNode_free (f->ensures);
5762 modifyNode_free (f->modify);
5763 ltoken_free (f->name);
5768 void declaratorInvNode_free (/*@null@*/ /*@only@*/ declaratorInvNode x)
5772 declaratorNode_free (x->declarator);
5773 abstBodyNode_free (x->body);
5778 /*@only@*/ lslOp lslOp_copy (lslOp x)
5780 return (makelslOpNode (nameNode_copy (x->name), x->signature));
5783 sigNode sigNode_copy (sigNode s)
5785 llassert (s != NULL);
5786 return (makesigNode (ltoken_copy (s->tok),
5787 ltokenList_copy (s->domain),
5788 ltoken_copy (s->range)));
5791 /*@null@*/ nameNode nameNode_copy (/*@null@*/ nameNode n)
5793 if (n == NULL) return NULL;
5794 return nameNode_copySafe (n);
5797 nameNode nameNode_copySafe (nameNode n)
5801 return (makeNameNodeId (ltoken_copy (n->content.opid)));
5805 /* error should be detected by lclint: forgot to copy opform! */
5806 return (makeNameNodeForm (opFormNode_copy (n->content.opform)));
5810 bool initDeclNode_isRedeclaration (initDeclNode d)
5812 return (d->declarator->isRedecl);
5815 void termNode_free (/*@only@*/ /*@null@*/ termNode t)
5820 /*@only@*/ termNode termNode_copySafe (termNode t)
5822 termNode ret = termNode_copy (t);
5824 llassert (ret != NULL);
5828 /*@null@*/ /*@only@*/ termNode termNode_copy (/*@null@*/ termNode t)
5832 termNode ret = (termNode) dmalloc (sizeof (*ret));
5834 ret->wrapped = t->wrapped;
5835 ret->kind = t->kind;
5836 ret->sort = t->sort;
5837 ret->given = t->given;
5838 ret->possibleSorts = sortSet_copy (t->possibleSorts);
5839 ret->error_reported = t->error_reported;
5840 ret->possibleOps = lslOpSet_copy (t->possibleOps);
5841 ret->name = nameNode_copy (t->name);
5842 ret->args = termNodeList_copy (t->args);
5844 if (t->kind == TRM_LITERAL
5845 || t->kind == TRM_SIZEOF
5846 || t->kind == TRM_VAR
5847 || t->kind == TRM_CONST
5848 || t->kind == TRM_ZEROARY)
5850 ret->literal = ltoken_copy (t->literal);
5853 if (t->kind == TRM_UNCHANGEDOTHERS)
5855 ret->unchanged = storeRefNodeList_copy (t->unchanged);
5858 if (t->kind == TRM_QUANTIFIER)
5860 ret->quantified = quantifiedTermNode_copy (t->quantified);
5863 if (t->kind == TRM_SIZEOF)
5865 ret->sizeofField = lclTypeSpecNode_copySafe (t->sizeofField);
5877 void importNode_free (/*@only@*/ /*@null@*/ importNode x)
5882 void initDeclNode_free (/*@only@*/ /*@null@*/ initDeclNode x)
5886 declaratorNode_free (x->declarator);
5887 termNode_free (x->value);
5892 void letDeclNode_free (/*@only@*/ /*@null@*/ letDeclNode x)
5896 lclTypeSpecNode_free (x->sortspec);
5897 termNode_free (x->term);
5898 ltoken_free (x->varid);
5903 void pairNode_free (/*@only@*/ /*@null@*/ pairNode x)
5908 /*@null@*/ paramNode paramNode_copy (/*@null@*/ paramNode p)
5912 paramNode ret = (paramNode) dmalloc (sizeof (*ret));
5914 ret->type = lclTypeSpecNode_copy (p->type);
5915 ret->paramdecl = typeExpr_copy (p->paramdecl);
5916 ret->kind = p->kind;
5923 void paramNode_free (/*@only@*/ /*@null@*/ paramNode x)
5927 lclTypeSpecNode_free (x->type);
5928 typeExpr_free (x->paramdecl);
5933 void programNode_free (/*@only@*/ /*@null@*/ programNode x)
5939 case ACT_SELF: stmtNode_free (x->content.self); break;
5942 case ACT_SEQUENCE: programNodeList_free (x->content.args); break;
5949 quantifierNode quantifierNode_copy (quantifierNode x)
5951 quantifierNode ret = (quantifierNode) dmalloc (sizeof (*ret));
5953 ret->quant = ltoken_copy (x->quant);
5954 ret->vars = varNodeList_copy (x->vars);
5955 ret->isForall = x->isForall;
5960 void quantifierNode_free (/*@null@*/ /*@only@*/ quantifierNode x)
5964 varNodeList_free (x->vars);
5965 ltoken_free (x->quant);
5970 void replaceNode_free (/*@only@*/ /*@null@*/ replaceNode x)
5980 nameNode_free (x->content.renamesortname.name);
5981 sigNode_free (x->content.renamesortname.signature);
5984 typeNameNode_free (x->typename);
5985 ltoken_free (x->tok);
5990 storeRefNode storeRefNode_copy (storeRefNode x)
5992 storeRefNode ret = (storeRefNode) dmalloc (sizeof (*ret));
5994 ret->kind = x->kind;
5999 ret->content.term = termNode_copySafe (x->content.term);
6001 case SRN_OBJ: case SRN_TYPE:
6002 ret->content.type = lclTypeSpecNode_copy (x->content.type);
6005 ret->content.ref = sRef_copy (x->content.ref);
6012 void storeRefNode_free (/*@only@*/ /*@null@*/ storeRefNode x)
6016 if (storeRefNode_isTerm (x))
6018 termNode_free (x->content.term);
6020 else if (storeRefNode_isType (x) || storeRefNode_isObj (x))
6022 lclTypeSpecNode_free (x->content.type);
6026 /* nothing to free */
6033 stDeclNode stDeclNode_copy (stDeclNode x)
6035 stDeclNode ret = (stDeclNode) dmalloc (sizeof (*ret));
6037 ret->lcltypespec = lclTypeSpecNode_copySafe (x->lcltypespec);
6038 ret->declarators = declaratorNodeList_copy (x->declarators);
6043 void stDeclNode_free (/*@only@*/ /*@null@*/ stDeclNode x)
6047 lclTypeSpecNode_free (x->lcltypespec);
6048 declaratorNodeList_free (x->declarators);
6053 void traitRefNode_free (/*@only@*/ /*@null@*/ traitRefNode x)
6057 ltokenList_free (x->traitid);
6058 renamingNode_free (x->rename);
6063 void typeNameNode_free (/*@only@*/ /*@null@*/ typeNameNode n)
6067 typeNamePack_free (n->typename);
6068 opFormNode_free (n->opform);
6073 void varDeclarationNode_free (/*@only@*/ /*@null@*/ varDeclarationNode x)
6083 lclTypeSpecNode_free (x->type);
6084 initDeclNodeList_free (x->decls);
6090 varNode varNode_copy (varNode x)
6092 varNode ret = (varNode) dmalloc (sizeof (*ret));
6094 ret->varid = ltoken_copy (x->varid);
6095 ret->isObj = x->isObj;
6096 ret->type = lclTypeSpecNode_copySafe (x->type);
6097 ret->sort = x->sort;
6102 void varNode_free (/*@only@*/ /*@null@*/ varNode x)
6106 lclTypeSpecNode_free (x->type);
6107 ltoken_free (x->varid);
6112 void stmtNode_free (/*@only@*/ /*@null@*/ stmtNode x)
6116 ltoken_free (x->lhs);
6117 termNodeList_free (x->args);
6118 ltoken_free (x->operator);
6123 void renamingNode_free (/*@only@*/ /*@null@*/ renamingNode x)
6129 replaceNodeList_free (x->content.replace);
6133 nameAndReplaceNode_free (x->content.name);
6140 void nameAndReplaceNode_free (/*@only@*/ /*@null@*/ nameAndReplaceNode x)
6144 typeNameNodeList_free (x->namelist);
6145 replaceNodeList_free (x->replacelist);
6150 void typeNamePack_free (/*@only@*/ /*@null@*/ typeNamePack x)
6154 lclTypeSpecNode_free (x->type);
6155 abstDeclaratorNode_free (x->abst);
6160 cstring interfaceNode_unparse (interfaceNode x)
6167 return (message ("[imports] %q", importNodeList_unparse (x->content.imports)));
6169 return (message ("[uses] %q", traitRefNodeList_unparse (x->content.uses)));
6171 return (message ("[export] %q", exportNode_unparse (x->content.export)));
6173 return (message ("[private] %q", privateNode_unparse (x->content.private)));
6180 return (cstring_makeLiteral ("<interface node undefined>"));
6184 void interfaceNode_free (/*@null@*/ /*@only@*/ interfaceNode x)
6191 case INF_IMPORTS: importNodeList_free (x->content.imports); break;
6192 case INF_USES: traitRefNodeList_free (x->content.uses); break;
6193 case INF_EXPORT: exportNode_free (x->content.export); break;
6194 case INF_PRIVATE: privateNode_free (x->content.private); break;
6200 void exportNode_free (/*@null@*/ /*@only@*/ exportNode x)
6206 case XPK_CONST: constDeclarationNode_free (x->content.constdeclaration); break;
6207 case XPK_VAR: varDeclarationNode_free (x->content.vardeclaration); break;
6208 case XPK_TYPE: typeNode_free (x->content.type); break;
6209 case XPK_FCN: fcnNode_free (x->content.fcn); break;
6210 case XPK_CLAIM: claimNode_free (x->content.claim); break;
6211 case XPK_ITER: iterNode_free (x->content.iter); break;
6218 void privateNode_free (/*@null@*/ /*@only@*/ privateNode x)
6225 constDeclarationNode_free (x->content.constdeclaration); break;
6227 varDeclarationNode_free (x->content.vardeclaration); break;
6229 typeNode_free (x->content.type); break;
6231 fcnNode_free (x->content.fcn); break;
6238 void constDeclarationNode_free (/*@only@*/ /*@null@*/ constDeclarationNode x)
6242 lclTypeSpecNode_free (x->type);
6243 initDeclNodeList_free (x->decls);
6248 void typeNode_free (/*@only@*/ /*@null@*/ typeNode t)
6254 case TK_ABSTRACT: abstractNode_free (t->content.abstract); break;
6255 case TK_EXPOSED: exposedNode_free (t->content.exposed); break;
6256 case TK_UNION: taggedUnionNode_free (t->content.taggedunion); break;
6263 void claimNode_free (/*@only@*/ /*@null@*/ claimNode x)
6267 paramNodeList_free (x->params);
6268 globalList_free (x->globals);
6269 letDeclNodeList_free (x->lets);
6270 lclPredicateNode_free (x->require);
6271 programNode_free (x->body);
6272 lclPredicateNode_free (x->ensures);
6273 ltoken_free (x->name);
6278 void iterNode_free (/*@only@*/ /*@null@*/ iterNode x)
6282 paramNodeList_free (x->params);
6283 ltoken_free (x->name);
6288 void abstractNode_free (/*@only@*/ /*@null@*/ abstractNode x)
6292 abstBodyNode_free (x->body);
6293 ltoken_free (x->tok);
6294 ltoken_free (x->name);
6299 void exposedNode_free (/*@only@*/ /*@null@*/ exposedNode x)
6303 lclTypeSpecNode_free (x->type);
6304 declaratorInvNodeList_free (x->decls);
6305 ltoken_free (x->tok);
6310 void taggedUnionNode_free (/*@only@*/ /*@null@*/ taggedUnionNode x)
6314 stDeclNodeList_free (x->structdecls);
6315 declaratorNode_free (x->declarator);
6320 /*@only@*/ /*@null@*/ strOrUnionNode
6321 strOrUnionNode_copy (/*@null@*/ strOrUnionNode n)
6325 strOrUnionNode ret = (strOrUnionNode) dmalloc (sizeof (*ret));
6327 ret->kind = n->kind;
6328 ret->tok = ltoken_copy (n->tok);
6329 ret->opttagid = ltoken_copy (n->opttagid);
6330 ret->sort = n->sort;
6331 ret->structdecls = stDeclNodeList_copy (n->structdecls);
6341 void strOrUnionNode_free (/*@null@*/ /*@only@*/ strOrUnionNode n)
6345 stDeclNodeList_free (n->structdecls);
6346 ltoken_free (n->tok);
6347 ltoken_free (n->opttagid);
6352 void enumSpecNode_free (/*@null@*/ /*@only@*/ enumSpecNode x)
6356 ltokenList_free (x->enums);
6357 ltoken_free (x->tok);
6358 ltoken_free (x->opttagid);
6363 /*@only@*/ /*@null@*/ enumSpecNode enumSpecNode_copy (/*@null@*/ enumSpecNode x)
6367 enumSpecNode ret = (enumSpecNode) dmalloc (sizeof (*ret));
6369 ret->tok = ltoken_copy (x->tok);
6370 ret->opttagid = ltoken_copy (x->opttagid);
6371 ret->enums = ltokenList_copy (x->enums);
6372 ret->sort = x->sort;
6382 void lsymbol_setbool (lsymbol s)
6387 lsymbol lsymbol_getbool ()
6389 return lsymbol_bool;
6392 lsymbol lsymbol_getBool ()
6394 return lsymbol_Bool;
6397 lsymbol lsymbol_getFALSE ()
6399 return lsymbol_FALSE;
6402 lsymbol lsymbol_getTRUE ()
6404 return lsymbol_TRUE;