aboutsummaryrefslogtreecommitdiff
path: root/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-02 03:55:37 +0000
committerChris Lattner <sabre@nondot.org>2007-08-02 03:55:37 +0000
commit991ae518e915bbdef5710b2965adee032a04f5a5 (patch)
treeb4a4b3d03f37628dacef642b2a11aaba6d09381a /Basic/SourceManager.cpp
parent9dfa7b4e320b51b1561dd597c7b3a2db4c0ac12c (diff)
Increase the macro id cache to look up several recent entries, not just the last one.
This is important in insane cases like the one dannyb sent me recently: #define F0(a) void a(){} #define F1(a) F0(a##0) F0(a##1) F0(a##2) F0(a##3) F0(a##4) F0(a##5) F0(a##6) F0(a##7) #define F2(a) F1(a##0) F1(a##1) F1(a##2) F1(a##3) F1(a##4) F1(a##5) F1(a##6) F1(a##7) #define F3(a) F2(a##0) F2(a##1) F2(a##2) F2(a##3) F2(a##4) F2(a##5) F2(a##6) F2(a##7) #define F4(a) F3(a##0) F3(a##1) F3(a##2) F3(a##3) F3(a##4) F3(a##5) F3(a##6) F3(a##7) #define F5(a) F4(a##0) F4(a##1) F4(a##2) F4(a##3) F4(a##4) F4(a##5) F4(a##6) F4(a##7) #define F6(a) F5(a##0) F5(a##1) F5(a##2) F5(a##3) F5(a##4) F5(a##5) F5(a##6) F5(a##7) F6(f) cpp is great. :) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40715 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Basic/SourceManager.cpp')
-rw-r--r--Basic/SourceManager.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/Basic/SourceManager.cpp b/Basic/SourceManager.cpp
index df13fad37c..05d58cf79e 100644
--- a/Basic/SourceManager.cpp
+++ b/Basic/SourceManager.cpp
@@ -178,18 +178,21 @@ SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc,
// If the last macro id is close to the currently requested location, try to
- // reuse it. This implements a single-entry cache.
- if (!MacroIDs.empty()) {
- MacroIDInfo &LastOne = MacroIDs.back();
+ // reuse it. This implements a small cache.
+ for (int i = MacroIDs.size()-1, e = MacroIDs.size()-6; i >= 0 && i != e; --i){
+ MacroIDInfo &LastOne = MacroIDs[i];
- if (LastOne.getInstantiationLoc() == InstantLoc &&
- LastOne.getPhysicalLoc().getFileID() == PhysLoc.getFileID()) {
-
- int PhysDelta = PhysLoc.getRawFilePos() -
- LastOne.getPhysicalLoc().getRawFilePos();
- if (SourceLocation::isValidMacroPhysOffs(PhysDelta))
- return SourceLocation::getMacroLoc(MacroIDs.size()-1, PhysDelta, 0);
- }
+ // The instanitation point and source physloc have to exactly match to reuse
+ // (for now). We could allow "nearby" instantiations in the future.
+ if (LastOne.getInstantiationLoc() != InstantLoc ||
+ LastOne.getPhysicalLoc().getFileID() != PhysLoc.getFileID())
+ continue;
+
+ // Check to see if the physloc of the token came from near enough to reuse.
+ int PhysDelta = PhysLoc.getRawFilePos() -
+ LastOne.getPhysicalLoc().getRawFilePos();
+ if (SourceLocation::isValidMacroPhysOffs(PhysDelta))
+ return SourceLocation::getMacroLoc(MacroIDs.size()-1, PhysDelta, 0);
}