]> 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 50ce86da590a9febd762e1816cc8d92ea0d79acd..77d33d09a311ec0bc9f0026ce211a91f1a6bc876 100644 (file)
@@ -1,6 +1,6 @@
 /*;-*-C-*-; 
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2001 University of Virginia,
+** Copyright (C) 1994-2002 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -17,8 +17,8 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on lclint: lclint-request@cs.virginia.edu
-** To report a bug: lclint-bug@cs.virginia.edu
+** For information on splint: splint@cs.virginia.edu
+** To report a bug: splint-bug@cs.virginia.edu
 ** For more information: http://www.splint.org
 */
 /*
@@ -36,7 +36,7 @@
 /*
 ** Modified by Mike Smith 
 ** Corrected missing 'line' in scanf() calls in handleSpecial().
-** Without this, I get an error when LCLint hits a '#line' directive
+** 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.
@@ -64,20 +64,26 @@ IS                  (u|U|l|L)*
 ULSuffix                ({U}{L}|{L}{U})
 
 %{
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # if defined(OS2) && defined(__IBMC__)
    /* needed for isatty()... */
 # include <io.h>
 # else
+
+/*
+** Win32 doesn't have unistd.h
+*/
+
+# ifndef WIN32
 # include <unistd.h>
 # endif
 
+# endif
+
 # include "basic.h"
 
 # include "cgrammar.h"
 # include "cgrammar_tokens.h"
-
-# include "fileIdList.h"
 # include "portab.h"
 
 static bool lastWasString = FALSE;
@@ -86,10 +92,11 @@ static char savechar = '\0';
 /*@notfunction@*/
 # define yyinput() (incColumn (), getc (yyin))
 
-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);
@@ -101,9 +108,9 @@ 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 *);
@@ -191,7 +198,7 @@ static void setTokLengthT (size_t len)
 
 %%
 
-"/*"           { llfatalbug (cstring_makeLiteral ("Comment in pre-processor output")); }
+"/*"           { llfatalerror (cstring_makeLiteral ("Comment in pre-processor output")); }
 
 "#"{Letter}({Letter}|{Digit})*  { 
                  context_saveLocation (); 
@@ -263,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); }
@@ -288,6 +296,8 @@ L\"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processWideString
 "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)); }
@@ -466,7 +476,7 @@ L'(\\.|[^\\'])+'       { setTokLengthT (mstring_length (yytext));
                     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);
                       }  
@@ -563,7 +573,8 @@ L'(\\.|[^\\'])+'       { setTokLengthT (mstring_length (yytext));
                }
 "%}"            { /* AFTER_COMMENT_MARKER */ 
                   setTokLength (2);
-                 inSpecPart = FALSE;
+                 s_inSpecPart = FALSE;
+                 s_whichSpecPart = BADTOK;
                  RETURN_TOK (QENDMACRO); }
 "\\"            { incColumn (); continueLine = TRUE; }
 .              { incColumn (); 
@@ -579,6 +590,58 @@ L'(\\.|[^\\'])+'       { setTokLengthT (mstring_length (yytext));
                }
 %%
 
+/*
+** 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;
@@ -590,7 +653,7 @@ struct skeyword
 ** grammar proper.
 */
 
-struct skeyword s_parsetable[] = {
+static struct skeyword s_parsetable[] = {
   { "modifies", QMODIFIES } ,
   { "globals", QGLOBALS } ,
   { "alt", QALT } ,
@@ -610,6 +673,7 @@ struct skeyword s_parsetable[] = {
   { "testinRange", QTESTINRANGE},
   { "requires", QPRECLAUSE } ,
   { "ensures", QPOSTCLAUSE } ,
+  { "invariant", QINVARIANT} ,
   { NULL, BADTOK } 
 } ;
 
@@ -618,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 } ,
@@ -632,6 +696,8 @@ struct skeyword s_keytable[] = {
   { "special", QSPECIAL } ,
   { "truenull", QTRUENULL } ,
   { "falsenull", QFALSENULL } ,
+  { "nullwhentrue", QTRUENULL } ,
+  { "falsewhennull", QFALSENULL } ,
   { "keep", QKEEP } ,
   { "kept", QKEPT } ,
   { "notnull", QNOTNULL } ,
@@ -655,15 +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 } ,
@@ -701,7 +775,7 @@ static bool isArtificial (cstring s)
          || cstring_equalLit (s, "alt"));
 }
 
-void swallowMacro (void)
+void cscanner_swallowMacro (void)
 {
   int i;
   bool skipnext = FALSE;
@@ -710,7 +784,6 @@ void swallowMacro (void)
     {
       char c = (char) i;
       
-      
       if (c == '\\')
        {
          skipnext = TRUE;
@@ -727,6 +800,10 @@ void swallowMacro (void)
              return;
            }
        }
+      else
+       {
+         ;
+       }
     }
 
   if (i != EOF)
@@ -767,9 +844,8 @@ 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@*/ "
                  "semantic comment"),
                 g_currentloc);
@@ -780,9 +856,8 @@ 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@*/ "
                  "semantic comment"),
                 g_currentloc);
@@ -793,9 +868,8 @@ 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@*/ "
                  "semantic comment."),
                 g_currentloc);
@@ -812,9 +886,8 @@ 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);
@@ -837,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);
@@ -847,10 +919,12 @@ static int tokenMacroCode (cstring s)
              setArgsUsed ();
              return SKIPTOK;
            }
-         
-         return s_keytable[i].token;
+         else
+           {
+             return s_keytable[i].token;
+           }
        }
-      
+
       i++;
     }
   
@@ -903,6 +977,10 @@ static int returnInt (ctype ct, long i)
        {
          c = context_typeofOne ();
        }
+      else
+       {
+         ;
+       }
     }
   
   yylval.expr = exprNode_numLiteral (c, cstring_fromChars (yytext), 
@@ -931,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;
@@ -1028,6 +1106,11 @@ static char macro_nextChar ()
           lmsavechar (c2);
        }
     }
+  else
+    {
+      ;
+    }
+
   return c;
 }
 
@@ -1035,7 +1118,7 @@ static char macro_nextChar ()
 ** 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;
@@ -1116,6 +1199,11 @@ static char macro_nextCharC ()
          lmsavechar (c2);
        }
     }
+  else /* normal character */
+    {
+      ;
+    }
+
   return c;
 }
 
@@ -1124,7 +1212,7 @@ static char macro_nextCharC ()
 ** returns first non-whitespace character
 */
 
-static char skip_whitespace ()
+static char skip_whitespace (void)
 {
   char c;
 
@@ -1154,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, ' ');
        }
@@ -1235,13 +1323,13 @@ static bool processMacro (void)
            {
              c = macro_nextChar ();
            }
-         unput (c);
+         unput ((int) c);
        }
 
       if (c == '\n')
        {
          emptyMacro = TRUE;
-         unput (c);
+         unput ((int) c);
        }
 
       c = oldc;
@@ -1365,6 +1453,10 @@ static bool processMacro (void)
                                  fileloc_unparse (oloc)),
                                 loc);
                            }
+                         else
+                           {
+                             /* No warning */
+                           }
                        }
 
                      context_enterConstantMacro (e2);        
@@ -1442,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);
@@ -1695,30 +1787,32 @@ static bool processMacro (void)
 
 static bool handleSpecial (char *yyt)
 {
-  char *l = mstring_create (MAX_NAME_LENGTH);
+  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_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;
@@ -1904,7 +1998,7 @@ static bool handleSpecial (char *yyt)
   return FALSE;
 }
   
-static int handleLlSpecial ()
+static int handleLlSpecial (void)
 { 
   bool hasnl = FALSE;
   int ic; 
@@ -1932,7 +2026,7 @@ static int handleLlSpecial ()
     {
       ic = ninput ();
 
-      llassert (ic == AFTER_COMMENT_MARKER[1]);
+      llassert (ic == (int) AFTER_COMMENT_MARKER[1]);
             
       if (*s == '\0')
        {
@@ -1949,7 +2043,8 @@ static int handleLlSpecial ()
     {
       tokLength = charsread;
       sfree (os);
-      inSpecPart = TRUE;
+      s_inSpecPart = TRUE;
+      s_whichSpecPart = tok;
       fileloc_free (loc);
       return tok;
     }
@@ -1965,7 +2060,7 @@ static int handleLlSpecial ()
       charsread++;
 
       while (((ic = ninput ()) != 0) && (ic != EOF)
-            && (ic != AFTER_COMMENT_MARKER[0]))
+            && (ic != (int) AFTER_COMMENT_MARKER[0]))
        {
          c = (char) ic;
 
@@ -1979,7 +2074,7 @@ static int handleLlSpecial ()
              (FLG_SYNTAX, 
               message ("Likely parse error: syntactic comment token spans multiple lines: %s",
                        cstring_fromChars (s)),
-              g_currentloc);
+              loc);
          }
 
          s = mstring_append (s, c);
@@ -1989,7 +2084,7 @@ static int handleLlSpecial ()
 
   DPRINTF (("Read: %s / %s", s, fileloc_unparse (g_currentloc)));
 
-  if (ic == AFTER_COMMENT_MARKER[0]) 
+  if (ic == (int) AFTER_COMMENT_MARKER[0]) 
     {
       int nc = ninput ();
       llassert ((char) nc ==  AFTER_COMMENT_MARKER[1]);
@@ -2027,39 +2122,36 @@ 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 
-                            ("Semantic 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
                    {
-                     voptgenerror
-                       (FLG_UNRECOGFLAGCOMMENTS,
-                        message ("Unrecognized option in semantic comment: %s", 
-                                 flagname),
-                        g_currentloc);
+                     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))
                {
                  voptgenerror
@@ -2068,11 +2160,11 @@ static int handleLlSpecial ()
                     ("Semantic comment attempts to set global flag %s.  "
                      "A global flag cannot be set locally.",
                      flagname),
-                    g_currentloc);
+                    loc);
                }
              else
                {
-                 context_fileSetFlag (fflag, set);
+                 context_fileSetFlag (fflag, set, loc);
                  
                  if (flagcode_hasArgument (fflag))
                    {
@@ -2084,7 +2176,7 @@ static int handleLlSpecial ()
                             ("Semantic comment attempts to restore flag %s.  "
                              "A flag for setting a value cannot be restored.",
                              flagname),
-                            g_currentloc);
+                            loc);
                        }
                      else
                        { /* cut-and-pastied from llmain...blecch */
@@ -2112,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))
@@ -2122,12 +2217,15 @@ static int handleLlSpecial ()
                                 message
                                 ("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);
                                }
@@ -2137,6 +2235,7 @@ static int handleLlSpecial ()
                                }
                              else
                                {
+                                 cstring_free (extra);
                                  BADEXIT;
                                }
                            }
@@ -2159,7 +2258,7 @@ static int handleLlSpecial ()
       if (context_inHeader () && !isArtificial (cstring_fromChars (os)))
        {
          DPRINTF (("Here adding comment: %s", os));
-         context_addComment (cstring_fromCharsNew (os));
+         context_addComment (cstring_fromCharsNew (os), loc);
        }
       else
        {
@@ -2190,7 +2289,7 @@ static int handleLlSpecial ()
 
       if (macrocode != BADTOK)
        {
-         tokLength = hasnl ? 0 : mstring_length (t);
+         tokLength = hasnl ? 0 : size_toInt (mstring_length (t));
          
          sfree (t);
          sfree (os);
@@ -2227,8 +2326,14 @@ static int handleLlSpecial ()
              && macrocode != SKIPTOK
              && !isArtificial (cstring_fromChars (os))) 
            {
-             DPRINTF (("Add comment: %s", 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
            {
@@ -2245,7 +2350,7 @@ static int handleLlSpecial ()
        {
          if (!context_getFlag (FLG_NOCOMMENTS))
            {
-             context_enterSuppressRegion ();
+             context_enterSuppressRegion (loc);
            }
        }
       else if ((*t == 'i' || *t == 't')
@@ -2254,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'))
@@ -2273,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"))
@@ -2302,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++;
                }
@@ -2344,20 +2449,20 @@ static int handleLlSpecial ()
                             message
                             ("Non-abstract type %s used in access comment",
                              tname),
-                            g_currentloc);
+                            loc);
                        }
                    }
                  else
                    {
                      if (!(context_inSuppressRegion ()
-                           || context_inSuppressZone (g_currentloc)))
+                           || context_inSuppressZone (loc)))
                        {
                          voptgenerror
                            (FLG_COMMENTERROR,
                             message
                             ("Unrecognized type %s used in access comment",
                              tname),
-                            g_currentloc);
+                            loc);
                        }
                    }
                }
@@ -2380,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++;
                }
@@ -2415,7 +2520,7 @@ static int handleLlSpecial ()
                      else
                        {
                          if (!(context_inSuppressRegion () 
-                               || context_inSuppressZone (g_currentloc)))
+                               || context_inSuppressZone (loc)))
                            {
                              uentry ue = usymtab_getTypeEntry (tuid);
                              
@@ -2426,7 +2531,7 @@ static int handleLlSpecial ()
                                     message
                                     ("Non-accessible abstract type %s used in noaccess comment",
                                      tname),
-                                    g_currentloc);
+                                    loc);
                                }
                              else
                                {
@@ -2435,7 +2540,7 @@ static int handleLlSpecial ()
                                     message
                                     ("Non-abstract type %s used in noaccess comment",
                                      tname),
-                                    g_currentloc);
+                                    loc);
                                }
                            }
                        }
@@ -2443,14 +2548,14 @@ static int handleLlSpecial ()
                  else
                    {
                      if (!(context_inSuppressRegion () 
-                           || context_inSuppressZone (g_currentloc)))
+                           || context_inSuppressZone (loc)))
                        {
                          voptgenerror
                            (FLG_COMMENTERROR,
                             message
                             ("Unrecognized type %s used in noaccess comment",
                              tname),
-                            g_currentloc);
+                            loc);
                        }
                    }
                }
@@ -2470,9 +2575,10 @@ static int handleLlSpecial ()
        {
          voptgenerror (FLG_UNRECOGCOMMENTS, 
                        message ("Semantic comment unrecognized: %s", 
-                                cstring_fromChars (os)), loc);
+                                cstring_fromChars (os)),
+                       loc);
        }
-
+      
       sfree (t);
     }
   
@@ -2483,7 +2589,7 @@ static int handleLlSpecial ()
 
 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 == '$')) 
@@ -2536,9 +2642,26 @@ 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)
@@ -2551,12 +2674,14 @@ static int processIdentifier (cstring id)
     }
 
   context_clearJustPopped ();
-  lastidprocessed = id; 
+  cscanner_setLastIdentifier (id);
+
+  DPRINTF (("Context: %s", context_unparse ()));
 
   if (context_inFunctionHeader ())
     {
       int tok = commentMarkerToken (id);
-      DPRINTF (("in function decl..."));
+      DPRINTF (("in function decl: %s", id));
 
       if (tok != BADTOK)
        {
@@ -2565,7 +2690,7 @@ static int processIdentifier (cstring id)
       else 
        {
          tok = tokenMacroCode (id);
-
+         
          if (tok != BADTOK)
            {
              return tok;
@@ -2605,6 +2730,8 @@ static int processIdentifier (cstring id)
        }
     }
 
+  DPRINTF (("Here!"));
+
   /* Consider handling: Defined by C99 as static const char __func__[] */
 
   if (context_getFlag (FLG_GNUEXTENSIONS))
@@ -2637,6 +2764,14 @@ 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__")) 
        {
@@ -2663,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)
                        {
@@ -2693,7 +2829,7 @@ static int processIdentifier (cstring id)
                          depth++;
                        }
                    }
-                 else if (ic == '{')
+                 else if (cc == '{')
                    {
                      if (!usebraces)
                        {
@@ -2708,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"))
                    {
@@ -2730,9 +2866,17 @@ static int processIdentifier (cstring id)
                      */ 
                      return TRBRACE;
                    }
+                 else
+                   {
+                     ;
+                   }
+               }
+             else
+               {
+                 ;
                }
 
-             if (ic == '\n')
+             if (cc == '\n')
                {
                  context_incLineno ();
 
@@ -2744,8 +2888,8 @@ static int processIdentifier (cstring id)
                }
            }
          
-         llassert ((useparens && ic == ')')
-                   || (usebraces && ic == '}')
+         llassert ((useparens && ic == (int) ')')
+                   || (usebraces && ic == (int) '}')
                    || (!useparens && !usebraces));
 
          return BADTOK;
@@ -2757,6 +2901,10 @@ static int processIdentifier (cstring id)
        {
          tok = QINLINE;
        }
+      else
+       {
+         ;
+       }
       
       if (tok != BADTOK)
        {
@@ -2780,7 +2928,7 @@ static int processIdentifier (cstring id)
     }
   else if (uentry_isUndefined (le))
     {
-      yylval.cname = id;
+      yylval.cname = cstring_copy (id);
 
       /* avoid parse errors for certain system built ins */
 
@@ -2796,7 +2944,7 @@ static int processIdentifier (cstring id)
     {
       if (uentry_isDatatype (le))
        {
-         yylval.cname = id;
+         yylval.cname = cstring_copy (id);
          return (NEW_IDENTIFIER);
        }
       else
@@ -2809,7 +2957,7 @@ static int processIdentifier (cstring id)
     {
       if (!g_expectingTypeName)
        {
-         yylval.cname = id;
+         yylval.cname = cstring_copy (id);
 
          return (NEW_IDENTIFIER);
        }
@@ -2839,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))
        {
@@ -2863,7 +3011,7 @@ static bool processHashIdentifier (/*@only@*/ cstring id)
 }
 
 
-static /*@only@*/ exprNode processString ()
+static /*@only@*/ exprNode processString (void)
 {
   exprNode res;
   fileloc loc;
@@ -2873,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
     {
@@ -2914,7 +3062,7 @@ static /*@only@*/ exprNode processWideString ()
   if (nl == NULL)
     {
       loc = fileloc_copy (g_currentloc);
-      addColumn (cstring_length (ns));
+      addColumn (size_toInt (cstring_length (ns)));
     }
   else
     {
@@ -3076,18 +3224,36 @@ 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 ()
This page took 0.098702 seconds and 4 git commands to generate.