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

Chris Lattner sabre at nondot.org
Tue Nov 16 22:55:10 PST 2010


Author: lattner
Date: Wed Nov 17 00:55:10 2010
New Revision: 119472

URL: http://llvm.org/viewvc/llvm-project?rev=119472&view=rev
Log:
add a static version of PP::AdvanceToTokenCharacter.

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

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=119472&r1=119471&r2=119472&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Nov 17 00:55:10 2010
@@ -727,7 +727,15 @@
 
   /// AdvanceToTokenCharacter - Given a location that specifies the start of a
   /// token, return a new location that specifies a character within the token.
-  SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart,unsigned Char);
+  SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart,
+                                         unsigned Char) const {
+    return AdvanceToTokenCharacter(FullSourceLoc(TokStart, SourceMgr), Char,
+                                   Features);
+  }
+  static FullSourceLoc AdvanceToTokenCharacter(FullSourceLoc TokStart,
+                                               unsigned Char,
+                                               const LangOptions &Features);
+
 
   /// IncrementPasteCounter - Increment the counters for the number of token
   /// paste operations performed.  If fast was specified, this is a 'fast paste'

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=119472&r1=119471&r2=119472&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Wed Nov 17 00:55:10 2010
@@ -167,11 +167,10 @@
 /// return the UTF32.
 static bool ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
                              uint32_t &UcnVal, unsigned short &UcnLen,
-                             SourceLocation Loc, Preprocessor &PP,
-                             Diagnostic *Diags, 
+                             FullSourceLoc Loc, Diagnostic *Diags, 
                              const LangOptions &Features) {
   if (!Features.CPlusPlus && !Features.C99 && Diags)
-    PP.Diag(Loc, diag::warn_ucn_not_valid_in_c89);
+    Diags->Report(Loc, diag::warn_ucn_not_valid_in_c89);
 
   // Save the beginning of the string (for error diagnostics).
   const char *ThisTokBegin = ThisTokBuf;
@@ -181,7 +180,7 @@
 
   if (ThisTokBuf == ThisTokEnd || !isxdigit(*ThisTokBuf)) {
     if (Diags)
-      PP.Diag(Loc, diag::err_ucn_escape_no_digits);
+      Diags->Report(Loc, diag::err_ucn_escape_no_digits);
     return false;
   }
   UcnLen = (ThisTokBuf[-1] == 'u' ? 4 : 8);
@@ -194,9 +193,11 @@
   }
   // If we didn't consume the proper number of digits, there is a problem.
   if (UcnLenSave) {
-    if (Diags)
-      PP.Diag(PP.AdvanceToTokenCharacter(Loc, ThisTokBuf-ThisTokBegin),
-              diag::err_ucn_escape_incomplete);
+    if (Diags) {
+      Loc = Preprocessor::AdvanceToTokenCharacter(Loc, ThisTokBuf-ThisTokBegin,
+                                                  Features);
+      Diags->Report(Loc, diag::err_ucn_escape_incomplete);
+    }
     return false;
   }
   // Check UCN constraints (C99 6.4.3p2).
@@ -205,7 +206,7 @@
       || (UcnVal >= 0xD800 && UcnVal <= 0xDFFF)
       || (UcnVal > 0x10FFFF)) /* the maximum legal UTF32 value */ {
     if (Diags)
-      PP.Diag(Loc, diag::err_ucn_escape_invalid);
+      Diags->Report(Loc, diag::err_ucn_escape_invalid);
     return false;
   }
   return true;
@@ -222,7 +223,8 @@
   typedef uint32_t UTF32;
   UTF32 UcnVal = 0;
   unsigned short UcnLen = 0;
-  if (!ProcessUCNEscape(ThisTokBuf, ThisTokEnd, UcnVal, UcnLen, Loc, PP,
+  if (!ProcessUCNEscape(ThisTokBuf, ThisTokEnd, UcnVal, UcnLen,
+                        FullSourceLoc(Loc, PP.getSourceManager()),
                         Complain ? &PP.getDiagnostics() : 0,
                         PP.getLangOptions())){
     HadError = 1;
@@ -724,7 +726,8 @@
       if (begin[1] == 'u' || begin[1] == 'U') {
         uint32_t utf32 = 0;
         unsigned short UcnLen = 0;
-        if (!ProcessUCNEscape(begin, end, utf32, UcnLen, Loc, PP,
+        if (!ProcessUCNEscape(begin, end, utf32, UcnLen,
+                              FullSourceLoc(Loc, PP.getSourceManager()),
                               &PP.getDiagnostics(), PP.getLangOptions())) {
           HadError = 1;
         }

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=119472&r1=119471&r2=119472&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Nov 17 00:55:10 2010
@@ -431,13 +431,14 @@
 
 /// AdvanceToTokenCharacter - Given a location that specifies the start of a
 /// token, return a new location that specifies a character within the token.
-SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart,
-                                                     unsigned CharNo) {
+FullSourceLoc Preprocessor::AdvanceToTokenCharacter(FullSourceLoc TokStart,
+                                                    unsigned CharNo,
+                                                  const LangOptions &Features) {
   // Figure out how many physical characters away the specified instantiation
   // character is.  This needs to take into consideration newlines and
   // trigraphs.
   bool Invalid = false;
-  const char *TokPtr = SourceMgr.getCharacterData(TokStart, &Invalid);
+  const char *TokPtr = TokStart.getCharacterData(&Invalid);
 
   // If they request the first char of the token, we're trivially done.
   if (Invalid || (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr)))
@@ -450,7 +451,8 @@
   // chars, this method is extremely fast.
   while (Lexer::isObviouslySimpleCharacter(*TokPtr)) {
     if (CharNo == 0)
-      return TokStart.getFileLocWithOffset(PhysOffset);
+      return FullSourceLoc(TokStart.getFileLocWithOffset(PhysOffset),
+                           TokStart.getManager());
     ++TokPtr, --CharNo, ++PhysOffset;
   }
 
@@ -470,7 +472,8 @@
   if (!Lexer::isObviouslySimpleCharacter(*TokPtr))
     PhysOffset += Lexer::SkipEscapedNewLines(TokPtr)-TokPtr;
 
-  return TokStart.getFileLocWithOffset(PhysOffset);
+  return FullSourceLoc(TokStart.getFileLocWithOffset(PhysOffset),
+                       TokStart.getManager());
 }
 
 SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc,





More information about the cfe-commits mailing list