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 == '@') */
408 llassert (FALSE); /*@i23@*/
409 if (cscannerHelp_handleLlSpecial () != BADTOK)
411 llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
414 return macro_nextChar ();
417 else if (!in_escape && c == '\"')
419 in_quote = !in_quote;
421 else if (!in_escape && c == '\'')
425 else if ((in_quote || in_char) && c == '\\')
427 in_escape = !in_escape;
429 else if ((in_quote || in_char) && in_escape)
433 else if (!in_quote && c == '/')
437 if ((c2 = char_fromInt (lminput ())) == '*')
441 while ((c2 = char_fromInt (lminput ())) != '\0'
442 && c2 != '\n' && c2 != '*')
449 while ((c2 = char_fromInt (lminput ())) != '\0'
462 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
466 return macro_nextChar ();
470 /*** putchar does not work! why? puts to stdio...??! ***/
483 ** keeps semantic comments
486 static char macro_nextCharC (void)
488 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
491 c = char_fromInt (lminput ());
493 if (!in_quote && !in_char && c == '\\')
495 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
497 ; /* skip to newline */
500 context_incLineno ();
504 return macro_nextCharC ();
511 else if (!in_escape && c == '\"')
513 in_quote = !in_quote;
515 else if (!in_escape && c == '\'')
519 else if ((in_quote || in_char) && c == '\\')
521 in_escape = !in_escape;
523 else if ((in_quote || in_char) && in_escape)
527 else if (!in_quote && c == '/')
531 if ((c2 = char_fromInt (lminput ())) == '*')
535 while ((c2 = char_fromInt (lminput ())) != '\0'
536 && c2 != '\n' && c2 != '*')
543 while ((c2 = char_fromInt (lminput ())) != '\0'
556 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
560 return macro_nextCharC ();
567 else /* normal character */
576 ** skips whitespace (handles line continuations)
577 ** returns first non-whitespace character
580 static char skip_whitespace (void)
584 while ((c = macro_nextChar ()) == ' ' || c == '\t')
592 void cscannerHelp_handleMacro ()
594 cstring mac = cstring_undefined;
598 while (currentColumn () > 2)
600 mac = cstring_appendChar (mac, ' ');
601 cscannerHelp_setTokLength (-1);
604 c = macro_nextCharC ();
606 if (c >= '0' && c <= '9')
610 for (i = 0; i < (((int) (c - '0')) + 1); i++)
612 mac = cstring_appendChar (mac, ' ');
620 while (((c = macro_nextCharC ()) != '\0') && (c != '\n'))
622 mac = cstring_appendChar (mac, c);
626 macrocode = tokenMacroCode (mac);
628 if (macrocode == BADTOK && !isArtificial (mac))
630 context_addMacroCache (mac);
639 context_incLineno ();
643 bool cscannerHelp_handleSpecial (char *yyt)
645 char *l; /* !! = mstring_create (MAX_NAME_LENGTH); */
652 len_yyt = strlen (yyt +1) ;
654 l = mstring_copy (yyt + 1);
656 while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
658 l = mstring_append(l, c);
661 /* Need to safe original l for deallocating. */
666 olc = cstring_fromChars (ol);
668 if (cstring_equalPrefixLit (olc, "pragma"))
670 char *pname = mstring_create (size_fromInt (MAX_PRAGMA_LEN));
671 char *opname = pname;
672 char *ptr = ol + 6; /* pragma is six characters, plus space */
676 /* skip whitespace */
677 while (((c = *ptr) != '\0') && isspace (c))
683 while (((c = *ptr) != '\0') && !isspace (c))
687 if (len > MAX_PRAGMA_LEN)
698 if (len == PRAGMA_LEN_EXPAND
699 && mstring_equal (opname, PRAGMA_EXPAND))
701 cstring exname = cstring_undefined;
705 while (((c = *ptr) != '\0') && !isspace (c))
707 exname = cstring_appendChar (exname, c);
712 ue = usymtab_lookupExposeGlob (exname);
714 if (uentry_isExpandedMacro (ue))
716 if (fileloc_isPreproc (uentry_whereDefined (ue)))
718 fileloc_setColumn (g_currentloc, 1);
719 uentry_setDefined (ue, g_currentloc);
723 cstring_free (exname);
726 else if (cstring_equalPrefixLit (olc, "ident"))
728 /* Some pre-processors will leave these in the code. Ignore rest of line */
731 ** Yuk...Win32 filenames can have spaces in them...we need to read
732 ** to the matching end quote.
734 else if ((sscanf (ol, "line %d \"", &lineno) == 1)
735 || (sscanf (ol, " %d \"", &lineno) == 1))
742 while (*tmp != '\"' && *tmp != '\0')
747 llassert (*tmp == '\"');
753 while (*tmp != '\"' && *tmp != '\0')
758 llassert (*tmp == '\"');
762 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
765 ** DOS-like path delimiters get delivered in pairs, something like
766 ** \"..\\\\file.h\", so we have to make it normal again. We do NOT
767 ** remove the pre dirs yet as we usually specify tmp paths relative
768 ** to the current directory, so tmp files would not get found in
769 ** the hash table. If this method fails we try it again later.
776 ** Skip past the drive marker.
779 if (strchr (stmp, ':') != NULL)
781 stmp = strchr (stmp, ':') + 1;
784 while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
786 if (*(stmp+1) == CONNECTCHAR)
788 memmove (stmp, stmp+1, strlen (stmp));
794 fid = fileTable_lookupBase (context_fileTable (), fname);
795 if (!(fileId_isValid (fid)))
797 fname = removePreDirs (fname);
798 fid = fileTable_lookupBase (context_fileTable (), fname);
801 # else /* !defined(OS2) && !defined(MSDOS) */
802 fname = removePreDirs (fname);
803 fid = fileTable_lookupBase (context_fileTable (), fname);
804 # endif /* !defined(OS2) && !defined(MSDOS) */
806 if (!(fileId_isValid (fid)))
808 if (context_inXHFile ())
810 fid = fileTable_addXHFile (context_fileTable (), fname);
812 else if (isHeaderFile (fname))
814 fid = fileTable_addHeaderFile (context_fileTable (), fname);
818 fid = fileTable_addFile (context_fileTable (), fname);
822 setFileLine (fid, lineno);
823 /*@noaccess cstring@*/
825 else if ((sscanf (ol, "line %d", &lineno) == 1)
826 || (sscanf (ol, " %d", &lineno) == 1))
828 setLine (lineno); /* next line is <cr> */
832 if (mstring_equal (ol, "")) {
833 DPRINTF (("Empty pp command!"));
835 ** evs 2000-05-16: This is a horrible kludge, to get around a bug (well, difficulty) in the pre-processor.
836 ** We handle a plain # in the input file, by echoing it, and ignoring it in the post-pp-file.
842 (FLG_UNRECOGDIRECTIVE,
843 message ("Unrecognized pre-processor directive: #%s",
844 cstring_fromChars (ol)),
849 return FALSE; /* evans 2001-12-30: was: TRUE; */
856 int cscannerHelp_handleLlSpecial (void)
861 char *s = mstring_createEmpty ();
867 loc = fileloc_copy (g_currentloc);
868 DPRINTF (("Handle special: %s", fileloc_unparse (loc)));
870 while (((ic = cscannerHelp_ninput ()) != 0) && isalpha (ic))
873 s = mstring_append (s, c);
877 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
880 if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
882 ic = cscannerHelp_ninput ();
884 llassert (ic == (int) AFTER_COMMENT_MARKER[1]);
890 return QNOMODS; /* special token no modifications token */
894 DPRINTF (("Coment marker: %s", os));
895 tok = commentMarkerToken (cstring_fromChars (os));
899 s_tokLength = charsread;
902 s_whichSpecPart = tok;
907 DPRINTF (("Not a comment marker..."));
908 /* Add rest of the comment */
910 if (ic != 0 && ic != EOF)
914 s = mstring_append (s, c);
917 while (((ic = cscannerHelp_ninput ()) != 0) && (ic != EOF)
918 && (ic != (int) AFTER_COMMENT_MARKER[0]))
922 /* evans 2001-09-01 added to prevent assertion failures for uncloses syntactic comments */
925 hasnl = TRUE; /* This prevents tokLength from being set later. */
930 message ("Likely parse error: syntactic comment token spans multiple lines: %s",
931 cstring_fromChars (s)),
935 s = mstring_append (s, c);
940 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
942 if (ic == (int) AFTER_COMMENT_MARKER[0])
944 int nc = cscannerHelp_ninput ();
945 llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
951 while (*s == ' ' || *s == '\t' || *s == '\n')
956 if (*s == '-' || *s == '+' || *s == '=') /* setting flags */
960 while (c == '-' || c == '+' || c == '=')
962 ynm set = ynm_fromCodeChar (c);
967 thisflag = cstring_fromChars (s);
969 while ((c = *s) != '\0' && (c != '-') && (c != '=')
970 && (c != '+') && (c != ' ') && (c != '\t') && (c != '\n'))
977 if (!context_getFlag (FLG_NOCOMMENTS))
979 cstring flagname = thisflag;
980 flagcode fflag = flags_identifyFlag (flagname);
982 if (flagcode_isSkip (fflag))
986 else if (flagcode_isModeName (fflag))
988 if (ynm_isMaybe (set))
993 ("Semantic comment attempts to restore flag %s. "
994 "A mode flag cannot be restored.",
999 context_setMode (flagname);
1002 else if (flagcode_isInvalid (fflag))
1005 (FLG_UNRECOGFLAGCOMMENTS,
1006 message ("Unrecognized option in semantic comment: %s",
1010 else if (flagcode_isGlobalFlag (fflag))
1015 ("Semantic comment attempts to set global flag %s. "
1016 "A global flag cannot be set locally.",
1022 context_fileSetFlag (fflag, set, loc);
1024 if (flagcode_hasArgument (fflag))
1026 if (ynm_isMaybe (set))
1031 ("Semantic comment attempts to restore flag %s. "
1032 "A flag for setting a value cannot be restored.",
1037 { /* cut-and-pastied from llmain...blecch */
1038 cstring extra = cstring_undefined;
1044 rest = mstring_copy (s);
1048 while ((rchar = *rest) != '\0'
1049 && (isspace (rchar)))
1055 while ((rchar = *rest) != '\0'
1056 && !isspace (rchar))
1058 extra = cstring_appendChar (extra, rchar);
1062 s--; /* evans 2002-07-12: this was previously only in the else branch.
1063 Leads to an invalid read on the true branch.
1068 if (cstring_isUndefined (extra))
1073 ("Flag %s (in semantic comment) must be followed by an argument",
1074 flagcode_unparse (fflag)));
1076 cstring_free (extra);
1080 if (flagcode_hasNumber (fflag))
1082 flags_setValueFlag (fflag, extra);
1084 else if (flagcode_hasChar (fflag))
1086 flags_setValueFlag (fflag, extra);
1088 else if (flagcode_hasString (fflag))
1090 flags_setStringFlag (fflag, extra);
1094 cstring_free (extra);
1108 while ((c == ' ') || (c == '\t') || (c == '\n'))
1114 if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
1116 DPRINTF (("Here adding comment: %s", os));
1117 context_addComment (cstring_fromCharsNew (os), loc);
1129 annotationInfo ainfo;
1131 while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
1143 t = cstring_toCharsSafe (cstring_downcase (cstring_fromChars (t)));
1144 macrocode = tokenMacroCode (cstring_fromChars (t));
1146 if (macrocode != BADTOK)
1148 s_tokLength = hasnl ? 0 : size_toInt (mstring_length (t));
1154 if (macrocode == SKIPTOK)
1162 ainfo = context_lookupAnnotation (cstring_fromChars (os));
1164 if (annotationInfo_isDefined (ainfo)) {
1165 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
1166 /*@i324@*/ yylval.annotation = ainfo;
1174 if (context_inHeader ())
1181 if ((context_inMacro () || context_inGlobalContext ())
1182 && macrocode != SKIPTOK
1183 && !isArtificial (cstring_fromChars (os)))
1185 if (context_processingMacros ())
1187 /* evans 2002-02-24: don't add comments when procssing macros */
1191 context_addComment (cstring_fromCharsNew (os), loc);
1205 if (mstring_equal (t, "ignore"))
1207 if (!context_getFlag (FLG_NOCOMMENTS))
1209 context_enterSuppressRegion (loc);
1212 else if ((*t == 'i' || *t == 't')
1213 && (*(t + 1) == '\0'))
1215 if (!context_getFlag (FLG_NOCOMMENTS)
1216 && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
1218 context_enterSuppressLine (-1, loc); /* infinite suppression */
1221 else if (((*t == 'i') || (*t == 't'))
1222 && ((*(t + 1) >= '0' && *(t + 1) <= '9')))
1224 bool tmpcomment = (*t == 't');
1226 char *tt = t; /* don't mangle t, since it is free'd */
1229 if (lc >= '0' && lc <= '9')
1231 val = (int)(lc - '0');
1234 while (lc >= '0' && lc <= '9')
1237 val += (int) (lc - '0');
1242 if (!context_getFlag (FLG_NOCOMMENTS)
1243 && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
1245 DPRINTF (("Here: enter suppress: %s", fileloc_unparse (loc)));
1246 context_enterSuppressLine (val, loc);
1249 else if (mstring_equal (t, "end"))
1251 if (!context_getFlag (FLG_NOCOMMENTS))
1253 context_exitSuppressRegion (loc);
1256 else if (mstring_equal (t, "notfunction"))
1258 ; /* handled by pcpp */
1260 else if (mstring_equal (t, "access"))
1266 while (((c = *s) != '\0') && (c == ' ' || c == '\t' || c == '\n'))
1276 tname = cstring_fromChars (s);
1278 while ((c = *s) != '\0' && c != ' '
1279 && c != '\t' && c != '\n' && c != ',')
1286 DPRINTF (("Access %s", tname));
1288 if (!context_getFlag (FLG_NOCOMMENTS)
1289 && !context_getFlag (FLG_NOACCESS))
1291 if (usymtab_existsType (tname))
1293 typeId uid = usymtab_getTypeId (tname);
1294 uentry ue = usymtab_getTypeEntry (uid);
1296 if (uentry_isAbstractDatatype (ue))
1298 context_addFileAccessType (uid);
1299 DPRINTF (("Adding access to: %s / %d", tname, uid));
1306 ("Non-abstract type %s used in access comment",
1313 if (!(context_inSuppressRegion ()
1314 || context_inSuppressZone (loc)))
1319 ("Unrecognized type %s used in access comment",
1331 if (c != ',' && c != ' ')
1337 else if (mstring_equal (t, "noaccess"))
1344 while (((lc = *s) != '\0') && (lc == ' ' || lc == '\t' || lc == '\n'))
1354 tname = cstring_fromChars (s);
1356 while ((lc = *s) != '\0' && lc != ' ' && lc != '\t'
1357 && lc != '\n' && lc != ',')
1364 if (!context_getFlag (FLG_NOCOMMENTS)
1365 && !context_getFlag (FLG_NOACCESS))
1367 if (usymtab_existsType (tname))
1369 typeId tuid = usymtab_getTypeId (tname);
1371 if (context_couldHaveAccess (tuid))
1373 DPRINTF (("Removing access: %s", tname));
1374 context_removeFileAccessType (tuid);
1378 if (!(context_inSuppressRegion ()
1379 || context_inSuppressZone (loc)))
1381 uentry ue = usymtab_getTypeEntry (tuid);
1383 if (uentry_isAbstractDatatype (ue))
1388 ("Non-accessible abstract type %s used in noaccess comment",
1397 ("Non-abstract type %s used in noaccess comment",
1406 if (!(context_inSuppressRegion ()
1407 || context_inSuppressZone (loc)))
1412 ("Unrecognized type %s used in noaccess comment",
1424 if (lc != ',' && lc != ' ')
1432 voptgenerror (FLG_UNRECOGCOMMENTS,
1433 message ("Semantic comment unrecognized: %s",
1434 cstring_fromChars (os)),
1446 /*@only@*/ cstring cscannerHelp_makeIdentifier (char *s)
1448 char *c = mstring_create (strlen (s) + 1);
1449 cstring id = cstring_fromChars (c);
1451 while (isalnum (*s) || (*s == '_') || (*s == '$'))
1460 /*@observer@*/ /*@dependent@*/ uentry cscannerHelp_coerceId (cstring cn)
1462 if (!(usymtab_exists (cn)))
1464 fileloc loc = fileloc_createExternal ();
1467 ** We need to put this in a global scope, otherwise the sRef will be deallocated.
1470 uentry ce = uentry_makeUnrecognized (cn, loc);
1472 if (!context_inIterEnd ())
1476 message ("Unrecognized (possibly system) identifier: %q",
1477 uentry_getName (ce)),
1484 return (usymtab_lookup (cn));
1488 ** like, cscannerHelp_coerceId, but doesn't supercede for iters
1491 /*@observer@*/ uentry cscannerHelp_coerceIterId (cstring cn)
1493 if (!(usymtab_exists (cn)))
1495 return uentry_undefined;
1498 return (usymtab_lookup (cn));
1502 ** Need to keep this in case there is a declaration that isn't processed until
1503 ** the scope exits. Would be good to rearrange the symbol table so this doesn't
1504 ** happen, and save all the cstring copying.
1507 /*@observer@*/ cstring cscannerHelp_observeLastIdentifier ()
1509 cstring res = s_lastidprocessed;
1513 static void cscanner_setLastIdentifier (/*@keep@*/ cstring id) /*@modifies s_lastidprocessed@*/
1515 if (cstring_isDefined (s_lastidprocessed))
1517 cstring_free (s_lastidprocessed);
1520 s_lastidprocessed = id;
1523 int cscannerHelp_processIdentifier (cstring id)
1527 if (context_getFlag (FLG_GRAMMAR))
1529 lldiagmsg (message ("Process identifier: %s", id));
1532 context_clearJustPopped ();
1533 cscanner_setLastIdentifier (id);
1535 DPRINTF (("Context: %s", context_unparse ()));
1537 if (context_inFunctionHeader ())
1539 int tok = commentMarkerToken (id);
1540 DPRINTF (("in function decl: %s", id));
1548 tok = tokenMacroCode (id);
1556 annotationInfo ainfo;
1558 if (s_expectingMetaStateName)
1560 metaStateInfo msinfo = context_lookupMetaStateInfo (id);
1562 if (metaStateInfo_isDefined (msinfo))
1564 yylval.msinfo = msinfo;
1565 return METASTATE_NAME;
1569 DPRINTF (("Not meta state name: %s", cstring_toCharsSafe (id)));
1573 ainfo = context_lookupAnnotation (id);
1575 if (annotationInfo_isDefined (ainfo))
1577 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
1578 /*@i324@*/ yylval.annotation = ainfo;
1583 DPRINTF (("Not annotation: %s", id));
1589 DPRINTF (("Here!"));
1591 /* Consider handling: Defined by C99 as static const char __func__[] */
1593 if (context_getFlag (FLG_GNUEXTENSIONS))
1597 if (cstring_equalLit (id, "__stdcall")
1598 || cstring_equalLit (id, "__cdecl")
1599 || cstring_equalLit (id, "__extension__"))
1603 else if (cstring_equalLit (id, "__volatile__"))
1607 else if (cstring_equalLit (id, "__signed"))
1611 else if (cstring_equalLit (id, "__unsigned"))
1615 else if (cstring_equalLit (id, "__const__"))
1619 else if (cstring_equalLit (id, "__alignof__"))
1621 tok = CALIGNOF; /* alignof is parsed like sizeof */
1623 else if (cstring_equalLit (id, "__typeof__"))
1627 else if (cstring_equalLit (id, "typeof"))
1631 else if (cstring_equalLit (id, "__FUNCTION__")
1632 || cstring_equalLit (id, "__PRETTY_FUNCTION__"))
1634 /* These tokens hold the name of the current function as strings */
1635 /* evans 2001-12-30: changed from exprNode_stringLiteral; bug reported by Jim Zelenka. */
1636 yylval.expr = exprNode_makeConstantString (id, fileloc_copy (g_currentloc));
1638 s_lastWasString = TRUE;
1642 else if (cstring_equalLit (id, "__attribute__")
1643 || cstring_equalLit (id, "__asm__")
1644 || cstring_equalLit (id, "_asm")
1645 || cstring_equalLit (id, "__asm")
1646 || cstring_equalLit (id, "__declspec"))
1649 bool useparens = FALSE;
1650 bool usebraces = FALSE;
1651 bool inquote = FALSE;
1652 bool inescape = FALSE;
1655 while ((ic = cscanner_input ()) != EOF)
1657 char cc = (char) ic;
1663 else if (cc == '\\')
1667 else if (cc == '\"')
1703 else if (cc == ')' && useparens)
1706 if (depth == 0) break;
1708 else if (cc == '}' && usebraces)
1711 if (depth == 0) break;
1714 && !usebraces && !useparens
1715 && cstring_equalLit (id, "__asm"))
1718 ** We need this because some MS VC++ include files
1719 ** have __asm mov ... }
1720 ** Its a kludge, but otherwise would need to parse
1737 context_incLineno ();
1739 if (cstring_equalLit (id, "__asm")
1740 && !useparens && !usebraces)
1747 llassert ((useparens && ic == (int) ')')
1748 || (usebraces && ic == (int) '}')
1749 || (!useparens && !usebraces));
1753 else if (cstring_equalLit (id, "inline")
1754 || cstring_equalLit (id, "__inline")
1755 || cstring_equalLit (id, "_inline")
1756 || cstring_equalLit (id, "__inline__"))
1767 return (cscannerHelp_returnToken (tok));
1771 le = usymtab_lookupSafe (id);
1773 /*@-dependenttrans@*/
1775 if (uentry_isIter (le))
1777 /*@i32@*/ yylval.entry = le;
1780 else if (uentry_isEndIter (le))
1782 /*@i32@*/ yylval.entry = le;
1783 return (ITER_ENDNAME);
1785 else if (uentry_isUndefined (le))
1787 yylval.cname = cstring_copy (id);
1789 /* avoid parse errors for certain system built ins */
1791 if (s_expectingTypeName && (cstring_firstChar (id) == '_')
1792 && (cstring_secondChar (id) == '_'))
1794 return (TYPE_NAME_OR_ID);
1797 return (NEW_IDENTIFIER);
1799 else if (!uentry_isDeclared (le) && !uentry_isCodeDefined (le))
1801 if (uentry_isDatatype (le))
1803 yylval.cname = cstring_copy (id);
1804 return (NEW_IDENTIFIER);
1808 /*@i32@*/ yylval.entry = le;
1809 return (IDENTIFIER);
1812 else if (uentry_isDatatype (le))
1814 if (!s_expectingTypeName)
1816 yylval.cname = cstring_copy (id);
1818 return (NEW_IDENTIFIER);
1822 yylval.ctyp = uentry_getAbstractType (le);
1824 uentry_setUsed (le, g_currentloc);
1830 /*@i32@*/ yylval.entry = le;
1831 return (IDENTIFIER);
1834 /*@=dependenttrans@*/
1837 bool cscannerHelp_processHashIdentifier (/*@only@*/ cstring id)
1839 if (context_inMacro () || context_inIterDef () ||
1840 context_inIterEnd ())
1844 context_clearJustPopped ();
1846 le = usymtab_lookupSafe (id);
1847 cscanner_setLastIdentifier (id);
1849 if (uentry_isParam (le) || uentry_isRefParam (le))
1861 ** Will be handled by handleLlSpecial
1869 /*@only@*/ exprNode cscannerHelp_processString (void)
1873 char *nl = strchr (yytext, '\n');
1874 cstring ns = cstring_fromCharsNew (yytext);
1878 loc = fileloc_copy (g_currentloc);
1879 addColumn (size_toInt (cstring_length (ns)));
1885 loc = fileloc_copy (g_currentloc);
1887 context_incLineno ();
1889 while ((nl = strchr ((nl + 1), '\n')) != NULL)
1891 context_incLineno ();
1897 res = exprNode_stringLiteral (ns, loc);
1902 ** process a wide character string L"...."
1905 /*@only@*/ exprNode cscannerHelp_processWideString ()
1909 char *nl = strchr (yytext, '\n');
1912 llassert (*yytext == 'L');
1915 ns = cstring_fromCharsNew (yytext);
1919 loc = fileloc_copy (g_currentloc);
1920 addColumn (size_toInt (cstring_length (ns)));
1926 loc = fileloc_copy (g_currentloc);
1928 context_incLineno ();
1930 while ((nl = strchr ((nl + 1), '\n')) != NULL)
1932 context_incLineno ();
1937 res = exprNode_wideStringLiteral (ns, loc);
1941 char cscannerHelp_processChar ()
1946 llassert (*yytext != '\0');
1947 fchar = *(yytext + 1);
1948 if (fchar != '\\') return fchar;
1950 next = *(yytext + 2);
1954 case 'n': return '\n';
1955 case 't': return '\t';
1956 case '\"': return '\"';
1957 case '\'': return '\'';
1958 case '\\': return '\\';
1959 default: return '\0';
1963 double cscannerHelp_processFloat ()
1965 double ret = atof (yytext);
1970 long cscannerHelp_processHex ()
1975 llassert (yytext[0] == '0'
1976 && (yytext[1] == 'X' || yytext[1] == 'x'));
1978 while (yytext[index] != '\0') {
1980 char c = yytext[index];
1982 if (c >= '0' && c <= '9') {
1983 tval = (int) c - (int) '0';
1984 } else if (c >= 'A' && c <= 'F') {
1985 tval = (int) c - (int) 'A' + 10;
1986 } else if (c >= 'a' && c <= 'f') {
1987 tval = (int) c - (int) 'a' + 10;
1988 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
1990 while (yytext[index] != '\0') {
1991 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
1996 message ("Invalid character (%c) following specifier in hex constant: %s",
1997 c, cstring_fromChars (yytext)),
2007 message ("Invalid character (%c) in hex constant: %s",
2008 c, cstring_fromChars (yytext)),
2013 val = (val * 16) + tval;
2017 DPRINTF (("Hex constant: %s = %ld", yytext, val));
2021 long cscannerHelp_processOctal ()
2026 llassert (yytext[0] == '0' && yytext[1] != 'X' && yytext[1] != 'x');
2028 while (yytext[index] != '\0') {
2030 char c = yytext[index];
2032 if (c >= '0' && c <= '7') {
2033 tval = (int) c - (int) '0';
2034 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2036 while (yytext[index] != '\0') {
2037 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2042 message ("Invalid character (%c) following specifier in octal constant: %s",
2043 c, cstring_fromChars (yytext)),
2053 message ("Invalid character (%c) in octal constant: %s",
2054 c, cstring_fromChars (yytext)),
2059 val = (val * 8) + tval;
2063 DPRINTF (("Octal constant: %s = %ld", yytext, val));
2067 long cscannerHelp_processDec ()
2069 return (atol (yytext));
2072 int cscannerHelp_processSpec (int tok)
2074 size_t length = strlen (yytext);
2080 patched to fix assert failures in constraint code.
2081 Added the else if test so that splint does not treat MaxSet and MaxRead
2084 if (s_whichSpecPart == QMODIFIES
2085 || s_whichSpecPart == QDEFINES
2086 || s_whichSpecPart == QUSES
2087 || s_whichSpecPart == QALLOCATES
2088 || s_whichSpecPart == QSETS
2089 || s_whichSpecPart == QRELEASES)
2092 DPRINTF((message("Treating specifaction keyword %s as an identifiers. (This corresponds to"
2093 " token %d and we're in the specification denoted by %d see cgrammar_tokens.h"
2094 " for an explanation of these numbers",
2095 yytext, tok, s_whichSpecPart)
2098 ; /* Allow specificiation keywords to be used as identifiers in these contexts. */
2100 else if ( (s_whichSpecPart == QPRECLAUSE
2101 || s_whichSpecPart == QPOSTCLAUSE
2102 || s_whichSpecPart == QINVARIANT )
2103 && (!cscannerHelp_isConstraintToken(tok) )
2106 DPRINTF((message("Treating specifaction keyword %s as an identifiers. (This corresponds to"
2107 " token %d and we're in the specification denoted by %d see cgrammar_tokens.h"
2108 " for an explanation of these numbers",
2109 yytext, tok, s_whichSpecPart)
2112 /* Allow specificiation keywords to be used as identifiers in these contexts. */
2116 cscannerHelp_setTokLengthT (length);
2117 return cscannerHelp_returnToken (tok);
2121 context_saveLocation ();
2122 cscannerHelp_setTokLengthT (length);
2123 return (cscannerHelp_processIdentifier (cscannerHelp_makeIdentifier (yytext)));
2126 void cscannerHelp_expectingMetaStateName ()
2128 llassert (!s_expectingMetaStateName);
2129 llassert (context_inFunctionHeader ());
2130 s_expectingMetaStateName = TRUE;
2133 void cscannerHelp_clearExpectingMetaStateName ()
2135 llassert (s_expectingMetaStateName);
2136 s_expectingMetaStateName = FALSE;
2139 bool cscannerHelp_isConstraintToken (int tok)
2140 /* drl added 12/11/2002
2141 Tell whether a token has special meaning
2142 within a function constraint
2145 return (tok == QMAXSET || tok == QMAXREAD);
2146 /* || tok == QMINREAD || tok == QMINSET */
2148 /* uncomment the additional if statement tests when minSet and minRead are supported */
2151 bool cscannerHelp_processMacro (void)
2156 cstring fname = cstring_undefined;
2158 bool isspecfcn = FALSE;
2159 bool isiter = FALSE;
2160 bool skipparam = FALSE;
2161 bool isenditer = FALSE;
2162 bool unknownm = FALSE;
2163 bool hasParams = FALSE;
2164 bool emptyMacro = FALSE;
2165 char c = skip_whitespace ();
2166 fileloc loc = fileloc_noColumn (g_currentloc);
2168 /* are both of these necessary? what do they mean? */
2169 uentryList specparams = uentryList_undefined;
2170 uentryList pn = uentryList_undefined;
2172 context_resetMacroMissingParams ();
2174 if (c == '\0' || c == '\n')
2176 llcontbug (cstring_makeLiteral ("Bad macro"));
2181 fname = cstring_appendChar (fname, c);
2183 while ((c = macro_nextChar ()) != '(' && c != '\0'
2184 && c != ' ' && c != '\t' && c != '\n')
2186 fname = cstring_appendChar (fname, c);
2189 if (c == ' ' || c == '\t' || c == '\n')
2195 while (c == ' ' || c == '\t')
2197 c = macro_nextChar ();
2199 cscanner_unput ((int) c);
2205 cscanner_unput ((int) c);
2211 hasParams = (c == '(');
2213 if (usymtab_exists (fname))
2215 e2 = usymtab_lookupExpose (fname);
2216 ct = uentry_getType (e2);
2218 if (uentry_isCodeDefined (e2)
2219 && fileloc_isUser (uentry_whereDefined (e2)))
2223 message ("Macro %s already defined", fname),
2226 uentry_showWhereDefined (e2);
2227 uentry_clearDefined (e2);
2230 if (uentry_isFunction (e2))
2232 uentry_setType (e2, ctype_unknown);
2235 context_enterUnknownMacro (e2);
2239 context_enterConstantMacro (e2);
2244 if (uentry_isForward (e2) && uentry_isFunction (e2))
2251 ("Parameterized macro has no prototype or specification: %s ",
2256 uentry_setType (e2, ctype_unknown);
2257 uentry_setFunctionDefined (e2, loc);
2258 uentry_setUsed (e2, fileloc_undefined);
2259 context_enterUnknownMacro (e2);
2263 if (uentry_isIter (e2))
2266 specparams = uentry_getParams (e2);
2267 noparams = uentryList_size (specparams);
2268 uentry_setDefined (e2, loc);
2269 context_enterIterDef (e2);
2271 else if (uentry_isEndIter (e2))
2274 uentry_setDefined (e2, loc);
2275 context_enterIterEnd (e2); /* don't care about it now */
2276 /* but should parse like an iter! */
2278 else if (uentry_isConstant (e2))
2284 message ("Constant %s implemented as parameterized macro",
2288 uentry_showWhereSpecified (e2);
2289 uentry_setType (e2, ctype_unknown);
2290 uentry_makeConstantFunction (e2);
2291 uentry_setDefined (e2, g_currentloc);
2292 uentry_setFunctionDefined (e2, g_currentloc);
2293 context_enterUnknownMacro (e2);
2297 if (!uentry_isSpecified (e2))
2299 fileloc oloc = uentry_whereDeclared (e2);
2301 if (fileloc_isLib (oloc))
2305 else if (fileloc_isUndefined (oloc)
2306 || fileloc_isPreproc (oloc))
2311 (FLG_MACROCONSTDECL,
2313 ("Macro constant %q not declared",
2314 uentry_getName (e2)),
2318 else if (!fileloc_withinLines (oloc, loc, 2))
2319 { /* bogus! will give errors if there is too much whitespace */
2323 ("Macro constant name %s does not match name in "
2324 "previous constant declaration. This constant "
2325 "is declared at %q", fname,
2326 fileloc_unparse (oloc)),
2335 context_enterConstantMacro (e2);
2336 cstring_free (fname);
2342 else if (ctype_isFunction (ct))
2345 specparams = ctype_argsFunction (ct);
2346 noparams = uentryList_size (specparams);
2348 uentry_setFunctionDefined (e2, loc);
2349 context_enterMacro (e2);
2351 else if (uentry_isVar (e2))
2357 message ("Variable %s implemented as parameterized macro",
2361 uentry_showWhereSpecified (e2);
2362 uentry_setType (e2, ctype_unknown);
2363 uentry_makeVarFunction (e2);
2364 uentry_setDefined (e2, g_currentloc);
2365 uentry_setFunctionDefined (e2, g_currentloc);
2366 context_enterUnknownMacro (e2);
2370 uentry ucons = uentry_makeConstant (fname,
2373 if (uentry_isExpandedMacro (e2))
2381 message ("Variable %s implemented by a macro",
2385 uentry_showWhereSpecified (e2);
2389 uentry_setDefined (e2, loc);
2390 uentry_setUsed (ucons, loc);
2392 context_enterConstantMacro (ucons);
2393 uentry_markOwned (ucons);
2394 cstring_free (fname);
2400 if (uentry_isDatatype (e2))
2404 message ("Type implemented as macro: %x",
2405 uentry_getName (e2)),
2406 message ("A type is implemented using a macro definition. A "
2407 "typedef should be used instead."),
2410 cscannerHelp_swallowMacro ();
2411 /* Must exit scope (not sure why a new scope was entered?) */
2412 usymtab_quietExitScope (g_currentloc);
2413 uentry_setDefined (e2, g_currentloc);
2419 (message ("Unexpanded macro not function or constant: %q",
2420 uentry_unparse (e2)));
2421 uentry_setType (e2, ctype_unknown);
2425 uentry_makeVarFunction (e2);
2426 uentry_setDefined (e2, g_currentloc);
2427 uentry_setFunctionDefined (e2, g_currentloc);
2428 context_enterUnknownMacro (e2);
2439 /* evans 2001-09-09 - if it has params, assume a function */
2443 (FLG_MACROMATCHNAME,
2444 message ("Unexpanded macro %s does not match name of a declared "
2445 "function. The name used in the control "
2446 "comment on the previous line should match.",
2450 ce = uentry_makeFunction (fname, ctype_unknown,
2454 warnClause_undefined,
2456 uentry_setUsed (ce, loc); /* perhaps bogus? */
2457 e2 = usymtab_supEntryReturn (ce);
2458 context_enterUnknownMacro (e2);
2463 (FLG_MACROMATCHNAME,
2464 message ("Unexpanded macro %s does not match name of a constant "
2465 "or iter declaration. The name used in the control "
2466 "comment on the previous line should match. "
2467 "(Assuming macro defines a constant.)",
2471 ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);
2472 uentry_setUsed (ce, loc); /* perhaps bogus? */
2473 e2 = usymtab_supEntryReturn (ce);
2475 context_enterConstantMacro (e2);
2476 cstring_free (fname);
2482 /* in macros, ( must follow immediatetly after name */
2488 c = skip_whitespace ();
2490 while (c != ')' && c != '\0')
2493 bool suppress = context_inSuppressRegion ();
2494 cstring paramname = cstring_undefined;
2497 ** save the parameter location
2501 context_saveLocation ();
2504 while (c != ' ' && c != '\t' && c != ',' && c != '\0' && c != ')')
2506 paramname = cstring_appendChar (paramname, c);
2507 c = macro_nextChar ();
2510 if (c == ' ' || c == '\t') c = skip_whitespace ();
2514 c = macro_nextChar ();
2515 if (c == ' ' || c == '\t') c = skip_whitespace ();
2520 llfatalerror (cstring_makeLiteral
2521 ("Bad macro syntax: uentryList"));
2524 if ((isspecfcn || isiter) && (paramno < noparams)
2525 && !uentry_isElipsisMarker (uentryList_getN
2526 (specparams, paramno)))
2528 fileloc sloc = context_getSaveLocation ();
2529 uentry decl = uentryList_getN (specparams, paramno);
2532 param = uentry_nameCopy (paramname, decl);
2534 uentry_setParam (param);
2535 sr = sRef_makeParam (paramno, uentry_getType (param),
2536 stateInfo_makeLoc (sloc, SA_DECLARED));
2538 if (sRef_getNullState (sr) == NS_ABSNULL)
2540 ctype pt = ctype_realType (uentry_getType (param));
2542 if (ctype_isUser (pt))
2544 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (pt));
2546 if (uentry_isValid (te))
2548 sRef_setStateFromUentry (sr, te);
2553 sRef_setNullState (sr, NS_UNKNOWN, sloc);
2557 uentry_setSref (param, sr);
2558 uentry_setDeclaredForceOnly (param, sloc);
2560 skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
2564 fileloc sloc = context_getSaveLocation ();
2566 param = uentry_makeVariableSrefParam
2567 (paramname, ctype_unknown, fileloc_copy (sloc),
2568 sRef_makeParam (paramno, ctype_unknown,
2569 stateInfo_makeLoc (sloc, SA_DECLARED)));
2570 DPRINTF (("Unknown param: %s", uentry_unparseFull (param)));
2571 cstring_free (paramname);
2573 sRef_setPosNull (uentry_getSref (param), sloc);
2574 uentry_setDeclaredForce (param, sloc);
2577 fileloc_free (sloc);
2582 llassert (!uentry_isElipsisMarker (param));
2586 sRef_makeUnsafe (uentry_getSref (param));
2589 pn = uentryList_add (pn, uentry_copy (param));
2590 usymtab_supEntry (param);
2594 /* don't add param */
2595 uentry_free (param);
2600 (void) macro_nextChar ();
2601 c = skip_whitespace ();
2609 if (isspecfcn || isiter)
2611 if (paramno != noparams && noparams >= 0)
2613 cscannerHelp_advanceLine ();
2617 message ("Macro %s specified with %d args, defined with %d",
2618 fname, noparams, paramno),
2621 uentry_showWhereSpecified (e2);
2622 uentry_resetParams (e2, pn);
2627 uentry_resetParams (e2, pn);
2634 ** the form should be:
2636 ** # define newname oldname
2637 ** where oldname refers to a function matching the specification
2643 sRef_setGlobalScope ();
2644 usymtab_supGlobalEntry (uentry_makeVariableLoc (fname, ctype_unknown));
2645 sRef_clearGlobalScope ();
2649 context_setMacroMissingParams ();
2654 /* context_setuentryList (pn); */
2655 usymtab_enterScope ();
2658 cstring_free (fname);
2663 void cscannerHelp_setTokLength (int len)
2667 DPRINTF (("Set tok length: %d", len));
2670 void cscannerHelp_setTokLengthT (size_t len)
2672 cscannerHelp_setTokLength (size_toInt (len));
2675 void cscannerHelp_advanceLine (void)
2681 int cscannerHelp_returnToken (int t)
2683 yylval.tok = lltok_create (t, fileloc_decColumn (g_currentloc, s_tokLength));
2685 s_lastWasString = FALSE;
2689 int cscannerHelp_returnTokenLength (int t, int length)
2691 cscannerHelp_setTokLength (length);
2692 return cscannerHelp_returnToken (t);
2695 int cscannerHelp_returnString (cstring s)
2697 yylval.expr = exprNode_stringLiteral (s, fileloc_decColumn (g_currentloc, s_tokLength));
2699 s_lastWasString = TRUE;
2703 int cscannerHelp_returnInt (ctype ct, long val)
2707 if (ctype_equal (ct, ctype_int))
2711 c = context_typeofZero ();
2715 c = context_typeofOne ();
2723 yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
2724 fileloc_decColumn (g_currentloc, s_tokLength),
2727 s_lastWasString = FALSE;
2731 int cscannerHelp_returnFloat (ctype ct, double f)
2733 yylval.expr = exprNode_floatLiteral (f, ct, cstring_fromChars (yytext),
2734 fileloc_decColumn (g_currentloc, s_tokLength));
2736 s_lastWasString = FALSE;
2740 int cscannerHelp_returnChar (char c)
2742 yylval.expr = exprNode_charLiteral (c, cstring_fromChars (yytext),
2743 fileloc_decColumn (g_currentloc, s_tokLength));
2745 s_lastWasString = FALSE;
2749 int cscannerHelp_returnType (int tok, ctype ct)
2753 s_lastWasString = FALSE;
2757 int cscannerHelp_returnExpr (exprNode e)
2761 s_lastWasString = TRUE;
2765 void cscannerHelp_setExpectingTypeName ()
2767 s_expectingTypeName = TRUE;
2770 void cscannerHelp_clearExpectingTypeName ()
2772 s_expectingTypeName = FALSE;
2775 bool cscannerHelp_isExpectingTypeName ()
2777 return s_expectingTypeName;
2780 int cscannerHelp_processTextIdentifier (char *text)
2782 context_saveLocation ();
2783 cscannerHelp_setTokLength (size_toInt (mstring_length (text)));
2784 return cscannerHelp_processIdentifier (cscannerHelp_makeIdentifier (text));
2787 static bool s_continueLine = FALSE;
2789 int cscannerHelp_handleNewLine ()
2791 context_incLineno ();
2793 if (s_tokLength != 0) {
2795 /* No error to report
2798 message ("Likely parse error: token spans multiple lines."),
2805 s_continueLine = FALSE;
2809 if (context_inMacro ())
2811 /* Don't use return cscannerHelp_returnToken */
2812 /* !!! evans 2002-03-13 */
2813 yylval.tok = lltok_create (TENDMACRO, fileloc_copy (g_currentloc));
2814 s_lastWasString = FALSE;
2822 void cscannerHelp_setContinueLine ()
2824 s_continueLine = TRUE;
2827 void cscannerHelp_exitSpecPart ()
2829 llassert (s_inSpecPart);
2830 s_inSpecPart = FALSE;
2831 s_whichSpecPart = BADTOK;