[cfe-commits] r119475 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Lex/LiteralSupport.cpp

Chris Lattner sabre at nondot.org
Tue Nov 16 23:12:42 PST 2010


Author: lattner
Date: Wed Nov 17 01:12:42 2010
New Revision: 119475

URL: http://llvm.org/viewvc/llvm-project?rev=119475&view=rev
Log:
push the preprocessor out of EncodeUCNEscape


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

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=119475&r1=119474&r2=119475&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Nov 17 01:12:42 2010
@@ -734,7 +734,6 @@
     return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, Features);
   }
 
-
   /// IncrementPasteCounter - Increment the counters for the number of token
   /// paste operations performed.  If fast was specified, this is a 'fast paste'
   /// case we handled.

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=119475&r1=119474&r2=119475&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Wed Nov 17 01:12:42 2010
@@ -219,26 +219,23 @@
 /// StringLiteralParser. When we decide to implement UCN's for identifiers,
 /// we will likely rework our support for UCN's.
 static void EncodeUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
-                             char *&ResultBuf, bool &HadError,
-                             SourceLocation Loc, Preprocessor &PP,
-                             bool wide, bool Complain) {
+                            char *&ResultBuf, bool &HadError,
+                            FullSourceLoc Loc, bool wide, Diagnostic *Diags, 
+                            const LangOptions &Features) {
   typedef uint32_t UTF32;
   UTF32 UcnVal = 0;
   unsigned short UcnLen = 0;
-  if (!ProcessUCNEscape(ThisTokBuf, ThisTokEnd, UcnVal, UcnLen,
-                        FullSourceLoc(Loc, PP.getSourceManager()),
-                        Complain ? &PP.getDiagnostics() : 0,
-                        PP.getLangOptions())){
+  if (!ProcessUCNEscape(ThisTokBuf, ThisTokEnd, UcnVal, UcnLen, Loc, Diags,
+                        Features)) {
     HadError = 1;
     return;
   }
 
   if (wide) {
     (void)UcnLen;
-    assert((UcnLen== 4 || UcnLen== 8) && 
-           "EncodeUCNEscape - only ucn length of 4 or 8 supported");
+    assert((UcnLen== 4 || UcnLen== 8) && "only ucn length of 4 or 8 supported");
 
-    if (!PP.getLangOptions().ShortWChar) {
+    if (!Features.ShortWChar) {
       // Note: our internal rep of wide char tokens is always little-endian.
       *ResultBuf++ = (UcnVal & 0x000000FF);
       *ResultBuf++ = (UcnVal & 0x0000FF00) >> 8;
@@ -253,7 +250,7 @@
       *ResultBuf++ = (UcnVal & 0x0000FF00) >> 8;
       return;
     }
-    PP.Diag(Loc, diag::warn_ucn_escape_too_large);
+    if (Diags) Diags->Report(Loc, diag::warn_ucn_escape_too_large);
 
     typedef uint16_t UTF16;
     UcnVal -= 0x10000;
@@ -867,7 +864,7 @@
   // query the target.  As such, wchar_tByteWidth is only valid if AnyWide=true.
   wchar_tByteWidth = ~0U;
   if (AnyWide) {
-    wchar_tByteWidth = PP.getTargetInfo().getWCharWidth();
+    wchar_tByteWidth = Target.getWCharWidth();
     assert((wchar_tByteWidth & 7) == 0 && "Assumes wchar_t is byte multiple!");
     wchar_tByteWidth /= 8;
   }
@@ -917,7 +914,7 @@
     ++ThisTokBuf;
 
     // Check if this is a pascal string
-    if (pp.getLangOptions().PascalStrings && ThisTokBuf + 1 != ThisTokEnd &&
+    if (Features.PascalStrings && ThisTokBuf + 1 != ThisTokEnd &&
         ThisTokBuf[0] == '\\' && ThisTokBuf[1] == 'p') {
 
       // If the \p sequence is found in the first token, we have a pascal string
@@ -956,8 +953,8 @@
       // Is this a Universal Character Name escape?
       if (ThisTokBuf[1] == 'u' || ThisTokBuf[1] == 'U') {
         EncodeUCNEscape(ThisTokBuf, ThisTokEnd, ResultPtr,
-                        hadError, StringToks[i].getLocation(), PP, wide, 
-                        Complain);
+                        hadError, FullSourceLoc(StringToks[i].getLocation(),SM),
+                        wide, Diags, Features);
         continue;
       }
       // Otherwise, this is a non-UCN escape character.  Process it.
@@ -991,16 +988,12 @@
     }
   } else if (Complain) {
     // Complain if this string literal has too many characters.
-    unsigned MaxChars = PP.getLangOptions().CPlusPlus? 65536
-                      : PP.getLangOptions().C99 ? 4095
-                      : 509;
+    unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
     
     if (GetNumStringChars() > MaxChars)
       PP.Diag(StringToks[0].getLocation(), diag::ext_string_too_long)
         << GetNumStringChars() << MaxChars
-        << (PP.getLangOptions().CPlusPlus? 2
-            : PP.getLangOptions().C99 ? 1
-            : 0)
+        << (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
         << SourceRange(StringToks[0].getLocation(),
                        StringToks[NumStringToks-1].getLocation());
   }





More information about the cfe-commits mailing list