[cfe-commits] r62332 - in /cfe/trunk: include/clang/Lex/LiteralSupport.h lib/Lex/LiteralSupport.cpp lib/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Fri Jan 16 10:51:42 PST 2009


Author: lattner
Date: Fri Jan 16 12:51:42 2009
New Revision: 62332

URL: http://llvm.org/viewvc/llvm-project?rev=62332&view=rev
Log:
minor cleanups to StringLiteralParser: no need to pass target info
into its ctor.  Also, make it handle validity checking of pascal
strings instead of making clients do it.

Modified:
    cfe/trunk/include/clang/Lex/LiteralSupport.h
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=62332&r1=62331&r2=62332&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Fri Jan 16 12:51:42 2009
@@ -141,7 +141,6 @@
 /// literals) (C99 5.1.1.2p1).
 class StringLiteralParser {
   Preprocessor &PP;
-  TargetInfo &Target;
   
   unsigned MaxTokenLength;
   unsigned SizeBound;
@@ -150,7 +149,7 @@
   char *ResultPtr; // cursor
 public:
   StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
-                      Preprocessor &PP, TargetInfo &T);
+                      Preprocessor &PP);
   bool hadError;
   bool AnyWide;
   bool Pascal;

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=62332&r1=62331&r2=62332&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Fri Jan 16 12:51:42 2009
@@ -647,8 +647,7 @@
 ///
 StringLiteralParser::
 StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
-                    Preprocessor &pp, TargetInfo &t)
-  : PP(pp), Target(t) {
+                    Preprocessor &pp) : PP(pp) {
   // Scan all of the string portions, remember the max individual token length,
   // computing a bound on the concatenated string length, and see whether any
   // piece is a wide-string.  If any of the string portions is a wide-string
@@ -684,7 +683,7 @@
   // query the target.  As such, wchar_tByteWidth is only valid if AnyWide=true.
   wchar_tByteWidth = ~0U;
   if (AnyWide) {
-    wchar_tByteWidth = Target.getWCharWidth();
+    wchar_tByteWidth = PP.getTargetInfo().getWCharWidth();
     assert((wchar_tByteWidth & 7) == 0 && "Assumes wchar_t is byte multiple!");
     wchar_tByteWidth /= 8;
   }
@@ -787,6 +786,15 @@
     *ResultPtr++ = 0;
   }
     
-  if (Pascal) 
+  if (Pascal) {
     ResultBuf[0] = ResultPtr-&ResultBuf[0]-1;
+
+    // Verify that pascal strings aren't too large.
+    if (GetStringLength() > 256)
+      PP.Diag(StringToks[0].getLocation(), diag::err_pascal_string_too_long)
+        << SourceRange(StringToks[0].getLocation(),
+                       StringToks[NumStringToks-1].getLocation());
+    hadError = 1;
+    return;
+  }
 }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=62332&r1=62331&r2=62332&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jan 16 12:51:42 2009
@@ -295,7 +295,7 @@
 Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) {
   assert(NumStringToks && "Must have at least one string!");
 
-  StringLiteralParser Literal(StringToks, NumStringToks, PP, Context.Target);
+  StringLiteralParser Literal(StringToks, NumStringToks, PP);
   if (Literal.hadError)
     return ExprResult(true);
 
@@ -303,12 +303,6 @@
   for (unsigned i = 0; i != NumStringToks; ++i)
     StringTokLocs.push_back(StringToks[i].getLocation());
 
-  // Verify that pascal strings aren't too large.
-  if (Literal.Pascal && Literal.GetStringLength() > 256)
-    return Diag(StringToks[0].getLocation(), diag::err_pascal_string_too_long)
-      << SourceRange(StringToks[0].getLocation(),
-                     StringToks[NumStringToks-1].getLocation());
-  
   QualType StrTy = Context.CharTy;
   if (Literal.AnyWide) StrTy = Context.getWCharType();
   if (Literal.Pascal) StrTy = Context.UnsignedCharTy;





More information about the cfe-commits mailing list