[cfe-commits] r169228 - in /cfe/trunk: include/clang/Lex/PreprocessingRecord.h lib/Lex/PreprocessingRecord.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Dec 3 23:26:54 PST 2012


Author: akirtzidis
Date: Tue Dec  4 01:26:53 2012
New Revision: 169228

URL: http://llvm.org/viewvc/llvm-project?rev=169228&view=rev
Log:
In the PreprocessingRecord, to identify the different conditional directive regions
use the SourceLocation at the start of the respective region, instead of a unique integer.

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

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=169228&r1=169227&r2=169228&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Tue Dec  4 01:26:53 2012
@@ -304,18 +304,18 @@
     std::vector<PreprocessedEntity *> LoadedPreprocessedEntities;
 
     bool RecordCondDirectives;
-    unsigned CondDirectiveNextIdx;
-    SmallVector<unsigned, 6> CondDirectiveStack; 
+    SmallVector<SourceLocation, 6> CondDirectiveStack;
 
     class CondDirectiveLoc {
       SourceLocation Loc;
-      unsigned Idx;
+      SourceLocation RegionLoc;
 
     public:
-      CondDirectiveLoc(SourceLocation Loc, unsigned Idx) : Loc(Loc), Idx(Idx) {}
+      CondDirectiveLoc(SourceLocation Loc, SourceLocation RegionLoc)
+        : Loc(Loc), RegionLoc(RegionLoc) {}
 
       SourceLocation getLoc() const { return Loc; }
-      unsigned getIdx() const { return Idx; }
+      SourceLocation getRegionLoc() const { return RegionLoc; }
 
       class Comp {
         SourceManager &SM;
@@ -339,7 +339,7 @@
     CondDirectiveLocsTy CondDirectiveLocs;
 
     void addCondDirectiveLoc(CondDirectiveLoc DirLoc);
-    unsigned findCondDirectiveIdx(SourceLocation Loc) const;
+    SourceLocation findCondDirectiveRegionLoc(SourceLocation Loc) const;
 
     /// \brief Global (loaded or local) ID for a preprocessed entity.
     /// Negative values are used to indicate preprocessed entities
@@ -597,7 +597,7 @@
     /// separated by conditional directive blocks.
     bool areInDifferentConditionalDirectiveRegion(SourceLocation LHS,
                                                   SourceLocation RHS) const {
-      return findCondDirectiveIdx(LHS) != findCondDirectiveIdx(RHS);
+      return findCondDirectiveRegionLoc(LHS) != findCondDirectiveRegionLoc(RHS);
     }
 
     /// \brief Set the external source for preprocessed entities.

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=169228&r1=169227&r2=169228&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Tue Dec  4 01:26:53 2012
@@ -41,11 +41,11 @@
 PreprocessingRecord::PreprocessingRecord(SourceManager &SM,
                                          bool RecordConditionalDirectives)
   : SourceMgr(SM),
-    RecordCondDirectives(RecordConditionalDirectives), CondDirectiveNextIdx(0),
+    RecordCondDirectives(RecordConditionalDirectives),
     ExternalSource(0)
 {
   if (RecordCondDirectives)
-    CondDirectiveStack.push_back(CondDirectiveNextIdx++);
+    CondDirectiveStack.push_back(SourceLocation());
 }
 
 /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities
@@ -455,25 +455,24 @@
   CondDirectiveLocsTy::const_iterator
     upp = std::upper_bound(low, CondDirectiveLocs.end(),
                            Range.getEnd(), CondDirectiveLoc::Comp(SourceMgr));
-  unsigned uppIdx;
+  SourceLocation uppRegion;
   if (upp != CondDirectiveLocs.end())
-    uppIdx = upp->getIdx();
-  else
-    uppIdx = 0;
+    uppRegion = upp->getRegionLoc();
 
-  return low->getIdx() != uppIdx;
+  return low->getRegionLoc() != uppRegion;
 }
 
-unsigned PreprocessingRecord::findCondDirectiveIdx(SourceLocation Loc) const {
+SourceLocation
+PreprocessingRecord::findCondDirectiveRegionLoc(SourceLocation Loc) const {
   if (Loc.isInvalid())
-    return 0;
+    return SourceLocation();
 
   CondDirectiveLocsTy::const_iterator
     low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(),
                            Loc, CondDirectiveLoc::Comp(SourceMgr));
   if (low == CondDirectiveLocs.end())
-    return 0;
-  return low->getIdx();
+    return SourceLocation();
+  return low->getRegionLoc();
 }
 
 void PreprocessingRecord::addCondDirectiveLoc(CondDirectiveLoc DirLoc) {
@@ -490,33 +489,37 @@
 void PreprocessingRecord::If(SourceLocation Loc, SourceRange ConditionRange) {
   if (RecordCondDirectives) {
     addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
-    CondDirectiveStack.push_back(CondDirectiveNextIdx++);
+    CondDirectiveStack.push_back(Loc);
   }
 }
 
 void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok) {
   if (RecordCondDirectives) {
     addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
-    CondDirectiveStack.push_back(CondDirectiveNextIdx++);
+    CondDirectiveStack.push_back(Loc);
   }
 }
 
 void PreprocessingRecord::Ifndef(SourceLocation Loc,const Token &MacroNameTok) {
   if (RecordCondDirectives) {
     addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
-    CondDirectiveStack.push_back(CondDirectiveNextIdx++);
+    CondDirectiveStack.push_back(Loc);
   }
 }
 
 void PreprocessingRecord::Elif(SourceLocation Loc, SourceRange ConditionRange,
                                SourceLocation IfLoc) {
-  if (RecordCondDirectives)
+  if (RecordCondDirectives) {
     addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
+    CondDirectiveStack.back() = Loc;
+  }
 }
 
 void PreprocessingRecord::Else(SourceLocation Loc, SourceLocation IfLoc) {
-  if (RecordCondDirectives)
+  if (RecordCondDirectives) {
     addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
+    CondDirectiveStack.back() = Loc;
+  }
 }
 
 void PreprocessingRecord::Endif(SourceLocation Loc, SourceLocation IfLoc) {





More information about the cfe-commits mailing list