diff options
author | Mike Stump <mrs@apple.com> | 2009-09-09 15:08:12 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-09-09 15:08:12 +0000 |
commit | 1eb4433ac451dc16f4133a88af2d002ac26c58ef (patch) | |
tree | 07065b80cb7787bb7b9ffcb985196007a57e86f7 /lib/Rewrite | |
parent | 79d39f92590cf2e91bf81486b02cd1156d13ca54 (diff) |
Remove tabs, and whitespace cleanups.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81346 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite')
-rw-r--r-- | lib/Rewrite/DeltaTree.cpp | 106 | ||||
-rw-r--r-- | lib/Rewrite/HTMLRewrite.cpp | 142 | ||||
-rw-r--r-- | lib/Rewrite/RewriteRope.cpp | 184 | ||||
-rw-r--r-- | lib/Rewrite/Rewriter.cpp | 44 | ||||
-rw-r--r-- | lib/Rewrite/TokenRewriter.cpp | 20 |
5 files changed, 248 insertions, 248 deletions
diff --git a/lib/Rewrite/DeltaTree.cpp b/lib/Rewrite/DeltaTree.cpp index 5d51ddae08..a94444b50c 100644 --- a/lib/Rewrite/DeltaTree.cpp +++ b/lib/Rewrite/DeltaTree.cpp @@ -39,7 +39,7 @@ namespace { /// former and adds children pointers. Each node knows the full delta of all /// entries (recursively) contained inside of it, which allows us to get the /// full delta implied by a whole subtree in constant time. - + namespace { /// SourceDelta - As code in the original input buffer is added and deleted, /// SourceDelta records are used to keep track of how the input SourceLocation @@ -47,7 +47,7 @@ namespace { struct SourceDelta { unsigned FileLoc; int Delta; - + static SourceDelta get(unsigned Loc, int D) { SourceDelta Delta; Delta.FileLoc = Loc; @@ -71,36 +71,36 @@ namespace { /// class DeltaTreeNode { friend class DeltaTreeInteriorNode; - + /// WidthFactor - This controls the number of K/V slots held in the BTree: /// how wide it is. Each level of the BTree is guaranteed to have at least /// WidthFactor-1 K/V pairs (except the root) and may have at most /// 2*WidthFactor-1 K/V pairs. enum { WidthFactor = 8 }; - + /// Values - This tracks the SourceDelta's currently in this node. /// SourceDelta Values[2*WidthFactor-1]; - + /// NumValuesUsed - This tracks the number of values this node currently /// holds. unsigned char NumValuesUsed; - + /// IsLeaf - This is true if this is a leaf of the btree. If false, this is /// an interior node, and is actually an instance of DeltaTreeInteriorNode. bool IsLeaf; - + /// FullDelta - This is the full delta of all the values in this node and /// all children nodes. int FullDelta; public: DeltaTreeNode(bool isLeaf = true) : NumValuesUsed(0), IsLeaf(isLeaf), FullDelta(0) {} - + bool isLeaf() const { return IsLeaf; } int getFullDelta() const { return FullDelta; } bool isFull() const { return NumValuesUsed == 2*WidthFactor-1; } - + unsigned getNumValuesUsed() const { return NumValuesUsed; } const SourceDelta &getValue(unsigned i) const { assert(i < NumValuesUsed && "Invalid value #"); @@ -110,7 +110,7 @@ namespace { assert(i < NumValuesUsed && "Invalid value #"); return Values[i]; } - + /// DoInsertion - Do an insertion of the specified FileIndex/Delta pair into /// this node. If insertion is easy, do it and return false. Otherwise, /// split the node, populate InsertRes with info about the split, and return @@ -118,14 +118,14 @@ namespace { bool DoInsertion(unsigned FileIndex, int Delta, InsertResult *InsertRes); void DoSplit(InsertResult &InsertRes); - - + + /// RecomputeFullDeltaLocally - Recompute the FullDelta field by doing a /// local walk over our contained deltas. void RecomputeFullDeltaLocally(); - + void Destroy(); - + static inline bool classof(const DeltaTreeNode *) { return true; } }; } // end anonymous namespace @@ -142,14 +142,14 @@ namespace { friend class DeltaTreeNode; public: DeltaTreeInteriorNode() : DeltaTreeNode(false /*nonleaf*/) {} - + DeltaTreeInteriorNode(DeltaTreeNode *FirstChild) : DeltaTreeNode(false /*nonleaf*/) { FullDelta = FirstChild->FullDelta; Children[0] = FirstChild; } - - DeltaTreeInteriorNode(const InsertResult &IR) + + DeltaTreeInteriorNode(const InsertResult &IR) : DeltaTreeNode(false /*nonleaf*/) { Children[0] = IR.LHS; Children[1] = IR.RHS; @@ -157,7 +157,7 @@ namespace { FullDelta = IR.LHS->getFullDelta()+IR.RHS->getFullDelta()+IR.Split.Delta; NumValuesUsed = 1; } - + const DeltaTreeNode *getChild(unsigned i) const { assert(i < getNumValuesUsed()+1 && "Invalid child"); return Children[i]; @@ -166,7 +166,7 @@ namespace { assert(i < getNumValuesUsed()+1 && "Invalid child"); return Children[i]; } - + static inline bool classof(const DeltaTreeInteriorNode *) { return true; } static inline bool classof(const DeltaTreeNode *N) { return !N->isLeaf(); } }; @@ -197,16 +197,16 @@ void DeltaTreeNode::RecomputeFullDeltaLocally() { /// this node. If insertion is easy, do it and return false. Otherwise, /// split the node, populate InsertRes with info about the split, and return /// true. -bool DeltaTreeNode::DoInsertion(unsigned FileIndex, int Delta, +bool DeltaTreeNode::DoInsertion(unsigned FileIndex, int Delta, InsertResult *InsertRes) { // Maintain full delta for this node. FullDelta += Delta; - + // Find the insertion point, the first delta whose index is >= FileIndex. unsigned i = 0, e = getNumValuesUsed(); while (i != e && FileIndex > getValue(i).FileLoc) ++i; - + // If we found an a record for exactly this file index, just merge this // value into the pre-existing record and finish early. if (i != e && getValue(i).FileLoc == FileIndex) { @@ -230,19 +230,19 @@ bool DeltaTreeNode::DoInsertion(unsigned FileIndex, int Delta, ++NumValuesUsed; return false; } - + // Otherwise, if this is leaf is full, split the node at its median, insert // the value into one of the children, and return the result. assert(InsertRes && "No result location specified"); DoSplit(*InsertRes); - + if (InsertRes->Split.FileLoc > FileIndex) InsertRes->LHS->DoInsertion(FileIndex, Delta, 0 /*can't fail*/); else InsertRes->RHS->DoInsertion(FileIndex, Delta, 0 /*can't fail*/); return true; } - + // Otherwise, this is an interior node. Send the request down the tree. DeltaTreeInteriorNode *IN = cast<DeltaTreeInteriorNode>(this); if (!IN->Children[i]->DoInsertion(FileIndex, Delta, InsertRes)) @@ -259,21 +259,21 @@ bool DeltaTreeNode::DoInsertion(unsigned FileIndex, int Delta, (e-i)*sizeof(IN->Children[0])); IN->Children[i] = InsertRes->LHS; IN->Children[i+1] = InsertRes->RHS; - + if (e != i) memmove(&Values[i+1], &Values[i], (e-i)*sizeof(Values[0])); Values[i] = InsertRes->Split; ++NumValuesUsed; return false; } - + // Finally, if this interior node was full and a node is percolated up, split // ourself and return that up the chain. Start by saving all our info to // avoid having the split clobber it. IN->Children[i] = InsertRes->LHS; DeltaTreeNode *SubRHS = InsertRes->RHS; SourceDelta SubSplit = InsertRes->Split; - + // Do the split. DoSplit(*InsertRes); @@ -283,22 +283,22 @@ bool DeltaTreeNode::DoInsertion(unsigned FileIndex, int Delta, InsertSide = cast<DeltaTreeInteriorNode>(InsertRes->LHS); else InsertSide = cast<DeltaTreeInteriorNode>(InsertRes->RHS); - - // We now have a non-empty interior node 'InsertSide' to insert + + // We now have a non-empty interior node 'InsertSide' to insert // SubRHS/SubSplit into. Find out where to insert SubSplit. - + // Find the insertion point, the first delta whose index is >SubSplit.FileLoc. i = 0; e = InsertSide->getNumValuesUsed(); while (i != e && SubSplit.FileLoc > InsertSide->getValue(i).FileLoc) ++i; - + // Now we know that i is the place to insert the split value into. Insert it // and the child right after it. if (i != e) memmove(&InsertSide->Children[i+2], &InsertSide->Children[i+1], (e-i)*sizeof(IN->Children[0])); InsertSide->Children[i+1] = SubRHS; - + if (e != i) memmove(&InsertSide->Values[i+1], &InsertSide->Values[i], (e-i)*sizeof(Values[0])); @@ -313,12 +313,12 @@ bool DeltaTreeNode::DoInsertion(unsigned FileIndex, int Delta, /// Return the pieces in InsertRes. void DeltaTreeNode::DoSplit(InsertResult &InsertRes) { assert(isFull() && "Why split a non-full node?"); - + // Since this node is full, it contains 2*WidthFactor-1 values. We move // the first 'WidthFactor-1' values to the LHS child (which we leave in this // node), propagate one value up, and move the last 'WidthFactor-1' values // into the RHS child. - + // Create the new child node. DeltaTreeNode *NewNode; if (DeltaTreeInteriorNode *IN = dyn_cast<DeltaTreeInteriorNode>(this)) { @@ -332,18 +332,18 @@ void DeltaTreeNode::DoSplit(InsertResult &InsertRes) { // Just create the new leaf node. NewNode = new DeltaTreeNode(); } - + // Move over the last 'WidthFactor-1' values from here to NewNode. memcpy(&NewNode->Values[0], &Values[WidthFactor], (WidthFactor-1)*sizeof(Values[0])); - + // Decrease the number of values in the two nodes. NewNode->NumValuesUsed = NumValuesUsed = WidthFactor-1; - + // Recompute the two nodes' full delta. NewNode->RecomputeFullDeltaLocally(); RecomputeFullDeltaLocally(); - + InsertRes.LHS = this; InsertRes.RHS = NewNode; InsertRes.Split = Values[WidthFactor-1]; @@ -374,7 +374,7 @@ static void VerifyTree(const DeltaTreeNode *N) { assert(FullDelta == N->getFullDelta()); return; } - + // Verify interior nodes: Ensure that FullDelta matches up and the // elements are in proper order and the children are in proper order. int FullDelta = 0; @@ -385,18 +385,18 @@ static void VerifyTree(const DeltaTreeNode *N) { assert(IN->getValue(i-1).FileLoc < IVal.FileLoc); FullDelta += IVal.Delta; FullDelta += IChild->getFullDelta(); - + // The largest value in child #i should be smaller than FileLoc. assert(IChild->getValue(IChild->getNumValuesUsed()-1).FileLoc < IVal.FileLoc); - + // The smallest value in child #i+1 should be larger than FileLoc. assert(IN->getChild(i+1)->getValue(0).FileLoc > IVal.FileLoc); VerifyTree(IChild); } - + FullDelta += IN->getChild(IN->getNumValuesUsed())->getFullDelta(); - + assert(FullDelta == N->getFullDelta()); } #endif // VERIFY_TREE @@ -424,9 +424,9 @@ DeltaTree::~DeltaTree() { /// specified file index. int DeltaTree::getDeltaAt(unsigned FileIndex) const { const DeltaTreeNode *Node = getRoot(Root); - + int Result = 0; - + // Walk down the tree. while (1) { // For all nodes, include any local deltas before the specified file @@ -436,29 +436,29 @@ int DeltaTree::getDeltaAt(unsigned FileIndex) const { for (unsigned e = Node->getNumValuesUsed(); NumValsGreater != e; ++NumValsGreater) { const SourceDelta &Val = Node->getValue(NumValsGreater); - + if (Val.FileLoc >= FileIndex) break; Result += Val.Delta; } - + // If we have an interior node, include information about children and // recurse. Otherwise, if we have a leaf, we're done. const DeltaTreeInteriorNode *IN = dyn_cast<DeltaTreeInteriorNode>(Node); if (!IN) return Result; - + // Include any children to the left of the values we skipped, all of // their deltas should be included as well. for (unsigned i = 0; i != NumValsGreater; ++i) Result += IN->getChild(i)->getFullDelta(); - + // If we found exactly the value we were looking for, break off the // search early. There is no need to search the RHS of the value for // partial results. if (NumValsGreater != Node->getNumValuesUsed() && Node->getValue(NumValsGreater).FileLoc == FileIndex) return Result+IN->getChild(NumValsGreater)->getFullDelta(); - + // Otherwise, traverse down the tree. The selected subtree may be // partially included in the range. Node = IN->getChild(NumValsGreater); @@ -472,12 +472,12 @@ int DeltaTree::getDeltaAt(unsigned FileIndex) const { void DeltaTree::AddDelta(unsigned FileIndex, int Delta) { assert(Delta && "Adding a noop?"); DeltaTreeNode *MyRoot = getRoot(Root); - + InsertResult InsertRes; if (MyRoot->DoInsertion(FileIndex, Delta, &InsertRes)) { Root = MyRoot = new DeltaTreeInteriorNode(InsertRes); } - + #ifdef VERIFY_TREE VerifyTree(MyRoot); #endif diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 925fa55312..7326890ded 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -39,10 +39,10 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E, unsigned BOffset = SM.getFileOffset(B); unsigned EOffset = SM.getFileOffset(E); - + // Include the whole end token in the range. EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts()); - + HighlightRange(R.getEditBuffer(FID), BOffset, EOffset, SM.getBufferData(FID).first, StartTag, EndTag); } @@ -55,11 +55,11 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E, // Insert the tag at the absolute start/end of the range. RB.InsertTextAfter(B, StartTag); RB.InsertTextBefore(E, EndTag); - + // Scan the range to see if there is a \r or \n. If so, and if the line is // not blank, insert tags on that line as well. bool HadOpenTag = true; - + unsigned LastNonWhiteSpace = B; for (unsigned i = B; i != E; ++i) { switch (BufferStart[i]) { @@ -69,7 +69,7 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E, // to insert a close tag at the first non-whitespace before the newline. if (HadOpenTag) RB.InsertTextBefore(LastNonWhiteSpace+1, EndTag); - + // Instead of inserting an open tag immediately after the newline, we // wait until we see a non-whitespace character. This prevents us from // inserting tags around blank lines, and also allows the open tag to @@ -83,14 +83,14 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E, case '\v': // Ignore whitespace. break; - + default: // If there is no tag open, do it now. if (!HadOpenTag) { RB.InsertTextAfter(i, StartTag); HadOpenTag = true; } - + // Remember this character. LastNonWhiteSpace = i; break; @@ -100,13 +100,13 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E, void html::EscapeText(Rewriter &R, FileID FID, bool EscapeSpaces, bool ReplaceTabs) { - + const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID); const char* C = Buf->getBufferStart(); const char* FileEnd = Buf->getBufferEnd(); - + assert (C <= FileEnd); - + RewriteBuffer &RB = R.getEditBuffer(FID); unsigned ColNo = 0; @@ -117,7 +117,7 @@ void html::EscapeText(Rewriter &R, FileID FID, case '\r': ColNo = 0; break; - + case ' ': if (EscapeSpaces) RB.ReplaceText(FilePos, 1, " "); @@ -127,7 +127,7 @@ void html::EscapeText(Rewriter &R, FileID FID, RB.ReplaceText(FilePos, 1, "<hr>"); ColNo = 0; break; - + case '\t': { if (!ReplaceTabs) break; @@ -145,12 +145,12 @@ void html::EscapeText(Rewriter &R, FileID FID, RB.ReplaceText(FilePos, 1, "<"); ++ColNo; break; - + case '>': RB.ReplaceText(FilePos, 1, ">"); ++ColNo; break; - + case '&': RB.ReplaceText(FilePos, 1, "&"); ++ColNo; @@ -161,23 +161,23 @@ void html::EscapeText(Rewriter &R, FileID FID, std::string html::EscapeText(const std::string& s, bool EscapeSpaces, bool ReplaceTabs) { - + unsigned len = s.size(); std::string Str; llvm::raw_string_ostream os(Str); - + for (unsigned i = 0 ; i < len; ++i) { - + char c = s[i]; switch (c) { default: os << c; break; - + case ' ': if (EscapeSpaces) os << " "; else os << ' '; break; - + case '\t': if (ReplaceTabs) { if (EscapeSpaces) @@ -187,17 +187,17 @@ std::string html::EscapeText(const std::string& s, bool EscapeSpaces, for (unsigned i = 0; i < 4; ++i) os << " "; } - else + else os << c; - + break; - + case '<': os << "<"; break; case '>': os << ">"; break; case '&': os << "&"; break; } } - + return os.str(); } @@ -209,7 +209,7 @@ static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo, OS << "<tr><td class=\"num\" id=\"LN" << LineNo << "\">" << LineNo << "</td><td class=\"line\">"; - + if (B == E) { // Handle empty lines. OS << " </td></tr>"; RB.InsertTextBefore(B, OS.str()); @@ -226,44 +226,44 @@ void html::AddLineNumbers(Rewriter& R, FileID FID) { const char* FileEnd = Buf->getBufferEnd(); const char* C = FileBeg; RewriteBuffer &RB = R.getEditBuffer(FID); - + assert (C <= FileEnd); - + unsigned LineNo = 0; unsigned FilePos = 0; - - while (C != FileEnd) { - + + while (C != FileEnd) { + ++LineNo; unsigned LineStartPos = FilePos; unsigned LineEndPos = FileEnd - FileBeg; - + assert (FilePos <= LineEndPos); assert (C < FileEnd); - + // Scan until the newline (or end-of-file). - + while (C != FileEnd) { char c = *C; ++C; - + if (c == '\n') { LineEndPos = FilePos++; break; } - + ++FilePos; } - + AddLineNumber(RB, LineNo, LineStartPos, LineEndPos); } - + // Add one big table tag that surrounds all of the code. RB.InsertTextBefore(0, "<table class=\"code\">\n"); RB.InsertTextAfter(FileEnd - FileBeg, "</table>"); } -void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, +void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, const char *title) { const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID); @@ -277,10 +277,10 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, llvm::raw_string_ostream os(s); os << "<!doctype html>\n" // Use HTML 5 doctype "<html>\n<head>\n"; - + if (title) os << "<title>" << html::EscapeText(title) << "</title>\n"; - + os << "<style type=\"text/css\">\n" " body { color:#000000; background-color:#ffffff }\n" " body { font-family:Helvetica, sans-serif; font-size:10pt }\n" @@ -341,7 +341,7 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, // Generate header R.InsertTextBefore(StartLoc, os.str()); // Generate footer - + R.InsertTextAfter(EndLoc, "</body></html>\n"); } @@ -355,16 +355,16 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { const SourceManager &SM = PP.getSourceManager(); Lexer L(FID, SM, PP.getLangOptions()); const char *BufferStart = L.getBufferStart(); - - // Inform the preprocessor that we want to retain comments as tokens, so we + + // Inform the preprocessor that we want to retain comments as tokens, so we // can highlight them. L.SetCommentRetentionState(true); - + // Lex all the tokens in raw mode, to avoid entering #includes or expanding // macros. Token Tok; L.LexFromRawLexer(Tok); - + while (Tok.isNot(tok::eof)) { // Since we are lexing unexpanded tokens, all tokens are from the main // FileID. @@ -376,7 +376,7 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { // Fill in Result.IdentifierInfo, looking up the identifier in the // identifier table. IdentifierInfo *II = PP.LookUpIdentifierInfo(Tok, BufferStart+TokOffs); - + // If this is a pp-identifier, for a keyword, highlight it as such. if (II->getTokenID() != tok::identifier) HighlightRange(RB, TokOffs, TokOffs+TokLen, BufferStart, @@ -400,7 +400,7 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { // If this is a preprocessor directive, all tokens to end of line are too. if (!Tok.isAtStartOfLine()) break; - + // Eat all of the tokens until we get to the next one at the start of // line. unsigned TokEnd = TokOffs+TokLen; @@ -409,16 +409,16 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { TokEnd = SM.getFileOffset(Tok.getLocation())+Tok.getLength(); L.LexFromRawLexer(Tok); } - + // Find end of line. This is a hack. HighlightRange(RB, TokOffs, TokEnd, BufferStart, "<span class='directive'>", "</span>"); - + // Don't skip the next token. continue; } } - + L.LexFromRawLexer(Tok); } } @@ -442,15 +442,15 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { // Re-lex the raw token stream into a token buffer. const SourceManager &SM = PP.getSourceManager(); std::vector<Token> TokenStream; - + Lexer L(FID, SM, PP.getLangOptions()); - + // Lex all the tokens in raw mode, to avoid entering #includes or expanding // macros. while (1) { Token Tok; L.LexFromRawLexer(Tok); - + // If this is a # at the start of a line, discard it from the token stream. // We don't want the re-preprocess step to see #defines, #includes or other // preprocessor directives. @@ -461,7 +461,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { // it will not produce an error. if (Tok.is(tok::hashhash)) Tok.setKind(tok::unknown); - + // If this raw token is an identifier, the raw lexer won't have looked up // the corresponding identifier info for it. Do this now so that it will be // macro expanded when we re-preprocess it. @@ -469,30 +469,30 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { // Change the kind of this identifier to the appropriate token kind, e.g. // turning "for" into a keyword. Tok.setKind(PP.LookUpIdentifierInfo(Tok)->getTokenID()); - } - + } + TokenStream.push_back(Tok); - + if (Tok.is(tok::eof)) break; } - + // Temporarily change the diagnostics object so that we ignore any generated // diagnostics from this pass. IgnoringDiagClient TmpDC; Diagnostic TmpDiags(&TmpDC); - + Diagnostic *OldDiags = &PP.getDiagnostics(); PP.setDiagnostics(TmpDiags); - + // Inform the preprocessor that we don't want comments. PP.SetCommentRetentionState(false, false); // Enter the tokens we just lexed. This will cause them to be macro expanded // but won't enter sub-files (because we removed #'s). PP.EnterTokenStream(&TokenStream[0], TokenStream.size(), false, false); - + TokenConcatenation ConcatInfo(PP); - + // Lex all the tokens. Token Tok; PP.Lex(Tok); @@ -502,13 +502,13 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { PP.Lex(Tok); continue; } - + // Okay, we have the first token of a macro expansion: highlight the // instantiation by inserting a start tag before the macro instantiation and // end tag after it. std::pair<SourceLocation, SourceLocation> LLoc = SM.getInstantiationRange(Tok.getLocation()); - + // Ignore tokens whose instantiation location was not the main file. if (SM.getFileID(LLoc.first) != FID) { PP.Lex(Tok); @@ -520,11 +520,11 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { std::string Expansion = EscapeText(PP.getSpelling(Tok)); unsigned LineLen = Expansion.size(); - + Token PrevTok = Tok; // Okay, eat this token, getting the next one. PP.Lex(Tok); - + // Skip all the rest of the tokens that are part of this macro // instantiation. It would be really nice to pop up a window with all the // spelling of the tokens or something. @@ -535,23 +535,23 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { Expansion += "<br>"; LineLen = 0; } - + LineLen -= Expansion.size(); - + // If the tokens were already space separated, or if they must be to avoid // them being implicitly pasted, add a space between them. if (Tok.hasLeadingSpace() || ConcatInfo.AvoidConcat(PrevTok, Tok)) Expansion += ' '; - + // Escape any special characters in the token text. Expansion += EscapeText(PP.getSpelling(Tok)); LineLen += Expansion.size(); - + PrevTok = Tok; PP.Lex(Tok); } - + // Insert the expansion as the end tag, so that multi-line macros all get // highlighted. @@ -567,7 +567,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { void html::HighlightMacros(Rewriter &R, FileID FID, PreprocessorFactory &PPF) { - + llvm::OwningPtr<Preprocessor> PP(PPF.CreatePreprocessor()); HighlightMacros(R, FID, *PP); } diff --git a/lib/Rewrite/RewriteRope.cpp b/lib/Rewrite/RewriteRope.cpp index 61cb02b9a5..30bbcfafb5 100644 --- a/lib/Rewrite/RewriteRope.cpp +++ b/lib/Rewrite/RewriteRope.cpp @@ -81,24 +81,24 @@ namespace { /// the root, which may have less) and may have at most 2*WidthFactor /// elements. enum { WidthFactor = 8 }; - + /// Size - This is the number of bytes of file this node (including any /// potential children) covers. unsigned Size; - + /// IsLeaf - True if this is an instance of RopePieceBTreeLeaf, false if it /// is an instance of RopePieceBTreeInterior. bool IsLeaf; - + RopePieceBTreeNode(bool isLeaf) : Size(0), IsLeaf(isLeaf) {} ~RopePieceBTreeNode() {} public: - + bool isLeaf() const { return IsLeaf; } unsigned size() const { return Size; } - + void Destroy(); - + /// split - Split the range containing the specified offset so that we are /// guaranteed that there is a place to do an insertion at the specified /// offset. The offset is relative, so "0" is the start of the node. @@ -106,7 +106,7 @@ namespace { /// If there is no space in this subtree for the extra piece, the extra tree /// node is returned and must be inserted into a parent. RopePieceBTreeNode *split(unsigned Offset); - + /// insert - Insert the specified ropepiece into this tree node at the /// specified offset. The offset is relative, so "0" is the start of the /// node. @@ -114,13 +114,13 @@ namespace { /// If there is no space in this subtree for the extra piece, the extra tree /// node is returned and must be inserted into a parent. RopePieceBTreeNode *insert(unsigned Offset, const RopePiece &R); - + /// erase - Remove NumBytes from this node at the specified offset. We are /// guaranteed that there is a split at Offset. void erase(unsigned Offset, unsigned NumBytes); - + static inline bool classof(const RopePieceBTreeNode *) { return true; } - + }; } // end anonymous namespace @@ -140,11 +140,11 @@ namespace { /// NumPieces - This holds the number of rope pieces currently active in the /// Pieces array. unsigned char NumPieces; - + /// Pieces - This tracks the file chunks currently in this leaf. /// RopePiece Pieces[2*WidthFactor]; - + /// NextLeaf - This is a pointer to the next leaf in the tree, allowing /// efficient in-order forward iteration of the tree without traversal. RopePieceBTreeLeaf **PrevLeaf, *NextLeaf; @@ -155,34 +155,34 @@ namespace { if (PrevLeaf || NextLeaf) removeFromLeafInOrder(); } - + bool isFull() const { return NumPieces == 2*WidthFactor; } - + /// clear - Remove all rope pieces from this leaf. void clear() { while (NumPieces) Pieces[--NumPieces] = RopePiece(); Size = 0; } - + unsigned getNumPieces() const { return NumPieces; } - + const RopePiece &getPiece(unsigned i) const { assert(i < getNumPieces() && "Invalid piece ID"); return Pieces[i]; } - + const RopePieceBTreeLeaf *getNextLeafInOrder() const { return NextLeaf; } void insertAfterLeafInOrder(RopePieceBTreeLeaf *Node) { assert(PrevLeaf == 0 && NextLeaf == 0 && "Already in ordering"); - + NextLeaf = Node->NextLeaf; if (NextLeaf) NextLeaf->PrevLeaf = &NextLeaf; PrevLeaf = &Node->NextLeaf; Node->NextLeaf = this; } - + void removeFromLeafInOrder() { if (PrevLeaf) { *PrevLeaf = NextLeaf; @@ -192,7 +192,7 @@ namespace { NextLeaf->PrevLeaf = 0; } } - + /// FullRecomputeSizeLocally - This method recomputes the 'Size' field by /// summing the size of all RopePieces. void FullRecomputeSizeLocally() { @@ -200,7 +200,7 @@ namespace { for (unsigned i = 0, e = getNumPieces(); i != e; ++i) Size += getPiece(i).size(); } - + /// split - Split the range containing the specified offset so that we are /// guaranteed that there is a place to do an insertion at the specified /// offset. The offset is relative, so "0" is the start of the node. @@ -208,7 +208,7 @@ namespace { /// If there is no space in this subtree for the extra piece, the extra tree /// node is returned and must be inserted into a parent. RopePieceBTreeNode *split(unsigned Offset); - + /// insert - Insert the specified ropepiece into this tree node at the /// specified offset. The offset is relative, so "0" is the start of the /// node. @@ -216,12 +216,12 @@ namespace { /// If there is no space in this subtree for the extra piece, the extra tree /// node is returned and must be inserted into a parent. RopePieceBTreeNode *insert(unsigned Offset, const RopePiece &R); - - + + /// erase - Remove NumBytes from this node at the specified offset. We are /// guaranteed that there is a split at Offset. void erase(unsigned Offset, unsigned NumBytes); - + static inline bool classof(const RopePieceBTreeLeaf *) { return true; } static inline bool classof(const RopePieceBTreeNode *N) { return N->isLeaf(); @@ -242,7 +242,7 @@ RopePieceBTreeNode *RopePieceBTreeLeaf::split(unsigned Offset) { // Fastpath for a common case. There is already a splitpoint at the end. return 0; } - + // Find the piece that this offset lands in. unsigned PieceOffs = 0; unsigned i = 0; @@ -250,23 +250,23 @@ RopePieceBTreeNode *RopePieceBTreeLeaf::split(unsigned Offset) { PieceOffs += Pieces[i].size(); ++i; } - + // If there is already a split point at the specified offset, just return // success. if (PieceOffs == Offset) return 0; - + // Otherwise, we need to split piece 'i' at Offset-PieceOffs. Convert Offset // to being Piece relative. unsigned IntraPieceOffset = Offset-PieceOffs; - + // We do this by shrinking the RopePiece and then doing an insert of the tail. RopePiece Tail(Pieces[i].StrData, Pieces[i].StartOffs+IntraPieceOffset, Pieces[i].EndOffs); Size -= Pieces[i].size(); Pieces[i].EndOffs = Pieces[i].StartOffs+IntraPieceOffset; Size += Pieces[i].size(); - + return insert(Offset, Tail); } @@ -292,7 +292,7 @@ RopePieceBTreeNode *RopePieceBTreeLeaf::insert(unsigned Offset, SlotOffs += getPiece(i).size(); assert(SlotOffs == Offset && "Split didn't occur before insertion!"); } - + // For an insertion into a non-full leaf node, just insert the value in // its sorted position. This requires moving later values over. for (; i != e; --e) @@ -302,31 +302,31 @@ RopePieceBTreeNode *RopePieceBTreeLeaf::insert(unsigned Offset, Size += R.size(); return 0; } - + // Otherwise, if this is leaf is full, split it in two halves. Since this // node is full, it contains 2*WidthFactor values. We move the first // 'WidthFactor' values to the LHS child (which we leave in this node) and // move the last 'WidthFactor' values into the RHS child. - + // Create the new node. RopePieceBTreeLeaf *NewNode = new RopePieceBTreeLeaf(); - + // Move over the last 'WidthFactor' values from here to NewNode. std::copy(&Pieces[WidthFactor], &Pieces[2*WidthFactor], &NewNode->Pieces[0]); // Replace old pieces with null RopePieces to drop refcounts. std::fill(&Pieces[WidthFactor], &Pieces[2*WidthFactor], RopePiece()); - + // Decrease the number of values in the two nodes. NewNode->NumPieces = NumPieces = WidthFactor; - + // Recompute the two nodes' size. NewNode->FullRecomputeSizeLocally(); |