aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Rewrite/Rewriter.h
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-05-18 13:56:52 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-05-18 13:56:52 +0000
commita0978c24829dfd552d38fc3bae2b86e18bb90d49 (patch)
treeeb234612ef1a0f6f7721bb84dd45230ae75b1b0e /include/clang/Rewrite/Rewriter.h
parenta3306f0b9f988677bf12c3403dd0c0336cb5c246 (diff)
Fix for PR2386: distinguish between insertion and replacements in the
delta tree. The issue is roughly a conflict in ReplaceText between two kinds of uses. One, it should be possible to replace a replacement: for example, the ObjC rewriter calls ReplaceStmt for an expression, then replaces the resulting expression with another expression. Two, it should be possible to replace text that already has text inserted before it: for example, the HTML rewriter inserts a bunch of tags at the beginning of the line, then tries to escape the first character on the line. This patch distinguishes the two cases by storing the deltas separately; essentially, replacements and insertions no longer interfere with each other. Another possibility would be to add some sort of flag to ReplaceText, but this seems a bit more intuitive and flexible. There are a few downsides to the current solution: one is that there isn't any way to remove/replace an insertion without touching additional surrounding text; if such an operation turns out to be useful, an additional method or flag can be added. Another is that an insertion and replacing a string of length zero are distinct operations; I'm not sure how to resolve this, or whether it will be confusing in practice. This is relatively sensitive code, so please test and tell me if anything breaks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72000 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Rewrite/Rewriter.h')
-rw-r--r--include/clang/Rewrite/Rewriter.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/include/clang/Rewrite/Rewriter.h b/include/clang/Rewrite/Rewriter.h
index afa018d9cb..c3ee0175c3 100644
--- a/include/clang/Rewrite/Rewriter.h
+++ b/include/clang/Rewrite/Rewriter.h
@@ -102,13 +102,19 @@ private: // Methods only usable by Rewriter.
/// inserted text at the position.
unsigned getMappedOffset(unsigned OrigOffset,
bool AfterInserts = false) const{
- return Deltas.getDeltaAt(OrigOffset+AfterInserts)+OrigOffset;
+ return Deltas.getDeltaAt(2*OrigOffset+AfterInserts)+OrigOffset;
}
- /// AddDelta - When a change is made that shifts around the text buffer, this
- /// method is used to record that info.
- void AddDelta(unsigned OrigOffset, int Change) {
- return Deltas.AddDelta(OrigOffset, Change);
+ /// AddInsertDelta - When an insertion is made at a position, this
+ /// method is used to record that information.
+ void AddInsertDelta(unsigned OrigOffset, int Change) {
+ return Deltas.AddDelta(2*OrigOffset, Change);
+ }
+
+ /// AddReplaceDelta - When a replacement/deletion is made at a position, this
+ /// method is used to record that information.
+ void AddReplaceDelta(unsigned OrigOffset, int Change) {
+ return Deltas.AddDelta(2*OrigOffset+1, Change);
}
};