[cfe-commits] r136056 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Lex/Lexer.cpp lib/Serialization/ASTWriter.cpp

Chandler Carruth chandlerc at gmail.com
Mon Jul 25 21:41:47 PDT 2011


Author: chandlerc
Date: Mon Jul 25 23:41:47 2011
New Revision: 136056

URL: http://llvm.org/viewvc/llvm-project?rev=136056&view=rev
Log:
Convert InstantiationInfo and much of the related code to ExpansionInfo
and various other 'expansion' based terms. I've tried to reformat where
appropriate and catch as many references in comments but I'm going to do
several more passes. Also I've tried to expand parameter names to be
more clear where appropriate.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=136056&r1=136055&r2=136056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon Jul 25 23:41:47 2011
@@ -224,70 +224,68 @@
     }
   };
 
-  /// InstantiationInfo - Each InstantiationInfo encodes the Instantiation
-  /// location - where the token was ultimately instantiated, and the
-  /// SpellingLoc - where the actual character data for the token came from.
-  class InstantiationInfo {
-     // Really these are all SourceLocations.
+  /// ExpansionInfo - Each ExpansionInfo encodes the expansion location - where
+  /// the token was ultimately expanded, and the SpellingLoc - where the actual
+  /// character data for the token came from.
+  class ExpansionInfo {
+    // Really these are all SourceLocations.
 
     /// SpellingLoc - Where the spelling for the token can be found.
     unsigned SpellingLoc;
 
-    /// InstantiationLocStart/InstantiationLocEnd - In a macro expansion, these
-    /// indicate the start and end of the instantiation.  In object-like macros,
-    /// these will be the same.  In a function-like macro instantiation, the
-    /// start will be the identifier and the end will be the ')'.  Finally, in
+    /// ExpansionLocStart/ExpansionLocEnd - In a macro expansion, these
+    /// indicate the start and end of the expansion. In object-like macros,
+    /// these will be the same. In a function-like macro instantiation, the
+    /// start will be the identifier and the end will be the ')'. Finally, in
     /// macro-argument instantitions, the end will be 'SourceLocation()', an
     /// invalid location.
-    unsigned InstantiationLocStart, InstantiationLocEnd;
+    unsigned ExpansionLocStart, ExpansionLocEnd;
 
   public:
     SourceLocation getSpellingLoc() const {
       return SourceLocation::getFromRawEncoding(SpellingLoc);
     }
-    SourceLocation getInstantiationLocStart() const {
-      return SourceLocation::getFromRawEncoding(InstantiationLocStart);
+    SourceLocation getExpansionLocStart() const {
+      return SourceLocation::getFromRawEncoding(ExpansionLocStart);
     }
-    SourceLocation getInstantiationLocEnd() const {
+    SourceLocation getExpansionLocEnd() const {
       SourceLocation EndLoc =
-        SourceLocation::getFromRawEncoding(InstantiationLocEnd);
-      return EndLoc.isInvalid() ? getInstantiationLocStart() : EndLoc;
+        SourceLocation::getFromRawEncoding(ExpansionLocEnd);
+      return EndLoc.isInvalid() ? getExpansionLocStart() : EndLoc;
     }
 
-    std::pair<SourceLocation,SourceLocation> getInstantiationLocRange() const {
-      return std::make_pair(getInstantiationLocStart(),
-                            getInstantiationLocEnd());
+    std::pair<SourceLocation,SourceLocation> getExpansionLocRange() const {
+      return std::make_pair(getExpansionLocStart(), getExpansionLocEnd());
     }
 
     bool isMacroArgExpansion() const {
       // Note that this needs to return false for default constructed objects.
-      return getInstantiationLocStart().isValid() &&
-        SourceLocation::getFromRawEncoding(InstantiationLocEnd).isInvalid();
+      return getExpansionLocStart().isValid() &&
+        SourceLocation::getFromRawEncoding(ExpansionLocEnd).isInvalid();
     }
 
-    /// create - Return a InstantiationInfo for an expansion. ILStart and
-    /// ILEnd specify the instantiation range (where the macro is expanded),
-    /// and SL specifies the spelling location (where the characters from the
-    /// token come from). All three can refer to normal File SLocs or
-    /// instantiation locations.
-    static InstantiationInfo create(SourceLocation SL,
-                                    SourceLocation ILStart,
-                                    SourceLocation ILEnd) {
-      InstantiationInfo X;
-      X.SpellingLoc = SL.getRawEncoding();
-      X.InstantiationLocStart = ILStart.getRawEncoding();
-      X.InstantiationLocEnd = ILEnd.getRawEncoding();
+    /// create - Return a ExpansionInfo for an expansion. Start and End specify
+    /// the expansion range (where the macro is expanded), and SpellingLoc
+    /// specifies the spelling location (where the characters from the token
+    /// come from). All three can refer to normal File SLocs or expansion
+    /// locations.
+    static ExpansionInfo create(SourceLocation SpellingLoc,
+                                SourceLocation Start, SourceLocation End) {
+      ExpansionInfo X;
+      X.SpellingLoc = SpellingLoc.getRawEncoding();
+      X.ExpansionLocStart = Start.getRawEncoding();
+      X.ExpansionLocEnd = End.getRawEncoding();
       return X;
     }
 
-    /// createForMacroArg - Return a special InstantiationInfo for the
-    /// expansion of a macro argument into a function-like macro's body. IL
-    /// specifies the instantiation location (where the macro is expanded).
-    /// This doesn't need to be a range because a macro is always instantiated
-    /// at a macro parameter reference, and macro parameters are always exactly
-    /// one token. SL specifies the spelling location (where the characters
-    /// from the token come from). IL and SL can both refer to normal File
-    /// SLocs or instantiation locations.
+    /// createForMacroArg - Return a special ExpansionInfo for the expansion of
+    /// a macro argument into a function-like macro's body. ExpansionLoc
+    /// specifies the expansion location (where the macro is expanded). This
+    /// doesn't need to be a range because a macro is always expanded at
+    /// a macro parameter reference, and macro parameters are always exactly
+    /// one token. SpellingLoc specifies the spelling location (where the
+    /// characters from the token come from). ExpansionLoc and SpellingLoc can
+    /// both refer to normal File SLocs or expansion locations.
     ///
     /// Given the code:
     /// \code
@@ -295,26 +293,26 @@
     ///   F(42);
     /// \endcode
     ///
-    /// When expanding '\c F(42)', the '\c x' would call this with an SL
-    /// pointing at '\c 42' anad an IL pointing at its location in the
-    /// definition of '\c F'.
-    static InstantiationInfo createForMacroArg(SourceLocation SL,
-                                               SourceLocation IL) {
+    /// When expanding '\c F(42)', the '\c x' would call this with an
+    /// SpellingLoc pointing at '\c 42' anad an ExpansionLoc pointing at its
+    /// location in the definition of '\c F'.
+    static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc,
+                                           SourceLocation ExpansionLoc) {
       // We store an intentionally invalid source location for the end of the
-      // instantiation range to mark that this is a macro argument instantation
-      // rather than a normal one.
-      return create(SL, IL, SourceLocation());
+      // expansion range to mark that this is a macro argument ion rather than
+      // a normal one.
+      return create(SpellingLoc, ExpansionLoc, SourceLocation());
     }
   };
 
   /// SLocEntry - This is a discriminated union of FileInfo and
-  /// InstantiationInfo.  SourceManager keeps an array of these objects, and
+  /// ExpansionInfo.  SourceManager keeps an array of these objects, and
   /// they are uniquely identified by the FileID datatype.
   class SLocEntry {
     unsigned Offset;   // low bit is set for instantiation info.
     union {
       FileInfo File;
-      InstantiationInfo Instantiation;
+      ExpansionInfo Instantiation;
     };
   public:
     unsigned getOffset() const { return Offset >> 1; }
@@ -327,7 +325,7 @@
       return File;
     }
 
-    const InstantiationInfo &getInstantiation() const {
+    const ExpansionInfo &getInstantiation() const {
       assert(isInstantiation() && "Not an instantiation SLocEntry!");
       return Instantiation;
     }
@@ -339,10 +337,10 @@
       return E;
     }
 
-    static SLocEntry get(unsigned Offset, const InstantiationInfo &II) {
+    static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) {
       SLocEntry E;
       E.Offset = (Offset << 1) | 1;
-      E.Instantiation = II;
+      E.Instantiation = Expansion;
       return E;
     }
   };
@@ -1083,7 +1081,7 @@
   /// createExpansionLoc - Implements the common elements of storing an
   /// instantiation info struct into the SLocEntry table and producing a source
   /// location that refers to it.
-  SourceLocation createExpansionLocImpl(const SrcMgr::InstantiationInfo &II,
+  SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion,
                                         unsigned TokLength,
                                         int LoadedID = 0,
                                         unsigned LoadedOffset = 0);

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=136056&r1=136055&r2=136056&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Jul 25 23:41:47 2011
@@ -521,9 +521,9 @@
 SourceManager::createMacroArgExpansionLoc(SourceLocation SpellingLoc,
                                           SourceLocation ExpansionLoc,
                                           unsigned TokLength) {
-  InstantiationInfo II =
-    InstantiationInfo::createForMacroArg(SpellingLoc, ExpansionLoc);
-  return createExpansionLocImpl(II, TokLength);
+  ExpansionInfo Info = ExpansionInfo::createForMacroArg(SpellingLoc,
+                                                        ExpansionLoc);
+  return createExpansionLocImpl(Info, TokLength);
 }
 
 SourceLocation
@@ -533,14 +533,13 @@
                                   unsigned TokLength,
                                   int LoadedID,
                                   unsigned LoadedOffset) {
-  InstantiationInfo II =
-    InstantiationInfo::create(SpellingLoc, ExpansionLocStart,
-                              ExpansionLocEnd);
-  return createExpansionLocImpl(II, TokLength, LoadedID, LoadedOffset);
+  ExpansionInfo Info = ExpansionInfo::create(SpellingLoc, ExpansionLocStart,
+                                             ExpansionLocEnd);
+  return createExpansionLocImpl(Info, TokLength, LoadedID, LoadedOffset);
 }
 
 SourceLocation
-SourceManager::createExpansionLocImpl(const InstantiationInfo &II,
+SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
                                       unsigned TokLength,
                                       int LoadedID,
                                       unsigned LoadedOffset) {
@@ -549,11 +548,11 @@
     unsigned Index = unsigned(-LoadedID) - 2;
     assert(Index < LoadedSLocEntryTable.size() && "FileID out of range");
     assert(!SLocEntryLoaded[Index] && "FileID already loaded");
-    LoadedSLocEntryTable[Index] = SLocEntry::get(LoadedOffset, II);
+    LoadedSLocEntryTable[Index] = SLocEntry::get(LoadedOffset, Info);
     SLocEntryLoaded[Index] = true;
     return SourceLocation::getMacroLoc(LoadedOffset);
   }
-  LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, II));
+  LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, Info));
   assert(NextLocalOffset + TokLength + 1 > NextLocalOffset &&
          NextLocalOffset + TokLength + 1 <= CurrentLoadedOffset &&
          "Ran out of source locations!");
@@ -794,7 +793,7 @@
     // with.  This is unlike when we get the spelling loc, because the offset
     // directly correspond to the token whose spelling we're inspecting.
     Loc = getSLocEntry(getFileID(Loc)).getInstantiation()
-                   .getInstantiationLocStart();
+                   .getExpansionLocStart();
   } while (!Loc.isFileID());
 
   return Loc;
@@ -819,7 +818,7 @@
   SourceLocation Loc;
   unsigned Offset;
   do {
-    Loc = E->getInstantiation().getInstantiationLocStart();
+    Loc = E->getInstantiation().getExpansionLocStart();
 
     FID = getFileID(Loc);
     E = &getSLocEntry(FID);
@@ -864,8 +863,9 @@
 std::pair<SourceLocation,SourceLocation>
 SourceManager::getImmediateExpansionRange(SourceLocation Loc) const {
   assert(Loc.isMacroID() && "Not an instantiation loc!");
-  const InstantiationInfo &II = getSLocEntry(getFileID(Loc)).getInstantiation();
-  return II.getInstantiationLocRange();
+  const ExpansionInfo &Expansion =
+    getSLocEntry(getFileID(Loc)).getInstantiation();
+  return Expansion.getExpansionLocRange();
 }
 
 /// getExpansionRange - Given a SourceLocation object, return the range of
@@ -891,8 +891,8 @@
 
   FileID FID = getFileID(Loc);
   const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
-  const SrcMgr::InstantiationInfo &II = E->getInstantiation();
-  return II.isMacroArgExpansion();
+  const SrcMgr::ExpansionInfo &Expansion = E->getInstantiation();
+  return Expansion.isMacroArgExpansion();
 }
 
 
@@ -1467,7 +1467,7 @@
   SourceLocation UpperLoc;
   const SrcMgr::SLocEntry &Entry = SM.getSLocEntry(Loc.first);
   if (Entry.isInstantiation())
-    UpperLoc = Entry.getInstantiation().getInstantiationLocStart();
+    UpperLoc = Entry.getInstantiation().getExpansionLocStart();
   else
     UpperLoc = Entry.getFile().getIncludeLoc();
   

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=136056&r1=136055&r2=136056&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Mon Jul 25 23:41:47 2011
@@ -714,7 +714,7 @@
 
   SourceLocation expansionLoc =
     SM.getSLocEntry(infoLoc.first)
-      .getInstantiation().getInstantiationLocStart();
+      .getInstantiation().getExpansionLocStart();
   if (expansionLoc.isFileID())
     return true; // No other macro expansions, this is the first.
 
@@ -744,7 +744,7 @@
     return false; // Still in the same FileID, does not point to the last token.
   
   SourceLocation expansionLoc =
-    SM.getSLocEntry(FID).getInstantiation().getInstantiationLocEnd();
+    SM.getSLocEntry(FID).getInstantiation().getExpansionLocEnd();
   if (expansionLoc.isFileID())
     return true; // No other macro expansions.
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=136056&r1=136055&r2=136056&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Jul 25 23:41:47 2011
@@ -1505,10 +1505,10 @@
       }
     } else {
       // The source location entry is a macro expansion.
-      const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation();
-      Record.push_back(Inst.getSpellingLoc().getRawEncoding());
-      Record.push_back(Inst.getInstantiationLocStart().getRawEncoding());
-      Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding());
+      const SrcMgr::ExpansionInfo &Expansion = SLoc->getInstantiation();
+      Record.push_back(Expansion.getSpellingLoc().getRawEncoding());
+      Record.push_back(Expansion.getExpansionLocStart().getRawEncoding());
+      Record.push_back(Expansion.getExpansionLocEnd().getRawEncoding());
 
       // Compute the token length for this macro expansion.
       unsigned NextOffset = SourceMgr.getNextLocalOffset();





More information about the cfe-commits mailing list