aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Rewrite/RewriteRope.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Rewrite/RewriteRope.h')
-rw-r--r--include/clang/Rewrite/RewriteRope.h58
1 files changed, 29 insertions, 29 deletions
diff --git a/include/clang/Rewrite/RewriteRope.h b/include/clang/Rewrite/RewriteRope.h
index 3b8eeb2b6b..c0bd741d55 100644
--- a/include/clang/Rewrite/RewriteRope.h
+++ b/include/clang/Rewrite/RewriteRope.h
@@ -22,7 +22,7 @@ namespace clang {
//===--------------------------------------------------------------------===//
// RopeRefCountString Class
//===--------------------------------------------------------------------===//
-
+
/// RopeRefCountString - This struct is allocated with 'new char[]' from the
/// heap, and represents a reference counted chunk of string data. When its
/// ref count drops to zero, it is delete[]'d. This is primarily managed
@@ -30,21 +30,21 @@ namespace clang {
struct RopeRefCountString {
unsigned RefCount;
char Data[1]; // Variable sized.
-
+
void addRef() {
if (this) ++RefCount;
}
-
+
void dropRef() {
if (this && --RefCount == 0)
delete [] (char*)this;
}
};
-
+
//===--------------------------------------------------------------------===//
// RopePiece Class
//===--------------------------------------------------------------------===//
-
+
/// RopePiece - This class represents a view into a RopeRefCountString object.
/// This allows references to string data to be efficiently chopped up and
/// moved around without having to push around the string data itself.
@@ -57,9 +57,9 @@ namespace clang {
RopeRefCountString *StrData;
unsigned StartOffs;
unsigned EndOffs;
-
+
RopePiece() : StrData(0), StartOffs(0), EndOffs(0) {}
-
+
RopePiece(RopeRefCountString *Str, unsigned Start, unsigned End)
: StrData(Str), StartOffs(Start), EndOffs(End) {
StrData->addRef();
@@ -68,11 +68,11 @@ namespace clang {
: StrData(RP.StrData), StartOffs(RP.StartOffs), EndOffs(RP.EndOffs) {
StrData->addRef();
}
-
+
~RopePiece() {
StrData->dropRef();
}
-
+
void operator=(const RopePiece &RHS) {
if (StrData != RHS.StrData) {
StrData->dropRef();
@@ -82,21 +82,21 @@ namespace clang {
StartOffs = RHS.StartOffs;
EndOffs = RHS.EndOffs;
}
-
+
const char &operator[](unsigned Offset) const {
return StrData->Data[Offset+StartOffs];
}
char &operator[](unsigned Offset) {
return StrData->Data[Offset+StartOffs];
}
-
+
unsigned size() const { return EndOffs-StartOffs; }
};
-
+
//===--------------------------------------------------------------------===//
// RopePieceBTreeIterator Class
//===--------------------------------------------------------------------===//
-
+
/// RopePieceBTreeIterator - This class provides read-only forward iteration
/// over bytes that are in a RopePieceBTree. This first iterates over bytes
/// in a RopePiece, then iterates over RopePiece's in a RopePieceBTreeLeaf,
@@ -115,18 +115,18 @@ namespace clang {
RopePieceBTreeIterator(const void /*RopePieceBTreeNode*/ *N);
// end iterator
RopePieceBTreeIterator() : CurNode(0), CurPiece(0), CurChar(0) {}
-
+
char operator*() const {
return (*CurPiece)[CurChar];
}
-
+
bool operator==(const RopePieceBTreeIterator &RHS) const {
return CurPiece == RHS.CurPiece && CurChar == RHS.CurChar;
}
bool operator!=(const RopePieceBTreeIterator &RHS) const {
return !operator==(RHS);
}
-
+
RopePieceBTreeIterator& operator++() { // Preincrement
if (CurChar+1 < CurPiece->size())
++CurChar;
@@ -140,11 +140,11 @@ namespace clang {
private:
void MoveToNextPiece();
};
-
+
//===--------------------------------------------------------------------===//
// RopePieceBTree Class
//===--------------------------------------------------------------------===//
-
+
class RopePieceBTree {
void /*RopePieceBTreeNode*/ *Root;
void operator=(const RopePieceBTree &); // DO NOT IMPLEMENT
@@ -152,15 +152,15 @@ namespace clang {
RopePieceBTree();
RopePieceBTree(const RopePieceBTree &RHS);
~RopePieceBTree();
-
+
typedef RopePieceBTreeIterator iterator;
iterator begin() const { return iterator(Root); }
iterator end() const { return iterator(); }
unsigned size() const;
unsigned empty() const { return size() == 0; }
-
+
void clear();
-
+
void insert(unsigned Offset, const RopePiece &R);
void erase(unsigned Offset, unsigned NumBytes);
@@ -169,13 +169,13 @@ namespace clang {
//===--------------------------------------------------------------------===//
// RewriteRope Class
//===--------------------------------------------------------------------===//
-
+
/// RewriteRope - A powerful string class. This class supports extremely
/// efficient insertions and deletions into the middle of it, even for
/// ridiculously long strings.
class RewriteRope {
RopePieceBTree Chunks;
-
+
/// We allocate space for string data out of a buffer of size AllocChunkSize.
/// This keeps track of how much space is left.
RopeRefCountString *AllocBuffer;
@@ -184,7 +184,7 @@ class RewriteRope {
public:
RewriteRope() : AllocBuffer(0), AllocOffs(AllocChunkSize) {}
- RewriteRope(const RewriteRope &RHS)
+ RewriteRope(const RewriteRope &RHS)
: Chunks(RHS.Chunks), AllocBuffer(0), AllocOffs(AllocChunkSize) {
}
@@ -192,23 +192,23 @@ public:
// If we had an allocation buffer, drop our reference to it.
AllocBuffer->dropRef();
}
-
+
typedef RopePieceBTree::iterator iterator;
typedef RopePieceBTree::iterator const_iterator;
iterator begin() const { return Chunks.begin(); }
iterator end() const { return Chunks.end(); }
unsigned size() const { return Chunks.size(); }
-
+
void clear() {
Chunks.clear();
}
-
+
void assign(const char *Start, const char *End) {
clear();
if (Start != End)
Chunks.insert(0, MakeRopeString(Start, End));
}
-
+
void insert(unsigned Offset, const char *Start, const char *End) {
assert(Offset <= size() && "Invalid position to insert!");
if (Start == End) return;
@@ -224,7 +224,7 @@ public:
private:
RopePiece MakeRopeString(const char *Start, const char *End);
};
-
+
} // end namespace clang
#endif