[cfe-commits] r43905 - in /cfe/trunk: Rewrite/Rewriter.cpp clang.xcodeproj/project.pbxproj include/clang/Rewrite/RewriteRope.h include/clang/Rewrite/Rewriter.h
Chris Lattner
sabre at nondot.org
Thu Nov 8 12:51:02 PST 2007
Author: lattner
Date: Thu Nov 8 14:51:02 2007
New Revision: 43905
URL: http://llvm.org/viewvc/llvm-project?rev=43905&view=rev
Log:
add a getAtOffset() member to simplify some code.
Modified:
cfe/trunk/Rewrite/Rewriter.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/include/clang/Rewrite/RewriteRope.h
cfe/trunk/include/clang/Rewrite/Rewriter.h
Modified: cfe/trunk/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Rewrite/Rewriter.cpp?rev=43905&r1=43904&r2=43905&view=diff
==============================================================================
--- cfe/trunk/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/Rewrite/Rewriter.cpp Thu Nov 8 14:51:02 2007
@@ -91,7 +91,8 @@
assert(RealOffset+Size < Buffer.size() && "Invalid location");
// Remove the dead characters.
- Buffer.erase(Buffer.begin()+RealOffset, Buffer.begin()+RealOffset+Size);
+ RewriteRope::iterator I = Buffer.getAtOffset(RealOffset);
+ Buffer.erase(I, I+Size);
// Add a delta so that future changes are offset correctly.
AddDelta(OrigOffset, -Size);
@@ -106,7 +107,7 @@
assert(RealOffset <= Buffer.size() && "Invalid location");
// Insert the new characters.
- Buffer.insert(Buffer.begin()+RealOffset, StrData, StrData+StrLen);
+ Buffer.insert(Buffer.getAtOffset(RealOffset), StrData, StrData+StrLen);
// Add a delta so that future changes are offset correctly.
AddDelta(OrigOffset, StrLen);
@@ -120,14 +121,16 @@
unsigned RealOffset = getMappedOffset(OrigOffset, true);
assert(RealOffset+OrigLength <= Buffer.size() && "Invalid location");
+#if 0
Buffer.erase(Buffer.begin()+RealOffset, Buffer.begin()+RealOffset+OrigLength);
Buffer.insert(Buffer.begin()+RealOffset, NewStr, NewStr+NewLength);
AddDelta(OrigOffset, NewLength-OrigLength);
return;
+#endif
// Overwrite the common piece.
unsigned CommonLength = std::min(OrigLength, NewLength);
- std::copy(NewStr, NewStr+CommonLength, Buffer.begin()+RealOffset);
+ std::copy(NewStr, NewStr+CommonLength, Buffer.getAtOffset(RealOffset));
// If replacing without shifting around, just overwrite the text.
if (OrigLength == NewLength)
@@ -135,12 +138,12 @@
// If inserting more than existed before, this is like an insertion.
if (NewLength > OrigLength) {
- Buffer.insert(Buffer.begin()+RealOffset+OrigLength,
+ Buffer.insert(Buffer.getAtOffset(RealOffset+OrigLength),
NewStr+OrigLength, NewStr+NewLength);
} else {
- // If insertion less than existed before, this is like a removal.
- Buffer.erase(Buffer.begin()+RealOffset+NewLength,
- Buffer.begin()+RealOffset+OrigLength);
+ // If inserting less than existed before, this is like a removal.
+ RewriteRope::iterator I = Buffer.getAtOffset(RealOffset+NewLength);
+ Buffer.erase(I, I+(OrigLength-NewLength));
}
AddDelta(OrigOffset, NewLength-OrigLength);
}
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43905&r1=43904&r2=43905&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Thu Nov 8 14:51:02 2007
@@ -251,7 +251,7 @@
84AF36A00CB17A3B00C820A5 /* DeclObjC.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclObjC.h; path = clang/AST/DeclObjC.h; sourceTree = "<group>"; };
84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
- 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
@@ -764,7 +764,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
Modified: cfe/trunk/include/clang/Rewrite/RewriteRope.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/RewriteRope.h?rev=43905&r1=43904&r2=43905&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/RewriteRope.h (original)
+++ cfe/trunk/include/clang/Rewrite/RewriteRope.h Thu Nov 8 14:51:02 2007
@@ -87,10 +87,6 @@
return *this;
}
- inline RewriteRopeIterator operator++(int) { // Postincrement
- RewriteRopeIterator tmp = *this; ++*this; return tmp;
- }
-
RewriteRopeIterator operator+(int Offset) const {
assert(Offset >= 0 && "FIXME: Only handle forward case so far!");
@@ -104,6 +100,10 @@
Char += Offset;
return RewriteRopeIterator(Piece, Char);
}
+
+ inline RewriteRopeIterator operator++(int) { // Postincrement
+ RewriteRopeIterator tmp = *this; ++*this; return tmp;
+ }
};
@@ -146,6 +146,27 @@
CurSize = End-Start;
}
+ iterator getAtOffset(unsigned Offset) {
+ assert(Offset <= CurSize && "Offset out of range!");
+ std::list<RopePiece>::iterator Piece = Chunks.begin();
+ while (Offset >= Piece->size()) {
+ Offset -= Piece->size();
+ ++Piece;
+ }
+ return iterator(Piece, Offset);
+ }
+
+ const_iterator getAtOffset(unsigned Offset) const {
+ assert(Offset <= CurSize && "Offset out of range!");
+ std::list<RopePiece>::const_iterator Piece = Chunks.begin();
+ while (Offset >= Piece->size()) {
+ Offset -= Piece->size();
+ ++Piece;
+ }
+ return const_iterator(Piece, Offset);
+ }
+
+
void insert(iterator Loc, const char *Start, const char *End) {
if (Start == End) return;
Chunks.insert(SplitAt(Loc), MakeRopeString(Start, End));
@@ -155,9 +176,6 @@
void erase(iterator Start, iterator End) {
if (Start == End) return;
- //unsigned StartChunkIdx = getChunkIdx(Start);
- //unsigned EndChunkIdx = getChunkIdx(End);
-
// If erase is localized within the same chunk, this is a degenerate case.
if (Start.CurPiece == End.CurPiece) {
RopePiece &Chunk = *Start.CurPiece;
Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=43905&r1=43904&r2=43905&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Thu Nov 8 14:51:02 2007
@@ -57,7 +57,6 @@
/// string is a horribly inefficient way to do this, we should use a rope
/// instead.
typedef RewriteRope BufferTy;
- //typedef std::vector<char> BufferTy;
BufferTy Buffer;
public:
typedef BufferTy::const_iterator iterator;
More information about the cfe-commits
mailing list