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); }
432 "/\\" { setTokLength (1); RETURN_TOK (TCAND); }
435 [ \t\v\f] { incColumn (); }
436 \n { context_incLineno ();
439 continueLine = FALSE;
443 if (context_inMacro ())
445 /* Don't use RETURN_TOK */
446 yylval.tok = lltok_create (TENDMACRO, g_currentloc);
447 lastWasString = FALSE;
452 "@@MR@@" { setTokLength (6);
454 if (processMacro ()) {
455 if (context_inIterDef ())
457 RETURN_TOK (LLMACROITER);
459 if (context_inIterEnd ())
461 RETURN_TOK (LLMACROEND);
463 if (context_inMacro ())
465 RETURN_TOK (LLMACRO);
469 "@QLMR" { if (context_inHeader () || context_inFunction ())
475 int nspchar = ninput ();
479 ** This is a hack to get the column number correct.
482 llassert (nspchar >= '0' && nspchar <= '9');
484 nspaces = nspchar - '0';
486 setTokLength (5 + nspaces);
490 if (context_inIterDef ())
492 RETURN_TOK (LLMACROITER);
494 if (context_inIterEnd ())
496 RETURN_TOK (LLMACROEND);
498 if (context_inMacro ())
500 RETURN_TOK (LLMACRO);
505 "@.CT" { setTokLength (4); lldiagmsg (ctype_unparseTable ()); }
506 "@.F" { setTokLength (3);
507 lldiagmsg (message ("%q: *** marker ***", fileloc_unparse (g_currentloc)));
509 "@.L" { setTokLength (3); usymtab_printLocal (); }
510 "@.A" { setTokLength (3); lldiagmsg (usymtab_unparseAliases ()); }
511 "@.C" { setTokLength (3); lldiagmsg (context_unparse ()); }
512 "@.W" { setTokLength (3); lldiagmsg (context_unparseClauses ()); }
513 "@.G" { setTokLength (3); usymtab_printGuards (); }
514 "@.S" { setTokLength (3); usymtab_printOut (); }
515 "@.X" { setTokLength (3); usymtab_printAll (); }
516 "@.Z" { setTokLength (3); usymtab_printComplete (); }
517 "@.T" { setTokLength (3); usymtab_printTypes (); }
518 "@.K" { setTokLength (3); lldiagmsg (usymtab_unparseStack ()); }
519 "@.M" { setTokLength (3);
520 lldiagmsg (message ("Can modify: %q",
521 sRefSet_unparse (context_modList ())));
523 "%{" { /* BEFORE_COMMENT_MARKER */
525 incColumn (); incColumn ();
526 tok = handleLlSpecial ();
532 "%}" { /* AFTER_COMMENT_MARKER */
535 RETURN_TOK (QENDMACRO); }
536 "\\" { incColumn (); continueLine = TRUE; }
540 message ("Invalid character (ascii: %d), skipping character",
548 /*@null@*/ /*@observer@*/ char *name;
553 ** These tokens are followed by syntax that is parsed by the
557 struct skeyword s_parsetable[] = {
558 { "modifies", QMODIFIES } ,
559 { "globals", QGLOBALS } ,
561 { "constant", QCONSTANT } ,
562 { "function", QFUNCTION } ,
564 { "defines", QDEFINES } ,
566 { "allocates", QALLOCATES } ,
568 { "releases", QRELEASES } ,
569 { "pre", QPRECLAUSE } ,
570 { "post", QPOSTCLAUSE } ,
571 {"setBufferSize", QSETBUFFERSIZE},
572 {"requires", QBUFFERCONSTRAINT},
573 {"ensures", QENSURESCONSTRAINT},
574 {"setStringLength", QSETSTRINGLENGTH},
575 {"testinRange", QTESTINRANGE},
580 ** These tokens are either stand-alone tokens, or followed by
581 ** token-specific text.
584 struct skeyword s_keytable[] = {
585 { "anytype", QANYTYPE } ,
586 { "integraltype", QINTEGRALTYPE } ,
587 { "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
588 { "signedintegraltype", QSIGNEDINTEGRALTYPE } ,
592 { "owned", QOWNED } ,
593 { "dependent", QDEPENDENT } ,
594 { "partial", QPARTIAL } ,
595 { "special", QSPECIAL } ,
596 { "truenull", QTRUENULL } ,
597 { "falsenull", QFALSENULL } ,
600 { "notnull", QNOTNULL } ,
601 { "abstract", QABSTRACT } ,
602 { "concrete", QCONCRETE } ,
603 { "mutable", QMUTABLE } ,
604 { "immutable", QIMMUTABLE } ,
605 { "unused", QUNUSED } ,
606 { "external", QEXTERNAL } ,
608 { "unique", QUNIQUE } ,
609 { "returned", QRETURNED } ,
610 { "exposed", QEXPOSED } ,
611 { "refcounted", QREFCOUNTED } ,
613 { "newref", QNEWREF } ,
614 { "tempref", QTEMPREF } ,
615 { "killref", QKILLREF } ,
617 { "relnull", QRELNULL } ,
618 { "nullterminated", QNULLTERMINATED },
619 { "setBufferSize", QSETBUFFERSIZE },
620 { "requires", QBUFFERCONSTRAINT },
621 { "ensures", QENSURESCONSTRAINT },
622 { "testInRange", QTESTINRANGE},
623 { "MaxSet", QMAXSET},
624 { "MaxRead", QMAXREAD},
625 { "reldef", QRELDEF } ,
626 { "observer", QOBSERVER } ,
627 { "exits", QEXITS } ,
628 { "mayexit", QMAYEXIT } ,
629 { "trueexit", QTRUEEXIT } ,
630 { "falseexit", QFALSEEXIT } ,
631 { "neverexit", QNEVEREXIT } ,
633 { "shared", QSHARED } ,
635 { "unchecked", QUNCHECKED } ,
636 { "checked", QCHECKED } ,
637 { "checkmod", QCHECKMOD } ,
638 { "checkedstrict", QCHECKEDSTRICT } ,
639 { "innercontinue", QINNERCONTINUE } ,
640 { "innerbreak", QINNERBREAK } ,
641 { "loopbreak", QLOOPBREAK } ,
642 { "switchbreak", QSWITCHBREAK } ,
643 { "safebreak", QSAFEBREAK } ,
644 { "fallthrough", QFALLTHROUGH } ,
645 { "l_fallthrou", QLINTFALLTHROUGH } ,
646 { "l_fallth", QLINTFALLTHRU } ,
647 { "notreached", QNOTREACHED } ,
648 { "l_notreach", QLINTNOTREACHED } ,
649 { "printflike", QPRINTFLIKE } ,
650 { "l_printfli", QLINTPRINTFLIKE } ,
651 { "scanflike", QSCANFLIKE } ,
652 { "messagelike", QMESSAGELIKE } ,
653 { "l_argsus", QARGSUSED } ,
658 ** would be better if these weren't hard coded...
661 static bool isArtificial (cstring s)
663 return (cstring_equalLit (s, "modifies")
664 || cstring_equalLit (s, "globals")
665 || cstring_equalLit (s, "alt"));
668 void swallowMacro (void)
671 bool skipnext = FALSE;
673 while ((i = lminput ()) != EOF)
690 checkUngetc (i, yyin);
698 checkUngetc (i, yyin);
702 static int commentMarkerToken (cstring s)
706 while (s_parsetable[i].name != NULL)
708 if (cstring_equalLit (s, s_parsetable[i].name))
710 return s_parsetable[i].token;
719 static int tokenMacroCode (cstring s)
723 while (s_keytable[i].name != NULL)
725 if (cstring_equalLit (s, s_keytable[i].name))
727 if (s_keytable[i].token == QLINTFALLTHROUGH)
730 (FLG_WARNLINTCOMMENTS,
732 ("Traditional lint comment /*FALLTHROUGH*/ used. "
733 "This is interpreted by "
734 "LCLint in the same way as most Unix lints, but it is "
735 "preferable to replace it with the /*@fallthrough@*/ "
740 else if (s_keytable[i].token == QLINTFALLTHRU)
743 (FLG_WARNLINTCOMMENTS,
745 ("Traditional lint comment /*FALLTHRU*/ used. "
746 "This is interpreted by "
747 "LCLint in the same way as most Unix lints, but it is "
748 "preferable to replace it with the /*@fallthrough@*/ "
753 else if (s_keytable[i].token == QLINTNOTREACHED)
756 (FLG_WARNLINTCOMMENTS,
758 ("Traditional lint comment /*NOTREACHED*/ used. "
759 "This is interpreted by "
760 "LCLint in the same way as most Unix lints, but it is "
761 "preferable to replace it with the /*@notreached@*/ "
762 "stylized comment."),
767 else if (s_keytable[i].token == QPRINTFLIKE)
769 setSpecialFunction (QU_PRINTFLIKE);
772 else if (s_keytable[i].token == QLINTPRINTFLIKE)
775 (FLG_WARNLINTCOMMENTS,
777 ("Traditional lint comment /*PRINTFLIKE*/ used. "
778 "This is interpreted by "
779 "LCLint in the same way as most Unix lints, but it is "
780 "preferable to replace it with either /*@printflike@*/, "
781 "/*@scanflike@*/ or /*@messagelike@*/."),
784 setSpecialFunction (QU_PRINTFLIKE);
787 else if (s_keytable[i].token == QSCANFLIKE)
789 setSpecialFunction (QU_SCANFLIKE);
792 else if (s_keytable[i].token == QMESSAGELIKE)
794 setSpecialFunction (QU_MESSAGELIKE);
797 else if (s_keytable[i].token == QARGSUSED)
800 (FLG_WARNLINTCOMMENTS,
802 ("Traditional lint comment /*ARGSUSED*/ used. "
803 "This is interpreted by "
804 "LCLint in the same way as most Unix lints, but it is "
805 "preferable to use /*@unused@*/ annotations on "
806 "the unused parameters."),
813 return s_keytable[i].token;
822 static int lminput ()
824 if (savechar == '\0')
831 int save = (int) savechar;
837 static void lmsavechar (char c)
839 if (savechar == '\0') savechar = c;
842 llbuglit ("lmsavechar: override");
846 static int returnFloat (ctype ct, double f)
848 yylval.expr = exprNode_floatLiteral (f, ct, cstring_fromChars (yytext),
849 fileloc_decColumn (g_currentloc, tokLength));
854 static int returnInt (ctype ct, long i)
858 if (ctype_equal (ct, ctype_int))
862 c = context_typeofZero ();
866 c = context_typeofOne ();
870 yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext),
871 fileloc_decColumn (g_currentloc, tokLength), i);
876 static int returnChar (char c)
878 yylval.expr = exprNode_charLiteral (c, cstring_fromChars (yytext),
879 fileloc_decColumn (g_currentloc, tokLength));
888 if (c != EOF && ((char)c == '\n'))
890 context_incLineno ();
896 static char macro_nextChar ()
898 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
903 c = char_fromInt (ic);
905 if (!in_quote && !in_char && (c == '\\' || c == BEFORE_COMMENT_MARKER[0]))
909 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
911 ; /* skip to newline */
914 context_incLineno ();
918 return macro_nextChar ();
925 else /* if (c == '@') */
927 if (handleLlSpecial () != BADTOK)
929 llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
932 return macro_nextChar ();
935 else if (!in_escape && c == '\"')
937 in_quote = !in_quote;
939 else if (!in_escape && c == '\'')
943 else if ((in_quote || in_char) && c == '\\')
945 in_escape = !in_escape;
947 else if ((in_quote || in_char) && in_escape)
951 else if (!in_quote && c == '/')
955 if ((c2 = char_fromInt (lminput ())) == '*')
959 while ((c2 = char_fromInt (lminput ())) != '\0'
960 && c2 != '\n' && c2 != '*')
967 while ((c2 = char_fromInt (lminput ())) != '\0'
980 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
984 return macro_nextChar ();
988 /*** putchar does not work! why? puts to stdio...??! ***/
996 ** keeps stylized comments
999 static char macro_nextCharC ()
1001 static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
1004 c = char_fromInt (lminput ());
1006 if (!in_quote && !in_char && c == '\\')
1008 while ((c = char_fromInt (lminput ())) != '\0' && c != '\n')
1010 ; /* skip to newline */
1013 context_incLineno ();
1017 return macro_nextCharC ();
1024 else if (!in_escape && c == '\"')
1026 in_quote = !in_quote;
1028 else if (!in_escape && c == '\'')
1032 else if ((in_quote || in_char) && c == '\\')
1034 in_escape = !in_escape;
1036 else if ((in_quote || in_char) && in_escape)
1040 else if (!in_quote && c == '/')
1044 if ((c2 = char_fromInt (lminput ())) == '*')
1048 while ((c2 = char_fromInt (lminput ())) != '\0'
1049 && c2 != '\n' && c2 != '*')
1056 while ((c2 = char_fromInt (lminput ())) != '\0'
1069 llfatalerror (cstring_makeLiteral ("Macro: bad comment!"));
1073 return macro_nextCharC ();
1084 ** skips whitespace (handles line continuations)
1085 ** returns first non-whitespace character
1088 static char skip_whitespace ()
1092 while ((c = macro_nextChar ()) == ' ' || c == '\t')
1100 static void handleMacro ()
1102 cstring mac = cstring_undefined;
1106 while (currentColumn () > 2)
1108 mac = cstring_appendChar (mac, ' ');
1112 c = macro_nextCharC ();
1114 if (c >= '0' && c <= '9')
1118 for (i = 0; i < ((c - '0') + 1); i++)
1120 mac = cstring_appendChar (mac, ' ');
1128 while (((c = macro_nextCharC ()) != '\0') && (c != '\n'))
1130 mac = cstring_appendChar (mac, c);
1134 macrocode = tokenMacroCode (mac);
1136 if (macrocode == BADTOK && !isArtificial (mac))
1138 DPRINTF (("Add macro: %s", mac));
1139 context_addMacroCache (mac);
1148 context_incLineno ();
1152 static bool processMacro (void)
1157 cstring fname = cstring_undefined;
1159 bool isspecfcn = FALSE;
1160 bool isiter = FALSE;
1161 bool skipparam = FALSE;
1162 bool isenditer = FALSE;
1163 bool unknownm = FALSE;
1164 bool hasParams = FALSE;
1165 bool emptyMacro = FALSE;
1166 char c = skip_whitespace ();
1167 fileloc loc = fileloc_noColumn (g_currentloc);
1169 /* are both of these necessary? what do they mean? */
1170 uentryList specparams = uentryList_undefined;
1171 uentryList pn = uentryList_undefined;
1173 context_resetMacroMissingParams ();
1175 if (c == '\0' || c == '\n')
1177 llcontbug (cstring_makeLiteral ("Bad macro"));
1182 fname = cstring_appendChar (fname, c);
1184 while ((c = macro_nextChar ()) != '(' && c != '\0'
1185 && c != ' ' && c != '\t' && c != '\n')
1187 fname = cstring_appendChar (fname, c);
1190 if (c == ' ' || c == '\t' || c == '\n')
1196 while (c == ' ' || c == '\t')
1198 c = macro_nextChar ();
1212 hasParams = (c == '(');
1215 if (usymtab_exists (fname))
1217 e2 = usymtab_lookupExpose (fname);
1218 ct = uentry_getType (e2);
1221 if (uentry_isCodeDefined (e2)
1222 && fileloc_isUser (uentry_whereDefined (e2)))
1226 message ("Macro %s already defined", fname),
1229 uentry_showWhereDefined (e2);
1230 uentry_clearDefined (e2);
1233 if (uentry_isFunction (e2))
1235 uentry_setType (e2, ctype_unknown);
1238 context_enterUnknownMacro (e2);
1242 context_enterConstantMacro (e2);
1247 if (uentry_isForward (e2) && uentry_isFunction (e2))
1254 ("Parameterized macro has no prototype or specification: %s ",
1259 uentry_setType (e2, ctype_unknown);
1260 uentry_setFunctionDefined (e2, loc);
1261 uentry_setUsed (e2, fileloc_undefined);
1262 context_enterUnknownMacro (e2);
1266 if (uentry_isIter (e2))
1269 specparams = uentry_getParams (e2);
1270 noparams = uentryList_size (specparams);
1271 uentry_setDefined (e2, loc);
1272 context_enterIterDef (e2);
1274 else if (uentry_isEndIter (e2))
1277 uentry_setDefined (e2, loc);
1278 context_enterIterEnd (e2); /* don't care about it now */
1279 /* but should parse like an iter! */
1281 else if (uentry_isConstant (e2))
1287 message ("Constant %s implemented as parameterized macro",
1291 uentry_showWhereSpecified (e2);
1292 uentry_setType (e2, ctype_unknown);
1293 uentry_makeVarFunction (e2);
1294 uentry_setDefined (e2, g_currentloc);
1295 uentry_setFunctionDefined (e2, g_currentloc);
1296 context_enterUnknownMacro (e2);
1300 if (!uentry_isSpecified (e2))
1302 fileloc oloc = uentry_whereDeclared (e2);
1304 if (fileloc_isLib (oloc))
1308 else if (fileloc_isUndefined (oloc)
1309 || fileloc_isPreproc (oloc))
1314 (FLG_MACROCONSTDECL,
1316 ("Macro constant %q not declared",
1317 uentry_getName (e2)),
1321 else if (!fileloc_withinLines (oloc, loc, 2))
1322 { /* bogus! will give errors if there is too much whitespace */
1326 ("Macro constant name %s does not match name in "
1327 "previous constant declaration. This constant "
1328 "is declared at %q", fname,
1329 fileloc_unparse (oloc)),
1334 context_enterConstantMacro (e2);
1335 cstring_free (fname);
1341 else if (ctype_isFunction (ct))
1344 specparams = ctype_argsFunction (ct);
1345 noparams = uentryList_size (specparams);
1347 uentry_setFunctionDefined (e2, loc);
1348 context_enterMacro (e2);
1350 else if (uentry_isVar (e2))
1356 message ("Variable %s implemented as parameterized macro",
1360 uentry_showWhereSpecified (e2);
1361 uentry_setType (e2, ctype_unknown);
1362 uentry_makeVarFunction (e2);
1363 uentry_setDefined (e2, g_currentloc);
1364 uentry_setFunctionDefined (e2, g_currentloc);
1365 context_enterUnknownMacro (e2);
1369 uentry ucons = uentry_makeConstant (fname,
1372 if (uentry_isExpandedMacro (e2))
1380 message ("Variable %s implemented by a macro",
1384 uentry_showWhereSpecified (e2);
1388 uentry_setDefined (e2, loc);
1389 uentry_setUsed (ucons, loc);
1391 context_enterConstantMacro (ucons);
1392 uentry_markOwned (ucons);
1393 cstring_free (fname);
1399 if (uentry_isDatatype (e2))
1403 message ("Type implemented as macro: %x",
1404 uentry_getName (e2)),
1405 message ("A type is implemented using a macro definition. A "
1406 "typedef should be used instead."),
1410 /* Must exit scope (not sure why a new scope was entered?) */
1411 usymtab_quietExitScope (g_currentloc);
1412 uentry_setDefined (e2, g_currentloc);
1418 (message ("Unexpanded macro not function or constant: %q",
1419 uentry_unparse (e2)));
1420 uentry_setType (e2, ctype_unknown);
1424 uentry_makeVarFunction (e2);
1425 uentry_setDefined (e2, g_currentloc);
1426 uentry_setFunctionDefined (e2, g_currentloc);
1427 context_enterUnknownMacro (e2);
1439 (FLG_MACROMATCHNAME,
1440 message ("Unexpanded macro %s does not match name of a constant "
1441 "or iter declaration. The name used in the control "
1442 "comment on the previous line should match. "
1443 "(Assuming macro defines a constant.)",
1448 ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);
1449 uentry_setUsed (ce, loc); /* perhaps bogus? */
1450 e2 = usymtab_supEntryReturn (ce);
1452 context_enterConstantMacro (e2);
1453 cstring_free (fname);
1458 /* in macros, ( must follow immediatetly after name */
1464 c = skip_whitespace ();
1466 while (c != ')' && c != '\0')
1469 bool suppress = context_inSuppressRegion ();
1470 cstring paramname = cstring_undefined;
1473 ** save the parameter location
1477 context_saveLocation ();
1480 while (c != ' ' && c != '\t' && c != ',' && c != '\0' && c != ')')
1482 paramname = cstring_appendChar (paramname, c);
1483 c = macro_nextChar ();
1486 if (c == ' ' || c == '\t') c = skip_whitespace ();
1490 c = macro_nextChar ();
1491 if (c == ' ' || c == '\t') c = skip_whitespace ();
1496 llfatalerror (cstring_makeLiteral
1497 ("Bad macro syntax: uentryList"));
1500 if ((isspecfcn || isiter) && (paramno < noparams)
1501 && !uentry_isElipsisMarker (uentryList_getN
1502 (specparams, paramno)))
1504 uentry decl = uentryList_getN (specparams, paramno);
1507 param = uentry_nameCopy (paramname, decl);
1510 uentry_setParam (param);
1511 sr = sRef_makeParam (paramno, uentry_getType (param));
1513 if (sRef_getNullState (sr) == NS_ABSNULL)
1515 ctype pt = ctype_realType (uentry_getType (param));
1517 if (ctype_isUser (pt))
1519 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (pt));
1521 if (uentry_isValid (te))
1523 sRef_setStateFromUentry (sr, te);
1528 sRef_setNullState (sr, NS_UNKNOWN, g_currentloc);
1532 uentry_setSref (param, sr);
1533 uentry_setDeclaredForceOnly (param, context_getSaveLocation ());
1535 skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
1539 fileloc sloc = context_getSaveLocation ();
1541 param = uentry_makeVariableSrefParam
1542 (paramname, ctype_unknown, sRef_makeParam (paramno, ctype_unknown));
1543 cstring_free (paramname);
1545 sRef_setPosNull (uentry_getSref (param), sloc);
1547 uentry_setDeclaredForce (param, sloc);
1550 fileloc_free (sloc);
1555 llassert (!uentry_isElipsisMarker (param));
1559 sRef_makeUnsafe (uentry_getSref (param));
1562 pn = uentryList_add (pn, uentry_copy (param));
1563 usymtab_supEntry (param);
1567 /* don't add param */
1568 uentry_free (param);
1573 (void) macro_nextChar ();
1574 c = skip_whitespace ();
1582 if (isspecfcn || isiter)
1584 if (paramno != noparams && noparams >= 0)
1590 message ("Macro %s specified with %d args, defined with %d",
1591 fname, noparams, paramno),
1594 uentry_showWhereSpecified (e2);
1595 uentry_resetParams (e2, pn);
1600 uentry_resetParams (e2, pn);
1607 ** the form should be:
1609 ** # define newname oldname
1610 ** where oldname refers to a function matching the specification
1616 sRef_setGlobalScope ();
1617 usymtab_supGlobalEntry (uentry_makeVariableLoc (fname, ctype_unknown));
1618 sRef_clearGlobalScope ();
1622 context_setMacroMissingParams ();
1627 /* context_setuentryList (pn); */
1628 usymtab_enterScope ();
1631 cstring_free (fname);
1636 static bool handleSpecial (char *yyt)
1638 char *l = mstring_create (MAX_NAME_LENGTH);
1639 static bool reportcpp = FALSE;
1645 strcpy (l, yyt + 1);
1647 /* Need to safe original l for deallocating. */
1650 l += strlen (yyt) - 1;
1652 while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
1658 olc = cstring_fromChars (ol);
1660 if (cstring_equalPrefix (olc, "pragma"))
1662 char *pname = mstring_create (longUnsigned_fromInt (MAX_PRAGMA_LEN));
1663 char *opname = pname;
1664 char *ptr = ol + 6; /* pragma is six characters, plus space */
1668 /* skip whitespace */
1669 while (((c = *ptr) != '\0') && isspace (c))
1675 while (((c = *ptr) != '\0') && !isspace (c))
1679 if (len > MAX_PRAGMA_LEN)
1690 if (len == PRAGMA_LEN_EXPAND
1691 && mstring_equal (opname, PRAGMA_EXPAND))
1693 cstring exname = cstring_undefined;
1697 while (((c = *ptr) != '\0') && !isspace (c))
1699 exname = cstring_appendChar (exname, c);
1704 ue = usymtab_lookupExposeGlob (exname);
1706 if (uentry_isExpandedMacro (ue))
1708 if (fileloc_isPreproc (uentry_whereDefined (ue)))
1710 fileloc_setColumn (g_currentloc, 1);
1711 uentry_setDefined (ue, g_currentloc);
1715 cstring_free (exname);
1718 else if (cstring_equalPrefix (olc, "ident"))
1720 /* Some pre-processors will leave these in the code. Ignore rest of line */
1723 ** Yuk...Win32 filenames can have spaces in them...we need to read
1724 ** to the matching end quote.
1726 else if ((sscanf (ol, "line %d \"", &lineno) == 1)
1727 || (sscanf (ol, " %d \"", &lineno) == 1))
1733 while (*tmp != '\"' && *tmp != '\0')
1738 llassert (*tmp == '\"');
1743 while (*tmp != '\"' && *tmp != '\0')
1748 llassert (*tmp == '\"');
1752 DPRINTF (("fname: %s", fname));
1754 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
1757 ** DOS-like path delimiters get delivered in pairs, something like
1758 ** \"..\\\\file.h\", so we have to make it normal again. We do NOT
1759 ** remove the pre dirs yet as we usually specify tmp paths relative
1760 ** to the current directory, so tmp files would not get found in
1761 ** the hash table. If this method fails we try it again later.
1768 ** Skip past the drive marker.
1771 DPRINTF (("stmp: %s / %s", stmp, fname));
1773 if (strchr (stmp, ':') != NULL)
1775 stmp = strchr (stmp, ':') + 1;
1778 DPRINTF (("stmp: %s / %s", stmp, fname));
1780 while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
1782 if (*(stmp+1) == CONNECTCHAR)
1784 memmove (stmp, stmp+1, strlen (stmp));
1788 DPRINTF (("stmp: %s / %s", stmp, fname));
1791 DPRINTF (("Now: base = %s", fname));
1793 fid = fileTable_lookupBase (context_fileTable (),
1794 cstring_fromChars (fname));
1795 if (!(fileId_isValid (fid)))
1797 fname = removePreDirs (fname);
1798 fid = fileTable_lookupBase (context_fileTable (),
1799 cstring_fromChars (fname));
1802 # else /* !defined(OS2) && !defined(MSDOS) */
1803 fname = removePreDirs (fname);
1804 fid = fileTable_lookupBase (context_fileTable (),
1805 cstring_fromChars (fname));
1806 # endif /* !defined(OS2) && !defined(MSDOS) */
1808 if (!(fileId_isValid (fid)))
1810 if (isHeaderFile (cstring_fromChars (fname)))
1812 fid = fileTable_addHeaderFile (context_fileTable (),
1813 cstring_fromChars (fname));
1817 fid = fileTable_addFile (context_fileTable (),
1818 cstring_fromChars (fname));
1822 setFileLine (fid, lineno);
1824 else if ((sscanf (ol, "line %d", &lineno) == 1)
1825 || (sscanf (ol, " %d", &lineno) == 1))
1827 setLine (lineno); /* next line is <cr> */
1831 if (mstring_equal (ol, "")) {
1832 DPRINTF (("Empty pp command!"));
1834 ** evs 2000-05-16: This is a horrible kludge, to get around a bug (well, difficulty) in the pre-processor.
1835 ** We handle a plain # in the input file, by echoing it, and ignoring it in the post-pp-file.
1844 llbug (message ("File contains preprocessor command: #%s",
1845 cstring_fromChars (ol)));
1858 static int handleLlSpecial ()
1862 char *s = mstring_createEmpty ();
1867 while (((ic = ninput ()) != 0) && isalpha (ic))
1870 s = mstring_append (s, c);
1876 if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
1880 llassert (ic == AFTER_COMMENT_MARKER[1]);
1883 if (isProcessingGlobMods () && (*s == '\0'))
1886 return QNOMODS; /* special token no modifications token */
1894 tok = commentMarkerToken (cstring_fromChars (os));
1898 tokLength = charsread;
1904 /* Add rest of the comment */
1906 if (ic != 0 && ic != EOF)
1911 s = mstring_append (s, c);
1914 while (((ic = ninput ()) != 0) && (ic != EOF)
1915 && (ic != AFTER_COMMENT_MARKER[0]))
1918 s = mstring_append (s, c);
1923 if (ic == AFTER_COMMENT_MARKER[0])
1926 llassert ((char) nc == AFTER_COMMENT_MARKER[1]);
1933 while (*s == ' ' || *s == '\t' || *s == '\n')
1938 if (*s == '-' || *s == '+' || *s == '=') /* setting flags */
1942 while (c == '-' || c == '+' || c == '=')
1944 ynm set = ynm_fromCodeChar (c);
1949 thisflag = cstring_fromChars (s);
1951 while ((c = *s) != '\0' && (c != '-') && (c != '=')
1952 && (c != '+') && (c != ' ') && (c != '\t') && (c != '\n'))
1959 if (!context_getFlag (FLG_NOCOMMENTS))
1961 cstring flagname = thisflag;
1962 flagcode fflag = identifyFlag (flagname);
1964 if (flagcode_isSkip (fflag))
1968 else if (flagcode_isInvalid (fflag))
1970 if (isMode (flagname))
1972 if (ynm_isMaybe (set))
1977 ("Stylized comment attempts to restore flag %s. "
1978 "A mode flag cannot be restored.",
1983 context_setMode (flagname);
1990 message ("Unrecognized option in stylized comment: %s",
1994 else if (flagcode_isGlobalFlag (fflag))
1999 ("Stylized comment attempts to set global flag %s. "
2000 "A global flag cannot be set locally.",
2005 context_fileSetFlag (fflag, set);
2007 if (flagcode_hasArgument (fflag))
2009 if (ynm_isMaybe (set))
2014 ("Stylized comment attempts to restore flag %s. "
2015 "A flag for setting a value cannot be restored.",
2019 { /* cut-and-pastied from llmain...blecch */
2020 cstring extra = cstring_undefined;
2026 rest = mstring_copy (s);
2030 while ((rchar = *rest) != '\0'
2031 && (isspace (rchar)))
2037 while ((rchar = *rest) != '\0'
2038 && !isspace (rchar))
2040 extra = cstring_appendChar (extra, rchar);
2047 if (cstring_isUndefined (extra))
2052 ("Flag %s (in stylized comment) must be followed by an argument",
2053 flagcode_unparse (fflag)));
2059 if (flagcode_hasValue (fflag))
2061 setValueFlag (fflag, extra);
2063 else if (flagcode_hasString (fflag))
2065 setStringFlag (fflag, extra);
2082 while ((c == ' ') || (c == '\t') || (c == '\n'))
2088 if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
2090 context_addComment (cstring_fromCharsNew (os));
2103 while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
2115 t = cstring_toCharsSafe (cstring_downcase (cstring_fromChars (t)));
2116 macrocode = tokenMacroCode (cstring_fromChars (t));
2118 if (macrocode != BADTOK)
2120 tokLength = mstring_length (t);
2126 if (macrocode == SKIPTOK)
2134 if (context_inHeader ())
2141 if ((context_inMacro () || context_inGlobalContext ())
2142 && macrocode != SKIPTOK
2143 && !isArtificial (cstring_fromChars (os)))
2145 context_addComment (cstring_fromCharsNew (os));
2158 if (mstring_equal (t, "ignore"))
2160 if (!context_getFlag (FLG_NOCOMMENTS))
2162 context_enterSuppressRegion ();
2165 else if ((*t == 'i' || *t == 't')
2166 && (*(t + 1) == '\0'))
2168 if (!context_getFlag (FLG_NOCOMMENTS)
2169 && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
2171 context_enterSuppressLine (-1); /* infinite suppression */
2174 else if (((*t == 'i') || (*t == 't'))
2175 && ((*(t + 1) >= '0' && *(t + 1) <= '9')))
2177 bool tmpcomment = (*t == 't');
2179 char *tt = t; /* don't mangle t, since it is free'd */
2182 if (lc >= '0' && lc <= '9')
2184 val = (int)(lc - '0');
2187 while (lc >= '0' && lc <= '9')
2196 if (!context_getFlag (FLG_NOCOMMENTS)
2197 && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
2199 context_enterSuppressLine (val);
2202 else if (mstring_equal (t, "end"))
2204 if (!context_getFlag (FLG_NOCOMMENTS))
2206 context_exitSuppressRegion ();
2209 else if (mstring_equal (t, "notfunction"))
2211 ; /* handled by pcpp */
2213 else if (mstring_equal (t, "access"))
2219 while ((c = *s) && (c == ' ' || c == '\t' || c == '\n'))
2229 tname = cstring_fromChars (s);
2231 while ((c = *s) != '\0' && c != ' '
2232 && c != '\t' && c != '\n' && c != ',')
2240 if (!context_getFlag (FLG_NOCOMMENTS)
2241 && !context_getFlag (FLG_NOACCESS))
2243 if (usymtab_existsType (tname))
2245 usymId uid = usymtab_getTypeId (tname);
2246 context_addFileAccessType (uid);
2250 if (!(context_inSuppressRegion ()
2251 || context_inSuppressZone (g_currentloc)))
2255 ("%q: Unrecognized type %s used in access comment",
2256 fileloc_unparse (g_currentloc), tname));
2266 if (c != ',' && c != ' ')
2272 else if (mstring_equal (t, "noaccess"))
2279 while ((lc = *s) && (lc == ' ' || lc == '\t' || lc == '\n'))
2289 tname = cstring_fromChars (s);
2291 while ((lc = *s) != '\0' && lc != ' ' && lc != '\t'
2292 && lc != '\n' && lc != ',')
2299 if (!context_getFlag (FLG_NOCOMMENTS)
2300 && !context_getFlag (FLG_NOACCESS))
2302 if (usymtab_existsType (tname))
2304 typeId tuid = usymtab_getTypeId (tname);
2306 if (context_couldHaveAccess (tuid))
2308 context_removeFileAccessType (tuid);
2312 if (!(context_inSuppressRegion ()
2313 || context_inSuppressZone (g_currentloc)))
2315 uentry ue = usymtab_getTypeEntry (tuid);
2317 if (uentry_isAbstractDatatype (ue))
2321 ("%q: Non-accessible abstract type %s used in noaccess comment",
2322 fileloc_unparse (g_currentloc), tname));
2328 ("%q: Non-abstract type %s used in noaccess comment",
2329 fileloc_unparse (g_currentloc), tname));
2336 if (!(context_inSuppressRegion ()
2337 || context_inSuppressZone (g_currentloc)))
2341 ("%q: Unrecognized type %s used in noaccess comment",
2342 fileloc_unparse (g_currentloc), tname));
2352 if (lc != ',' && lc != ' ')
2360 setTokLength (- (2 + charsread));
2362 voptgenerror (FLG_UNRECOGCOMMENTS,
2363 message ("Stylized comment unrecognized: %s",
2364 cstring_fromChars (os)),
2375 static /*@only@*/ cstring makeIdentifier (char *s)
2377 char *c = mstring_create (size_toInt (strlen (s)) + 1);
2378 cstring id = cstring_fromChars (c);
2380 while (isalnum (*s) || (*s == '_') || (*s == '$'))
2389 /*@observer@*/ /*@dependent@*/ uentry coerceId (cstring cn)
2391 if (!(usymtab_exists (cn)))
2393 fileloc loc = fileloc_createExternal ();
2396 ** We need to put this in a global scope, otherwise the sRef will be deallocated.
2399 uentry ce = uentry_makeUnrecognized (cn, loc);
2401 if (!context_inIterEnd ())
2405 message ("Unrecognized (possibly system) identifier: %q",
2406 uentry_getName (ce)),
2413 return (usymtab_lookup (cn));
2417 ** like, coerceId, but doesn't supercede for iters
2420 /*@observer@*/ uentry coerceIterId (cstring cn)
2422 if (!(usymtab_exists (cn)))
2424 return uentry_undefined;
2427 return (usymtab_lookup (cn));
2430 /*@observer@*/ cstring LastIdentifier ()
2432 return (lastidprocessed);
2435 static int processIdentifier (cstring id)
2439 DPRINTF (("Process identifier: %s", id));
2441 context_clearJustPopped ();
2442 lastidprocessed = id;
2444 if (context_inFunctionDecl ())
2446 int tok = commentMarkerToken (id);
2454 tok = tokenMacroCode (id);
2463 /* Consider handling: Defined by C99 as static const char __func__[] */
2465 if (context_getFlag (FLG_GNUEXTENSIONS))
2469 if (cstring_equalLit (id, "__stdcall")
2470 || cstring_equalLit (id, "__cdecl")
2471 || cstring_equalLit (id, "__extension__"))
2475 else if (cstring_equalLit (id, "__volatile__"))
2479 else if (cstring_equalLit (id, "__signed"))
2483 else if (cstring_equalLit (id, "__unsigned"))
2487 else if (cstring_equalLit (id, "__const__"))
2491 else if (cstring_equalLit (id, "__alignof__"))
2493 tok = CALIGNOF; /* alignof is parsed like sizeof */
2495 else if (cstring_equalLit (id, "__FUNCTION__")
2496 || cstring_equalLit (id, "__PRETTY_FUNCTION__"))
2498 /* These tokens hold the name of the current function as strings */
2499 yylval.expr = exprNode_stringLiteral (id, fileloc_copy (g_currentloc));
2501 lastWasString = TRUE;
2505 else if (cstring_equalLit (id, "__attribute__")
2506 || cstring_equalLit (id, "__asm__")
2507 || cstring_equalLit (id, "_asm")
2508 || cstring_equalLit (id, "__asm")
2509 || cstring_equalLit (id, "__declspec"))
2512 bool useparens = FALSE;
2513 bool usebraces = FALSE;
2514 bool inquote = FALSE;
2515 bool inescape = FALSE;
2518 while ((ic = input ()) != EOF)
2525 else if (ic == '\\')
2529 else if (ic == '\"')
2565 else if (ic == ')' && useparens)
2568 if (depth == 0) break;
2570 else if (ic == '}' && usebraces)
2573 if (depth == 0) break;
2576 && !usebraces && !useparens
2577 && cstring_equalLit (id, "__asm"))
2580 ** We need this because some MS VC++ include files
2581 ** have __asm mov ... }
2582 ** Its a kludge, but otherwise would need to parse
2591 context_incLineno ();
2593 if (cstring_equalLit (id, "__asm")
2594 && !useparens && !usebraces)
2601 llassert ((useparens && ic == ')')
2602 || (usebraces && ic == '}')
2603 || (!useparens && !usebraces));
2607 else if (cstring_equalLit (id, "inline")
2608 || cstring_equalLit (id, "__inline")
2609 || cstring_equalLit (id, "_inline")
2610 || cstring_equalLit (id, "__inline__"))
2621 le = usymtab_lookupSafe (id);
2623 /*@-dependenttrans@*/
2625 if (uentry_isIter (le))
2630 else if (uentry_isEndIter (le))
2633 return (ITER_ENDNAME);
2635 else if (uentry_isUndefined (le))
2639 /* avoid parse errors for certain system built ins */
2641 if (g_expectingTypeName && (cstring_firstChar (id) == '_')
2642 && (cstring_secondChar (id) == '_'))
2644 return (TYPE_NAME_OR_ID);
2647 return (NEW_IDENTIFIER);
2649 else if (!uentry_isDeclared (le) && !uentry_isCodeDefined (le))
2651 if (uentry_isDatatype (le))
2654 return (NEW_IDENTIFIER);
2659 return (IDENTIFIER);
2662 else if (uentry_isDatatype (le))
2664 if (!g_expectingTypeName)
2668 return (NEW_IDENTIFIER);
2672 yylval.ctyp = uentry_getAbstractType (le);
2674 uentry_setUsed (le, g_currentloc);
2681 return (IDENTIFIER);
2684 /*@=dependenttrans@*/
2687 static bool processHashIdentifier (/*@only@*/ cstring id)
2689 if (context_inMacro () || context_inIterDef () ||
2690 context_inIterEnd ())
2694 context_clearJustPopped ();
2696 lastidprocessed = id;
2697 le = usymtab_lookupSafe (id);
2699 if (uentry_isParam (le) || uentry_isRefParam (le))
2716 static /*@only@*/ exprNode processString ()
2720 char *nl = strchr (yytext, '\n');
2721 cstring ns = cstring_fromCharsNew (yytext);
2725 loc = fileloc_copy (g_currentloc);
2726 addColumn (cstring_length (ns));
2732 loc = fileloc_copy (g_currentloc);
2734 context_incLineno ();
2736 while ((nl = strchr ((nl + 1), '\n')) != NULL)
2738 context_incLineno ();
2744 res = exprNode_stringLiteral (ns, loc);
2754 llassert (*yytext != '\0');
2755 fchar = *(yytext + 1);
2756 if (fchar != '\\') return fchar;
2758 next = *(yytext + 2);
2762 case 'n': return '\n';
2763 case 't': return '\t';
2764 case '\"': return '\"';
2765 case '\'': return '\'';
2766 case '\\': return '\\';
2767 default: return '\0';
2772 double processFloat ()
2774 double ret = atof (yytext);
2785 llassert (yytext[0] == '0'
2786 && (yytext[1] == 'X' || yytext[1] == 'x'));
2788 while (yytext[index] != '\0') {
2790 char c = yytext[index];
2792 if (c >= '0' && c <= '9') {
2793 tval = (int) c - (int) '0';
2794 } else if (c >= 'A' && c <= 'F') {
2795 tval = (int) c - (int) 'A' + 10;
2796 } else if (c >= 'a' && c <= 'f') {
2797 tval = (int) c - (int) 'a' + 10;
2798 } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2800 while (yytext[index] != '\0') {
2801 if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
2806 message ("Invalid character (%c) following specifier in hex constant: %s",
2807 c, cstring_fromChars (yytext)),
2817 message ("Invalid character (%c) in hex constant: %s",
2818 c, cstring_fromChars (yytext)),
2823 val = (val * 16) + tval;
2827 DPRINTF (("Hex constant: %s = %ld", yytext, val));
2832 long processOctal ()
2837 llassert (yytext[0] == '0' && yytext[1] != 'X' && yytext[1] != 'x');
2839 while (yytext[index] != '\0') {
2841 char c = yytext[index];
2843 if (c >= '0' && c <= '7') {
2844 tval = (int) c - (int) '0';
2848 message ("Invalid character (%c) in octal constant: %s",
2849 c, cstring_fromChars (yytext)),
2854 val = (val * 8) + tval;
2858 DPRINTF (("Octal constant: %s = %ld", yytext, val));
2865 return (atol (yytext));
2869 processSpec (int tok)
2871 size_t length = strlen (yytext);
2876 setTokLengthT (length);
2882 context_saveLocation ();
2883 setTokLengthT (length);
2884 return (processIdentifier (makeIdentifier (yytext)));