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"
65 # include "cgrammar.h"
66 # include "cgrammar_tokens.h"
68 # include "fileIdList.h"
71 # if defined(OS2) && defined(__IBMC__)
72 /* needed for isatty()... */
76 static bool lastWasString = FALSE;
77 static char savechar = '\0';
80 # define yyinput() (incColumn (), getc (yyin))
84 extern /*@external@*/ int read ();
88 static /*@owned@*/ cstring lastidprocessed = cstring_undefined;
90 static int lminput (void);
91 static int tokLength = 0;
92 static bool inSpecPart = FALSE;
93 static bool continueLine = FALSE;
95 static int ninput (void);
96 static char processChar (void);
97 static double processFloat (void);
98 static /*@only@*/ exprNode processString (void);
99 static long processDec (void);
100 static long processHex (void);
101 static long processOctal (void);
102 static int processIdentifier (/*@only@*/ cstring)
103 /*@globals undef lastidprocessed@*/ ;
104 static bool processHashIdentifier (/*@only@*/ cstring)
105 /*@globals undef lastidprocessed@*/ ;
107 static int processSpec (int);
108 static bool handleSpecial (char *);
109 static int handleLlSpecial (void);
110 static void handleMacro (void);
111 static bool processMacro (void);
112 static /*@only@*/ cstring makeIdentifier (char *);
114 /* yes, this is exported! */
115 bool g_expectingTypeName = TRUE; /* beginning of file can be type name! */
117 static int returnInt (ctype, long);
118 static int returnFloat (ctype, double);
119 static int returnChar (char);
120 static void setTokLength (int) /*@modifies g_currentloc@*/ ;
121 static void setTokLengthT (size_t) /*@modifies g_currentloc@*/ ;
123 static void advanceLine (void)
130 # define RETURN_INT(c,i) \
131 do { lastWasString = FALSE; \
132 return (returnInt (c, i)); } while (FALSE)
134 # define RETURN_FLOAT(c,f) \
135 do { lastWasString = FALSE; \
136 return (returnFloat (c, f)); \
139 # define RETURN_CHAR(c) \
140 do { lastWasString = FALSE; \
141 return (returnChar (c)); \
144 # define RETURN_TOK(t) \
145 do { yylval.tok = lltok_create (t, fileloc_decColumn (g_currentloc, tokLength)); \
147 lastWasString = FALSE; \
148 return (t); } while (FALSE)
150 # define RETURN_TYPE(t, ct) \
151 do { yylval.ctyp = ct; tokLength = 0; return (t); } while (FALSE)
153 /* don't fileloc_decColumn (g_currentloc, tokLength));
154 the string could have \n's in it!
157 # define RETURN_STRING(c) \
158 do { yylval.expr = exprNode_stringLiteral (c, fileloc_decColumn (g_currentloc, tokLength)); \
160 lastWasString = TRUE; \
161 return (CCONSTANT); } while (FALSE)
163 # define RETURN_EXPR(e) \
164 do { yylval.expr = e; \
166 lastWasString = TRUE; \
167 return (CCONSTANT); } while (FALSE)
171 static void setTokLength (int len)
177 static void setTokLengthT (size_t len)
179 setTokLength (size_toInt (len));
182 # include "flex.head"
187 "/*" { llfatalbug (cstring_makeLiteral ("Comment in pre-processor output")); }
189 "#"{Letter}({Letter}|{Digit})* {
190 context_saveLocation ();
191 setTokLength (longUnsigned_toInt (mstring_length (yytext)));
193 if (processHashIdentifier (makeIdentifier (yytext + 1)))
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 "out" { return (processSpec (QOUT)); }
269 "in" { return (processSpec (QIN)); }
270 "partial" { return (processSpec (QPARTIAL)); }
271 "special" { return (processSpec (QSPECIAL)); }
272 "anytype" { return (processSpec (QANYTYPE)); }
273 "integraltype" { return (processSpec (QINTEGRALTYPE)); }
274 "unsignedintegraltype" { return (processSpec (QUNSIGNEDINTEGRALTYPE)); }
275 "signedintegraltype" { return (processSpec (QSIGNEDINTEGRALTYPE)); }
276 "keep" { return (processSpec (QKEEP)); }
277 "null" { return (processSpec (QNULL)); }
278 "notnull" { return (processSpec (QNOTNULL)); }
279 "isnull" { return (processSpec (QISNULL)); }
280 "truenull" { return (processSpec (QTRUENULL)); }
281 "falsenull" { return (processSpec (QFALSENULL)); }
282 "relnull" { return (processSpec (QRELNULL)); }
283 "reldef" { return (processSpec (QRELDEF)); }
284 "exposed" { return (processSpec (QEXPOSED)); }
285 "newref" { return (processSpec (QNEWREF)); }
286 "tempref" { return (processSpec (QTEMPREF)); }
287 "killref" { return (processSpec (QKILLREF)); }
288 "refcounted" { return (processSpec (QREFCOUNTED)); }
289 "checked" { return (processSpec (QCHECKED)); }
290 "checkmod" { return (processSpec (QCHECKMOD)); }
291 "checkedstrict" { return (processSpec (QCHECKEDSTRICT)); }
292 "unchecked" { return (processSpec (QUNCHECKED)); }
293 "only" { return (processSpec (QONLY)); }
294 "owned" { return (processSpec (QOWNED)); }
295 "observer" { return (processSpec (QOBSERVER)); }
296 "dependent" { return (processSpec (QDEPENDENT)); }
297 "unused" { return (processSpec (QUNUSED)); }
298 "external" { return (processSpec (QEXTERNAL)); }
299 "sef" { return (processSpec (QSEF)); }
300 "shared" { return (processSpec (QSHARED)); }
301 "yield" { return (processSpec (QYIELD)); }
302 "undef" { return (processSpec (QUNDEF)); }
303 "killed" { return (processSpec (QKILLED)); }
304 "nullterminated" { return (processSpec (QNULLTERMINATED));}
305 "MaxSet" { return (processSpec (QMAXSET));}
306 "MaxRead" { return (processSpec (QMAXREAD));}
308 {Letter}({Letter}|{Digit})* { int tok;
309 context_saveLocation ();
310 setTokLength (longUnsigned_toInt (mstring_length (yytext)));
311 tok = processIdentifier (makeIdentifier (yytext));
317 0[xX]{H}+ { setTokLengthT (mstring_length (yytext));
318 RETURN_INT (ctype_int, processHex ()); /* evs 2000-05-17 was ctype_uint */
320 0[xX]{H}+{L} { setTokLengthT (mstring_length (yytext));
321 RETURN_INT (ctype_lint, processHex ()); }
322 0[xX]{H}+{L}{L} { setTokLengthT (mstring_length (yytext));
323 RETURN_INT (ctype_llint, processHex ()); }
324 0[xX]{H}+{U} { setTokLengthT (mstring_length (yytext));
325 RETURN_INT (ctype_uint, processHex ()); }
326 0[xX]{H}+{ULSuffix} { setTokLengthT (mstring_length (yytext));
327 RETURN_INT (ctype_ulint, processHex ()); }
328 0[xX]{H}+{U}{L}{L} { setTokLengthT (mstring_length (yytext));
329 RETURN_INT (ctype_ullint, processHex ()); }
330 0[xX]{H}+{L}{L}{U} { setTokLengthT (mstring_length (yytext));
331 RETURN_INT (ctype_ullint, processHex ()); }
332 0{Digit}+ { setTokLengthT (mstring_length (yytext));
333 RETURN_INT (ctype_int, processOctal ()); }
334 0{Digit}+{U} { setTokLengthT (mstring_length (yytext));
335 RETURN_INT (ctype_uint, processOctal ()); }
336 0{Digit}+{L} { setTokLengthT (mstring_length (yytext));
337 RETURN_INT (ctype_lint, processOctal ()); }
338 0{Digit}+{L}{L} { setTokLengthT (mstring_length (yytext));
339 RETURN_INT (ctype_llint, processOctal ()); }
340 0{Digit}+{ULSuffix} { setTokLengthT (mstring_length (yytext));
341 RETURN_INT (ctype_ulint, processOctal ()); }
342 0{Digit}+{U}{L}{L} { setTokLengthT (mstring_length (yytext));
343 RETURN_INT (ctype_ullint, processOctal ()); }
344 0{Digit}+{L}{L}{U} { setTokLengthT (mstring_length (yytext));
345 RETURN_INT (ctype_ullint, processOctal ()); }
346 {Digit}+ { setTokLengthT (mstring_length (yytext));
347 RETURN_INT (ctype_int, processDec ()); }
348 {Digit}+{U} { setTokLengthT (mstring_length (yytext));
349 RETURN_INT (ctype_uint, processDec ()); }
350 {Digit}+{L} { setTokLengthT (mstring_length (yytext));
351 RETURN_INT (ctype_lint, processDec ()); }
352 {Digit}+{L}{L} { setTokLengthT (mstring_length (yytext));
353 RETURN_INT (ctype_llint, processDec ()); }
354 {Digit}+{ULSuffix} { setTokLengthT (mstring_length (yytext));
355 RETURN_INT (ctype_ulint, processDec ()); }
356 {Digit}+{U}{L}{L} { setTokLengthT (mstring_length (yytext));
357 RETURN_INT (ctype_ullint, processDec ()); }
358 {Digit}+{L}{L}{U} { setTokLengthT (mstring_length (yytext));
359 RETURN_INT (ctype_ullint, processDec ()); }
360 '(\\.|[^\\'])+' { setTokLengthT (mstring_length (yytext));
361 RETURN_CHAR (processChar ()); }
362 {Digit}+{E}[fF] { setTokLengthT (mstring_length (yytext));
363 RETURN_FLOAT (ctype_float, processFloat ()); }
364 {Digit}+{E}[lL] { setTokLengthT (mstring_length (yytext));
365 RETURN_FLOAT (ctype_ldouble, processFloat ()); }
366 {Digit}+{E} { setTokLengthT (mstring_length (yytext));
367 RETURN_FLOAT (ctype_double, processFloat ()); }
369 {Digit}*"."{Digit}+({E})?[fF] { setTokLengthT (mstring_length (yytext));
370 RETURN_FLOAT (ctype_float, processFloat ()); }
371 {Digit}*"."{Digit}+({E})?[lL] { setTokLengthT (mstring_length (yytext));
372 RETURN_FLOAT (ctype_ldouble, processFloat ()); }
373 {Digit}*"."{Digit}+({E})? { setTokLengthT (mstring_length (yytext));
374 RETURN_FLOAT (ctype_double, processFloat ()); }
376 {Digit}+"."{Digit}*({E})?[fF] { setTokLengthT (mstring_length (yytext));
377 RETURN_FLOAT (ctype_float, processFloat ()); }
378 {Digit}+"."{Digit}*({E})?[lL] { setTokLengthT (mstring_length (yytext));
379 RETURN_FLOAT (ctype_ldouble, processFloat ()); }
380 {Digit}+"."{Digit}*({E})? { setTokLengthT (mstring_length (yytext));
381 RETURN_FLOAT (ctype_double, processFloat ()); }
383 ">>=" { setTokLength (3); RETURN_TOK (RIGHT_ASSIGN); }
384 "<<=" { setTokLength (3); RETURN_TOK (LEFT_ASSIGN); }
385 "+=" { setTokLength (2); RETURN_TOK (ADD_ASSIGN); }
386 "-=" { setTokLength (2); RETURN_TOK (SUB_ASSIGN); }
387 "*=" { setTokLength (2); RETURN_TOK (MUL_ASSIGN); }
388 "/=" { setTokLength (2); RETURN_TOK (DIV_ASSIGN); }
389 "%=" { setTokLength (2); RETURN_TOK (MOD_ASSIGN); }
390 "&=" { setTokLength (2); RETURN_TOK (AND_ASSIGN); }
391 "^=" { setTokLength (2); RETURN_TOK (XOR_ASSIGN); }
392 "|=" { setTokLength (2); RETURN_TOK (OR_ASSIGN); }
393 ">>" { setTokLength (2); RETURN_TOK (RIGHT_OP); }
394 "<<" { setTokLength (2); RETURN_TOK (LEFT_OP); }
395 "++" { setTokLength (2); RETURN_TOK (INC_OP); }
396 "--" { setTokLength (2); RETURN_TOK (DEC_OP); }
397 "->" { setTokLength (2); RETURN_TOK (ARROW_OP); }
398 "&&" { setTokLength (2); RETURN_TOK (AND_OP); }
399 "||" { setTokLength (2); RETURN_TOK (OR_OP); }
400 "<=" { setTokLength (2); RETURN_TOK (LE_OP); }
401 ">=" { setTokLength (2); RETURN_TOK (GE_OP); }
402 "==" { setTokLength (2); RETURN_TOK (EQ_OP); }
403 "!=" { setTokLength (2); RETURN_TOK (NE_OP); }
404 ";" { setTokLength (1); RETURN_TOK (TSEMI); }
405 "{" { setTokLength (1); RETURN_TOK (TLBRACE); }
406 "}" { setTokLength (1); RETURN_TOK (TRBRACE); }
407 "," { setTokLength (1); RETURN_TOK (TCOMMA); }
408 ":" { setTokLength (1); RETURN_TOK (TCOLON); }
409 "=" { setTokLength (1); RETURN_TOK (TASSIGN); }
410 "(" { setTokLength (1); RETURN_TOK (TLPAREN); }
411 ")" { setTokLength (1); RETURN_TOK (TRPAREN); }
412 "[" { setTokLength (1); RETURN_TOK (TLSQBR); }
413 "]" { setTokLength (1); RETURN_TOK (TRSQBR); }
414 "." { setTokLength (1); RETURN_TOK (TDOT); }
415 "&" { setTokLength (1); RETURN_TOK (TAMPERSAND); }
416 "!" { setTokLength (1); RETURN_TOK (TEXCL); }
419 "~" { setTokLength (1); RETURN_TOK (TTILDE); }
420 "-" { setTokLength (1); RETURN_TOK (TMINUS); }
421 "+" { setTokLength (1); RETURN_TOK (TPLUS); }
422 "*" { setTokLength (1); RETURN_TOK (TMULT); }
423 "/" { setTokLength (1); RETURN_TOK (TDIV); }
424 "%" { setTokLength (1); RETURN_TOK (TPERCENT); }
425 "<" { setTokLength (1); RETURN_TOK (TLT); }
426 ">" { setTokLength (1); RETURN_TOK (TGT); }
427 "^" { setTokLength (1); RETURN_TOK (TCIRC); }
428 "|" { setTokLength (1); RETURN_TOK (TBAR); }
429 "?" { setTokLength (1); RETURN_TOK (TQUEST); }
431 [ \t\v\f] { incColumn (); }
432 \n { context_incLineno ();
435 continueLine = FALSE;
439 if (context_inMacro ())
441 /* Don't use RETURN_TOK */
442 yylval.tok = lltok_create (TENDMACRO, g_currentloc);
443 lastWasString = FALSE;
448 "@@MR@@" { setTokLength (6);
450 if (processMacro ()) {
451 if (context_inIterDef ())
453 RETURN_TOK (LLMACROITER);
455 if (context_inIterEnd ())
457 RETURN_TOK (LLMACROEND);
459 if (context_inMacro ())
461 RETURN_TOK (LLMACRO);
465 "@QLMR" { if (context_inHeader () || context_inFunction ())
471 int nspchar = ninput ();
475 ** This is a hack to get the column number correct.
478 llassert (nspchar >= '0' && nspchar <= '9');
480 nspaces = nspchar - '0';
482 setTokLength (5 + nspaces);
486 if (context_inIterDef ())
488 RETURN_TOK (LLMACROITER);
490 if (context_inIterEnd ())
492 RETURN_TOK (LLMACROEND);
494 if (context_inMacro ())
496 RETURN_TOK (LLMACRO);
501 "@.CT" { setTokLength (4); lldiagmsg (ctype_unparseTable ()); }
502 "@.F" { setTokLength (3);
503 lldiagmsg (message ("%q: *** marker ***", fileloc_unparse (g_currentloc)));
505 "@.L" { setTokLength (3); usymtab_printLocal (); }
506 "@.A" { setTokLength (3); lldiagmsg (usymtab_unparseAliases ()); }
507 "@.C" { setTokLength (3); lldiagmsg (context_unparse ()); }
508 "@.W" { setTokLength (3); lldiagmsg (context_unparseClauses ()); }
509 "@.G" { setTokLength (3); usymtab_printGuards (); }
510 "@.S" { setTokLength (3); usymtab_printOut (); }
511 "@.X" { setTokLength (3); usymtab_printAll (); }
512 "@.Z" { setTokLength (3); usymtab_printComplete (); }
513 "@.T" { setTokLength (3); usymtab_printTypes (); }
514 "@.K" { setTokLength (3); lldiagmsg (usymtab_unparseStack ()); }
515 "@.M" { setTokLength (3);
516 lldiagmsg (message ("Can modify: %q",
517 sRefSet_unparse (context_modList ())));
519 "%{" { /* BEFORE_COMMENT_MARKER */
521 incColumn (); incColumn ();
522 tok = handleLlSpecial ();
528 "%}" { /* AFTER_COMMENT_MARKER */
531 RETURN_TOK (QENDMACRO); }
532 "\\" { incColumn (); continueLine = TRUE; }
536 message ("Invalid character (ascii: %d), skipping character",
544 /*@null@*/ /*@observer@*/ char *name;
549 ** These tokens are followed by syntax that is parsed by the
553 struct skeyword s_parsetable[] = {
554 { "modifies", QMODIFIES } ,
555 { "globals", QGLOBALS } ,
557 { "constant", QCONSTANT } ,
558 { "function", QFUNCTION } ,
560 { "defines", QDEFINES } ,
562 { "allocates", QALLOCATES } ,
564 { "releases", QRELEASES } ,
565 { "pre", QPRECLAUSE } ,
566 { "post", QPOSTCLAUSE } ,
567 {"setBufferSize", QSETBUFFERSIZE},
568 {"bufferConstraint", QBUFFERCONSTRAINT},
569 {"setStringLength", QSETSTRINGLENGTH},
570 {"testinRange", QTESTINRANGE},
575 ** These tokens are either stand-alone tokens, or followed by
576 ** token-specific text.
579 struct skeyword s_keytable[] = {
580 { "anytype", QANYTYPE } ,
581 { "integraltype", QINTEGRALTYPE } ,
582 { "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
583 { "signedintegraltype", QSIGNEDINTEGRALTYPE } ,
587 { "owned", QOWNED } ,
588 { "dependent", QDEPENDENT } ,
589 { "partial", QPARTIAL } ,
590 { "special", QSPECIAL } ,
591 { "truenull", QTRUENULL } ,
592 { "falsenull", QFALSENULL } ,
595 { "notnull", QNOTNULL } ,
596 { "abstract", QABSTRACT } ,
597 { "concrete", QCONCRETE } ,
598 { "mutable", QMUTABLE } ,
599 { "immutable", QIMMUTABLE } ,
600 { "unused", QUNUSED } ,
601 { "external", QEXTERNAL } ,
603 { "unique", QUNIQUE } ,
604 { "returned", QRETURNED } ,
605 { "exposed", QEXPOSED } ,
606 { "refcounted", QREFCOUNTED } ,
608 { "newref", QNEWREF } ,
609 { "tempref", QTEMPREF } ,
610 { "killref", QKILLREF } ,
612 { "relnull", QRELNULL } ,
613 { "nullterminated", QNULLTERMINATED },
614 { "setBufferSize", QSETBUFFERSIZE },
615 { "bufferConstraint", QBUFFERCONSTRAINT },
616 { "testInRange", QTESTINRANGE},
617 { "MaxSet", QMAXSET},
618 { "MaxRead", QMAXREAD},
619 { "reldef", QRELDEF } ,
620 { "observer", QOBSERVER } ,
621 { "exits", QEXITS } ,
622 { "mayexit", QMAYEXIT } ,
623 { "trueexit", QTRUEEXIT } ,
624 { "falseexit", QFALSEEXIT } ,
625 { "neverexit", QNEVEREXIT } ,
627 { "shared", QSHARED } ,
629 { "unchecked", QUNCHECKED } ,
630 { "checked", QCHECKED } ,
631 { "checkmod", QCHECKMOD } ,
632 { "checkedstrict", QCHECKEDSTRICT } ,
633 { "innercontinue", QINNERCONTINUE } ,
634 { "innerbreak", QINNERBREAK } ,
635 { "loopbreak", QLOOPBREAK } ,
636 { "switchbreak", QSWITCHBREAK } ,
637 { "safebreak", QSAFEBREAK } ,
638 { "fallthrough", QFALLTHROUGH } ,
639 { "l_fallthrou", QLINTFALLTHROUGH } ,
640 { "l_fallth", QLINTFALLTHRU } ,
641 { "notreached", QNOTREACHED } ,
642 { "l_notreach", QLINTNOTREACHED } ,
643 { "printflike", QPRINTFLIKE } ,
644 { "l_printfli", QLINTPRINTFLIKE } ,
645 { "scanflike", QSCANFLIKE } ,
646 { "messagelike", QMESSAGELIKE } ,
647 { "l_argsus", QARGSUSED } ,
652 ** would be better if these weren't hard coded...
655 static bool isArtificial (cstring s)
657 return (cstring_equalLit (s, "modifies")
658 || cstring_equalLit (s, "globals")
659 || cstring_equalLit (s, "alt"));
662 void swallowMacro (void)
665 bool skipnext = FALSE;
667 while ((i = lminput ()) != EOF)
684 checkUngetc (i, yyin);
692 checkUngetc (i, yyin);
696 static int commentMarkerToken (cstring s)
700 while (s_parsetable[i].name != NULL)
702 if (cstring_equalLit (s, s_parsetable[i].name))
704 return s_parsetable[i].token;
713 static int tokenMacroCode (cstring s)
717 while (s_keytable[i].name != NULL)
719 if (cstring_equalLit (s, s_keytable[i].name))
721 if (s_keytable[i].token == QLINTFALLTHROUGH)
724 (FLG_WARNLINTCOMMENTS,
726 ("Traditional lint comment /*FALLTHROUGH*/ used. "
727 "This is interpreted by "
728 "LCLint in the same way as most Unix lints, but it is "
729 "preferable to replace it with the /*@fallthrough@*/ "
734 else if (s_keytable[i].token == QLINTFALLTHRU)
737 (FLG_WARNLINTCOMMENTS,
739 ("Traditional lint comment /*FALLTHRU*/ used. "
740 "This is interpreted by "
741 "LCLint in the same way as most Unix lints, but it is "
742 "preferable to replace it with the /*@fallthrough@*/ "
747 else if (s_keytable[i].token == QLINTNOTREACHED)
750 (FLG_WARNLINTCOMMENTS,
752 ("Traditional lint comment /*NOTREACHED*/ used. "
753 "This is interpreted by "
754 "LCLint in the same way as most Unix lints, but it is "
755 "preferable to replace it with the /*@notreached@*/ "
756 "stylized comment."),
761 else if (s_keytable[i].token == QPRINTFLIKE)
763 setSpecialFunction (QU_PRINTFLIKE);
766 else if (s_keytable[i].token == QLINTPRINTFLIKE)
769 (FLG_WARNLINTCOMMENTS,
771 ("Traditional lint comment /*PRINTFLIKE*/ used. "
772 "This is interpreted by "
773 "LCLint in the same way as most Unix lints, but it is "
774 "preferable to replace it with either /*@printflike@*/, "
775 "/*@scanflike@*/ or /*@messagelike@*/."),
778 setSpecialFunction (QU_PRINTFLIKE);
781 else if (s_keytable[i].token == QSCANFLIKE)
783 setSpecialFunction (QU_SCANFLIKE);
786 else if (s_keytable[i].token == QMESSAGELIKE)
788 setSpecialFunction (QU_MESSAGELIKE);
791 else if (s_keytable[i].token == QARGSUSED)
794 (FLG_WARNLINTCOMMENTS,
796 ("Traditional lint comment /*ARGSUSED*/ used. "
797 "This is interpreted by "
798 "LCLint in the same way as most Unix lints, but it is "
799 "preferable to use /*@unused@*/ annotations on "
800 "the unused parameters."),
807 return s_keytable[i].token;
816 static int lminput ()
818 if (savechar == '\0')
825 int save = (int) savechar;
831 static void lmsavechar (char c)
833 if (savechar == '\0') savechar = c;
836 llbuglit ("lmsavechar: override");
840 static int returnFloat (ctype ct, double f)
842 yylval.expr = exprNode_floatLiteral (f, ct, cstring_fromChars (yytext),
843 fileloc_decColumn (g_currentloc, tokLength));
848 static int returnInt (ctype ct, long i)
852 if (ctype_equal (ct, ctype_int))
856 c = context_typeofZero ();
860 c = context_typeofOne ();
864 yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
865 fileloc_decColumn (g_currentloc, tokLength), i);
870 static int returnChar (char c)
872 yylval.expr = exprNode_charLiteral (c, cstring_fromChars (yytext),
873 fileloc_decColumn (g_currentloc, tokLength));
882 if (c != EOF && ((char)c == '\n'))
884 context_incLineno ();
890 static char macro_nextChar ()
892 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
897 c = char_fromInt (ic);
899 if (!in_quote && !in_char && (c == '\\' || c == BEFORE_COMMENT_MARKER[0]))
903 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
905 ; /* skip to newline */
908 context_incLineno ();
912 return macro_nextChar ();
919 else /* if (c == '@') */
921 if (handleLlSpecial () != BADTOK)
923 llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
926 return macro_nextChar ();
929 else if (!in_escape && c == '\"')
931 in_quote = !in_quote;
933 else if (!in_escape && c == '\'')
937 else if ((in_quote || in_char) && c == '\\')
939 in_escape = !in_escape;
941 else if ((in_quote || in_char) && in_escape)
945 else if (!in_quote && c == '/')
949 if ((c2 = char_fromInt (lminput ())) == '*')
953 while ((c2 = char_fromInt (lminput ())) != '\0'
954 && c2 != '\n' && c2 != '*')
961 while ((c2 = char_fromInt (lminput ())) != '\0'
974 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
978 return macro_nextChar ();
982 /*** putchar does not work! why? puts to stdio...??! ***/
990 ** keeps stylized comments
993 static char macro_nextCharC ()
995 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
998 c = char_fromInt (lminput ());
1000 if (!in_quote && !in_char && c == '\\')
1002 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
1004 ; /* skip to newline */
1007 context_incLineno ();
1011 return macro_nextCharC ();
1018 else if (!in_escape && c == '\"')
1020 in_quote = !in_quote;
1022 else if (!in_escape && c == '\'')
1026 else if ((in_quote || in_char) && c == '\\')
1028 in_escape = !in_escape;
1030 else if ((in_quote || in_char) && in_escape)
1034 else if (!in_quote && c == '/')
1038 if ((c2 = char_fromInt (lminput ())) == '*')
1042 while ((c2 = char_fromInt (lminput ())) != '\0'
1043 && c2 != '\n' && c2 != '*')
1050 while ((c2 = char_fromInt (lminput ())) != '\0'
1063 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
1067 return macro_nextCharC ();
1078 ** skips whitespace (handles line continuations)
1079 ** returns first non-whitespace character
1082 static char skip_whitespace ()
1086 while ((c = macro_nextChar ()) == ' ' || c == '\t')
1094 static void handleMacro ()
1096 cstring mac = cstring_undefined;
1100 while (currentColumn () > 2)
1102 mac = cstring_appendChar (mac, ' ');
1106 c = macro_nextCharC ();
1108 if (c >= '0' && c <= '9')
1112 for (i = 0; i < ((c - '0') + 1); i++)
1114 mac = cstring_appendChar (mac, ' ');
1122 while (((c = macro_nextCharC ()) != '\0') && (c != '\n'))
1124 mac = cstring_appendChar (mac, c);
1128 macrocode = tokenMacroCode (mac);
1130 if (macrocode == BADTOK && !isArtificial (mac))
1132 DPRINTF (("Add macro: %s", mac));
1133 context_addMacroCache (mac);
1142 context_incLineno ();
1146 static bool processMacro (void)
1151 cstring fname = cstring_undefined;
1153 bool isspecfcn = FALSE;
1154 bool isiter = FALSE;
1155 bool skipparam = FALSE;
1156 bool isenditer = FALSE;
1157 bool unknownm = FALSE;
1158 bool hasParams = FALSE;
1159 bool emptyMacro = FALSE;
1160 char c = skip_whitespace ();
1161 fileloc loc = fileloc_noColumn (g_currentloc);
1163 /* are both of these necessary? what do they mean? */
1164 uentryList specparams = uentryList_undefined;
1165 uentryList pn = uentryList_undefined;
1167 context_resetMacroMissingParams ();
1169 if (c == '\0' || c == '\n')
1171 llcontbug (cstring_makeLiteral ("Bad macro"));
1176 fname = cstring_appendChar (fname, c);
1178 while ((c = macro_nextChar ()) != '(' && c != '\0'
1179 && c != ' ' && c != '\t' && c != '\n')
1181 fname = cstring_appendChar (fname, c);
1184 if (c == ' ' || c == '\t' || c == '\n')
1190 while (c == ' ' || c == '\t')
1192 c = macro_nextChar ();
1206 hasParams = (c == '(');
1209 if (usymtab_exists (fname))
1211 e2 = usymtab_lookupExpose (fname);
1212 ct = uentry_getType (e2);
1215 if (uentry_isCodeDefined (e2)
1216 && fileloc_isUser (uentry_whereDefined (e2)))
1220 message ("Macro %s already defined", fname),
1223 uentry_showWhereDefined (e2);
1224 uentry_clearDefined (e2);
1227 if (uentry_isFunction (e2))
1229 uentry_setType (e2, ctype_unknown);
1232 context_enterUnknownMacro (e2);
1236 context_enterConstantMacro (e2);
1241 if (uentry_isForward (e2) && uentry_isFunction (e2))
1248 ("Parameterized macro has no prototype or specification: %s ",
1253 uentry_setType (e2, ctype_unknown);
1254 uentry_setFunctionDefined (e2, loc);
1255 uentry_setUsed (e2, fileloc_undefined);
1256 context_enterUnknownMacro (e2);
1260 if (uentry_isIter (e2))
1263 specparams = uentry_getParams (e2);
1264 noparams = uentryList_size (specparams);
1265 uentry_setDefined (e2, loc);
1266 context_enterIterDef (e2);
1268 else if (uentry_isEndIter (e2))
1271 uentry_setDefined (e2, loc);
1272 context_enterIterEnd (e2); /* don't care about it now */
1273 /* but should parse like an iter! */
1275 else if (uentry_isConstant (e2))
1281 message ("Constant %s implemented as parameterized macro",
1285 uentry_showWhereSpecified (e2);
1286 uentry_setType (e2, ctype_unknown);
1287 uentry_makeVarFunction (e2);
1288 uentry_setDefined (e2, g_currentloc);
1289 uentry_setFunctionDefined (e2, g_currentloc);
1290 context_enterUnknownMacro (e2);
1294 if (!uentry_isSpecified (e2))
1296 fileloc oloc = uentry_whereDeclared (e2);
1298 if (fileloc_isLib (oloc))
1302 else if (fileloc_isUndefined (oloc)
1303 || fileloc_isPreproc (oloc))
1308 (FLG_MACROCONSTDECL,
1310 ("Macro constant %q not declared",
1311 uentry_getName (e2)),
1315 else if (!fileloc_withinLines (oloc, loc, 2))
1316 { /* bogus! will give errors if there is too much whitespace */
1320 ("Macro constant name %s does not match name in "
1321 "previous constant declaration. This constant "
1322 "is declared at %q", fname,
1323 fileloc_unparse (oloc)),
1328 context_enterConstantMacro (e2);
1329 cstring_free (fname);
1335 else if (ctype_isFunction (ct))
1338 specparams = ctype_argsFunction (ct);
1339 noparams = uentryList_size (specparams);
1341 uentry_setFunctionDefined (e2, loc);
1342 context_enterMacro (e2);
1344 else if (uentry_isVar (e2))
1350 message ("Variable %s implemented as parameterized macro",
1354 uentry_showWhereSpecified (e2);
1355 uentry_setType (e2, ctype_unknown);
1356 uentry_makeVarFunction (e2);
1357 uentry_setDefined (e2, g_currentloc);
1358 uentry_setFunctionDefined (e2, g_currentloc);
1359 context_enterUnknownMacro (e2);
1363 uentry ucons = uentry_makeConstant (fname,
1366 if (uentry_isExpandedMacro (e2))
1374 message ("Variable %s implemented by a macro",
1378 uentry_showWhereSpecified (e2);
1382 uentry_setDefined (e2, loc);
1383 uentry_setUsed (ucons, loc);
1385 context_enterConstantMacro (ucons);
1386 uentry_markOwned (ucons);
1387 cstring_free (fname);
1393 if (uentry_isDatatype (e2))
1397 message ("Type implemented as macro: %x",
1398 uentry_getName (e2)),
1399 message ("A type is implemented using a macro definition. A "
1400 "typedef should be used instead."),
1404 /* Must exit scope (not sure why a new scope was entered?) */
1405 usymtab_quietExitScope (g_currentloc);
1406 uentry_setDefined (e2, g_currentloc);
1412 (message ("Unexpanded macro not function or constant: %q",
1413 uentry_unparse (e2)));
1414 uentry_setType (e2, ctype_unknown);
1418 uentry_makeVarFunction (e2);
1419 uentry_setDefined (e2, g_currentloc);
1420 uentry_setFunctionDefined (e2, g_currentloc);
1421 context_enterUnknownMacro (e2);
1433 (FLG_MACROMATCHNAME,
1434 message ("Unexpanded macro %s does not match name of a constant "
1435 "or iter declaration. The name used in the control "
1436 "comment on the previous line should match. "
1437 "(Assuming macro defines a constant.)",
1442 ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);
1443 uentry_setUsed (ce, loc); /* perhaps bogus? */
1444 e2 = usymtab_supEntryReturn (ce);
1446 context_enterConstantMacro (e2);
1447 cstring_free (fname);
1452 /* in macros, ( must follow immediatetly after name */
1458 c = skip_whitespace ();
1460 while (c != ')' && c != '\0')
1463 bool suppress = context_inSuppressRegion ();
1464 cstring paramname = cstring_undefined;
1467 ** save the parameter location
1471 context_saveLocation ();
1474 while (c != ' ' && c != '\t' && c != ',' && c != '\0' && c != ')')
1476 paramname = cstring_appendChar (paramname, c);
1477 c = macro_nextChar ();
1480 if (c == ' ' || c == '\t') c = skip_whitespace ();
1484 c = macro_nextChar ();
1485 if (c == ' ' || c == '\t') c = skip_whitespace ();
1490 llfatalerror (cstring_makeLiteral
1491 ("Bad macro syntax: uentryList"));
1494 if ((isspecfcn || isiter) && (paramno < noparams)
1495 && !uentry_isElipsisMarker (uentryList_getN
1496 (specparams, paramno)))
1498 uentry decl = uentryList_getN (specparams, paramno);
1501 param = uentry_nameCopy (paramname, decl);
1504 uentry_setParam (param);
1505 sr = sRef_makeParam (paramno, uentry_getType (param));
1507 if (sRef_getNullState (sr) == NS_ABSNULL)
1509 ctype pt = ctype_realType (uentry_getType (param));
1511 if (ctype_isUser (pt))
1513 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (pt));
1515 if (uentry_isValid (te))
1517 sRef_setStateFromUentry (sr, te);
1522 sRef_setNullState (sr, NS_UNKNOWN, g_currentloc);
1526 uentry_setSref (param, sr);
1527 uentry_setDeclaredForceOnly (param, context_getSaveLocation ());
1529 skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
1533 fileloc sloc = context_getSaveLocation ();
1535 param = uentry_makeVariableSrefParam
1536 (paramname, ctype_unknown, sRef_makeParam (paramno, ctype_unknown));
1537 cstring_free (paramname);
1539 sRef_setPosNull (uentry_getSref (param), sloc);
1541 uentry_setDeclaredForce (param, sloc);
1544 fileloc_free (sloc);
1549 llassert (!uentry_isElipsisMarker (param));
1553 sRef_makeUnsafe (uentry_getSref (param));
1556 pn = uentryList_add (pn, uentry_copy (param));
1557 usymtab_supEntry (param);
1561 /* don't add param */
1562 uentry_free (param);
1567 (void) macro_nextChar ();
1568 c = skip_whitespace ();
1576 if (isspecfcn || isiter)
1578 if (paramno != noparams && noparams >= 0)
1584 message ("Macro %s specified with %d args, defined with %d",
1585 fname, noparams, paramno),
1588 uentry_showWhereSpecified (e2);
1589 uentry_resetParams (e2, pn);
1594 uentry_resetParams (e2, pn);
1601 ** the form should be:
1603 ** # define newname oldname
1604 ** where oldname refers to a function matching the specification
1610 sRef_setGlobalScope ();
1611 usymtab_supGlobalEntry (uentry_makeVariableLoc (fname, ctype_unknown));
1612 sRef_clearGlobalScope ();
1616 context_setMacroMissingParams ();
1621 /* context_setuentryList (pn); */
1622 usymtab_enterScope ();
1625 cstring_free (fname);
1630 static bool handleSpecial (char *yyt)
1632 char *l = mstring_create (MAX_NAME_LENGTH);
1633 static bool reportcpp = FALSE;
1639 strcpy (l, yyt + 1);
1641 /* Need to safe original l for deallocating. */
1644 l += strlen (yyt) - 1;
1646 while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
1652 olc = cstring_fromChars (ol);
1654 if (cstring_equalPrefix (olc, "pragma"))
1656 char *pname = mstring_create (longUnsigned_fromInt (MAX_PRAGMA_LEN));
1657 char *opname = pname;
1658 char *ptr = ol + 6; /* pragma is six characters, plus space */
1662 /* skip whitespace */
1663 while (((c = *ptr) != '\0') && isspace (c))
1669 while (((c = *ptr) != '\0') && !isspace (c))
1673 if (len > MAX_PRAGMA_LEN)
1684 if (len == PRAGMA_LEN_EXPAND
1685 && mstring_equal (opname, PRAGMA_EXPAND))
1687 cstring exname = cstring_undefined;
1691 while (((c = *ptr) != '\0') && !isspace (c))
1693 exname = cstring_appendChar (exname, c);
1698 ue = usymtab_lookupExposeGlob (exname);
1700 if (uentry_isExpandedMacro (ue))
1702 if (fileloc_isPreproc (uentry_whereDefined (ue)))
1704 fileloc_setColumn (g_currentloc, 1);
1705 uentry_setDefined (ue, g_currentloc);
1709 cstring_free (exname);
1712 else if (cstring_equalPrefix (olc, "ident"))
1714 /* Some pre-processors will leave these in the code. Ignore rest of line */
1717 ** Yuk...Win32 filenames can have spaces in them...we need to read
1718 ** to the matching end quote.
1720 else if ((sscanf (ol, "line %d \"", &lineno) == 1)
1721 || (sscanf (ol, " %d \"", &lineno) == 1))
1727 while (*tmp != '\"' && *tmp != '\0')
1732 llassert (*tmp == '\"');
1737 while (*tmp != '\"' && *tmp != '\0')
1742 llassert (*tmp == '\"');
1746 DPRINTF (("fname: %s", fname));
1748 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
1751 ** DOS-like path delimiters get delivered in pairs, something like
1752 ** \"..\\\\file.h\", so we have to make it normal again. We do NOT
1753 ** remove the pre dirs yet as we usually specify tmp paths relative
1754 ** to the current directory, so tmp files would not get found in
1755 ** the hash table. If this method fails we try it again later.
1762 ** Skip past the drive marker.
1765 DPRINTF (("stmp: %s / %s", stmp, fname));
1767 if (strchr (stmp, ':') != NULL)
1769 stmp = strchr (stmp, ':') + 1;
1772 DPRINTF (("stmp: %s / %s", stmp, fname));
1774 while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
1776 if (*(stmp+1) == CONNECTCHAR)
1778 memmove (stmp, stmp+1, strlen (stmp));
1782 DPRINTF (("stmp: %s / %s", stmp, fname));
1785 DPRINTF (("Now: base = %s", fname));
1787 fid = fileTable_lookupBase (context_fileTable (),
1788 cstring_fromChars (fname));
1789 if (!(fileId_isValid (fid)))
1791 fname = removePreDirs (fname);
1792 fid = fileTable_lookupBase (context_fileTable (),
1793 cstring_fromChars (fname));
1796 # else /* !defined(OS2) && !defined(MSDOS) */
1797 fname = removePreDirs (fname);
1798 fid = fileTable_lookupBase (context_fileTable (),
1799 cstring_fromChars (fname));
1800 # endif /* !defined(OS2) && !defined(MSDOS) */
1802 if (!(fileId_isValid (fid)))
1804 if (isHeaderFile (cstring_fromChars (fname)))
1806 fid = fileTable_addHeaderFile (context_fileTable (),
1807 cstring_fromChars (fname));
1811 fid = fileTable_addFile (context_fileTable (),
1812 cstring_fromChars (fname));
1816 setFileLine (fid, lineno);
1818 else if ((sscanf (ol, "line %d", &lineno) == 1)
1819 || (sscanf (ol, " %d", &lineno) == 1))
1821 setLine (lineno); /* next line is <cr> */
1825 if (mstring_equal (ol, "")) {
1826 DPRINTF (("Empty pp command!"));
1828 ** evs 2000-05-16: This is a horrible kludge, to get around a bug (well, difficulty) in the pre-processor.
1829 ** We handle a plain # in the input file, by echoing it, and ignoring it in the post-pp-file.
1838 llbug (message ("File contains preprocessor command: #%s",
1839 cstring_fromChars (ol)));
1852 static int handleLlSpecial ()
1856 char *s = mstring_createEmpty ();
1861 while (((ic = ninput ()) != 0) && isalpha (ic))
1864 s = mstring_append (s, c);
1870 if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
1874 llassert (ic == AFTER_COMMENT_MARKER[1]);
1877 if (isProcessingGlobMods () && (*s == '\0'))
1880 return QNOMODS; /* special token no modifications token */
1888 tok = commentMarkerToken (cstring_fromChars (os));
1892 tokLength = charsread;
1898 /* Add rest of the comment */
1900 if (ic != 0 && ic != EOF)
1905 s = mstring_append (s, c);
1908 while (((ic = ninput ()) != 0) && (ic != EOF)
1909 && (ic != AFTER_COMMENT_MARKER[0]))
1912 s = mstring_append (s, c);
1917 if (ic == AFTER_COMMENT_MARKER[0])
1920 llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
1927 while (*s == ' ' || *s == '\t' || *s == '\n')
1932 if (*s == '-' || *s == '+' || *s == '=') /* setting flags */
1936 while (c == '-' || c == '+' || c == '=')
1938 ynm set = ynm_fromCodeChar (c);
1943 thisflag = cstring_fromChars (s);
1945 while ((c = *s) != '\0' && (c != '-') && (c != '=')
1946 && (c != '+') && (c != ' ') && (c != '\t') && (c != '\n'))
1953 if (!context_getFlag (FLG_NOCOMMENTS))
1955 cstring flagname = thisflag;
1956 flagcode fflag = identifyFlag (flagname);
1958 if (flagcode_isSkip (fflag))
1962 else if (flagcode_isInvalid (fflag))
1964 if (isMode (flagname))
1966 if (ynm_isMaybe (set))
1971 ("Stylized comment attempts to restore flag %s. "
1972 "A mode flag cannot be restored.",
1977 context_setMode (flagname);
1984 message ("Unrecognized option in stylized comment: %s",
1988 else if (flagcode_isGlobalFlag (fflag))
1993 ("Stylized comment attempts to set global flag %s. "
1994 "A global flag cannot be set locally.",
1999 context_fileSetFlag (fflag, set);
2001 if (flagcode_hasArgument (fflag))
2003 if (ynm_isMaybe (set))
2008 ("Stylized comment attempts to restore flag %s. "
2009 "A flag for setting a value cannot be restored.",
2013 { /* cut-and-pastied from llmain...blecch */
2014 cstring extra = cstring_undefined;
2020 rest = mstring_copy (s);
2024 while ((rchar = *rest) != '\0'
2025 && (isspace (rchar)))
2031 while ((rchar = *rest) != '\0'
2032 && !isspace (rchar))
2034 extra = cstring_appendChar (extra, rchar);
2041 if (cstring_isUndefined (extra))
2046 ("Flag %s (in stylized comment) must be followed by an argument",
2047 flagcode_unparse (fflag)));
2053 if (flagcode_hasValue (fflag))
2055 setValueFlag (fflag, extra);
2057 else if (flagcode_hasString (fflag))
2059 setStringFlag (fflag, extra);
2076 while ((c == ' ') || (c == '\t') || (c == '\n'))
2082 if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
2084 context_addComment (cstring_fromCharsNew (os));
2097 while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
2109 t = cstring_toCharsSafe (cstring_downcase (cstring_fromChars (t)));
2110 macrocode = tokenMacroCode (cstring_fromChars (t));
2112 if (macrocode != BADTOK)
2114 tokLength = mstring_length (t);
2120 if (macrocode == SKIPTOK)
2128 if (context_inHeader ())
2135 if ((context_inMacro () || context_inGlobalContext ())
2136 && macrocode != SKIPTOK
2137 && !isArtificial (cstring_fromChars (os)))
2139 context_addComment (cstring_fromCharsNew (os));
2152 if (mstring_equal (t, "ignore"))
2154 if (!context_getFlag (FLG_NOCOMMENTS))
2156 context_enterSuppressRegion ();
2159 else if ((*t == 'i' || *t == 't')
2160 && (*(t + 1) == '\0'))
2162 if (!context_getFlag (FLG_NOCOMMENTS)
2163 && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
2165 context_enterSuppressLine (-1); /* infinite suppression */
2168 else if (((*t == 'i') || (*t == 't'))
2169 && ((*(t + 1) >= '0' && *(t + 1) <= '9')))
2171 bool tmpcomment = (*t == 't');
2173 char *tt = t; /* don't mangle t, since it is free'd */
2176 if (lc >= '0' && lc <= '9')
2178 val = (int)(lc - '0');
2181 while (lc >= '0' && lc <= '9')
2190 if (!context_getFlag (FLG_NOCOMMENTS)
2191 && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
2193 context_enterSuppressLine (val);
2196 else if (mstring_equal (t, "end"))
2198 if (!context_getFlag (FLG_NOCOMMENTS))
2200 context_exitSuppressRegion ();
2203 else if (mstring_equal (t, "notfunction"))
2205 ; /* handled by pcpp */
2207 else if (mstring_equal (t, "access"))
2213 while ((c = *s) && (c == ' ' || c == '\t' || c == '\n'))
2223 tname = cstring_fromChars (s);
2225 while ((c = *s) != '\0' && c != ' '
2226 && c != '\t' && c != '\n' && c != ',')
2234 if (!context_getFlag (FLG_NOCOMMENTS)
2235 && !context_getFlag (FLG_NOACCESS))
2237 if (usymtab_existsType (tname))
2239 usymId uid = usymtab_getTypeId (tname);
2240 context_addFileAccessType (uid);
2244 if (!(context_inSuppressRegion ()
2245 || context_inSuppressZone (g_currentloc)))
2249 ("%q: Unrecognized type %s used in access comment",
2250 fileloc_unparse (g_currentloc), tname));
2260 if (c != ',' && c != ' ')
2266 else if (mstring_equal (t, "noaccess"))
2273 while ((lc = *s) && (lc == ' ' || lc == '\t' || lc == '\n'))
2283 tname = cstring_fromChars (s);
2285 while ((lc = *s) != '\0' && lc != ' ' && lc != '\t'
2286 && lc != '\n' && lc != ',')
2293 if (!context_getFlag (FLG_NOCOMMENTS)
2294 && !context_getFlag (FLG_NOACCESS))
2296 if (usymtab_existsType (tname))
2298 typeId tuid = usymtab_getTypeId (tname);
2300 if (context_couldHaveAccess (tuid))
2302 context_removeFileAccessType (tuid);
2306 if (!(context_inSuppressRegion ()
2307 || context_inSuppressZone (g_currentloc)))
2309 uentry ue = usymtab_getTypeEntry (tuid);
2311 if (uentry_isAbstractDatatype (ue))
2315 ("%q: Non-accessible abstract type %s used in noaccess comment",
2316 fileloc_unparse (g_currentloc), tname));
2322 ("%q: Non-abstract type %s used in noaccess comment",
2323 fileloc_unparse (g_currentloc), tname));
2330 if (!(context_inSuppressRegion ()
2331 || context_inSuppressZone (g_currentloc)))
2335 ("%q: Unrecognized type %s used in noaccess comment",
2336 fileloc_unparse (g_currentloc), tname));
2346 if (lc != ',' && lc != ' ')
2354 setTokLength (- (2 + charsread));
2356 voptgenerror (FLG_UNRECOGCOMMENTS,
2357 message ("Stylized comment unrecognized: %s",
2358 cstring_fromChars (os)),
2369 static /*@only@*/ cstring makeIdentifier (char *s)
2371 char *c = mstring_create (size_toInt (strlen (s)) + 1);
2372 cstring id = cstring_fromChars (c);
2374 while (isalnum (*s) || (*s == '_') || (*s == '$'))
2383 /*@observer@*/ /*@dependent@*/ uentry coerceId (cstring cn)
2385 if (!(usymtab_exists (cn)))
2387 fileloc loc = fileloc_createExternal ();
2390 ** We need to put this in a global scope, otherwise the sRef will be deallocated.
2393 uentry ce = uentry_makeUnrecognized (cn, loc);
2395 if (!context_inIterEnd ())
2399 message ("Unrecognized (possibly system) identifier: %q",
2400 uentry_getName (ce)),
2407 return (usymtab_lookup (cn));
2411 ** like, coerceId, but doesn't supercede for iters
2414 /*@observer@*/ uentry coerceIterId (cstring cn)
2416 if (!(usymtab_exists (cn)))
2418 return uentry_undefined;
2421 return (usymtab_lookup (cn));
2424 /*@observer@*/ cstring LastIdentifier ()
2426 return (lastidprocessed);
2429 static int processIdentifier (cstring id)
2433 DPRINTF (("Process identifier: %s", id));
2435 context_clearJustPopped ();
2436 lastidprocessed = id;
2438 if (context_inFunctionDecl ())
2440 int tok = commentMarkerToken (id);
2448 tok = tokenMacroCode (id);
2457 /* Consider handling: Defined by C99 as static const char __func__[] */
2459 if (context_getFlag (FLG_GNUEXTENSIONS))
2463 if (cstring_equalLit (id, "__stdcall")
2464 || cstring_equalLit (id, "__cdecl")
2465 || cstring_equalLit (id, "__extension__"))
2469 else if (cstring_equalLit (id, "__volatile__"))
2473 else if (cstring_equalLit (id, "__signed"))
2477 else if (cstring_equalLit (id, "__unsigned"))
2481 else if (cstring_equalLit (id, "__const__"))
2485 else if (cstring_equalLit (id, "__alignof__"))
2487 tok = CALIGNOF; /* alignof is parsed like sizeof */
2489 else if (cstring_equalLit (id, "__FUNCTION__")
2490 || cstring_equalLit (id, "__PRETTY_FUNCTION__"))
2492 /* These tokens hold the name of the current function as strings */
2493 yylval.expr = exprNode_stringLiteral (id, fileloc_copy (g_currentloc));
2495 lastWasString = TRUE;
2499 else if (cstring_equalLit (id, "__attribute__")
2500 || cstring_equalLit (id, "__asm__")
2501 || cstring_equalLit (id, "_asm")
2502 || cstring_equalLit (id, "__asm")
2503 || cstring_equalLit (id, "__declspec"))
2506 bool useparens = FALSE;
2507 bool usebraces = FALSE;
2508 bool inquote = FALSE;
2509 bool inescape = FALSE;
2512 while ((ic = input ()) != EOF)
2519 else if (ic == '\\')
2523 else if (ic == '\"')
2559 else if (ic == ')' && useparens)
2562 if (depth == 0) break;
2564 else if (ic == '}' && usebraces)
2567 if (depth == 0) break;
2570 && !usebraces && !useparens
2571 && cstring_equalLit (id, "__asm"))
2574 ** We need this because some MS VC++ include files
2575 ** have __asm mov ... }
2576 ** Its a kludge, but otherwise would need to parse
2585 context_incLineno ();
2587 if (cstring_equalLit (id, "__asm")
2588 && !useparens && !usebraces)
2595 llassert ((useparens && ic == ')')
2596 || (usebraces && ic == '}')
2597 || (!useparens && !usebraces));
2601 else if (cstring_equalLit (id, "inline")
2602 || cstring_equalLit (id, "__inline")
2603 || cstring_equalLit (id, "_inline")
2604 || cstring_equalLit (id, "__inline__"))
2615 le = usymtab_lookupSafe (id);
2617 /*@-dependenttrans@*/
2619 if (uentry_isIter (le))
2624 else if (uentry_isEndIter (le))
2627 return (ITER_ENDNAME);
2629 else if (uentry_isUndefined (le))
2633 /* avoid parse errors for certain system built ins */
2635 if (g_expectingTypeName && (cstring_firstChar (id) == '_')
2636 && (cstring_secondChar (id) == '_'))
2638 return (TYPE_NAME_OR_ID);
2641 return (NEW_IDENTIFIER);
2643 else if (!uentry_isDeclared (le) && !uentry_isCodeDefined (le))
2645 if (uentry_isDatatype (le))
2648 return (NEW_IDENTIFIER);
2653 return (IDENTIFIER);
2656 else if (uentry_isDatatype (le))
2658 if (!g_expectingTypeName)
2662 return (NEW_IDENTIFIER);
2666 yylval.ctyp = uentry_getAbstractType (le);
2668 uentry_setUsed (le, g_currentloc);
2675 return (IDENTIFIER);
2678 /*@=dependenttrans@*/
2681 static bool processHashIdentifier (/*@only@*/ cstring id)
2683 if (context_inMacro () || context_inIterDef () ||
2684 context_inIterEnd ())
2688 context_clearJustPopped ();
2690 lastidprocessed = id;
2691 le = usymtab_lookupSafe (id);
2693 if (uentry_isParam (le) || uentry_isRefParam (le))
2710 static /*@only@*/ exprNode processString ()
2714 char *nl = strchr (yytext, '\n');
2715 cstring ns = cstring_fromCharsNew (yytext);
2719 loc = fileloc_copy (g_currentloc);
2720 addColumn (cstring_length (ns));
2726 loc = fileloc_copy (g_currentloc);
2728 context_incLineno ();
2730 while ((nl = strchr ((nl + 1), '\n')) != NULL)
2732 context_incLineno ();
2738 res = exprNode_stringLiteral (ns, loc);
2748 llassert (*yytext != '\0');
2749 fchar = *(yytext + 1);
2750 if (fchar != '\\') return fchar;
2752 next = *(yytext + 2);
2756 case 'n': return '\n';
2757 case 't': return '\t';
2758 case '\"': return '\"';
2759 case '\'': return '\'';
2760 case '\\': return '\\';
2761 default: return '\0';
2766 double processFloat ()
2768 double ret = atof (yytext);
2779 llassert (yytext[0] == '0'
2780 && (yytext[1] == 'X' || yytext[1] == 'x'));
2782 while (yytext[index] != '\0') {
2784 char c = yytext[index];
2786 if (c >= '0' && c <= '9') {
2787 tval = (int) c - (int) '0';
2788 } else if (c >= 'A' && c <= 'F') {
2789 tval = (int) c - (int) 'A' + 10;
2790 } else if (c >= 'a' && c <= 'f') {
2791 tval = (int) c - (int) 'a' + 10;
2792 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2794 while (yytext[index] != '\0') {
2795 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2800 message ("Invalid character (%c) following specifier in hex constant: %s",
2801 c, cstring_fromChars (yytext)),
2811 message ("Invalid character (%c) in hex constant: %s",
2812 c, cstring_fromChars (yytext)),
2817 val = (val * 16) + tval;
2821 DPRINTF (("Hex constant: %s = %ld", yytext, val));
2826 long processOctal ()
2831 llassert (yytext[0] == '0' && yytext[1] != 'X' && yytext[1] != 'x');
2833 while (yytext[index] != '\0') {
2835 char c = yytext[index];
2837 if (c >= '0' && c <= '7') {
2838 tval = (int) c - (int) '0';
2842 message ("Invalid character (%c) in octal constant: %s",
2843 c, cstring_fromChars (yytext)),
2848 val = (val * 8) + tval;
2852 DPRINTF (("Octal constant: %s = %ld", yytext, val));
2859 return (atol (yytext));
2863 processSpec (int tok)
2865 size_t length = strlen (yytext);
2870 setTokLengthT (length);
2876 context_saveLocation ();
2877 setTokLengthT (length);
2878 return (processIdentifier (makeIdentifier (yytext)));