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"
38 static int lminput (void);
39 static int s_tokLength = 0;
41 static /*@owned@*/ cstring s_lastidprocessed = cstring_undefined;
42 static bool s_inSpecPart = FALSE;
43 static int s_whichSpecPart;
44 static char s_savechar = '\0';
45 static bool s_expectingMetaStateName = FALSE;
46 static bool s_lastWasString = FALSE;
47 static bool s_expectingTypeName = TRUE;
51 /*@null@*/ /*@observer@*/ char *name;
56 ** These tokens are followed by syntax that is parsed by the
60 static struct skeyword s_parsetable[] = {
61 { "modifies", QMODIFIES } ,
62 { "globals", QGLOBALS } ,
65 { "constant", QCONSTANT } ,
66 { "function", QFUNCTION } ,
68 { "defines", QDEFINES } ,
70 { "allocates", QALLOCATES } ,
72 { "releases", QRELEASES } ,
73 { "pre", QPRECLAUSE } ,
74 { "post", QPOSTCLAUSE } ,
75 { "setBufferSize", QSETBUFFERSIZE},
76 { "setStringLength", QSETSTRINGLENGTH},
77 { "testinRange", QTESTINRANGE},
78 { "requires", QPRECLAUSE } ,
79 { "ensures", QPOSTCLAUSE } ,
80 { "invariant", QINVARIANT} ,
85 ** These tokens are either stand-alone tokens, or followed by
86 ** token-specific text.
89 static struct skeyword s_keytable[] = {
90 { "anytype", QANYTYPE } ,
91 { "integraltype", QINTEGRALTYPE } ,
92 { "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
93 { "signedintegraltype", QSIGNEDINTEGRALTYPE } ,
98 { "dependent", QDEPENDENT } ,
99 { "partial", QPARTIAL } ,
100 { "special", QSPECIAL } ,
101 { "truenull", QTRUENULL } ,
102 { "falsenull", QFALSENULL } ,
103 { "nullwhentrue", QTRUENULL } ,
104 { "falsewhennull", QFALSENULL } ,
107 { "notnull", QNOTNULL } ,
108 { "abstract", QABSTRACT } ,
109 { "numabstract", QNUMABSTRACT } ,
110 { "concrete", QCONCRETE } ,
111 { "mutable", QMUTABLE } ,
112 { "immutable", QIMMUTABLE } ,
113 { "unused", QUNUSED } ,
114 { "external", QEXTERNAL } ,
116 { "unique", QUNIQUE } ,
117 { "returned", QRETURNED } ,
118 { "exposed", QEXPOSED } ,
119 { "refcounted", QREFCOUNTED } ,
121 { "newref", QNEWREF } ,
122 { "tempref", QTEMPREF } ,
123 { "killref", QKILLREF } ,
125 { "relnull", QRELNULL } ,
126 { "nullterminated", QNULLTERMINATED },
127 { "setBufferSize", QSETBUFFERSIZE },
128 { "testInRange", QTESTINRANGE},
129 { "isnull", QISNULL },
130 { "MaxSet", QMAXSET},
131 { "MaxRead", QMAXREAD},
132 { "maxSet", QMAXSET},
133 { "maxRead", QMAXREAD},
134 { "reldef", QRELDEF } ,
135 { "observer", QOBSERVER } ,
136 { "exits", QEXITS } ,
137 { "noreturn", QEXITS } ,
138 { "mayexit", QMAYEXIT } ,
139 { "maynotreturn", QMAYEXIT } ,
140 { "trueexit", QTRUEEXIT } ,
141 { "falseexit", QFALSEEXIT } ,
142 { "noreturnwhentrue", QTRUEEXIT } ,
143 { "noreturnwhenfalse", QFALSEEXIT } ,
144 { "neverexit", QNEVEREXIT } ,
145 { "alwaysreturns", QNEVEREXIT } ,
147 { "shared", QSHARED } ,
149 { "unchecked", QUNCHECKED } ,
150 { "checked", QCHECKED } ,
151 { "checkmod", QCHECKMOD } ,
152 { "checkedstrict", QCHECKEDSTRICT } ,
153 { "innercontinue", QINNERCONTINUE } ,
154 { "innerbreak", QINNERBREAK } ,
155 { "loopbreak", QLOOPBREAK } ,
156 { "switchbreak", QSWITCHBREAK } ,
157 { "safebreak", QSAFEBREAK } ,
158 { "fallthrough", QFALLTHROUGH } ,
159 { "l_fallthrou", QLINTFALLTHROUGH } ,
160 { "l_fallth", QLINTFALLTHRU } ,
161 { "notreached", QNOTREACHED } ,
162 { "l_notreach", QLINTNOTREACHED } ,
163 { "printflike", QPRINTFLIKE } ,
164 { "l_printfli", QLINTPRINTFLIKE } ,
165 { "scanflike", QSCANFLIKE } ,
166 { "messagelike", QMESSAGELIKE } ,
167 { "l_argsus", QARGSUSED } ,
172 ** would be better if these weren't hard coded...
175 static bool isArtificial (cstring s)
177 return (cstring_equalLit (s, "modifies")
178 || cstring_equalLit (s, "globals")
179 || cstring_equalLit (s, "warn")
180 || cstring_equalLit (s, "alt"));
183 void cscannerHelp_swallowMacro (void)
186 bool skipnext = FALSE;
188 while ((i = lminput ()) != EOF)
204 reader_checkUngetc (i, yyin);
216 reader_checkUngetc (i, yyin);
220 static int commentMarkerToken (cstring s)
224 while (s_parsetable[i].name != NULL)
226 DPRINTF (("Try :%s:%s:", s, s_parsetable[i].name));
228 if (cstring_equalLit (s, s_parsetable[i].name))
230 return s_parsetable[i].token;
239 static int tokenMacroCode (cstring s)
243 while (s_keytable[i].name != NULL)
245 if (cstring_equalLit (s, s_keytable[i].name))
247 if (s_keytable[i].token == QLINTFALLTHROUGH)
250 (FLG_WARNLINTCOMMENTS,
252 ("Traditional lint comment /*FALLTHROUGH*/ used. "
253 "Splint interprets this in the same way as most Unix lints, but it is "
254 "preferable to replace it with the /*@fallthrough@*/ "
259 else if (s_keytable[i].token == QLINTFALLTHRU)
262 (FLG_WARNLINTCOMMENTS,
264 ("Traditional lint comment /*FALLTHRU*/ used. "
265 "Splint interprets this in the same way as most Unix lints, but it is "
266 "preferable to replace it with the /*@fallthrough@*/ "
271 else if (s_keytable[i].token == QLINTNOTREACHED)
274 (FLG_WARNLINTCOMMENTS,
276 ("Traditional lint comment /*NOTREACHED*/ used. "
277 "Splint interprets this in the same way as most Unix lints, but it is "
278 "preferable to replace it with the /*@notreached@*/ "
279 "semantic comment."),
284 else if (s_keytable[i].token == QPRINTFLIKE)
286 setSpecialFunction (qual_createPrintfLike ());
289 else if (s_keytable[i].token == QLINTPRINTFLIKE)
292 (FLG_WARNLINTCOMMENTS,
294 ("Traditional lint comment /*PRINTFLIKE*/ used. "
295 "Splint interprets this in the same way as most Unix lints, but it is "
296 "preferable to replace it with either /*@printflike@*/, "
297 "/*@scanflike@*/ or /*@messagelike@*/."),
300 setSpecialFunction (qual_createPrintfLike ());
303 else if (s_keytable[i].token == QSCANFLIKE)
305 setSpecialFunction (qual_createScanfLike ());
308 else if (s_keytable[i].token == QMESSAGELIKE)
310 setSpecialFunction (qual_createMessageLike ());
313 else if (s_keytable[i].token == QARGSUSED)
316 (FLG_WARNLINTCOMMENTS,
318 ("Traditional lint comment /*ARGSUSED*/ used. "
319 "Splint interprets this in the same way as most Unix lints, but it is "
320 "preferable to use /*@unused@*/ annotations on "
321 "the unused parameters."),
329 return s_keytable[i].token;
339 static int lminput ()
341 if (s_savechar == '\0')
344 return (cscanner_input ());
348 int save = (int) s_savechar;
354 static void lmsavechar (char c)
356 if (s_savechar == '\0')
362 llbuglit ("lmsavechar: override");
366 int cscannerHelp_ninput ()
370 if (c != EOF && ((char)c == '\n'))
372 context_incLineno ();
378 static char macro_nextChar (void)
380 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
385 c = char_fromInt (ic);
387 if (!in_quote && !in_char && (c == '\\' || c == BEFORE_COMMENT_MARKER[0]))
391 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
393 ; /* skip to newline */
396 context_incLineno ();
400 return macro_nextChar ();
407 else /* if (c == '@') */
411 if (cscannerHelp_handleLlSpecial () != BADTOK)
413 llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
416 return macro_nextChar ();
419 else if (!in_escape && c == '\"')
421 in_quote = !in_quote;
423 else if (!in_escape && c == '\'')
427 else if ((in_quote || in_char) && c == '\\')
429 in_escape = !in_escape;
431 else if ((in_quote || in_char) && in_escape)
435 else if (!in_quote && c == '/')
439 if ((c2 = char_fromInt (lminput ())) == '*')
443 while ((c2 = char_fromInt (lminput ())) != '\0'
444 && c2 != '\n' && c2 != '*')
451 while ((c2 = char_fromInt (lminput ())) != '\0'
464 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
468 return macro_nextChar ();
472 /*** putchar does not work! why? puts to stdio...??! ***/
485 ** keeps semantic comments
488 static char macro_nextCharC (void)
490 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
493 c = char_fromInt (lminput ());
495 if (!in_quote && !in_char && c == '\\')
497 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
499 ; /* skip to newline */
502 context_incLineno ();
506 return macro_nextCharC ();
513 else if (!in_escape && c == '\"')
515 in_quote = !in_quote;
517 else if (!in_escape && c == '\'')
521 else if ((in_quote || in_char) && c == '\\')
523 in_escape = !in_escape;
525 else if ((in_quote || in_char) && in_escape)
529 else if (!in_quote && c == '/')
533 if ((c2 = char_fromInt (lminput ())) == '*')
537 while ((c2 = char_fromInt (lminput ())) != '\0'
538 && c2 != '\n' && c2 != '*')
545 while ((c2 = char_fromInt (lminput ())) != '\0'
558 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
562 return macro_nextCharC ();
569 else /* normal character */
578 ** skips whitespace (handles line continuations)
579 ** returns first non-whitespace character
582 static char skip_whitespace (void)
586 while ((c = macro_nextChar ()) == ' ' || c == '\t')
594 void cscannerHelp_handleMacro ()
596 cstring mac = cstring_undefined;
600 while (currentColumn () > 2)
602 mac = cstring_appendChar (mac, ' ');
603 cscannerHelp_setTokLength (-1);
606 c = macro_nextCharC ();
608 if (c >= '0' && c <= '9')
612 for (i = 0; i < (((int) (c - '0')) + 1); i++)
614 mac = cstring_appendChar (mac, ' ');
622 while (((c = macro_nextCharC ()) != '\0') && (c != '\n'))
624 mac = cstring_appendChar (mac, c);
628 macrocode = tokenMacroCode (mac);
630 if (macrocode == BADTOK && !isArtificial (mac))
632 context_addMacroCache (mac);
641 context_incLineno ();
645 bool cscannerHelp_handleSpecial (char *yyt)
647 char *l; /* !! = mstring_create (MAX_NAME_LENGTH); */
654 len_yyt = strlen (yyt +1) ;
656 l = mstring_copy (yyt + 1);
658 while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
660 l = mstring_append(l, c);
663 /* Need to safe original l for deallocating. */
668 olc = cstring_fromChars (ol);
670 if (cstring_equalPrefixLit (olc, "pragma"))
672 char *pname = mstring_create (size_fromInt (MAX_PRAGMA_LEN));
673 char *opname = pname;
674 char *ptr = ol + 6; /* pragma is six characters, plus space */
678 /* skip whitespace */
679 while (((c = *ptr) != '\0') && isspace (c))
685 while (((c = *ptr) != '\0') && !isspace (c))
689 if (len > MAX_PRAGMA_LEN)
700 if (len == PRAGMA_LEN_EXPAND
701 && mstring_equal (opname, PRAGMA_EXPAND))
703 cstring exname = cstring_undefined;
707 while (((c = *ptr) != '\0') && !isspace (c))
709 exname = cstring_appendChar (exname, c);
714 ue = usymtab_lookupExposeGlob (exname);
716 if (uentry_isExpandedMacro (ue))
718 if (fileloc_isPreproc (uentry_whereDefined (ue)))
720 fileloc_setColumn (g_currentloc, 1);
721 uentry_setDefined (ue, g_currentloc);
725 cstring_free (exname);
728 else if (cstring_equalPrefixLit (olc, "ident"))
730 /* Some pre-processors will leave these in the code. Ignore rest of line */
733 ** Yuk...Win32 filenames can have spaces in them...we need to read
734 ** to the matching end quote.
736 else if ((sscanf (ol, "line %d \"", &lineno) == 1)
737 || (sscanf (ol, " %d \"", &lineno) == 1))
744 while (*tmp != '\"' && *tmp != '\0')
749 llassert (*tmp == '\"');
753 while (*tmp != '\"' && *tmp != '\0')
758 llassert (*tmp == '\"');
761 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
764 ** DOS-like path delimiters get delivered in pairs, something like
765 ** \"..\\\\file.h\", so we have to make it normal again. We do NOT
766 ** remove the pre dirs yet as we usually specify tmp paths relative
767 ** to the current directory, so tmp files would not get found in
768 ** the hash table. If this method fails we try it again later.
775 ** Skip past the drive marker.
778 if (strchr (stmp, ':') != NULL)
780 stmp = strchr (stmp, ':') + 1;
783 while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
785 if (*(stmp+1) == CONNECTCHAR)
787 memmove (stmp, stmp+1, strlen (stmp));
793 fid = fileTable_lookupBase (context_fileTable (), fname);
794 if (!(fileId_isValid (fid)))
796 fname = removePreDirs (fname);
797 fid = fileTable_lookupBase (context_fileTable (), fname);
800 # else /* !defined(OS2) && !defined(MSDOS) */
801 fname = removePreDirs (fname);
802 fid = fileTable_lookupBase (context_fileTable (), fname);
803 # endif /* !defined(OS2) && !defined(MSDOS) */
805 if (!(fileId_isValid (fid)))
807 if (context_inXHFile ())
809 fid = fileTable_addXHFile (context_fileTable (), fname);
811 else if (isHeaderFile (fname))
813 fid = fileTable_addHeaderFile (context_fileTable (), fname);
817 fid = fileTable_addFile (context_fileTable (), fname);
821 setFileLine (fid, lineno);
822 /*@noaccess cstring@*/
824 else if ((sscanf (ol, "line %d", &lineno) == 1)
825 || (sscanf (ol, " %d", &lineno) == 1))
827 setLine (lineno); /* next line is <cr> */
831 if (mstring_equal (ol, "")) {
832 DPRINTF (("Empty pp command!"));
834 ** evs 2000-05-16: This is a horrible kludge, to get around a bug (well, difficulty) in the pre-processor.
835 ** We handle a plain # in the input file, by echoing it, and ignoring it in the post-pp-file.
841 (FLG_UNRECOGDIRECTIVE,
842 message ("Unrecognized pre-processor directive: #%s",
843 cstring_fromChars (ol)),
848 return FALSE; /* evans 2001-12-30: was: TRUE; */
855 int cscannerHelp_handleLlSpecial (void)
860 char *s = mstring_createEmpty ();
866 loc = fileloc_copy (g_currentloc);
867 DPRINTF (("Handle special: %s", fileloc_unparse (loc)));
869 while (((ic = cscannerHelp_ninput ()) != 0) && isalpha (ic))
872 s = mstring_append (s, c);
876 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
879 if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
881 ic = cscannerHelp_ninput ();
883 llassert (ic == (int) AFTER_COMMENT_MARKER[1]);
889 return QNOMODS; /* special token no modifications token */
893 DPRINTF (("Coment marker: %s", os));
894 tok = commentMarkerToken (cstring_fromChars (os));
898 s_tokLength = charsread;
901 s_whichSpecPart = tok;
906 DPRINTF (("Not a comment marker..."));
907 /* Add rest of the comment */
909 if (ic != 0 && ic != EOF)
913 s = mstring_append (s, c);
916 while (((ic = cscannerHelp_ninput ()) != 0) && (ic != EOF)
917 && (ic != (int) AFTER_COMMENT_MARKER[0]))
921 /* evans 2001-09-01 added to prevent assertion failures for uncloses syntactic comments */
924 hasnl = TRUE; /* This prevents tokLength from being set later. */
929 message ("Likely parse error: syntactic comment token spans multiple lines: %s",
930 cstring_fromChars (s)),
934 s = mstring_append (s, c);
938 } /* spurious (?) warnings about s */
941 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
943 if (ic == (int) AFTER_COMMENT_MARKER[0])
945 int nc = cscannerHelp_ninput ();
946 llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
952 while (*s == ' ' || *s == '\t' || *s == '\n')
957 if (*s == '-' || *s == '+' || *s == '=') /* setting flags */
961 while (c == '-' || c == '+' || c == '=')
963 ynm set = ynm_fromCodeChar (c);
968 thisflag = cstring_fromChars (s);
970 while ((c = *s) != '\0' && (c != '-') && (c != '=')
971 && (c != '+') && (c != ' ') && (c != '\t') && (c != '\n'))
978 if (!context_getFlag (FLG_NOCOMMENTS))
980 cstring flagname = thisflag;
981 flagcode fflag = flags_identifyFlag (flagname);
983 if (flagcode_isSkip (fflag))
987 else if (flagcode_isModeName (fflag))
989 if (ynm_isMaybe (set))
994 ("Semantic comment attempts to restore flag %s. "
995 "A mode flag cannot be restored.",
1000 context_setMode (flagname);
1003 else if (flagcode_isInvalid (fflag))
1006 (FLG_UNRECOGFLAGCOMMENTS,
1007 message ("Unrecognized option in semantic comment: %s",
1011 else if (flagcode_isGlobalFlag (fflag))
1016 ("Semantic comment attempts to set global flag %s. "
1017 "A global flag cannot be set locally.",
1023 context_fileSetFlag (fflag, set, loc);
1025 if (flagcode_hasArgument (fflag))
1027 if (ynm_isMaybe (set))
1032 ("Semantic comment attempts to restore flag %s. "
1033 "A flag for setting a value cannot be restored.",
1038 { /* cut-and-pastied from llmain...blecch */
1039 cstring extra = cstring_undefined;
1045 rest = mstring_copy (s);
1049 while ((rchar = *rest) != '\0'
1050 && (isspace (rchar)))
1056 while ((rchar = *rest) != '\0'
1057 && !isspace (rchar))
1059 extra = cstring_appendChar (extra, rchar);
1063 s--; /* evans 2002-07-12: this was previously only in the else branch.
1064 Leads to an invalid read on the true branch.
1069 if (cstring_isUndefined (extra))
1074 ("Flag %s (in semantic comment) must be followed by an argument",
1075 flagcode_unparse (fflag)));
1077 cstring_free (extra);
1081 if (flagcode_hasNumber (fflag))
1083 flags_setValueFlag (fflag, extra);
1085 else if (flagcode_hasChar (fflag))
1087 flags_setValueFlag (fflag, extra);
1089 else if (flagcode_hasString (fflag))
1091 flags_setStringFlag (fflag, extra);
1095 cstring_free (extra);
1109 while ((c == ' ') || (c == '\t') || (c == '\n'))
1115 if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
1117 DPRINTF (("Here adding comment: %s", os));
1118 context_addComment (cstring_fromCharsNew (os), loc);
1130 annotationInfo ainfo;
1132 while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
1144 t = cstring_toCharsSafe (cstring_downcase (cstring_fromChars (t)));
1145 macrocode = tokenMacroCode (cstring_fromChars (t));
1147 if (macrocode != BADTOK)
1149 s_tokLength = hasnl ? 0 : size_toInt (mstring_length (t));
1155 if (macrocode == SKIPTOK)
1163 ainfo = context_lookupAnnotation (cstring_fromChars (os));
1165 if (annotationInfo_isDefined (ainfo)) {
1166 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
1167 yylval.annotation = ainfo;
1175 if (context_inHeader ())
1182 if ((context_inMacro () || context_inGlobalContext ())
1183 && macrocode != SKIPTOK
1184 && !isArtificial (cstring_fromChars (os)))
1186 if (context_processingMacros ())
1188 /* evans 2002-02-24: don't add comments when procssing macros */
1192 context_addComment (cstring_fromCharsNew (os), loc);
1206 if (mstring_equal (t, "ignore"))
1208 if (!context_getFlag (FLG_NOCOMMENTS))
1210 context_enterSuppressRegion (loc);
1213 else if ((*t == 'i' || *t == 't')
1214 && (*(t + 1) == '\0'))
1216 if (!context_getFlag (FLG_NOCOMMENTS)
1217 && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
1219 context_enterSuppressLine (-1, loc); /* infinite suppression */
1222 else if (((*t == 'i') || (*t == 't'))
1223 && ((*(t + 1) >= '0' && *(t + 1) <= '9')))
1225 bool tmpcomment = (*t == 't');
1227 char *tt = t; /* don't mangle t, since it is free'd */
1230 if (lc >= '0' && lc <= '9')
1232 val = (int)(lc - '0');
1235 while (lc >= '0' && lc <= '9')
1238 val += (int) (lc - '0');
1243 if (!context_getFlag (FLG_NOCOMMENTS)
1244 && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
1246 DPRINTF (("Here: enter suppress: %s", fileloc_unparse (loc)));
1247 context_enterSuppressLine (val, loc);
1250 else if (mstring_equal (t, "end"))
1252 if (!context_getFlag (FLG_NOCOMMENTS))
1254 context_exitSuppressRegion (loc);
1257 else if (mstring_equal (t, "notfunction"))
1259 ; /* handled by pcpp */
1261 else if (mstring_equal (t, "access"))
1267 while (((c = *s) != '\0') && (c == ' ' || c == '\t' || c == '\n'))
1277 tname = cstring_fromChars (s);
1279 while ((c = *s) != '\0' && c != ' '
1280 && c != '\t' && c != '\n' && c != ',')
1287 DPRINTF (("Access %s", tname));
1289 if (!context_getFlag (FLG_NOCOMMENTS)
1290 && !context_getFlag (FLG_NOACCESS))
1292 if (usymtab_existsType (tname))
1294 typeId uid = usymtab_getTypeId (tname);
1295 uentry ue = usymtab_getTypeEntry (uid);
1297 if (uentry_isAbstractDatatype (ue))
1299 context_addFileAccessType (uid);
1300 DPRINTF (("Adding access to: %s / %d", tname, uid));
1307 ("Non-abstract type %s used in access comment",
1314 if (!(context_inSuppressRegion ()
1315 || context_inSuppressZone (loc)))
1320 ("Unrecognized type %s used in access comment",
1332 if (c != ',' && c != ' ')
1338 else if (mstring_equal (t, "noaccess"))
1345 while (((lc = *s) != '\0') && (lc == ' ' || lc == '\t' || lc == '\n'))
1355 tname = cstring_fromChars (s);
1357 while ((lc = *s) != '\0' && lc != ' ' && lc != '\t'
1358 && lc != '\n' && lc != ',')
1365 if (!context_getFlag (FLG_NOCOMMENTS)
1366 && !context_getFlag (FLG_NOACCESS))
1368 if (usymtab_existsType (tname))
1370 typeId tuid = usymtab_getTypeId (tname);
1372 if (context_couldHaveAccess (tuid))
1374 DPRINTF (("Removing access: %s", tname));
1375 context_removeFileAccessType (tuid);
1379 if (!(context_inSuppressRegion ()
1380 || context_inSuppressZone (loc)))
1382 uentry ue = usymtab_getTypeEntry (tuid);
1384 if (uentry_isAbstractDatatype (ue))
1389 ("Non-accessible abstract type %s used in noaccess comment",
1398 ("Non-abstract type %s used in noaccess comment",
1407 if (!(context_inSuppressRegion ()
1408 || context_inSuppressZone (loc)))
1413 ("Unrecognized type %s used in noaccess comment",
1425 if (lc != ',' && lc != ' ')
1433 voptgenerror (FLG_UNRECOGCOMMENTS,
1434 message ("Semantic comment unrecognized: %s",
1435 cstring_fromChars (os)),
1438 } /* spurious (?) warning about t */
1449 /*@only@*/ cstring cscannerHelp_makeIdentifier (char *s)
1451 char *c = mstring_create (strlen (s) + 1);
1452 cstring id = cstring_fromChars (c);
1454 while (isalnum (*s) || (*s == '_') || (*s == '$'))
1463 /*@observer@*/ /*@dependent@*/ uentry cscannerHelp_coerceId (cstring cn)
1465 if (!(usymtab_exists (cn)))
1467 fileloc loc = fileloc_createExternal ();
1470 ** We need to put this in a global scope, otherwise the sRef will be deallocated.
1473 uentry ce = uentry_makeUnrecognized (cn, loc);
1475 if (!context_inIterEnd ())
1479 message ("Unrecognized (possibly system) identifier: %q",
1480 uentry_getName (ce)),
1487 return (usymtab_lookup (cn));
1491 ** like, cscannerHelp_coerceId, but doesn't supercede for iters
1494 /*@observer@*/ uentry cscannerHelp_coerceIterId (cstring cn)
1496 if (!(usymtab_exists (cn)))
1498 return uentry_undefined;
1501 return (usymtab_lookup (cn));
1505 ** Need to keep this in case there is a declaration that isn't processed until
1506 ** the scope exits. Would be good to rearrange the symbol table so this doesn't
1507 ** happen, and save all the cstring copying.
1510 /*@observer@*/ cstring cscannerHelp_observeLastIdentifier ()
1512 cstring res = s_lastidprocessed;
1516 static void cscanner_setLastIdentifier (/*@keep@*/ cstring id) /*@modifies s_lastidprocessed@*/
1518 if (cstring_isDefined (s_lastidprocessed))
1520 cstring_free (s_lastidprocessed);
1523 s_lastidprocessed = id;
1526 int cscannerHelp_processIdentifier (cstring id)
1530 if (context_getFlag (FLG_GRAMMAR))
1532 lldiagmsg (message ("Process identifier: %s", id));
1535 context_clearJustPopped ();
1536 cscanner_setLastIdentifier (id);
1538 DPRINTF (("Context: %s", context_unparse ()));
1540 if (context_inFunctionHeader ())
1542 int tok = commentMarkerToken (id);
1543 DPRINTF (("in function decl: %s", id));
1551 tok = tokenMacroCode (id);
1559 annotationInfo ainfo;
1561 if (s_expectingMetaStateName)
1563 metaStateInfo msinfo = context_lookupMetaStateInfo (id);
1565 if (metaStateInfo_isDefined (msinfo))
1567 yylval.msinfo = msinfo;
1568 return METASTATE_NAME;
1572 DPRINTF (("Not meta state name: %s", cstring_toCharsSafe (id)));
1576 ainfo = context_lookupAnnotation (id);
1578 if (annotationInfo_isDefined (ainfo))
1580 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
1581 yylval.annotation = ainfo;
1586 DPRINTF (("Not annotation: %s", id));
1592 DPRINTF (("Here!"));
1594 /* Consider handling: Defined by C99 as static const char __func__[] */
1596 if (context_getFlag (FLG_GNUEXTENSIONS))
1600 if (cstring_equalLit (id, "__stdcall")
1601 || cstring_equalLit (id, "__cdecl")
1602 || cstring_equalLit (id, "__extension__"))
1606 else if (cstring_equalLit (id, "__volatile__"))
1610 else if (cstring_equalLit (id, "__signed"))
1614 else if (cstring_equalLit (id, "__unsigned"))
1618 else if (cstring_equalLit (id, "__const__"))
1622 else if (cstring_equalLit (id, "__alignof__"))
1624 tok = CALIGNOF; /* alignof is parsed like sizeof */
1626 else if (cstring_equalLit (id, "__typeof__"))
1630 else if (cstring_equalLit (id, "typeof"))
1634 else if (cstring_equalLit (id, "__FUNCTION__")
1635 || cstring_equalLit (id, "__PRETTY_FUNCTION__"))
1637 /* These tokens hold the name of the current function as strings */
1638 /* evans 2001-12-30: changed from exprNode_stringLiteral; bug reported by Jim Zelenka. */
1639 yylval.expr = exprNode_makeConstantString (id, fileloc_copy (g_currentloc));
1641 s_lastWasString = TRUE;
1645 else if (cstring_equalLit (id, "__attribute__")
1646 || cstring_equalLit (id, "__asm__")
1647 || cstring_equalLit (id, "_asm")
1648 || cstring_equalLit (id, "__asm")
1649 || cstring_equalLit (id, "__declspec"))
1652 bool useparens = FALSE;
1653 bool usebraces = FALSE;
1654 bool inquote = FALSE;
1655 bool inescape = FALSE;
1658 while ((ic = cscanner_input ()) != EOF)
1660 char cc = (char) ic;
1666 else if (cc == '\\')
1670 else if (cc == '\"')
1706 else if (cc == ')' && useparens)
1709 if (depth == 0) break;
1711 else if (cc == '}' && usebraces)
1714 if (depth == 0) break;
1717 && !usebraces && !useparens
1718 && cstring_equalLit (id, "__asm"))
1721 ** We need this because some MS VC++ include files
1722 ** have __asm mov ... }
1723 ** Its a kludge, but otherwise would need to parse
1740 context_incLineno ();
1742 if (cstring_equalLit (id, "__asm")
1743 && !useparens && !usebraces)
1750 llassert ((useparens && ic == (int) ')')
1751 || (usebraces && ic == (int) '}')
1752 || (!useparens && !usebraces));
1756 else if (cstring_equalLit (id, "inline")
1757 || cstring_equalLit (id, "__inline")
1758 || cstring_equalLit (id, "_inline")
1759 || cstring_equalLit (id, "__inline__"))
1770 return (cscannerHelp_returnToken (tok));
1774 le = usymtab_lookupSafe (id);
1776 /*@-dependenttrans@*/
1778 if (uentry_isIter (le))
1783 else if (uentry_isEndIter (le))
1786 return (ITER_ENDNAME);
1788 else if (uentry_isUndefined (le))
1790 yylval.cname = cstring_copy (id);
1792 /* avoid parse errors for certain system built ins */
1794 if (s_expectingTypeName && (cstring_firstChar (id) == '_')
1795 && (cstring_secondChar (id) == '_'))
1797 return (TYPE_NAME_OR_ID);
1800 return (NEW_IDENTIFIER);
1802 else if (!uentry_isDeclared (le) && !uentry_isCodeDefined (le))
1804 if (uentry_isDatatype (le))
1806 yylval.cname = cstring_copy (id);
1807 return (NEW_IDENTIFIER);
1812 return (IDENTIFIER);
1815 else if (uentry_isDatatype (le))
1817 if (!s_expectingTypeName)
1819 yylval.cname = cstring_copy (id);
1821 return (NEW_IDENTIFIER);
1825 yylval.ctyp = uentry_getAbstractType (le);
1827 uentry_setUsed (le, g_currentloc);
1834 return (IDENTIFIER);
1837 /*@=dependenttrans@*/
1840 bool cscannerHelp_processHashIdentifier (/*@only@*/ cstring id)
1842 if (context_inMacro () || context_inIterDef () ||
1843 context_inIterEnd ())
1847 context_clearJustPopped ();
1849 le = usymtab_lookupSafe (id);
1850 cscanner_setLastIdentifier (id);
1852 if (uentry_isParam (le) || uentry_isRefParam (le))
1864 ** Will be handled by handleLlSpecial
1872 /*@only@*/ exprNode cscannerHelp_processString (void)
1876 char *nl = strchr (yytext, '\n');
1877 cstring ns = cstring_fromCharsNew (yytext);
1881 loc = fileloc_copy (g_currentloc);
1882 addColumn (size_toInt (cstring_length (ns)));
1888 loc = fileloc_copy (g_currentloc);
1890 context_incLineno ();
1892 while ((nl = strchr ((nl + 1), '\n')) != NULL)
1894 context_incLineno ();
1900 res = exprNode_stringLiteral (ns, loc);
1905 ** process a wide character string L"...."
1908 /*@only@*/ exprNode cscannerHelp_processWideString ()
1912 char *nl = strchr (yytext, '\n');
1915 llassert (*yytext == 'L');
1918 ns = cstring_fromCharsNew (yytext);
1922 loc = fileloc_copy (g_currentloc);
1923 addColumn (size_toInt (cstring_length (ns)));
1929 loc = fileloc_copy (g_currentloc);
1931 context_incLineno ();
1933 while ((nl = strchr ((nl + 1), '\n')) != NULL)
1935 context_incLineno ();
1940 res = exprNode_wideStringLiteral (ns, loc);
1944 char cscannerHelp_processChar ()
1949 llassert (*yytext != '\0');
1950 fchar = *(yytext + 1);
1951 if (fchar != '\\') return fchar;
1953 next = *(yytext + 2);
1957 case 'n': return '\n';
1958 case 't': return '\t';
1959 case '\"': return '\"';
1960 case '\'': return '\'';
1961 case '\\': return '\\';
1962 default: return '\0';
1966 double cscannerHelp_processFloat ()
1968 double ret = atof (yytext);
1973 long cscannerHelp_processHex ()
1978 llassert (yytext[0] == '0'
1979 && (yytext[1] == 'X' || yytext[1] == 'x'));
1981 while (yytext[index] != '\0') {
1983 char c = yytext[index];
1985 if (c >= '0' && c <= '9') {
1986 tval = (int) c - (int) '0';
1987 } else if (c >= 'A' && c <= 'F') {
1988 tval = (int) c - (int) 'A' + 10;
1989 } else if (c >= 'a' && c <= 'f') {
1990 tval = (int) c - (int) 'a' + 10;
1991 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
1993 while (yytext[index] != '\0') {
1994 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
1999 message ("Invalid character (%c) following specifier in hex constant: %s",
2000 c, cstring_fromChars (yytext)),
2010 message ("Invalid character (%c) in hex constant: %s",
2011 c, cstring_fromChars (yytext)),
2016 val = (val * 16) + tval;
2020 DPRINTF (("Hex constant: %s = %ld", yytext, val));
2024 long cscannerHelp_processOctal ()
2029 llassert (yytext[0] == '0' && yytext[1] != 'X' && yytext[1] != 'x');
2031 while (yytext[index] != '\0') {
2033 char c = yytext[index];
2035 if (c >= '0' && c <= '7') {
2036 tval = (int) c - (int) '0';
2037 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2039 while (yytext[index] != '\0') {
2040 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2045 message ("Invalid character (%c) following specifier in octal constant: %s",
2046 c, cstring_fromChars (yytext)),
2056 message ("Invalid character (%c) in octal constant: %s",
2057 c, cstring_fromChars (yytext)),
2062 val = (val * 8) + tval;
2066 DPRINTF (("Octal constant: %s = %ld", yytext, val));
2070 long cscannerHelp_processDec ()
2072 return (atol (yytext));
2075 int cscannerHelp_processSpec (int tok)
2077 size_t length = strlen (yytext);
2083 patched to fix assert failures in constraint code.
2084 Added the else if test so that splint does not treat MaxSet and MaxRead
2087 if (s_whichSpecPart == QMODIFIES
2088 || s_whichSpecPart == QDEFINES
2089 || s_whichSpecPart == QUSES
2090 || s_whichSpecPart == QALLOCATES
2091 || s_whichSpecPart == QSETS
2092 || s_whichSpecPart == QRELEASES)
2095 DPRINTF((message("Treating specifaction keyword %s as an identifiers. (This corresponds to"
2096 " token %d and we're in the specification denoted by %d see cgrammar_tokens.h"
2097 " for an explanation of these numbers",
2098 yytext, tok, s_whichSpecPart)
2101 ; /* Allow specificiation keywords to be used as identifiers in these contexts. */
2103 else if ( (s_whichSpecPart == QPRECLAUSE
2104 || s_whichSpecPart == QPOSTCLAUSE
2105 || s_whichSpecPart == QINVARIANT )
2106 && (!cscannerHelp_isConstraintToken(tok) )
2109 DPRINTF((message("Treating specifaction keyword %s as an identifiers. (This corresponds to"
2110 " token %d and we're in the specification denoted by %d see cgrammar_tokens.h"
2111 " for an explanation of these numbers",
2112 yytext, tok, s_whichSpecPart)
2115 /* Allow specificiation keywords to be used as identifiers in these contexts. */
2119 cscannerHelp_setTokLengthT (length);
2120 return cscannerHelp_returnToken (tok);
2124 context_saveLocation ();
2125 cscannerHelp_setTokLengthT (length);
2126 return (cscannerHelp_processIdentifier (cscannerHelp_makeIdentifier (yytext)));
2129 void cscannerHelp_expectingMetaStateName ()
2131 llassert (!s_expectingMetaStateName);
2132 llassert (context_inFunctionHeader ());
2133 s_expectingMetaStateName = TRUE;
2136 void cscannerHelp_clearExpectingMetaStateName ()
2138 llassert (s_expectingMetaStateName);
2139 s_expectingMetaStateName = FALSE;
2142 bool cscannerHelp_isConstraintToken (int tok)
2143 /* drl added 12/11/2002
2144 Tell whether a token has special meaning
2145 within a function constraint
2148 return (tok == QMAXSET || tok == QMAXREAD);
2149 /* || tok == QMINREAD || tok == QMINSET */
2150 /* uncomment the additional if statement tests when minSet and minRead are supported */
2153 bool cscannerHelp_processMacro (void)
2158 cstring fname = cstring_undefined;
2160 bool isspecfcn = FALSE;
2161 bool isiter = FALSE;
2162 bool skipparam = FALSE;
2163 bool isenditer = FALSE;
2164 bool unknownm = FALSE;
2165 bool hasParams = FALSE;
2166 bool emptyMacro = FALSE;
2167 char c = skip_whitespace ();
2168 fileloc loc = fileloc_noColumn (g_currentloc);
2170 /* are both of these necessary? what do they mean? */
2171 uentryList specparams = uentryList_undefined;
2172 uentryList pn = uentryList_undefined;
2174 context_resetMacroMissingParams ();
2176 if (c == '\0' || c == '\n')
2178 llcontbug (cstring_makeLiteral ("Bad macro"));
2183 fname = cstring_appendChar (fname, c);
2185 while ((c = macro_nextChar ()) != '(' && c != '\0'
2186 && c != ' ' && c != '\t' && c != '\n')
2188 fname = cstring_appendChar (fname, c);
2191 if (c == ' ' || c == '\t' || c == '\n')
2197 while (c == ' ' || c == '\t')
2199 c = macro_nextChar ();
2201 cscanner_unput ((int) c);
2207 cscanner_unput ((int) c);
2213 hasParams = (c == '(');
2215 if (usymtab_exists (fname))
2217 e2 = usymtab_lookupExpose (fname);
2218 ct = uentry_getType (e2);
2220 if (uentry_isCodeDefined (e2)
2221 && fileloc_isUser (uentry_whereDefined (e2)))
2225 message ("Macro %s already defined", fname),
2228 uentry_showWhereDefined (e2);
2229 uentry_clearDefined (e2);
2232 if (uentry_isFunction (e2))
2234 uentry_setType (e2, ctype_unknown);
2237 context_enterUnknownMacro (e2);
2241 context_enterConstantMacro (e2);
2246 if (uentry_isForward (e2) && uentry_isFunction (e2))
2253 ("Parameterized macro has no prototype or specification: %s ",
2258 uentry_setType (e2, ctype_unknown);
2259 uentry_setFunctionDefined (e2, loc);
2260 uentry_setUsed (e2, fileloc_undefined);
2261 context_enterUnknownMacro (e2);
2265 if (uentry_isIter (e2))
2268 specparams = uentry_getParams (e2);
2269 noparams = uentryList_size (specparams);
2270 uentry_setDefined (e2, loc);
2271 context_enterIterDef (e2);
2273 else if (uentry_isEndIter (e2))
2276 uentry_setDefined (e2, loc);
2277 context_enterIterEnd (e2); /* don't care about it now */
2278 /* but should parse like an iter! */
2280 else if (uentry_isConstant (e2))
2286 message ("Constant %s implemented as parameterized macro",
2290 uentry_showWhereSpecified (e2);
2291 uentry_setType (e2, ctype_unknown);
2292 uentry_makeConstantFunction (e2);
2293 uentry_setDefined (e2, g_currentloc);
2294 uentry_setFunctionDefined (e2, g_currentloc);
2295 context_enterUnknownMacro (e2);
2299 if (!uentry_isSpecified (e2))
2301 fileloc oloc = uentry_whereDeclared (e2);
2303 if (fileloc_isLib (oloc))
2307 else if (fileloc_isUndefined (oloc)
2308 || fileloc_isPreproc (oloc))
2313 (FLG_MACROCONSTDECL,
2315 ("Macro constant %q not declared",
2316 uentry_getName (e2)),
2320 else if (!fileloc_withinLines (oloc, loc, 2))
2321 { /* bogus! will give errors if there is too much whitespace */
2325 ("Macro constant name %s does not match name in "
2326 "previous constant declaration. This constant "
2327 "is declared at %q", fname,
2328 fileloc_unparse (oloc)),
2337 context_enterConstantMacro (e2);
2338 cstring_free (fname);
2344 else if (ctype_isFunction (ct))
2347 specparams = ctype_argsFunction (ct);
2348 noparams = uentryList_size (specparams);
2350 uentry_setFunctionDefined (e2, loc);
2351 context_enterMacro (e2);
2353 else if (uentry_isVar (e2))
2359 message ("Variable %s implemented as parameterized macro",
2363 uentry_showWhereSpecified (e2);
2364 uentry_setType (e2, ctype_unknown);
2365 uentry_makeVarFunction (e2);
2366 uentry_setDefined (e2, g_currentloc);
2367 uentry_setFunctionDefined (e2, g_currentloc);
2368 context_enterUnknownMacro (e2);
2372 uentry ucons = uentry_makeConstant (fname,
2375 if (uentry_isExpandedMacro (e2))
2383 message ("Variable %s implemented by a macro",
2387 uentry_showWhereSpecified (e2);
2391 uentry_setDefined (e2, loc);
2392 uentry_setUsed (ucons, loc);
2394 context_enterConstantMacro (ucons);
2395 uentry_markOwned (ucons);
2396 cstring_free (fname);
2402 if (uentry_isDatatype (e2))
2406 message ("Type implemented as macro: %x",
2407 uentry_getName (e2)),
2408 message ("A type is implemented using a macro definition. A "
2409 "typedef should be used instead."),
2412 cscannerHelp_swallowMacro ();
2413 /* Must exit scope (not sure why a new scope was entered?) */
2414 usymtab_quietExitScope (g_currentloc);
2415 uentry_setDefined (e2, g_currentloc);
2421 (message ("Unexpanded macro not function or constant: %q",
2422 uentry_unparse (e2)));
2423 uentry_setType (e2, ctype_unknown);
2427 uentry_makeVarFunction (e2);
2428 uentry_setDefined (e2, g_currentloc);
2429 uentry_setFunctionDefined (e2, g_currentloc);
2430 context_enterUnknownMacro (e2);
2441 /* evans 2001-09-09 - if it has params, assume a function */
2445 (FLG_MACROMATCHNAME,
2446 message ("Unexpanded macro %s does not match name of a declared "
2447 "function. The name used in the control "
2448 "comment on the previous line should match.",
2452 ce = uentry_makeFunction (fname, ctype_unknown,
2456 warnClause_undefined,
2458 uentry_setUsed (ce, loc); /* perhaps bogus? */
2459 e2 = usymtab_supEntryReturn (ce);
2460 context_enterUnknownMacro (e2);
2465 (FLG_MACROMATCHNAME,
2466 message ("Unexpanded macro %s does not match name of a constant "
2467 "or iter declaration. The name used in the control "
2468 "comment on the previous line should match. "
2469 "(Assuming macro defines a constant.)",
2473 ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);
2474 uentry_setUsed (ce, loc); /* perhaps bogus? */
2475 e2 = usymtab_supEntryReturn (ce);
2477 context_enterConstantMacro (e2);
2478 cstring_free (fname);
2484 /* in macros, ( must follow immediatetly after name */
2490 c = skip_whitespace ();
2492 while (c != ')' && c != '\0')
2495 bool suppress = context_inSuppressRegion ();
2496 cstring paramname = cstring_undefined;
2499 ** save the parameter location
2503 context_saveLocation ();
2506 while (c != ' ' && c != '\t' && c != ',' && c != '\0' && c != ')')
2508 paramname = cstring_appendChar (paramname, c);
2509 c = macro_nextChar ();
2512 if (c == ' ' || c == '\t') c = skip_whitespace ();
2516 c = macro_nextChar ();
2517 if (c == ' ' || c == '\t') c = skip_whitespace ();
2522 llfatalerror (cstring_makeLiteral
2523 ("Bad macro syntax: uentryList"));
2526 if ((isspecfcn || isiter) && (paramno < noparams)
2527 && !uentry_isElipsisMarker (uentryList_getN
2528 (specparams, paramno)))
2530 fileloc sloc = context_getSaveLocation ();
2531 uentry decl = uentryList_getN (specparams, paramno);
2534 param = uentry_nameCopy (paramname, decl);
2536 uentry_setParam (param);
2537 sr = sRef_makeParam (paramno, uentry_getType (param),
2538 stateInfo_makeLoc (sloc, SA_DECLARED));
2540 if (sRef_getNullState (sr) == NS_ABSNULL)
2542 ctype pt = ctype_realType (uentry_getType (param));
2544 if (ctype_isUser (pt))
2546 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (pt));
2548 if (uentry_isValid (te))
2550 sRef_setStateFromUentry (sr, te);
2555 sRef_setNullState (sr, NS_UNKNOWN, sloc);
2559 uentry_setSref (param, sr);
2560 uentry_setDeclaredForceOnly (param, sloc);
2562 skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
2566 fileloc sloc = context_getSaveLocation ();
2568 param = uentry_makeVariableSrefParam
2569 (paramname, ctype_unknown, fileloc_copy (sloc),
2570 sRef_makeParam (paramno, ctype_unknown,
2571 stateInfo_makeLoc (sloc, SA_DECLARED)));
2572 DPRINTF (("Unknown param: %s", uentry_unparseFull (param)));
2573 cstring_free (paramname);
2575 sRef_setPosNull (uentry_getSref (param), sloc);
2576 uentry_setDeclaredForce (param, sloc);
2579 fileloc_free (sloc);
2584 llassert (!uentry_isElipsisMarker (param));
2588 sRef_makeUnsafe (uentry_getSref (param));
2591 pn = uentryList_add (pn, uentry_copy (param));
2592 usymtab_supEntry (param);
2596 /* don't add param */
2597 uentry_free (param);
2602 (void) macro_nextChar ();
2603 c = skip_whitespace ();
2611 if (isspecfcn || isiter)
2613 if (paramno != noparams && noparams >= 0)
2615 cscannerHelp_advanceLine ();
2619 message ("Macro %s specified with %d args, defined with %d",
2620 fname, noparams, paramno),
2623 uentry_showWhereSpecified (e2);
2624 uentry_resetParams (e2, pn);
2629 uentry_resetParams (e2, pn);
2636 ** the form should be:
2638 ** # define newname oldname
2639 ** where oldname refers to a function matching the specification
2645 sRef_setGlobalScope ();
2646 usymtab_supGlobalEntry (uentry_makeVariableLoc (fname, ctype_unknown));
2647 sRef_clearGlobalScope ();
2651 context_setMacroMissingParams ();
2656 /* context_setuentryList (pn); */
2657 usymtab_enterScope ();
2660 cstring_free (fname);
2665 void cscannerHelp_setTokLength (int len)
2669 DPRINTF (("Set tok length: %d", len));
2672 void cscannerHelp_setTokLengthT (size_t len)
2674 cscannerHelp_setTokLength (size_toInt (len));
2677 void cscannerHelp_advanceLine (void)
2683 int cscannerHelp_returnToken (int t)
2685 yylval.tok = lltok_create (t, fileloc_decColumn (g_currentloc, s_tokLength));
2687 s_lastWasString = FALSE;
2691 int cscannerHelp_returnTokenLength (int t, int length)
2693 cscannerHelp_setTokLength (length);
2694 return cscannerHelp_returnToken (t);
2697 int cscannerHelp_returnString (cstring s)
2699 yylval.expr = exprNode_stringLiteral (s, fileloc_decColumn (g_currentloc, s_tokLength));
2701 s_lastWasString = TRUE;
2705 int cscannerHelp_returnInt (ctype ct, long val)
2709 if (ctype_equal (ct, ctype_int))
2713 c = context_typeofZero ();
2717 c = context_typeofOne ();
2725 yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
2726 fileloc_decColumn (g_currentloc, s_tokLength),
2729 s_lastWasString = FALSE;
2733 int cscannerHelp_returnFloat (ctype ct, double f)
2735 yylval.expr = exprNode_floatLiteral (f, ct, cstring_fromChars (yytext),
2736 fileloc_decColumn (g_currentloc, s_tokLength));
2738 s_lastWasString = FALSE;
2742 int cscannerHelp_returnChar (char c)
2744 yylval.expr = exprNode_charLiteral (c, cstring_fromChars (yytext),
2745 fileloc_decColumn (g_currentloc, s_tokLength));
2747 s_lastWasString = FALSE;
2751 int cscannerHelp_returnType (int tok, ctype ct)
2755 s_lastWasString = FALSE;
2759 int cscannerHelp_returnExpr (exprNode e)
2763 s_lastWasString = TRUE;
2767 void cscannerHelp_setExpectingTypeName ()
2769 s_expectingTypeName = TRUE;
2772 void cscannerHelp_clearExpectingTypeName ()
2774 s_expectingTypeName = FALSE;
2777 bool cscannerHelp_isExpectingTypeName ()
2779 return s_expectingTypeName;
2782 int cscannerHelp_processTextIdentifier (char *text)
2784 context_saveLocation ();
2785 cscannerHelp_setTokLength (size_toInt (mstring_length (text)));
2786 return cscannerHelp_processIdentifier (cscannerHelp_makeIdentifier (text));
2789 static bool s_continueLine = FALSE;
2791 int cscannerHelp_handleNewLine ()
2793 context_incLineno ();
2795 if (s_tokLength != 0) {
2797 /* No error to report
2800 message ("Likely parse error: token spans multiple lines."),
2807 s_continueLine = FALSE;
2811 if (context_inMacro ())
2813 /* Don't use return cscannerHelp_returnToken */
2814 /* !!! evans 2002-03-13 */
2815 yylval.tok = lltok_create (TENDMACRO, fileloc_copy (g_currentloc));
2816 s_lastWasString = FALSE;
2824 void cscannerHelp_setContinueLine ()
2826 s_continueLine = TRUE;
2829 void cscannerHelp_exitSpecPart ()
2831 llassert (s_inSpecPart);
2832 s_inSpecPart = FALSE;
2833 s_whichSpecPart = BADTOK;