]> andersk Git - splint.git/commitdiff
Fixed handling of wide character strings (L"test").
authorevans1629 <evans1629>
Mon, 31 Dec 2001 04:24:37 +0000 (04:24 +0000)
committerevans1629 <evans1629>
Mon, 31 Dec 2001 04:24:37 +0000 (04:24 +0000)
src/Headers/exprNode.h
src/Headers/lctype.h
src/cscanner.l
src/ctype.c
src/exprNode.c
src/maketags
test/Makefile.am
test/Makefile.in
test/widestrings.c [new file with mode: 0644]
test/widestrings.expect [new file with mode: 0644]

index a004add04b0e0a4a809c279a62d519263f5fb371..69fb4ca9fd1a953b9a62c0ef41f04d5214ebc8b2 100644 (file)
@@ -278,6 +278,9 @@ extern exprNode
 extern exprNode 
   exprNode_stringLiteral (/*@only@*/ cstring p_t, /*@only@*/ fileloc p_loc) /*@*/ ;
 
+extern /*@only@*/ exprNode
+  exprNode_wideStringLiteral (/*@only@*/ cstring p_t, /*@only@*/ fileloc p_loc) /*@*/ ;
+
 /*
 ** No surrounding quotes.
 */
index f563c8136bb734612ea6e9b8ea586b053097222b..34b17773998e7add53d47848e284f8c882e8c916 100644 (file)
@@ -264,6 +264,8 @@ extern ctype ctype_makeFunction (ctype p_base, /*@only@*/ uentryList p_p) /*@*/
 extern ctype ctype_makeNFParamsFunction (ctype p_base, /*@only@*/ uentryList p_p) /*@*/ ;
 extern ctype ctype_makePointer (ctype p_c);
 extern ctype ctype_makeRawFunction (ctype p_base, /*@only@*/ uentryList p_p);
+extern ctype ctype_makeWideString (void) /*@modifies internalState@*/ ;
+extern bool ctype_isWideString (ctype p_c) /*@*/ ;
 
 extern ctype ctype_newBase (ctype p_c, ctype p_p) /*@*/ ;
 extern ctype ctype_realType (ctype p_c) /*@*/ ;
index eddfd1d88c91147a453a369bf848e03faa483545..b519f7958015ed1ff7ca29d5c688219568b77da6 100644 (file)
@@ -95,7 +95,8 @@ 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);
@@ -272,7 +273,7 @@ static void setTokLengthT (size_t len)
 "static"       { setTokLength (6); RETURN_TOK (QSTATIC); }
 
 \"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processString ()); }
-L\"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processString ()); }
+L\"(\\.|[^\\"])*\"([ \t\n]*\"(\\.|[^\\"])*\")* { RETURN_EXPR (processWideString ()); }
 "out"                   { return (processSpec (QOUT)); }
 "in"                    { return (processSpec (QIN)); }
 "partial"               { return (processSpec (QPARTIAL)); }
@@ -2894,6 +2895,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 (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 ()
 {
index 0c5778c27b998cdc62fa90804e5097a11a17e8b6..afc38f875f677a5725023be6005ed7975eeeec0f 100644 (file)
@@ -381,6 +381,56 @@ ctype_baseArrayPtr (ctype c)
     }
 }
 
+/*
+** wchar_t *
+*/
+
+ctype 
+ctype_makeWideString ()
+{
+  static ctype res = ctype_unknown;
+
+  if (ctype_isUnknown (res))
+    {
+      ctype wchart;
+
+      if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
+       {
+         wchart = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t")));
+       }
+      else
+       {
+         wchart = ctype_char;
+       }
+      
+      res = ctype_makePointer (wchart);
+    }
+  
+  return res;
+}
+
+bool
+ctype_isWideString (ctype c)
+{
+  if (ctype_isPointer (c))
+    {
+      ctype ct = ctype_baseArrayPtr (c);
+      
+      if (usymtab_existsType (cstring_makeLiteralTemp ("wchar_t")))
+       {
+         return (ct == uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("wchar_t"))));
+       }
+      else
+       {
+         return FALSE;
+       }
+    }
+  else
+    {
+      return FALSE;
+    }
+}
+
 ctype
 ctype_getReturnType (ctype c)
 {
index 3547de0cef9c1b8e17d1691bafc2e38cb0b19b2d..ca9c7672f522c12519dc4d92d82d5cd1b5de5152 100644 (file)
@@ -843,6 +843,15 @@ exprNode_rawStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
   return (e); /* s released */
 }
 
+/*@only@*/ exprNode
+exprNode_wideStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
+{
+  exprNode res = exprNode_stringLiteral (t, loc);
+  res->typ = ctype_makeWideString ();
+
+  return res;
+}
+
 /*@only@*/ exprNode
 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
 {
@@ -4702,7 +4711,7 @@ ctype sizeof_resultType (void)
        }
       else
        {
-                 sizet = ctype_ulint;
+         sizet = ctype_ulint;
        }
     }
   return sizet;
@@ -9316,7 +9325,14 @@ static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
       break;
 
     case XPR_STRINGLITERAL:
-      ret = message ("\"%s\"", exprData_getLiteral (data));
+      if (ctype_isWideString (e->typ))
+       {
+         ret = message ("L\"%s\"", exprData_getLiteral (data));
+       }
+      else
+       {
+         ret = message ("\"%s\"", exprData_getLiteral (data));
+       }
       break;
 
     case XPR_NUMLIT:
index 6b415591a0f95beefb01005ce866c835b0b3ff2a..beab1b086375d1522c1fcb56e2c3171852d914f2 100755 (executable)
@@ -1,4 +1,4 @@
 #!/bin/sh
 
-etags *.y Headers/* *.c  *.l  *.i || echo "Error creating TAGS file (ignoring)"
+etags *.y  *.l *.c *.i Headers/* || echo "Error creating TAGS file (ignoring)"
 
index 28bd1ad64153ae6bd28d9877cb0a275a958ddde6..4e26591bfc5e0ed48def378dcb428b6dd8c096f8 100644 (file)
@@ -52,7 +52,7 @@ UNITTESTS = \
   postnotnull preds prefixes printflike rc refcounts release repexpose \
   returned sharing slovaknames specclauses special stack staticarray strings \
   structassign typequals ud ulstypes union unioninit unreachable unsignedcompare \
-  unused ullint utypes void
+  unused ullint utypes void widestrings
 UNITEXPECTS = $(addsuffix .expect, $(UNITTESTS))
 
 INTEGTESTS = db1 db2 db3
@@ -761,6 +761,14 @@ utypes:
 void:
        ${SPLINTRN} void.c -expect 2
 
+###
+### 2001-12-30: Problems with wide character strings reported by Nelson Beebe
+###
+
+.PHONY: widestrings
+widestrings:
+       ${SPLINTRN} widestrings.c -expect 2
+
 ###
 ### New since 2.5q:
 ###
index 342691e6f8b34e55f550bb0b71dcd4cf303c250a..c75fc3e7ae795774ac85fb6ef7da77a8e5b1d2c5 100644 (file)
@@ -121,7 +121,7 @@ UNITTESTS = \
   postnotnull preds prefixes printflike rc refcounts release repexpose \
   returned sharing slovaknames specclauses special stack staticarray strings \
   structassign typequals ud ulstypes union unioninit unreachable unsignedcompare \
-  unused ullint utypes void
+  unused ullint utypes void widestrings
 
 UNITEXPECTS = $(addsuffix .expect, $(UNITTESTS))
 
@@ -1569,6 +1569,14 @@ utypes:
 void:
        ${SPLINTRN} void.c -expect 2
 
+###
+### 2001-12-30: Problems with wide character strings reported by Nelson Beebe
+###
+
+.PHONY: widestrings
+widestrings:
+       ${SPLINTRN} widestrings.c -expect 2
+
 ###
 ### New since 2.5q:
 ###
diff --git a/test/widestrings.c b/test/widestrings.c
new file mode 100644 (file)
index 0000000..db55347
--- /dev/null
@@ -0,0 +1,17 @@
+/* Provided by Nelson Beebe */
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+int main(void) 
+{
+  (void)wprintf(L"English:  Hello, world!\n");
+  (void)printf(L"English:  Hello, world!\n"); /* error */
+  (void)wprintf("English:  Hello, world!\n"); /* error */
+  
+  (void)wprintf(L"Russian:  Ð^×аÑ^ÀегиÑ^ÁÑ^ÂÑ^ÀиÑ^ÀÑ^ÃйÑ^ÂеÑ^ÁÑ^Ì Ñ^ÁейÑ^ÇаÑ^Á Ð½Ð° Ð^ÔеÑ^ÁÑ^ÏÑ^ÂÑ^ÃÑ^ΠÐ^ÜеждÑ^ÃнаÑ^ÀоднÑ^ÃÑ^ΠÐ^ÚонÑ^ÄеÑ^ÀенÑ^ÆиÑ^Î...\n");
+  (void)wprintf(L"Greek:    Î£á½² Î³Î½Ï^ÉÏ^ÁίζÏ^É á¼^ÀÏ^Àὸ Ï^Äὴν Îºá½¹Ï^Èη...\n");
+  (void)wprintf(L"Georgian: á^Ã^Òá^Ã^×á^îá^Ã^Ýá^Ã^Õá^Ã^× á^Ã^Ðá^îá^Ã^Úá^Ã^Ðá^Ã^Õá^Ã^Ô á^Ã^Òá^Ã^Ðá^Ã^Øá^Ã^Ðá^àá^Ã^Ýá^Ã^× á^àá^Ã^Ôá^Ã^Òá^Ã^Øá^áá^âá^àá^Ã^Ðá^êá^Ã^Øá^Ã^РUnicode-á^Ã^Øá^á á^Ã^Ûá^Ã^Ôá^Ã^Ðá^Ã^×á^Ã^Ô á^áá^Ã^Ðá^Ã^Ôá^àá^Ã^×á^Ã^Ðá^èá^Ã^Ýá^àá^Ã^Øá^áá^Ã^Ý\n");
+  return (EXIT_SUCCESS);
+}
+
diff --git a/test/widestrings.expect b/test/widestrings.expect
new file mode 100644 (file)
index 0000000..03c7fa9
--- /dev/null
@@ -0,0 +1,8 @@
+
+widestrings.c: (in function main)
+widestrings.c:9:16: Function printf expects arg 1 to be char * gets wchar_t *:
+                       L"English:  Hello, world!\n"
+widestrings.c:10:17: Function wprintf expects arg 1 to be wchar_t * gets char
+                        *: "English:  Hello, world!\n"
+
+Finished checking --- 2 code warnings, as expected
This page took 0.976151 seconds and 5 git commands to generate.