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 = sort_float;
190 symtable_enterType (g_symtab, ti);
194 declareForwardType (declaratorNode declare)
196 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
200 typedefname = ltoken_getText (declare->id);
201 ti->id = ltoken_copy (declare->id);
203 ltoken_setCode (ti->id, LLT_TYPEDEF_NAME);
204 ltoken_setIdType (ti->id, SID_TYPE);
206 ti->modifiable = FALSE;
207 ti->abstract = FALSE;
208 tsort = lclTypeSpecNode2sort (exposedType);
209 handle = typeExpr2ptrSort (tsort, declare->type);
210 ti->basedOn = sort_makeSyn (declare->id, handle, typedefname);
213 symtable_enterType (g_symtab, ti);
216 void LCLBuiltins (void)
218 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
219 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
221 /* immutable type bool;
223 constant bool FALSE = false;
224 constant bool TRUE = true; */
226 /* the following defines the builtin LSL sorts and operators */
229 /* now LCL builtin proper */
230 /* do "immutable type bool;" */
232 ti->id = ltoken_copy (ltoken_bool);
234 ltoken_setCode (ti->id, LLT_TYPEDEF_NAME);
235 ltoken_setIdType (ti->id, SID_TYPE);
237 ti->modifiable = FALSE;
239 ti->basedOn = sort_bool;
240 ti->export = FALSE; /* this wasn't set (detected by 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 = sort_bool;
250 (void) symtable_enterVar (g_symtab, vi);
252 /* do "constant bool TRUE = true;" */
253 /* vi->id = ltoken_copy (vi->id); */
254 ltoken_setText (vi->id, lsymbol_fromChars ("TRUE"));
255 (void) symtable_enterVar (g_symtab, vi);
271 ** Minimal we need to bootstrap is to provide the sort
272 ** "bool" and 2 bool constants "true" and "false".
273 ** sort_init should already have been called, and hence
274 ** the bool and Bool sorts defined.
277 s = sort_makeImmutable (ltoken_undefined, lsymbol_bool);
278 range = ltoken_create (simpleId, lsymbol_bool);
279 sign = makesigNode (ltoken_undefined, ltokenList_new (), range);
281 nn1 = (nameNode) dmalloc (sizeof (*nn1));
284 nn1->content.opid = ltoken_create (simpleId, lsymbol_fromChars ("true"));
286 symtable_enterOp (g_symtab, nn1, sign);
288 nn2 = (nameNode) dmalloc (sizeof (*nn2));
290 nn2->content.opid = ltoken_create (simpleId, lsymbol_fromChars ("false"));
292 symtable_enterOp (g_symtab, nn2, sigNode_copy (sign));
296 consInterfaceNode (/*@only@*/ interfaceNode n, /*@returned@*/ interfaceNodeList ns)
298 /* n is never empty, but ns may be empty */
299 interfaceNodeList_addl (ns, n);
303 /*@only@*/ interfaceNode
304 makeInterfaceNodeImports (/*@only@*/ importNodeList x)
306 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
307 lsymbol importSymbol;
309 i->kind = INF_IMPORTS;
310 i->content.imports = x; /* an importNodeList */
312 importNodeList_elements (x, imp)
314 importSymbol = ltoken_getRawText (imp->val);
316 if (lsymbolSet_member (g_currentImports, importSymbol))
319 message ("Circular imports: %s",
320 cstring_fromChars (lsymbol_toChars (importSymbol))));
324 processImport (importSymbol, imp->val, imp->kind);
326 } end_importNodeList_elements;
328 lhOutLine (cstring_undefined);
332 /*@only@*/ interfaceNode
333 makeInterfaceNodeUses (/*@only@*/ traitRefNodeList x)
335 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
339 /* read in LSL traits */
344 /*@only@*/ interfaceNode
345 interfaceNode_makeConst (/*@only@*/ constDeclarationNode x)
347 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
348 exportNode e = (exportNode) dmalloc (sizeof (*e));
351 e->content.constdeclaration = x;
352 i->kind = INF_EXPORT;
353 i->content.export = e;
358 /*@only@*/ interfaceNode
359 interfaceNode_makeVar (/*@only@*/ varDeclarationNode x)
361 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
362 exportNode e = (exportNode) dmalloc (sizeof (*e));
365 e->content.vardeclaration = x;
366 i->kind = INF_EXPORT;
367 i->content.export = e;
369 if (context_msgLh ())
371 lhOutLine (lhVarDecl (x->type, x->decls, x->qualifier));
377 /*@only@*/ interfaceNode
378 interfaceNode_makeType (/*@only@*/ typeNode x)
380 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
381 exportNode e = (exportNode) dmalloc (sizeof (*e));
384 i->kind = INF_EXPORT;
385 i->content.export = e;
387 if (context_msgLh ())
390 lhOutLine (lhType (x));
396 /*@only@*/ interfaceNode
397 interfaceNode_makeFcn (/*@only@*/ fcnNode x)
399 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
400 exportNode e = (exportNode) dmalloc (sizeof (*e));
404 i->kind = INF_EXPORT;
405 i->content.export = e;
407 if (context_msgLh ())
409 llassert (x->typespec != NULL);
410 llassert (x->declarator != NULL);
412 lhOutLine (lhFunction (x->typespec, x->declarator));
418 /*@only@*/ interfaceNode
419 interfaceNode_makeClaim (/*@only@*/ claimNode x)
421 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
422 exportNode e = (exportNode) dmalloc (sizeof (*e));
425 e->content.claim = x;
426 i->kind = INF_EXPORT;
427 i->content.export = e;
431 /*@only@*/ interfaceNode
432 interfaceNode_makeIter (/*@only@*/ iterNode x)
434 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
435 exportNode e = (exportNode) dmalloc (sizeof (*e));
439 i->kind = INF_EXPORT;
440 i->content.export = e;
444 /*@only@*/ interfaceNode
445 interfaceNode_makePrivConst (/*@only@*/ constDeclarationNode x)
447 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
448 privateNode e = (privateNode) dmalloc (sizeof (*e));
450 e->kind = PRIV_CONST;
451 e->content.constdeclaration = x;
452 i->kind = INF_PRIVATE;
453 i->content.private = e;
457 /*@only@*/ interfaceNode
458 interfaceNode_makePrivVar (/*@only@*/ varDeclarationNode x)
460 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
461 privateNode e = (privateNode) dmalloc (sizeof (*e));
464 e->content.vardeclaration = x;
465 i->kind = INF_PRIVATE;
466 i->content.private = e;
470 /*@only@*/ interfaceNode
471 interfaceNode_makePrivType (/*@only@*/ typeNode x)
473 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
474 privateNode e = (privateNode) dmalloc (sizeof (*e));
478 i->kind = INF_PRIVATE;
479 i->content.private = e;
483 /*@only@*/ interfaceNode
484 interfaceNode_makePrivFcn (/*@only@*/ fcnNode x)
486 interfaceNode i = (interfaceNode) dmalloc (sizeof (*i));
487 privateNode e = (privateNode) dmalloc (sizeof (*e));
490 ** bug detected by 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.
2526 /*@i3@*/ x->content.function.returntype = makeArrayNode (x, a);
2531 typeExpr y = (typeExpr) dmalloc (sizeof (*y));
2533 y->kind = TEXPR_ARRAY;
2535 if (a == (arrayQualNode) 0)
2537 y->content.array.size = (termNode) 0;
2541 y->content.array.size = a->term;
2542 ltoken_free (a->tok);
2546 y->content.array.elementtype = x;
2547 y->sort = sort_makeNoSort ();
2553 /*@only@*/ constDeclarationNode
2554 makeConstDeclarationNode (lclTypeSpecNode t, initDeclNodeList decls)
2556 constDeclarationNode n = (constDeclarationNode) dmalloc (sizeof (*n));
2557 sort s, s2, initValueSort;
2558 ltoken varid, errtok;
2561 s = lclTypeSpecNode2sort (t);
2563 initDeclNodeList_elements (decls, init)
2565 declaratorNode vdnode = init->declarator;
2566 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
2568 varid = ltoken_copy (vdnode->id);
2569 s2 = typeExpr2ptrSort (s, vdnode->type);
2570 initValue = init->value;
2572 if (termNode_isDefined (initValue) && !initValue->error_reported)
2574 initValueSort = initValue->sort;
2576 /* should keep the arguments in order */
2577 if (!sort_member_modulo_cstring (s2, initValue)
2578 && !initValue->error_reported)
2580 errtok = termNode_errorToken (initValue);
2584 message ("Constant %s declared type %q, initialized to %q: %q",
2585 ltoken_unparse (varid),
2587 sort_unparse (initValueSort),
2588 termNode_unparse (initValue)));
2593 vi->kind = VRK_CONST;
2597 (void) symtable_enterVar (g_symtab, vi);
2600 } end_initDeclNodeList_elements;
2608 varDeclarationNode makeInternalStateNode (void)
2610 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2612 n->isSpecial = TRUE;
2613 n->sref = sRef_makeInternalState ();
2615 /*@-compdef@*/ return n; /*@=compdef@*/
2618 varDeclarationNode makeFileSystemNode (void)
2620 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2622 n->isSpecial = TRUE;
2623 n->sref = sRef_makeSystemState ();
2625 /*@-compdef@*/ return n; /*@=compdef@*/
2628 /*@only@*/ varDeclarationNode
2629 makeVarDeclarationNode (lclTypeSpecNode t, initDeclNodeList x,
2630 bool isGlobal, bool isPrivate)
2632 varDeclarationNode n = (varDeclarationNode) dmalloc (sizeof (*n));
2633 sort s, s2, initValueSort;
2634 ltoken varid, errtok;
2636 declaratorNode vdnode;
2638 n->isSpecial = FALSE;
2639 n->qualifier = QLF_NONE;
2640 n->isGlobal = isGlobal;
2641 n->isPrivate = isPrivate;
2644 s = lclTypeSpecNode2sort (t);
2646 /* t is an lclTypeSpec, its sort may not be assigned yet */
2648 initDeclNodeList_elements (x, init)
2650 vdnode = init->declarator;
2652 s2 = typeExpr2ptrSort (s, vdnode->type);
2653 initValue = init->value;
2655 if (termNode_isDefined (initValue) && !initValue->error_reported)
2657 initValueSort = initValue->sort;
2658 /* should keep the arguments in order */
2659 if (!sort_member_modulo_cstring (s2, initValue)
2660 && !initValue->error_reported)
2662 errtok = termNode_errorToken (initValue);
2665 message ("Variable %s declared type %q, initialized to %q",
2666 ltoken_unparse (varid),
2668 sort_unparse (initValueSort)));
2673 ** If global, check that it has been declared already, don't push
2674 ** onto symbol table yet (wrong scope, done in enteringFcnScope
2679 varInfo vi = symtable_varInfo (g_symtab, ltoken_getText (varid));
2681 if (!varInfo_exists (vi))
2684 message ("Undeclared global variable: %s",
2685 ltoken_getRawString (varid)));
2689 if (vi->kind == VRK_CONST)
2692 message ("Constant used in global list: %s",
2693 ltoken_getRawString (varid)));
2699 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
2701 vi->id = ltoken_copy (varid);
2704 vi->kind = VRK_PRIVATE;
2705 /* check that initValue is not empty */
2706 if (initValue == (termNode) 0)
2709 message ("Private variable must have initialization: %s",
2710 ltoken_getRawString (varid)));
2718 vi->sort = sort_makeGlobal (s2);
2721 vdnode->isRedecl = symtable_enterVar (g_symtab, vi);
2724 } end_initDeclNodeList_elements;
2731 /*@only@*/ initDeclNode
2732 makeInitDeclNode (declaratorNode d, termNode x)
2734 initDeclNode n = (initDeclNode) dmalloc (sizeof (*n));
2741 /*@only@*/ abstractNode
2742 makeAbstractNode (ltoken t, ltoken name,
2743 bool isMutable, bool isRefCounted, abstBodyNode a)
2745 abstractNode n = (abstractNode) dmalloc (sizeof (*n));
2747 typeInfo ti = (typeInfo) dmalloc (sizeof (*ti));
2750 n->isMutable = isMutable;
2753 n->isRefCounted = isRefCounted;
2756 handle = sort_makeMutable (name, ltoken_getText (name));
2758 handle = sort_makeImmutable (name, ltoken_getText (name));
2761 ti->id = ltoken_createType (ltoken_getCode (ltoken_typename), SID_TYPE,
2762 ltoken_getText (name));
2763 ti->modifiable = isMutable;
2764 ti->abstract = TRUE;
2765 ti->basedOn = handle;
2768 symtable_enterType (g_symtab, ti);
2775 abstractNode_unparse (abstractNode n)
2777 if (n != (abstractNode) 0)
2782 s = cstring_makeLiteral ("mutable");
2784 s = cstring_makeLiteral ("immutable");
2786 return (message ("%q type %s%q;", s, ltoken_getRawString (n->name),
2787 abstBodyNode_unparse (n->body)));
2789 return cstring_undefined;
2793 setExposedType (lclTypeSpecNode s)
2798 /*@only@*/ exposedNode
2799 makeExposedNode (ltoken t, lclTypeSpecNode s,
2800 declaratorInvNodeList d)
2802 exposedNode n = (exposedNode) dmalloc (sizeof (*n));
2812 exposedNode_unparse (exposedNode n)
2814 if (n != (exposedNode) 0)
2816 return (message ("typedef %q %q;",
2817 lclTypeSpecNode_unparse (n->type),
2818 declaratorInvNodeList_unparse (n->decls)));
2820 return cstring_undefined;
2823 /*@only@*/ declaratorInvNode
2824 makeDeclaratorInvNode (declaratorNode d, abstBodyNode b)
2826 declaratorInvNode n = (declaratorInvNode) dmalloc (sizeof (*n));
2834 declaratorInvNode_unparse (declaratorInvNode d)
2836 return (message ("%q%q", declaratorNode_unparse (d->declarator),
2837 abstBodyNode_unparseExposed (d->body)));
2841 abstBodyNode_unparse (abstBodyNode n)
2843 if (n != (abstBodyNode) 0)
2845 return (lclPredicateNode_unparse (n->typeinv));
2847 return cstring_undefined;
2851 abstBodyNode_unparseExposed (abstBodyNode n)
2853 if (n != (abstBodyNode) 0)
2855 return (message ("%q", lclPredicateNode_unparse (n->typeinv)));
2857 return cstring_undefined;
2861 taggedUnionNode_unparse (taggedUnionNode n)
2863 if (n != (taggedUnionNode) 0)
2865 return (message ("tagged union {%q}%q;\n",
2866 stDeclNodeList_unparse (n->structdecls),
2867 declaratorNode_unparse (n->declarator)));
2869 return cstring_undefined;
2872 static /*@observer@*/ paramNodeList
2873 typeExpr_toParamNodeList (/*@null@*/ typeExpr te)
2875 if (te != (typeExpr) 0)
2880 return te->content.function.args;
2882 return typeExpr_toParamNodeList (te->content.pointer);
2884 /* return typeExpr_toParamNodeList (te->content.array.elementtype); */
2886 return paramNodeList_undefined;
2889 return paramNodeList_undefined;
2893 fcnNode_fromDeclarator (/*@only@*/ /*@null@*/ lclTypeSpecNode t,
2894 /*@only@*/ declaratorNode d)
2896 return (makeFcnNode (qual_createUnknown (), t, d,
2897 varDeclarationNodeList_new (),
2898 varDeclarationNodeList_new (),
2899 letDeclNodeList_new (),
2900 (lclPredicateNode) 0,
2901 (lclPredicateNode) 0,
2903 (lclPredicateNode) 0,
2904 (lclPredicateNode) 0));
2908 makeIterNode (ltoken id, paramNodeList p)
2910 iterNode x = (iterNode) dmalloc (sizeof (*x));
2911 bool hasYield = FALSE;
2916 /* check there is at least one yield param */
2918 paramNodeList_elements (p, pe)
2920 if (paramNode_isYield (pe))
2925 } end_paramNodeList_elements
2929 lclerror (id, message ("Iterator has no yield parameters: %s",
2930 ltoken_getRawString (id)));
2937 makeFcnNode (qual specQual,
2938 /*@null@*/ lclTypeSpecNode t,
2940 /*@null@*/ globalList g,
2941 /*@null@*/ varDeclarationNodeList privateinits,
2942 /*@null@*/ letDeclNodeList lets,
2943 /*@null@*/ lclPredicateNode checks,
2944 /*@null@*/ lclPredicateNode requires,
2945 /*@null@*/ modifyNode m,
2946 /*@null@*/ lclPredicateNode ensures,
2947 /*@null@*/ lclPredicateNode claims)
2949 fcnNode x = (fcnNode) dmalloc (sizeof (*x));
2951 if (d->type != (typeExpr)0 && (d->type)->kind != TEXPR_FCN)
2953 lclerror (d->id, cstring_makeLiteral
2954 ("Attempt to specify function without parameter list"));
2955 d->type = makeFunctionNode (d->type, paramNodeList_new ());
2958 x->special = specQual;
2962 x->inits = privateinits;
2965 x->require = requires;
2967 x->ensures = ensures;
2970 /* extract info to fill in x->name =; x->signature =; */
2971 x->name = ltoken_copy (d->id);
2976 /*@only@*/ claimNode
2977 makeClaimNode (ltoken id, paramNodeList p,
2978 globalList g, letDeclNodeList lets, lclPredicateNode requires,
2979 programNode b, lclPredicateNode ensures)
2981 claimNode x = (claimNode) dmalloc (sizeof (*x));
2988 x->require = requires;
2990 x->ensures = ensures;
2994 /*@only@*/ lclPredicateNode
2995 makeIntraClaimNode (ltoken t, lclPredicateNode n)
2997 ltoken_free (n->tok);
2999 n->kind = LPD_INTRACLAIM;
3003 /*@only@*/ lclPredicateNode
3004 makeRequiresNode (ltoken t, lclPredicateNode n)
3006 ltoken_free (n->tok);
3008 n->kind = LPD_REQUIRES;
3012 /*@only@*/ lclPredicateNode
3013 makeChecksNode (ltoken t, lclPredicateNode n)
3015 ltoken_free (n->tok);
3017 n->kind = LPD_CHECKS;
3021 /*@only@*/ lclPredicateNode
3022 makeEnsuresNode (ltoken t, lclPredicateNode n)
3024 ltoken_free (n->tok);
3026 n->kind = LPD_ENSURES;
3030 /*@only@*/ lclPredicateNode
3031 makeLclPredicateNode (ltoken t, termNode n,
3034 lclPredicateNode x = (lclPredicateNode) dmalloc (sizeof (*x));
3042 /*@only@*/ quantifierNode
3043 makeQuantifierNode (varNodeList v, ltoken quant)
3045 quantifierNode x = (quantifierNode) dmalloc (sizeof (*x));
3049 x->isForall = cstring_equalLit (ltoken_unparse (quant), "\forall");
3054 /*@only@*/ arrayQualNode
3055 makeArrayQualNode (ltoken t, termNode term)
3057 arrayQualNode x = (arrayQualNode) dmalloc (sizeof (*x));
3065 makeVarNode (/*@only@*/ ltoken varid, bool isObj, lclTypeSpecNode t)
3067 varNode x = (varNode) dmalloc (sizeof (*x));
3068 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
3071 vi->id = ltoken_copy (varid);
3072 sort = lclTypeSpecNode2sort (t);
3074 /* 9/3/93, The following is needed because we want value sorts to be
3075 the default, object sort is generated only if there is "obj" qualifier.
3076 There are 2 cases: (1) for immutable types (including C primitive types),
3077 we need to generate the object sort if qualifier is present; (2) for
3078 array, struct and union types, they are already in their object sorts.
3081 sort = sort_makeVal (sort); /* both cases are now value sorts */
3085 sort = sort_makeObj (sort);
3090 vi->kind = VRK_QUANT;
3093 (void) symtable_enterVar (g_symtab, vi);
3099 x->sort = sort_makeNoSort ();
3104 /*@only@*/ abstBodyNode
3105 makeAbstBodyNode (ltoken t, fcnNodeList f)
3107 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3110 x->typeinv = (lclPredicateNode)0;
3115 /*@only@*/ abstBodyNode
3116 makeExposedBodyNode (ltoken t, lclPredicateNode inv)
3118 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3122 x->fcns = fcnNodeList_undefined;
3126 /*@only@*/ abstBodyNode
3127 makeAbstBodyNode2 (ltoken t, ltokenList ops)
3129 abstBodyNode x = (abstBodyNode) dmalloc (sizeof (*x));
3132 x->typeinv = (lclPredicateNode) 0;
3134 x->fcns = fcnNodeList_new ();
3136 ltokenList_elements (ops, op)
3138 x->fcns = fcnNodeList_add
3140 fcnNode_fromDeclarator (lclTypeSpecNode_undefined,
3141 makeUnknownDeclaratorNode (ltoken_copy (op))));
3142 } end_ltokenList_elements;
3144 ltokenList_free (ops);
3150 makeStmtNode (ltoken varId, ltoken fcnId, /*@only@*/ termNodeList v)
3152 stmtNode n = (stmtNode) dmalloc (sizeof (*n));
3155 n->operator = fcnId;
3160 /* printDeclarators -> declaratorNodeList_unparse */
3162 static cstring abstDeclaratorNode_unparse (abstDeclaratorNode x)
3164 return (typeExpr_unparse ((typeExpr) x));
3167 /*@only@*/ paramNode
3168 makeParamNode (lclTypeSpecNode t, typeExpr d)
3170 paramNode x = (paramNode) dmalloc (sizeof (*x));
3172 paramNode_checkQualifiers (t, d);
3176 x->kind = PNORMAL; /*< forgot this! >*/
3181 /*@only@*/ paramNode
3182 paramNode_elipsis (void)
3184 paramNode x = (paramNode) dmalloc (sizeof (*x));
3186 x->type = (lclTypeSpecNode) 0;
3187 x->paramdecl = (typeExpr) 0;
3193 static /*@observer@*/ ltoken typeExpr_getTok (typeExpr d)
3195 while (d != (typeExpr)0)
3197 if (d->kind == TEXPR_BASE)
3199 return (d->content.base);
3203 if (d->kind == TEXPR_PTR)
3205 d = d->content.pointer;
3207 else if (d->kind == TEXPR_ARRAY)
3209 d = d->content.array.elementtype;
3211 else if (d->kind == TEXPR_FCN)
3213 d = d->content.function.returntype;
3222 llfatalerror (cstring_makeLiteral ("typeExpr_getTok: unreachable code"));
3227 paramNode_checkQualifiers (lclTypeSpecNode t, typeExpr d)
3229 bool isPointer = FALSE;
3230 bool isUser = FALSE;
3231 bool hasAlloc = FALSE;
3232 bool hasAlias = FALSE;
3234 llassert (lclTypeSpecNode_isDefined (t));
3236 if (pointers_isUndefined (t->pointers)
3237 && (d != (typeExpr)0 && d->kind != TEXPR_PTR) && d->kind != TEXPR_ARRAY)
3239 if (t->kind == LTS_TYPE)
3243 llassert (t->content.type != NULL);
3245 sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
3247 if (sn->kind == SRT_PTR || sn->kind == SRT_ARRAY
3248 || sn->kind == SRT_HOF || sn->kind == SRT_NONE)
3259 if (d != (typeExpr)0 && d->kind != TEXPR_BASE)
3261 if (t->kind == LTS_TYPE)
3265 llassert (t->content.type != NULL);
3266 sn = sort_quietLookup (sort_getUnderlying ((t->content.type)->sort));
3268 if (sn->kind == SRT_PTR || sn->kind == SRT_ARRAY
3269 || sn->kind == SRT_HOF || sn->kind == SRT_NONE)
3280 if (d != (typeExpr)NULL)
3282 qualList_elements (t->quals, q)
3284 if (qual_isAllocQual (q))
3288 ltoken tok = typeExpr_getTok (d);
3289 lclerror (tok, message ("Parameter declared with multiple allocation "
3290 "qualifiers: %q", typeExpr_unparse (d)));
3296 ltoken tok = typeExpr_getTok (d);
3297 lclerror (tok, message ("Non-pointer declared as %s parameter: %q",
3299 typeExpr_unparse (d)));
3302 if (qual_isAliasQual (q))
3306 ltoken tok = typeExpr_getTok (d);
3307 lclerror (tok, message ("Parameter declared with multiple alias qualifiers: %q",
3308 typeExpr_unparse (d)));
3312 if (!(isPointer || isUser))
3314 ltoken tok = typeExpr_getTok (d);
3315 lclerror (tok, message ("Unsharable type declared as %s parameter: %q",
3317 typeExpr_unparse (d)));
3320 } end_qualList_elements;
3325 paramNode_unparse (paramNode x)
3327 if (x != (paramNode) 0)
3329 if (x->kind == PELIPSIS)
3331 return (cstring_makeLiteral ("..."));
3334 if (x->paramdecl != (typeExpr) 0)
3335 { /* handle (void) */
3336 return (message ("%q %q", lclTypeSpecNode_unparse (x->type),
3337 typeExpr_unparse (x->paramdecl)));
3341 return (lclTypeSpecNode_unparse (x->type));
3344 return cstring_undefined;
3348 lclTypeSpecNode_unparseAltComments (/*@null@*/ lclTypeSpecNode typespec) /*@*/
3350 if (typespec != (lclTypeSpecNode) 0)
3352 cstring s = qualList_toCComments (typespec->quals);
3354 switch (typespec->kind)
3358 llassert (typespec->content.type != NULL);
3360 return (cstring_concatFree
3361 (s, printLeaves (typespec->content.type->ctypes)));
3366 enumSpecNode n = typespec->content.enumspec;
3368 s = cstring_concatFree (s, cstring_makeLiteral ("enum"));
3369 llassert (n != NULL);
3371 if (!ltoken_isUndefined (n->opttagid))
3373 s = message ("%q %s", s, ltoken_unparse (n->opttagid));
3375 s = message ("%q {", s);
3377 ltokenList_elements (n->enums, e)
3382 s = message ("%q%s", s, ltoken_getRawString (e));
3385 s = message ("%q, %s", s, ltoken_getRawString (e));
3386 } end_ltokenList_elements;
3388 return (message ("%q}", s));
3390 case LTS_STRUCTUNION:
3392 strOrUnionNode n = typespec->content.structorunion;
3393 stDeclNodeList decls;
3395 llassert (n != NULL);
3400 s = cstring_concatFree (s, cstring_makeLiteral ("struct "));
3401 /*@switchbreak@*/ break;
3403 s = cstring_concatFree (s, cstring_makeLiteral ("union "));
3404 /*@switchbreak@*/ break;
3407 if (!ltoken_isUndefined (n->opttagid))
3409 if (stDeclNodeList_size (n->structdecls) == 0)
3411 return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
3414 s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid));
3418 s = message ("%q{\n\t", s);
3421 decls = n->structdecls;
3423 stDeclNodeList_elements (decls, f)
3425 s = message ("%q%q %q;\n\t", s,
3426 lclTypeSpecNode_unparseAltComments (f->lcltypespec),
3427 declaratorNodeList_unparse (f->declarators));
3428 } end_stDeclNodeList_elements;
3430 return (message ("%q }", s));
3439 lclTypeSpecNode_unparseAltComments (typespec->content.conj->a),
3440 lclTypeSpecNode_unparseAltComments (typespec->content.conj->b)));
3447 llcontbuglit ("lclTypeSpecNode_unparseComments: null typespec");
3449 return cstring_undefined;
3455 cstring lclTypeSpecNode_unparseComments (/*@null@*/ lclTypeSpecNode typespec)
3457 if (typespec != (lclTypeSpecNode) 0)
3459 cstring s = qualList_toCComments (typespec->quals);
3461 switch (typespec->kind)
3465 llassert (typespec->content.type != NULL);
3467 return (cstring_concatFree
3468 (s, printLeaves (typespec->content.type->ctypes)));
3473 enumSpecNode n = typespec->content.enumspec;
3475 s = cstring_concatFree (s, cstring_makeLiteral ("enum"));
3476 llassert (n != NULL);
3478 if (!ltoken_isUndefined (n->opttagid))
3480 s = message ("%q %s", s, ltoken_unparse (n->opttagid));
3482 s = message ("%q {", s);
3484 ltokenList_elements (n->enums, e)
3489 s = message ("%q%s", s, ltoken_getRawString (e));
3492 s = message ("%q, %s", s, ltoken_getRawString (e));
3493 } end_ltokenList_elements;
3495 return (message ("%q}", s));
3497 case LTS_STRUCTUNION:
3499 strOrUnionNode n = typespec->content.structorunion;
3500 stDeclNodeList decls;
3502 llassert (n != NULL);
3507 s = cstring_concatFree (s, cstring_makeLiteral ("struct "));
3508 /*@switchbreak@*/ break;
3510 s = cstring_concatFree (s, cstring_makeLiteral ("union "));
3511 /*@switchbreak@*/ break;
3514 if (!ltoken_isUndefined (n->opttagid))
3516 if (stDeclNodeList_size (n->structdecls) == 0)
3518 return (message ("%q%s", s, ltoken_unparse (n->opttagid)));
3521 s = message ("%q%s {\n\t", s, ltoken_unparse (n->opttagid));
3525 s = message ("%q{\n\t", s);
3528 decls = n->structdecls;
3530 stDeclNodeList_elements (decls, f)
3532 s = message ("%q%q %q;\n\t", s,
3533 lclTypeSpecNode_unparseComments (f->lcltypespec),
3534 declaratorNodeList_unparse (f->declarators));
3535 } end_stDeclNodeList_elements;
3537 return (message ("%q }", s));
3546 lclTypeSpecNode_unparseComments (typespec->content.conj->a),
3547 lclTypeSpecNode_unparseAltComments (typespec->content.conj->b)));
3554 llcontbuglit ("lclTypeSpecNode_unparseComments: null typespec");
3556 return cstring_undefined;
3563 paramNode_unparseComments (paramNode x)
3565 if (x != (paramNode) 0)
3567 if (x->kind == PELIPSIS)
3569 return (cstring_makeLiteral ("..."));
3572 if (x->paramdecl != (typeExpr) 0)
3573 { /* handle (void) */
3574 return (message ("%q %q",
3575 lclTypeSpecNode_unparseComments (x->type),
3576 typeExpr_unparseNoBase (x->paramdecl)));
3580 return (lclTypeSpecNode_unparseComments (x->type));
3583 return cstring_undefined;
3587 makeIfTermNode (ltoken ift, termNode ifn, ltoken thent,
3588 termNode thenn, ltoken elset,
3591 termNode t = (termNode) dmalloc (sizeof (*t));
3592 opFormNode opform = makeOpFormNode (ift, OPF_IF, opFormUnion_createMiddle (0),
3594 nameNode nn = makeNameNodeForm (opform);
3595 termNodeList args = termNodeList_new ();
3597 t->error_reported = FALSE;
3599 termNodeList_addh (args, ifn);
3600 termNodeList_addh (args, thenn);
3601 termNodeList_addh (args, elsen);
3604 t->kind = TRM_APPLICATION;
3605 t->sort = sort_makeNoSort ();
3607 t->possibleSorts = sortSet_new ();
3608 t->possibleOps = lslOpSet_new ();
3610 ltoken_free (thent);
3611 ltoken_free (elset);
3616 static /*@observer@*/ ltoken
3617 nameNode2anyOp (nameNode n)
3619 if (n != (nameNode) 0)
3621 opFormNode opnode = n->content.opform;
3624 llassert (opnode != NULL);
3626 kind = opnode->kind;
3628 if (kind == OPF_MANYOPM || kind == OPF_ANYOP ||
3629 kind == OPF_MANYOP || kind == OPF_ANYOPM)
3633 u = opnode->content;
3637 return ltoken_undefined;
3641 makeInfixTermNode (termNode x, ltoken op, termNode y)
3643 termNode t = (termNode) dmalloc (sizeof (*t));
3646 termNodeList args = termNodeList_new ();
3648 checkAssociativity (x, op);
3650 opform = makeOpFormNode (op, OPF_MANYOPM,
3651 opFormUnion_createAnyOp (op),
3654 nn = makeNameNodeForm (opform);
3656 t->error_reported = FALSE;
3658 termNodeList_addh (args, x);
3659 termNodeList_addh (args, y);
3662 t->kind = TRM_APPLICATION;
3663 t->sort = sort_makeNoSort ();
3665 t->possibleSorts = sortSet_new (); /* sort_equal */
3666 t->possibleOps = lslOpSet_new ();
3670 /*@only@*/ quantifiedTermNode
3671 quantifiedTermNode_copy (quantifiedTermNode q)
3673 quantifiedTermNode ret = (quantifiedTermNode) dmalloc (sizeof (*ret));
3675 ret->quantifiers = quantifierNodeList_copy (q->quantifiers);
3676 ret->open = ltoken_copy (q->open);
3677 ret->close = ltoken_copy (q->close);
3678 ret->body = termNode_copySafe (q->body);
3684 makeQuantifiedTermNode (quantifierNodeList qn, ltoken open,
3685 termNode t, ltoken close)
3688 termNode n = (termNode) dmalloc (sizeof (*n));
3689 quantifiedTermNode q = (quantifiedTermNode) dmalloc (sizeof (*q));
3691 n->name = NULL; /*> missing this --- detected by splint <*/
3692 n->error_reported = FALSE;
3694 n->error_reported = FALSE;
3695 n->kind = TRM_QUANTIFIER;
3696 n->possibleSorts = sortSet_new ();
3697 n->possibleOps = lslOpSet_new ();
3698 n->kind = TRM_UNCHANGEDALL;
3699 n->args = termNodeList_new (); /*< forgot this >*/
3701 termNodeList_free (t->args);
3702 t->args = termNodeList_new ();
3706 (void) sortSet_insert (n->possibleSorts, sort);
3708 q->quantifiers = qn;
3718 makePostfixTermNode (/*@returned@*/ /*@only@*/ termNode secondary, ltokenList postfixops)
3720 termNode top = secondary;
3722 ltokenList_elements (postfixops, op)
3724 top = makePostfixTermNode2 (top, ltoken_copy (op));
3725 /*@i@*/ } end_ltokenList_elements;
3727 ltokenList_free (postfixops);
3729 return (top); /* dep as only? */
3733 ** secondary is returned in the args list
3737 makePostfixTermNode2 (/*@returned@*/ /*@only@*/ termNode secondary,
3738 /*@only@*/ ltoken postfixop)
3740 termNode t = (termNode) dmalloc (sizeof (*t));
3742 opFormNode opform = makeOpFormNode (postfixop,
3743 OPF_MANYOP, opFormUnion_createAnyOp (postfixop),
3745 nameNode nn = makeNameNodeForm (opform);
3746 termNodeList args = termNodeList_new ();
3748 t->error_reported = FALSE;
3750 termNodeList_addh (args, secondary);
3753 t->kind = TRM_APPLICATION;
3754 t->sort = sort_makeNoSort ();
3756 t->possibleSorts = sortSet_new ();
3757 t->possibleOps = lslOpSet_new ();
3762 makePrefixTermNode (ltoken op, termNode arg)
3764 termNode t = (termNode) dmalloc (sizeof (*t));
3765 termNodeList args = termNodeList_new ();
3766 opFormNode opform = makeOpFormNode (op, OPF_ANYOPM, opFormUnion_createAnyOp (op),
3768 nameNode nn = makeNameNodeForm (opform);
3770 t->error_reported = FALSE;
3773 termNodeList_addh (args, arg);
3775 t->kind = TRM_APPLICATION;
3776 t->sort = sort_makeNoSort ();
3778 t->possibleSorts = sortSet_new ();
3779 t->possibleOps = lslOpSet_new ();
3784 makeOpCallTermNode (ltoken op, ltoken open,
3785 termNodeList args, ltoken close)
3787 /* like prefixTerm, but with opId LPAR termNodeList RPAR */
3788 termNode t = (termNode) dmalloc (sizeof (*t));
3789 nameNode nn = makeNameNodeId (op);
3791 t->error_reported = FALSE;
3795 t->kind = TRM_APPLICATION;
3796 t->sort = sort_makeNoSort ();
3798 t->possibleSorts = sortSet_new ();
3799 t->possibleOps = lslOpSet_new ();
3802 ltoken_free (close);
3807 /*@exposed@*/ termNode
3808 CollapseInfixTermNode (/*@returned@*/ termNode secondary, termNodeList infix)
3810 termNode left = secondary;
3812 termNodeList_elements (infix, node)
3814 termNodeList_addl (node->args, termNode_copySafe (left));
3816 /* computePossibleSorts (left); */
3817 } end_termNodeList_elements;
3823 checkAssociativity (termNode x, ltoken op)
3827 if (x->wrapped == 0 && /* no parentheses */
3828 x->kind == TRM_APPLICATION && x->name != (nameNode) 0 &&
3831 lastOpToken = nameNode2anyOp (x->name);
3833 if ((ltoken_getCode (lastOpToken) == logicalOp &&
3834 ltoken_getCode (op) == logicalOp) ||
3835 ((ltoken_getCode (lastOpToken) == simpleOp ||
3836 ltoken_getCode (lastOpToken) == LLT_MULOP) &&
3837 (ltoken_getCode (op) == simpleOp ||
3838 ltoken_getCode (op) == LLT_MULOP)))
3839 if (ltoken_getText (lastOpToken) != ltoken_getText (op))
3843 ("Parentheses needed to specify associativity of %s and %s",
3844 cstring_fromChars (lsymbol_toChars (ltoken_getText (lastOpToken))),
3845 cstring_fromChars (lsymbol_toChars (ltoken_getText (op)))));
3851 pushInfixOpPartNode (/*@returned@*/ termNodeList x, ltoken op,
3852 /*@only@*/ termNode secondary)
3854 termNode lastLeftTerm;
3855 termNodeList args = termNodeList_new ();
3856 termNode t = (termNode) dmalloc (sizeof (*t));
3860 termNodeList_addh (args, secondary);
3862 if (!termNodeList_empty (x))
3864 termNodeList_reset (x);
3865 lastLeftTerm = termNodeList_current (x);
3866 checkAssociativity (lastLeftTerm, op);
3869 opform = makeOpFormNode (op, OPF_MANYOPM,
3870 opFormUnion_createAnyOp (op), ltoken_undefined);
3872 nn = makeNameNodeForm (opform);
3874 t->error_reported = FALSE;
3877 t->kind = TRM_APPLICATION;
3879 t->sort = sort_makeNoSort ();
3881 t->possibleSorts = sortSet_new ();
3882 t->possibleOps = lslOpSet_new ();
3883 termNodeList_addh (x, t);
3884 /* don't compute sort yet, do it in CollapseInfixTermNode */
3889 updateMatchedNode (/*@only@*/ termNode left, /*@returned@*/ termNode t,
3890 /*@only@*/ termNode right)
3894 if ((t == (termNode) 0) || (t->name == NULL) || t->name->isOpId)
3896 llbugexitlit ("updateMatchedNode: expect opForm in nameNode");
3899 op = t->name->content.opform;
3900 llassert (op != NULL);
3902 if (left == (termNode) 0)
3904 if (right == (termNode) 0)
3906 /* op->kind is not changed */
3907 termNode_free (right);
3911 op->kind = OPF_MIDDLEM;
3912 op->key = opFormNode2key (op, OPF_MIDDLEM);
3913 termNodeList_addh (t->args, right);
3918 termNodeList_addl (t->args, left);
3919 if (right == (termNode) 0)
3921 op->kind = OPF_MMIDDLE;
3922 op->key = opFormNode2key (op, OPF_MMIDDLE);
3926 op->kind = OPF_MMIDDLEM;
3927 op->key = opFormNode2key (op, OPF_MMIDDLEM);
3928 termNodeList_addh (t->args, right);
3935 updateSqBracketedNode (/*@only@*/ termNode left,
3936 /*@only@*/ /*@returned@*/ termNode t,
3937 /*@only@*/ termNode right)
3941 if ((t == (termNode) 0) || (t->name == NULL) || (t->name->isOpId))
3943 llbugexitlit ("updateSqBracketededNode: expect opForm in nameNode");
3946 op = t->name->content.opform;
3947 llassert (op != NULL);
3949 if (left == (termNode) 0)
3951 if (right == (termNode) 0)
3953 /* op->kind is not changed */
3957 op->kind = OPF_BMIDDLEM;
3958 op->key = opFormNode2key (op, OPF_BMIDDLEM);
3959 termNodeList_addh (t->args, right);
3964 termNodeList_addl (t->args, left);
3966 if (right == (termNode) 0)
3968 op->kind = OPF_BMMIDDLE;
3969 op->key = opFormNode2key (op, OPF_BMMIDDLE);
3973 op->kind = OPF_BMMIDDLEM;
3974 op->key = opFormNode2key (op, OPF_BMMIDDLEM);
3975 termNodeList_addh (t->args, right);
3982 makeSqBracketedNode (ltoken lbracket,
3983 termNodeList args, ltoken rbracket)
3985 termNode t = (termNode) dmalloc (sizeof (*t));
3990 t->error_reported = FALSE;
3993 size = termNodeList_size (args);
3994 opform = makeOpFormNode (lbracket, OPF_BMIDDLE, opFormUnion_createMiddle (size),
3996 nn = makeNameNodeForm (opform);
3998 t->kind = TRM_APPLICATION;
4000 t->sort = sort_makeNoSort ();
4002 t->possibleSorts = sortSet_new ();
4003 t->possibleOps = lslOpSet_new ();
4004 /* do sort checking later, not here, incomplete parse */
4009 makeMatchedNode (ltoken open, termNodeList args, ltoken close)
4011 /* matched : open args close */
4012 termNode t = (termNode) dmalloc (sizeof (*t));
4017 t->error_reported = FALSE;
4020 size = termNodeList_size (args);
4021 opform = makeOpFormNode (open, OPF_MIDDLE, opFormUnion_createMiddle (size), close);
4022 nn = makeNameNodeForm (opform);
4024 t->kind = TRM_APPLICATION;
4026 t->sort = sort_makeNoSort ();
4028 t->possibleSorts = sortSet_new ();
4029 t->possibleOps = lslOpSet_new ();
4030 /* do sort checking later, not here, incomplete parse */
4035 makeSimpleTermNode (ltoken varid)
4037 sort theSort = sort_makeNoSort ();
4041 termNode n = (termNode) dmalloc (sizeof (*n));
4043 n->error_reported = FALSE;
4045 n->name = (nameNode) 0;
4047 n->args = termNodeList_new ();
4048 n->possibleSorts = sortSet_new ();
4049 n->possibleOps = lslOpSet_new ();
4051 sym = ltoken_getText (varid);
4053 /* lookup current scope */
4054 vi = symtable_varInfoInScope (g_symtab, sym);
4056 if (varInfo_exists (vi))
4062 (void) sortSet_insert (n->possibleSorts, theSort);
4065 { /* need to handle LCL constants */
4066 vi = symtable_varInfo (g_symtab, sym);
4068 if (varInfo_exists (vi) && vi->kind == VRK_CONST)
4071 n->kind = TRM_CONST;
4074 (void) sortSet_insert (n->possibleSorts, theSort);
4077 { /* and LSL operators (true, false, new, nil, etc) */
4078 nameNode nn = makeNameNodeId (ltoken_copy (varid));
4079 oi = symtable_opInfo (g_symtab, nn);
4081 if (opInfo_exists (oi) && (oi->name->isOpId) &&
4082 !sigNodeSet_isEmpty (oi->signatures))
4084 sigNodeSet_elements (oi->signatures, x)
4086 if (ltokenList_empty (x->domain))
4087 /* yes, it really is empty, not not empty */
4089 lslOp op = (lslOp) dmalloc (sizeof (*op));
4091 op->name = nameNode_copy (nn);
4093 (void) sortSet_insert (n->possibleSorts, sigNode_rangeSort (x));
4094 (void) lslOpSet_insert (n->possibleOps, op);
4096 } end_sigNodeSet_elements;
4101 if (sortSet_size (n->possibleSorts) == 0)
4105 message ("Unrecognized identifier (constant, variable or operator): %s",
4106 ltoken_getRawString (varid)));
4110 n->sort = sort_makeNoSort ();
4112 n->kind = TRM_ZEROARY;
4120 makeSelectTermNode (termNode pri, ltoken select, /*@dependent@*/ ltoken id)
4122 termNode t = (termNode) dmalloc (sizeof (*t));
4123 opFormNode opform = makeOpFormNode (select,
4124 OPF_MSELECT, opFormUnion_createAnyOp (id),
4126 nameNode nn = makeNameNodeForm (opform);
4127 termNodeList args = termNodeList_new ();
4129 t->error_reported = FALSE;
4132 t->kind = TRM_APPLICATION;
4133 termNodeList_addh (args, pri);
4135 t->kind = TRM_APPLICATION;
4136 t->sort = sort_makeNoSort ();
4138 t->possibleSorts = sortSet_new ();
4139 t->possibleOps = lslOpSet_new ();
4145 makeMapTermNode (termNode pri, ltoken map, /*@dependent@*/ ltoken id)
4147 termNode t = (termNode) dmalloc (sizeof (*t));
4148 opFormNode opform = makeOpFormNode (map, OPF_MMAP, opFormUnion_createAnyOp (id),
4150 nameNode nn = makeNameNodeForm (opform);
4151 termNodeList args = termNodeList_new ();
4153 t->error_reported = FALSE;
4155 t->kind = TRM_APPLICATION;
4157 termNodeList_addh (args, pri);
4159 t->kind = TRM_APPLICATION;
4160 t->sort = sort_makeNoSort ();
4162 t->possibleSorts = sortSet_new ();
4163 t->possibleOps = lslOpSet_new ();
4168 makeLiteralTermNode (ltoken tok, sort s)
4170 nameNode nn = makeNameNodeId (ltoken_copy (tok));
4171 opInfo oi = symtable_opInfo (g_symtab, nn);
4172 lslOp op = (lslOp) dmalloc (sizeof (*op));
4173 termNode n = (termNode) dmalloc (sizeof (*n));
4178 n->error_reported = FALSE;
4180 n->kind = TRM_LITERAL;
4182 n->given = sort_makeNoSort ();
4184 n->args = termNodeList_new ();
4185 n->possibleSorts = sortSet_new ();
4186 n->possibleOps = lslOpSet_new ();
4188 /* look up signatures for this operator too */
4190 range = ltoken_create (simpleId, sort_getLsymbol (s));
4191 sign = makesigNode (ltoken_undefined, ltokenList_new (),
4192 ltoken_copy (range));
4194 if (opInfo_exists (oi) && (oi->name->isOpId)
4195 && (sigNodeSet_size (oi->signatures) > 0))
4197 sigNodeSet_elements (oi->signatures, x)
4199 if (ltokenList_empty (x->domain))
4201 lslOp opn = (lslOp) dmalloc (sizeof (*opn));
4204 opn->name = nameNode_copy (nn);
4206 sort = sigNode_rangeSort (x);
4207 (void) sortSet_insert (n->possibleSorts, sort);
4208 (void) lslOpSet_insert (n->possibleOps, opn);
4210 } end_sigNodeSet_elements;
4213 /* insert into literal term */
4214 (void) sortSet_insert (n->possibleSorts, s);
4216 op->name = nameNode_copy (nn);
4217 op->signature = sign;
4218 (void) lslOpSet_insert (n->possibleOps, op);
4220 /* enter the literal as an operator into the operator table */
4221 /* 8/9/93. C's char constant 'c' syntax conflicts
4222 with LSL's lslinit.lsi table. Throw out, because it's not
4224 /* symtable_enterOp (g_symtab, nn, sign); */
4229 lslOp opn = (lslOp) dmalloc (sizeof (*opn));
4231 /* if it is a C int, we should overload it as double too because
4232 C allows you to say "x > 2". */
4234 (void) sortSet_insert (n->possibleSorts, sort_double);
4236 ltoken_setText (range, lsymbol_fromChars ("double"));
4237 osign = makesigNode (ltoken_undefined, ltokenList_new (), range);
4238 opn->name = nameNode_copy (nn);
4239 opn->signature = osign;
4240 (void) lslOpSet_insert (n->possibleOps, opn);
4242 symtable_enterOp (g_symtab, nameNode_copySafe (nn), sigNode_copy (osign));
4246 ltoken_free (range);
4249 /* future: could overload cstrings to be both char_Vec as well as
4257 makeUnchangedTermNode1 (ltoken op, /*@unused@*/ ltoken all)
4259 termNode t = (termNode) dmalloc (sizeof (*t));
4261 t->error_reported = FALSE;
4263 t->kind = TRM_UNCHANGEDALL;
4264 t->sort = sort_bool;
4266 t->given = sort_makeNoSort ();
4267 t->name = NULL; /*< missing this >*/
4268 t->args = termNodeList_new ();
4269 t->possibleSorts = sortSet_new ();
4270 t->possibleOps = lslOpSet_new ();
4271 (void) sortSet_insert (t->possibleSorts, t->sort);
4279 makeUnchangedTermNode2 (ltoken op, storeRefNodeList x)
4281 termNode t = (termNode) dmalloc (sizeof (*t));
4285 t->name = NULL; /*< missing this >*/
4286 t->error_reported = FALSE;
4288 t->kind = TRM_UNCHANGEDOTHERS;
4289 t->sort = sort_bool;
4292 t->given = sort_makeNoSort ();
4293 t->possibleSorts = sortSet_new ();
4294 t->possibleOps = lslOpSet_new ();
4295 t->args = termNodeList_new ();
4297 (void) sortSet_insert (t->possibleSorts, t->sort);
4298 /* check storeRefNode's are mutable, uses sort of term */
4300 storeRefNodeList_elements (x, sto)
4302 if (storeRefNode_isTerm (sto))
4304 sort = sto->content.term->sort;
4305 if (!sort_mutable (sort))
4307 errtok = termNode_errorToken (sto->content.term);
4309 message ("Term denoting immutable object used in unchanged list: %q",
4310 termNode_unparse (sto->content.term)));
4315 if (storeRefNode_isType (sto))
4317 lclTypeSpecNode type = sto->content.type;
4318 sort = lclTypeSpecNode2sort (type);
4319 if (!sort_mutable (sort))
4321 errtok = lclTypeSpecNode_errorToken (type);
4322 lclerror (errtok, message ("Immutable type used in unchanged list: %q",
4323 sort_unparse (sort)));
4327 } end_storeRefNodeList_elements;
4333 makeSizeofTermNode (ltoken op, lclTypeSpecNode type)
4335 termNode t = (termNode) dmalloc (sizeof (*t));
4337 t->name = NULL; /*< missing this >*/
4338 t->error_reported = FALSE;
4340 t->kind = TRM_SIZEOF;
4343 t->sizeofField = type;
4344 t->given = sort_makeNoSort ();
4345 t->possibleSorts = sortSet_new ();
4346 t->possibleOps = lslOpSet_new ();
4347 t->args = termNodeList_new ();
4349 (void) sortSet_insert (t->possibleSorts, t->sort);
4350 /* nothing to check */
4355 claimNode_unparse (claimNode c)
4357 if (c != (claimNode) 0)
4359 cstring s = message ("claims (%q)%q{\n%q",
4360 paramNodeList_unparse (c->params),
4361 varDeclarationNodeList_unparse (c->globals),
4362 lclPredicateNode_unparse (c->require));
4364 if (c->body != NULL)
4366 s = message ("%qbody {%q}\n", s, programNode_unparse (c->body));
4368 s = message ("%q%q}\n", s, lclPredicateNode_unparse (c->ensures));
4371 return cstring_undefined;
4375 WrongArity (ltoken tok, int expect, int size)
4377 lclerror (tok, message ("Expecting %d arguments but given %d", expect, size));
4381 printTermNode2 (/*@null@*/ opFormNode op, termNodeList args, sort sort)
4383 if (op != (opFormNode) 0)
4385 cstring s = cstring_undefined;
4389 if (sort != sort_makeNoSort ())
4391 sortText = message (": %s", cstring_fromChars (lsymbol_toChars (sort_getLsymbol (sort))));
4392 sortSpace = cstring_makeLiteral (" ");
4396 sortText = cstring_undefined;
4397 sortSpace = cstring_undefined;
4404 int size = termNodeList_size (args);
4408 s = message ("if %q then %q else %q\n",
4409 termNode_unparse (termNodeList_getN (args, 0)),
4410 termNode_unparse (termNodeList_getN (args, 1)),
4411 termNode_unparse (termNodeList_getN (args, 2)));
4415 WrongArity (op->tok, 3, size);
4416 s = cstring_makeLiteral ("if __ then __ else __");
4418 s = message ("%q%s", s, sortText);
4423 s = message ("%s %s",
4424 ltoken_getRawString (op->content.anyop),
4430 int size = termNodeList_size (args);
4434 s = message ("%q ", termNode_unparse (termNodeList_head (args)));
4438 WrongArity (op->content.anyop, 1, size);
4439 s = cstring_makeLiteral ("__ ");
4441 s = message ("%q%s%s", s, ltoken_getRawString (op->content.anyop),
4447 int size = termNodeList_size (args);
4449 s = message ("%s ", ltoken_getRawString (op->content.anyop));
4453 s = message ("%q%q", s, termNode_unparse (termNodeList_head (args)));
4457 WrongArity (op->content.anyop, 1, size);
4458 s = message ("%q__", s);
4460 s = message ("%q%s", s, sortText);
4465 int size = termNodeList_size (args);
4469 s = message ("%q %s %q",
4470 termNode_unparse (termNodeList_getN (args, 0)),
4471 ltoken_getRawString (op->content.anyop),
4472 termNode_unparse (termNodeList_getN (args, 1)));
4476 WrongArity (op->content.anyop, 2, size);
4477 s = message ("__ %s __", ltoken_getRawString (op->content.anyop));
4479 s = message ("%q%s", s, sortText);
4484 int size = termNodeList_size (args);
4485 int expect = op->content.middle;
4487 /* ymtan ? use { or openSym token ? */
4491 s = message ("{%q}", termNodeList_unparse (args));
4495 WrongArity (op->tok, expect, size);
4496 s = cstring_makeLiteral ("{ * }");
4499 s = message ("%q%s", s, sortText);
4504 int size = termNodeList_size (args);
4505 int expect = op->content.middle + 1;
4509 s = message ("%q{%q}",
4510 termNode_unparse (termNodeList_head (args)),
4511 termNodeList_unparseTail (args));
4515 WrongArity (op->tok, expect, size);
4516 s = cstring_makeLiteral ("__ { * }");
4519 s = message ("%q%s", s, sortText);
4524 int size = termNodeList_size (args);
4525 int expect = op->content.middle + 1;
4529 termNodeList_finish (args);
4531 s = message ("{%q}%s%s%q",
4532 termNodeList_unparseToCurrent (args),
4533 sortText, sortSpace,
4534 termNode_unparse (termNodeList_current (args)));
4538 WrongArity (op->tok, expect, size);
4540 s = message ("{ * }%s __", sortText);
4542 /* used to put in extra space! evs 94-01-05 */
4548 int size = termNodeList_size (args);
4549 int expect = op->content.middle + 2;
4553 termNodeList_finish (args);
4555 s = message ("%q {%q} %s%s%q",
4556 termNode_unparse (termNodeList_head (args)),
4557 termNodeList_unparseSecondToCurrent (args),
4558 sortText, sortSpace,
4559 termNode_unparse (termNodeList_current (args)));
4563 WrongArity (op->tok, expect, size);
4564 s = message ("__ { * } %s __", sortText);
4566 /* also had extra space? */
4572 int size = termNodeList_size (args);
4573 int expect = op->content.middle;
4577 s = message ("[%q]", termNodeList_unparse (args));
4581 WrongArity (op->tok, expect, size);
4582 s = cstring_makeLiteral ("[ * ]");
4584 s = message ("%q%s", s, sortText);
4589 int size = termNodeList_size (args);
4590 int expect = op->content.middle + 1;
4594 s = message ("%q[%q]",
4595 termNode_unparse (termNodeList_head (args)),
4596 termNodeList_unparseTail (args));
4600 WrongArity (op->tok, expect, size);
4601 s = cstring_makeLiteral ("__ [ * ]");
4604 s = message ("%q%s", s, sortText);
4609 int size = termNodeList_size (args);
4610 int expect = op->content.middle + 1;
4614 s = message ("%q[%q] __",
4615 termNode_unparse (termNodeList_head (args)),
4616 termNodeList_unparseTail (args));
4620 WrongArity (op->tok, expect, size);
4621 s = cstring_makeLiteral ("__ [ * ] __");
4623 s = message ("%q%s", s, sortText);
4628 int size = termNodeList_size (args);
4629 int expect = op->content.middle + 1;
4633 termNodeList_finish (args);
4635 s = message ("[%q]%s%s%q",
4636 termNodeList_unparseToCurrent (args),
4637 sortText, sortSpace,
4638 termNode_unparse (termNodeList_current (args)));
4642 WrongArity (op->tok, expect, size);
4643 s = cstring_makeLiteral ("[ * ] __");
4649 { /* ymtan constant, check args ? */
4650 s = cstring_prependChar ('.', ltoken_getRawString (op->content.id));
4654 s = cstring_concat (cstring_makeLiteralTemp ("->"),
4655 ltoken_getRawString (op->content.id));
4659 int size = termNodeList_size (args);
4663 s = message ("%q.%s", termNode_unparse (termNodeList_head (args)),
4664 ltoken_getRawString (op->content.id));
4668 WrongArity (op->content.id, 1, size);
4669 s = cstring_concat (cstring_makeLiteralTemp ("__."),
4670 ltoken_getRawString (op->content.id));
4676 int size = termNodeList_size (args);
4680 s = message ("%q->%s", termNode_unparse (termNodeList_head (args)),
4681 ltoken_getRawString (op->content.id));
4685 WrongArity (op->content.id, 1, size);
4686 s = cstring_concat (cstring_makeLiteralTemp ("__->"),
4687 ltoken_getRawString (op->content.id));
4693 cstring_free (sortSpace);
4694 cstring_free (sortText);
4697 return cstring_undefined;
4701 termNode_unparse (/*@null@*/ termNode n)
4703 cstring s = cstring_undefined;
4704 cstring back = cstring_undefined;
4705 cstring front = cstring_undefined;
4708 if (n != (termNode) 0)
4710 for (count = n->wrapped; count > 0; count--)
4712 front = cstring_appendChar (front, '(');
4713 back = cstring_appendChar (back, ')');
4722 s = cstring_copy (ltoken_getRawString (n->literal));
4724 case TRM_APPLICATION:
4726 nameNode nn = n->name;
4727 if (nn != (nameNode) 0)
4731 s = message ("%s (%q) ",
4732 ltoken_getRawString (nn->content.opid),
4733 termNodeList_unparse (n->args));
4734 /* must we handle n->given ? skip for now */
4738 s = message ("%q ", printTermNode2 (nn->content.opform, n->args, n->given));
4744 (message ("termNode_unparse: expect non-empty nameNode: TRM_APPLICATION: %q",
4745 nameNode_unparse (nn)));
4749 case TRM_UNCHANGEDALL:
4750 s = cstring_makeLiteral ("unchanged (all)");
4752 case TRM_UNCHANGEDOTHERS:
4753 s = message ("unchanged (%q)", storeRefNodeList_unparse (n->unchanged));
4756 s = message ("sizeof (%q)", lclTypeSpecNode_unparse (n->sizeofField));
4758 case TRM_QUANTIFIER:
4760 quantifiedTermNode x = n->quantified;
4761 s = message ("%q%s%q%s",
4762 quantifierNodeList_unparse (x->quantifiers),
4763 ltoken_getRawString (x->open),
4764 termNode_unparse (x->body),
4765 ltoken_getRawString (x->close));
4770 return (message ("%q%q%q", front, s, back));
4773 static void modifyNode_free (/*@null@*/ /*@only@*/ modifyNode m)
4775 if (m != (modifyNode) 0)
4778 if (m->hasStoreRefList)
4780 storeRefNodeList_free (m->list);
4785 ltoken_free (m->tok);
4791 modifyNode_unparse (/*@null@*/ modifyNode m)
4793 if (m != (modifyNode) 0)
4795 if (m->hasStoreRefList)
4797 return (message (" modifies %q; \n", storeRefNodeList_unparse (m->list)));
4801 if (m->modifiesNothing)
4803 return (cstring_makeLiteral ("modifies nothing; \n"));
4807 return (cstring_makeLiteral ("modifies anything; \n"));
4811 return cstring_undefined;
4815 programNode_unparse (programNode p)
4817 if (p != (programNode) 0)
4819 cstring s = cstring_undefined;
4826 cstring back = cstring_undefined;
4828 for (count = p->wrapped; count > 0; count--)
4830 s = cstring_appendChar (s, '(');
4831 back = cstring_appendChar (back, ')');
4833 s = message ("%q%q%q", s, stmtNode_unparse (p->content.self), back);
4837 s = message ("*(%q)", programNodeList_unparse (p->content.args));
4840 s = message ("|(%q)", programNodeList_unparse (p->content.args));
4843 s = programNodeList_unparse (p->content.args);
4849 return cstring_undefined;
4853 stmtNode_unparse (stmtNode x)
4855 cstring s = cstring_undefined;
4857 if (x != (stmtNode) 0)
4859 if (ltoken_isValid (x->lhs))
4861 s = cstring_concat (ltoken_getRawString (x->lhs),
4862 cstring_makeLiteralTemp (" = "));
4865 s = message ("%q%s (%q)", s,
4866 ltoken_getRawString (x->operator),
4867 termNodeList_unparse (x->args));
4874 makelslOpNode (/*@only@*/ /*@null@*/ nameNode name,
4875 /*@dependent@*/ sigNode s)
4877 lslOp x = (lslOp) dmalloc (sizeof (*x));
4882 /* enter operator info into symtab */
4883 /* if not, they may need to be renamed in LCL imports */
4885 if (g_lslParsingTraits)
4889 symtable_enterOp (g_symtab, nameNode_copySafe (name), sigNode_copy (s));
4894 /* nameNode_free (name); */ /* YIKES! */
4901 lslOp_unparse (lslOp x)
4903 char *s = mstring_createEmpty ();
4907 s = mstring_concatFree (s, cstring_toCharsSafe (nameNode_unparse (x->name)));
4909 if (x->signature != (sigNode) 0)
4911 s = mstring_concatFree (s, cstring_toCharsSafe (sigNode_unparse (x->signature)));
4915 return cstring_fromCharsO (s);
4919 sameOpFormNode (/*@null@*/ opFormNode n1, /*@null@*/ opFormNode n2)
4930 if (n1->kind == n2->kind)
4939 return (ltoken_similar (n1->content.anyop, n2->content.anyop));
4942 /* want to treat eq and = the same */
4943 return ltoken_similar (n1->content.anyop, n2->content.anyop);
4949 /* need to check the rawText of openSym and closeSym */
4950 if ((int) n1->content.middle == (int) n2->content.middle)
4952 if (lsymbol_equal (ltoken_getRawText (n1->tok),
4953 ltoken_getRawText (n2->tok)) &&
4954 lsymbol_equal (ltoken_getRawText (n1->close),
4955 ltoken_getRawText (n2->close)))
4963 return ((int) n1->content.middle == (int) n2->content.middle);
4968 return (ltoken_similar (n1->content.id, n2->content.id));
4975 sameNameNode (/*@null@*/ nameNode n1, /*@null@*/ nameNode n2)
4979 if (n1 != (nameNode) 0 && n2 != (nameNode) 0)
4981 if (bool_equal (n1->isOpId, n2->isOpId))
4984 return (ltoken_similar (n1->content.opid, n2->content.opid));
4986 return sameOpFormNode (n1->content.opform,
4987 n2->content.opform);
4993 void CTypesNode_free (/*@only@*/ /*@null@*/ CTypesNode x)
4997 ltokenList_free (x->ctypes);
5002 /*@null@*/ CTypesNode CTypesNode_copy (/*@null@*/ CTypesNode x)
5006 CTypesNode newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5007 newnode->intfield = x->intfield;
5008 newnode->ctypes = ltokenList_copy (x->ctypes);
5009 newnode->sort = x->sort;
5019 /*@only@*/ CTypesNode
5020 makeCTypesNode (/*@only@*/ CTypesNode ctypes, ltoken ct)
5022 /*@only@*/ CTypesNode newnode;
5026 if (ctypes == (CTypesNode) NULL)
5028 newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5029 newnode->intfield = 0;
5030 newnode->ctypes = ltokenList_new ();
5031 newnode->sort = sort_makeNoSort ();
5038 if ((ltoken_getIntField (ct) & newnode->intfield) != 0)
5042 ("Duplicate type specifier ignored: %s",
5045 (lclctype_toSortDebug (ltoken_getIntField (ct))))));
5047 /* evs --- don't know how to generator this error */
5049 /* Use previous value, to keep things consistent */
5054 sortbits = newnode->intfield | ltoken_getIntField (ct);
5055 sortname = lclctype_toSort (sortbits);
5057 if (sortname == lsymbol_fromChars ("error"))
5059 lclerror (ct, cstring_makeLiteral ("Invalid combination of type specifiers"));
5063 newnode->intfield = sortbits;
5066 ltokenList_addh (newnode->ctypes, ct);
5069 ** Sorts are assigned after CTypesNode is created during parsing,
5070 ** see bison grammar.
5076 /*@only@*/ CTypesNode
5077 makeTypeSpecifier (ltoken typedefname)
5079 CTypesNode newnode = (CTypesNode) dmalloc (sizeof (*newnode));
5080 typeInfo ti = symtable_typeInfo (g_symtab, ltoken_getText (typedefname));
5082 newnode->intfield = 0;
5083 newnode->ctypes = ltokenList_singleton (ltoken_copy (typedefname));
5085 /* if we see "bool" include bool.h header file */
5087 if (ltoken_getText (typedefname) == lsymbol_bool)
5092 if (typeInfo_exists (ti))
5094 /* must we be concern about whether this type is exported by module?
5095 No. Because all typedef's are exported. No hiding supported. */
5096 /* Later, may want to keep types around too */
5097 /* 3/2/93, use underlying sort */
5098 newnode->sort = sort_getUnderlying (ti->basedOn);
5102 lclerror (typedefname, message ("Unrecognized type: %s",
5103 ltoken_getRawString (typedefname)));
5104 /* evs --- Don't know how to get this message */
5106 newnode->sort = sort_makeNoSort ();
5109 ltoken_free (typedefname);
5113 bool sigNode_equal (sigNode n1, sigNode n2)
5115 /* n1 and n2 are never 0 */
5117 return ((n1 == n2) ||
5118 (n1->key == n2->key &&
5119 ltoken_similar (n1->range, n2->range) &&
5120 ltokenList_equal (n1->domain, n2->domain)));
5124 typeExpr2ptrSort (sort base, /*@null@*/ typeExpr t)
5126 if (t != (typeExpr) 0)
5133 return typeExpr2ptrSort (sort_makePtr (ltoken_undefined, base),
5134 t->content.pointer);
5136 return typeExpr2ptrSort (sort_makeArr (ltoken_undefined, base),
5137 t->content.array.elementtype);
5139 /* map all hof types to some sort of SRT_HOF */
5140 return sort_makeHOFSort (base);
5147 typeExpr2returnSort (sort base, /*@null@*/ typeExpr t)
5149 if (t != (typeExpr) 0)
5156 return typeExpr2returnSort (sort_makePtr (ltoken_undefined, base),
5157 t->content.pointer);
5159 return typeExpr2returnSort (sort_makeArr (ltoken_undefined, base),
5160 t->content.array.elementtype);
5162 return typeExpr2returnSort (base, t->content.function.returntype);
5169 lclTypeSpecNode2sort (lclTypeSpecNode type)
5171 if (type != (lclTypeSpecNode) 0)
5176 llassert (type->content.type != NULL);
5177 return sort_makePtrN (type->content.type->sort, type->pointers);
5178 case LTS_STRUCTUNION:
5179 llassert (type->content.structorunion != NULL);
5180 return sort_makePtrN (type->content.structorunion->sort, type->pointers);
5182 llassert (type->content.enumspec != NULL);
5183 return sort_makePtrN (type->content.enumspec->sort, type->pointers);
5185 return (lclTypeSpecNode2sort (type->content.conj->a));
5188 return (sort_makeNoSort ());
5192 checkAndEnterTag (tagKind k, ltoken opttagid)
5194 /* should be tagKind, instead of int */
5196 sort sort = sort_makeNoSort ();
5198 if (!ltoken_isUndefined (opttagid))
5204 sort = sort_makeStr (opttagid);
5208 sort = sort_makeUnion (opttagid);
5211 sort = sort_makeEnum (opttagid);
5215 /* see if it is already in symbol table */
5216 t = symtable_tagInfo (g_symtab, ltoken_getText (opttagid));
5218 if (tagInfo_exists (t))
5220 if (t->kind == TAG_FWDUNION || t->kind == TAG_FWDSTRUCT)
5222 /* this is fine, for mutually recursive types */
5225 { /* this is not good, complain later */
5231 s = cstring_makeLiteral ("Enum");
5235 s = cstring_makeLiteral ("Struct");
5239 s = cstring_makeLiteral ("Union");
5246 message ("Tag redefined: %q %s", s,
5247 ltoken_getRawString (opttagid)));
5251 ltoken_free (opttagid);
5255 tagInfo newnode = (tagInfo) dmalloc (sizeof (*newnode));
5257 newnode->sort = sort;
5259 newnode->id = opttagid;
5260 newnode->imported = FALSE;
5261 newnode->content.decls = stDeclNodeList_new ();
5263 (void) symtable_enterTag (g_symtab, newnode);
5267 return sort_getLsymbol (sort);
5271 extractReturnSort (lclTypeSpecNode t, declaratorNode d)
5274 sort = lclTypeSpecNode2sort (t);
5275 sort = typeExpr2returnSort (sort, d->type);
5280 signNode_free (/*@only@*/ signNode sn)
5282 sortList_free (sn->domain);
5283 ltoken_free (sn->tok);
5288 signNode_unparse (signNode sn)
5290 cstring s = cstring_undefined;
5292 if (sn != (signNode) 0)
5294 s = message (": %q -> %s", sortList_unparse (sn->domain),
5295 sort_unparseName (sn->range));
5300 static /*@only@*/ pairNodeList
5301 globalList_toPairNodeList (globalList g)
5303 /* expect list to be globals, drop private ones */
5304 pairNodeList result = pairNodeList_new ();
5306 declaratorNode vdnode;
5307 lclTypeSpecNode type;
5310 initDeclNodeList decls;
5312 varDeclarationNodeList_elements (g, x)
5320 if (x->isGlobal && !x->isPrivate)
5325 initDeclNodeList_elements (decls, init)
5327 p = (pairNode) dmalloc (sizeof (*p));
5329 vdnode = init->declarator;
5330 sym = ltoken_getText (vdnode->id);
5331 /* 2/21/93, not sure if it should be extractReturnSort,
5332 or some call to typeExpr2ptrSort */
5333 sort = extractReturnSort (type, vdnode);
5334 p->sort = sort_makeGlobal (sort);
5335 /* if (!sort_isArrayKind (sort)) p->sort = sort_makeObj (sort);
5336 else p->sort = sort; */
5337 /* p->name = sym; */
5338 p->tok = ltoken_copy (vdnode->id);
5339 pairNodeList_addh (result, p);
5340 } end_initDeclNodeList_elements;
5343 } end_varDeclarationNodeList_elements;
5348 enteringFcnScope (lclTypeSpecNode t, declaratorNode d, globalList g)
5350 scopeInfo si = (scopeInfo) dmalloc (sizeof (*si));
5351 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5353 ltoken result = ltoken_copy (ltoken_id);
5354 pairNodeList paramPairs, globals;
5355 fctInfo fi = (fctInfo) dmalloc (sizeof (*fi));
5356 signNode sign = (signNode) dmalloc (sizeof (*sign));
5357 sortList domain = sortList_new ();
5358 unsigned long int key;
5360 paramPairs = extractParams (d->type);
5361 returnSort = extractReturnSort (t, d);
5362 globals = globalList_toPairNodeList (g);
5364 sign->tok = ltoken_undefined;
5365 sign->range = returnSort;
5367 key = MASH (0, sort_getLsymbol (returnSort));
5369 pairNodeList_elements (paramPairs, p)
5371 sortList_addh (domain, p->sort);
5372 key = MASH (key, sort_getLsymbol (p->sort));
5373 } end_pairNodeList_elements;
5375 sign->domain = domain;
5378 /* push fcn onto symbol table stack first */
5379 fi->id = ltoken_copy (d->id);
5381 fi->signature = sign;
5382 fi->globals = globals;
5384 (void) symtable_enterFct (g_symtab, fi);
5386 /* push new fcn scope */
5388 symtable_enterScope (g_symtab, si);
5390 /* add "result" with return type to current scope */
5391 ltoken_setText (result, lsymbol_fromChars ("result"));
5394 vi->sort = sort_makeFormal (returnSort); /* make appropriate values */
5395 vi->kind = VRK_PARAM;
5398 (void) symtable_enterVar (g_symtab, vi);
5402 ** pust globals first (they are in outer scope)
5405 /* push onto symbol table the global variables declared in this function,
5406 together with their respective sorts */
5408 pairNodeList_elements (globals, gl)
5410 ltoken_free (vi->id);
5411 vi->id = ltoken_copy (gl->tok);
5412 vi->kind = VRK_GLOBAL;
5413 vi->sort = gl->sort;
5414 (void) symtable_enterVar (g_symtab, vi);
5415 } end_pairNodeList_elements;
5418 ** could enter a new scope; instead, warn when variable shadows global
5423 ** push onto symbol table the formal parameters of this function,
5424 ** together with their respective sorts
5427 pairNodeList_elements (paramPairs, pair)
5429 ltoken_free (vi->id);
5430 vi->id = ltoken_copy (pair->tok);
5431 vi->sort = pair->sort;
5432 vi->kind = VRK_PARAM;
5433 (void) symtable_enterVar (g_symtab, vi);
5434 } end_pairNodeList_elements;
5436 pairNodeList_free (paramPairs);
5441 enteringClaimScope (paramNodeList params, globalList g)
5443 scopeInfo si = (scopeInfo) dmalloc (sizeof (*si));
5444 pairNodeList globals;
5445 lclTypeSpecNode paramtype;
5449 globals = globalList_toPairNodeList (g);
5450 /* push new claim scope */
5451 si->kind = SPE_CLAIM;
5453 symtable_enterScope (g_symtab, si);
5455 /* push onto symbol table the formal parameters of this function,
5456 together with their respective sorts */
5458 paramNodeList_elements (params, param)
5460 paramdecl = param->paramdecl;
5461 paramtype = param->type;
5462 if (paramdecl != (typeExpr) 0 && paramtype != (lclTypeSpecNode) 0)
5464 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5466 sort = lclTypeSpecNode2sort (paramtype);
5467 sort = sort_makeFormal (sort);
5468 vi->sort = typeExpr2ptrSort (sort, paramdecl);
5469 vi->id = ltoken_copy (extractDeclarator (paramdecl));
5470 vi->kind = VRK_PARAM;
5473 (void) symtable_enterVar (g_symtab, vi);
5476 } end_paramNodeList_elements;
5478 /* push onto symbol table the global variables declared in this function,
5479 together with their respective sorts */
5481 pairNodeList_elements (globals, g2)
5483 varInfo vi = (varInfo) dmalloc (sizeof (*vi));
5485 vi->id = ltoken_copy (g2->tok);
5486 vi->kind = VRK_GLOBAL;
5487 vi->sort = g2->sort;
5490 /* should catch duplicates in formals */
5491 (void) symtable_enterVar (g_symtab, vi);
5493 } end_pairNodeList_elements;
5495 pairNodeList_free (globals);
5496 /* should not free it here! ltoken_free (claimId); @*/
5499 static /*@only@*/ pairNodeList
5500 extractParams (/*@null@*/ typeExpr te)
5502 /* extract the parameters from a function header declarator's typeExpr */
5505 paramNodeList params;
5506 lclTypeSpecNode paramtype;
5507 pairNodeList head = pairNodeList_new ();
5510 if (te != (typeExpr) 0)
5512 params = typeExpr_toParamNodeList (te);
5513 if (paramNodeList_isDefined (params))
5515 paramNodeList_elements (params, param)
5517 paramdecl = param->paramdecl;
5518 paramtype = param->type;
5519 if (paramdecl != (typeExpr) 0 && paramtype != (lclTypeSpecNode) 0)
5521 pair = (pairNode) dmalloc (sizeof (*pair));
5522 sort = lclTypeSpecNode2sort (paramtype);
5523 /* 2/17/93, was sort_makeVal (sort) */
5524 sort = sort_makeFormal (sort);
5525 pair->sort = typeExpr2ptrSort (sort, paramdecl);
5526 /* pair->name = ltoken_getText (extractDeclarator (paramdecl)); */
5527 pair->tok = ltoken_copy (extractDeclarator (paramdecl));
5528 pairNodeList_addh (head, pair);
5530 } end_paramNodeList_elements;
5537 sigNode_rangeSort (sigNode sig)
5539 if (sig == (sigNode) 0)
5541 return sort_makeNoSort ();
5545 return sort_fromLsymbol (ltoken_getText (sig->range));
5550 sigNode_domain (sigNode sig)
5552 sortList domain = sortList_new ();
5554 if (sig == (sigNode) 0)
5560 ltokenList dom = sig->domain;
5562 ltokenList_elements (dom, tok)
5564 sortList_addh (domain, sort_fromLsymbol (ltoken_getText (tok)));
5565 } end_ltokenList_elements;
5572 opFormUnion_createAnyOp (/*@temp@*/ ltoken t)
5576 /* do not distinguish between .anyop and .id */
5582 opFormUnion_createMiddle (int middle)
5591 markYieldParamNode (paramNode p)
5595 llassert (p->type != NULL);
5596 p->type->quals = qualList_add (p->type->quals, qual_createYield ());
5601 /*@only@*/ lclTypeSpecNode
5602 lclTypeSpecNode_copySafe (lclTypeSpecNode n)
5604 lclTypeSpecNode ret = lclTypeSpecNode_copy (n);
5606 llassert (ret != NULL);
5610 /*@null@*/ /*@only@*/ lclTypeSpecNode
5611 lclTypeSpecNode_copy (/*@null@*/ lclTypeSpecNode n)
5618 return (makeLclTypeSpecNodeConj (lclTypeSpecNode_copy (n->content.conj->a),
5619 lclTypeSpecNode_copy (n->content.conj->b)));
5621 return (makeLclTypeSpecNodeType (CTypesNode_copy (n->content.type)));
5622 case LTS_STRUCTUNION:
5623 return (makeLclTypeSpecNodeSU (strOrUnionNode_copy (n->content.structorunion)));
5625 return (makeLclTypeSpecNodeEnum (enumSpecNode_copy (n->content.enumspec)));
5632 void lclTypeSpecNode_free (/*@null@*/ /*@only@*/ lclTypeSpecNode n)
5639 lclTypeSpecNode_free (n->content.conj->a);
5640 lclTypeSpecNode_free (n->content.conj->b);
5643 CTypesNode_free (n->content.type);
5645 case LTS_STRUCTUNION:
5646 strOrUnionNode_free (n->content.structorunion);
5649 enumSpecNode_free (n->content.enumspec);
5653 qualList_free (n->quals);
5658 static /*@null@*/ opFormNode opFormNode_copy (/*@null@*/ opFormNode op)
5662 opFormNode ret = (opFormNode) dmalloc (sizeof (*ret));
5664 ret->tok = ltoken_copy (op->tok);
5665 ret->kind = op->kind;
5666 ret->content = op->content;
5668 ret->close = ltoken_copy (op->close);
5678 void opFormNode_free (/*@null@*/ opFormNode op)
5682 ltoken_free (op->tok);
5683 ltoken_free (op->close);
5688 void nameNode_free (nameNode n)
5695 opFormNode_free (n->content.opform);
5703 lslOp_equal (lslOp x, lslOp y)
5706 ((x != 0) && (y != 0) &&
5707 sameNameNode (x->name, y->name) &&
5708 sigNode_equal (x->signature, y->signature)));
5711 void lslOp_free (lslOp x)
5713 nameNode_free (x->name);
5717 void sigNode_free (sigNode x)
5721 ltokenList_free (x->domain);
5722 ltoken_free (x->tok);
5723 ltoken_free (x->range);
5728 void declaratorNode_free (/*@null@*/ /*@only@*/ declaratorNode x)
5732 typeExpr_free (x->type);
5733 ltoken_free (x->id);
5738 void abstBodyNode_free (/*@null@*/ /*@only@*/ abstBodyNode n)
5742 lclPredicateNode_free (n->typeinv);
5743 fcnNodeList_free (n->fcns);
5744 ltoken_free (n->tok);
5749 void fcnNode_free (/*@null@*/ /*@only@*/ fcnNode f)
5753 lclTypeSpecNode_free (f->typespec);
5754 declaratorNode_free (f->declarator);
5755 globalList_free (f->globals);
5756 varDeclarationNodeList_free (f->inits);
5757 letDeclNodeList_free (f->lets);
5758 lclPredicateNode_free (f->checks);
5759 lclPredicateNode_free (f->require);
5760 lclPredicateNode_free (f->claim);
5761 lclPredicateNode_free (f->ensures);
5762 modifyNode_free (f->modify);
5763 ltoken_free (f->name);
5768 void declaratorInvNode_free (/*@null@*/ /*@only@*/ declaratorInvNode x)
5772 declaratorNode_free (x->declarator);
5773 abstBodyNode_free (x->body);
5778 /*@only@*/ lslOp lslOp_copy (lslOp x)
5780 return (makelslOpNode (nameNode_copy (x->name), x->signature));
5783 sigNode sigNode_copy (sigNode s)
5785 llassert (s != NULL);
5786 return (makesigNode (ltoken_copy (s->tok),
5787 ltokenList_copy (s->domain),
5788 ltoken_copy (s->range)));
5791 /*@null@*/ nameNode nameNode_copy (/*@null@*/ nameNode n)
5793 if (n == NULL) return NULL;
5794 return nameNode_copySafe (n);
5797 nameNode nameNode_copySafe (nameNode n)
5801 return (makeNameNodeId (ltoken_copy (n->content.opid)));
5805 /* error should be detected by splint: forgot to copy opform! */
5806 return (makeNameNodeForm (opFormNode_copy (n->content.opform)));
5810 bool initDeclNode_isRedeclaration (initDeclNode d)
5812 return (d->declarator->isRedecl);
5815 void termNode_free (/*@only@*/ /*@null@*/ termNode t)
5819 sortSet_free (t->possibleSorts);
5820 lslOpSet_free (t->possibleOps);
5821 nameNode_free (t->name);
5822 termNodeList_free (t->args);
5827 /*@only@*/ termNode termNode_copySafe (termNode t)
5829 termNode ret = termNode_copy (t);
5831 llassert (ret != NULL);
5835 /*@null@*/ /*@only@*/ termNode termNode_copy (/*@null@*/ termNode t)
5839 termNode ret = (termNode) dmalloc (sizeof (*ret));
5841 ret->wrapped = t->wrapped;
5842 ret->kind = t->kind;
5843 ret->sort = t->sort;
5844 ret->given = t->given;
5845 ret->possibleSorts = sortSet_copy (t->possibleSorts);
5846 ret->error_reported = t->error_reported;
5847 ret->possibleOps = lslOpSet_copy (t->possibleOps);
5848 ret->name = nameNode_copy (t->name);
5849 ret->args = termNodeList_copy (t->args);
5851 if (t->kind == TRM_LITERAL
5852 || t->kind == TRM_SIZEOF
5853 || t->kind == TRM_VAR
5854 || t->kind == TRM_CONST
5855 || t->kind == TRM_ZEROARY)
5857 ret->literal = ltoken_copy (t->literal);
5860 if (t->kind == TRM_UNCHANGEDOTHERS)
5862 ret->unchanged = storeRefNodeList_copy (t->unchanged);
5865 if (t->kind == TRM_QUANTIFIER)
5867 ret->quantified = quantifiedTermNode_copy (t->quantified);
5870 if (t->kind == TRM_SIZEOF)
5872 ret->sizeofField = lclTypeSpecNode_copySafe (t->sizeofField);
5884 void importNode_free (/*@only@*/ /*@null@*/ importNode x)
5888 ltoken_free (x->val);
5893 void initDeclNode_free (/*@only@*/ /*@null@*/ initDeclNode x)
5897 declaratorNode_free (x->declarator);
5898 termNode_free (x->value);
5903 void letDeclNode_free (/*@only@*/ /*@null@*/ letDeclNode x)
5907 lclTypeSpecNode_free (x->sortspec);
5908 termNode_free (x->term);
5909 ltoken_free (x->varid);
5914 void pairNode_free (/*@only@*/ /*@null@*/ pairNode x)
5918 ltoken_free (x->tok);
5923 /*@null@*/ paramNode paramNode_copy (/*@null@*/ paramNode p)
5927 paramNode ret = (paramNode) dmalloc (sizeof (*ret));
5929 ret->type = lclTypeSpecNode_copy (p->type);
5930 ret->paramdecl = typeExpr_copy (p->paramdecl);
5931 ret->kind = p->kind;
5938 void paramNode_free (/*@only@*/ /*@null@*/ paramNode x)
5942 lclTypeSpecNode_free (x->type);
5943 typeExpr_free (x->paramdecl);
5948 void programNode_free (/*@only@*/ /*@null@*/ programNode x)
5954 case ACT_SELF: stmtNode_free (x->content.self); break;
5957 case ACT_SEQUENCE: programNodeList_free (x->content.args); break;
5964 quantifierNode quantifierNode_copy (quantifierNode x)
5966 quantifierNode ret = (quantifierNode) dmalloc (sizeof (*ret));
5968 ret->quant = ltoken_copy (x->quant);
5969 ret->vars = varNodeList_copy (x->vars);
5970 ret->isForall = x->isForall;
5975 void quantifierNode_free (/*@null@*/ /*@only@*/ quantifierNode x)
5979 varNodeList_free (x->vars);
5980 ltoken_free (x->quant);
5985 void replaceNode_free (/*@only@*/ /*@null@*/ replaceNode x)
5995 nameNode_free (x->content.renamesortname.name);
5996 sigNode_free (x->content.renamesortname.signature);
5999 typeNameNode_free (x->typename);
6000 ltoken_free (x->tok);
6005 storeRefNode storeRefNode_copy (storeRefNode x)
6007 storeRefNode ret = (storeRefNode) dmalloc (sizeof (*ret));
6009 ret->kind = x->kind;
6014 ret->content.term = termNode_copySafe (x->content.term);
6016 case SRN_OBJ: case SRN_TYPE:
6017 ret->content.type = lclTypeSpecNode_copy (x->content.type);
6020 ret->content.ref = sRef_copy (x->content.ref);
6027 void storeRefNode_free (/*@only@*/ /*@null@*/ storeRefNode x)
6031 if (storeRefNode_isTerm (x))
6033 termNode_free (x->content.term);
6035 else if (storeRefNode_isType (x) || storeRefNode_isObj (x))
6037 lclTypeSpecNode_free (x->content.type);
6041 /* nothing to free */
6048 stDeclNode stDeclNode_copy (stDeclNode x)
6050 stDeclNode ret = (stDeclNode) dmalloc (sizeof (*ret));
6052 ret->lcltypespec = lclTypeSpecNode_copySafe (x->lcltypespec);
6053 ret->declarators = declaratorNodeList_copy (x->declarators);
6058 void stDeclNode_free (/*@only@*/ /*@null@*/ stDeclNode x)
6062 lclTypeSpecNode_free (x->lcltypespec);
6063 declaratorNodeList_free (x->declarators);
6068 void traitRefNode_free (/*@only@*/ /*@null@*/ traitRefNode x)
6072 ltokenList_free (x->traitid);
6073 renamingNode_free (x->rename);
6078 void typeNameNode_free (/*@only@*/ /*@null@*/ typeNameNode n)
6082 typeNamePack_free (n->typename);
6083 opFormNode_free (n->opform);
6088 void varDeclarationNode_free (/*@only@*/ /*@null@*/ varDeclarationNode x)
6098 lclTypeSpecNode_free (x->type);
6099 initDeclNodeList_free (x->decls);
6105 varNode varNode_copy (varNode x)
6107 varNode ret = (varNode) dmalloc (sizeof (*ret));
6109 ret->varid = ltoken_copy (x->varid);
6110 ret->isObj = x->isObj;
6111 ret->type = lclTypeSpecNode_copySafe (x->type);
6112 ret->sort = x->sort;
6117 void varNode_free (/*@only@*/ /*@null@*/ varNode x)
6121 lclTypeSpecNode_free (x->type);
6122 ltoken_free (x->varid);
6127 void stmtNode_free (/*@only@*/ /*@null@*/ stmtNode x)
6131 ltoken_free (x->lhs);
6132 termNodeList_free (x->args);
6133 ltoken_free (x->operator);
6138 void renamingNode_free (/*@only@*/ /*@null@*/ renamingNode x)
6144 replaceNodeList_free (x->content.replace);
6148 nameAndReplaceNode_free (x->content.name);
6155 void nameAndReplaceNode_free (/*@only@*/ /*@null@*/ nameAndReplaceNode x)
6159 typeNameNodeList_free (x->namelist);
6160 replaceNodeList_free (x->replacelist);
6165 void typeNamePack_free (/*@only@*/ /*@null@*/ typeNamePack x)
6169 lclTypeSpecNode_free (x->type);
6170 abstDeclaratorNode_free (x->abst);
6175 cstring interfaceNode_unparse (interfaceNode x)
6182 return (message ("[imports] %q", importNodeList_unparse (x->content.imports)));
6184 return (message ("[uses] %q", traitRefNodeList_unparse (x->content.uses)));
6186 return (message ("[export] %q", exportNode_unparse (x->content.export)));
6188 return (message ("[private] %q", privateNode_unparse (x->content.private)));
6195 return (cstring_makeLiteral ("<interface node undefined>"));
6198 BADBRANCHRET (cstring_undefined);
6201 void interfaceNode_free (/*@null@*/ /*@only@*/ interfaceNode x)
6208 case INF_IMPORTS: importNodeList_free (x->content.imports); break;
6209 case INF_USES: traitRefNodeList_free (x->content.uses); break;
6210 case INF_EXPORT: exportNode_free (x->content.export); break;
6211 case INF_PRIVATE: privateNode_free (x->content.private); break;
6217 void exportNode_free (/*@null@*/ /*@only@*/ exportNode x)
6223 case XPK_CONST: constDeclarationNode_free (x->content.constdeclaration); break;
6224 case XPK_VAR: varDeclarationNode_free (x->content.vardeclaration); break;
6225 case XPK_TYPE: typeNode_free (x->content.type); break;
6226 case XPK_FCN: fcnNode_free (x->content.fcn); break;
6227 case XPK_CLAIM: claimNode_free (x->content.claim); break;
6228 case XPK_ITER: iterNode_free (x->content.iter); break;
6235 void privateNode_free (/*@null@*/ /*@only@*/ privateNode x)
6242 constDeclarationNode_free (x->content.constdeclaration); break;
6244 varDeclarationNode_free (x->content.vardeclaration); break;
6246 typeNode_free (x->content.type); break;
6248 fcnNode_free (x->content.fcn); break;
6255 void constDeclarationNode_free (/*@only@*/ /*@null@*/ constDeclarationNode x)
6259 lclTypeSpecNode_free (x->type);
6260 initDeclNodeList_free (x->decls);
6265 void typeNode_free (/*@only@*/ /*@null@*/ typeNode t)
6271 case TK_ABSTRACT: abstractNode_free (t->content.abstract); break;
6272 case TK_EXPOSED: exposedNode_free (t->content.exposed); break;
6273 case TK_UNION: taggedUnionNode_free (t->content.taggedunion); break;
6280 void claimNode_free (/*@only@*/ /*@null@*/ claimNode x)
6284 paramNodeList_free (x->params);
6285 globalList_free (x->globals);
6286 letDeclNodeList_free (x->lets);
6287 lclPredicateNode_free (x->require);
6288 programNode_free (x->body);
6289 lclPredicateNode_free (x->ensures);
6290 ltoken_free (x->name);
6295 void iterNode_free (/*@only@*/ /*@null@*/ iterNode x)
6299 paramNodeList_free (x->params);
6300 ltoken_free (x->name);
6305 void abstractNode_free (/*@only@*/ /*@null@*/ abstractNode x)
6309 abstBodyNode_free (x->body);
6310 ltoken_free (x->tok);
6311 ltoken_free (x->name);
6316 void exposedNode_free (/*@only@*/ /*@null@*/ exposedNode x)
6320 lclTypeSpecNode_free (x->type);
6321 declaratorInvNodeList_free (x->decls);
6322 ltoken_free (x->tok);
6327 void taggedUnionNode_free (/*@only@*/ /*@null@*/ taggedUnionNode x)
6331 stDeclNodeList_free (x->structdecls);
6332 declaratorNode_free (x->declarator);
6337 /*@only@*/ /*@null@*/ strOrUnionNode
6338 strOrUnionNode_copy (/*@null@*/ strOrUnionNode n)
6342 strOrUnionNode ret = (strOrUnionNode) dmalloc (sizeof (*ret));
6344 ret->kind = n->kind;
6345 ret->tok = ltoken_copy (n->tok);
6346 ret->opttagid = ltoken_copy (n->opttagid);
6347 ret->sort = n->sort;
6348 ret->structdecls = stDeclNodeList_copy (n->structdecls);
6358 void strOrUnionNode_free (/*@null@*/ /*@only@*/ strOrUnionNode n)
6362 stDeclNodeList_free (n->structdecls);
6363 ltoken_free (n->tok);
6364 ltoken_free (n->opttagid);
6369 void enumSpecNode_free (/*@null@*/ /*@only@*/ enumSpecNode x)
6373 ltokenList_free (x->enums);
6374 ltoken_free (x->tok);
6375 ltoken_free (x->opttagid);
6380 /*@only@*/ /*@null@*/ enumSpecNode enumSpecNode_copy (/*@null@*/ enumSpecNode x)
6384 enumSpecNode ret = (enumSpecNode) dmalloc (sizeof (*ret));
6386 ret->tok = ltoken_copy (x->tok);
6387 ret->opttagid = ltoken_copy (x->opttagid);
6388 ret->enums = ltokenList_copy (x->enums);
6389 ret->sort = x->sort;
6399 void lsymbol_setbool (lsymbol s)
6404 lsymbol lsymbol_getbool ()
6406 return lsymbol_bool;
6409 lsymbol lsymbol_getBool ()
6411 return lsymbol_Bool;
6414 lsymbol lsymbol_getFALSE ()
6416 return lsymbol_FALSE;
6419 lsymbol lsymbol_getTRUE ()
6421 return lsymbol_TRUE;