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
25 ** cscannerHelp.c - procedures for scanning C
27 ** Most of this code was in cscanner.l, but moved here to separate it
28 ** from the flex-generated code.
31 # include "splintMacros.nf"
33 # include "cscannerHelp.h"
34 # include "cscanner.h"
35 # include "cgrammar_tokens.h"
37 static int lminput (void);
38 static int s_tokLength = 0;
40 static /*@owned@*/ cstring s_lastidprocessed = cstring_undefined;
41 static bool s_inSpecPart = FALSE;
42 static int s_whichSpecPart;
43 static char s_savechar = '\0';
44 static bool s_expectingMetaStateName = FALSE;
45 static bool s_lastWasString = FALSE;
46 static bool s_expectingTypeName = TRUE;
50 /*@null@*/ /*@observer@*/ char *name;
55 ** These tokens are followed by syntax that is parsed by the
59 static struct skeyword s_parsetable[] = {
60 { "modifies", QMODIFIES } ,
61 { "globals", QGLOBALS } ,
64 { "constant", QCONSTANT } ,
65 { "function", QFUNCTION } ,
67 { "defines", QDEFINES } ,
69 { "allocates", QALLOCATES } ,
71 { "releases", QRELEASES } ,
72 { "pre", QPRECLAUSE } ,
73 { "post", QPOSTCLAUSE } ,
74 { "setBufferSize", QSETBUFFERSIZE},
75 { "setStringLength", QSETSTRINGLENGTH},
76 { "testinRange", QTESTINRANGE},
77 { "requires", QPRECLAUSE } ,
78 { "ensures", QPOSTCLAUSE } ,
79 { "invariant", QINVARIANT} ,
84 ** These tokens are either stand-alone tokens, or followed by
85 ** token-specific text.
88 static struct skeyword s_keytable[] = {
89 { "anytype", QANYTYPE } ,
90 { "integraltype", QINTEGRALTYPE } ,
91 { "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
92 { "signedintegraltype", QSIGNEDINTEGRALTYPE } ,
97 { "dependent", QDEPENDENT } ,
98 { "partial", QPARTIAL } ,
99 { "special", QSPECIAL } ,
100 { "truenull", QTRUENULL } ,
101 { "falsenull", QFALSENULL } ,
102 { "nullwhentrue", QTRUENULL } ,
103 { "falsewhennull", QFALSENULL } ,
106 { "notnull", QNOTNULL } ,
107 { "abstract", QABSTRACT } ,
108 { "numabstract", QNUMABSTRACT } ,
109 { "concrete", QCONCRETE } ,
110 { "mutable", QMUTABLE } ,
111 { "immutable", QIMMUTABLE } ,
112 { "unused", QUNUSED } ,
113 { "external", QEXTERNAL } ,
115 { "unique", QUNIQUE } ,
116 { "returned", QRETURNED } ,
117 { "exposed", QEXPOSED } ,
118 { "refcounted", QREFCOUNTED } ,
120 { "newref", QNEWREF } ,
121 { "tempref", QTEMPREF } ,
122 { "killref", QKILLREF } ,
124 { "relnull", QRELNULL } ,
125 { "nullterminated", QNULLTERMINATED },
126 { "setBufferSize", QSETBUFFERSIZE },
127 { "testInRange", QTESTINRANGE},
128 { "isnull", QISNULL },
129 { "MaxSet", QMAXSET},
130 { "MaxRead", QMAXREAD},
131 { "maxSet", QMAXSET},
132 { "maxRead", QMAXREAD},
133 { "reldef", QRELDEF } ,
134 { "observer", QOBSERVER } ,
135 { "exits", QEXITS } ,
136 { "noreturn", QEXITS } ,
137 { "mayexit", QMAYEXIT } ,
138 { "maynotreturn", QMAYEXIT } ,
139 { "trueexit", QTRUEEXIT } ,
140 { "falseexit", QFALSEEXIT } ,
141 { "noreturnwhentrue", QTRUEEXIT } ,
142 { "noreturnwhenfalse", QFALSEEXIT } ,
143 { "neverexit", QNEVEREXIT } ,
144 { "alwaysreturns", QNEVEREXIT } ,
146 { "shared", QSHARED } ,
148 { "unchecked", QUNCHECKED } ,
149 { "checked", QCHECKED } ,
150 { "checkmod", QCHECKMOD } ,
151 { "checkedstrict", QCHECKEDSTRICT } ,
152 { "innercontinue", QINNERCONTINUE } ,
153 { "innerbreak", QINNERBREAK } ,
154 { "loopbreak", QLOOPBREAK } ,
155 { "switchbreak", QSWITCHBREAK } ,
156 { "safebreak", QSAFEBREAK } ,
157 { "fallthrough", QFALLTHROUGH } ,
158 { "l_fallthrou", QLINTFALLTHROUGH } ,
159 { "l_fallth", QLINTFALLTHRU } ,
160 { "notreached", QNOTREACHED } ,
161 { "l_notreach", QLINTNOTREACHED } ,
162 { "printflike", QPRINTFLIKE } ,
163 { "l_printfli", QLINTPRINTFLIKE } ,
164 { "scanflike", QSCANFLIKE } ,
165 { "messagelike", QMESSAGELIKE } ,
166 { "l_argsus", QARGSUSED } ,
171 ** would be better if these weren't hard coded...
174 static bool isArtificial (cstring s)
176 return (cstring_equalLit (s, "modifies")
177 || cstring_equalLit (s, "globals")
178 || cstring_equalLit (s, "warn")
179 || cstring_equalLit (s, "alt"));
182 void cscannerHelp_swallowMacro (void)
185 bool skipnext = FALSE;
187 while ((i = lminput ()) != EOF)
203 reader_checkUngetc (i, yyin);
215 reader_checkUngetc (i, yyin);
219 static int commentMarkerToken (cstring s)
223 while (s_parsetable[i].name != NULL)
225 DPRINTF (("Try :%s:%s:", s, s_parsetable[i].name));
227 if (cstring_equalLit (s, s_parsetable[i].name))
229 return s_parsetable[i].token;
238 static int tokenMacroCode (cstring s)
242 while (s_keytable[i].name != NULL)
244 if (cstring_equalLit (s, s_keytable[i].name))
246 if (s_keytable[i].token == QLINTFALLTHROUGH)
249 (FLG_WARNLINTCOMMENTS,
251 ("Traditional lint comment /*FALLTHROUGH*/ used. "
252 "Splint interprets this in the same way as most Unix lints, but it is "
253 "preferable to replace it with the /*@fallthrough@*/ "
258 else if (s_keytable[i].token == QLINTFALLTHRU)
261 (FLG_WARNLINTCOMMENTS,
263 ("Traditional lint comment /*FALLTHRU*/ used. "
264 "Splint interprets this in the same way as most Unix lints, but it is "
265 "preferable to replace it with the /*@fallthrough@*/ "
270 else if (s_keytable[i].token == QLINTNOTREACHED)
273 (FLG_WARNLINTCOMMENTS,
275 ("Traditional lint comment /*NOTREACHED*/ used. "
276 "Splint interprets this in the same way as most Unix lints, but it is "
277 "preferable to replace it with the /*@notreached@*/ "
278 "semantic comment."),
283 else if (s_keytable[i].token == QPRINTFLIKE)
285 setSpecialFunction (qual_createPrintfLike ());
288 else if (s_keytable[i].token == QLINTPRINTFLIKE)
291 (FLG_WARNLINTCOMMENTS,
293 ("Traditional lint comment /*PRINTFLIKE*/ used. "
294 "Splint interprets this in the same way as most Unix lints, but it is "
295 "preferable to replace it with either /*@printflike@*/, "
296 "/*@scanflike@*/ or /*@messagelike@*/."),
299 setSpecialFunction (qual_createPrintfLike ());
302 else if (s_keytable[i].token == QSCANFLIKE)
304 setSpecialFunction (qual_createScanfLike ());
307 else if (s_keytable[i].token == QMESSAGELIKE)
309 setSpecialFunction (qual_createMessageLike ());
312 else if (s_keytable[i].token == QARGSUSED)
315 (FLG_WARNLINTCOMMENTS,
317 ("Traditional lint comment /*ARGSUSED*/ used. "
318 "Splint interprets this in the same way as most Unix lints, but it is "
319 "preferable to use /*@unused@*/ annotations on "
320 "the unused parameters."),
328 return s_keytable[i].token;
338 static int lminput ()
340 if (s_savechar == '\0')
343 return (cscanner_input ());
347 int save = (int) s_savechar;
353 static void lmsavechar (char c)
355 if (s_savechar == '\0')
361 llbuglit ("lmsavechar: override");
365 int cscannerHelp_ninput ()
369 if (c != EOF && ((char)c == '\n'))
371 context_incLineno ();
377 static char macro_nextChar (void)
379 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
384 c = char_fromInt (ic);
386 if (!in_quote && !in_char && (c == '\\' || c == BEFORE_COMMENT_MARKER[0]))
390 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
392 ; /* skip to newline */
395 context_incLineno ();
399 return macro_nextChar ();
406 else /* if (c == '@') */
410 if (cscannerHelp_handleLlSpecial () != BADTOK)
412 llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
415 return macro_nextChar ();
418 else if (!in_escape && c == '\"')
420 in_quote = !in_quote;
422 else if (!in_escape && c == '\'')
426 else if ((in_quote || in_char) && c == '\\')
428 in_escape = !in_escape;
430 else if ((in_quote || in_char) && in_escape)
434 else if (!in_quote && c == '/')
438 if ((c2 = char_fromInt (lminput ())) == '*')
442 while ((c2 = char_fromInt (lminput ())) != '\0'
443 && c2 != '\n' && c2 != '*')
450 while ((c2 = char_fromInt (lminput ())) != '\0'
463 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
467 return macro_nextChar ();
471 /*** putchar does not work! why? puts to stdio...??! ***/
484 ** keeps semantic comments
487 static char macro_nextCharC (void)
489 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
492 c = char_fromInt (lminput ());
494 if (!in_quote && !in_char && c == '\\')
496 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
498 ; /* skip to newline */
501 context_incLineno ();
505 return macro_nextCharC ();
512 else if (!in_escape && c == '\"')
514 in_quote = !in_quote;
516 else if (!in_escape && c == '\'')
520 else if ((in_quote || in_char) && c == '\\')
522 in_escape = !in_escape;
524 else if ((in_quote || in_char) && in_escape)
528 else if (!in_quote && c == '/')
532 if ((c2 = char_fromInt (lminput ())) == '*')
536 while ((c2 = char_fromInt (lminput ())) != '\0'
537 && c2 != '\n' && c2 != '*')
544 while ((c2 = char_fromInt (lminput ())) != '\0'
557 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
561 return macro_nextCharC ();
568 else /* normal character */
577 ** skips whitespace (handles line continuations)
578 ** returns first non-whitespace character
581 static char skip_whitespace (void)
585 while ((c = macro_nextChar ()) == ' ' || c == '\t')
593 void cscannerHelp_handleMacro ()
595 cstring mac = cstring_undefined;
599 while (currentColumn () > 2)
601 mac = cstring_appendChar (mac, ' ');
602 cscannerHelp_setTokLength (-1);
605 c = macro_nextCharC ();
607 if (c >= '0' && c <= '9')
611 for (i = 0; i < (((int) (c - '0')) + 1); i++)
613 mac = cstring_appendChar (mac, ' ');
621 while (((c = macro_nextCharC ()) != '\0') && (c != '\n'))
623 mac = cstring_appendChar (mac, c);
627 macrocode = tokenMacroCode (mac);
629 if (macrocode == BADTOK && !isArtificial (mac))
631 context_addMacroCache (mac);
640 context_incLineno ();
644 bool cscannerHelp_handleSpecial (char *yyt)
646 char *l; /* !! = mstring_create (MAX_NAME_LENGTH); */
653 len_yyt = strlen (yyt +1) ;
655 l = mstring_copy (yyt + 1);
657 while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
659 l = mstring_append(l, c);
662 /* Need to safe original l for deallocating. */
667 olc = cstring_fromChars (ol);
669 if (cstring_equalPrefixLit (olc, "pragma"))
671 char *pname = mstring_create (size_fromInt (MAX_PRAGMA_LEN));
672 char *opname = pname;
673 char *ptr = ol + 6; /* pragma is six characters, plus space */
677 /* skip whitespace */
678 while (((c = *ptr) != '\0') && isspace (c))
684 while (((c = *ptr) != '\0') && !isspace (c))
688 if (len > MAX_PRAGMA_LEN)
699 if (len == PRAGMA_LEN_EXPAND
700 && mstring_equal (opname, PRAGMA_EXPAND))
702 cstring exname = cstring_undefined;
706 while (((c = *ptr) != '\0') && !isspace (c))
708 exname = cstring_appendChar (exname, c);
713 ue = usymtab_lookupExposeGlob (exname);
715 if (uentry_isExpandedMacro (ue))
717 if (fileloc_isPreproc (uentry_whereDefined (ue)))
719 fileloc_setColumn (g_currentloc, 1);
720 uentry_setDefined (ue, g_currentloc);
724 cstring_free (exname);
727 else if (cstring_equalPrefixLit (olc, "ident"))
729 /* Some pre-processors will leave these in the code. Ignore rest of line */
732 ** Yuk...Win32 filenames can have spaces in them...we need to read
733 ** to the matching end quote.
735 else if ((sscanf (ol, "line %d \"", &lineno) == 1)
736 || (sscanf (ol, " %d \"", &lineno) == 1))
743 while (*tmp != '\"' && *tmp != '\0')
748 llassert (*tmp == '\"');
754 while (*tmp != '\"' && *tmp != '\0')
759 llassert (*tmp == '\"');
763 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
766 ** DOS-like path delimiters get delivered in pairs, something like
767 ** \"..\\\\file.h\", so we have to make it normal again. We do NOT
768 ** remove the pre dirs yet as we usually specify tmp paths relative
769 ** to the current directory, so tmp files would not get found in
770 ** the hash table. If this method fails we try it again later.
777 ** Skip past the drive marker.
780 if (strchr (stmp, ':') != NULL)
782 stmp = strchr (stmp, ':') + 1;
785 while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
787 if (*(stmp+1) == CONNECTCHAR)
789 memmove (stmp, stmp+1, strlen (stmp));
795 fid = fileTable_lookupBase (context_fileTable (), fname);
796 if (!(fileId_isValid (fid)))
798 fname = removePreDirs (fname);
799 fid = fileTable_lookupBase (context_fileTable (), fname);
802 # else /* !defined(OS2) && !defined(MSDOS) */
803 fname = removePreDirs (fname);
804 fid = fileTable_lookupBase (context_fileTable (), fname);
805 # endif /* !defined(OS2) && !defined(MSDOS) */
807 if (!(fileId_isValid (fid)))
809 if (context_inXHFile ())
811 fid = fileTable_addXHFile (context_fileTable (), fname);
813 else if (isHeaderFile (fname))
815 fid = fileTable_addHeaderFile (context_fileTable (), fname);
819 fid = fileTable_addFile (context_fileTable (), fname);
823 setFileLine (fid, lineno);
824 /*@noaccess cstring@*/
826 else if ((sscanf (ol, "line %d", &lineno) == 1)
827 || (sscanf (ol, " %d", &lineno) == 1))
829 setLine (lineno); /* next line is <cr> */
833 if (mstring_equal (ol, "")) {
834 DPRINTF (("Empty pp command!"));
836 ** evs 2000-05-16: This is a horrible kludge, to get around a bug (well, difficulty) in the pre-processor.
837 ** We handle a plain # in the input file, by echoing it, and ignoring it in the post-pp-file.
843 (FLG_UNRECOGDIRECTIVE,
844 message ("Unrecognized pre-processor directive: #%s",
845 cstring_fromChars (ol)),
850 return FALSE; /* evans 2001-12-30: was: TRUE; */
857 int cscannerHelp_handleLlSpecial (void)
862 char *s = mstring_createEmpty ();
868 loc = fileloc_copy (g_currentloc);
869 DPRINTF (("Handle special: %s", fileloc_unparse (loc)));
871 while (((ic = cscannerHelp_ninput ()) != 0) && isalpha (ic))
874 s = mstring_append (s, c);
878 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
881 if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
883 ic = cscannerHelp_ninput ();
885 llassert (ic == (int) AFTER_COMMENT_MARKER[1]);
891 return QNOMODS; /* special token no modifications token */
895 DPRINTF (("Coment marker: %s", os));
896 tok = commentMarkerToken (cstring_fromChars (os));
900 s_tokLength = charsread;
903 s_whichSpecPart = tok;
908 DPRINTF (("Not a comment marker..."));
909 /* Add rest of the comment */
911 if (ic != 0 && ic != EOF)
915 s = mstring_append (s, c);
918 while (((ic = cscannerHelp_ninput ()) != 0) && (ic != EOF)
919 && (ic != (int) AFTER_COMMENT_MARKER[0]))
923 /* evans 2001-09-01 added to prevent assertion failures for uncloses syntactic comments */
926 hasnl = TRUE; /* This prevents tokLength from being set later. */
931 message ("Likely parse error: syntactic comment token spans multiple lines: %s",
932 cstring_fromChars (s)),
936 s = mstring_append (s, c);
940 } /* spurious (?) warnings about s */
943 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
945 if (ic == (int) AFTER_COMMENT_MARKER[0])
947 int nc = cscannerHelp_ninput ();
948 llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
954 while (*s == ' ' || *s == '\t' || *s == '\n')
959 if (*s == '-' || *s == '+' || *s == '=') /* setting flags */
963 while (c == '-' || c == '+' || c == '=')
965 ynm set = ynm_fromCodeChar (c);
970 thisflag = cstring_fromChars (s);
972 while ((c = *s) != '\0' && (c != '-') && (c != '=')
973 && (c != '+') && (c != ' ') && (c != '\t') && (c != '\n'))
980 if (!context_getFlag (FLG_NOCOMMENTS))
982 cstring flagname = thisflag;
983 flagcode fflag = flags_identifyFlag (flagname);
985 if (flagcode_isSkip (fflag))
989 else if (flagcode_isModeName (fflag))
991 if (ynm_isMaybe (set))
996 ("Semantic comment attempts to restore flag %s. "
997 "A mode flag cannot be restored.",
1002 context_setMode (flagname);
1005 else if (flagcode_isInvalid (fflag))
1008 (FLG_UNRECOGFLAGCOMMENTS,
1009 message ("Unrecognized option in semantic comment: %s",
1013 else if (flagcode_isGlobalFlag (fflag))
1018 ("Semantic comment attempts to set global flag %s. "
1019 "A global flag cannot be set locally.",
1025 context_fileSetFlag (fflag, set, loc);
1027 if (flagcode_hasArgument (fflag))
1029 if (ynm_isMaybe (set))
1034 ("Semantic comment attempts to restore flag %s. "
1035 "A flag for setting a value cannot be restored.",
1040 { /* cut-and-pastied from llmain...blecch */
1041 cstring extra = cstring_undefined;
1047 rest = mstring_copy (s);
1051 while ((rchar = *rest) != '\0'
1052 && (isspace (rchar)))
1058 while ((rchar = *rest) != '\0'
1059 && !isspace (rchar))
1061 extra = cstring_appendChar (extra, rchar);
1065 s--; /* evans 2002-07-12: this was previously only in the else branch.
1066 Leads to an invalid read on the true branch.
1071 if (cstring_isUndefined (extra))
1076 ("Flag %s (in semantic comment) must be followed by an argument",
1077 flagcode_unparse (fflag)));
1079 cstring_free (extra);
1083 if (flagcode_hasNumber (fflag))
1085 flags_setValueFlag (fflag, extra);
1087 else if (flagcode_hasChar (fflag))
1089 flags_setValueFlag (fflag, extra);
1091 else if (flagcode_hasString (fflag))
1093 flags_setStringFlag (fflag, extra);
1097 cstring_free (extra);
1111 while ((c == ' ') || (c == '\t') || (c == '\n'))
1117 if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
1119 DPRINTF (("Here adding comment: %s", os));
1120 context_addComment (cstring_fromCharsNew (os), loc);
1132 annotationInfo ainfo;
1134 while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
1146 t = cstring_toCharsSafe (cstring_downcase (cstring_fromChars (t)));
1147 macrocode = tokenMacroCode (cstring_fromChars (t));
1149 if (macrocode != BADTOK)
1151 s_tokLength = hasnl ? 0 : size_toInt (mstring_length (t));
1157 if (macrocode == SKIPTOK)
1165 ainfo = context_lookupAnnotation (cstring_fromChars (os));
1167 if (annotationInfo_isDefined (ainfo)) {
1168 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
1169 yylval.annotation = ainfo;
1177 if (context_inHeader ())
1184 if ((context_inMacro () || context_inGlobalContext ())
1185 && macrocode != SKIPTOK
1186 && !isArtificial (cstring_fromChars (os)))
1188 if (context_processingMacros ())
1190 /* evans 2002-02-24: don't add comments when procssing macros */
1194 context_addComment (cstring_fromCharsNew (os), loc);
1208 if (mstring_equal (t, "ignore"))
1210 if (!context_getFlag (FLG_NOCOMMENTS))
1212 context_enterSuppressRegion (loc);
1215 else if ((*t == 'i' || *t == 't')
1216 && (*(t + 1) == '\0'))
1218 if (!context_getFlag (FLG_NOCOMMENTS)
1219 && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
1221 context_enterSuppressLine (-1, loc); /* infinite suppression */
1224 else if (((*t == 'i') || (*t == 't'))
1225 && ((*(t + 1) >= '0' && *(t + 1) <= '9')))
1227 bool tmpcomment = (*t == 't');
1229 char *tt = t; /* don't mangle t, since it is free'd */
1232 if (lc >= '0' && lc <= '9')
1234 val = (int)(lc - '0');
1237 while (lc >= '0' && lc <= '9')
1240 val += (int) (lc - '0');
1245 if (!context_getFlag (FLG_NOCOMMENTS)
1246 && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
1248 DPRINTF (("Here: enter suppress: %s", fileloc_unparse (loc)));
1249 context_enterSuppressLine (val, loc);
1252 else if (mstring_equal (t, "end"))
1254 if (!context_getFlag (FLG_NOCOMMENTS))
1256 context_exitSuppressRegion (loc);
1259 else if (mstring_equal (t, "notfunction"))
1261 ; /* handled by pcpp */
1263 else if (mstring_equal (t, "access"))
1269 while (((c = *s) != '\0') && (c == ' ' || c == '\t' || c == '\n'))
1279 tname = cstring_fromChars (s);
1281 while ((c = *s) != '\0' && c != ' '
1282 && c != '\t' && c != '\n' && c != ',')
1289 DPRINTF (("Access %s", tname));
1291 if (!context_getFlag (FLG_NOCOMMENTS)
1292 && !context_getFlag (FLG_NOACCESS))
1294 if (usymtab_existsType (tname))
1296 typeId uid = usymtab_getTypeId (tname);
1297 uentry ue = usymtab_getTypeEntry (uid);
1299 if (uentry_isAbstractDatatype (ue))
1301 context_addFileAccessType (uid);
1302 DPRINTF (("Adding access to: %s / %d", tname, uid));
1309 ("Non-abstract type %s used in access comment",
1316 if (!(context_inSuppressRegion ()
1317 || context_inSuppressZone (loc)))
1322 ("Unrecognized type %s used in access comment",
1334 if (c != ',' && c != ' ')
1340 else if (mstring_equal (t, "noaccess"))
1347 while (((lc = *s) != '\0') && (lc == ' ' || lc == '\t' || lc == '\n'))
1357 tname = cstring_fromChars (s);
1359 while ((lc = *s) != '\0' && lc != ' ' && lc != '\t'
1360 && lc != '\n' && lc != ',')
1367 if (!context_getFlag (FLG_NOCOMMENTS)
1368 && !context_getFlag (FLG_NOACCESS))
1370 if (usymtab_existsType (tname))
1372 typeId tuid = usymtab_getTypeId (tname);
1374 if (context_couldHaveAccess (tuid))
1376 DPRINTF (("Removing access: %s", tname));
1377 context_removeFileAccessType (tuid);
1381 if (!(context_inSuppressRegion ()
1382 || context_inSuppressZone (loc)))
1384 uentry ue = usymtab_getTypeEntry (tuid);
1386 if (uentry_isAbstractDatatype (ue))
1391 ("Non-accessible abstract type %s used in noaccess comment",
1400 ("Non-abstract type %s used in noaccess comment",
1409 if (!(context_inSuppressRegion ()
1410 || context_inSuppressZone (loc)))
1415 ("Unrecognized type %s used in noaccess comment",
1427 if (lc != ',' && lc != ' ')
1435 voptgenerror (FLG_UNRECOGCOMMENTS,
1436 message ("Semantic comment unrecognized: %s",
1437 cstring_fromChars (os)),
1440 } /* spurious (?) warning about t */
1451 /*@only@*/ cstring cscannerHelp_makeIdentifier (char *s)
1453 char *c = mstring_create (strlen (s) + 1);
1454 cstring id = cstring_fromChars (c);
1456 while (isalnum (*s) || (*s == '_') || (*s == '$'))
1465 /*@observer@*/ /*@dependent@*/ uentry cscannerHelp_coerceId (cstring cn)
1467 if (!(usymtab_exists (cn)))
1469 fileloc loc = fileloc_createExternal ();
1472 ** We need to put this in a global scope, otherwise the sRef will be deallocated.
1475 uentry ce = uentry_makeUnrecognized (cn, loc);
1477 if (!context_inIterEnd ())
1481 message ("Unrecognized (possibly system) identifier: %q",
1482 uentry_getName (ce)),
1489 return (usymtab_lookup (cn));
1493 ** like, cscannerHelp_coerceId, but doesn't supercede for iters
1496 /*@observer@*/ uentry cscannerHelp_coerceIterId (cstring cn)
1498 if (!(usymtab_exists (cn)))
1500 return uentry_undefined;
1503 return (usymtab_lookup (cn));
1507 ** Need to keep this in case there is a declaration that isn't processed until
1508 ** the scope exits. Would be good to rearrange the symbol table so this doesn't
1509 ** happen, and save all the cstring copying.
1512 /*@observer@*/ cstring cscannerHelp_observeLastIdentifier ()
1514 cstring res = s_lastidprocessed;
1518 static void cscanner_setLastIdentifier (/*@keep@*/ cstring id) /*@modifies s_lastidprocessed@*/
1520 if (cstring_isDefined (s_lastidprocessed))
1522 cstring_free (s_lastidprocessed);
1525 s_lastidprocessed = id;
1528 int cscannerHelp_processIdentifier (cstring id)
1532 if (context_getFlag (FLG_GRAMMAR))
1534 lldiagmsg (message ("Process identifier: %s", id));
1537 context_clearJustPopped ();
1538 cscanner_setLastIdentifier (id);
1540 DPRINTF (("Context: %s", context_unparse ()));
1542 if (context_inFunctionHeader ())
1544 int tok = commentMarkerToken (id);
1545 DPRINTF (("in function decl: %s", id));
1553 tok = tokenMacroCode (id);
1561 annotationInfo ainfo;
1563 if (s_expectingMetaStateName)
1565 metaStateInfo msinfo = context_lookupMetaStateInfo (id);
1567 if (metaStateInfo_isDefined (msinfo))
1569 yylval.msinfo = msinfo;
1570 return METASTATE_NAME;
1574 DPRINTF (("Not meta state name: %s", cstring_toCharsSafe (id)));
1578 ainfo = context_lookupAnnotation (id);
1580 if (annotationInfo_isDefined (ainfo))
1582 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
1583 yylval.annotation = ainfo;
1588 DPRINTF (("Not annotation: %s", id));
1594 DPRINTF (("Here!"));
1596 /* Consider handling: Defined by C99 as static const char __func__[] */
1598 if (context_getFlag (FLG_GNUEXTENSIONS))
1602 if (cstring_equalLit (id, "__stdcall")
1603 || cstring_equalLit (id, "__cdecl")
1604 || cstring_equalLit (id, "__extension__"))
1608 else if (cstring_equalLit (id, "__volatile__"))
1612 else if (cstring_equalLit (id, "__signed"))
1616 else if (cstring_equalLit (id, "__unsigned"))
1620 else if (cstring_equalLit (id, "__const__"))
1624 else if (cstring_equalLit (id, "__alignof__"))
1626 tok = CALIGNOF; /* alignof is parsed like sizeof */
1628 else if (cstring_equalLit (id, "__typeof__"))
1632 else if (cstring_equalLit (id, "typeof"))
1636 else if (cstring_equalLit (id, "__FUNCTION__")
1637 || cstring_equalLit (id, "__PRETTY_FUNCTION__"))
1639 /* These tokens hold the name of the current function as strings */
1640 /* evans 2001-12-30: changed from exprNode_stringLiteral; bug reported by Jim Zelenka. */
1641 yylval.expr = exprNode_makeConstantString (id, fileloc_copy (g_currentloc));
1643 s_lastWasString = TRUE;
1647 else if (cstring_equalLit (id, "__attribute__")
1648 || cstring_equalLit (id, "__asm__")
1649 || cstring_equalLit (id, "_asm")
1650 || cstring_equalLit (id, "__asm")
1651 || cstring_equalLit (id, "__declspec"))
1654 bool useparens = FALSE;
1655 bool usebraces = FALSE;
1656 bool inquote = FALSE;
1657 bool inescape = FALSE;
1660 while ((ic = cscanner_input ()) != EOF)
1662 char cc = (char) ic;
1668 else if (cc == '\\')
1672 else if (cc == '\"')
1708 else if (cc == ')' && useparens)
1711 if (depth == 0) break;
1713 else if (cc == '}' && usebraces)
1716 if (depth == 0) break;
1719 && !usebraces && !useparens
1720 && cstring_equalLit (id, "__asm"))
1723 ** We need this because some MS VC++ include files
1724 ** have __asm mov ... }
1725 ** Its a kludge, but otherwise would need to parse
1742 context_incLineno ();
1744 if (cstring_equalLit (id, "__asm")
1745 && !useparens && !usebraces)
1752 llassert ((useparens && ic == (int) ')')
1753 || (usebraces && ic == (int) '}')
1754 || (!useparens && !usebraces));
1758 else if (cstring_equalLit (id, "inline")
1759 || cstring_equalLit (id, "__inline")
1760 || cstring_equalLit (id, "_inline")
1761 || cstring_equalLit (id, "__inline__"))
1772 return (cscannerHelp_returnToken (tok));
1776 le = usymtab_lookupSafe (id);
1778 /*@-dependenttrans@*/
1780 if (uentry_isIter (le))
1785 else if (uentry_isEndIter (le))
1788 return (ITER_ENDNAME);
1790 else if (uentry_isUndefined (le))
1792 yylval.cname = cstring_copy (id);
1794 /* avoid parse errors for certain system built ins */
1796 if (s_expectingTypeName && (cstring_firstChar (id) == '_')
1797 && (cstring_secondChar (id) == '_'))
1799 return (TYPE_NAME_OR_ID);
1802 return (NEW_IDENTIFIER);
1804 else if (!uentry_isDeclared (le) && !uentry_isCodeDefined (le))
1806 if (uentry_isDatatype (le))
1808 yylval.cname = cstring_copy (id);
1809 return (NEW_IDENTIFIER);
1814 return (IDENTIFIER);
1817 else if (uentry_isDatatype (le))
1819 if (!s_expectingTypeName)
1821 yylval.cname = cstring_copy (id);
1823 return (NEW_IDENTIFIER);
1827 yylval.ctyp = uentry_getAbstractType (le);
1829 uentry_setUsed (le, g_currentloc);
1836 return (IDENTIFIER);
1839 /*@=dependenttrans@*/
1842 bool cscannerHelp_processHashIdentifier (/*@only@*/ cstring id)
1844 if (context_inMacro () || context_inIterDef () ||
1845 context_inIterEnd ())
1849 context_clearJustPopped ();
1851 le = usymtab_lookupSafe (id);
1852 cscanner_setLastIdentifier (id);
1854 if (uentry_isParam (le) || uentry_isRefParam (le))
1866 ** Will be handled by handleLlSpecial
1874 /*@only@*/ exprNode cscannerHelp_processString (void)
1878 char *nl = strchr (yytext, '\n');
1879 cstring ns = cstring_fromCharsNew (yytext);
1883 loc = fileloc_copy (g_currentloc);
1884 addColumn (size_toInt (cstring_length (ns)));
1890 loc = fileloc_copy (g_currentloc);
1892 context_incLineno ();
1894 while ((nl = strchr ((nl + 1), '\n')) != NULL)
1896 context_incLineno ();
1902 res = exprNode_stringLiteral (ns, loc);
1907 ** process a wide character string L"...."
1910 /*@only@*/ exprNode cscannerHelp_processWideString ()
1914 char *nl = strchr (yytext, '\n');
1917 llassert (*yytext == 'L');
1920 ns = cstring_fromCharsNew (yytext);
1924 loc = fileloc_copy (g_currentloc);
1925 addColumn (size_toInt (cstring_length (ns)));
1931 loc = fileloc_copy (g_currentloc);
1933 context_incLineno ();
1935 while ((nl = strchr ((nl + 1), '\n')) != NULL)
1937 context_incLineno ();
1942 res = exprNode_wideStringLiteral (ns, loc);
1946 char cscannerHelp_processChar ()
1951 llassert (*yytext != '\0');
1952 fchar = *(yytext + 1);
1953 if (fchar != '\\') return fchar;
1955 next = *(yytext + 2);
1959 case 'n': return '\n';
1960 case 't': return '\t';
1961 case '\"': return '\"';
1962 case '\'': return '\'';
1963 case '\\': return '\\';
1964 default: return '\0';
1968 double cscannerHelp_processFloat ()
1970 double ret = atof (yytext);
1975 long cscannerHelp_processHex ()
1980 llassert (yytext[0] == '0'
1981 && (yytext[1] == 'X' || yytext[1] == 'x'));
1983 while (yytext[index] != '\0') {
1985 char c = yytext[index];
1987 if (c >= '0' && c <= '9') {
1988 tval = (int) c - (int) '0';
1989 } else if (c >= 'A' && c <= 'F') {
1990 tval = (int) c - (int) 'A' + 10;
1991 } else if (c >= 'a' && c <= 'f') {
1992 tval = (int) c - (int) 'a' + 10;
1993 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
1995 while (yytext[index] != '\0') {
1996 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2001 message ("Invalid character (%c) following specifier in hex constant: %s",
2002 c, cstring_fromChars (yytext)),
2012 message ("Invalid character (%c) in hex constant: %s",
2013 c, cstring_fromChars (yytext)),
2018 val = (val * 16) + tval;
2022 DPRINTF (("Hex constant: %s = %ld", yytext, val));
2026 long cscannerHelp_processOctal ()
2031 llassert (yytext[0] == '0' && yytext[1] != 'X' && yytext[1] != 'x');
2033 while (yytext[index] != '\0') {
2035 char c = yytext[index];
2037 if (c >= '0' && c <= '7') {
2038 tval = (int) c - (int) '0';
2039 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2041 while (yytext[index] != '\0') {
2042 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2047 message ("Invalid character (%c) following specifier in octal constant: %s",
2048 c, cstring_fromChars (yytext)),
2058 message ("Invalid character (%c) in octal constant: %s",
2059 c, cstring_fromChars (yytext)),
2064 val = (val * 8) + tval;
2068 DPRINTF (("Octal constant: %s = %ld", yytext, val));
2072 long cscannerHelp_processDec ()
2074 return (atol (yytext));
2077 int cscannerHelp_processSpec (int tok)
2079 size_t length = strlen (yytext);
2085 patched to fix assert failures in constraint code.
2086 Added the else if test so that splint does not treat MaxSet and MaxRead
2089 if (s_whichSpecPart == QMODIFIES
2090 || s_whichSpecPart == QDEFINES
2091 || s_whichSpecPart == QUSES
2092 || s_whichSpecPart == QALLOCATES
2093 || s_whichSpecPart == QSETS
2094 || s_whichSpecPart == QRELEASES)
2097 DPRINTF((message("Treating specifaction keyword %s as an identifiers. (This corresponds to"
2098 " token %d and we're in the specification denoted by %d see cgrammar_tokens.h"
2099 " for an explanation of these numbers",
2100 yytext, tok, s_whichSpecPart)
2103 ; /* Allow specificiation keywords to be used as identifiers in these contexts. */
2105 else if ( (s_whichSpecPart == QPRECLAUSE
2106 || s_whichSpecPart == QPOSTCLAUSE
2107 || s_whichSpecPart == QINVARIANT )
2108 && (!cscannerHelp_isConstraintToken(tok) )
2111 DPRINTF((message("Treating specifaction keyword %s as an identifiers. (This corresponds to"
2112 " token %d and we're in the specification denoted by %d see cgrammar_tokens.h"
2113 " for an explanation of these numbers",
2114 yytext, tok, s_whichSpecPart)
2117 /* Allow specificiation keywords to be used as identifiers in these contexts. */
2121 cscannerHelp_setTokLengthT (length);
2122 return cscannerHelp_returnToken (tok);
2126 context_saveLocation ();
2127 cscannerHelp_setTokLengthT (length);
2128 return (cscannerHelp_processIdentifier (cscannerHelp_makeIdentifier (yytext)));
2131 void cscannerHelp_expectingMetaStateName ()
2133 llassert (!s_expectingMetaStateName);
2134 llassert (context_inFunctionHeader ());
2135 s_expectingMetaStateName = TRUE;
2138 void cscannerHelp_clearExpectingMetaStateName ()
2140 llassert (s_expectingMetaStateName);
2141 s_expectingMetaStateName = FALSE;
2144 bool cscannerHelp_isConstraintToken (int tok)
2145 /* drl added 12/11/2002
2146 Tell whether a token has special meaning
2147 within a function constraint
2150 return (tok == QMAXSET || tok == QMAXREAD);
2151 /* || tok == QMINREAD || tok == QMINSET */
2152 /* uncomment the additional if statement tests when minSet and minRead are supported */
2155 bool cscannerHelp_processMacro (void)
2160 cstring fname = cstring_undefined;
2162 bool isspecfcn = FALSE;
2163 bool isiter = FALSE;
2164 bool skipparam = FALSE;
2165 bool isenditer = FALSE;
2166 bool unknownm = FALSE;
2167 bool hasParams = FALSE;
2168 bool emptyMacro = FALSE;
2169 char c = skip_whitespace ();
2170 fileloc loc = fileloc_noColumn (g_currentloc);
2172 /* are both of these necessary? what do they mean? */
2173 uentryList specparams = uentryList_undefined;
2174 uentryList pn = uentryList_undefined;
2176 context_resetMacroMissingParams ();
2178 if (c == '\0' || c == '\n')
2180 llcontbug (cstring_makeLiteral ("Bad macro"));
2185 fname = cstring_appendChar (fname, c);
2187 while ((c = macro_nextChar ()) != '(' && c != '\0'
2188 && c != ' ' && c != '\t' && c != '\n')
2190 fname = cstring_appendChar (fname, c);
2193 if (c == ' ' || c == '\t' || c == '\n')
2199 while (c == ' ' || c == '\t')
2201 c = macro_nextChar ();
2203 cscanner_unput ((int) c);
2209 cscanner_unput ((int) c);
2215 hasParams = (c == '(');
2217 if (usymtab_exists (fname))
2219 e2 = usymtab_lookupExpose (fname);
2220 ct = uentry_getType (e2);
2222 if (uentry_isCodeDefined (e2)
2223 && fileloc_isUser (uentry_whereDefined (e2)))
2227 message ("Macro %s already defined", fname),
2230 uentry_showWhereDefined (e2);
2231 uentry_clearDefined (e2);
2234 if (uentry_isFunction (e2))
2236 uentry_setType (e2, ctype_unknown);
2239 context_enterUnknownMacro (e2);
2243 context_enterConstantMacro (e2);
2248 if (uentry_isForward (e2) && uentry_isFunction (e2))
2255 ("Parameterized macro has no prototype or specification: %s ",
2260 uentry_setType (e2, ctype_unknown);
2261 uentry_setFunctionDefined (e2, loc);
2262 uentry_setUsed (e2, fileloc_undefined);
2263 context_enterUnknownMacro (e2);
2267 if (uentry_isIter (e2))
2270 specparams = uentry_getParams (e2);
2271 noparams = uentryList_size (specparams);
2272 uentry_setDefined (e2, loc);
2273 context_enterIterDef (e2);
2275 else if (uentry_isEndIter (e2))
2278 uentry_setDefined (e2, loc);
2279 context_enterIterEnd (e2); /* don't care about it now */
2280 /* but should parse like an iter! */
2282 else if (uentry_isConstant (e2))
2288 message ("Constant %s implemented as parameterized macro",
2292 uentry_showWhereSpecified (e2);
2293 uentry_setType (e2, ctype_unknown);
2294 uentry_makeConstantFunction (e2);
2295 uentry_setDefined (e2, g_currentloc);
2296 uentry_setFunctionDefined (e2, g_currentloc);
2297 context_enterUnknownMacro (e2);
2301 if (!uentry_isSpecified (e2))
2303 fileloc oloc = uentry_whereDeclared (e2);
2305 if (fileloc_isLib (oloc))
2309 else if (fileloc_isUndefined (oloc)
2310 || fileloc_isPreproc (oloc))
2315 (FLG_MACROCONSTDECL,
2317 ("Macro constant %q not declared",
2318 uentry_getName (e2)),
2322 else if (!fileloc_withinLines (oloc, loc, 2))
2323 { /* bogus! will give errors if there is too much whitespace */
2327 ("Macro constant name %s does not match name in "
2328 "previous constant declaration. This constant "
2329 "is declared at %q", fname,
2330 fileloc_unparse (oloc)),
2339 context_enterConstantMacro (e2);
2340 cstring_free (fname);
2346 else if (ctype_isFunction (ct))
2349 specparams = ctype_argsFunction (ct);
2350 noparams = uentryList_size (specparams);
2352 uentry_setFunctionDefined (e2, loc);
2353 context_enterMacro (e2);
2355 else if (uentry_isVar (e2))
2361 message ("Variable %s implemented as parameterized macro",
2365 uentry_showWhereSpecified (e2);
2366 uentry_setType (e2, ctype_unknown);
2367 uentry_makeVarFunction (e2);
2368 uentry_setDefined (e2, g_currentloc);
2369 uentry_setFunctionDefined (e2, g_currentloc);
2370 context_enterUnknownMacro (e2);
2374 uentry ucons = uentry_makeConstant (fname,
2377 if (uentry_isExpandedMacro (e2))
2385 message ("Variable %s implemented by a macro",
2389 uentry_showWhereSpecified (e2);
2393 uentry_setDefined (e2, loc);
2394 uentry_setUsed (ucons, loc);
2396 context_enterConstantMacro (ucons);
2397 uentry_markOwned (ucons);
2398 cstring_free (fname);
2404 if (uentry_isDatatype (e2))
2408 message ("Type implemented as macro: %x",
2409 uentry_getName (e2)),
2410 message ("A type is implemented using a macro definition. A "
2411 "typedef should be used instead."),
2414 cscannerHelp_swallowMacro ();
2415 /* Must exit scope (not sure why a new scope was entered?) */
2416 usymtab_quietExitScope (g_currentloc);
2417 uentry_setDefined (e2, g_currentloc);
2423 (message ("Unexpanded macro not function or constant: %q",
2424 uentry_unparse (e2)));
2425 uentry_setType (e2, ctype_unknown);
2429 uentry_makeVarFunction (e2);
2430 uentry_setDefined (e2, g_currentloc);
2431 uentry_setFunctionDefined (e2, g_currentloc);
2432 context_enterUnknownMacro (e2);
2443 /* evans 2001-09-09 - if it has params, assume a function */
2447 (FLG_MACROMATCHNAME,
2448 message ("Unexpanded macro %s does not match name of a declared "
2449 "function. The name used in the control "
2450 "comment on the previous line should match.",
2454 ce = uentry_makeFunction (fname, ctype_unknown,
2458 warnClause_undefined,
2460 uentry_setUsed (ce, loc); /* perhaps bogus? */
2461 e2 = usymtab_supEntryReturn (ce);
2462 context_enterUnknownMacro (e2);
2467 (FLG_MACROMATCHNAME,
2468 message ("Unexpanded macro %s does not match name of a constant "
2469 "or iter declaration. The name used in the control "
2470 "comment on the previous line should match. "
2471 "(Assuming macro defines a constant.)",
2475 ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);
2476 uentry_setUsed (ce, loc); /* perhaps bogus? */
2477 e2 = usymtab_supEntryReturn (ce);
2479 context_enterConstantMacro (e2);
2480 cstring_free (fname);
2486 /* in macros, ( must follow immediatetly after name */
2492 c = skip_whitespace ();
2494 while (c != ')' && c != '\0')
2497 bool suppress = context_inSuppressRegion ();
2498 cstring paramname = cstring_undefined;
2501 ** save the parameter location
2505 context_saveLocation ();
2508 while (c != ' ' && c != '\t' && c != ',' && c != '\0' && c != ')')
2510 paramname = cstring_appendChar (paramname, c);
2511 c = macro_nextChar ();
2514 if (c == ' ' || c == '\t') c = skip_whitespace ();
2518 c = macro_nextChar ();
2519 if (c == ' ' || c == '\t') c = skip_whitespace ();
2524 llfatalerror (cstring_makeLiteral
2525 ("Bad macro syntax: uentryList"));
2528 if ((isspecfcn || isiter) && (paramno < noparams)
2529 && !uentry_isElipsisMarker (uentryList_getN
2530 (specparams, paramno)))
2532 fileloc sloc = context_getSaveLocation ();
2533 uentry decl = uentryList_getN (specparams, paramno);
2536 param = uentry_nameCopy (paramname, decl);
2538 uentry_setParam (param);
2539 sr = sRef_makeParam (paramno, uentry_getType (param),
2540 stateInfo_makeLoc (sloc, SA_DECLARED));
2542 if (sRef_getNullState (sr) == NS_ABSNULL)
2544 ctype pt = ctype_realType (uentry_getType (param));
2546 if (ctype_isUser (pt))
2548 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (pt));
2550 if (uentry_isValid (te))
2552 sRef_setStateFromUentry (sr, te);
2557 sRef_setNullState (sr, NS_UNKNOWN, sloc);
2561 uentry_setSref (param, sr);
2562 uentry_setDeclaredForceOnly (param, sloc);
2564 skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
2568 fileloc sloc = context_getSaveLocation ();
2570 param = uentry_makeVariableSrefParam
2571 (paramname, ctype_unknown, fileloc_copy (sloc),
2572 sRef_makeParam (paramno, ctype_unknown,
2573 stateInfo_makeLoc (sloc, SA_DECLARED)));
2574 DPRINTF (("Unknown param: %s", uentry_unparseFull (param)));
2575 cstring_free (paramname);
2577 sRef_setPosNull (uentry_getSref (param), sloc);
2578 uentry_setDeclaredForce (param, sloc);
2581 fileloc_free (sloc);
2586 llassert (!uentry_isElipsisMarker (param));
2590 sRef_makeUnsafe (uentry_getSref (param));
2593 pn = uentryList_add (pn, uentry_copy (param));
2594 usymtab_supEntry (param);
2598 /* don't add param */
2599 uentry_free (param);
2604 (void) macro_nextChar ();
2605 c = skip_whitespace ();
2613 if (isspecfcn || isiter)
2615 if (paramno != noparams && noparams >= 0)
2617 cscannerHelp_advanceLine ();
2621 message ("Macro %s specified with %d args, defined with %d",
2622 fname, noparams, paramno),
2625 uentry_showWhereSpecified (e2);
2626 uentry_resetParams (e2, pn);
2631 uentry_resetParams (e2, pn);
2638 ** the form should be:
2640 ** # define newname oldname
2641 ** where oldname refers to a function matching the specification
2647 sRef_setGlobalScope ();
2648 usymtab_supGlobalEntry (uentry_makeVariableLoc (fname, ctype_unknown));
2649 sRef_clearGlobalScope ();
2653 context_setMacroMissingParams ();
2658 /* context_setuentryList (pn); */
2659 usymtab_enterScope ();
2662 cstring_free (fname);
2667 void cscannerHelp_setTokLength (int len)
2671 DPRINTF (("Set tok length: %d", len));
2674 void cscannerHelp_setTokLengthT (size_t len)
2676 cscannerHelp_setTokLength (size_toInt (len));
2679 void cscannerHelp_advanceLine (void)
2685 int cscannerHelp_returnToken (int t)
2687 yylval.tok = lltok_create (t, fileloc_decColumn (g_currentloc, s_tokLength));
2689 s_lastWasString = FALSE;
2693 int cscannerHelp_returnTokenLength (int t, int length)
2695 cscannerHelp_setTokLength (length);
2696 return cscannerHelp_returnToken (t);
2699 int cscannerHelp_returnString (cstring s)
2701 yylval.expr = exprNode_stringLiteral (s, fileloc_decColumn (g_currentloc, s_tokLength));
2703 s_lastWasString = TRUE;
2707 int cscannerHelp_returnInt (ctype ct, long val)
2711 if (ctype_equal (ct, ctype_int))
2715 c = context_typeofZero ();
2719 c = context_typeofOne ();
2727 yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
2728 fileloc_decColumn (g_currentloc, s_tokLength),
2731 s_lastWasString = FALSE;
2735 int cscannerHelp_returnFloat (ctype ct, double f)
2737 yylval.expr = exprNode_floatLiteral (f, ct, cstring_fromChars (yytext),
2738 fileloc_decColumn (g_currentloc, s_tokLength));
2740 s_lastWasString = FALSE;
2744 int cscannerHelp_returnChar (char c)
2746 yylval.expr = exprNode_charLiteral (c, cstring_fromChars (yytext),
2747 fileloc_decColumn (g_currentloc, s_tokLength));
2749 s_lastWasString = FALSE;
2753 int cscannerHelp_returnType (int tok, ctype ct)
2757 s_lastWasString = FALSE;
2761 int cscannerHelp_returnExpr (exprNode e)
2765 s_lastWasString = TRUE;
2769 void cscannerHelp_setExpectingTypeName ()
2771 s_expectingTypeName = TRUE;
2774 void cscannerHelp_clearExpectingTypeName ()
2776 s_expectingTypeName = FALSE;
2779 bool cscannerHelp_isExpectingTypeName ()
2781 return s_expectingTypeName;
2784 int cscannerHelp_processTextIdentifier (char *text)
2786 context_saveLocation ();
2787 cscannerHelp_setTokLength (size_toInt (mstring_length (text)));
2788 return cscannerHelp_processIdentifier (cscannerHelp_makeIdentifier (text));
2791 static bool s_continueLine = FALSE;
2793 int cscannerHelp_handleNewLine ()
2795 context_incLineno ();
2797 if (s_tokLength != 0) {
2799 /* No error to report
2802 message ("Likely parse error: token spans multiple lines."),
2809 s_continueLine = FALSE;
2813 if (context_inMacro ())
2815 /* Don't use return cscannerHelp_returnToken */
2816 /* !!! evans 2002-03-13 */
2817 yylval.tok = lltok_create (TENDMACRO, fileloc_copy (g_currentloc));
2818 s_lastWasString = FALSE;
2826 void cscannerHelp_setContinueLine ()
2828 s_continueLine = TRUE;
2831 void cscannerHelp_exitSpecPart ()
2833 llassert (s_inSpecPart);
2834 s_inSpecPart = FALSE;
2835 s_whichSpecPart = BADTOK;