]> andersk Git - splint.git/blobdiff - src/cscanner.l
Fixed problem with make dist so that packages can be made and distributed.
[splint.git] / src / cscanner.l
index 1cb34c9d892fe950bd52ecf8201387c54ffdf49c..77d33d09a311ec0bc9f0026ce211a91f1a6bc876 100644 (file)
@@ -1,46 +1,57 @@
 /*;-*-C-*-; 
-** Copyright (c) Massachusetts Institute of Technology 1994-1998.
-**          All Rights Reserved.
-**          Unpublished rights reserved under the copyright laws of
-**          the United States.
+** Splint - annotation-assisted static program checker
+** Copyright (C) 1994-2002 University of Virginia,
+**         Massachusetts Institute of Technology
 **
-** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
-** OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License as published by the
+** Free Software Foundation; either version 2 of the License, or (at your
+** option) any later version.
+** 
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+** General Public License for more details.
+** 
+** The GNU General Public License is available from http://www.gnu.org/ or
+** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+** MA 02111-1307, USA.
 **
-** This code is distributed freely and may be used freely under the 
-** following conditions:
-**
-**     1. This notice may not be removed or altered.
+** For information on splint: splint@cs.virginia.edu
+** To report a bug: splint-bug@cs.virginia.edu
+** For more information: http://www.splint.org
+*/
+/*
+** cscanner.l
 **
-**     2. Works derived from this code are not distributed for
-**        commercial gain without explicit permission from MIT 
-**        (for permission contact lclint-request@sds.lcs.mit.edu).
+** Flex lexer for C.
+** Based on a C lexer by Nate Osgood
+**    from hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
 */
 /*
- * Modified by Herbert 08/19/97:
- * - added #include for IBM's OS/2 compiler.
- * - fixed weird bug with lookup of tmp files (OS/2 and MSDOS only).
- */
-
+** Modified by Herbert 08/19/97:
+** - added #include for IBM's OS/2 compiler.
+** - fixed weird bug with lookup of tmp files (OS/2 and MSDOS only).
+*/
 /*
- * Modified by Mike Smith 
- * Corrected missing 'line' in scanf() calls in handleSpecial().
- * Without this, I get an error when LCLint hits a '#line' directive
- * in the pre-pre-processed source files. For safety, I have made these
- * conditional on OS2 and MSDOS because I don't understand why noone else
- * has seen this problem.
- *
- * Modified by Mike Smith, 4th June 1997
- * Finally resolved the #line problem.  The scanf() calls have been fixed to
- * allow the following #line forms:-
- *
- *        #line 123 "filename"
- *        #line 123
- *        # 123 "filename"
- *        # 123
- *
- * The last two are generated by the GNU pre-processor, apparently
- */
+** Modified by Mike Smith 
+** Corrected missing 'line' in scanf() calls in handleSpecial().
+** Without this, I get an error when Splint hits a '#line' directive
+** in the pre-pre-processed source files. For safety, I have made these
+** conditional on OS2 and MSDOS because I don't understand why noone else
+** has seen this problem.
+**
+** Modified by Mike Smith, 4th June 1997
+** Finally resolved the #line problem.  The scanf() calls have been fixed to
+** allow the following #line forms:-
+**
+**        #line 123 "filename"
+**        #line 123
+**        # 123 "filename"
+**        # 123
+**
+** The last two are generated by the GNU pre-processor, apparently
+*/
 
 Digit                  [0-9]
 Letter                 [a-zA-Z_$]
@@ -53,56 +64,53 @@ IS                  (u|U|l|L)*
 ULSuffix                ({U}{L}|{L}{U})
 
 %{
+# include "splintMacros.nf"
+# if defined(OS2) && defined(__IBMC__)
+   /* needed for isatty()... */
+# include <io.h>
+# else
+
 /*
-** based on original C lexer by Nate Osgood
-**    from hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
-**
+** Win32 doesn't have unistd.h
 */
 
-# include "lclintMacros.nf"
+# ifndef WIN32
+# include <unistd.h>
+# endif
+
+# endif
+
 # include "basic.h"
 
 # include "cgrammar.h"
 # include "cgrammar_tokens.h"
-
-# include "fileIdList.h"
 # include "portab.h"
 
-# if defined(OS2) && defined(__IBMC__)
-   /* needed for isatty()... */
-# include <io.h>
-# endif
-
 static bool lastWasString = FALSE;
 static char savechar = '\0';
 
 /*@notfunction@*/
 # define yyinput() (incColumn (), getc (yyin))
 
-/*@-noparams@*/
-/*@-incondefs@*/
-extern /*@external@*/ int read ();
-/*@=incondefs@*/
-/*@=noparams@*/
-
-static /*@owned@*/ cstring lastidprocessed = cstring_undefined;
-
+static /*@owned@*/ cstring s_lastidprocessed = cstring_undefined;
 static int lminput (void);
 static int tokLength = 0;
-static bool inSpecPart = FALSE;
+static bool s_inSpecPart = FALSE;
+static int s_whichSpecPart;
 static bool continueLine = FALSE;
 
 static int ninput (void);
 static char processChar (void);
 static double processFloat (void);
-static /*@only@*/ exprNode processString (void);
+static /*@only@*/ exprNode processString (void) ;
+static /*@only@*/ exprNode processWideString (void) ;
 static long processDec (void);
 static long processHex (void);
 static long processOctal (void);
 static int processIdentifier (/*@only@*/ cstring)
-   /*@globals undef lastidprocessed@*/ ;
+   /*@globals s_lastidprocessed@*/ ;
 static bool processHashIdentifier (/*@only@*/ cstring)
-   /*@globals undef lastidprocessed@*/ ;
+   /*@globals s_lastidprocessed@*/ ;
 
 static int processSpec (int);
 static bool handleSpecial (char *);
@@ -114,6 +122,8 @@ static /*@only@*/ cstring makeIdentifier (char *);
 /* yes, this is exported! */
 bool g_expectingTypeName = TRUE; /* beginning of file can be type name! */
 
+static bool expectingMetaStateName = FALSE;
+
 static int returnInt (ctype, long);
 static int returnFloat (ctype, double);
 static int returnChar (char);
@@ -172,6 +182,7 @@ static void setTokLength (int len)
 {
   addColumn (len);
   tokLength = len;
+  DPRINTF (("Set tok length: %d", len));
 }
 
 static void setTokLengthT (size_t len)
@@ -180,11 +191,14 @@ static void setTokLengthT (size_t len)
 }
 
 # include "flex.head"
+
+/*@-unrecog@*/ /*@i5343@*/
+
 %}
 
 %%
 
-"/*"           { llfatalbug (cstring_makeLiteral ("Comment in pre-processor output")); }
+"/*"           { llfatalerror (cstring_makeLiteral ("Comment in pre-processor output")); }
 
 "#"{Letter}({Letter}|{Digit})*  { 
                  context_saveLocation (); 
@@ -194,7 +208,8 @@ static void setTokLengthT (size_t len)
                    {
                     if (lastWasString)
                       {
-                        ;
+                        /* was nothing! */ /*@i32@*/
+                        RETURN_STRING (cstring_makeLiteral ("\"\""));
                       }
                     else
                       {
@@ -255,6 +270,7 @@ static void setTokLengthT (size_t len)
 
 "volatile"     { setTokLength (8); RETURN_TOK (QVOLATILE); }
 "const"                { setTokLength (5); RETURN_TOK (QCONST); }
+"restrict"     { setTokLength (8); RETURN_TOK (QRESTRICT); }
 
                         /* some systems expect this! [gack!] */ 
 "__const"      { setTokLength (7); RETURN_TOK (QCONST); }
@@ -265,6 +281,7 @@ static void setTokLengthT (size_t len)
 "static"       { setTokLength (6); RETURN_TOK (QSTATIC); }
 
 \"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processString ()); }
+L\"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processWideString ()); }
 "out"                   { return (processSpec (QOUT)); }
 "in"                    { return (processSpec (QIN)); }
 "partial"               { return (processSpec (QPARTIAL)); }
@@ -279,6 +296,8 @@ static void setTokLengthT (size_t len)
 "isnull"                { return (processSpec (QISNULL)); } 
 "truenull"              { return (processSpec (QTRUENULL)); } 
 "falsenull"             { return (processSpec (QFALSENULL)); } 
+"nullwhentrue"          { return (processSpec (QTRUENULL)); } 
+"nullwhenfalse"             { return (processSpec (QFALSENULL)); } 
 "relnull"               { return (processSpec (QRELNULL)); }
 "reldef"                { return (processSpec (QRELDEF)); }
 "exposed"               { return (processSpec (QEXPOSED)); }
@@ -302,6 +321,10 @@ static void setTokLengthT (size_t len)
 "undef"                 { return (processSpec (QUNDEF)); }
 "killed"                { return (processSpec (QKILLED)); }
 "nullterminated"        { return (processSpec (QNULLTERMINATED));}
+"MaxSet"                { return (processSpec (QMAXSET));}
+"MaxRead"               { return (processSpec (QMAXREAD));}
+"maxSet"                { return (processSpec (QMAXSET));}
+"maxRead"               { return (processSpec (QMAXREAD));}
 
 {Letter}({Letter}|{Digit})* { int tok; 
                              context_saveLocation (); 
@@ -357,6 +380,8 @@ static void setTokLengthT (size_t len)
                         RETURN_INT (ctype_ullint, processDec ()); } 
 '(\\.|[^\\'])+'               { setTokLengthT (mstring_length (yytext)); 
                          RETURN_CHAR (processChar ()); }
+L'(\\.|[^\\'])+'       { setTokLengthT (mstring_length (yytext)); 
+                         RETURN_CHAR (processChar ()); }
 {Digit}+{E}[fF]        { setTokLengthT (mstring_length (yytext)); 
                         RETURN_FLOAT (ctype_float, processFloat ()); }
 {Digit}+{E}[lL]        { setTokLengthT (mstring_length (yytext)); 
@@ -426,8 +451,22 @@ static void setTokLengthT (size_t len)
 "|"            { setTokLength (1); RETURN_TOK (TBAR); }
 "?"            { setTokLength (1); RETURN_TOK (TQUEST); }
 
+
+"/\\"          { setTokLength (1); RETURN_TOK (TCAND); }
+
+
 [ \t\v\f]      { incColumn (); }
 \n              { context_incLineno ();
+                  if (tokLength != 0) { 
+                   tokLength = 0; 
+                   /* No error to report 
+                   voptgenerror
+                     (FLG_SYNTAX, 
+                      message ("Likely parse error: token spans multiple lines."),
+                      g_currentloc);
+                   */
+                 }
+                 
                  if (continueLine)
                    {
                      continueLine = FALSE;
@@ -437,7 +476,7 @@ static void setTokLengthT (size_t len)
                     if (context_inMacro ())
                       {
                         /* Don't use RETURN_TOK */
-                        yylval.tok = lltok_create (TENDMACRO, g_currentloc);
+                        yylval.tok = lltok_create (TENDMACRO, fileloc_copy (g_currentloc)); /* !!! evans 2002-03-13 */
                         lastWasString = FALSE;
                         return (TENDMACRO);
                       }  
@@ -481,6 +520,8 @@ static void setTokLengthT (size_t len)
                      
                      if (processMacro ()) 
                        {
+                         DPRINTF (("Here we are: %s", context_unparse ()));
+                         
                          if (context_inIterDef ()) 
                            {
                              RETURN_TOK (LLMACROITER); 
@@ -497,6 +538,7 @@ static void setTokLengthT (size_t len)
                    }
                }
 "@.CT"          { setTokLength (4); lldiagmsg (ctype_unparseTable ()); }
+"@.FA"          { setTokLength (4); lldiagmsg (message ("Access types: %q", typeIdSet_unparse (context_fileAccessTypes ()))); }
 "@.F"           { setTokLength (3); 
                  lldiagmsg (message ("%q: *** marker ***", fileloc_unparse (g_currentloc)));
                }
@@ -518,25 +560,88 @@ static void setTokLengthT (size_t len)
                   int tok; 
                  incColumn (); incColumn ();
                  tok = handleLlSpecial (); 
+
                  if (tok != BADTOK)
                    {
-                     RETURN_TOK (tok); 
+                     if (tok == CANNOTATION) {
+                       return (tok);
+                     } else {
+                       /* Beware - this bashes yylval! */
+                       RETURN_TOK (tok); 
+                     }
                    }
                }
 "%}"            { /* AFTER_COMMENT_MARKER */ 
                   setTokLength (2);
-                 inSpecPart = FALSE;
+                 s_inSpecPart = FALSE;
+                 s_whichSpecPart = BADTOK;
                  RETURN_TOK (QENDMACRO); }
 "\\"            { incColumn (); continueLine = TRUE; }
 .              { incColumn (); 
-                 voptgenerror
-                   (FLG_SYNTAX, 
-                    message ("Invalid character (ascii: %d), skipping character",
-                             (int)(*yytext)),
-                    g_currentloc);
+                  if ((int) *yytext == 13 ) {
+                    ;
+                  } else {
+                   voptgenerror
+                     (FLG_SYNTAX, 
+                      message ("Invalid character (ascii: %d), skipping character",
+                               (int)(*yytext)),
+                      g_currentloc);
+                 }
                }
 %%
 
+/*
+** Resets flags set by flex.head.
+*/
+
+/*@=allmacros@*/
+/*@=pred@*/
+/*@=globstate@*/
+/*@=null@*/
+/*@=boolint@*/
+/*@=charint@*/
+/*@=macrospec@*/
+/*@=macroredef@*/
+/*@=exitarg@*/
+/*@=compdef@*/
+/*@=uniondef@*/
+/*@=ignorequals@*/
+/*@=noreturn@*/
+/*@=mustfree@*/
+/*@=compdestroy@*/
+/*@=branchstate@*/
+/*@=unreachable@*/
+/*@=varuse@*/
+/*@=fcnuse@*/
+/*@=exportlocal@*/
+/*@=evalorderuncon@*/
+/*@=exportheader@*/
+/*@=redecl@*/
+/*@=loopswitchbreak@*/
+/*@=switchswitchbreak@*/
+/*@=sizeoftype@*/
+/*@=czechfcns@*/
+/*@=noparams@*/
+/*@=ansireserved@*/
+/*@=ifblock@*/
+/*@=whileblock@*/
+/*@=forblock@*/
+/*@=elseifcomplete@*/
+/*@=ptrnegate@*/
+/*@=onlytrans@*/
+/*@=temptrans@*/
+/*@=immediatetrans@*/
+/*@=namechecks@*/
+/*@=matchanyintegral@*/
+/*@=statictrans@*/
+/*@=compmempass@*/
+/*@=forempty@*/
+/*@=evalorder@*/
+/*@=retalias@*/
+/*@=redecl@*/
+/*@=retvalother@*/
+/*@=exportheader@*/
+
 struct skeyword
 {
   /*@null@*/ /*@observer@*/ char *name;
@@ -548,10 +653,11 @@ struct skeyword
 ** grammar proper.
 */
 
-struct skeyword s_parsetable[] = {
+static struct skeyword s_parsetable[] = {
   { "modifies", QMODIFIES } ,
   { "globals", QGLOBALS } ,
   { "alt", QALT } ,
+  { "warn", QWARN } ,
   { "constant", QCONSTANT } ,
   { "function", QFUNCTION } ,
   { "iter", QITER } ,
@@ -562,10 +668,13 @@ struct skeyword s_parsetable[] = {
   { "releases", QRELEASES } ,
   { "pre", QPRECLAUSE } ,
   { "post", QPOSTCLAUSE } ,
-  {"setBufferSize", QSETBUFFERSIZE},
-  {"setStringLength", QSETSTRINGLENGTH},
-  {"testinRange", QTESTINRANGE},
-  { NULL, BADTOK }
+  { "setBufferSize", QSETBUFFERSIZE},
+  { "setStringLength", QSETSTRINGLENGTH},
+  { "testinRange", QTESTINRANGE},
+  { "requires", QPRECLAUSE } ,
+  { "ensures", QPOSTCLAUSE } ,
+  { "invariant", QINVARIANT} ,
+  { NULL, BADTOK } 
 } ;
 
 /*
@@ -573,7 +682,7 @@ struct skeyword s_parsetable[] = {
 ** token-specific text.
 */
 
-struct skeyword s_keytable[] = {
+static struct skeyword s_keytable[] = {
   { "anytype", QANYTYPE } ,
   { "integraltype", QINTEGRALTYPE } ,
   { "unsignedintegraltype", QUNSIGNEDINTEGRALTYPE } ,
@@ -587,6 +696,8 @@ struct skeyword s_keytable[] = {
   { "special", QSPECIAL } ,
   { "truenull", QTRUENULL } ,
   { "falsenull", QFALSENULL } ,
+  { "nullwhentrue", QTRUENULL } ,
+  { "falsewhennull", QFALSENULL } ,
   { "keep", QKEEP } ,
   { "kept", QKEPT } ,
   { "notnull", QNOTNULL } ,
@@ -610,13 +721,23 @@ struct skeyword s_keytable[] = {
   { "nullterminated", QNULLTERMINATED }, 
   { "setBufferSize", QSETBUFFERSIZE },
   { "testInRange", QTESTINRANGE},
+  { "isnull", QISNULL }, 
+  { "MaxSet", QMAXSET},
+  { "MaxRead", QMAXREAD},
+  { "maxSet", QMAXSET},
+  { "maxRead", QMAXREAD},
   { "reldef", QRELDEF } ,
   { "observer", QOBSERVER } ,
   { "exits", QEXITS } ,
+  { "noreturn", QEXITS } ,
   { "mayexit", QMAYEXIT } ,
+  { "maynotreturn", QMAYEXIT } ,
   { "trueexit", QTRUEEXIT } ,
   { "falseexit", QFALSEEXIT } ,
+  { "noreturnwhentrue", QTRUEEXIT } ,
+  { "noreturnwhenfalse", QFALSEEXIT } ,
   { "neverexit", QNEVEREXIT } ,
+  { "alwaysreturns", QNEVEREXIT } ,
   { "temp", QTEMP } ,
   { "shared", QSHARED } ,
   { "ref", QREF } ,
@@ -650,10 +771,11 @@ static bool isArtificial (cstring s)
 {
   return (cstring_equalLit (s, "modifies") 
          || cstring_equalLit (s, "globals") 
+         || cstring_equalLit (s, "warn")
          || cstring_equalLit (s, "alt"));
 }
 
-void swallowMacro (void)
+void cscanner_swallowMacro (void)
 {
   int i;
   bool skipnext = FALSE;
@@ -662,7 +784,6 @@ void swallowMacro (void)
     {
       char c = (char) i;
       
-      
       if (c == '\\')
        {
          skipnext = TRUE;
@@ -675,15 +796,19 @@ void swallowMacro (void)
            }
          else
            {
-             checkUngetc (i, yyin);
+             reader_checkUngetc (i, yyin);
              return;
            }
        }
+      else
+       {
+         ;
+       }
     }
 
   if (i != EOF)
     {
-      checkUngetc (i, yyin);
+      reader_checkUngetc (i, yyin);
     }
 }
 
@@ -693,6 +818,8 @@ static int commentMarkerToken (cstring s)
   
   while (s_parsetable[i].name != NULL) 
     {
+      DPRINTF (("Try :%s:%s:", s, s_parsetable[i].name));
+
       if (cstring_equalLit (s, s_parsetable[i].name))
        {
          return s_parsetable[i].token;
@@ -717,11 +844,10 @@ static int tokenMacroCode (cstring s)
              voptgenerror
                (FLG_WARNLINTCOMMENTS,
                 cstring_makeLiteral
-                ("Traditional lint comment /*FALLTHROUGH*/ used.  "
-                 "This is interpreted by "
-                 "LCLint in the same way as most Unix lints, but it is "
+                ("Traditional lint comment /*FALLTHROUGH*/ used. "
+                 "Splint interprets this in the same way as most Unix lints, but it is "
                  "preferable to replace it with the /*@fallthrough@*/ "
-                 "stylized comment"),
+                 "semantic comment"),
                 g_currentloc);
              return QFALLTHROUGH;            
            }
@@ -730,11 +856,10 @@ static int tokenMacroCode (cstring s)
              voptgenerror 
                (FLG_WARNLINTCOMMENTS,
                 cstring_makeLiteral
-                ("Traditional lint comment /*FALLTHRU*/ used.  "
-                 "This is interpreted by "
-                 "LCLint in the same way as most Unix lints, but it is "
+                ("Traditional lint comment /*FALLTHRU*/ used. "
+                 "Splint interprets this in the same way as most Unix lints, but it is "
                  "preferable to replace it with the /*@fallthrough@*/ "
-                 "stylized comment"),
+                 "semantic comment"),
                 g_currentloc);
              return QFALLTHROUGH;
            }
@@ -743,18 +868,17 @@ static int tokenMacroCode (cstring s)
              voptgenerror 
                (FLG_WARNLINTCOMMENTS,
                 cstring_makeLiteral
-                ("Traditional lint comment /*NOTREACHED*/ used.  "
-                 "This is interpreted by "
-                 "LCLint in the same way as most Unix lints, but it is "
+                ("Traditional lint comment /*NOTREACHED*/ used. "
+                 "Splint interprets this in the same way as most Unix lints, but it is "
                  "preferable to replace it with the /*@notreached@*/ "
-                 "stylized comment."),
+                 "semantic comment."),
                 g_currentloc);
              
              return QNOTREACHED;
            }
          else if (s_keytable[i].token == QPRINTFLIKE)
            {
-             setSpecialFunction (QU_PRINTFLIKE);
+             setSpecialFunction (qual_createPrintfLike ());
              return SKIPTOK;
            }
          else if (s_keytable[i].token == QLINTPRINTFLIKE)
@@ -762,24 +886,23 @@ static int tokenMacroCode (cstring s)
              voptgenerror 
                (FLG_WARNLINTCOMMENTS,
                 cstring_makeLiteral
-                ("Traditional lint comment /*PRINTFLIKE*/ used.  "
-                 "This is interpreted by "
-                 "LCLint in the same way as most Unix lints, but it is "
+                ("Traditional lint comment /*PRINTFLIKE*/ used. "
+                 "Splint interprets this in the same way as most Unix lints, but it is "
                  "preferable to replace it with either /*@printflike@*/, "
                  "/*@scanflike@*/ or /*@messagelike@*/."),
                 g_currentloc);
              
-             setSpecialFunction (QU_PRINTFLIKE);
+             setSpecialFunction (qual_createPrintfLike ());
              return SKIPTOK;
            }
          else if (s_keytable[i].token == QSCANFLIKE)
            {
-             setSpecialFunction (QU_SCANFLIKE);
+             setSpecialFunction (qual_createScanfLike ());
              return SKIPTOK;
            }
          else if (s_keytable[i].token == QMESSAGELIKE)
            {
-             setSpecialFunction (QU_MESSAGELIKE);
+             setSpecialFunction (qual_createMessageLike ());
              return SKIPTOK;
            }
          else if (s_keytable[i].token == QARGSUSED)
@@ -787,9 +910,8 @@ static int tokenMacroCode (cstring s)
              voptgenerror
                (FLG_WARNLINTCOMMENTS,
                 cstring_makeLiteral
-                ("Traditional lint comment /*ARGSUSED*/ used.  "
-                 "This is interpreted by "
-                 "LCLint in the same way as most Unix lints, but it is "
+                ("Traditional lint comment /*ARGSUSED*/ used. "
+                 "Splint interprets this in the same way as most Unix lints, but it is "
                  "preferable to use /*@unused@*/ annotations on "
                  "the unused parameters."),
                 g_currentloc);
@@ -797,10 +919,12 @@ static int tokenMacroCode (cstring s)
              setArgsUsed ();
              return SKIPTOK;
            }
-         
-         return s_keytable[i].token;
+         else
+           {
+             return s_keytable[i].token;
+           }
        }
-      
+
       i++;
     }
   
@@ -853,6 +977,10 @@ static int returnInt (ctype ct, long i)
        {
          c = context_typeofOne ();
        }
+      else
+       {
+         ;
+       }
     }
   
   yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext), 
@@ -881,7 +1009,7 @@ static int ninput ()
   return c;
 }
 
-static char macro_nextChar ()
+static char macro_nextChar (void)
 {
   static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
   int ic;
@@ -912,6 +1040,7 @@ static char macro_nextChar ()
        }
       else /* if (c == '@') */
        {
+         llassert (FALSE); /*@i23@*/
          if (handleLlSpecial () != BADTOK)
            {
              llerrorlit (FLG_SYNTAX, "Macro cannot use special syntax");
@@ -977,14 +1106,19 @@ static char macro_nextChar ()
           lmsavechar (c2);
        }
     }
+  else
+    {
+      ;
+    }
+
   return c;
 }
 
 /*
-** keeps stylized comments
+** keeps semantic comments
 */
 
-static char macro_nextCharC ()
+static char macro_nextCharC (void)
 {
   static bool in_quote = FALSE, in_escape = FALSE, in_char = FALSE;
   char c;
@@ -1065,6 +1199,11 @@ static char macro_nextCharC ()
          lmsavechar (c2);
        }
     }
+  else /* normal character */
+    {
+      ;
+    }
+
   return c;
 }
 
@@ -1073,7 +1212,7 @@ static char macro_nextCharC ()
 ** returns first non-whitespace character
 */
 
-static char skip_whitespace ()
+static char skip_whitespace (void)
 {
   char c;
 
@@ -1103,7 +1242,7 @@ static void handleMacro ()
     {
       int i;
 
-      for (i = 0; i < ((c - '0') + 1); i++)
+      for (i = 0; i < (((int) (c - '0')) + 1); i++)
        {
          mac = cstring_appendChar (mac, ' ');
        }
@@ -1123,7 +1262,6 @@ static void handleMacro ()
 
   if (macrocode == BADTOK && !isArtificial (mac))
     {
-      DPRINTF (("Add macro: %s", mac));
       context_addMacroCache (mac);
     }
   else
@@ -1185,27 +1323,25 @@ static bool processMacro (void)
            {
              c = macro_nextChar ();
            }
-         unput (c);
+         unput ((int) c);
        }
 
       if (c == '\n')
        {
          emptyMacro = TRUE;
-         unput (c);
+         unput ((int) c);
        }
 
       c = oldc;
     }
 
   hasParams = (c == '(');
-
   
   if (usymtab_exists (fname))
     {
       e2 = usymtab_lookupExpose (fname);
       ct = uentry_getType (e2);
 
-      
       if (uentry_isCodeDefined (e2) 
          && fileloc_isUser (uentry_whereDefined (e2)))
        {
@@ -1278,7 +1414,7 @@ static bool processMacro (void)
                      
                      uentry_showWhereSpecified (e2);
                      uentry_setType (e2, ctype_unknown);
-                     uentry_makeVarFunction (e2);
+                     uentry_makeConstantFunction (e2);
                      uentry_setDefined (e2, g_currentloc);
                      uentry_setFunctionDefined (e2, g_currentloc);
                      context_enterUnknownMacro (e2); 
@@ -1317,6 +1453,10 @@ static bool processMacro (void)
                                  fileloc_unparse (oloc)),
                                 loc);
                            }
+                         else
+                           {
+                             /* No warning */
+                           }
                        }
 
                      context_enterConstantMacro (e2);        
@@ -1394,7 +1534,7 @@ static bool processMacro (void)
                                  "typedef should be used instead."),
                         g_currentloc);
 
-                     swallowMacro ();
+                     cscanner_swallowMacro ();
                      /* Must exit scope (not sure why a new scope was entered?) */
                      usymtab_quietExitScope (g_currentloc);
                      uentry_setDefined (e2, g_currentloc);
@@ -1423,24 +1563,47 @@ static bool processMacro (void)
     {
       uentry ce;
 
-      voptgenerror 
-       (FLG_MACROMATCHNAME,
-        message ("Unexpanded macro %s does not match name of a constant "
-                 "or iter declaration.  The name used in the control "
-                 "comment on the previous line should match.  "
-                 "(Assuming macro defines a constant.)", 
-                 fname),
-        loc);
-
-
-      ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);      
-      uentry_setUsed (ce, loc); /* perhaps bogus? */
-      e2 = usymtab_supEntryReturn (ce);
-      
-      context_enterConstantMacro (e2);       
-      cstring_free (fname);
-      fileloc_free (loc);
-      return res;
+      /* evans 2001-09-09 - if it has params, assume a function */
+      if (hasParams)
+       {
+         voptgenerror 
+           (FLG_MACROMATCHNAME,
+            message ("Unexpanded macro %s does not match name of a declared "
+                     "function. The name used in the control "
+                     "comment on the previous line should match.",
+                     fname),
+            loc);
+         
+         ce = uentry_makeFunction (fname, ctype_unknown, 
+                                   typeId_invalid,
+                                   globSet_undefined,
+                                   sRefSet_undefined,
+                                   warnClause_undefined,
+                                   fileloc_undefined);      
+         uentry_setUsed (ce, loc); /* perhaps bogus? */
+         e2 = usymtab_supEntryReturn (ce);
+         context_enterUnknownMacro (e2);             
+       }
+      else
+       {
+         voptgenerror 
+           (FLG_MACROMATCHNAME,
+            message ("Unexpanded macro %s does not match name of a constant "
+                     "or iter declaration.  The name used in the control "
+                     "comment on the previous line should match.  "
+                     "(Assuming macro defines a constant.)", 
+                     fname),
+            loc);
+         
+         ce = uentry_makeConstant (fname, ctype_unknown, fileloc_undefined);      
+         uentry_setUsed (ce, loc); /* perhaps bogus? */
+         e2 = usymtab_supEntryReturn (ce);
+         
+         context_enterConstantMacro (e2);            
+         cstring_free (fname);
+         fileloc_free (loc);
+         return res;
+       }
     }
   
   /* in macros, ( must follow immediatetly after name */
@@ -1489,14 +1652,14 @@ static bool processMacro (void)
              && !uentry_isElipsisMarker (uentryList_getN 
                                          (specparams, paramno)))
            {
+             fileloc sloc = context_getSaveLocation ();
              uentry decl = uentryList_getN (specparams, paramno);
              sRef sr;
              
              param = uentry_nameCopy (paramname, decl);
-
                              
              uentry_setParam (param);
-             sr = sRef_makeParam (paramno, uentry_getType (param));
+             sr = sRef_makeParam (paramno, uentry_getType (param), stateInfo_makeLoc (sloc));
 
              if (sRef_getNullState (sr) == NS_ABSNULL)
                {
@@ -1513,12 +1676,12 @@ static bool processMacro (void)
                    }
                  else
                    {
-                     sRef_setNullState (sr, NS_UNKNOWN, g_currentloc);
+                     sRef_setNullState (sr, NS_UNKNOWN, sloc);
                    }
                }
 
              uentry_setSref (param, sr);
-             uentry_setDeclaredForceOnly (param, context_getSaveLocation ());
+             uentry_setDeclaredForceOnly (param, sloc);
 
              skipparam = isiter && uentry_isOut (uentryList_getN (specparams, paramno));
            }
@@ -1527,11 +1690,12 @@ static bool processMacro (void)
              fileloc sloc = context_getSaveLocation ();
 
              param = uentry_makeVariableSrefParam 
-               (paramname, ctype_unknown, sRef_makeParam (paramno, ctype_unknown));
+               (paramname, ctype_unknown, fileloc_copy (sloc), 
+                sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (sloc)));
+             DPRINTF (("Unknown param: %s", uentry_unparseFull (param)));
              cstring_free (paramname);
 
              sRef_setPosNull  (uentry_getSref (param), sloc);
-
              uentry_setDeclaredForce (param, sloc);
 
              skipparam = FALSE;
@@ -1623,31 +1787,32 @@ static bool processMacro (void)
 
 static bool handleSpecial (char *yyt)
 {
-  char *l = mstring_create (MAX_NAME_LENGTH);
-  static bool reportcpp = FALSE;
+  char *l; /* !!  = mstring_create (MAX_NAME_LENGTH); */
   int lineno = 0;
   char c;
   char *ol;
   cstring olc;
-  
-  strcpy (l, yyt + 1);
+  size_t len_yyt;
 
-  /* Need to safe original l for deallocating. */
-  ol = l;
+  len_yyt = strlen (yyt +1) ;
 
-  l += strlen (yyt) - 1;
+  l = mstring_copy (yyt + 1);
   
   while ((c = char_fromInt (lminput ())) != '\n' && c != '\0')
     {
-      *l++ = c;
+      l = mstring_append(l, c);
     }
 
-  *l = '\0';
+    /* Need to safe original l for deallocating. */
+  ol = l;
+
+  l += strlen (l);
+
   olc = cstring_fromChars (ol);
   
-  if (cstring_equalPrefix (olc, "pragma"))
+  if (cstring_equalPrefixLit (olc, "pragma"))
     {
-      char *pname = mstring_create (longUnsigned_fromInt (MAX_PRAGMA_LEN));
+      char *pname = mstring_create (size_fromInt (MAX_PRAGMA_LEN));
       char *opname = pname;
       char *ptr = ol + 6; /* pragma is six characters, plus space */
       int len = 0;
@@ -1703,7 +1868,7 @@ static bool handleSpecial (char *yyt)
          cstring_free (exname);
        }
     }
-  else if (cstring_equalPrefix (olc, "ident"))
+  else if (cstring_equalPrefixLit (olc, "ident"))
     {
       /* Some pre-processors will leave these in the code.  Ignore rest of line */
     }
@@ -1715,9 +1880,10 @@ static bool handleSpecial (char *yyt)
           || (sscanf (ol, " %d \"", &lineno) == 1))
     {
       char *tmp = ol;
-      char *fname;
+      cstring fname;
       fileId fid;
 
+      /*@access cstring@*/
       while (*tmp != '\"' && *tmp != '\0')
        {
          tmp++;
@@ -1726,6 +1892,7 @@ static bool handleSpecial (char *yyt)
       llassert (*tmp == '\"');
 
       tmp++;
+
       fname = tmp;
       
       while (*tmp != '\"' && *tmp != '\0')
@@ -1737,8 +1904,6 @@ static bool handleSpecial (char *yyt)
 
       *tmp = '\0';
 
-      DPRINTF (("fname: %s", fname));
-
 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
 
       /*
@@ -1756,15 +1921,11 @@ static bool handleSpecial (char *yyt)
        ** Skip past the drive marker.
        */
        
-       DPRINTF (("stmp: %s / %s", stmp, fname));
-       
        if (strchr (stmp, ':') != NULL)
          {
            stmp = strchr (stmp, ':') + 1;
          }
        
-       DPRINTF (("stmp: %s / %s", stmp, fname));
-       
        while ((stmp = strchr (stmp, CONNECTCHAR)) != NULL )
          {
            if (*(stmp+1) == CONNECTCHAR)
@@ -1773,41 +1934,38 @@ static bool handleSpecial (char *yyt)
              }
            
            stmp++;
-           DPRINTF (("stmp: %s / %s", stmp, fname));
          }
        
-       DPRINTF (("Now: base = %s", fname));
-       
-       fid = fileTable_lookupBase (context_fileTable (),
-                                   cstring_fromChars (fname));
+       fid = fileTable_lookupBase (context_fileTable (), fname);
        if (!(fileId_isValid (fid)))
          {
            fname = removePreDirs (fname);
-           fid = fileTable_lookupBase (context_fileTable (),
-                                       cstring_fromChars (fname));
+           fid = fileTable_lookupBase (context_fileTable (), fname);
          }
       }
 # else  /* !defined(OS2) && !defined(MSDOS) */
       fname = removePreDirs (fname);
-      fid = fileTable_lookupBase (context_fileTable (),
-                                 cstring_fromChars (fname));
+      fid = fileTable_lookupBase (context_fileTable (), fname);      
 # endif /* !defined(OS2) && !defined(MSDOS) */
       
       if (!(fileId_isValid (fid)))
        {
-         if (isHeaderFile (cstring_fromChars (fname)))
+         if (context_inXHFile ())
            {
-             fid = fileTable_addHeaderFile (context_fileTable (), 
-                                            cstring_fromChars (fname));
+             fid = fileTable_addXHFile (context_fileTable (), fname);
+           }
+         else if (isHeaderFile (fname))
+           {
+             fid = fileTable_addHeaderFile (context_fileTable (), fname);
            }
          else
            {
-             fid = fileTable_addFile (context_fileTable (), 
-                                      cstring_fromChars (fname));
+             fid = fileTable_addFile (context_fileTable (), fname);
            }
        }
       
       setFileLine (fid, lineno);
+      /*@noaccess cstring@*/
     }
   else if ((sscanf (ol, "line %d", &lineno) == 1) 
           || (sscanf (ol, " %d", &lineno) == 1))
@@ -1825,32 +1983,34 @@ static bool handleSpecial (char *yyt)
        mstring_free (ol);
        return FALSE;
       } else {
-       if (!reportcpp)
-         {
-           
-         } else {
-           llbug (message ("File contains preprocessor command: #%s", 
-                           cstring_fromChars (ol)));
-           reportcpp = TRUE;
-         }
+       voptgenerror
+         (FLG_UNRECOGDIRECTIVE,
+          message ("Unrecognized pre-processor directive: #%s", 
+                   cstring_fromChars (ol)),
+          g_currentloc);
       }
       
       sfree (ol);
-      return TRUE;
+      return FALSE; /* evans 2001-12-30: was: TRUE; */
     }
 
   sfree (ol);
   return FALSE;
 }
   
-static int handleLlSpecial ()
+static int handleLlSpecial (void)
 { 
+  bool hasnl = FALSE;
   int ic; 
   char c;
   char *s = mstring_createEmpty ();
   char *os; 
   int tok;
   int charsread = 0;
+  fileloc loc;
+
+  loc = fileloc_copy (g_currentloc);
+  DPRINTF (("Handle special: %s", fileloc_unparse (loc)));
 
   while (((ic = ninput ()) != 0) && isalpha (ic))
     {
@@ -1859,63 +2019,78 @@ static int handleLlSpecial ()
       charsread++;
     }
 
+  DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
   os = s;
 
   if (charsread == 0 && ic == (int) AFTER_COMMENT_MARKER[0])
     {
       ic = ninput ();
 
-      llassert (ic == AFTER_COMMENT_MARKER[1]);
-
+      llassert (ic == (int) AFTER_COMMENT_MARKER[1]);
             
-      if (isProcessingGlobMods () && (*s == '\0'))
+      if (*s == '\0')
        {
          sfree (os);
+         fileloc_free (loc);
          return QNOMODS; /* special token no modifications token */
        }
-      else
-       {
-         ;
-       }
     }
   
+  DPRINTF (("Coment marker: %s", os));
   tok = commentMarkerToken (cstring_fromChars (os));
 
   if (tok != BADTOK)
     {
       tokLength = charsread;
       sfree (os);
-      inSpecPart = TRUE;
+      s_inSpecPart = TRUE;
+      s_whichSpecPart = tok;
+      fileloc_free (loc);
       return tok;
     }
-  
+
+  DPRINTF (("Not a comment marker..."));
   /* Add rest of the comment */
   
   if (ic != 0 && ic != EOF)
     {
       c = (char) ic;
-
       
       s = mstring_append (s, c);
       charsread++;
 
       while (((ic = ninput ()) != 0) && (ic != EOF)
-            && (ic != AFTER_COMMENT_MARKER[0]))
+            && (ic != (int) AFTER_COMMENT_MARKER[0]))
        {
          c = (char) ic;
+
+         /* evans 2001-09-01 added to prevent assertion failures for uncloses syntactic comments */
+
+         if (c == '\n') {
+           hasnl = TRUE; /* This prevents tokLength from being set later. */
+           tokLength = 0; 
+
+           voptgenerror
+             (FLG_SYNTAX, 
+              message ("Likely parse error: syntactic comment token spans multiple lines: %s",
+                       cstring_fromChars (s)),
+              loc);
+         }
+
          s = mstring_append (s, c);
          charsread++;
        }
     }
 
-  if (ic == AFTER_COMMENT_MARKER[0]) 
+  DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
+
+  if (ic == (int) AFTER_COMMENT_MARKER[0]) 
     {
       int nc = ninput ();
       llassert ((char) nc ==  AFTER_COMMENT_MARKER[1]);
       charsread++;
     }
 
-  
   os = s;
 
   while (*s == ' ' || *s == '\t' || *s == '\n') 
@@ -1947,61 +2122,61 @@ static int handleLlSpecial ()
          if (!context_getFlag (FLG_NOCOMMENTS))
            {
              cstring flagname = thisflag;
-             flagcode fflag = identifyFlag (flagname);
-               
+             flagcode fflag = flags_identifyFlag (flagname);
+             
              if (flagcode_isSkip (fflag))
                {
                  ;
                }
-             else if (flagcode_isInvalid (fflag))
+             else if (flagcode_isModeName (fflag))
                {
-                 if (isMode (flagname))
+                 if (ynm_isMaybe (set))
                    {
-                     if (ynm_isMaybe (set))
-                       {
-                         llerror
-                           (FLG_BADFLAG, 
-                            message 
-                            ("Stylized comment attempts to restore flag %s.  "
-                             "A mode flag cannot be restored.",
-                             flagname));
-                       }
-                     else
-                       {
-                         context_setMode (flagname);
-                       }
+                     llerror
+                       (FLG_BADFLAG, 
+                        message 
+                        ("Semantic comment attempts to restore flag %s.  "
+                         "A mode flag cannot be restored.",
+                         flagname));
                    }
                  else
                    {
-                     llerror
-                       (FLG_BADFLAG, 
-                        message ("Unrecognized option in stylized comment: %s", 
-                                 flagname));
+                     context_setMode (flagname);
                    }
                }
+             else if (flagcode_isInvalid (fflag))
+               {
+                 voptgenerror
+                   (FLG_UNRECOGFLAGCOMMENTS,
+                    message ("Unrecognized option in semantic comment: %s", 
+                             flagname),
+                    loc);
+               }
              else if (flagcode_isGlobalFlag (fflag))
                {
-                 llerror
+                 voptgenerror
                    (FLG_BADFLAG, 
                     message 
-                    ("Stylized comment attempts to set global flag %s.  "
+                    ("Semantic comment attempts to set global flag %s.  "
                      "A global flag cannot be set locally.",
-                     flagname));
+                     flagname),
+                    loc);
                }
              else
                {
-                 context_fileSetFlag (fflag, set);
+                 context_fileSetFlag (fflag, set, loc);
                  
                  if (flagcode_hasArgument (fflag))
                    {
                      if (ynm_isMaybe (set))
                        {
-                         llerror
+                         voptgenerror
                            (FLG_BADFLAG, 
                             message 
-                            ("Stylized comment attempts to restore flag %s.  "
+                            ("Semantic comment attempts to restore flag %s.  "
                              "A flag for setting a value cannot be restored.",
-                             flagname));
+                             flagname),
+                            loc);
                        }
                      else
                        { /* cut-and-pastied from llmain...blecch */
@@ -2029,7 +2204,10 @@ static int handleLlSpecial ()
                              rest++; 
                              s++;
                            }
-                         
+                         s--; /* evans 2002-07-12: this was previously only in the else branch.
+                                 Leads to an invalid read on the true branch.
+                              */
+
                          sfree (orest);
                          
                          if (cstring_isUndefined (extra))
@@ -2037,14 +2215,17 @@ static int handleLlSpecial ()
                              llerror 
                                (FLG_BADFLAG,
                                 message
-                                ("Flag %s (in stylized comment) must be followed by an argument",
+                                ("Flag %s (in semantic comment) must be followed by an argument",
                                  flagcode_unparse (fflag)));
+
                            }
                          else
                            {
-                             s--;
-                             
-                             if (flagcode_hasValue (fflag))
+                             if (flagcode_hasNumber (fflag))
+                               {
+                                 setValueFlag (fflag, extra);
+                               }
+                             else if (flagcode_hasChar (fflag))
                                {
                                  setValueFlag (fflag, extra);
                                }
@@ -2054,6 +2235,7 @@ static int handleLlSpecial ()
                                }
                              else
                                {
+                                 cstring_free (extra);
                                  BADEXIT;
                                }
                            }
@@ -2075,7 +2257,8 @@ static int handleLlSpecial ()
 
       if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
        {
-                 context_addComment (cstring_fromCharsNew (os));
+         DPRINTF (("Here adding comment: %s", os));
+         context_addComment (cstring_fromCharsNew (os), loc);
        }
       else
        {
@@ -2087,6 +2270,7 @@ static int handleLlSpecial ()
       char *t = s;
       int macrocode;
       char tchar = '\0';
+      annotationInfo ainfo;
 
       while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n') 
        {
@@ -2105,11 +2289,11 @@ static int handleLlSpecial ()
 
       if (macrocode != BADTOK)
        {
-         tokLength = mstring_length (t);
-
+         tokLength = hasnl ? 0 : size_toInt (mstring_length (t));
          
          sfree (t);
          sfree (os);
+         fileloc_free (loc);
 
          if (macrocode == SKIPTOK)
            {
@@ -2119,6 +2303,18 @@ static int handleLlSpecial ()
          return macrocode;
        }
       
+      ainfo = context_lookupAnnotation (cstring_fromChars (os));
+      
+      if (annotationInfo_isDefined (ainfo)) {
+       DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
+       /*@i324@*/ yylval.annotation = ainfo;
+       tokLength = 0;
+       sfree (os);
+       sfree (t);
+       fileloc_free (loc);
+       return CANNOTATION;
+      } 
+
       if (context_inHeader ())
        {
          if (tchar != '\0')
@@ -2130,7 +2326,14 @@ static int handleLlSpecial ()
              && macrocode != SKIPTOK
              && !isArtificial (cstring_fromChars (os))) 
            {
-             context_addComment (cstring_fromCharsNew (os));
+             if (context_processingMacros ())
+               {
+                 /* evans 2002-02-24: don't add comments when procssing macros */
+               }
+             else
+               {
+                 context_addComment (cstring_fromCharsNew (os), loc);
+               }
            }
          else
            {
@@ -2147,7 +2350,7 @@ static int handleLlSpecial ()
        {
          if (!context_getFlag (FLG_NOCOMMENTS))
            {
-             context_enterSuppressRegion ();
+             context_enterSuppressRegion (loc);
            }
        }
       else if ((*t == 'i' || *t == 't')
@@ -2156,7 +2359,7 @@ static int handleLlSpecial ()
          if (!context_getFlag (FLG_NOCOMMENTS)
              && (*t == 'i' || context_getFlag (FLG_TMPCOMMENTS)))
            {
-             context_enterSuppressLine (-1); /* infinite suppression */
+             context_enterSuppressLine (-1, loc); /* infinite suppression */
            }
        }
       else if (((*t == 'i') || (*t == 't'))
@@ -2175,23 +2378,23 @@ static int handleLlSpecial ()
              while (lc >= '0' && lc <= '9')
                {
                  val *= 10;
-                 val += lc - '0';
+                 val += (int) (lc - '0');
                  lc = *(++tt);
                }
            }
-
          
          if (!context_getFlag (FLG_NOCOMMENTS)
              && (!tmpcomment || context_getFlag (FLG_TMPCOMMENTS)))
            {
-             context_enterSuppressLine (val);
+             DPRINTF (("Here: enter suppress: %s", fileloc_unparse (loc)));
+             context_enterSuppressLine (val, loc);
            }
        }
       else if (mstring_equal (t, "end"))
        {
          if (!context_getFlag (FLG_NOCOMMENTS))
            {
-             context_exitSuppressRegion ();
+             context_exitSuppressRegion (loc);
            }
        }
       else if (mstring_equal (t, "notfunction"))
@@ -2204,7 +2407,7 @@ static int handleLlSpecial ()
          
          while (TRUE)
            {
-             while ((c = *s) && (c == ' ' || c == '\t' || c == '\n'))
+             while (((c = *s) != '\0') && (c == ' ' || c == '\t' || c == '\n'))
                {
                  s++;
                }
@@ -2224,24 +2427,42 @@ static int handleLlSpecial ()
 
              *s = '\0';
 
-             
+             DPRINTF (("Access %s", tname));
+
              if (!context_getFlag (FLG_NOCOMMENTS) 
                  && !context_getFlag (FLG_NOACCESS))
                {
                  if (usymtab_existsType (tname))
                    {
-                     usymId uid = usymtab_getTypeId (tname);
-                     context_addFileAccessType (uid);
+                     typeId uid = usymtab_getTypeId (tname);
+                     uentry ue = usymtab_getTypeEntry (uid);
+
+                     if (uentry_isAbstractDatatype (ue))
+                       {
+                         context_addFileAccessType (uid);
+                         DPRINTF (("Adding access to: %s / %d", tname, uid));
+                       }
+                     else
+                       {
+                         voptgenerror
+                           (FLG_COMMENTERROR,
+                            message
+                            ("Non-abstract type %s used in access comment",
+                             tname),
+                            loc);
+                       }
                    }
                  else
                    {
                      if (!(context_inSuppressRegion ()
-                           || context_inSuppressZone (g_currentloc)))
+                           || context_inSuppressZone (loc)))
                        {
-                         llmsg 
-                           (message
-                            ("%q: Unrecognized type %s used in access comment",
-                             fileloc_unparse (g_currentloc), tname));
+                         voptgenerror
+                           (FLG_COMMENTERROR,
+                            message
+                            ("Unrecognized type %s used in access comment",
+                             tname),
+                            loc);
                        }
                    }
                }
@@ -2264,7 +2485,7 @@ static int handleLlSpecial ()
          
          while (TRUE)
            {
-             while ((lc = *s) && (lc == ' ' || lc == '\t' || lc == '\n')) 
+             while (((lc = *s) != '\0') && (lc == ' ' || lc == '\t' || lc == '\n')) 
                {
                  s++;
                }
@@ -2293,28 +2514,33 @@ static int handleLlSpecial ()
                      
                      if (context_couldHaveAccess (tuid))
                        {
+                         DPRINTF (("Removing access: %s", tname));
                          context_removeFileAccessType (tuid);
                        }
                      else
                        {
                          if (!(context_inSuppressRegion () 
-                               || context_inSuppressZone (g_currentloc)))
+                               || context_inSuppressZone (loc)))
                            {
                              uentry ue = usymtab_getTypeEntry (tuid);
                              
                              if (uentry_isAbstractDatatype (ue))
                                {
-                                 llmsg
-                                   (message
-                                    ("%q: Non-accessible abstract type %s used in noaccess comment",
-                                     fileloc_unparse (g_currentloc), tname));
+                                 voptgenerror
+                                   (FLG_COMMENTERROR,
+                                    message
+                                    ("Non-accessible abstract type %s used in noaccess comment",
+                                     tname),
+                                    loc);
                                }
                              else
                                {
-                                 llmsg
-                                   (message
-                                    ("%q: Non-abstract type %s used in noaccess comment",
-                                     fileloc_unparse (g_currentloc), tname));
+                                 voptgenerror
+                                   (FLG_COMMENTERROR,
+                                    message
+                                    ("Non-abstract type %s used in noaccess comment",
+                                     tname),
+                                    loc);
                                }
                            }
                        }
@@ -2322,12 +2548,14 @@ static int handleLlSpecial ()
                  else
                    {
                      if (!(context_inSuppressRegion () 
-                           || context_inSuppressZone (g_currentloc)))
+                           || context_inSuppressZone (loc)))
                        {
-                         llmsg
-                           (message
-                            ("%q: Unrecognized type %s used in noaccess comment",
-                             fileloc_unparse (g_currentloc), tname));
+                         voptgenerror
+                           (FLG_COMMENTERROR,
+                            message
+                            ("Unrecognized type %s used in noaccess comment",
+                             tname),
+                            loc);
                        }
                    }
                }
@@ -2345,24 +2573,23 @@ static int handleLlSpecial ()
        }
       else
        {
-         setTokLength (- (2 + charsread));
-
          voptgenerror (FLG_UNRECOGCOMMENTS, 
-                       message ("Stylized comment unrecognized: %s", 
-                                cstring_fromChars (os)), 
-                       g_currentloc);
+                       message ("Semantic comment unrecognized: %s", 
+                                cstring_fromChars (os)),
+                       loc);
        }
-
+      
       sfree (t);
     }
   
-  sfree (os); 
+  sfree (os);
+  fileloc_free (loc);
   return BADTOK;
 }
 
 static /*@only@*/ cstring makeIdentifier (char *s)
 {
-  char *c = mstring_create (size_toInt (strlen (s)) + 1);
+  char *c = mstring_create (strlen (s) + 1);
   cstring id = cstring_fromChars (c);
 
   while (isalnum (*s) || (*s == '_') || (*s == '$')) 
@@ -2415,23 +2642,46 @@ static /*@only@*/ cstring makeIdentifier (char *s)
   return (usymtab_lookup (cn));
 }
 
-/*@observer@*/ cstring LastIdentifier ()
+/*
+** Need to keep this in case there is a declaration that isn't processed until
+** the scope exits.  Would be good to rearrange the symbol table so this doesn't
+** happen, and save all the cstring copying.
+*/
+
+/*@observer@*/ cstring cscanner_observeLastIdentifier ()
 {
-  return (lastidprocessed);
+  cstring res = s_lastidprocessed;
+  return res;
+}
+
+static void cscanner_setLastIdentifier (/*@keep@*/ cstring id) /*@modifies s_lastidprocessed@*/
+{
+  if (cstring_isDefined (s_lastidprocessed))
+    {
+      cstring_free (s_lastidprocessed); 
+    }
+
+  s_lastidprocessed = id;
 }
 
 static int processIdentifier (cstring id)
 {
   uentry le;
 
-  DPRINTF (("Process identifier: %s", id));
+  if (context_getFlag (FLG_GRAMMAR))
+    {
+      lldiagmsg (message ("Process identifier: %s", id));
+    }
 
   context_clearJustPopped ();
-  lastidprocessed = id; 
+  cscanner_setLastIdentifier (id);
+
+  DPRINTF (("Context: %s", context_unparse ()));
 
-  if (context_inFunctionDecl ())
+  if (context_inFunctionHeader ())
     {
       int tok = commentMarkerToken (id);
+      DPRINTF (("in function decl: %s", id));
 
       if (tok != BADTOK)
        {
@@ -2440,14 +2690,48 @@ static int processIdentifier (cstring id)
       else 
        {
          tok = tokenMacroCode (id);
-
+         
          if (tok != BADTOK)
            {
              return tok;
            }
+         else 
+           {
+             annotationInfo ainfo;
+
+             if (expectingMetaStateName) 
+               {
+                 metaStateInfo msinfo = context_lookupMetaStateInfo (id);
+
+                 if (metaStateInfo_isDefined (msinfo))
+                   {
+                     yylval.msinfo = msinfo;
+                     return METASTATE_NAME;
+                   }
+                 else
+                   {
+                     DPRINTF (("Not meta state name: %s", cstring_toCharsSafe (id)));
+                   }
+               }
+             
+             ainfo = context_lookupAnnotation (id);
+             
+             if (annotationInfo_isDefined (ainfo)) 
+               {
+                 DPRINTF (("Found annotation: %s", annotationInfo_unparse (ainfo)));
+                 /*@i324@*/ yylval.annotation = ainfo;
+                 return CANNOTATION;
+               }
+             else
+               {
+                 DPRINTF (("Not annotation: %s", id));
+               }
+           }
        }
     }
 
+  DPRINTF (("Here!"));
+
   /* Consider handling: Defined by C99 as static const char __func__[] */
 
   if (context_getFlag (FLG_GNUEXTENSIONS))
@@ -2480,11 +2764,20 @@ static int processIdentifier (cstring id)
        {
          tok = CALIGNOF; /* alignof is parsed like sizeof */
        }
+      else if (cstring_equalLit (id, "__typeof__")) 
+       {
+         tok = CTYPEOF;
+       }
+      else if (cstring_equalLit (id, "typeof")) 
+       {
+         tok = CTYPEOF;
+       }
       else if (cstring_equalLit (id, "__FUNCTION__")
               || cstring_equalLit (id, "__PRETTY_FUNCTION__")) 
        {
          /* These tokens hold the name of the current function as strings */
-         yylval.expr = exprNode_stringLiteral (id, fileloc_copy (g_currentloc));
+         /* evans 2001-12-30: changed from exprNode_stringLiteral; bug reported by Jim Zelenka. */
+         yylval.expr = exprNode_makeConstantString (id, fileloc_copy (g_currentloc));
          tokLength = 0;
          lastWasString = TRUE;
          tok = CCONSTANT;
@@ -2505,22 +2798,23 @@ static int processIdentifier (cstring id)
 
          while ((ic = input ()) != EOF)
            {
-                             
+             char cc = (char) ic;
+
              if (inescape)
                {
                  inescape = FALSE;
                }
-             else if (ic == '\\')
+             else if (cc == '\\')
                {
                  inescape = TRUE;
                }
-             else if (ic == '\"')
+             else if (cc == '\"')
                {
                  inquote = !inquote;
                }
              else if (!inquote)
                {
-                 if (ic == '(')
+                 if (cc == '(')
                    {
                      if (!useparens)
                        {
@@ -2535,7 +2829,7 @@ static int processIdentifier (cstring id)
                          depth++;
                        }
                    }
-                 else if (ic == '{')
+                 else if (cc == '{')
                    {
                      if (!usebraces)
                        {
@@ -2550,17 +2844,17 @@ static int processIdentifier (cstring id)
                          depth++;
                        }
                    }
-                 else if (ic == ')' && useparens)
+                 else if (cc == ')' && useparens)
                    {
                      depth--;
                      if (depth == 0) break;
                    }
-                 else if (ic == '}' && usebraces)
+                 else if (cc == '}' && usebraces)
                    {
                      depth--;
                      if (depth == 0) break;
                    }
-                 else if (ic == '}' 
+                 else if (cc == '}' 
                           && !usebraces && !useparens
                           && cstring_equalLit (id, "__asm"))
                    {
@@ -2572,9 +2866,17 @@ static int processIdentifier (cstring id)
                      */ 
                      return TRBRACE;
                    }
+                 else
+                   {
+                     ;
+                   }
+               }
+             else
+               {
+                 ;
                }
 
-             if (ic == '\n')
+             if (cc == '\n')
                {
                  context_incLineno ();
 
@@ -2586,8 +2888,8 @@ static int processIdentifier (cstring id)
                }
            }
          
-         llassert ((useparens && ic == ')')
-                   || (usebraces && ic == '}')
+         llassert ((useparens && ic == (int) ')')
+                   || (usebraces && ic == (int) '}')
                    || (!useparens && !usebraces));
 
          return BADTOK;
@@ -2599,6 +2901,10 @@ static int processIdentifier (cstring id)
        {
          tok = QINLINE;
        }
+      else
+       {
+         ;
+       }
       
       if (tok != BADTOK)
        {
@@ -2612,17 +2918,17 @@ static int processIdentifier (cstring id)
   
   if (uentry_isIter (le))
     {
-      yylval.entry = le;
+      /*@i32@*/ yylval.entry = le;
       return (ITER_NAME);
     }
   else if (uentry_isEndIter (le))
     {
-      yylval.entry = le;
+      /*@i32@*/ yylval.entry = le;
       return (ITER_ENDNAME);
     }
   else if (uentry_isUndefined (le))
     {
-      yylval.cname = id;
+      yylval.cname = cstring_copy (id);
 
       /* avoid parse errors for certain system built ins */
 
@@ -2638,12 +2944,12 @@ static int processIdentifier (cstring id)
     {
       if (uentry_isDatatype (le))
        {
-         yylval.cname = id;
+         yylval.cname = cstring_copy (id);
          return (NEW_IDENTIFIER);
        }
       else
        {
-         yylval.entry = le;              
+         /*@i32@*/ yylval.entry = le;            
          return (IDENTIFIER); 
        }
     }
@@ -2651,7 +2957,7 @@ static int processIdentifier (cstring id)
     {
       if (!g_expectingTypeName)
        {
-         yylval.cname = id;
+         yylval.cname = cstring_copy (id);
 
          return (NEW_IDENTIFIER);
        }
@@ -2665,7 +2971,7 @@ static int processIdentifier (cstring id)
     }
   else
     {
-      yylval.entry = le;            
+      /*@i32@*/ yylval.entry = le;            
       return (IDENTIFIER); 
     }
 
@@ -2681,8 +2987,8 @@ static bool processHashIdentifier (/*@only@*/ cstring id)
       
       context_clearJustPopped ();
 
-      lastidprocessed = id; 
       le = usymtab_lookupSafe (id);
+      cscanner_setLastIdentifier (id);
 
       if (uentry_isParam (le) || uentry_isRefParam (le))
        {
@@ -2695,13 +3001,17 @@ static bool processHashIdentifier (/*@only@*/ cstring id)
     }
   else
     {
+      /*
+      ** Will be handled by handleLlSpecial
+      */
+
       cstring_free (id);
       return FALSE;
     }
 }
 
 
-static /*@only@*/ exprNode processString ()
+static /*@only@*/ exprNode processString (void)
 {
   exprNode res;
   fileloc loc;
@@ -2711,7 +3021,7 @@ static /*@only@*/ exprNode processString ()
   if (nl == NULL)
     {
       loc = fileloc_copy (g_currentloc);
-      addColumn (cstring_length (ns));
+      addColumn (size_toInt (cstring_length (ns)));
     }
   else
     {
@@ -2733,6 +3043,46 @@ static /*@only@*/ exprNode processString ()
   return (res);
 }
 
+/*
+** process a wide character string L"...."
+*/
+
+static /*@only@*/ exprNode processWideString ()
+{
+  exprNode res;
+  fileloc loc;
+  char *nl = strchr (yytext, '\n');
+  cstring ns;
+
+  llassert (*yytext == 'L');
+  yytext++;
+
+  ns = cstring_fromCharsNew (yytext);
+  
+  if (nl == NULL)
+    {
+      loc = fileloc_copy (g_currentloc);
+      addColumn (size_toInt (cstring_length (ns)));
+    }
+  else
+    {
+      char *lastnl = nl;
+
+      loc = fileloc_copy (g_currentloc);
+
+      context_incLineno ();
+      
+      while ((nl = strchr ((nl + 1), '\n')) != NULL)
+       {
+         context_incLineno ();
+         lastnl = nl;
+       }
+    }
+
+  res = exprNode_wideStringLiteral (ns, loc);
+  return (res);
+}
+
 static 
 char processChar ()
 {
@@ -2830,6 +3180,22 @@ long processOctal ()
     
     if (c >= '0' && c <= '7') {
       tval = (int) c - (int) '0';
+    } else if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
+      index++;
+      while (yytext[index] != '\0') {
+       if (c == 'U' || c == 'L' || c == 'u' || c == 'l') {
+         ;
+       } else {
+         voptgenerror
+           (FLG_SYNTAX, 
+            message ("Invalid character (%c) following specifier in octal constant: %s",
+                     c, cstring_fromChars (yytext)),
+            g_currentloc);
+       }
+       index++;
+      }
+
+      break;
     } else {
       voptgenerror
        (FLG_SYNTAX, 
@@ -2857,18 +3223,48 @@ static int
 processSpec (int tok)
 {
   size_t length = strlen (yytext);
-
   
-  if (inSpecPart)
-    {
-      setTokLengthT (length);
-      RETURN_TOK (tok);
-    }
-  else
+  if (s_inSpecPart)
     {
       
-      context_saveLocation ();
-      setTokLengthT (length);
-      return (processIdentifier (makeIdentifier (yytext)));
+#if 0
+
+      if (s_whichSpecPart == QMODIFIES
+         || s_whichSpecPart == QDEFINES
+         || s_whichSpecPart == QUSES 
+         || s_whichSpecPart == QALLOCATES
+         || s_whichSpecPart == QSETS
+         || s_whichSpecPart == QRELEASES
+         || s_whichSpecPart == QPRECLAUSE
+         || s_whichSpecPart == QPOSTCLAUSE
+         || s_whichSpecPart == QINVARIANT)
+       {
+         ; /* Allow specificiation keywords to be used as identifiers in these contexts. */
+       }
+      else
+
+#endif
+
+       {
+         setTokLengthT (length);
+         RETURN_TOK (tok);
+       }
     }
+  
+  context_saveLocation ();
+  setTokLengthT (length);
+  return (processIdentifier (makeIdentifier (yytext)));
+}
+
+void cscanner_expectingMetaStateName ()
+{
+  llassert (!expectingMetaStateName);
+  llassert (context_inFunctionHeader ());
+  expectingMetaStateName = TRUE;
+}
+
+void cscanner_clearExpectingMetaStateName ()
+{
+  llassert (expectingMetaStateName);
+  expectingMetaStateName = FALSE;
 }
This page took 0.134003 seconds and 4 git commands to generate.