2 ** Copyright (c) Massachusetts Institute of Technology 1994-1998.
3 ** All Rights Reserved.
4 ** Unpublished rights reserved under the copyright laws of
7 ** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 ** OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 ** This code is distributed freely and may be used freely under the
11 ** following conditions:
13 ** 1. This notice may not be removed or altered.
15 ** 2. Works derived from this code are not distributed for
16 ** commercial gain without explicit permission from MIT
17 ** (for permission contact lclint-request@sds.lcs.mit.edu).
20 * Modified by Herbert 08/19/97:
21 * - added #include for IBM's OS/2 compiler.
22 * - fixed weird bug with lookup of tmp files (OS/2 and MSDOS only).
26 * Modified by Mike Smith
27 * Corrected missing 'line' in scanf() calls in handleSpecial().
28 * Without this, I get an error when LCLint hits a '#line' directive
29 * in the pre-pre-processed source files. For safety, I have made these
30 * conditional on OS2 and MSDOS because I don't understand why noone else
31 * has seen this problem.
33 * Modified by Mike Smith, 4th June 1997
34 * Finally resolved the #line problem. The scanf() calls have been fixed to
35 * allow the following #line forms:-
37 * #line 123 "filename"
42 * The last two are generated by the GNU pre-processor, apparently
53 ULSuffix ({U}{L}|{L}{U})
57 ** based on original C lexer by Nate Osgood
58 ** from hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
62 # include "lclintMacros.nf"
66 # include "cgrammar.h"
67 # include "cgrammar_tokens.h"
69 # include "fileIdList.h"
72 # if defined(OS2) && defined(__IBMC__)
73 /* needed for isatty()... */
77 static bool lastWasString = FALSE;
78 static char savechar = '\0';
81 # define yyinput() (incColumn (), getc (yyin))
83 static /*@owned@*/ cstring lastidprocessed = cstring_undefined;
84 static int lminput (void);
85 static int tokLength = 0;
86 static bool inSpecPart = FALSE;
87 static bool continueLine = FALSE;
89 static int ninput (void);
90 static char processChar (void);
91 static double processFloat (void);
92 static /*@only@*/ exprNode processString (void);
93 static long processDec (void);
94 static long processHex (void);
95 static long processOctal (void);
96 static int processIdentifier (/*@only@*/ cstring)
97 /*@globals undef lastidprocessed@*/ ;
98 static bool processHashIdentifier (/*@only@*/ cstring)
99 /*@globals undef lastidprocessed@*/ ;
101 static int processSpec (int);
102 static bool handleSpecial (char *);
103 static int handleLlSpecial (void);
104 static void handleMacro (void);
105 static bool processMacro (void);
106 static /*@only@*/ cstring makeIdentifier (char *);
108 /* yes, this is exported! */
109 bool g_expectingTypeName = TRUE; /* beginning of file can be type name! */
111 static bool expectingMetaStateName = FALSE;
113 static int returnInt (ctype, long);
114 static int returnFloat (ctype, double);
115 static int returnChar (char);
116 static void setTokLength (int) /*@modifies g_currentloc@*/ ;
117 static void setTokLengthT (size_t) /*@modifies g_currentloc@*/ ;
119 static void advanceLine (void)
126 # define RETURN_INT(c,i) \
127 do { lastWasString = FALSE; \
128 return (returnInt (c, i)); } while (FALSE)
130 # define RETURN_FLOAT(c,f) \
131 do { lastWasString = FALSE; \
132 return (returnFloat (c, f)); \
135 # define RETURN_CHAR(c) \
136 do { lastWasString = FALSE; \
137 return (returnChar (c)); \
140 # define RETURN_TOK(t) \
141 do { yylval.tok = lltok_create (t, fileloc_decColumn (g_currentloc, tokLength)); \
143 lastWasString = FALSE; \
144 return (t); } while (FALSE)
146 # define RETURN_TYPE(t, ct) \
147 do { yylval.ctyp = ct; tokLength = 0; return (t); } while (FALSE)
149 /* don't fileloc_decColumn (g_currentloc, tokLength));
150 the string could have \n's in it!
153 # define RETURN_STRING(c) \
154 do { yylval.expr = exprNode_stringLiteral (c, fileloc_decColumn (g_currentloc, tokLength)); \
156 lastWasString = TRUE; \
157 return (CCONSTANT); } while (FALSE)
159 # define RETURN_EXPR(e) \
160 do { yylval.expr = e; \
162 lastWasString = TRUE; \
163 return (CCONSTANT); } while (FALSE)
167 static void setTokLength (int len)
173 static void setTokLengthT (size_t len)
175 setTokLength (size_toInt (len));
178 # include "flex.head"
180 /*@-unrecog@*/ /*@i5343@*/
186 "/*" { llfatalbug (cstring_makeLiteral ("Comment in pre-processor output")); }
188 "#"{Letter}({Letter}|{Digit})* {
189 context_saveLocation ();
190 setTokLength (longUnsigned_toInt (mstring_length (yytext)));
192 if (processHashIdentifier (makeIdentifier (yytext + 1)))
196 /* was nothing! */ /*@i32@*/
197 RETURN_STRING (cstring_makeLiteral ("\"\""));
201 RETURN_STRING (cstring_makeLiteral ("\"\""));
206 if (handleSpecial (yytext))
213 "#" { if (handleSpecial (yytext))
215 setTokLength (1); RETURN_TOK (0);
218 "..." { setTokLength (3); RETURN_TOK (CTOK_ELIPSIS); }
219 "break" { setTokLength (5); RETURN_TOK (BREAK); }
220 "case" { setTokLength (4); RETURN_TOK (CASE); }
221 "continue" { setTokLength (8); RETURN_TOK (CONTINUE); }
222 "default" { setTokLength (7); RETURN_TOK (DEFAULT); }
223 "do" { setTokLength (2); RETURN_TOK (DO); }
224 "else" { setTokLength (4); RETURN_TOK (CELSE); }
225 "for" { setTokLength (3); RETURN_TOK (CFOR); }
226 "goto" { setTokLength (4); RETURN_TOK (GOTO); }
227 "if" { setTokLength (2); RETURN_TOK (CIF); }
228 "return" { setTokLength (6); RETURN_TOK (RETURN); }
229 "sizeof" { setTokLength (6); RETURN_TOK (CSIZEOF); }
230 "offsetof" { setTokLength (8); RETURN_TOK (COFFSETOF); }
231 "switch" { setTokLength (6); RETURN_TOK (SWITCH); }
232 "while" { setTokLength (5); RETURN_TOK (WHILE); }
233 "va_arg" { setTokLength (6); RETURN_TOK (VA_ARG); }
234 "va_dcl" { setTokLength (6); RETURN_TOK (VA_DCL); }
236 /* gcc extension...this might not be appropriate */
237 setTokLength (6); RETURN_TOK (QINLINE); }
239 "struct" { setTokLength (6); RETURN_TOK (CSTRUCT); }
240 "typedef" { setTokLength (7); RETURN_TOK (CTYPEDEF); }
242 "union" { setTokLength (5); RETURN_TOK (CUNION); }
243 "enum" { setTokLength (4); RETURN_TOK (CENUM); }
245 "void" { setTokLength (4); RETURN_TYPE (CVOID, ctype_void); }
246 "int" { setTokLength (3); RETURN_TYPE (CINT, ctype_int); }
247 "double" { setTokLength (6); RETURN_TYPE (CDOUBLE, ctype_double); }
248 "char" { setTokLength (4); RETURN_TYPE (CGCHAR, ctype_char); }
249 "float" { setTokLength (5); RETURN_TYPE (CGFLOAT, ctype_float); }
251 "long" { setTokLength (4); RETURN_TOK (QLONG); }
252 "short" { setTokLength (5); RETURN_TOK (QSHORT); }
253 "unsigned" { setTokLength (8); RETURN_TOK (QUNSIGNED); }
254 "signed" { setTokLength (6); RETURN_TOK (QSIGNED); }
256 "volatile" { setTokLength (8); RETURN_TOK (QVOLATILE); }
257 "const" { setTokLength (5); RETURN_TOK (QCONST); }
259 /* some systems expect this! [gack!] */
260 "__const" { setTokLength (7); RETURN_TOK (QCONST); }
262 "extern" { setTokLength (6); RETURN_TOK (QEXTERN); }
263 "auto" { setTokLength (4); RETURN_TOK (QAUTO); }
264 "register" { setTokLength (8); RETURN_TOK (QREGISTER); }
265 "static" { setTokLength (6); RETURN_TOK (QSTATIC); }
267 \"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processString ()); }
268 L\"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processString ()); }
269 "out" { return (processSpec (QOUT)); }
270 "in" { return (processSpec (QIN)); }
271 "partial" { return (processSpec (QPARTIAL)); }
272 "special" { return (processSpec (QSPECIAL)); }
273 "anytype" { return (processSpec (QANYTYPE)); }
274 "integraltype" { return (processSpec (QINTEGRALTYPE)); }
275 "unsignedintegraltype" { return (processSpec (QUNSIGNEDINTEGRALTYPE)); }
276 "signedintegraltype" { return (processSpec (QSIGNEDINTEGRALTYPE)); }
277 "keep" { return (processSpec (QKEEP)); }
278 "null" { return (processSpec (QNULL)); }
279 "notnull" { return (processSpec (QNOTNULL)); }
280 "isnull" { return (processSpec (QISNULL)); }
281 "truenull" { return (processSpec (QTRUENULL)); }
282 "falsenull" { return (processSpec (QFALSENULL)); }
283 "relnull" { return (processSpec (QRELNULL)); }
284 "reldef" { return (processSpec (QRELDEF)); }
285 "exposed" { return (processSpec (QEXPOSED)); }
286 "newref" { return (processSpec (QNEWREF)); }
287 "tempref" { return (processSpec (QTEMPREF)); }
288 "killref" { return (processSpec (QKILLREF)); }
289 "refcounted" { return (processSpec (QREFCOUNTED)); }
290 "checked" { return (processSpec (QCHECKED)); }
291 "checkmod" { return (processSpec (QCHECKMOD)); }
292 "checkedstrict" { return (processSpec (QCHECKEDSTRICT)); }
293 "unchecked" { return (processSpec (QUNCHECKED)); }
294 "only" { return (processSpec (QONLY)); }
295 "owned" { return (processSpec (QOWNED)); }
296 "observer" { return (processSpec (QOBSERVER)); }
297 "dependent" { return (processSpec (QDEPENDENT)); }
298 "unused" { return (processSpec (QUNUSED)); }
299 "external" { return (processSpec (QEXTERNAL)); }
300 "sef" { return (processSpec (QSEF)); }
301 "shared" { return (processSpec (QSHARED)); }
302 "yield" { return (processSpec (QYIELD)); }
303 "undef" { return (processSpec (QUNDEF)); }
304 "killed" { return (processSpec (QKILLED)); }
305 "nullterminated" { return (processSpec (QNULLTERMINATED));}
306 "MaxSet" { return (processSpec (QMAXSET));}
307 "MaxRead" { return (processSpec (QMAXREAD));}
308 "maxSet" { return (processSpec (QMAXSET));}
309 "maxRead" { return (processSpec (QMAXREAD));}
311 {Letter}({Letter}|{Digit})* { int tok;
312 context_saveLocation ();
313 setTokLength (longUnsigned_toInt (mstring_length (yytext)));
314 tok = processIdentifier (makeIdentifier (yytext));
320 0[xX]{H}+ { setTokLengthT (mstring_length (yytext));
321 RETURN_INT (ctype_int, processHex ()); /* evs 2000-05-17 was ctype_uint */
323 0[xX]{H}+{L} { setTokLengthT (mstring_length (yytext));
324 RETURN_INT (ctype_lint, processHex ()); }
325 0[xX]{H}+{L}{L} { setTokLengthT (mstring_length (yytext));
326 RETURN_INT (ctype_llint, processHex ()); }
327 0[xX]{H}+{U} { setTokLengthT (mstring_length (yytext));
328 RETURN_INT (ctype_uint, processHex ()); }
329 0[xX]{H}+{ULSuffix} { setTokLengthT (mstring_length (yytext));
330 RETURN_INT (ctype_ulint, processHex ()); }
331 0[xX]{H}+{U}{L}{L} { setTokLengthT (mstring_length (yytext));
332 RETURN_INT (ctype_ullint, processHex ()); }
333 0[xX]{H}+{L}{L}{U} { setTokLengthT (mstring_length (yytext));
334 RETURN_INT (ctype_ullint, processHex ()); }
335 0{Digit}+ { setTokLengthT (mstring_length (yytext));
336 RETURN_INT (ctype_int, processOctal ()); }
337 0{Digit}+{U} { setTokLengthT (mstring_length (yytext));
338 RETURN_INT (ctype_uint, processOctal ()); }
339 0{Digit}+{L} { setTokLengthT (mstring_length (yytext));
340 RETURN_INT (ctype_lint, processOctal ()); }
341 0{Digit}+{L}{L} { setTokLengthT (mstring_length (yytext));
342 RETURN_INT (ctype_llint, processOctal ()); }
343 0{Digit}+{ULSuffix} { setTokLengthT (mstring_length (yytext));
344 RETURN_INT (ctype_ulint, processOctal ()); }
345 0{Digit}+{U}{L}{L} { setTokLengthT (mstring_length (yytext));
346 RETURN_INT (ctype_ullint, processOctal ()); }
347 0{Digit}+{L}{L}{U} { setTokLengthT (mstring_length (yytext));
348 RETURN_INT (ctype_ullint, processOctal ()); }
349 {Digit}+ { setTokLengthT (mstring_length (yytext));
350 RETURN_INT (ctype_int, processDec ()); }
351 {Digit}+{U} { setTokLengthT (mstring_length (yytext));
352 RETURN_INT (ctype_uint, processDec ()); }
353 {Digit}+{L} { setTokLengthT (mstring_length (yytext));
354 RETURN_INT (ctype_lint, processDec ()); }
355 {Digit}+{L}{L} { setTokLengthT (mstring_length (yytext));
356 RETURN_INT (ctype_llint, processDec ()); }
357 {Digit}+{ULSuffix} { setTokLengthT (mstring_length (yytext));
358 RETURN_INT (ctype_ulint, processDec ()); }
359 {Digit}+{U}{L}{L} { setTokLengthT (mstring_length (yytext));
360 RETURN_INT (ctype_ullint, processDec ()); }
361 {Digit}+{L}{L}{U} { setTokLengthT (mstring_length (yytext));
362 RETURN_INT (ctype_ullint, processDec ()); }
363 '(\\.|[^\\'])+' { setTokLengthT (mstring_length (yytext));
364 RETURN_CHAR (processChar ()); }
365 L'(\\.|[^\\'])+' { setTokLengthT (mstring_length (yytext));
366 RETURN_CHAR (processChar ()); }
367 {Digit}+{E}[fF] { setTokLengthT (mstring_length (yytext));
368 RETURN_FLOAT (ctype_float, processFloat ()); }
369 {Digit}+{E}[lL] { setTokLengthT (mstring_length (yytext));
370 RETURN_FLOAT (ctype_ldouble, processFloat ()); }
371 {Digit}+{E} { setTokLengthT (mstring_length (yytext));
372 RETURN_FLOAT (ctype_double, processFloat ()); }
374 {Digit}*"."{Digit}+({E})?[fF] { setTokLengthT (mstring_length (yytext));
375 RETURN_FLOAT (ctype_float, processFloat ()); }
376 {Digit}*"."{Digit}+({E})?[lL] { setTokLengthT (mstring_length (yytext));
377 RETURN_FLOAT (ctype_ldouble, processFloat ()); }
378 {Digit}*"."{Digit}+({E})? { setTokLengthT (mstring_length (yytext));
379 RETURN_FLOAT (ctype_double, processFloat ()); }
381 {Digit}+"."{Digit}*({E})?[fF] { setTokLengthT (mstring_length (yytext));
382 RETURN_FLOAT (ctype_float, processFloat ()); }
383 {Digit}+"."{Digit}*({E})?[lL] { setTokLengthT (mstring_length (yytext));
384 RETURN_FLOAT (ctype_ldouble, processFloat ()); }
385 {Digit}+"."{Digit}*({E})? { setTokLengthT (mstring_length (yytext));
386 RETURN_FLOAT (ctype_double, processFloat ()); }
388 ">>=" { setTokLength (3); RETURN_TOK (RIGHT_ASSIGN); }
389 "<<=" { setTokLength (3); RETURN_TOK (LEFT_ASSIGN); }
390 "+=" { setTokLength (2); RETURN_TOK (ADD_ASSIGN); }
391 "-=" { setTokLength (2); RETURN_TOK (SUB_ASSIGN); }
392 "*=" { setTokLength (2); RETURN_TOK (MUL_ASSIGN); }
393 "/=" { setTokLength (2); RETURN_TOK (DIV_ASSIGN); }
394 "%=" { setTokLength (2); RETURN_TOK (MOD_ASSIGN); }
395 "&=" { setTokLength (2); RETURN_TOK (AND_ASSIGN); }
396 "^=" { setTokLength (2); RETURN_TOK (XOR_ASSIGN); }
397 "|=" { setTokLength (2); RETURN_TOK (OR_ASSIGN); }
398 ">>" { setTokLength (2); RETURN_TOK (RIGHT_OP); }
399 "<<" { setTokLength (2); RETURN_TOK (LEFT_OP); }
400 "++" { setTokLength (2); RETURN_TOK (INC_OP); }
401 "--" { setTokLength (2); RETURN_TOK (DEC_OP); }
402 "->" { setTokLength (2); RETURN_TOK (ARROW_OP); }
403 "&&" { setTokLength (2); RETURN_TOK (AND_OP); }
404 "||" { setTokLength (2); RETURN_TOK (OR_OP); }
405 "<=" { setTokLength (2); RETURN_TOK (LE_OP); }
406 ">=" { setTokLength (2); RETURN_TOK (GE_OP); }
407 "==" { setTokLength (2); RETURN_TOK (EQ_OP); }
408 "!=" { setTokLength (2); RETURN_TOK (NE_OP); }
409 ";" { setTokLength (1); RETURN_TOK (TSEMI); }
410 "{" { setTokLength (1); RETURN_TOK (TLBRACE); }
411 "}" { setTokLength (1); RETURN_TOK (TRBRACE); }
412 "," { setTokLength (1); RETURN_TOK (TCOMMA); }
413 ":" { setTokLength (1); RETURN_TOK (TCOLON); }
414 "=" { setTokLength (1); RETURN_TOK (TASSIGN); }
415 "(" { setTokLength (1); RETURN_TOK (TLPAREN); }
416 ")" { setTokLength (1); RETURN_TOK (TRPAREN); }
417 "[" { setTokLength (1); RETURN_TOK (TLSQBR); }
418 "]" { setTokLength (1); RETURN_TOK (TRSQBR); }
419 "." { setTokLength (1); RETURN_TOK (TDOT); }
420 "&" { setTokLength (1); RETURN_TOK (TAMPERSAND); }
421 "!" { setTokLength (1); RETURN_TOK (TEXCL); }
424 "~" { setTokLength (1); RETURN_TOK (TTILDE); }
425 "-" { setTokLength (1); RETURN_TOK (TMINUS); }
426 "+" { setTokLength (1); RETURN_TOK (TPLUS); }
427 "*" { setTokLength (1); RETURN_TOK (TMULT); }
428 "/" { setTokLength (1); RETURN_TOK (TDIV); }
429 "%" { setTokLength (1); RETURN_TOK (TPERCENT); }
430 "<" { setTokLength (1); RETURN_TOK (TLT); }
431 ">" { setTokLength (1); RETURN_TOK (TGT); }
432 "^" { setTokLength (1); RETURN_TOK (TCIRC); }
433 "|" { setTokLength (1); RETURN_TOK (TBAR); }
434 "?" { setTokLength (1); RETURN_TOK (TQUEST); }
437 "/\\" { setTokLength (1); RETURN_TOK (TCAND); }
440 [ \t\v\f] { incColumn (); }
441 \n { context_incLineno ();
444 continueLine = FALSE;
448 if (context_inMacro ())
450 /* Don't use RETURN_TOK */
451 yylval.tok = lltok_create (TENDMACRO, g_currentloc);
452 lastWasString = FALSE;
457 "@@MR@@" { setTokLength (6);
459 if (processMacro ()) {
460 if (context_inIterDef ())
462 RETURN_TOK (LLMACROITER);
464 if (context_inIterEnd ())
466 RETURN_TOK (LLMACROEND);
468 if (context_inMacro ())
470 RETURN_TOK (LLMACRO);
474 "@QLMR" { if (context_inHeader () || context_inFunction ())
480 int nspchar = ninput ();
484 ** This is a hack to get the column number correct.
487 llassert (nspchar >= '0' && nspchar <= '9');
489 nspaces = nspchar - '0';
491 setTokLength (5 + nspaces);
495 if (context_inIterDef ())
497 RETURN_TOK (LLMACROITER);
499 if (context_inIterEnd ())
501 RETURN_TOK (LLMACROEND);
503 if (context_inMacro ())
505 RETURN_TOK (LLMACRO);
510 "@.CT" { setTokLength (4); lldiagmsg (ctype_unparseTable ()); }
511 "@.FA" { setTokLength (4); lldiagmsg (message ("Access types: %q", typeIdSet_unparse (context_fileAccessTypes ()))); }
512 "@.F" { setTokLength (3);
513 lldiagmsg (message ("%q: *** marker ***", fileloc_unparse (g_currentloc)));
515 "@.L" { setTokLength (3); usymtab_printLocal (); }
516 "@.A" { setTokLength (3); lldiagmsg (usymtab_unparseAliases ()); }
517 "@.C" { setTokLength (3); lldiagmsg (context_unparse ()); }
518 "@.W" { setTokLength (3); lldiagmsg (context_unparseClauses ()); }
519 "@.G" { setTokLength (3); usymtab_printGuards (); }
520 "@.S" { setTokLength (3); usymtab_printOut (); }
521 "@.X" { setTokLength (3); usymtab_printAll (); }
522 "@.Z" { setTokLength (3); usymtab_printComplete (); }
523 "@.T" { setTokLength (3); usymtab_printTypes (); }
524 "@.K" { setTokLength (3); lldiagmsg (usymtab_unparseStack ()); }
525 "@.M" { setTokLength (3);
526 lldiagmsg (message ("Can modify: %q",
527 sRefSet_unparse (context_modList ())));
529 "%{" { /* BEFORE_COMMENT_MARKER */
531 incColumn (); incColumn ();
532 tok = handleLlSpecial ();
536 if (tok == CANNOTATION) {
539 /* Beware - this bashes yylval! */
544 "%}" { /* AFTER_COMMENT_MARKER */
547 RETURN_TOK (QENDMACRO); }
548 "\\" { incColumn (); continueLine = TRUE; }
550 if ((int) *yytext == 13 ) {
555 message ("Invalid character (ascii: %d), skipping character",
564 /*@null@*/ /*@observer@*/ char *name;
569 ** These tokens are followed by syntax that is parsed by the
573 struct skeyword s_parsetable[] = {
574 { "modifies", QMODIFIES } ,
575 { "globals", QGLOBALS } ,
578 { "constant", QCONSTANT } ,
579 { "function", QFUNCTION } ,
581 { "defines", QDEFINES } ,
583 { "allocates", QALLOCATES } ,
585 { "releases", QRELEASES } ,
586 { "pre", QPRECLAUSE } ,
587 { "post", QPOSTCLAUSE } ,
588 { "setBufferSize", QSETBUFFERSIZE},
589 { "setStringLength", QSETSTRINGLENGTH},
590 { "testinRange", QTESTINRANGE},
591 { "requires", QPRECLAUSE } ,
592 { "ensures", QPOSTCLAUSE } ,
597 ** These tokens are either stand-alone tokens, or followed by
598 ** token-specific text.
601 struct skeyword s_keytable[] = {
602 { "anytype", QANYTYPE } ,
603 { "integraltype", QINTEGRALTYPE } ,
604 { "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
605 { "signedintegraltype", QSIGNEDINTEGRALTYPE } ,
609 { "owned", QOWNED } ,
610 { "dependent", QDEPENDENT } ,
611 { "partial", QPARTIAL } ,
612 { "special", QSPECIAL } ,
613 { "truenull", QTRUENULL } ,
614 { "falsenull", QFALSENULL } ,
617 { "notnull", QNOTNULL } ,
618 { "abstract", QABSTRACT } ,
619 { "concrete", QCONCRETE } ,
620 { "mutable", QMUTABLE } ,
621 { "immutable", QIMMUTABLE } ,
622 { "unused", QUNUSED } ,
623 { "external", QEXTERNAL } ,
625 { "unique", QUNIQUE } ,
626 { "returned", QRETURNED } ,
627 { "exposed", QEXPOSED } ,
628 { "refcounted", QREFCOUNTED } ,
630 { "newref", QNEWREF } ,
631 { "tempref", QTEMPREF } ,
632 { "killref", QKILLREF } ,
634 { "relnull", QRELNULL } ,
635 { "nullterminated", QNULLTERMINATED },
636 { "setBufferSize", QSETBUFFERSIZE },
637 { "testInRange", QTESTINRANGE},
638 { "MaxSet", QMAXSET},
639 { "MaxRead", QMAXREAD},
640 { "reldef", QRELDEF } ,
641 { "observer", QOBSERVER } ,
642 { "exits", QEXITS } ,
643 { "mayexit", QMAYEXIT } ,
644 { "trueexit", QTRUEEXIT } ,
645 { "falseexit", QFALSEEXIT } ,
646 { "neverexit", QNEVEREXIT } ,
648 { "shared", QSHARED } ,
650 { "unchecked", QUNCHECKED } ,
651 { "checked", QCHECKED } ,
652 { "checkmod", QCHECKMOD } ,
653 { "checkedstrict", QCHECKEDSTRICT } ,
654 { "innercontinue", QINNERCONTINUE } ,
655 { "innerbreak", QINNERBREAK } ,
656 { "loopbreak", QLOOPBREAK } ,
657 { "switchbreak", QSWITCHBREAK } ,
658 { "safebreak", QSAFEBREAK } ,
659 { "fallthrough", QFALLTHROUGH } ,
660 { "l_fallthrou", QLINTFALLTHROUGH } ,
661 { "l_fallth", QLINTFALLTHRU } ,
662 { "notreached", QNOTREACHED } ,
663 { "l_notreach", QLINTNOTREACHED } ,
664 { "printflike", QPRINTFLIKE } ,
665 { "l_printfli", QLINTPRINTFLIKE } ,
666 { "scanflike", QSCANFLIKE } ,
667 { "messagelike", QMESSAGELIKE } ,
668 { "l_argsus", QARGSUSED } ,
673 ** would be better if these weren't hard coded...
676 static bool isArtificial (cstring s)
678 return (cstring_equalLit (s, "modifies")
679 || cstring_equalLit (s, "globals")
680 || cstring_equalLit (s, "warn")
681 || cstring_equalLit (s, "alt"));
684 void swallowMacro (void)
687 bool skipnext = FALSE;
689 while ((i = lminput ()) != EOF)
706 reader_checkUngetc (i, yyin);
714 reader_checkUngetc (i, yyin);
718 static int commentMarkerToken (cstring s)
722 while (s_parsetable[i].name != NULL)
724 DPRINTF (("Try :%s:%s:", s, s_parsetable[i].name));
726 if (cstring_equalLit (s, s_parsetable[i].name))
728 return s_parsetable[i].token;
737 static int tokenMacroCode (cstring s)
741 while (s_keytable[i].name != NULL)
743 if (cstring_equalLit (s, s_keytable[i].name))
745 if (s_keytable[i].token == QLINTFALLTHROUGH)
748 (FLG_WARNLINTCOMMENTS,
750 ("Traditional lint comment /*FALLTHROUGH*/ used. "
751 "This is interpreted by "
752 "LCLint in the same way as most Unix lints, but it is "
753 "preferable to replace it with the /*@fallthrough@*/ "
758 else if (s_keytable[i].token == QLINTFALLTHRU)
761 (FLG_WARNLINTCOMMENTS,
763 ("Traditional lint comment /*FALLTHRU*/ used. "
764 "This is interpreted by "
765 "LCLint in the same way as most Unix lints, but it is "
766 "preferable to replace it with the /*@fallthrough@*/ "
771 else if (s_keytable[i].token == QLINTNOTREACHED)
774 (FLG_WARNLINTCOMMENTS,
776 ("Traditional lint comment /*NOTREACHED*/ used. "
777 "This is interpreted by "
778 "LCLint in the same way as most Unix lints, but it is "
779 "preferable to replace it with the /*@notreached@*/ "
780 "semantic comment."),
785 else if (s_keytable[i].token == QPRINTFLIKE)
787 setSpecialFunction (qual_createPrintfLike ());
790 else if (s_keytable[i].token == QLINTPRINTFLIKE)
793 (FLG_WARNLINTCOMMENTS,
795 ("Traditional lint comment /*PRINTFLIKE*/ used. "
796 "This is interpreted by "
797 "LCLint in the same way as most Unix lints, but it is "
798 "preferable to replace it with either /*@printflike@*/, "
799 "/*@scanflike@*/ or /*@messagelike@*/."),
802 setSpecialFunction (qual_createPrintfLike ());
805 else if (s_keytable[i].token == QSCANFLIKE)
807 setSpecialFunction (qual_createScanfLike ());
810 else if (s_keytable[i].token == QMESSAGELIKE)
812 setSpecialFunction (qual_createMessageLike ());
815 else if (s_keytable[i].token == QARGSUSED)
818 (FLG_WARNLINTCOMMENTS,
820 ("Traditional lint comment /*ARGSUSED*/ used. "
821 "This is interpreted by "
822 "LCLint in the same way as most Unix lints, but it is "
823 "preferable to use /*@unused@*/ annotations on "
824 "the unused parameters."),
831 return s_keytable[i].token;
840 static int lminput ()
842 if (savechar == '\0')
849 int save = (int) savechar;
855 static void lmsavechar (char c)
857 if (savechar == '\0') savechar = c;
860 llbuglit ("lmsavechar: override");
864 static int returnFloat (ctype ct, double f)
866 yylval.expr = exprNode_floatLiteral (f, ct, cstring_fromChars (yytext),
867 fileloc_decColumn (g_currentloc, tokLength));
872 static int returnInt (ctype ct, long i)
876 if (ctype_equal (ct, ctype_int))
880 c = context_typeofZero ();
884 c = context_typeofOne ();
888 yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
889 fileloc_decColumn (g_currentloc, tokLength), i);
894 static int returnChar (char c)
896 yylval.expr = exprNode_charLiteral (c, cstring_fromChars (yytext),
897 fileloc_decColumn (g_currentloc, tokLength));
906 if (c != EOF && ((char)c == '\n'))
908 context_incLineno ();
914 static char macro_nextChar ()
916 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
921 c = char_fromInt (ic);
923 if (!in_quote && !in_char && (c == '\\' || c == BEFORE_COMMENT_MARKER[0]))
927 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
929 ; /* skip to newline */
932 context_incLineno ();
936 return macro_nextChar ();
943 else /* if (c == '@') */
945 llassert (FALSE); /*@i23@*/
946 if (handleLlSpecial () != BADTOK)
948 llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
951 return macro_nextChar ();
954 else if (!in_escape && c == '\"')
956 in_quote = !in_quote;
958 else if (!in_escape && c == '\'')
962 else if ((in_quote || in_char) && c == '\\')
964 in_escape = !in_escape;
966 else if ((in_quote || in_char) && in_escape)
970 else if (!in_quote && c == '/')
974 if ((c2 = char_fromInt (lminput ())) == '*')
978 while ((c2 = char_fromInt (lminput ())) != '\0'
979 && c2 != '\n' && c2 != '*')
986 while ((c2 = char_fromInt (lminput ())) != '\0'
999 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
1003 return macro_nextChar ();
1007 /*** putchar does not work! why? puts to stdio...??! ***/
1015 ** keeps semantic comments
1018 static char macro_nextCharC ()
1020 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
1023 c = char_fromInt (lminput ());
1025 if (!in_quote && !in_char && c == '\\')
1027 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
1029 ; /* skip to newline */
1032 context_incLineno ();
1036 return macro_nextCharC ();
1043 else if (!in_escape && c == '\"')
1045 in_quote = !in_quote;
1047 else if (!in_escape && c == '\'')
1051 else if ((in_quote || in_char) && c == '\\')
1053 in_escape = !in_escape;
1055 else if ((in_quote || in_char) && in_escape)
1059 else if (!in_quote && c == '/')
1063 if ((c2 = char_fromInt (lminput ())) == '*')
1067 while ((c2 = char_fromInt (lminput ())) != '\0'
1068 && c2 != '\n' && c2 != '*')
1075 while ((c2 = char_fromInt (lminput ())) != '\0'
1088 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
1092 return macro_nextCharC ();
1103 ** skips whitespace (handles line continuations)
1104 ** returns first non-whitespace character
1107 static char skip_whitespace ()
1111 while ((c = macro_nextChar ()) == ' ' || c == '\t')
1119 static void handleMacro ()
1121 cstring mac = cstring_undefined;
1125 while (currentColumn () > 2)
1127 mac = cstring_appendChar (mac, ' ');
1131 c = macro_nextCharC ();
1133 if (c >= '0' && c <= '9')
1137 for (i = 0; i < ((c - '0') + 1); i++)
1139 mac = cstring_appendChar (mac, ' ');
1147 while (((c = macro_nextCharC ()) != '\0') && (c != '\n'))
1149 mac = cstring_appendChar (mac, c);
1153 macrocode = tokenMacroCode (mac);
1155 if (macrocode == BADTOK && !isArtificial (mac))
1157 context_addMacroCache (mac);
1166 context_incLineno ();
1170 static bool processMacro (void)
1175 cstring fname = cstring_undefined;
1177 bool isspecfcn = FALSE;
1178 bool isiter = FALSE;
1179 bool skipparam = FALSE;
1180 bool isenditer = FALSE;
1181 bool unknownm = FALSE;
1182 bool hasParams = FALSE;
1183 bool emptyMacro = FALSE;
1184 char c = skip_whitespace ();
1185 fileloc loc = fileloc_noColumn (g_currentloc);
1187 /* are both of these necessary? what do they mean? */
1188 uentryList specparams = uentryList_undefined;
1189 uentryList pn = uentryList_undefined;
1191 context_resetMacroMissingParams ();
1193 if (c == '\0' || c == '\n')
1195 llcontbug (cstring_makeLiteral ("Bad macro"));
1200 fname = cstring_appendChar (fname, c);
1202 while ((c = macro_nextChar ()) != '(' && c != '\0'
1203 && c != ' ' && c != '\t' && c != '\n')
1205 fname = cstring_appendChar (fname, c);
1208 if (c == ' ' || c == '\t' || c == '\n')
1214 while (c == ' ' || c == '\t')
1216 c = macro_nextChar ();
1230 hasParams = (c == '(');
1233 if (usymtab_exists (fname))
1235 e2 = usymtab_lookupExpose (fname);
1236 ct = uentry_getType (e2);
1238 if (uentry_isCodeDefined (e2)
1239 && fileloc_isUser (uentry_whereDefined (e2)))
1243 message ("Macro %s already defined", fname),
1246 uentry_showWhereDefined (e2);
1247 uentry_clearDefined (e2);
1250 if (uentry_isFunction (e2))
1252 uentry_setType (e2, ctype_unknown);
1255 context_enterUnknownMacro (e2);
1259 context_enterConstantMacro (e2);
1264 if (uentry_isForward (e2) && uentry_isFunction (e2))
1271 ("Parameterized macro has no prototype or specification: %s ",
1276 uentry_setType (e2, ctype_unknown);
1277 uentry_setFunctionDefined (e2, loc);
1278 uentry_setUsed (e2, fileloc_undefined);
1279 context_enterUnknownMacro (e2);
1283 if (uentry_isIter (e2))
1286 specparams = uentry_getParams (e2);
1287 noparams = uentryList_size (specparams);
1288 uentry_setDefined (e2, loc);
1289 context_enterIterDef (e2);
1291 else if (uentry_isEndIter (e2))
1294 uentry_setDefined (e2, loc);
1295 context_enterIterEnd (e2); /* don't care about it now */
1296 /* but should parse like an iter! */
1298 else if (uentry_isConstant (e2))
1304 message ("Constant %s implemented as parameterized macro",
1308 uentry_showWhereSpecified (e2);
1309 uentry_setType (e2, ctype_unknown);
1310 uentry_makeConstantFunction (e2);
1311 uentry_setDefined (e2, g_currentloc);
1312 uentry_setFunctionDefined (e2, g_currentloc);
1313 context_enterUnknownMacro (e2);
1317 if (!uentry_isSpecified (e2))
1319 fileloc oloc = uentry_whereDeclared (e2);
1321 if (fileloc_isLib (oloc))
1325 else if (fileloc_isUndefined (oloc)
1326 || fileloc_isPreproc (oloc))
1331 (FLG_MACROCONSTDECL,
1333 ("Macro constant %q not declared",
1334 uentry_getName (e2)),
1338 else if (!fileloc_withinLines (oloc, loc, 2))
1339 { /* bogus! will give errors if there is too much whitespace */
1343 ("Macro constant name %s does not match name in "
1344 "previous constant declaration. This constant "
1345 "is declared at %q", fname,
1346 fileloc_unparse (oloc)),
1351 context_enterConstantMacro (e2);
1352 cstring_free (fname);
1358 else if (ctype_isFunction (ct))
1361 specparams = ctype_argsFunction (ct);
1362 noparams = uentryList_size (specparams);
1364 uentry_setFunctionDefined (e2, loc);
1365 context_enterMacro (e2);
1367 else if (uentry_isVar (e2))
1373 message ("Variable %s implemented as parameterized macro",
1377 uentry_showWhereSpecified (e2);
1378 uentry_setType (e2, ctype_unknown);
1379 uentry_makeVarFunction (e2);
1380 uentry_setDefined (e2, g_currentloc);
1381 uentry_setFunctionDefined (e2, g_currentloc);
1382 context_enterUnknownMacro (e2);
1386 uentry ucons = uentry_makeConstant (fname,
1389 if (uentry_isExpandedMacro (e2))
1397 message ("Variable %s implemented by a macro",
1401 uentry_showWhereSpecified (e2);
1405 uentry_setDefined (e2, loc);
1406 uentry_setUsed (ucons, loc);
1408 context_enterConstantMacro (ucons);
1409 uentry_markOwned (ucons);
1410 cstring_free (fname);
1416 if (uentry_isDatatype (e2))
1420 message ("Type implemented as macro: %x",
1421 uentry_getName (e2)),
1422 message ("A type is implemented using a macro definition. A "
1423 "typedef should be used instead."),
1427 /* Must exit scope (not sure why a new scope was entered?) */
1428 usymtab_quietExitScope (g_currentloc);
1429 uentry_setDefined (e2, g_currentloc);
1435 (message ("Unexpanded macro not function or constant: %q",
1436 uentry_unparse (e2)));
1437 uentry_setType (e2, ctype_unknown);
1441 uentry_makeVarFunction (e2);
1442 uentry_setDefined (e2, g_currentloc);
1443 uentry_setFunctionDefined (e2, g_currentloc);
1444 context_enterUnknownMacro (e2);
1456 (FLG_MACROMATCHNAME,
1457 message ("Unexpanded macro %s does not match name of a constant "
1458 "or iter declaration. The name used in the control "
1459 "comment on the previous line should match. "
1460 "(Assuming macro defines a constant.)",
1465 ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);
1466 uentry_setUsed (ce, loc); /* perhaps bogus? */
1467 e2 = usymtab_supEntryReturn (ce);
1469 context_enterConstantMacro (e2);
1470 cstring_free (fname);
1475 /* in macros, ( must follow immediatetly after name */
1481 c = skip_whitespace ();
1483 while (c != ')' && c != '\0')
1486 bool suppress = context_inSuppressRegion ();
1487 cstring paramname = cstring_undefined;
1490 ** save the parameter location
1494 context_saveLocation ();
1497 while (c != ' ' && c != '\t' && c != ',' && c != '\0' && c != ')')
1499 paramname = cstring_appendChar (paramname, c);
1500 c = macro_nextChar ();
1503 if (c == ' ' || c == '\t') c = skip_whitespace ();
1507 c = macro_nextChar ();
1508 if (c == ' ' || c == '\t') c = skip_whitespace ();
1513 llfatalerror (cstring_makeLiteral
1514 ("Bad macro syntax: uentryList"));
1517 if ((isspecfcn || isiter) && (paramno < noparams)
1518 && !uentry_isElipsisMarker (uentryList_getN
1519 (specparams, paramno)))
1521 fileloc sloc = context_getSaveLocation ();
1522 uentry decl = uentryList_getN (specparams, paramno);
1525 param = uentry_nameCopy (paramname, decl);
1528 uentry_setParam (param);
1529 sr = sRef_makeParam (paramno, uentry_getType (param), stateInfo_makeLoc (sloc));
1531 if (sRef_getNullState (sr) == NS_ABSNULL)
1533 ctype pt = ctype_realType (uentry_getType (param));
1535 if (ctype_isUser (pt))
1537 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (pt));
1539 if (uentry_isValid (te))
1541 sRef_setStateFromUentry (sr, te);
1546 sRef_setNullState (sr, NS_UNKNOWN, sloc);
1550 uentry_setSref (param, sr);
1551 uentry_setDeclaredForceOnly (param, sloc);
1553 skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
1557 fileloc sloc = context_getSaveLocation ();
1559 param = uentry_makeVariableSrefParam
1560 (paramname, ctype_unknown, fileloc_copy (sloc),
1561 sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (sloc)));
1562 cstring_free (paramname);
1564 sRef_setPosNull (uentry_getSref (param), sloc);
1565 uentry_setDeclaredForce (param, sloc);
1568 fileloc_free (sloc);
1573 llassert (!uentry_isElipsisMarker (param));
1577 sRef_makeUnsafe (uentry_getSref (param));
1580 pn = uentryList_add (pn, uentry_copy (param));
1581 usymtab_supEntry (param);
1585 /* don't add param */
1586 uentry_free (param);
1591 (void) macro_nextChar ();
1592 c = skip_whitespace ();
1600 if (isspecfcn || isiter)
1602 if (paramno != noparams && noparams >= 0)
1608 message ("Macro %s specified with %d args, defined with %d",
1609 fname, noparams, paramno),
1612 uentry_showWhereSpecified (e2);
1613 uentry_resetParams (e2, pn);
1618 uentry_resetParams (e2, pn);
1625 ** the form should be:
1627 ** # define newname oldname
1628 ** where oldname refers to a function matching the specification
1634 sRef_setGlobalScope ();
1635 usymtab_supGlobalEntry (uentry_makeVariableLoc (fname, ctype_unknown));
1636 sRef_clearGlobalScope ();
1640 context_setMacroMissingParams ();
1645 /* context_setuentryList (pn); */
1646 usymtab_enterScope ();
1649 cstring_free (fname);
1654 static bool handleSpecial (char *yyt)
1656 char *l = mstring_create (MAX_NAME_LENGTH);
1657 static bool reportcpp = FALSE;
1663 strcpy (l, yyt + 1);
1665 /* Need to safe original l for deallocating. */
1668 l += strlen (yyt) - 1;
1670 while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
1676 olc = cstring_fromChars (ol);
1678 if (cstring_equalPrefix (olc, "pragma"))
1680 char *pname = mstring_create (longUnsigned_fromInt (MAX_PRAGMA_LEN));
1681 char *opname = pname;
1682 char *ptr = ol + 6; /* pragma is six characters, plus space */
1686 /* skip whitespace */
1687 while (((c = *ptr) != '\0') && isspace (c))
1693 while (((c = *ptr) != '\0') && !isspace (c))
1697 if (len > MAX_PRAGMA_LEN)
1708 if (len == PRAGMA_LEN_EXPAND
1709 && mstring_equal (opname, PRAGMA_EXPAND))
1711 cstring exname = cstring_undefined;
1715 while (((c = *ptr) != '\0') && !isspace (c))
1717 exname = cstring_appendChar (exname, c);
1722 ue = usymtab_lookupExposeGlob (exname);
1724 if (uentry_isExpandedMacro (ue))
1726 if (fileloc_isPreproc (uentry_whereDefined (ue)))
1728 fileloc_setColumn (g_currentloc, 1);
1729 uentry_setDefined (ue, g_currentloc);
1733 cstring_free (exname);
1736 else if (cstring_equalPrefix (olc, "ident"))
1738 /* Some pre-processors will leave these in the code. Ignore rest of line */
1741 ** Yuk...Win32 filenames can have spaces in them...we need to read
1742 ** to the matching end quote.
1744 else if ((sscanf (ol, "line %d \"", &lineno) == 1)
1745 || (sscanf (ol, " %d \"", &lineno) == 1))
1751 /*@access cstring@*/
1752 while (*tmp != '\"' && *tmp != '\0')
1757 llassert (*tmp == '\"');
1763 while (*tmp != '\"' && *tmp != '\0')
1768 llassert (*tmp == '\"');
1772 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
1775 ** DOS-like path delimiters get delivered in pairs, something like
1776 ** \"..\\\\file.h\", so we have to make it normal again. We do NOT
1777 ** remove the pre dirs yet as we usually specify tmp paths relative
1778 ** to the current directory, so tmp files would not get found in
1779 ** the hash table. If this method fails we try it again later.
1786 ** Skip past the drive marker.
1789 if (strchr (stmp, ':') != NULL)
1791 stmp = strchr (stmp, ':') + 1;
1794 while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
1796 if (*(stmp+1) == CONNECTCHAR)
1798 memmove (stmp, stmp+1, strlen (stmp));
1804 fid = fileTable_lookupBase (context_fileTable (), fname);
1805 if (!(fileId_isValid (fid)))
1807 fname = removePreDirs (fname);
1808 fid = fileTable_lookupBase (context_fileTable (), fname);
1811 # else /* !defined(OS2) && !defined(MSDOS) */
1812 fname = removePreDirs (fname);
1813 fid = fileTable_lookupBase (context_fileTable (), fname);
1814 # endif /* !defined(OS2) && !defined(MSDOS) */
1816 if (!(fileId_isValid (fid)))
1818 if (context_inXHFile ())
1820 fid = fileTable_addXHFile (context_fileTable (), fname);
1822 else if (isHeaderFile (fname))
1824 fid = fileTable_addHeaderFile (context_fileTable (), fname);
1828 fid = fileTable_addFile (context_fileTable (), fname);
1832 setFileLine (fid, lineno);
1833 /*@noaccess cstring@*/
1835 else if ((sscanf (ol, "line %d", &lineno) == 1)
1836 || (sscanf (ol, " %d", &lineno) == 1))
1838 setLine (lineno); /* next line is <cr> */
1842 if (mstring_equal (ol, "")) {
1843 DPRINTF (("Empty pp command!"));
1845 ** evs 2000-05-16: This is a horrible kludge, to get around a bug (well, difficulty) in the pre-processor.
1846 ** We handle a plain # in the input file, by echoing it, and ignoring it in the post-pp-file.
1855 llbug (message ("File contains preprocessor command: #%s",
1856 cstring_fromChars (ol)));
1869 static int handleLlSpecial ()
1873 char *s = mstring_createEmpty ();
1879 loc = fileloc_copy (g_currentloc);
1880 DPRINTF (("Handle special: %s", fileloc_unparse (loc)));
1882 while (((ic = ninput ()) != 0) && isalpha (ic))
1885 s = mstring_append (s, c);
1889 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
1892 if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
1896 llassert (ic == AFTER_COMMENT_MARKER[1]);
1902 return QNOMODS; /* special token no modifications token */
1906 DPRINTF (("Coment marker: %s", os));
1907 tok = commentMarkerToken (cstring_fromChars (os));
1911 tokLength = charsread;
1918 DPRINTF (("Not a comment marker..."));
1919 /* Add rest of the comment */
1921 if (ic != 0 && ic != EOF)
1925 s = mstring_append (s, c);
1928 while (((ic = ninput ()) != 0) && (ic != EOF)
1929 && (ic != AFTER_COMMENT_MARKER[0]))
1932 s = mstring_append (s, c);
1937 DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
1939 if (ic == AFTER_COMMENT_MARKER[0])
1942 llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
1948 while (*s == ' ' || *s == '\t' || *s == '\n')
1953 if (*s == '-' || *s == '+' || *s == '=') /* setting flags */
1957 while (c == '-' || c == '+' || c == '=')
1959 ynm set = ynm_fromCodeChar (c);
1964 thisflag = cstring_fromChars (s);
1966 while ((c = *s) != '\0' && (c != '-') && (c != '=')
1967 && (c != '+') && (c != ' ') && (c != '\t') && (c != '\n'))
1974 if (!context_getFlag (FLG_NOCOMMENTS))
1976 cstring flagname = thisflag;
1977 flagcode fflag = identifyFlag (flagname);
1979 if (flagcode_isSkip (fflag))
1983 else if (flagcode_isInvalid (fflag))
1985 if (isMode (flagname))
1987 if (ynm_isMaybe (set))
1992 ("Semantic comment attempts to restore flag %s. "
1993 "A mode flag cannot be restored.",
1998 context_setMode (flagname);
2004 (FLG_UNRECOGFLAGCOMMENTS,
2005 message ("Unrecognized option in semantic comment: %s",
2010 else if (flagcode_isGlobalFlag (fflag))
2015 ("Semantic comment attempts to set global flag %s. "
2016 "A global flag cannot be set locally.",
2022 context_fileSetFlag (fflag, set);
2024 if (flagcode_hasArgument (fflag))
2026 if (ynm_isMaybe (set))
2031 ("Semantic comment attempts to restore flag %s. "
2032 "A flag for setting a value cannot be restored.",
2037 { /* cut-and-pastied from llmain...blecch */
2038 cstring extra = cstring_undefined;
2044 rest = mstring_copy (s);
2048 while ((rchar = *rest) != '\0'
2049 && (isspace (rchar)))
2055 while ((rchar = *rest) != '\0'
2056 && !isspace (rchar))
2058 extra = cstring_appendChar (extra, rchar);
2065 if (cstring_isUndefined (extra))
2070 ("Flag %s (in semantic comment) must be followed by an argument",
2071 flagcode_unparse (fflag)));
2077 if (flagcode_hasValue (fflag))
2079 setValueFlag (fflag, extra);
2081 else if (flagcode_hasString (fflag))
2083 setStringFlag (fflag, extra);
2100 while ((c == ' ') || (c == '\t') || (c == '\n'))
2106 if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
2108 DPRINTF (("Here adding comment: %s", os));
2109 context_addComment (cstring_fromCharsNew (os));
2121 annotationInfo ainfo;
2123 while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
2135 t = cstring_toCharsSafe (cstring_downcase (cstring_fromChars (t)));
2136 macrocode = tokenMacroCode (cstring_fromChars (t));
2138 if (macrocode != BADTOK)
2140 tokLength = mstring_length (t);
2146 if (macrocode == SKIPTOK)
2154 ainfo = context_lookupAnnotation (cstring_fromChars (os));
2156 if (annotationInfo_isDefined (ainfo)) {
2157 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
2158 /*@i324@*/ yylval.annotation = ainfo;
2166 if (context_inHeader ())
2173 if ((context_inMacro () || context_inGlobalContext ())
2174 && macrocode != SKIPTOK
2175 && !isArtificial (cstring_fromChars (os)))
2177 DPRINTF (("Add comment: %s", os));
2178 context_addComment (cstring_fromCharsNew (os));
2191 if (mstring_equal (t, "ignore"))
2193 if (!context_getFlag (FLG_NOCOMMENTS))
2195 context_enterSuppressRegion ();
2198 else if ((*t == 'i' || *t == 't')
2199 && (*(t + 1) == '\0'))
2201 if (!context_getFlag (FLG_NOCOMMENTS)
2202 && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
2204 context_enterSuppressLine (-1); /* infinite suppression */
2207 else if (((*t == 'i') || (*t == 't'))
2208 && ((*(t + 1) >= '0' && *(t + 1) <= '9')))
2210 bool tmpcomment = (*t == 't');
2212 char *tt = t; /* don't mangle t, since it is free'd */
2215 if (lc >= '0' && lc <= '9')
2217 val = (int)(lc - '0');
2220 while (lc >= '0' && lc <= '9')
2229 if (!context_getFlag (FLG_NOCOMMENTS)
2230 && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
2232 context_enterSuppressLine (val);
2235 else if (mstring_equal (t, "end"))
2237 if (!context_getFlag (FLG_NOCOMMENTS))
2239 context_exitSuppressRegion ();
2242 else if (mstring_equal (t, "notfunction"))
2244 ; /* handled by pcpp */
2246 else if (mstring_equal (t, "access"))
2252 while ((c = *s) && (c == ' ' || c == '\t' || c == '\n'))
2262 tname = cstring_fromChars (s);
2264 while ((c = *s) != '\0' && c != ' '
2265 && c != '\t' && c != '\n' && c != ',')
2272 DPRINTF (("Access %s", tname));
2274 if (!context_getFlag (FLG_NOCOMMENTS)
2275 && !context_getFlag (FLG_NOACCESS))
2277 if (usymtab_existsType (tname))
2279 typeId uid = usymtab_getTypeId (tname);
2280 uentry ue = usymtab_getTypeEntry (uid);
2282 if (uentry_isAbstractDatatype (ue))
2284 context_addFileAccessType (uid);
2285 DPRINTF (("Adding access to: %s / %d", tname, uid));
2292 ("Non-abstract type %s used in access comment",
2299 if (!(context_inSuppressRegion ()
2300 || context_inSuppressZone (g_currentloc)))
2305 ("Unrecognized type %s used in access comment",
2317 if (c != ',' && c != ' ')
2323 else if (mstring_equal (t, "noaccess"))
2330 while ((lc = *s) && (lc == ' ' || lc == '\t' || lc == '\n'))
2340 tname = cstring_fromChars (s);
2342 while ((lc = *s) != '\0' && lc != ' ' && lc != '\t'
2343 && lc != '\n' && lc != ',')
2350 if (!context_getFlag (FLG_NOCOMMENTS)
2351 && !context_getFlag (FLG_NOACCESS))
2353 if (usymtab_existsType (tname))
2355 typeId tuid = usymtab_getTypeId (tname);
2357 if (context_couldHaveAccess (tuid))
2359 DPRINTF (("Removing access: %s", tname));
2360 context_removeFileAccessType (tuid);
2364 if (!(context_inSuppressRegion ()
2365 || context_inSuppressZone (g_currentloc)))
2367 uentry ue = usymtab_getTypeEntry (tuid);
2369 if (uentry_isAbstractDatatype (ue))
2374 ("Non-accessible abstract type %s used in noaccess comment",
2383 ("Non-abstract type %s used in noaccess comment",
2392 if (!(context_inSuppressRegion ()
2393 || context_inSuppressZone (g_currentloc)))
2398 ("Unrecognized type %s used in noaccess comment",
2410 if (lc != ',' && lc != ' ')
2418 voptgenerror (FLG_UNRECOGCOMMENTS,
2419 message ("Semantic comment unrecognized: %s",
2420 cstring_fromChars (os)), loc);
2431 static /*@only@*/ cstring makeIdentifier (char *s)
2433 char *c = mstring_create (size_toInt (strlen (s)) + 1);
2434 cstring id = cstring_fromChars (c);
2436 while (isalnum (*s) || (*s == '_') || (*s == '$'))
2445 /*@observer@*/ /*@dependent@*/ uentry coerceId (cstring cn)
2447 if (!(usymtab_exists (cn)))
2449 fileloc loc = fileloc_createExternal ();
2452 ** We need to put this in a global scope, otherwise the sRef will be deallocated.
2455 uentry ce = uentry_makeUnrecognized (cn, loc);
2457 if (!context_inIterEnd ())
2461 message ("Unrecognized (possibly system) identifier: %q",
2462 uentry_getName (ce)),
2469 return (usymtab_lookup (cn));
2473 ** like, coerceId, but doesn't supercede for iters
2476 /*@observer@*/ uentry coerceIterId (cstring cn)
2478 if (!(usymtab_exists (cn)))
2480 return uentry_undefined;
2483 return (usymtab_lookup (cn));
2486 /*@observer@*/ cstring LastIdentifier ()
2488 return (lastidprocessed);
2491 static int processIdentifier (cstring id)
2495 if (context_getFlag (FLG_GRAMMAR))
2497 lldiagmsg (message ("Process identifier: %s", id));
2500 context_clearJustPopped ();
2501 lastidprocessed = id;
2503 if (context_inFunctionHeader ())
2505 int tok = commentMarkerToken (id);
2506 DPRINTF (("in function decl..."));
2514 tok = tokenMacroCode (id);
2522 annotationInfo ainfo;
2524 if (expectingMetaStateName)
2526 metaStateInfo msinfo = context_lookupMetaStateInfo (id);
2528 if (metaStateInfo_isDefined (msinfo))
2530 yylval.msinfo = msinfo;
2531 return METASTATE_NAME;
2535 DPRINTF (("Not meta state name: %s", cstring_toCharsSafe (id)));
2539 ainfo = context_lookupAnnotation (id);
2541 if (annotationInfo_isDefined (ainfo))
2543 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
2544 /*@i324@*/ yylval.annotation = ainfo;
2549 DPRINTF (("Not annotation: %s", id));
2555 /* Consider handling: Defined by C99 as static const char __func__[] */
2557 if (context_getFlag (FLG_GNUEXTENSIONS))
2561 if (cstring_equalLit (id, "__stdcall")
2562 || cstring_equalLit (id, "__cdecl")
2563 || cstring_equalLit (id, "__extension__"))
2567 else if (cstring_equalLit (id, "__volatile__"))
2571 else if (cstring_equalLit (id, "__signed"))
2575 else if (cstring_equalLit (id, "__unsigned"))
2579 else if (cstring_equalLit (id, "__const__"))
2583 else if (cstring_equalLit (id, "__alignof__"))
2585 tok = CALIGNOF; /* alignof is parsed like sizeof */
2587 else if (cstring_equalLit (id, "__FUNCTION__")
2588 || cstring_equalLit (id, "__PRETTY_FUNCTION__"))
2590 /* These tokens hold the name of the current function as strings */
2591 yylval.expr = exprNode_stringLiteral (id, fileloc_copy (g_currentloc));
2593 lastWasString = TRUE;
2597 else if (cstring_equalLit (id, "__attribute__")
2598 || cstring_equalLit (id, "__asm__")
2599 || cstring_equalLit (id, "_asm")
2600 || cstring_equalLit (id, "__asm")
2601 || cstring_equalLit (id, "__declspec"))
2604 bool useparens = FALSE;
2605 bool usebraces = FALSE;
2606 bool inquote = FALSE;
2607 bool inescape = FALSE;
2610 while ((ic = input ()) != EOF)
2617 else if (ic == '\\')
2621 else if (ic == '\"')
2657 else if (ic == ')' && useparens)
2660 if (depth == 0) break;
2662 else if (ic == '}' && usebraces)
2665 if (depth == 0) break;
2668 && !usebraces && !useparens
2669 && cstring_equalLit (id, "__asm"))
2672 ** We need this because some MS VC++ include files
2673 ** have __asm mov ... }
2674 ** Its a kludge, but otherwise would need to parse
2683 context_incLineno ();
2685 if (cstring_equalLit (id, "__asm")
2686 && !useparens && !usebraces)
2693 llassert ((useparens && ic == ')')
2694 || (usebraces && ic == '}')
2695 || (!useparens && !usebraces));
2699 else if (cstring_equalLit (id, "inline")
2700 || cstring_equalLit (id, "__inline")
2701 || cstring_equalLit (id, "_inline")
2702 || cstring_equalLit (id, "__inline__"))
2713 le = usymtab_lookupSafe (id);
2715 /*@-dependenttrans@*/
2717 if (uentry_isIter (le))
2719 /*@i32@*/ yylval.entry = le;
2722 else if (uentry_isEndIter (le))
2724 /*@i32@*/ yylval.entry = le;
2725 return (ITER_ENDNAME);
2727 else if (uentry_isUndefined (le))
2731 /* avoid parse errors for certain system built ins */
2733 if (g_expectingTypeName && (cstring_firstChar (id) == '_')
2734 && (cstring_secondChar (id) == '_'))
2736 return (TYPE_NAME_OR_ID);
2739 return (NEW_IDENTIFIER);
2741 else if (!uentry_isDeclared (le) && !uentry_isCodeDefined (le))
2743 if (uentry_isDatatype (le))
2746 return (NEW_IDENTIFIER);
2750 /*@i32@*/ yylval.entry = le;
2751 return (IDENTIFIER);
2754 else if (uentry_isDatatype (le))
2756 if (!g_expectingTypeName)
2760 return (NEW_IDENTIFIER);
2764 yylval.ctyp = uentry_getAbstractType (le);
2766 uentry_setUsed (le, g_currentloc);
2772 /*@i32@*/ yylval.entry = le;
2773 return (IDENTIFIER);
2776 /*@=dependenttrans@*/
2779 static bool processHashIdentifier (/*@only@*/ cstring id)
2781 if (context_inMacro () || context_inIterDef () ||
2782 context_inIterEnd ())
2786 context_clearJustPopped ();
2788 lastidprocessed = id;
2789 le = usymtab_lookupSafe (id);
2791 if (uentry_isParam (le) || uentry_isRefParam (le))
2808 static /*@only@*/ exprNode processString ()
2812 char *nl = strchr (yytext, '\n');
2813 cstring ns = cstring_fromCharsNew (yytext);
2817 loc = fileloc_copy (g_currentloc);
2818 addColumn (cstring_length (ns));
2824 loc = fileloc_copy (g_currentloc);
2826 context_incLineno ();
2828 while ((nl = strchr ((nl + 1), '\n')) != NULL)
2830 context_incLineno ();
2836 res = exprNode_stringLiteral (ns, loc);
2846 llassert (*yytext != '\0');
2847 fchar = *(yytext + 1);
2848 if (fchar != '\\') return fchar;
2850 next = *(yytext + 2);
2854 case 'n': return '\n';
2855 case 't': return '\t';
2856 case '\"': return '\"';
2857 case '\'': return '\'';
2858 case '\\': return '\\';
2859 default: return '\0';
2864 double processFloat ()
2866 double ret = atof (yytext);
2877 llassert (yytext[0] == '0'
2878 && (yytext[1] == 'X' || yytext[1] == 'x'));
2880 while (yytext[index] != '\0') {
2882 char c = yytext[index];
2884 if (c >= '0' && c <= '9') {
2885 tval = (int) c - (int) '0';
2886 } else if (c >= 'A' && c <= 'F') {
2887 tval = (int) c - (int) 'A' + 10;
2888 } else if (c >= 'a' && c <= 'f') {
2889 tval = (int) c - (int) 'a' + 10;
2890 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2892 while (yytext[index] != '\0') {
2893 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2898 message ("Invalid character (%c) following specifier in hex constant: %s",
2899 c, cstring_fromChars (yytext)),
2909 message ("Invalid character (%c) in hex constant: %s",
2910 c, cstring_fromChars (yytext)),
2915 val = (val * 16) + tval;
2919 DPRINTF (("Hex constant: %s = %ld", yytext, val));
2924 long processOctal ()
2929 llassert (yytext[0] == '0' && yytext[1] != 'X' && yytext[1] != 'x');
2931 while (yytext[index] != '\0') {
2933 char c = yytext[index];
2935 if (c >= '0' && c <= '7') {
2936 tval = (int) c - (int) '0';
2940 message ("Invalid character (%c) in octal constant: %s",
2941 c, cstring_fromChars (yytext)),
2946 val = (val * 8) + tval;
2950 DPRINTF (("Octal constant: %s = %ld", yytext, val));
2957 return (atol (yytext));
2961 processSpec (int tok)
2963 size_t length = strlen (yytext);
2968 setTokLengthT (length);
2974 context_saveLocation ();
2975 setTokLengthT (length);
2976 return (processIdentifier (makeIdentifier (yytext)));
2980 void cscanner_expectingMetaStateName ()
2982 llassert (!expectingMetaStateName);
2983 llassert (context_inFunctionHeader ());
2984 expectingMetaStateName = TRUE;
2987 void cscanner_clearExpectingMetaStateName ()
2989 llassert (expectingMetaStateName);
2990 expectingMetaStateName = FALSE;