[cfe-commits] r134644 - in /cfe/trunk: include/clang/Basic/SourceManager.h include/clang/Lex/Lexer.h include/clang/Lex/Preprocessor.h lib/ARCMigrate/TransformActions.cpp lib/ARCMigrate/Transforms.cpp lib/Basic/SourceManager.cpp lib/Lex/Lexer.cpp lib/Parse/ParseExpr.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Jul 7 14:54:45 PDT 2011


Author: akirtzidis
Date: Thu Jul  7 16:54:45 2011
New Revision: 134644

URL: http://llvm.org/viewvc/llvm-project?rev=134644&view=rev
Log:
Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the Lexer, since they depend on it now.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/include/clang/Lex/Lexer.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/ARCMigrate/TransformActions.cpp
    cfe/trunk/lib/ARCMigrate/Transforms.cpp
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Parse/ParseExpr.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Thu Jul  7 16:54:45 2011
@@ -832,16 +832,6 @@
     return getFileCharacteristic(Loc) == SrcMgr::C_ExternCSystem;
   }
 
-  /// \brief Returns true if the given MacroID location points at the first
-  /// token of the macro instantiation.
-  bool isAtStartOfMacroInstantiation(SourceLocation Loc,
-                                     const LangOptions &LangOpts) const;
-
-  /// \brief Returns true if the given MacroID location points at the last
-  /// token of the macro instantiation.
-  bool isAtEndOfMacroInstantiation(SourceLocation Loc,
-                                   const LangOptions &LangOpts) const;
-
   /// \brief Given a specific chunk of a FileID (FileID with offset+length),
   /// returns true if \arg Loc is inside that chunk and sets relative offset
   /// (offset of \arg Loc from beginning of chunk) to \arg relativeOffset.

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Thu Jul  7 16:54:45 2011
@@ -293,7 +293,19 @@
   static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset,
                                             const SourceManager &SM,
                                             const LangOptions &Features);
-    
+
+  /// \brief Returns true if the given MacroID location points at the first
+  /// token of the macro instantiation.
+  static bool isAtStartOfMacroInstantiation(SourceLocation loc,
+                                            const SourceManager &SM,
+                                            const LangOptions &LangOpts);
+
+  /// \brief Returns true if the given MacroID location points at the last
+  /// token of the macro instantiation.
+  static bool isAtEndOfMacroInstantiation(SourceLocation loc,
+                                          const SourceManager &SM,
+                                          const LangOptions &LangOpts);
+
   /// \brief Compute the preamble of the given file.
   ///
   /// The preamble of a file contains the initial comments, include directives,

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Jul  7 16:54:45 2011
@@ -753,6 +753,18 @@
     return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, Features);
   }
 
+  /// \brief Returns true if the given MacroID location points at the first
+  /// token of the macro instantiation.
+  bool isAtStartOfMacroInstantiation(SourceLocation loc) const {
+    return Lexer::isAtStartOfMacroInstantiation(loc, SourceMgr, Features);
+  }
+
+  /// \brief Returns true if the given MacroID location points at the last
+  /// token of the macro instantiation.
+  bool isAtEndOfMacroInstantiation(SourceLocation loc) const {
+    return Lexer::isAtEndOfMacroInstantiation(loc, SourceMgr, Features);
+  }
+
   /// DumpToken - Print the token to stderr, used for debugging.
   ///
   void DumpToken(const Token &Tok, bool DumpFlags = false) const;

Modified: cfe/trunk/lib/ARCMigrate/TransformActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransformActions.cpp?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransformActions.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransformActions.cpp Thu Jul  7 16:54:45 2011
@@ -388,7 +388,7 @@
 
   if (loc.isFileID())
     return true;
-  return SM.isAtStartOfMacroInstantiation(loc, Ctx.getLangOptions());
+  return PP.isAtStartOfMacroInstantiation(loc);
 }
 
 bool TransformActionsImpl::canInsertAfterToken(SourceLocation loc) {
@@ -401,7 +401,7 @@
 
   if (loc.isFileID())
     return true;
-  return SM.isAtEndOfMacroInstantiation(loc, Ctx.getLangOptions());
+  return PP.isAtEndOfMacroInstantiation(loc);
 }
 
 bool TransformActionsImpl::canRemoveRange(SourceRange range) {

Modified: cfe/trunk/lib/ARCMigrate/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.cpp?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Transforms.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/Transforms.cpp Thu Jul  7 16:54:45 2011
@@ -37,7 +37,7 @@
                                             ASTContext &Ctx) {
   SourceManager &SM = Ctx.getSourceManager();
   if (loc.isMacroID()) {
-    if (!SM.isAtEndOfMacroInstantiation(loc, Ctx.getLangOptions()))
+    if (!Lexer::isAtEndOfMacroInstantiation(loc, SM, Ctx.getLangOptions()))
       return SourceLocation();
     loc = SM.getInstantiationRange(loc).second;
   }

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Thu Jul  7 16:54:45 2011
@@ -11,7 +11,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Lex/Lexer.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceManagerInternals.h"
 #include "clang/Basic/Diagnostic.h"
@@ -1215,60 +1214,6 @@
   return PresumedLoc(Filename, LineNo, ColNo, IncludeLoc);
 }
 
-/// \brief Returns true if the given MacroID location points at the first
-/// token of the macro instantiation.
-bool SourceManager::isAtStartOfMacroInstantiation(SourceLocation loc,
-                                            const LangOptions &LangOpts) const {
-  assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
-
-  std::pair<FileID, unsigned> infoLoc = getDecomposedLoc(loc);
-  // FIXME: If the token comes from the macro token paste operator ('##')
-  // this function will always return false;
-  if (infoLoc.second > 0)
-    return false; // Does not point at the start of token.
-
-  SourceLocation instLoc = 
-      getSLocEntry(infoLoc.first).getInstantiation().getInstantiationLocStart();
-  if (instLoc.isFileID())
-    return true; // No other macro instantiations, this is the first.
-
-  return isAtStartOfMacroInstantiation(instLoc, LangOpts);
-}
-
-/// \brief Returns true if the given MacroID location points at the last
-/// token of the macro instantiation.
-bool SourceManager::isAtEndOfMacroInstantiation(SourceLocation loc,
-                                            const LangOptions &LangOpts) const {
-  assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
-
-  SourceLocation spellLoc = getSpellingLoc(loc);
-  unsigned tokLen = Lexer::MeasureTokenLength(spellLoc, *this, LangOpts);
-  if (tokLen == 0)
-    return false;
-
-  std::pair<FileID, unsigned> infoLoc = getDecomposedLoc(loc);
-  unsigned FID = infoLoc.first.ID;
-
-  unsigned NextOffset;
-  if (FID+1 == sloc_entry_size())
-    NextOffset = getNextOffset();
-  else
-    NextOffset = getSLocEntry(FID+1).getOffset();
-
-  // FIXME: If the token comes from the macro token paste operator ('##')
-  // or the stringify operator ('#') this function will always return false;
-  assert(loc.getOffset() + tokLen < NextOffset);
-  if (loc.getOffset() + tokLen < NextOffset-1)
-    return false; // Does not point to the last token.
-  
-  SourceLocation instLoc = 
-      getSLocEntry(infoLoc.first).getInstantiation().getInstantiationLocEnd();
-  if (instLoc.isFileID())
-    return true; // No other macro instantiations.
-
-  return isAtEndOfMacroInstantiation(instLoc, LangOpts);
-}
-
 //===----------------------------------------------------------------------===//
 // Other miscellaneous methods.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Jul  7 16:54:45 2011
@@ -683,7 +683,7 @@
     return SourceLocation();
 
   if (Loc.isMacroID()) {
-    if (Offset > 0 || !SM.isAtEndOfMacroInstantiation(Loc, Features))
+    if (Offset > 0 || !isAtEndOfMacroInstantiation(Loc, SM, Features))
       return SourceLocation(); // Points inside the macro instantiation.
 
     // Continue and find the location just after the macro instantiation.
@@ -699,6 +699,57 @@
   return Loc.getFileLocWithOffset(Len);
 }
 
+/// \brief Returns true if the given MacroID location points at the first
+/// token of the macro instantiation.
+bool Lexer::isAtStartOfMacroInstantiation(SourceLocation loc,
+                                          const SourceManager &SM,
+                                          const LangOptions &LangOpts) {
+  assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
+
+  std::pair<FileID, unsigned> infoLoc = SM.getDecomposedLoc(loc);
+  // FIXME: If the token comes from the macro token paste operator ('##')
+  // this function will always return false;
+  if (infoLoc.second > 0)
+    return false; // Does not point at the start of token.
+
+  SourceLocation instLoc = 
+      SM.getSLocEntry(infoLoc.first).getInstantiation().getInstantiationLocStart();
+  if (instLoc.isFileID())
+    return true; // No other macro instantiations, this is the first.
+
+  return isAtStartOfMacroInstantiation(instLoc, SM, LangOpts);
+}
+
+/// \brief Returns true if the given MacroID location points at the last
+/// token of the macro instantiation.
+bool Lexer::isAtEndOfMacroInstantiation(SourceLocation loc,
+                                        const SourceManager &SM,
+                                        const LangOptions &LangOpts) {
+  assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc");
+
+  SourceLocation spellLoc = SM.getSpellingLoc(loc);
+  unsigned tokLen = MeasureTokenLength(spellLoc, SM, LangOpts);
+  if (tokLen == 0)
+    return false;
+
+  FileID FID = SM.getFileID(loc);
+  SourceLocation afterLoc = loc.getFileLocWithOffset(tokLen+1);
+  if (!SM.isBeforeInSourceLocationOffset(afterLoc, SM.getNextOffset()))
+    return true; // We got past the last FileID, this points to the last token.
+
+  // FIXME: If the token comes from the macro token paste operator ('##')
+  // or the stringify operator ('#') this function will always return false;
+  if (FID == SM.getFileID(afterLoc))
+    return false; // Still in the same FileID, does not point to the last token.
+  
+  SourceLocation instLoc = 
+    SM.getSLocEntry(FID).getInstantiation().getInstantiationLocEnd();
+  if (instLoc.isFileID())
+    return true; // No other macro instantiations.
+
+  return isAtEndOfMacroInstantiation(instLoc, SM, LangOpts);
+}
+
 //===----------------------------------------------------------------------===//
 // Character information.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=134644&r1=134643&r2=134644&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Jul  7 16:54:45 2011
@@ -310,8 +310,7 @@
         SourceLocation FILoc = Tok.getLocation();
         const char *FIText = ": ";
         const SourceManager &SM = PP.getSourceManager();
-        if (FILoc.isFileID() ||
-            SM.isAtStartOfMacroInstantiation(FILoc, getLang())) {
+        if (FILoc.isFileID() || PP.isAtStartOfMacroInstantiation(FILoc)) {
           FILoc = SM.getInstantiationLoc(FILoc);
           bool IsInvalid = false;
           const char *SourcePtr =





More information about the cfe-commits mailing list