]> andersk Git - splint.git/blobdiff - src/cpplib.c
noexpand always false.
[splint.git] / src / cpplib.c
index fbbf3ad09cda75d9fda403d031fd49520e7e2b58..a18e1218508ead358c1919c33bf3ae358f2ae465 100644 (file)
@@ -70,7 +70,11 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # include <fcntl.h>
 # if defined (WIN32) || defined (OS2) && defined (__IBMC__)
 # include <io.h>
+/* SMF */
+# ifndef BCC32
 # include <sys/utime.h>                /* for __DATE__ and __TIME__ */
+# endif
+
 # include <time.h>
 # else
 # ifndef VMS
@@ -356,6 +360,8 @@ static void cppReader_scanBuffer (cppReader *p_pfile);
 
 # if defined (WIN32) || defined (OS2) && defined (__IBMC__)
 
+/* SMF */
+# ifndef BCC32
 /*
 ** WIN32 (at least the VC++ include files) does not define mode_t.
 */
@@ -363,6 +369,7 @@ static void cppReader_scanBuffer (cppReader *p_pfile);
 /*@-incondefs@*/ /*@-czechtypes@*/
 typedef unsigned int mode_t;
 /*@=incondefs@*/ /*@=czechtypes@*/
+# endif
 
 # endif
 
@@ -963,6 +970,9 @@ cppOptions_init (cppOptions *opts)
   opts->warn_comments = 0;
   opts->warnings_are_errors = 0;
 
+  /* Added 2003-07-10: */
+  opts->traditional = FALSE;
+  opts->c89 = TRUE;
   initialize_char_syntax (opts);
 }
 
@@ -1553,6 +1563,7 @@ collect_expansion (cppReader *pfile, char *buf, char *limit,
   defn->predefined = NULL;
 
   exp_p = defn->expansion = (char *) defn + sizeof (*defn);
+  *defn->expansion = '\0'; /* convince splint it is initialized */
 
   defn->line = 0;
   defn->rest_args = NULL;
@@ -1820,7 +1831,7 @@ collect_expansion (cppReader *pfile, char *buf, char *limit,
       llfatalbug (cstring_makeLiteral ("Maximum definition size exceeded."));
     }
 
-  return defn;
+  return defn; /* Spurious warning here */
 }
 
 /*
@@ -1884,7 +1895,6 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
   defn->pattern = NULL;
   defn->nargs = nargs;
   defn->predefined = NULL;
-
   exp_p = defn->expansion = (char *) defn + sizeof (*defn);
 
   defn->line = 0;
@@ -2166,8 +2176,10 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
     {
       llfatalbug (cstring_makeLiteral ("Maximum definition size exceeded."));
     }
-
-  return defn;
+  
+  /*@-compdef@*/ /* defn->expansion defined? */
+  return defn; 
+  /*@=compdef@*/
 }
 
 /*
@@ -2835,7 +2847,7 @@ do_defineAux (cppReader *pfile, struct directive *keyword,
       else if (hp->type == T_CONST)
        ok = !CPPOPTIONS (pfile)->done_initializing;
       else {
-       BADBRANCH;
+       ok = FALSE; /* Redefining anything else is bad. */
       }
 
       /* Print the warning if it's not ok.  */
@@ -3726,18 +3738,11 @@ initialize_builtins (cppReader *pfile)
   cpplib_installBuiltin ("__REGISTER_PREFIX__", ctype_string, -1, T_REGISTER_PREFIX_TYPE, 0, NULL, -1);
   cpplib_installBuiltin ("__TIME__", ctype_string, -1, T_TIME, 0, NULL, -1);
 
-  /*
-  ** No, don't define __STDC__
-  **
-
   if (!cppReader_isTraditional (pfile))
     {
       cpplib_installBuiltin ("__STDC__", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
     }
 
-  **
-  */
-
 # ifdef WIN32
     cpplib_installBuiltin ("_WIN32", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
 # endif
@@ -3755,7 +3760,9 @@ initialize_builtins (cppReader *pfile)
   /*drl 1/9/2001/ try to define the right symbol for the architecture
     We use autoconf to determine the target cpu 
    */
+# ifndef S_SPLINT_S
   cpplib_installBuiltin ("__" TARGET_CPU, ctype_int, -1, T_CONST, 2, NULL, -1);
+# endif
 
   /*drl 1/2/2002  set some flags based on uname
     I'd like to be able to do this with autoconf macro instead...
@@ -6208,6 +6215,8 @@ get_next:
                      if (cc == '\n')
                        {
                          /* Backslash newline is replaced by nothing at all.  */
+                         pfile->lineno++; /* 2003-11-03: AMiller suggested adding this, but
+                                             its not clear why it is needed. */
                          cppReader_adjustWritten (pfile, -1);
                          pfile->lineno++;
                        }
@@ -6394,10 +6403,20 @@ get_next:
        op2:
          token = CPP_OTHER;
          pfile->only_seen_white = 0;
-        op2any:
+        op2any: /* jumped to for \ continuations */
          cpplib_reserve(pfile, 3);
          cppReader_putCharQ (pfile, c);
-         cppReader_putCharQ (pfile, cppReader_getC (pfile));
+
+         /* evans 2003-08-24: This is a hack to fix line output for \
+            continuations.  Someday I really should get a decent pre-processor! 
+         */
+
+         if (c == '\\') {
+           (void) cppReader_getC (pfile); /* skip the newline to avoid extra lines */
+         } else {
+           cppReader_putCharQ (pfile, cppReader_getC (pfile)); 
+         }
+
          cppReader_nullTerminateQ (pfile);
          return token;
 
@@ -6663,6 +6682,8 @@ get_next:
 
         case '\\':
          c2 = cppReader_peekC (pfile);
+         /* allow other stuff here if a flag is set? */
+         DPRINTF (("Got continuation!"));
          if (c2 != '\n')
            goto randomchar;
          token = CPP_HSPACE;
@@ -7055,7 +7076,7 @@ finclude (cppReader *pfile, int f,
          bool system_header_p,
          /*@dependent@*/ struct file_name_list *dirptr)
 {
-  mode_t st_mode;
+  mode_t st_mode; /* was __mode_t */
   size_t st_size;
   long i;
   int length = 0;
@@ -7265,12 +7286,16 @@ file_size_and_mode (int fd, mode_t *mode_pointer, size_t *size_pointer)
   if (fstat (fd, &sbuf) < 0) {
     *mode_pointer = 0;
     *size_pointer = 0;
+    /*@-compdestroy@*/ /* possibly spurious warnings here (or memory leak) */
     return (-1);
+    /*@=compdestroy@*/
   }
 
   if (mode_pointer != NULL)
     {
+      /*@-type@*/ /* confusion between __mode_t and mode_t types */
       *mode_pointer = sbuf.st_mode;
+      /*@=type@*/
     }
 
   if (size_pointer != NULL)
@@ -7278,7 +7303,9 @@ file_size_and_mode (int fd, mode_t *mode_pointer, size_t *size_pointer)
       *size_pointer = (size_t) sbuf.st_size;
     }
 
+  /*@-compdestroy@*/ /* possibly spurious warnings here (or memory leak) */
   return 0;
+  /*@=compdestroy@*/
 }
 
 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
@@ -7385,7 +7412,7 @@ parseMoveMark (struct parse_marker *pmark, cppReader *pfile)
     }
 
   pmark->position = pbuf->cur - pbuf->buf;
-  DPRINTF (("move mark: %s", pmark->position));
+  DPRINTF (("move mark: %d", pmark->position));
 }
 
 void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is loaded. */
@@ -7838,7 +7865,6 @@ static bool cpp_shouldCheckMacro (cppReader *pfile, char *p) /*@modifies p*/
 {
   bool checkmacro = FALSE;
   bool hasParams = FALSE;
-  bool noexpand = FALSE;
   cstring sname;
   char c;
 
@@ -7914,17 +7940,6 @@ static bool cpp_shouldCheckMacro (cppReader *pfile, char *p) /*@modifies p*/
     }
   else
     {
-      if (noexpand)
-       {
-         checkmacro = TRUE;
-
-         if (!expectenditer)
-           {
-             noexpand = FALSE;
-           }
-       }
-      else
-       {
          if (usymtab_existsReal (sname))
            {
              uentry ue = usymtab_lookup (sname);
@@ -8079,7 +8094,6 @@ static bool cpp_shouldCheckMacro (cppReader *pfile, char *p) /*@modifies p*/
                  incLine ();
                }
            }
-       }
     }
 
   if (!checkmacro)
This page took 0.040763 seconds and 4 git commands to generate.