2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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 splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
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 "splintMacros.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_fromString (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 = g_sortFloat;
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 = g_sortBool;
240 ti->export = FALSE; /* this wasn't set (detected by Splint) */
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 = g_sortBool;
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 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 (inputStream_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 size_t 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_fromString (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));
1368 unsigned long int key;
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;
1416 static unsigned long opFormNode2key (opFormNode op, opFormKind k)
1418 unsigned long int key;
1423 /* OPF_IF is the first enum, so it's 0 */
1426 key = MASH (k, k + 1);
1434 { /* treat eq and = the same */
1435 lsymbol sym = ltoken_getText (op->content.anyop);
1437 if (sym == equalSymbol)
1439 key = MASH (k, eqSymbol);
1443 key = MASH (k, ltoken_getText (op->content.anyop));
1455 key = MASH (k, op->content.middle);
1456 key = MASH (key, ltoken_getRawText (op->tok));
1462 key = MASH (k, ltoken_getRawText (op->content.id));
1471 /*@only@*/ opFormNode
1472 makeOpFormNode (ltoken t, opFormKind k, opFormUnion u,
1475 opFormNode n = (opFormNode) dmalloc (sizeof (*n));
1476 unsigned long int key = 0;
1479 ** Assign a hash key here to speed up lookup of operators.
1489 n->content.middle = 0;
1490 /* OPF_IF is the first enum, so it's 0 */
1491 key = MASH /*@+enumint@*/ (k, k + 1) /*@=enumint@*/;
1497 { /* treat eq and = the same */
1498 lsymbol sym = ltoken_getText (u.anyop);
1500 if (sym == equalSymbol)
1502 key = MASH (k, eqSymbol);
1506 key = MASH (k, ltoken_getText (u.anyop));
1521 key = MASH (k, u.middle);
1522 key = MASH (key, ltoken_getRawText (t));
1528 key = MASH (k, ltoken_getRawText (u.id));
1533 llbug (message ("makeOpFormNode: unknown opFormKind: %d", (int) k));
1540 static cstring printMiddle (int j)
1543 char *s = mstring_createEmpty ();
1545 for (i = j; i >= 1; i--)
1547 s = mstring_concatFree1 (s, "__");
1551 s = mstring_concatFree1 (s, ", ");
1555 return cstring_fromCharsO (s);
1559 opFormNode_unparse (/*@null@*/ opFormNode n)
1561 if (n != (opFormNode) 0)
1566 return (cstring_makeLiteral ("if __ then __ else __ "));
1568 return (cstring_copy (ltoken_getRawString (n->content.anyop)));
1570 return (message ("__ %s", 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 %q %s",
1577 ltoken_getRawString (n->tok),
1578 printMiddle (n->content.middle),
1579 ltoken_getRawString (n->close)));
1581 return (message ("__ %s %q %s",
1582 ltoken_getRawString (n->tok),
1583 printMiddle (n->content.middle),
1584 ltoken_getRawString (n->close)));
1586 return (message ("%s %q %s __",
1587 ltoken_getRawString (n->tok),
1588 printMiddle (n->content.middle),
1589 ltoken_getRawString (n->close)));
1591 return (message ("__ %s%q %s __",
1592 ltoken_getRawString (n->tok),
1593 printMiddle (n->content.middle),
1594 ltoken_getRawString (n->close)));
1596 return (message ("[%q]", printMiddle (n->content.middle)));
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 (" \\select %s", ltoken_getRawString (n->content.id)));
1606 return (message (" \\field_arrow%s", ltoken_getRawString (n->content.id)));
1608 return (message ("__ \\select %s", ltoken_getRawString (n->content.id)));
1610 return (message ("__ \\field_arrow %s", ltoken_getRawString (n->content.id)));
1612 llfatalbug (message ("opFormNodeUnparse: unknown kind: %d",
1616 return cstring_undefined;
1619 /*@only@*/ typeNameNode
1620 makeTypeNameNode (bool isObj, lclTypeSpecNode t, abstDeclaratorNode n)
1622 typeNameNode tn = (typeNameNode) dmalloc (sizeof (*tn));
1623 typeNamePack p = (typeNamePack) dmalloc (sizeof (*p));
1625 tn->isTypeName = TRUE;
1629 tn->opform = (opFormNode) 0;
1634 /*@only@*/ typeNameNode
1635 makeTypeNameNodeOp (opFormNode n)
1637 typeNameNode t = (typeNameNode) dmalloc (sizeof (*t));
1638 t->typename = (typeNamePack) 0;
1640 t->isTypeName = FALSE;
1645 typeNameNode_unparse (/*@null@*/ typeNameNode n)
1647 if (n != (typeNameNode) 0)
1651 cstring st = cstring_undefined;
1652 typeNamePack p = n->typename;
1654 llassert (p != NULL);
1657 st = cstring_makeLiteral ("obj ");
1659 return (message ("%q%q%q", st, lclTypeSpecNode_unparse (p->type),
1660 abstDeclaratorNode_unparse (p->abst)));
1664 return (opFormNode_unparse (n->opform));
1666 return cstring_undefined;
1669 /*@only@*/ lclTypeSpecNode
1670 makeLclTypeSpecNodeConj (/*@null@*/ lclTypeSpecNode a, /*@null@*/ lclTypeSpecNode b)
1672 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1675 n->pointers = pointers_undefined;
1676 n->quals = qualList_new ();
1677 n->content.conj = (lclconj) dmalloc (sizeof (*n->content.conj));
1678 n->content.conj->a = a;
1679 n->content.conj->b = b;
1684 /*@only@*/ lclTypeSpecNode
1685 makeLclTypeSpecNodeType (/*@null@*/ CTypesNode x)
1687 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1690 n->pointers = pointers_undefined;
1691 n->content.type = x;
1692 n->quals = qualList_new ();
1696 /*@only@*/ lclTypeSpecNode
1697 makeLclTypeSpecNodeSU (/*@null@*/ strOrUnionNode x)
1699 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1701 n->kind = LTS_STRUCTUNION;
1702 n->pointers = pointers_undefined;
1703 n->content.structorunion = x;
1704 n->quals = qualList_new ();
1708 /*@only@*/ lclTypeSpecNode
1709 makeLclTypeSpecNodeEnum (/*@null@*/ enumSpecNode x)
1711 lclTypeSpecNode n = (lclTypeSpecNode) dmalloc (sizeof (*n));
1713 n->quals = qualList_new ();
1715 n->pointers = pointers_undefined;
1716 n->content.enumspec = x;
1721 lclTypeSpecNode_addQual (lclTypeSpecNode n, qual q)
1723 llassert (lclTypeSpecNode_isDefined (n));
1724 n->quals = qualList_add (n->quals, q);
1729 lclTypeSpecNode_unparse (/*@null@*/ lclTypeSpecNode n)
1731 if (n != (lclTypeSpecNode) 0)
1736 llassert (n->content.type != NULL);
1737 return (printLeaves (n->content.type->ctypes));
1738 case LTS_STRUCTUNION:
1739 return (strOrUnionNode_unparse (n->content.structorunion));
1741 return (enumSpecNode_unparse (n->content.enumspec));
1743 return (lclTypeSpecNode_unparse (n->content.conj->a));
1745 llfatalbug (message ("lclTypeSpecNode_unparse: unknown lclTypeSpec kind: %d",
1749 return cstring_undefined;
1752 /*@only@*/ enumSpecNode
1753 makeEnumSpecNode (ltoken t, ltoken optTagId,
1754 /*@owned@*/ ltokenList enums)
1756 enumSpecNode n = (enumSpecNode) dmalloc (sizeof (*n));
1758 smemberInfo *top = smemberInfo_undefined;
1761 n->opttagid = ltoken_copy (optTagId);
1764 /* generate sort for this LCL type */
1765 n->sort = sort_makeEnum (optTagId);
1767 if (!ltoken_isUndefined (optTagId))
1769 /* First, check to see if tag is already defined */
1770 ti = symtable_tagInfo (g_symtab, ltoken_getText (optTagId));
1772 if (tagInfo_exists (ti))
1774 if (ti->kind == TAG_ENUM)
1776 /* 23 Sep 1995 --- had been noting here...is this right? */
1778 ti->content.enums = enums;
1780 ti->imported = context_inImport ();
1785 message ("Tag %s previously defined as %q, redefined as enum",
1786 ltoken_getRawString (optTagId),
1787 tagKind_unparse (ti->kind)));
1789 /* evs --- shouldn't they be in different name spaces? */
1792 ltoken_free (optTagId);
1796 ti = (tagInfo) dmalloc (sizeof (*ti));
1798 ti->kind = TAG_ENUM;
1800 ti->content.enums = enums;
1802 ti->imported = context_inImport ();
1803 /* First, store tag info in symbol table */
1804 (void) symtable_enterTag (g_symtab, ti);
1808 /* check that enumeration constants are unique */
1810 ltokenList_reset (enums);
1812 while (!ltokenList_isFinished (enums))
1814 ltoken c = ltokenList_current (enums);
1815 smemberInfo *ei = (smemberInfo *) dmalloc (sizeof (*ei));
1817 ei->name = ltoken_getText (c);
1822 if (!varInfo_exists (symtable_varInfo (g_symtab, ltoken_getText (c))))
1823 { /* put info into symbol table */
1824 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
1826 vi->id = ltoken_copy (c);
1827 vi->kind = VRK_ENUM;
1831 (void) symtable_enterVar (g_symtab, vi);
1836 lclerror (c, message ("Enumerated value redeclared: %s",
1837 ltoken_getRawString (c)));
1838 ltokenList_removeCurrent (enums);
1840 ltokenList_advance (enums);
1845 (void) sort_updateEnum (n->sort, top);
1849 /*@only@*/ enumSpecNode
1850 makeEnumSpecNode2 (ltoken t, ltoken tagid)
1852 /* a reference, not a definition */
1853 enumSpecNode n = (enumSpecNode) dmalloc (sizeof (*n));
1854 tagInfo ti = symtable_tagInfo (g_symtab, ltoken_getText (tagid));
1857 n->opttagid = tagid;
1858 n->enums = ltokenList_new ();
1860 if (tagInfo_exists (ti))
1862 if (ti->kind == TAG_ENUM)
1868 n->sort = sort_makeNoSort ();
1869 lclerror (tagid, message ("Tag %s defined as %q, used as enum",
1870 ltoken_getRawString (tagid),
1871 tagKind_unparse (ti->kind)));
1876 n->sort = sort_makeNoSort ();
1877 lclerror (t, message ("Undefined type: enum %s",
1878 ltoken_getRawString (tagid)));
1885 enumSpecNode_unparse (/*@null@*/ enumSpecNode n)
1887 if (n != (enumSpecNode) 0)
1889 cstring s = cstring_makeLiteral ("enum ");
1891 if (!ltoken_isUndefined (n->opttagid))
1893 s = message ("%q%s ", s, ltoken_getRawString (n->opttagid));
1896 s = message ("%q{%q}", s, printLeaves2 (n->enums));
1899 return cstring_undefined;
1902 /*@only@*/ strOrUnionNode
1903 makestrOrUnionNode (ltoken str, suKind k, ltoken opttagid,
1904 /*@only@*/ stDeclNodeList x)
1906 strOrUnionNode n = (strOrUnionNode) dmalloc (sizeof (*n));
1907 lsymbolSet set = lsymbolSet_new ();
1908 declaratorNodeList declarators;
1909 sort fieldsort, tsort1, tsort2;
1910 smemberInfo *mi, *top = smemberInfo_undefined;
1912 bool isStruct = (k == SU_STRUCT);
1918 n->opttagid = ltoken_copy (opttagid);
1920 n->sort = isStruct ? sort_makeStr (opttagid) : sort_makeUnion (opttagid);
1922 if (!ltoken_isUndefined (opttagid))
1924 /* First, check to see if tag is already defined */
1925 t = symtable_tagInfo (g_symtab, ltoken_getText (opttagid));
1927 if (tagInfo_exists (t))
1929 if ((t->kind == TAG_FWDUNION && k == SU_UNION) ||
1930 (t->kind == TAG_FWDSTRUCT && k == SU_STRUCT))
1932 /* to allow self-recursive types and forward tag declarations */
1933 t->content.decls = stDeclNodeList_copy (x); /* update tag info */
1939 message ("Tag %s previously defined as %q, used as %q",
1940 ltoken_getRawString (opttagid),
1941 tagKind_unparse (t->kind),
1942 cstring_makeLiteral (isStruct ? "struct" : "union")));
1955 if (doTag && !ltoken_isUndefined (opttagid))
1957 t = (tagInfo) dmalloc (sizeof (*t));
1959 /* can either override prev defn or use prev defn */
1960 /* override it so as to detect more errors */
1962 t->kind = (k == SU_STRUCT) ? TAG_STRUCT : TAG_UNION;
1964 t->content.decls = stDeclNodeList_copy (x);
1966 t->imported = FALSE;
1968 /* Next, update tag info in symbol table */
1969 (void) symtable_enterTagForce (g_symtab, t);
1972 /* check no duplicate field names */
1974 stDeclNodeList_elements (x, i)
1976 fieldsort = lclTypeSpecNode2sort (i->lcltypespec);
1978 /* need the locations, not values */
1979 /* fieldsort = sort_makeObj (fieldsort); */
1981 fieldsort = sort_makeGlobal (fieldsort); */
1983 declarators = i->declarators;
1985 declaratorNodeList_elements (declarators, decl)
1988 mi = (smemberInfo *) dmalloc (sizeof (*mi));
1989 /* need to make dynamic copies */
1990 fieldname = ltoken_getText (decl->id);
1992 /* 2/19/93, added */
1993 tsort1 = typeExpr2ptrSort (fieldsort, decl->type);
1994 tsort2 = sort_makeGlobal (tsort1);
1996 mi->name = fieldname;
1997 mi->sort = tsort2; /* fieldsort; */
2001 if (lsymbolSet_member (set, fieldname))
2004 message ("Field name reused: %s",
2005 ltoken_getRawString (decl->id)));
2009 (void) lsymbolSet_insert (set, fieldname);
2012 } end_declaratorNodeList_elements;
2014 } end_stDeclNodeList_elements;
2018 (void) sort_updateStr (n->sort, top);
2022 (void) sort_updateUnion (n->sort, top);
2025 /* We shall keep the info with both tags and types if any
2026 of them are present. */
2028 lsymbolSet_free (set);
2033 /*@only@*/ strOrUnionNode
2034 makeForwardstrOrUnionNode (ltoken str, suKind k,
2037 strOrUnionNode n = (strOrUnionNode) dmalloc (sizeof (*n));
2038 sort sort = sort_makeNoSort ();
2041 /* a reference, not a definition */
2045 n->opttagid = tagid;
2046 n->structdecls = stDeclNodeList_new ();
2048 /* get sort for this LCL type */
2049 t = symtable_tagInfo (g_symtab, ltoken_getText (tagid));
2051 if (tagInfo_exists (t))
2055 if (!(((t->kind == TAG_STRUCT || t->kind == TAG_FWDSTRUCT) && k == SU_STRUCT)
2056 || ((t->kind == TAG_UNION || t->kind == TAG_FWDUNION) && k == SU_UNION)))
2059 message ("Tag %s previously defined as %q, used as %q",
2060 ltoken_getRawString (tagid),
2061 tagKind_unparse (t->kind),
2062 cstring_makeLiteral ((k == SU_STRUCT) ? "struct" : "union")));
2068 ** changed from error: 31 Mar 1994
2070 ** lclerror (str, message ("Undefined type: %s %s", s, ltoken_getRawString (tagid));
2074 /* forward struct's and union's are ok... */
2078 (void) checkAndEnterTag (TAG_FWDSTRUCT, ltoken_copy (tagid));
2079 lhForwardStruct (tagid);
2080 sort = sort_makeStr (tagid);
2084 (void) checkAndEnterTag (TAG_FWDUNION, ltoken_copy (tagid));
2085 lhForwardUnion (tagid);
2086 sort = sort_makeUnion (tagid);
2095 strOrUnionNode_unparse (/*@null@*/ strOrUnionNode n)
2097 if (n != (strOrUnionNode) 0)
2103 s = cstring_makeLiteral ("struct ");
2106 s = cstring_makeLiteral ("union ");
2111 if (!ltoken_isUndefined (n->opttagid))
2113 s = message ("%q%s ", s, ltoken_getRawString (n->opttagid));
2115 s = message ("%q{%q}", s, stDeclNodeList_unparse (n->structdecls));
2118 return cstring_undefined;
2121 /*@only@*/ stDeclNode
2122 makestDeclNode (lclTypeSpecNode s,
2123 declaratorNodeList x)
2125 stDeclNode n = (stDeclNode) dmalloc (sizeof (*n));
2133 makeFunctionNode (typeExpr x, paramNodeList p)
2135 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2138 y->kind = TEXPR_FCN;
2139 y->content.function.returntype = x;
2140 y->content.function.args = p;
2141 y->sort = sort_makeNoSort ();
2146 static /*@observer@*/ ltoken
2147 extractDeclarator (/*@null@*/ typeExpr t)
2149 if (t != (typeExpr) 0)
2154 return t->content.base;
2156 return (extractDeclarator (t->content.pointer));
2158 return (extractDeclarator (t->content.array.elementtype));
2160 return (extractDeclarator (t->content.function.returntype));
2164 return ltoken_undefined;
2168 makeTypeExpr (ltoken t)
2170 typeExpr x = (typeExpr) dmalloc (sizeof (*x));
2174 x->kind = TEXPR_BASE;
2175 x->content.base = t;
2176 x->sort = sort_makeNoSort ();
2182 /*@only@*/ declaratorNode
2183 makeDeclaratorNode (typeExpr t)
2185 declaratorNode x = (declaratorNode) dmalloc (sizeof (*x));
2187 x->id = ltoken_copy (extractDeclarator (t));
2189 x->isRedecl = FALSE;
2194 static /*@only@*/ declaratorNode
2195 makeUnknownDeclaratorNode (/*@only@*/ ltoken t)
2197 declaratorNode x = (declaratorNode) dmalloc (sizeof (*x));
2200 x->type = (typeExpr) 0;
2201 x->isRedecl = FALSE;
2206 static /*@only@*/ cstring
2207 printTypeExpr2 (/*@null@*/ typeExpr x)
2209 paramNodeList params;
2211 if (x != (typeExpr) 0)
2213 cstring s; /* print out types in reverse order */
2218 return (message ("%s ", ltoken_getRawString (x->content.base)));
2220 return (message ("%qptr to ", printTypeExpr2 (x->content.pointer)));
2222 return (message ("array[%q] of %q",
2223 termNode_unparse (x->content.array.size),
2224 printTypeExpr2 (x->content.array.elementtype)));
2226 s = printTypeExpr2 (x->content.function.returntype);
2227 params = x->content.function.args;
2228 if (!paramNodeList_empty (params))
2230 s = message ("%qfcn with args: (%q)", s,
2231 paramNodeList_unparse (x->content.function.args));
2234 s = message ("%qfcn with no args", s);
2237 llfatalbug (message ("printTypeExpr2: unknown typeExprKind: %d", (int) x->kind));
2240 return cstring_undefined;
2244 declaratorNode_unparse (declaratorNode x)
2246 return (typeExpr_unparse (x->type));
2249 /*@only@*/ declaratorNode
2250 declaratorNode_copy (declaratorNode x)
2252 declaratorNode ret = (declaratorNode) dmalloc (sizeof (*ret));
2254 ret->type = typeExpr_copy (x->type);
2255 ret->id = ltoken_copy (x->id);
2256 ret->isRedecl = x->isRedecl;
2261 static /*@null@*/ typeExpr typeExpr_copy (/*@null@*/ typeExpr x)
2269 typeExpr ret = (typeExpr) dmalloc (sizeof (*ret));
2271 ret->wrapped = x->wrapped;
2272 ret->kind = x->kind;
2277 ret->content.base = ltoken_copy (x->content.base);
2280 ret->content.pointer = typeExpr_copy (x->content.pointer);
2283 ret->content.array.elementtype = typeExpr_copy (x->content.array.elementtype);
2284 ret->content.array.size = termNode_copy (x->content.array.size);
2287 ret->content.function.returntype = typeExpr_copy (x->content.function.returntype);
2288 ret->content.function.args = paramNodeList_copy (x->content.function.args);
2292 ret->sort = x->sort;
2297 static /*@only@*/ cstring
2298 typeExpr_unparseCode (/*@null@*/ typeExpr x)
2300 /* print out types in order of appearance in source */
2301 cstring s = cstring_undefined;
2303 if (x != (typeExpr) 0)
2308 return (cstring_copy (ltoken_getRawString (x->content.base)));
2310 return (typeExpr_unparseCode (x->content.pointer));
2312 return (typeExpr_unparseCode (x->content.array.elementtype));
2314 return (typeExpr_unparseCode (x->content.function.returntype));
2320 void typeExpr_free (/*@only@*/ /*@null@*/ typeExpr x)
2322 if (x != (typeExpr) 0)
2329 typeExpr_free (x->content.pointer);
2332 typeExpr_free (x->content.array.elementtype);
2333 termNode_free (x->content.array.size);
2336 typeExpr_free (x->content.function.returntype);
2337 paramNodeList_free (x->content.function.args);
2349 declaratorNode_unparseCode (declaratorNode x)
2351 return (typeExpr_unparseCode (x->type));
2355 typeExpr_unparse (/*@null@*/ typeExpr x)
2357 cstring s = cstring_undefined; /* print out types in order of appearance in source */
2358 paramNodeList params;
2361 if (x != (typeExpr) 0)
2363 cstring front = cstring_undefined;
2364 cstring back = cstring_undefined;
2366 llassert (x->wrapped < 100);
2368 for (i = x->wrapped; i >= 1; i--)
2370 front = cstring_appendChar (front, '(');
2371 back = cstring_appendChar (back, ')');
2377 s = message ("%q%s", s, ltoken_getRawString (x->content.base));
2380 s = message ("%q*%q", s, typeExpr_unparse (x->content.pointer));
2383 s = message ("%q%q[%q]", s,
2384 typeExpr_unparse (x->content.array.elementtype),
2385 termNode_unparse (x->content.array.size));
2388 s = message ("%q%q (", s,
2389 typeExpr_unparse (x->content.function.returntype));
2390 params = x->content.function.args;
2392 if (!paramNodeList_empty (params))
2394 s = message ("%q%q", s,
2395 paramNodeList_unparse (x->content.function.args));
2398 s = message ("%q)", s);
2401 s = message ("%q%q%q", front, s, back);
2405 s = cstring_makeLiteral ("?");
2412 typeExpr_unparseNoBase (/*@null@*/ typeExpr x)
2414 cstring s = cstring_undefined; /* print out types in order of appearance in source */
2415 paramNodeList params;
2418 if (x != (typeExpr) 0)
2420 cstring front = cstring_undefined;
2421 cstring back = cstring_undefined;
2423 llassert (x->wrapped < 100);
2425 for (i = x->wrapped; i >= 1; i--)
2427 front = cstring_appendChar (front, '(');
2428 back = cstring_appendChar (back, ')');
2434 s = message ("%q /* %s */", s, ltoken_getRawString (x->content.base));
2437 s = message ("%q*%q", s, typeExpr_unparseNoBase (x->content.pointer));
2440 s = message ("%q%q[%q]", s,
2441 typeExpr_unparseNoBase (x->content.array.elementtype),
2442 termNode_unparse (x->content.array.size));
2445 s = message ("%q%q (", s,
2446 typeExpr_unparseNoBase (x->content.function.returntype));
2447 params = x->content.function.args;
2449 if (!paramNodeList_empty (params))
2451 s = message ("%q%q", s,
2452 paramNodeList_unparse (x->content.function.args));
2455 s = message ("%q)", s);
2458 s = message ("%q%q%q", front, s, back);
2462 s = cstring_makeLiteral ("?");
2469 typeExpr_name (/*@null@*/ typeExpr x)
2471 if (x != (typeExpr) 0)
2476 return (cstring_copy (ltoken_getRawString (x->content.base)));
2478 return (typeExpr_name (x->content.pointer));
2480 return (typeExpr_name (x->content.array.elementtype));
2482 return (typeExpr_name (x->content.function.returntype));
2486 /* evs --- 14 Mar 1995
2487 ** not a bug: its okay to have empty parameter names
2488 ** llbug ("typeExpr_name: null");
2491 return cstring_undefined;
2495 makePointerNode (ltoken star, /*@only@*/ /*@returned@*/ typeExpr x)
2497 if (x != (typeExpr)0 && (x->kind == TEXPR_FCN && (x->wrapped == 0)))
2499 x->content.function.returntype = makePointerNode (star, x->content.function.returntype);
2504 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2507 y->kind = TEXPR_PTR;
2508 y->content.pointer = x;
2509 y->sort = sort_makeNoSort ();
2516 typeExpr makeArrayNode (/*@returned@*/ typeExpr x,
2517 /*@only@*/ arrayQualNode a)
2519 if (x != (typeExpr)0 && (x->kind == TEXPR_FCN && (x->wrapped == 0)))
2522 ** Spurious errors reported here, because of referencing
2523 ** in makeArrayNode.
2527 x->content.function.returntype = makeArrayNode (x, a);
2535 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2537 y->kind = TEXPR_ARRAY;
2539 if (a == (arrayQualNode) 0)
2541 y->content.array.size = (termNode) 0;
2545 y->content.array.size = a->term;
2546 ltoken_free (a->tok);
2550 y->content.array.elementtype = x;
2551 y->sort = sort_makeNoSort ();
2557 /*@only@*/ constDeclarationNode
2558 makeConstDeclarationNode (lclTypeSpecNode t, initDeclNodeList decls)
2560 constDeclarationNode n = (constDeclarationNode) dmalloc (sizeof (*n));
2561 sort s, s2, initValueSort;
2562 ltoken varid, errtok;
2565 s = lclTypeSpecNode2sort (t);
2567 initDeclNodeList_elements (decls, init)
2569 declaratorNode vdnode = init->declarator;
2570 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
2572 varid = ltoken_copy (vdnode->id);
2573 s2 = typeExpr2ptrSort (s, vdnode->type);
2574 initValue = init->value;
2576 if (termNode_isDefined (initValue) && !initValue->error_reported)
2578 initValueSort = initValue->sort;
2580 /* should keep the arguments in order */
2581 if (!sort_member_modulo_cstring (s2, initValue)
2582 && !initValue->error_reported)
2584 errtok = termNode_errorToken (initValue);
2588 message ("Constant %s declared type %q, initialized to %q: %q",
2589 ltoken_unparse (varid),
2591 sort_unparse (initValueSort),
2592 termNode_unparse (initValue)));
2597 vi->kind = VRK_CONST;
2601 (void) symtable_enterVar (g_symtab, vi);
2604 } end_initDeclNodeList_elements;
2612 varDeclarationNode makeInternalStateNode (void)
2614 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2616 n->isSpecial = TRUE;
2617 n->sref = sRef_makeInternalState ();
2619 /*@-compdef@*/ return n; /*@=compdef@*/
2622 varDeclarationNode makeFileSystemNode (void)
2624 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2626 n->isSpecial = TRUE;
2627 n->sref = sRef_makeSystemState ();
2629 /*@-compdef@*/ return n; /*@=compdef@*/
2632 /*@only@*/ varDeclarationNode
2633 makeVarDeclarationNode (lclTypeSpecNode t, initDeclNodeList x,
2634 bool isGlobal, bool isPrivate)
2636 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2637 sort s, s2, initValueSort;
2638 ltoken varid, errtok;
2640 declaratorNode vdnode;
2642 n->isSpecial = FALSE;
2643 n->qualifier = QLF_NONE;
2644 n->isGlobal = isGlobal;
2645 n->isPrivate = isPrivate;
2648 s = lclTypeSpecNode2sort (t);
2650 /* t is an lclTypeSpec, its sort may not be assigned yet */
2652 initDeclNodeList_elements (x, init)
2654 vdnode = init->declarator;
2656 s2 = typeExpr2ptrSort (s, vdnode->type);
2657 initValue = init->value;
2659 if (termNode_isDefined (initValue) && !initValue->error_reported)
2661 initValueSort = initValue->sort;
2662 /* should keep the arguments in order */
2663 if (!sort_member_modulo_cstring (s2, initValue)
2664 && !initValue->error_reported)
2666 errtok = termNode_errorToken (initValue);
2669 message ("Variable %s declared type %q, initialized to %q",
2670 ltoken_unparse (varid),
2672 sort_unparse (initValueSort)));
2677 ** If global, check that it has been declared already, don't push
2678 ** onto symbol table yet (wrong scope, done in enteringFcnScope
2683 varInfo vi = symtable_varInfo (g_symtab, ltoken_getText (varid));
2685 if (!varInfo_exists (vi))
2688 message ("Undeclared global variable: %s",
2689 ltoken_getRawString (varid)));
2693 if (vi->kind == VRK_CONST)
2696 message ("Constant used in global list: %s",
2697 ltoken_getRawString (varid)));
2703 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
2705 vi->id = ltoken_copy (varid);
2708 vi->kind = VRK_PRIVATE;
2709 /* check that initValue is not empty */
2710 if (initValue == (termNode) 0)
2713 message ("Private variable must have initialization: %s",
2714 ltoken_getRawString (varid)));
2722 vi->sort = sort_makeGlobal (s2);
2725 vdnode->isRedecl = symtable_enterVar (g_symtab, vi);
2728 } end_initDeclNodeList_elements;
2735 /*@only@*/ initDeclNode
2736 makeInitDeclNode (declaratorNode d, termNode x)
2738 initDeclNode n = (initDeclNode) dmalloc (sizeof (*n));
2745 /*@only@*/ abstractNode
2746 makeAbstractNode (ltoken t, ltoken name,
2747 bool isMutable, bool isRefCounted, abstBodyNode a)
2749 abstractNode n = (abstractNode) dmalloc (sizeof (*n));
2751 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
2754 n->isMutable = isMutable;
2757 n->isRefCounted = isRefCounted;
2760 handle = sort_makeMutable (name, ltoken_getText (name));
2762 handle = sort_makeImmutable (name, ltoken_getText (name));
2765 ti->id = ltoken_createType (ltoken_getCode (ltoken_typename), SID_TYPE,
2766 ltoken_getText (name));
2767 ti->modifiable = isMutable;
2768 ti->abstract = TRUE;
2769 ti->basedOn = handle;
2772 symtable_enterType (g_symtab, ti);
2779 abstractNode_unparse (abstractNode n)
2781 if (n != (abstractNode) 0)
2786 s = cstring_makeLiteral ("mutable");
2788 s = cstring_makeLiteral ("immutable");
2790 return (message ("%q type %s%q;", s, ltoken_getRawString (n->name),
2791 abstBodyNode_unparse (n->body)));
2793 return cstring_undefined;
2797 setExposedType (lclTypeSpecNode s)
2802 /*@only@*/ exposedNode
2803 makeExposedNode (ltoken t, lclTypeSpecNode s,
2804 declaratorInvNodeList d)
2806 exposedNode n = (exposedNode) dmalloc (sizeof (*n));
2816 exposedNode_unparse (exposedNode n)
2818 if (n != (exposedNode) 0)
2820 return (message ("typedef %q %q;",
2821 lclTypeSpecNode_unparse (n->type),
2822 declaratorInvNodeList_unparse (n->decls)));
2824 return cstring_undefined;
2827 /*@only@*/ declaratorInvNode
2828 makeDeclaratorInvNode (declaratorNode d, abstBodyNode b)
2830 declaratorInvNode n = (declaratorInvNode) dmalloc (sizeof (*n));
2838 declaratorInvNode_unparse (declaratorInvNode d)
2840 return (message ("%q%q", declaratorNode_unparse (d->declarator),
2841 abstBodyNode_unparseExposed (d->body)));
2845 abstBodyNode_unparse (abstBodyNode n)
2847 if (n != (abstBodyNode) 0)
2849 return (lclPredicateNode_unparse (n->typeinv));
2851 return cstring_undefined;
2855 abstBodyNode_unparseExposed (abstBodyNode n)
2857 if (n != (abstBodyNode) 0)
2859 return (message ("%q", lclPredicateNode_unparse (n->typeinv)));
2861 return cstring_undefined;
2865 taggedUnionNode_unparse (taggedUnionNode n)
2867 if (n != (taggedUnionNode) 0)
2869 return (message ("tagged union {%q}%q;\n",
2870 stDeclNodeList_unparse (n->structdecls),
2871 declaratorNode_unparse (n->declarator)));
2873 return cstring_undefined;
2876 static /*@observer@*/ paramNodeList
2877 typeExpr_toParamNodeList (/*@null@*/ typeExpr te)
2879 if (te != (typeExpr) 0)
2884 return te->content.function.args;
2886 return typeExpr_toParamNodeList (te->content.pointer);
2888 /* return typeExpr_toParamNodeList (te->content.array.elementtype); */
2890 return paramNodeList_undefined;
2893 return paramNodeList_undefined;
2897 fcnNode_fromDeclarator (/*@only@*/ /*@null@*/ lclTypeSpecNode t,
2898 /*@only@*/ declaratorNode d)
2900 return (makeFcnNode (qual_createUnknown (), t, d,
2901 varDeclarationNodeList_new (),
2902 varDeclarationNodeList_new (),
2903 letDeclNodeList_new (),
2904 (lclPredicateNode) 0,
2905 (lclPredicateNode) 0,
2907 (lclPredicateNode) 0,
2908 (lclPredicateNode) 0));
2912 makeIterNode (ltoken id, paramNodeList p)
2914 iterNode x = (iterNode) dmalloc (sizeof (*x));
2915 bool hasYield = FALSE;
2920 /* check there is at least one yield param */
2922 paramNodeList_elements (p, pe)
2924 if (paramNode_isYield (pe))
2929 } end_paramNodeList_elements
2933 lclerror (id, message ("Iterator has no yield parameters: %s",
2934 ltoken_getRawString (id)));
2941 makeFcnNode (qual specQual,
2942 /*@null@*/ lclTypeSpecNode t,
2944 /*@null@*/ globalList g,
2945 /*@null@*/ varDeclarationNodeList privateinits,
2946 /*@null@*/ letDeclNodeList lets,
2947 /*@null@*/ lclPredicateNode checks,
2948 /*@null@*/ lclPredicateNode requires,
2949 /*@null@*/ modifyNode m,
2950 /*@null@*/ lclPredicateNode ensures,
2951 /*@null@*/ lclPredicateNode claims)
2953 fcnNode x = (fcnNode) dmalloc (sizeof (*x));
2955 if (d->type != (typeExpr)0 && (d->type)->kind != TEXPR_FCN)
2957 lclerror (d->id, cstring_makeLiteral
2958 ("Attempt to specify function without parameter list"));
2959 d->type = makeFunctionNode (d->type, paramNodeList_new ());
2962 x->special = specQual;
2966 x->inits = privateinits;
2969 x->require = requires;
2971 x->ensures = ensures;
2974 /* extract info to fill in x->name =; x->signature =; */
2975 x->name = ltoken_copy (d->id);
2980 /*@only@*/ claimNode
2981 makeClaimNode (ltoken id, paramNodeList p,
2982 globalList g, letDeclNodeList lets, lclPredicateNode requires,
2983 programNode b, lclPredicateNode ensures)
2985 claimNode x = (claimNode) dmalloc (sizeof (*x));
2992 x->require = requires;
2994 x->ensures = ensures;
2998 /*@only@*/ lclPredicateNode
2999 makeIntraClaimNode (ltoken t, lclPredicateNode n)
3001 ltoken_free (n->tok);
3003 n->kind = LPD_INTRACLAIM;
3007 /*@only@*/ lclPredicateNode
3008 makeRequiresNode (ltoken t, lclPredicateNode n)
3010 ltoken_free (n->tok);
3012 n->kind = LPD_REQUIRES;
3016 /*@only@*/ lclPredicateNode
3017 makeChecksNode (ltoken t, lclPredicateNode n)
3019 ltoken_free (n->tok);
3021 n->kind = LPD_CHECKS;
3025 /*@only@*/ lclPredicateNode
3026 makeEnsuresNode (ltoken t, lclPredicateNode n)
3028 ltoken_free (n->tok);
3030 n->kind = LPD_ENSURES;
3034 /*@only@*/ lclPredicateNode
3035 makeLclPredicateNode (ltoken t, termNode n,
3038 lclPredicateNode x = (lclPredicateNode) dmalloc (sizeof (*x));
3046 /*@only@*/ quantifierNode
3047 makeQuantifierNode (varNodeList v, ltoken quant)
3049 quantifierNode x = (quantifierNode) dmalloc (sizeof (*x));
3053 x->isForall = cstring_equalLit (ltoken_unparse (quant), "\forall");
3058 /*@only@*/ arrayQualNode
3059 makeArrayQualNode (ltoken t, termNode term)
3061 arrayQualNode x = (arrayQualNode) dmalloc (sizeof (*x));
3069 makeVarNode (/*@only@*/ ltoken varid, bool isObj, lclTypeSpecNode t)
3071 varNode x = (varNode) dmalloc (sizeof (*x));
3072 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
3075 vi->id = ltoken_copy (varid);
3076 sort = lclTypeSpecNode2sort (t);
3078 /* 9/3/93, The following is needed because we want value sorts to be
3079 the default, object sort is generated only if there is "obj" qualifier.
3080 There are 2 cases: (1) for immutable types (including C primitive types),
3081 we need to generate the object sort if qualifier is present; (2) for
3082 array, struct and union types, they are already in their object sorts.
3085 sort = sort_makeVal (sort); /* both cases are now value sorts */
3089 sort = sort_makeObj (sort);
3094 vi->kind = VRK_QUANT;
3097 (void) symtable_enterVar (g_symtab, vi);
3103 x->sort = sort_makeNoSort ();
3108 /*@only@*/ abstBodyNode
3109 makeAbstBodyNode (ltoken t, fcnNodeList f)
3111 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3114 x->typeinv = (lclPredicateNode)0;
3119 /*@only@*/ abstBodyNode
3120 makeExposedBodyNode (ltoken t, lclPredicateNode inv)
3122 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3126 x->fcns = fcnNodeList_undefined;
3130 /*@only@*/ abstBodyNode
3131 makeAbstBodyNode2 (ltoken t, ltokenList ops)
3133 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3136 x->typeinv = (lclPredicateNode) 0;
3138 x->fcns = fcnNodeList_new ();
3140 ltokenList_elements (ops, op)
3142 x->fcns = fcnNodeList_add
3144 fcnNode_fromDeclarator (lclTypeSpecNode_undefined,
3145 makeUnknownDeclaratorNode (ltoken_copy (op))));
3146 } end_ltokenList_elements;
3148 ltokenList_free (ops);
3154 makeStmtNode (ltoken varId, ltoken fcnId, /*@only@*/ termNodeList v)
3156 stmtNode n = (stmtNode) dmalloc (sizeof (*n));
3159 n->operator = fcnId;
3164 /* printDeclarators -> declaratorNodeList_unparse */
3166 static cstring abstDeclaratorNode_unparse (abstDeclaratorNode x)
3168 return (typeExpr_unparse ((typeExpr) x));
3171 /*@only@*/ paramNode
3172 makeParamNode (lclTypeSpecNode t, typeExpr d)
3174 paramNode x = (paramNode) dmalloc (sizeof (*x));
3176 paramNode_checkQualifiers (t, d);
3180 x->kind = PNORMAL; /*< forgot this! >*/
3185 /*@only@*/ paramNode
3186 paramNode_elipsis (void)
3188 paramNode x = (paramNode) dmalloc (sizeof (*x));
3190 x->type = (lclTypeSpecNode) 0;
3191 x->paramdecl = (typeExpr) 0;
3197 static /*@observer@*/ ltoken typeExpr_getTok (typeExpr d)
3199 while (d != (typeExpr)0)
3201 if (d->kind == TEXPR_BASE)
3203 return (d->content.base);
3207 if (d->kind == TEXPR_PTR)
3209 d = d->content.pointer;
3211 else if (d->kind == TEXPR_ARRAY)
3213 d = d->content.array.elementtype;
3215 else if (d->kind == TEXPR_FCN)
3217 d = d->content.function.returntype;
3226 llfatalerror (cstring_makeLiteral ("typeExpr_getTok: unreachable code"));
3231 paramNode_checkQualifiers (lclTypeSpecNode t, typeExpr d)
3233 bool isPointer = FALSE;
3234 bool isUser = FALSE;
3235 bool hasAlloc = FALSE;
3236 bool hasAlias = FALSE;
3238 llassert (lclTypeSpecNode_isDefined (t));
3240 if (pointers_isUndefined (t->pointers)
3241 && (d != (typeExpr)0 && d->kind != TEXPR_PTR) && d->kind != TEXPR_ARRAY)
3243 if (t->kind == LTS_TYPE)
3247 llassert (t->content.type != NULL);
3249 sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
3251 if (sn->kind == SRT_PTR || sn->kind == SRT_ARRAY
3252 || sn->kind == SRT_HOF || sn->kind == SRT_NONE)
3263 if (d != (typeExpr)0 && d->kind != TEXPR_BASE)
3265 if (t->kind == LTS_TYPE)
3269 llassert (t->content.type != NULL);
3270 sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
3272 if (sn->kind == SRT_PTR || sn->kind == SRT_ARRAY
3273 || sn->kind == SRT_HOF || sn->kind == SRT_NONE)
3284 if (d != (typeExpr)NULL)
3286 qualList_elements (t->quals, q)
3288 if (qual_isAllocQual (q))
3292 ltoken tok = typeExpr_getTok (d);
3293 lclerror (tok, message ("Parameter declared with multiple allocation "
3294 "qualifiers: %q", typeExpr_unparse (d)));
3300 ltoken tok = typeExpr_getTok (d);
3301 lclerror (tok, message ("Non-pointer declared as %s parameter: %q",
3303 typeExpr_unparse (d)));
3306 if (qual_isAliasQual (q))
3310 ltoken tok = typeExpr_getTok (d);
3311 lclerror (tok, message ("Parameter declared with multiple alias qualifiers: %q",
3312 typeExpr_unparse (d)));
3316 if (!(isPointer || isUser))
3318 ltoken tok = typeExpr_getTok (d);
3319 lclerror (tok, message ("Unsharable type declared as %s parameter: %q",
3321 typeExpr_unparse (d)));
3324 } end_qualList_elements;
3329 paramNode_unparse (paramNode x)
3331 if (x != (paramNode) 0)
3333 if (x->kind == PELIPSIS)
3335 return (cstring_makeLiteral ("..."));
3338 if (x->paramdecl != (typeExpr) 0)
3339 { /* handle (void) */
3340 return (message ("%q %q", lclTypeSpecNode_unparse (x->type),
3341 typeExpr_unparse (x->paramdecl)));
3345 return (lclTypeSpecNode_unparse (x->type));
3348 return cstring_undefined;
3352 lclTypeSpecNode_unparseAltComments (/*@null@*/ lclTypeSpecNode typespec) /*@*/
3354 if (typespec != (lclTypeSpecNode) 0)
3356 cstring s = qualList_toCComments (typespec->quals);
3358 switch (typespec->kind)
3362 llassert (typespec->content.type != NULL);
3364 return (cstring_concatFree
3365 (s, printLeaves (typespec->content.type->ctypes)));
3370 enumSpecNode n = typespec->content.enumspec;
3372 s = cstring_concatFree (s, cstring_makeLiteral ("enum"));
3373 llassert (n != NULL);
3375 if (!ltoken_isUndefined (n->opttagid))
3377 s = message ("%q %s", s, ltoken_unparse (n->opttagid));
3379 s = message ("%q {", s);
3381 ltokenList_elements (n->enums, e)
3386 s = message ("%q%s", s, ltoken_getRawString (e));
3389 s = message ("%q, %s", s, ltoken_getRawString (e));
3390 } end_ltokenList_elements;
3392 return (message ("%q}", s));
3394 case LTS_STRUCTUNION:
3396 strOrUnionNode n = typespec->content.structorunion;
3397 stDeclNodeList decls;
3399 llassert (n != NULL);
3404 s = cstring_concatFree (s, cstring_makeLiteral ("struct "));
3405 /*@switchbreak@*/ break;
3407 s = cstring_concatFree (s, cstring_makeLiteral ("union "));
3408 /*@switchbreak@*/ break;
3411 if (!ltoken_isUndefined (n->opttagid))
3413 if (stDeclNodeList_size (n->structdecls) == 0)
3415 return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
3418 s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid));
3422 s = message ("%q{\n\t", s);
3425 decls = n->structdecls;
3427 stDeclNodeList_elements (decls, f)
3429 s = message ("%q%q %q;\n\t", s,
3430 lclTypeSpecNode_unparseAltComments (f->lcltypespec),
3431 declaratorNodeList_unparse (f->declarators));
3432 } end_stDeclNodeList_elements;
3434 return (message ("%q }", s));
3443 lclTypeSpecNode_unparseAltComments (typespec->content.conj->a),
3444 lclTypeSpecNode_unparseAltComments (typespec->content.conj->b)));
3451 llcontbuglit ("lclTypeSpecNode_unparseComments: null typespec");
3453 return cstring_undefined;
3459 cstring lclTypeSpecNode_unparseComments (/*@null@*/ lclTypeSpecNode typespec)
3461 if (typespec != (lclTypeSpecNode) 0)
3463 cstring s = qualList_toCComments (typespec->quals);
3465 switch (typespec->kind)
3469 llassert (typespec->content.type != NULL);
3471 return (cstring_concatFree
3472 (s, printLeaves (typespec->content.type->ctypes)));
3477 enumSpecNode n = typespec->content.enumspec;
3479 s = cstring_concatFree (s, cstring_makeLiteral ("enum"));
3480 llassert (n != NULL);
3482 if (!ltoken_isUndefined (n->opttagid))
3484 s = message ("%q %s", s, ltoken_unparse (n->opttagid));
3486 s = message ("%q {", s);
3488 ltokenList_elements (n->enums, e)
3493 s = message ("%q%s", s, ltoken_getRawString (e));
3496 s = message ("%q, %s", s, ltoken_getRawString (e));
3497 } end_ltokenList_elements;
3499 return (message ("%q}", s));
3501 case LTS_STRUCTUNION:
3503 strOrUnionNode n = typespec->content.structorunion;
3504 stDeclNodeList decls;
3506 llassert (n != NULL);
3511 s = cstring_concatFree (s, cstring_makeLiteral ("struct "));
3512 /*@switchbreak@*/ break;
3514 s = cstring_concatFree (s, cstring_makeLiteral ("union "));
3515 /*@switchbreak@*/ break;
3518 if (!ltoken_isUndefined (n->opttagid))
3520 if (stDeclNodeList_size (n->structdecls) == 0)
3522 return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
3525 s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid));
3529 s = message ("%q{\n\t", s);
3532 decls = n->structdecls;
3534 stDeclNodeList_elements (decls, f)
3536 s = message ("%q%q %q;\n\t", s,
3537 lclTypeSpecNode_unparseComments (f->lcltypespec),
3538 declaratorNodeList_unparse (f->declarators));
3539 } end_stDeclNodeList_elements;
3541 return (message ("%q }", s));
3550 lclTypeSpecNode_unparseComments (typespec->content.conj->a),
3551 lclTypeSpecNode_unparseAltComments (typespec->content.conj->b)));
3558 llcontbuglit ("lclTypeSpecNode_unparseComments: null typespec");
3560 return cstring_undefined;
3567 paramNode_unparseComments (paramNode x)
3569 if (x != (paramNode) 0)
3571 if (x->kind == PELIPSIS)
3573 return (cstring_makeLiteral ("..."));
3576 if (x->paramdecl != (typeExpr) 0)
3577 { /* handle (void) */
3578 return (message ("%q %q",
3579 lclTypeSpecNode_unparseComments (x->type),
3580 typeExpr_unparseNoBase (x->paramdecl)));
3584 return (lclTypeSpecNode_unparseComments (x->type));
3587 return cstring_undefined;
3591 makeIfTermNode (ltoken ift, termNode ifn, ltoken thent,
3592 termNode thenn, ltoken elset,
3595 termNode t = (termNode) dmalloc (sizeof (*t));
3596 opFormNode opform = makeOpFormNode (ift, OPF_IF, opFormUnion_createMiddle (0),
3598 nameNode nn = makeNameNodeForm (opform);
3599 termNodeList args = termNodeList_new ();
3601 t->error_reported = FALSE;
3603 termNodeList_addh (args, ifn);
3604 termNodeList_addh (args, thenn);
3605 termNodeList_addh (args, elsen);
3608 t->kind = TRM_APPLICATION;
3609 t->sort = sort_makeNoSort ();
3611 t->possibleSorts = sortSet_new ();
3612 t->possibleOps = lslOpSet_new ();
3614 ltoken_free (thent);
3615 ltoken_free (elset);
3620 static /*@observer@*/ ltoken
3621 nameNode2anyOp (nameNode n)
3623 if (n != (nameNode) 0)
3625 opFormNode opnode = n->content.opform;
3628 llassert (opnode != NULL);
3630 kind = opnode->kind;
3632 if (kind == OPF_MANYOPM || kind == OPF_ANYOP ||
3633 kind == OPF_MANYOP || kind == OPF_ANYOPM)
3637 u = opnode->content;
3641 return ltoken_undefined;
3645 makeInfixTermNode (termNode x, ltoken op, termNode y)
3647 termNode t = (termNode) dmalloc (sizeof (*t));
3650 termNodeList args = termNodeList_new ();
3652 checkAssociativity (x, op);
3654 opform = makeOpFormNode (op, OPF_MANYOPM,
3655 opFormUnion_createAnyOp (op),
3658 nn = makeNameNodeForm (opform);
3660 t->error_reported = FALSE;
3662 termNodeList_addh (args, x);
3663 termNodeList_addh (args, y);
3666 t->kind = TRM_APPLICATION;
3667 t->sort = sort_makeNoSort ();
3669 t->possibleSorts = sortSet_new (); /* sort_equal */
3670 t->possibleOps = lslOpSet_new ();
3674 /*@only@*/ quantifiedTermNode
3675 quantifiedTermNode_copy (quantifiedTermNode q)
3677 quantifiedTermNode ret = (quantifiedTermNode) dmalloc (sizeof (*ret));
3679 ret->quantifiers = quantifierNodeList_copy (q->quantifiers);
3680 ret->open = ltoken_copy (q->open);
3681 ret->close = ltoken_copy (q->close);
3682 ret->body = termNode_copySafe (q->body);
3688 makeQuantifiedTermNode (quantifierNodeList qn, ltoken open,
3689 termNode t, ltoken close)
3692 termNode n = (termNode) dmalloc (sizeof (*n));
3693 quantifiedTermNode q = (quantifiedTermNode) dmalloc (sizeof (*q));
3695 n->name = NULL; /*> missing this --- detected by splint <*/
3696 n->error_reported = FALSE;
3698 n->error_reported = FALSE;
3699 n->kind = TRM_QUANTIFIER;
3700 n->possibleSorts = sortSet_new ();
3701 n->possibleOps = lslOpSet_new ();
3702 n->kind = TRM_UNCHANGEDALL;
3703 n->args = termNodeList_new (); /*< forgot this >*/
3705 termNodeList_free (t->args);
3706 t->args = termNodeList_new ();
3710 (void) sortSet_insert (n->possibleSorts, sort);
3712 q->quantifiers = qn;
3722 makePostfixTermNode (/*@returned@*/ /*@only@*/ termNode secondary, ltokenList postfixops)
3724 termNode top = secondary;
3726 ltokenList_elements (postfixops, op)
3728 top = makePostfixTermNode2 (top, ltoken_copy (op));
3729 /*@i@*/ } end_ltokenList_elements;
3731 ltokenList_free (postfixops);
3733 return (top); /* dep as only? */
3737 ** secondary is returned in the args list
3741 makePostfixTermNode2 (/*@returned@*/ /*@only@*/ termNode secondary,
3742 /*@only@*/ ltoken postfixop)
3744 termNode t = (termNode) dmalloc (sizeof (*t));
3746 opFormNode opform = makeOpFormNode (postfixop,
3747 OPF_MANYOP, opFormUnion_createAnyOp (postfixop),
3749 nameNode nn = makeNameNodeForm (opform);
3750 termNodeList args = termNodeList_new ();
3752 t->error_reported = FALSE;
3754 termNodeList_addh (args, secondary);
3757 t->kind = TRM_APPLICATION;
3758 t->sort = sort_makeNoSort ();
3760 t->possibleSorts = sortSet_new ();
3761 t->possibleOps = lslOpSet_new ();
3766 makePrefixTermNode (ltoken op, termNode arg)
3768 termNode t = (termNode) dmalloc (sizeof (*t));
3769 termNodeList args = termNodeList_new ();
3770 opFormNode opform = makeOpFormNode (op, OPF_ANYOPM, opFormUnion_createAnyOp (op),
3772 nameNode nn = makeNameNodeForm (opform);
3774 t->error_reported = FALSE;
3777 termNodeList_addh (args, arg);
3779 t->kind = TRM_APPLICATION;
3780 t->sort = sort_makeNoSort ();
3782 t->possibleSorts = sortSet_new ();
3783 t->possibleOps = lslOpSet_new ();
3788 makeOpCallTermNode (ltoken op, ltoken open,
3789 termNodeList args, ltoken close)
3791 /* like prefixTerm, but with opId LPAR termNodeList RPAR */
3792 termNode t = (termNode) dmalloc (sizeof (*t));
3793 nameNode nn = makeNameNodeId (op);
3795 t->error_reported = FALSE;
3799 t->kind = TRM_APPLICATION;
3800 t->sort = sort_makeNoSort ();
3802 t->possibleSorts = sortSet_new ();
3803 t->possibleOps = lslOpSet_new ();
3806 ltoken_free (close);
3811 /*@exposed@*/ termNode
3812 CollapseInfixTermNode (/*@returned@*/ termNode secondary, termNodeList infix)
3814 termNode left = secondary;
3816 termNodeList_elements (infix, node)
3818 termNodeList_addl (node->args, termNode_copySafe (left));
3820 /* computePossibleSorts (left); */
3821 } end_termNodeList_elements;
3827 checkAssociativity (termNode x, ltoken op)
3831 if (x->wrapped == 0 && /* no parentheses */
3832 x->kind == TRM_APPLICATION && x->name != (nameNode) 0 &&
3835 lastOpToken = nameNode2anyOp (x->name);
3837 if ((ltoken_getCode (lastOpToken) == logicalOp &&
3838 ltoken_getCode (op) == logicalOp) ||
3839 ((ltoken_getCode (lastOpToken) == simpleOp ||
3840 ltoken_getCode (lastOpToken) == LLT_MULOP) &&
3841 (ltoken_getCode (op) == simpleOp ||
3842 ltoken_getCode (op) == LLT_MULOP)))
3843 if (ltoken_getText (lastOpToken) != ltoken_getText (op))
3847 ("Parentheses needed to specify associativity of %s and %s",
3848 cstring_fromChars (lsymbol_toChars (ltoken_getText (lastOpToken))),
3849 cstring_fromChars (lsymbol_toChars (ltoken_getText (op)))));
3855 pushInfixOpPartNode (/*@returned@*/ termNodeList x, ltoken op,
3856 /*@only@*/ termNode secondary)
3858 termNode lastLeftTerm;
3859 termNodeList args = termNodeList_new ();
3860 termNode t = (termNode) dmalloc (sizeof (*t));
3864 termNodeList_addh (args, secondary);
3866 if (!termNodeList_empty (x))
3868 termNodeList_reset (x);
3869 lastLeftTerm = termNodeList_current (x);
3870 checkAssociativity (lastLeftTerm, op);
3873 opform = makeOpFormNode (op, OPF_MANYOPM,
3874 opFormUnion_createAnyOp (op), ltoken_undefined);
3876 nn = makeNameNodeForm (opform);
3878 t->error_reported = FALSE;
3881 t->kind = TRM_APPLICATION;
3883 t->sort = sort_makeNoSort ();
3885 t->possibleSorts = sortSet_new ();
3886 t->possibleOps = lslOpSet_new ();
3887 termNodeList_addh (x, t);
3888 /* don't compute sort yet, do it in CollapseInfixTermNode */
3893 updateMatchedNode (/*@only@*/ termNode left, /*@returned@*/ termNode t,
3894 /*@only@*/ termNode right)
3898 if ((t == (termNode) 0) || (t->name == NULL) || t->name->isOpId)
3900 llbugexitlit ("updateMatchedNode: expect opForm in nameNode");
3903 op = t->name->content.opform;
3904 llassert (op != NULL);
3906 if (left == (termNode) 0)
3908 if (right == (termNode) 0)
3910 /* op->kind is not changed */
3911 termNode_free (right);
3915 op->kind = OPF_MIDDLEM;
3916 op->key = opFormNode2key (op, OPF_MIDDLEM);
3917 termNodeList_addh (t->args, right);
3922 termNodeList_addl (t->args, left);
3923 if (right == (termNode) 0)
3925 op->kind = OPF_MMIDDLE;
3926 op->key = opFormNode2key (op, OPF_MMIDDLE);
3930 op->kind = OPF_MMIDDLEM;
3931 op->key = opFormNode2key (op, OPF_MMIDDLEM);
3932 termNodeList_addh (t->args, right);
3939 updateSqBracketedNode (/*@only@*/ termNode left,
3940 /*@only@*/ /*@returned@*/ termNode t,
3941 /*@only@*/ termNode right)
3945 if ((t == (termNode) 0) || (t->name == NULL) || (t->name->isOpId))
3947 llbugexitlit ("updateSqBracketededNode: expect opForm in nameNode");
3950 op = t->name->content.opform;
3951 llassert (op != NULL);
3953 if (left == (termNode) 0)
3955 if (right == (termNode) 0)
3957 /* op->kind is not changed */
3961 op->kind = OPF_BMIDDLEM;
3962 op->key = opFormNode2key (op, OPF_BMIDDLEM);
3963 termNodeList_addh (t->args, right);
3968 termNodeList_addl (t->args, left);
3970 if (right == (termNode) 0)
3972 op->kind = OPF_BMMIDDLE;
3973 op->key = opFormNode2key (op, OPF_BMMIDDLE);
3977 op->kind = OPF_BMMIDDLEM;
3978 op->key = opFormNode2key (op, OPF_BMMIDDLEM);
3979 termNodeList_addh (t->args, right);
3986 makeSqBracketedNode (ltoken lbracket,
3987 termNodeList args, ltoken rbracket)
3989 termNode t = (termNode) dmalloc (sizeof (*t));
3994 t->error_reported = FALSE;
3997 size = termNodeList_size (args);
3998 opform = makeOpFormNode (lbracket, OPF_BMIDDLE, opFormUnion_createMiddle (size),
4000 nn = makeNameNodeForm (opform);
4002 t->kind = TRM_APPLICATION;
4004 t->sort = sort_makeNoSort ();
4006 t->possibleSorts = sortSet_new ();
4007 t->possibleOps = lslOpSet_new ();
4008 /* do sort checking later, not here, incomplete parse */
4013 makeMatchedNode (ltoken open, termNodeList args, ltoken close)
4015 /* matched : open args close */
4016 termNode t = (termNode) dmalloc (sizeof (*t));
4021 t->error_reported = FALSE;
4024 size = termNodeList_size (args);
4025 opform = makeOpFormNode (open, OPF_MIDDLE, opFormUnion_createMiddle (size), close);
4026 nn = makeNameNodeForm (opform);
4028 t->kind = TRM_APPLICATION;
4030 t->sort = sort_makeNoSort ();
4032 t->possibleSorts = sortSet_new ();
4033 t->possibleOps = lslOpSet_new ();
4034 /* do sort checking later, not here, incomplete parse */
4039 makeSimpleTermNode (ltoken varid)
4041 sort theSort = sort_makeNoSort ();
4045 termNode n = (termNode) dmalloc (sizeof (*n));
4047 n->error_reported = FALSE;
4049 n->name = (nameNode) 0;
4051 n->args = termNodeList_new ();
4052 n->possibleSorts = sortSet_new ();
4053 n->possibleOps = lslOpSet_new ();
4055 sym = ltoken_getText (varid);
4057 /* lookup current scope */
4058 vi = symtable_varInfoInScope (g_symtab, sym);
4060 if (varInfo_exists (vi))
4066 (void) sortSet_insert (n->possibleSorts, theSort);
4069 { /* need to handle LCL constants */
4070 vi = symtable_varInfo (g_symtab, sym);
4072 if (varInfo_exists (vi) && vi->kind == VRK_CONST)
4075 n->kind = TRM_CONST;
4078 (void) sortSet_insert (n->possibleSorts, theSort);
4081 { /* and LSL operators (true, false, new, nil, etc) */
4082 nameNode nn = makeNameNodeId (ltoken_copy (varid));
4083 oi = symtable_opInfo (g_symtab, nn);
4085 if (opInfo_exists (oi) && (oi->name->isOpId) &&
4086 !sigNodeSet_isEmpty (oi->signatures))
4088 sigNodeSet_elements (oi->signatures, x)
4090 if (ltokenList_empty (x->domain))
4091 /* yes, it really is empty, not not empty */
4093 lslOp op = (lslOp) dmalloc (sizeof (*op));
4095 op->name = nameNode_copy (nn);
4097 (void) sortSet_insert (n->possibleSorts, sigNode_rangeSort (x));
4098 (void) lslOpSet_insert (n->possibleOps, op);
4100 } end_sigNodeSet_elements;
4105 if (sortSet_size (n->possibleSorts) == 0)
4109 message ("Unrecognized identifier (constant, variable or operator): %s",
4110 ltoken_getRawString (varid)));
4114 n->sort = sort_makeNoSort ();
4116 n->kind = TRM_ZEROARY;
4124 makeSelectTermNode (termNode pri, ltoken select, /*@dependent@*/ ltoken id)
4126 termNode t = (termNode) dmalloc (sizeof (*t));
4127 opFormNode opform = makeOpFormNode (select,
4128 OPF_MSELECT, opFormUnion_createAnyOp (id),
4130 nameNode nn = makeNameNodeForm (opform);
4131 termNodeList args = termNodeList_new ();
4133 t->error_reported = FALSE;
4136 t->kind = TRM_APPLICATION;
4137 termNodeList_addh (args, pri);
4139 t->kind = TRM_APPLICATION;
4140 t->sort = sort_makeNoSort ();
4142 t->possibleSorts = sortSet_new ();
4143 t->possibleOps = lslOpSet_new ();
4149 makeMapTermNode (termNode pri, ltoken map, /*@dependent@*/ ltoken id)
4151 termNode t = (termNode) dmalloc (sizeof (*t));
4152 opFormNode opform = makeOpFormNode (map, OPF_MMAP, opFormUnion_createAnyOp (id),
4154 nameNode nn = makeNameNodeForm (opform);
4155 termNodeList args = termNodeList_new ();
4157 t->error_reported = FALSE;
4159 t->kind = TRM_APPLICATION;
4161 termNodeList_addh (args, pri);
4163 t->kind = TRM_APPLICATION;
4164 t->sort = sort_makeNoSort ();
4166 t->possibleSorts = sortSet_new ();
4167 t->possibleOps = lslOpSet_new ();
4172 makeLiteralTermNode (ltoken tok, sort s)
4174 nameNode nn = makeNameNodeId (ltoken_copy (tok));
4175 opInfo oi = symtable_opInfo (g_symtab, nn);
4176 lslOp op = (lslOp) dmalloc (sizeof (*op));
4177 termNode n = (termNode) dmalloc (sizeof (*n));
4182 n->error_reported = FALSE;
4184 n->kind = TRM_LITERAL;
4186 n->given = sort_makeNoSort ();
4188 n->args = termNodeList_new ();
4189 n->possibleSorts = sortSet_new ();
4190 n->possibleOps = lslOpSet_new ();
4192 /* look up signatures for this operator too */
4194 range = ltoken_create (simpleId, sort_getLsymbol (s));
4195 sign = makesigNode (ltoken_undefined, ltokenList_new (),
4196 ltoken_copy (range));
4198 if (opInfo_exists (oi) && (oi->name->isOpId)
4199 && (sigNodeSet_size (oi->signatures) > 0))
4201 sigNodeSet_elements (oi->signatures, x)
4203 if (ltokenList_empty (x->domain))
4205 lslOp opn = (lslOp) dmalloc (sizeof (*opn));
4208 opn->name = nameNode_copy (nn);
4210 sort = sigNode_rangeSort (x);
4211 (void) sortSet_insert (n->possibleSorts, sort);
4212 (void) lslOpSet_insert (n->possibleOps, opn);
4214 } end_sigNodeSet_elements;
4217 /* insert into literal term */
4218 (void) sortSet_insert (n->possibleSorts, s);
4220 op->name = nameNode_copy (nn);
4221 op->signature = sign;
4222 (void) lslOpSet_insert (n->possibleOps, op);
4224 /* enter the literal as an operator into the operator table */
4225 /* 8/9/93. C's char constant 'c' syntax conflicts
4226 with LSL's lslinit.lsi table. Throw out, because it's not
4228 /* symtable_enterOp (g_symtab, nn, sign); */
4233 lslOp opn = (lslOp) dmalloc (sizeof (*opn));
4235 /* if it is a C int, we should overload it as double too because
4236 C allows you to say "x > 2". */
4238 (void) sortSet_insert (n->possibleSorts, g_sortDouble);
4240 ltoken_setText (range, lsymbol_fromChars ("double"));
4241 osign = makesigNode (ltoken_undefined, ltokenList_new (), range);
4242 opn->name = nameNode_copy (nn);
4243 opn->signature = osign;
4244 (void) lslOpSet_insert (n->possibleOps, opn);
4246 symtable_enterOp (g_symtab, nameNode_copySafe (nn), sigNode_copy (osign));
4250 ltoken_free (range);
4253 /* future: could overload cstrings to be both char_Vec as well as
4261 makeUnchangedTermNode1 (ltoken op, /*@unused@*/ ltoken all)
4263 termNode t = (termNode) dmalloc (sizeof (*t));
4265 t->error_reported = FALSE;
4267 t->kind = TRM_UNCHANGEDALL;
4268 t->sort = g_sortBool;
4270 t->given = sort_makeNoSort ();
4271 t->name = NULL; /*< missing this >*/
4272 t->args = termNodeList_new ();
4273 t->possibleSorts = sortSet_new ();
4274 t->possibleOps = lslOpSet_new ();
4275 (void) sortSet_insert (t->possibleSorts, t->sort);
4283 makeUnchangedTermNode2 (ltoken op, storeRefNodeList x)
4285 termNode t = (termNode) dmalloc (sizeof (*t));
4289 t->name = NULL; /*< missing this >*/
4290 t->error_reported = FALSE;
4292 t->kind = TRM_UNCHANGEDOTHERS;
4293 t->sort = g_sortBool;
4296 t->given = sort_makeNoSort ();
4297 t->possibleSorts = sortSet_new ();
4298 t->possibleOps = lslOpSet_new ();
4299 t->args = termNodeList_new ();
4301 (void) sortSet_insert (t->possibleSorts, t->sort);
4302 /* check storeRefNode's are mutable, uses sort of term */
4304 storeRefNodeList_elements (x, sto)
4306 if (storeRefNode_isTerm (sto))
4308 sort = sto->content.term->sort;
4309 if (!sort_mutable (sort))
4311 errtok = termNode_errorToken (sto->content.term);
4313 message ("Term denoting immutable object used in unchanged list: %q",
4314 termNode_unparse (sto->content.term)));
4319 if (storeRefNode_isType (sto))
4321 lclTypeSpecNode type = sto->content.type;
4322 sort = lclTypeSpecNode2sort (type);
4323 if (!sort_mutable (sort))
4325 errtok = lclTypeSpecNode_errorToken (type);
4326 lclerror (errtok, message ("Immutable type used in unchanged list: %q",
4327 sort_unparse (sort)));
4331 } end_storeRefNodeList_elements;
4337 makeSizeofTermNode (ltoken op, lclTypeSpecNode type)
4339 termNode t = (termNode) dmalloc (sizeof (*t));
4341 t->name = NULL; /*< missing this >*/
4342 t->error_reported = FALSE;
4344 t->kind = TRM_SIZEOF;
4345 t->sort = g_sortInt;
4347 t->sizeofField = type;
4348 t->given = sort_makeNoSort ();
4349 t->possibleSorts = sortSet_new ();
4350 t->possibleOps = lslOpSet_new ();
4351 t->args = termNodeList_new ();
4353 (void) sortSet_insert (t->possibleSorts, t->sort);
4354 /* nothing to check */
4359 claimNode_unparse (claimNode c)
4361 if (c != (claimNode) 0)
4363 cstring s = message ("claims (%q)%q{\n%q",
4364 paramNodeList_unparse (c->params),
4365 varDeclarationNodeList_unparse (c->globals),
4366 lclPredicateNode_unparse (c->require));
4368 if (c->body != NULL)
4370 s = message ("%qbody {%q}\n", s, programNode_unparse (c->body));
4372 s = message ("%q%q}\n", s, lclPredicateNode_unparse (c->ensures));
4375 return cstring_undefined;
4379 WrongArity (ltoken tok, int expect, int size)
4381 lclerror (tok, message ("Expecting %d arguments but given %d", expect, size));
4385 printTermNode2 (/*@null@*/ opFormNode op, termNodeList args, sort sort)
4387 if (op != (opFormNode) 0)
4389 cstring s = cstring_undefined;
4393 if (sort != sort_makeNoSort ())
4395 sortText = message (": %s", cstring_fromChars (lsymbol_toChars (sort_getLsymbol (sort))));
4396 sortSpace = cstring_makeLiteral (" ");
4400 sortText = cstring_undefined;
4401 sortSpace = cstring_undefined;
4408 int size = termNodeList_size (args);
4412 s = message ("if %q then %q else %q\n",
4413 termNode_unparse (termNodeList_getN (args, 0)),
4414 termNode_unparse (termNodeList_getN (args, 1)),
4415 termNode_unparse (termNodeList_getN (args, 2)));
4419 WrongArity (op->tok, 3, size);
4420 s = cstring_makeLiteral ("if __ then __ else __");
4422 s = message ("%q%s", s, sortText);
4427 s = message ("%s %s",
4428 ltoken_getRawString (op->content.anyop),
4434 int size = termNodeList_size (args);
4438 s = message ("%q ", termNode_unparse (termNodeList_head (args)));
4442 WrongArity (op->content.anyop, 1, size);
4443 s = cstring_makeLiteral ("__ ");
4445 s = message ("%q%s%s", s, ltoken_getRawString (op->content.anyop),
4451 int size = termNodeList_size (args);
4453 s = message ("%s ", ltoken_getRawString (op->content.anyop));
4457 s = message ("%q%q", s, termNode_unparse (termNodeList_head (args)));
4461 WrongArity (op->content.anyop, 1, size);
4462 s = message ("%q__", s);
4464 s = message ("%q%s", s, sortText);
4469 int size = termNodeList_size (args);
4473 s = message ("%q %s %q",
4474 termNode_unparse (termNodeList_getN (args, 0)),
4475 ltoken_getRawString (op->content.anyop),
4476 termNode_unparse (termNodeList_getN (args, 1)));
4480 WrongArity (op->content.anyop, 2, size);
4481 s = message ("__ %s __", ltoken_getRawString (op->content.anyop));
4483 s = message ("%q%s", s, sortText);
4488 int size = termNodeList_size (args);
4489 int expect = op->content.middle;
4491 /* ymtan ? use { or openSym token ? */
4495 s = message ("{%q}", termNodeList_unparse (args));
4499 WrongArity (op->tok, expect, size);
4500 s = cstring_makeLiteral ("{ * }");
4503 s = message ("%q%s", s, sortText);
4508 int size = termNodeList_size (args);
4509 int expect = op->content.middle + 1;
4513 s = message ("%q{%q}",
4514 termNode_unparse (termNodeList_head (args)),
4515 termNodeList_unparseTail (args));
4519 WrongArity (op->tok, expect, size);
4520 s = cstring_makeLiteral ("__ { * }");
4523 s = message ("%q%s", s, sortText);
4528 int size = termNodeList_size (args);
4529 int expect = op->content.middle + 1;
4533 termNodeList_finish (args);
4535 s = message ("{%q}%s%s%q",
4536 termNodeList_unparseToCurrent (args),
4537 sortText, sortSpace,
4538 termNode_unparse (termNodeList_current (args)));
4542 WrongArity (op->tok, expect, size);
4544 s = message ("{ * }%s __", sortText);
4546 /* used to put in extra space! evs 94-01-05 */
4552 int size = termNodeList_size (args);
4553 int expect = op->content.middle + 2;
4557 termNodeList_finish (args);
4559 s = message ("%q {%q} %s%s%q",
4560 termNode_unparse (termNodeList_head (args)),
4561 termNodeList_unparseSecondToCurrent (args),
4562 sortText, sortSpace,
4563 termNode_unparse (termNodeList_current (args)));
4567 WrongArity (op->tok, expect, size);
4568 s = message ("__ { * } %s __", sortText);
4570 /* also had extra space? */
4576 int size = termNodeList_size (args);
4577 int expect = op->content.middle;
4581 s = message ("[%q]", termNodeList_unparse (args));
4585 WrongArity (op->tok, expect, size);
4586 s = cstring_makeLiteral ("[ * ]");
4588 s = message ("%q%s", s, sortText);
4593 int size = termNodeList_size (args);
4594 int expect = op->content.middle + 1;
4598 s = message ("%q[%q]",
4599 termNode_unparse (termNodeList_head (args)),
4600 termNodeList_unparseTail (args));
4604 WrongArity (op->tok, expect, size);
4605 s = cstring_makeLiteral ("__ [ * ]");
4608 s = message ("%q%s", s, sortText);
4613 int size = termNodeList_size (args);
4614 int expect = op->content.middle + 1;
4618 s = message ("%q[%q] __",
4619 termNode_unparse (termNodeList_head (args)),
4620 termNodeList_unparseTail (args));
4624 WrongArity (op->tok, expect, size);
4625 s = cstring_makeLiteral ("__ [ * ] __");
4627 s = message ("%q%s", s, sortText);
4632 int size = termNodeList_size (args);
4633 int expect = op->content.middle + 1;
4637 termNodeList_finish (args);
4639 s = message ("[%q]%s%s%q",
4640 termNodeList_unparseToCurrent (args),
4641 sortText, sortSpace,
4642 termNode_unparse (termNodeList_current (args)));
4646 WrongArity (op->tok, expect, size);
4647 s = cstring_makeLiteral ("[ * ] __");
4653 { /* ymtan constant, check args ? */
4654 s = cstring_prependChar ('.', ltoken_getRawString (op->content.id));
4658 s = cstring_concat (cstring_makeLiteralTemp ("->"),
4659 ltoken_getRawString (op->content.id));
4663 int size = termNodeList_size (args);
4667 s = message ("%q.%s", termNode_unparse (termNodeList_head (args)),
4668 ltoken_getRawString (op->content.id));
4672 WrongArity (op->content.id, 1, size);
4673 s = cstring_concat (cstring_makeLiteralTemp ("__."),
4674 ltoken_getRawString (op->content.id));
4680 int size = termNodeList_size (args);
4684 s = message ("%q->%s", termNode_unparse (termNodeList_head (args)),
4685 ltoken_getRawString (op->content.id));
4689 WrongArity (op->content.id, 1, size);
4690 s = cstring_concat (cstring_makeLiteralTemp ("__->"),
4691 ltoken_getRawString (op->content.id));
4697 cstring_free (sortSpace);
4698 cstring_free (sortText);
4701 return cstring_undefined;
4705 termNode_unparse (/*@null@*/ termNode n)
4707 cstring s = cstring_undefined;
4708 cstring back = cstring_undefined;
4709 cstring front = cstring_undefined;
4712 if (n != (termNode) 0)
4714 for (count = n->wrapped; count > 0; count--)
4716 front = cstring_appendChar (front, '(');
4717 back = cstring_appendChar (back, ')');
4726 s = cstring_copy (ltoken_getRawString (n->literal));
4728 case TRM_APPLICATION:
4730 nameNode nn = n->name;
4731 if (nn != (nameNode) 0)
4735 s = message ("%s (%q) ",
4736 ltoken_getRawString (nn->content.opid),
4737 termNodeList_unparse (n->args));
4738 /* must we handle n->given ? skip for now */
4742 s = message ("%q ", printTermNode2 (nn->content.opform, n->args, n->given));
4748 (message ("termNode_unparse: expect non-empty nameNode: TRM_APPLICATION: %q",
4749 nameNode_unparse (nn)));
4753 case TRM_UNCHANGEDALL:
4754 s = cstring_makeLiteral ("unchanged (all)");
4756 case TRM_UNCHANGEDOTHERS:
4757 s = message ("unchanged (%q)", storeRefNodeList_unparse (n->unchanged));
4760 s = message ("sizeof (%q)", lclTypeSpecNode_unparse (n->sizeofField));
4762 case TRM_QUANTIFIER:
4764 quantifiedTermNode x = n->quantified;
4765 s = message ("%q%s%q%s",
4766 quantifierNodeList_unparse (x->quantifiers),
4767 ltoken_getRawString (x->open),
4768 termNode_unparse (x->body),
4769 ltoken_getRawString (x->close));
4774 return (message ("%q%q%q", front, s, back));
4777 static void modifyNode_free (/*@null@*/ /*@only@*/ modifyNode m)
4779 if (m != (modifyNode) 0)
4782 if (m->hasStoreRefList)
4784 storeRefNodeList_free (m->list);
4789 ltoken_free (m->tok);
4795 modifyNode_unparse (/*@null@*/ modifyNode m)
4797 if (m != (modifyNode) 0)
4799 if (m->hasStoreRefList)
4801 return (message (" modifies %q; \n", storeRefNodeList_unparse (m->list)));
4805 if (m->modifiesNothing)
4807 return (cstring_makeLiteral ("modifies nothing; \n"));
4811 return (cstring_makeLiteral ("modifies anything; \n"));
4815 return cstring_undefined;
4819 programNode_unparse (programNode p)
4821 if (p != (programNode) 0)
4823 cstring s = cstring_undefined;
4830 cstring back = cstring_undefined;
4832 for (count = p->wrapped; count > 0; count--)
4834 s = cstring_appendChar (s, '(');
4835 back = cstring_appendChar (back, ')');
4837 s = message ("%q%q%q", s, stmtNode_unparse (p->content.self), back);
4841 s = message ("*(%q)", programNodeList_unparse (p->content.args));
4844 s = message ("|(%q)", programNodeList_unparse (p->content.args));
4847 s = programNodeList_unparse (p->content.args);
4853 return cstring_undefined;
4857 stmtNode_unparse (stmtNode x)
4859 cstring s = cstring_undefined;
4861 if (x != (stmtNode) 0)
4863 if (ltoken_isValid (x->lhs))
4865 s = cstring_concat (ltoken_getRawString (x->lhs),
4866 cstring_makeLiteralTemp (" = "));
4869 s = message ("%q%s (%q)", s,
4870 ltoken_getRawString (x->operator),
4871 termNodeList_unparse (x->args));
4878 makelslOpNode (/*@only@*/ /*@null@*/ nameNode name,
4879 /*@dependent@*/ sigNode s)
4881 lslOp x = (lslOp) dmalloc (sizeof (*x));
4886 /* enter operator info into symtab */
4887 /* if not, they may need to be renamed in LCL imports */
4889 if (g_lslParsingTraits)
4893 symtable_enterOp (g_symtab, nameNode_copySafe (name), sigNode_copy (s));
4898 /* nameNode_free (name); */ /* YIKES! */
4905 lslOp_unparse (lslOp x)
4907 char *s = mstring_createEmpty ();
4911 s = mstring_concatFree (s, cstring_toCharsSafe (nameNode_unparse (x->name)));
4913 if (x->signature != (sigNode) 0)
4915 s = mstring_concatFree (s, cstring_toCharsSafe (sigNode_unparse (x->signature)));
4919 return cstring_fromCharsO (s);
4923 sameOpFormNode (/*@null@*/ opFormNode n1, /*@null@*/ opFormNode n2)
4934 if (n1->kind == n2->kind)
4943 return (ltoken_similar (n1->content.anyop, n2->content.anyop));
4946 /* want to treat eq and = the same */
4947 return ltoken_similar (n1->content.anyop, n2->content.anyop);
4953 /* need to check the rawText of openSym and closeSym */
4954 if ((int) n1->content.middle == (int) n2->content.middle)
4956 if (lsymbol_equal (ltoken_getRawText (n1->tok),
4957 ltoken_getRawText (n2->tok)) &&
4958 lsymbol_equal (ltoken_getRawText (n1->close),
4959 ltoken_getRawText (n2->close)))
4967 return ((int) n1->content.middle == (int) n2->content.middle);
4972 return (ltoken_similar (n1->content.id, n2->content.id));
4979 sameNameNode (/*@null@*/ nameNode n1, /*@null@*/ nameNode n2)
4983 if (n1 != (nameNode) 0 && n2 != (nameNode) 0)
4985 if (bool_equal (n1->isOpId, n2->isOpId))
4988 return (ltoken_similar (n1->content.opid, n2->content.opid));
4990 return sameOpFormNode (n1->content.opform,
4991 n2->content.opform);
4997 void CTypesNode_free (/*@only@*/ /*@null@*/ CTypesNode x)
5001 ltokenList_free (x->ctypes);
5006 /*@null@*/ CTypesNode CTypesNode_copy (/*@null@*/ CTypesNode x)
5010 CTypesNode newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5011 newnode->intfield = x->intfield;
5012 newnode->ctypes = ltokenList_copy (x->ctypes);
5013 newnode->sort = x->sort;
5023 /*@only@*/ CTypesNode
5024 makeCTypesNode (/*@only@*/ CTypesNode ctypes, ltoken ct)
5026 /*@only@*/ CTypesNode newnode;
5030 if (ctypes == (CTypesNode) NULL)
5032 newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5033 newnode->intfield = 0;
5034 newnode->ctypes = ltokenList_new ();
5035 newnode->sort = sort_makeNoSort ();
5042 if ((ltoken_getIntField (ct) & newnode->intfield) != 0)
5046 ("Duplicate type specifier ignored: %s",
5049 (lclctype_toSortDebug (ltoken_getIntField (ct))))));
5051 /* evs --- don't know how to generator this error */
5053 /* Use previous value, to keep things consistent */
5058 sortbits = newnode->intfield | ltoken_getIntField (ct);
5059 sortname = lclctype_toSort (sortbits);
5061 if (sortname == lsymbol_fromChars ("error"))
5063 lclerror (ct, cstring_makeLiteral ("Invalid combination of type specifiers"));
5067 newnode->intfield = sortbits;
5070 ltokenList_addh (newnode->ctypes, ct);
5073 ** Sorts are assigned after CTypesNode is created during parsing,
5074 ** see bison grammar.
5080 /*@only@*/ CTypesNode
5081 makeTypeSpecifier (ltoken typedefname)
5083 CTypesNode newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5084 typeInfo ti = symtable_typeInfo (g_symtab, ltoken_getText (typedefname));
5086 newnode->intfield = 0;
5087 newnode->ctypes = ltokenList_singleton (ltoken_copy (typedefname));
5089 /* if we see "bool" include bool.h header file */
5091 if (ltoken_getText (typedefname) == lsymbol_bool)
5096 if (typeInfo_exists (ti))
5098 /* must we be concern about whether this type is exported by module?
5099 No. Because all typedef's are exported. No hiding supported. */
5100 /* Later, may want to keep types around too */
5101 /* 3/2/93, use underlying sort */
5102 newnode->sort = sort_getUnderlying (ti->basedOn);
5106 lclerror (typedefname, message ("Unrecognized type: %s",
5107 ltoken_getRawString (typedefname)));
5108 /* evs --- Don't know how to get this message */
5110 newnode->sort = sort_makeNoSort ();
5113 ltoken_free (typedefname);
5117 bool sigNode_equal (sigNode n1, sigNode n2)
5119 /* n1 and n2 are never 0 */
5121 return ((n1 == n2) ||
5122 (n1->key == n2->key &&
5123 ltoken_similar (n1->range, n2->range) &&
5124 ltokenList_equal (n1->domain, n2->domain)));
5128 typeExpr2ptrSort (sort base, /*@null@*/ typeExpr t)
5130 if (t != (typeExpr) 0)
5137 return typeExpr2ptrSort (sort_makePtr (ltoken_undefined, base),
5138 t->content.pointer);
5140 return typeExpr2ptrSort (sort_makeArr (ltoken_undefined, base),
5141 t->content.array.elementtype);
5143 /* map all hof types to some sort of SRT_HOF */
5144 return sort_makeHOFSort (base);
5151 typeExpr2returnSort (sort base, /*@null@*/ typeExpr t)
5153 if (t != (typeExpr) 0)
5160 return typeExpr2returnSort (sort_makePtr (ltoken_undefined, base),
5161 t->content.pointer);
5163 return typeExpr2returnSort (sort_makeArr (ltoken_undefined, base),
5164 t->content.array.elementtype);
5166 return typeExpr2returnSort (base, t->content.function.returntype);
5173 lclTypeSpecNode2sort (lclTypeSpecNode type)
5175 if (type != (lclTypeSpecNode) 0)
5180 llassert (type->content.type != NULL);
5181 return sort_makePtrN (type->content.type->sort, type->pointers);
5182 case LTS_STRUCTUNION:
5183 llassert (type->content.structorunion != NULL);
5184 return sort_makePtrN (type->content.structorunion->sort, type->pointers);
5186 llassert (type->content.enumspec != NULL);
5187 return sort_makePtrN (type->content.enumspec->sort, type->pointers);
5189 return (lclTypeSpecNode2sort (type->content.conj->a));
5192 return (sort_makeNoSort ());
5196 checkAndEnterTag (tagKind k, ltoken opttagid)
5198 /* should be tagKind, instead of int */
5200 sort sort = sort_makeNoSort ();
5202 if (!ltoken_isUndefined (opttagid))
5208 sort = sort_makeStr (opttagid);
5212 sort = sort_makeUnion (opttagid);
5215 sort = sort_makeEnum (opttagid);
5219 /* see if it is already in symbol table */
5220 t = symtable_tagInfo (g_symtab, ltoken_getText (opttagid));
5222 if (tagInfo_exists (t))
5224 if (t->kind == TAG_FWDUNION || t->kind == TAG_FWDSTRUCT)
5226 /* this is fine, for mutually recursive types */
5229 { /* this is not good, complain later */
5235 s = cstring_makeLiteral ("Enum");
5239 s = cstring_makeLiteral ("Struct");
5243 s = cstring_makeLiteral ("Union");
5250 message ("Tag redefined: %q %s", s,
5251 ltoken_getRawString (opttagid)));
5255 ltoken_free (opttagid);
5259 tagInfo newnode = (tagInfo) dmalloc (sizeof (*newnode));
5261 newnode->sort = sort;
5263 newnode->id = opttagid;
5264 newnode->imported = FALSE;
5265 newnode->content.decls = stDeclNodeList_new ();
5267 (void) symtable_enterTag (g_symtab, newnode);
5271 return sort_getLsymbol (sort);
5275 extractReturnSort (lclTypeSpecNode t, declaratorNode d)
5278 sort = lclTypeSpecNode2sort (t);
5279 sort = typeExpr2returnSort (sort, d->type);
5284 signNode_free (/*@only@*/ signNode sn)
5286 sortList_free (sn->domain);
5287 ltoken_free (sn->tok);
5292 signNode_unparse (signNode sn)
5294 cstring s = cstring_undefined;
5296 if (sn != (signNode) 0)
5298 s = message (": %q -> %s", sortList_unparse (sn->domain),
5299 sort_unparseName (sn->range));
5304 static /*@only@*/ pairNodeList
5305 globalList_toPairNodeList (globalList g)
5307 /* expect list to be globals, drop private ones */
5308 pairNodeList result = pairNodeList_new ();
5310 declaratorNode vdnode;
5311 lclTypeSpecNode type;
5314 initDeclNodeList decls;
5316 varDeclarationNodeList_elements (g, x)
5324 if (x->isGlobal && !x->isPrivate)
5329 initDeclNodeList_elements (decls, init)
5331 p = (pairNode) dmalloc (sizeof (*p));
5333 vdnode = init->declarator;
5334 sym = ltoken_getText (vdnode->id);
5335 /* 2/21/93, not sure if it should be extractReturnSort,
5336 or some call to typeExpr2ptrSort */
5337 sort = extractReturnSort (type, vdnode);
5338 p->sort = sort_makeGlobal (sort);
5339 /* if (!sort_isArrayKind (sort)) p->sort = sort_makeObj (sort);
5340 else p->sort = sort; */
5341 /* p->name = sym; */
5342 p->tok = ltoken_copy (vdnode->id);
5343 pairNodeList_addh (result, p);
5344 } end_initDeclNodeList_elements;
5347 } end_varDeclarationNodeList_elements;
5352 enteringFcnScope (lclTypeSpecNode t, declaratorNode d, globalList g)
5354 scopeInfo si = (scopeInfo) dmalloc (sizeof (*si));
5355 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5357 ltoken result = ltoken_copy (ltoken_id);
5358 pairNodeList paramPairs, globals;
5359 fctInfo fi = (fctInfo) dmalloc (sizeof (*fi));
5360 signNode sign = (signNode) dmalloc (sizeof (*sign));
5361 sortList domain = sortList_new ();
5362 unsigned long int key;
5364 paramPairs = extractParams (d->type);
5365 returnSort = extractReturnSort (t, d);
5366 globals = globalList_toPairNodeList (g);
5368 sign->tok = ltoken_undefined;
5369 sign->range = returnSort;
5371 key = MASH (0, sort_getLsymbol (returnSort));
5373 pairNodeList_elements (paramPairs, p)
5375 sortList_addh (domain, p->sort);
5376 key = MASH (key, sort_getLsymbol (p->sort));
5377 } end_pairNodeList_elements;
5379 sign->domain = domain;
5382 /* push fcn onto symbol table stack first */
5383 fi->id = ltoken_copy (d->id);
5385 fi->signature = sign;
5386 fi->globals = globals;
5388 (void) symtable_enterFct (g_symtab, fi);
5390 /* push new fcn scope */
5392 symtable_enterScope (g_symtab, si);
5394 /* add "result" with return type to current scope */
5395 ltoken_setText (result, lsymbol_fromChars ("result"));
5398 vi->sort = sort_makeFormal (returnSort); /* make appropriate values */
5399 vi->kind = VRK_PARAM;
5402 (void) symtable_enterVar (g_symtab, vi);
5406 ** pust globals first (they are in outer scope)
5409 /* push onto symbol table the global variables declared in this function,
5410 together with their respective sorts */
5412 pairNodeList_elements (globals, gl)
5414 ltoken_free (vi->id);
5415 vi->id = ltoken_copy (gl->tok);
5416 vi->kind = VRK_GLOBAL;
5417 vi->sort = gl->sort;
5418 (void) symtable_enterVar (g_symtab, vi);
5419 } end_pairNodeList_elements;
5422 ** could enter a new scope; instead, warn when variable shadows global
5427 ** push onto symbol table the formal parameters of this function,
5428 ** together with their respective sorts
5431 pairNodeList_elements (paramPairs, pair)
5433 ltoken_free (vi->id);
5434 vi->id = ltoken_copy (pair->tok);
5435 vi->sort = pair->sort;
5436 vi->kind = VRK_PARAM;
5437 (void) symtable_enterVar (g_symtab, vi);
5438 } end_pairNodeList_elements;
5440 pairNodeList_free (paramPairs);
5445 enteringClaimScope (paramNodeList params, globalList g)
5447 scopeInfo si = (scopeInfo) dmalloc (sizeof (*si));
5448 pairNodeList globals;
5449 lclTypeSpecNode paramtype;
5453 globals = globalList_toPairNodeList (g);
5454 /* push new claim scope */
5455 si->kind = SPE_CLAIM;
5457 symtable_enterScope (g_symtab, si);
5459 /* push onto symbol table the formal parameters of this function,
5460 together with their respective sorts */
5462 paramNodeList_elements (params, param)
5464 paramdecl = param->paramdecl;
5465 paramtype = param->type;
5466 if (paramdecl != (typeExpr) 0 && paramtype != (lclTypeSpecNode) 0)
5468 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5470 sort = lclTypeSpecNode2sort (paramtype);
5471 sort = sort_makeFormal (sort);
5472 vi->sort = typeExpr2ptrSort (sort, paramdecl);
5473 vi->id = ltoken_copy (extractDeclarator (paramdecl));
5474 vi->kind = VRK_PARAM;
5477 (void) symtable_enterVar (g_symtab, vi);
5480 } end_paramNodeList_elements;
5482 /* push onto symbol table the global variables declared in this function,
5483 together with their respective sorts */
5485 pairNodeList_elements (globals, g2)
5487 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5489 vi->id = ltoken_copy (g2->tok);
5490 vi->kind = VRK_GLOBAL;
5491 vi->sort = g2->sort;
5494 /* should catch duplicates in formals */
5495 (void) symtable_enterVar (g_symtab, vi);
5497 } end_pairNodeList_elements;
5499 pairNodeList_free (globals);
5500 /* should not free it here! ltoken_free (claimId); @*/
5503 static /*@only@*/ pairNodeList
5504 extractParams (/*@null@*/ typeExpr te)
5506 /* extract the parameters from a function header declarator's typeExpr */
5509 paramNodeList params;
5510 lclTypeSpecNode paramtype;
5511 pairNodeList head = pairNodeList_new ();
5514 if (te != (typeExpr) 0)
5516 params = typeExpr_toParamNodeList (te);
5517 if (paramNodeList_isDefined (params))
5519 paramNodeList_elements (params, param)
5521 paramdecl = param->paramdecl;
5522 paramtype = param->type;
5523 if (paramdecl != (typeExpr) 0 && paramtype != (lclTypeSpecNode) 0)
5525 pair = (pairNode) dmalloc (sizeof (*pair));
5526 sort = lclTypeSpecNode2sort (paramtype);
5527 /* 2/17/93, was sort_makeVal (sort) */
5528 sort = sort_makeFormal (sort);
5529 pair->sort = typeExpr2ptrSort (sort, paramdecl);
5530 /* pair->name = ltoken_getText (extractDeclarator (paramdecl)); */
5531 pair->tok = ltoken_copy (extractDeclarator (paramdecl));
5532 pairNodeList_addh (head, pair);
5534 } end_paramNodeList_elements;
5541 sigNode_rangeSort (sigNode sig)
5543 if (sig == (sigNode) 0)
5545 return sort_makeNoSort ();
5549 return sort_fromLsymbol (ltoken_getText (sig->range));
5554 sigNode_domain (sigNode sig)
5556 sortList domain = sortList_new ();
5558 if (sig == (sigNode) 0)
5564 ltokenList dom = sig->domain;
5566 ltokenList_elements (dom, tok)
5568 sortList_addh (domain, sort_fromLsymbol (ltoken_getText (tok)));
5569 } end_ltokenList_elements;
5576 opFormUnion_createAnyOp (/*@temp@*/ ltoken t)
5580 /* do not distinguish between .anyop and .id */
5586 opFormUnion_createMiddle (int middle)
5595 markYieldParamNode (paramNode p)
5599 llassert (p->type != NULL);
5600 p->type->quals = qualList_add (p->type->quals, qual_createYield ());
5605 /*@only@*/ lclTypeSpecNode
5606 lclTypeSpecNode_copySafe (lclTypeSpecNode n)
5608 lclTypeSpecNode ret = lclTypeSpecNode_copy (n);
5610 llassert (ret != NULL);
5614 /*@null@*/ /*@only@*/ lclTypeSpecNode
5615 lclTypeSpecNode_copy (/*@null@*/ lclTypeSpecNode n)
5622 return (makeLclTypeSpecNodeConj (lclTypeSpecNode_copy (n->content.conj->a),
5623 lclTypeSpecNode_copy (n->content.conj->b)));
5625 return (makeLclTypeSpecNodeType (CTypesNode_copy (n->content.type)));
5626 case LTS_STRUCTUNION:
5627 return (makeLclTypeSpecNodeSU (strOrUnionNode_copy (n->content.structorunion)));
5629 return (makeLclTypeSpecNodeEnum (enumSpecNode_copy (n->content.enumspec)));
5636 void lclTypeSpecNode_free (/*@null@*/ /*@only@*/ lclTypeSpecNode n)
5643 lclTypeSpecNode_free (n->content.conj->a);
5644 lclTypeSpecNode_free (n->content.conj->b);
5647 CTypesNode_free (n->content.type);
5649 case LTS_STRUCTUNION:
5650 strOrUnionNode_free (n->content.structorunion);
5653 enumSpecNode_free (n->content.enumspec);
5657 qualList_free (n->quals);
5662 static /*@null@*/ opFormNode opFormNode_copy (/*@null@*/ opFormNode op)
5666 opFormNode ret = (opFormNode) dmalloc (sizeof (*ret));
5668 ret->tok = ltoken_copy (op->tok);
5669 ret->kind = op->kind;
5670 ret->content = op->content;
5672 ret->close = ltoken_copy (op->close);
5682 void opFormNode_free (/*@null@*/ opFormNode op)
5686 ltoken_free (op->tok);
5687 ltoken_free (op->close);
5692 void nameNode_free (nameNode n)
5699 opFormNode_free (n->content.opform);
5707 lslOp_equal (lslOp x, lslOp y)
5710 ((x != 0) && (y != 0) &&
5711 sameNameNode (x->name, y->name) &&
5712 sigNode_equal (x->signature, y->signature)));
5715 void lslOp_free (lslOp x)
5717 nameNode_free (x->name);
5721 void sigNode_free (sigNode x)
5725 ltokenList_free (x->domain);
5726 ltoken_free (x->tok);
5727 ltoken_free (x->range);
5732 void declaratorNode_free (/*@null@*/ /*@only@*/ declaratorNode x)
5736 typeExpr_free (x->type);
5737 ltoken_free (x->id);
5742 void abstBodyNode_free (/*@null@*/ /*@only@*/ abstBodyNode n)
5746 lclPredicateNode_free (n->typeinv);
5747 fcnNodeList_free (n->fcns);
5748 ltoken_free (n->tok);
5753 void fcnNode_free (/*@null@*/ /*@only@*/ fcnNode f)
5757 lclTypeSpecNode_free (f->typespec);
5758 declaratorNode_free (f->declarator);
5759 globalList_free (f->globals);
5760 varDeclarationNodeList_free (f->inits);
5761 letDeclNodeList_free (f->lets);
5762 lclPredicateNode_free (f->checks);
5763 lclPredicateNode_free (f->require);
5764 lclPredicateNode_free (f->claim);
5765 lclPredicateNode_free (f->ensures);
5766 modifyNode_free (f->modify);
5767 ltoken_free (f->name);
5772 void declaratorInvNode_free (/*@null@*/ /*@only@*/ declaratorInvNode x)
5776 declaratorNode_free (x->declarator);
5777 abstBodyNode_free (x->body);
5782 /*@only@*/ lslOp lslOp_copy (lslOp x)
5784 return (makelslOpNode (nameNode_copy (x->name), x->signature));
5787 sigNode sigNode_copy (sigNode s)
5789 llassert (s != NULL);
5790 return (makesigNode (ltoken_copy (s->tok),
5791 ltokenList_copy (s->domain),
5792 ltoken_copy (s->range)));
5795 /*@null@*/ nameNode nameNode_copy (/*@null@*/ nameNode n)
5797 if (n == NULL) return NULL;
5798 return nameNode_copySafe (n);
5801 nameNode nameNode_copySafe (nameNode n)
5805 return (makeNameNodeId (ltoken_copy (n->content.opid)));
5809 /* error should be detected by splint: forgot to copy opform! */
5810 return (makeNameNodeForm (opFormNode_copy (n->content.opform)));
5814 bool initDeclNode_isRedeclaration (initDeclNode d)
5816 return (d->declarator->isRedecl);
5819 void termNode_free (/*@only@*/ /*@null@*/ termNode t)
5823 sortSet_free (t->possibleSorts);
5824 lslOpSet_free (t->possibleOps);
5825 nameNode_free (t->name);
5826 termNodeList_free (t->args);
5831 /*@only@*/ termNode termNode_copySafe (termNode t)
5833 termNode ret = termNode_copy (t);
5835 llassert (ret != NULL);
5839 /*@null@*/ /*@only@*/ termNode termNode_copy (/*@null@*/ termNode t)
5843 termNode ret = (termNode) dmalloc (sizeof (*ret));
5845 ret->wrapped = t->wrapped;
5846 ret->kind = t->kind;
5847 ret->sort = t->sort;
5848 ret->given = t->given;
5849 ret->possibleSorts = sortSet_copy (t->possibleSorts);
5850 ret->error_reported = t->error_reported;
5851 ret->possibleOps = lslOpSet_copy (t->possibleOps);
5852 ret->name = nameNode_copy (t->name);
5853 ret->args = termNodeList_copy (t->args);
5855 if (t->kind == TRM_LITERAL
5856 || t->kind == TRM_SIZEOF
5857 || t->kind == TRM_VAR
5858 || t->kind == TRM_CONST
5859 || t->kind == TRM_ZEROARY)
5861 ret->literal = ltoken_copy (t->literal);
5864 if (t->kind == TRM_UNCHANGEDOTHERS)
5866 ret->unchanged = storeRefNodeList_copy (t->unchanged);
5869 if (t->kind == TRM_QUANTIFIER)
5871 ret->quantified = quantifiedTermNode_copy (t->quantified);
5874 if (t->kind == TRM_SIZEOF)
5876 ret->sizeofField = lclTypeSpecNode_copySafe (t->sizeofField);
5888 void importNode_free (/*@only@*/ /*@null@*/ importNode x)
5892 ltoken_free (x->val);
5897 void initDeclNode_free (/*@only@*/ /*@null@*/ initDeclNode x)
5901 declaratorNode_free (x->declarator);
5902 termNode_free (x->value);
5907 void letDeclNode_free (/*@only@*/ /*@null@*/ letDeclNode x)
5911 lclTypeSpecNode_free (x->sortspec);
5912 termNode_free (x->term);
5913 ltoken_free (x->varid);
5918 void pairNode_free (/*@only@*/ /*@null@*/ pairNode x)
5922 ltoken_free (x->tok);
5927 /*@null@*/ paramNode paramNode_copy (/*@null@*/ paramNode p)
5931 paramNode ret = (paramNode) dmalloc (sizeof (*ret));
5933 ret->type = lclTypeSpecNode_copy (p->type);
5934 ret->paramdecl = typeExpr_copy (p->paramdecl);
5935 ret->kind = p->kind;
5942 void paramNode_free (/*@only@*/ /*@null@*/ paramNode x)
5946 lclTypeSpecNode_free (x->type);
5947 typeExpr_free (x->paramdecl);
5952 void programNode_free (/*@only@*/ /*@null@*/ programNode x)
5958 case ACT_SELF: stmtNode_free (x->content.self); break;
5961 case ACT_SEQUENCE: programNodeList_free (x->content.args); break;
5968 quantifierNode quantifierNode_copy (quantifierNode x)
5970 quantifierNode ret = (quantifierNode) dmalloc (sizeof (*ret));
5972 ret->quant = ltoken_copy (x->quant);
5973 ret->vars = varNodeList_copy (x->vars);
5974 ret->isForall = x->isForall;
5979 void quantifierNode_free (/*@null@*/ /*@only@*/ quantifierNode x)
5983 varNodeList_free (x->vars);
5984 ltoken_free (x->quant);
5989 void replaceNode_free (/*@only@*/ /*@null@*/ replaceNode x)
5999 nameNode_free (x->content.renamesortname.name);
6000 sigNode_free (x->content.renamesortname.signature);
6003 typeNameNode_free (x->typename);
6004 ltoken_free (x->tok);
6009 storeRefNode storeRefNode_copy (storeRefNode x)
6011 storeRefNode ret = (storeRefNode) dmalloc (sizeof (*ret));
6013 ret->kind = x->kind;
6018 ret->content.term = termNode_copySafe (x->content.term);
6020 case SRN_OBJ: case SRN_TYPE:
6021 ret->content.type = lclTypeSpecNode_copy (x->content.type);
6024 ret->content.ref = sRef_copy (x->content.ref);
6031 void storeRefNode_free (/*@only@*/ /*@null@*/ storeRefNode x)
6035 if (storeRefNode_isTerm (x))
6037 termNode_free (x->content.term);
6039 else if (storeRefNode_isType (x) || storeRefNode_isObj (x))
6041 lclTypeSpecNode_free (x->content.type);
6045 /* nothing to free */
6052 stDeclNode stDeclNode_copy (stDeclNode x)
6054 stDeclNode ret = (stDeclNode) dmalloc (sizeof (*ret));
6056 ret->lcltypespec = lclTypeSpecNode_copySafe (x->lcltypespec);
6057 ret->declarators = declaratorNodeList_copy (x->declarators);
6062 void stDeclNode_free (/*@only@*/ /*@null@*/ stDeclNode x)
6066 lclTypeSpecNode_free (x->lcltypespec);
6067 declaratorNodeList_free (x->declarators);
6072 void traitRefNode_free (/*@only@*/ /*@null@*/ traitRefNode x)
6076 ltokenList_free (x->traitid);
6077 renamingNode_free (x->rename);
6082 void typeNameNode_free (/*@only@*/ /*@null@*/ typeNameNode n)
6086 typeNamePack_free (n->typename);
6087 opFormNode_free (n->opform);
6092 void varDeclarationNode_free (/*@only@*/ /*@null@*/ varDeclarationNode x)
6102 lclTypeSpecNode_free (x->type);
6103 initDeclNodeList_free (x->decls);
6109 varNode varNode_copy (varNode x)
6111 varNode ret = (varNode) dmalloc (sizeof (*ret));
6113 ret->varid = ltoken_copy (x->varid);
6114 ret->isObj = x->isObj;
6115 ret->type = lclTypeSpecNode_copySafe (x->type);
6116 ret->sort = x->sort;
6121 void varNode_free (/*@only@*/ /*@null@*/ varNode x)
6125 lclTypeSpecNode_free (x->type);
6126 ltoken_free (x->varid);
6131 void stmtNode_free (/*@only@*/ /*@null@*/ stmtNode x)
6135 ltoken_free (x->lhs);
6136 termNodeList_free (x->args);
6137 ltoken_free (x->operator);
6142 void renamingNode_free (/*@only@*/ /*@null@*/ renamingNode x)
6148 replaceNodeList_free (x->content.replace);
6152 nameAndReplaceNode_free (x->content.name);
6159 void nameAndReplaceNode_free (/*@only@*/ /*@null@*/ nameAndReplaceNode x)
6163 typeNameNodeList_free (x->namelist);
6164 replaceNodeList_free (x->replacelist);
6169 void typeNamePack_free (/*@only@*/ /*@null@*/ typeNamePack x)
6173 lclTypeSpecNode_free (x->type);
6174 abstDeclaratorNode_free (x->abst);
6179 cstring interfaceNode_unparse (interfaceNode x)
6186 return (message ("[imports] %q", importNodeList_unparse (x->content.imports)));
6188 return (message ("[uses] %q", traitRefNodeList_unparse (x->content.uses)));
6190 return (message ("[export] %q", exportNode_unparse (x->content.export)));
6192 return (message ("[private] %q", privateNode_unparse (x->content.private)));
6199 return (cstring_makeLiteral ("<interface node undefined>"));
6202 BADBRANCHRET (cstring_undefined);
6205 void interfaceNode_free (/*@null@*/ /*@only@*/ interfaceNode x)
6212 case INF_IMPORTS: importNodeList_free (x->content.imports); break;
6213 case INF_USES: traitRefNodeList_free (x->content.uses); break;
6214 case INF_EXPORT: exportNode_free (x->content.export); break;
6215 case INF_PRIVATE: privateNode_free (x->content.private); break;
6221 void exportNode_free (/*@null@*/ /*@only@*/ exportNode x)
6227 case XPK_CONST: constDeclarationNode_free (x->content.constdeclaration); break;
6228 case XPK_VAR: varDeclarationNode_free (x->content.vardeclaration); break;
6229 case XPK_TYPE: typeNode_free (x->content.type); break;
6230 case XPK_FCN: fcnNode_free (x->content.fcn); break;
6231 case XPK_CLAIM: claimNode_free (x->content.claim); break;
6232 case XPK_ITER: iterNode_free (x->content.iter); break;
6239 void privateNode_free (/*@null@*/ /*@only@*/ privateNode x)
6246 constDeclarationNode_free (x->content.constdeclaration); break;
6248 varDeclarationNode_free (x->content.vardeclaration); break;
6250 typeNode_free (x->content.type); break;
6252 fcnNode_free (x->content.fcn); break;
6259 void constDeclarationNode_free (/*@only@*/ /*@null@*/ constDeclarationNode x)
6263 lclTypeSpecNode_free (x->type);
6264 initDeclNodeList_free (x->decls);
6269 void typeNode_free (/*@only@*/ /*@null@*/ typeNode t)
6275 case TK_ABSTRACT: abstractNode_free (t->content.abstract); break;
6276 case TK_EXPOSED: exposedNode_free (t->content.exposed); break;
6277 case TK_UNION: taggedUnionNode_free (t->content.taggedunion); break;
6284 void claimNode_free (/*@only@*/ /*@null@*/ claimNode x)
6288 paramNodeList_free (x->params);
6289 globalList_free (x->globals);
6290 letDeclNodeList_free (x->lets);
6291 lclPredicateNode_free (x->require);
6292 programNode_free (x->body);
6293 lclPredicateNode_free (x->ensures);
6294 ltoken_free (x->name);
6299 void iterNode_free (/*@only@*/ /*@null@*/ iterNode x)
6303 paramNodeList_free (x->params);
6304 ltoken_free (x->name);
6309 void abstractNode_free (/*@only@*/ /*@null@*/ abstractNode x)
6313 abstBodyNode_free (x->body);
6314 ltoken_free (x->tok);
6315 ltoken_free (x->name);
6320 void exposedNode_free (/*@only@*/ /*@null@*/ exposedNode x)
6324 lclTypeSpecNode_free (x->type);
6325 declaratorInvNodeList_free (x->decls);
6326 ltoken_free (x->tok);
6331 void taggedUnionNode_free (/*@only@*/ /*@null@*/ taggedUnionNode x)
6335 stDeclNodeList_free (x->structdecls);
6336 declaratorNode_free (x->declarator);
6341 /*@only@*/ /*@null@*/ strOrUnionNode
6342 strOrUnionNode_copy (/*@null@*/ strOrUnionNode n)
6346 strOrUnionNode ret = (strOrUnionNode) dmalloc (sizeof (*ret));
6348 ret->kind = n->kind;
6349 ret->tok = ltoken_copy (n->tok);
6350 ret->opttagid = ltoken_copy (n->opttagid);
6351 ret->sort = n->sort;
6352 ret->structdecls = stDeclNodeList_copy (n->structdecls);
6362 void strOrUnionNode_free (/*@null@*/ /*@only@*/ strOrUnionNode n)
6366 stDeclNodeList_free (n->structdecls);
6367 ltoken_free (n->tok);
6368 ltoken_free (n->opttagid);
6373 void enumSpecNode_free (/*@null@*/ /*@only@*/ enumSpecNode x)
6377 ltokenList_free (x->enums);
6378 ltoken_free (x->tok);
6379 ltoken_free (x->opttagid);
6384 /*@only@*/ /*@null@*/ enumSpecNode enumSpecNode_copy (/*@null@*/ enumSpecNode x)
6388 enumSpecNode ret = (enumSpecNode) dmalloc (sizeof (*ret));
6390 ret->tok = ltoken_copy (x->tok);
6391 ret->opttagid = ltoken_copy (x->opttagid);
6392 ret->enums = ltokenList_copy (x->enums);
6393 ret->sort = x->sort;
6403 void lsymbol_setbool (lsymbol s)
6408 lsymbol lsymbol_getbool ()
6410 return lsymbol_bool;
6413 lsymbol lsymbol_getBool ()
6415 return lsymbol_Bool;
6418 lsymbol lsymbol_getFALSE ()
6420 return lsymbol_FALSE;
6423 lsymbol lsymbol_getTRUE ()
6425 return lsymbol_TRUE;