summaryrefslogtreecommitdiffstats
path: root/include/clang/Rewrite
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Rewrite')
-rw-r--r--include/clang/Rewrite/Core/DeltaTree.h50
-rw-r--r--include/clang/Rewrite/Core/HTMLRewrite.h81
-rw-r--r--include/clang/Rewrite/Core/RewriteBuffer.h117
-rw-r--r--include/clang/Rewrite/Core/RewriteRope.h214
-rw-r--r--include/clang/Rewrite/Core/Rewriter.h195
-rw-r--r--include/clang/Rewrite/Core/TokenRewriter.h79
-rw-r--r--include/clang/Rewrite/Frontend/ASTConsumers.h48
-rw-r--r--include/clang/Rewrite/Frontend/FixItRewriter.h132
-rw-r--r--include/clang/Rewrite/Frontend/FrontendActions.h83
-rw-r--r--include/clang/Rewrite/Frontend/Rewriters.h35
10 files changed, 0 insertions, 1034 deletions
diff --git a/include/clang/Rewrite/Core/DeltaTree.h b/include/clang/Rewrite/Core/DeltaTree.h
deleted file mode 100644
index fbffb38..0000000
--- a/include/clang/Rewrite/Core/DeltaTree.h
+++ /dev/null
@@ -1,50 +0,0 @@
-//===--- DeltaTree.h - B-Tree for Rewrite Delta tracking --------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the DeltaTree class.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_DELTATREE_H
-#define LLVM_CLANG_REWRITE_CORE_DELTATREE_H
-
-#include "llvm/Support/Compiler.h"
-
-namespace clang {
-
- /// DeltaTree - a multiway search tree (BTree) structure with some fancy
- /// features. B-Trees are generally more memory and cache efficient than
- /// binary trees, because they store multiple keys/values in each node. This
- /// implements a key/value mapping from index to delta, and allows fast lookup
- /// on index. However, an added (important) bonus is that it can also
- /// efficiently tell us the full accumulated delta for a specific file offset
- /// as well, without traversing the whole tree.
- class DeltaTree {
- void *Root; // "DeltaTreeNode *"
- void operator=(const DeltaTree &) = delete;
- public:
- DeltaTree();
-
- // Note: Currently we only support copying when the RHS is empty.
- DeltaTree(const DeltaTree &RHS);
- ~DeltaTree();
-
- /// getDeltaAt - Return the accumulated delta at the specified file offset.
- /// This includes all insertions or delections that occurred *before* the
- /// specified file index.
- int getDeltaAt(unsigned FileIndex) const;
-
- /// AddDelta - When a change is made that shifts around the text buffer,
- /// this method is used to record that info. It inserts a delta of 'Delta'
- /// into the current DeltaTree at offset FileIndex.
- void AddDelta(unsigned FileIndex, int Delta);
- };
-} // end namespace clang
-
-#endif
diff --git a/include/clang/Rewrite/Core/HTMLRewrite.h b/include/clang/Rewrite/Core/HTMLRewrite.h
deleted file mode 100644
index dafdf51..0000000
--- a/include/clang/Rewrite/Core/HTMLRewrite.h
+++ /dev/null
@@ -1,81 +0,0 @@
-//==- HTMLRewrite.h - Translate source code into prettified HTML ---*- C++ -*-//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines a set of functions used for translating source code
-// into beautified HTML.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_HTMLREWRITE_H
-#define LLVM_CLANG_REWRITE_CORE_HTMLREWRITE_H
-
-#include "clang/Basic/SourceLocation.h"
-#include <string>
-
-namespace clang {
-
-class Rewriter;
-class RewriteBuffer;
-class Preprocessor;
-
-namespace html {
-
- /// HighlightRange - Highlight a range in the source code with the specified
- /// start/end tags. B/E must be in the same file. This ensures that
- /// start/end tags are placed at the start/end of each line if the range is
- /// multiline.
- void HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
- const char *StartTag, const char *EndTag);
-
- /// HighlightRange - Highlight a range in the source code with the specified
- /// start/end tags. The Start/end of the range must be in the same file.
- /// This ensures that start/end tags are placed at the start/end of each line
- /// if the range is multiline.
- inline void HighlightRange(Rewriter &R, SourceRange Range,
- const char *StartTag, const char *EndTag) {
- HighlightRange(R, Range.getBegin(), Range.getEnd(), StartTag, EndTag);
- }
-
- /// HighlightRange - This is the same as the above method, but takes
- /// decomposed file locations.
- void HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
- const char *BufferStart,
- const char *StartTag, const char *EndTag);
-
- /// EscapeText - HTMLize a specified file so that special characters are
- /// are translated so that they are not interpreted as HTML tags.
- void EscapeText(Rewriter& R, FileID FID,
- bool EscapeSpaces = false, bool ReplaceTabs = false);
-
- /// EscapeText - HTMLized the provided string so that special characters
- /// in 's' are not interpreted as HTML tags. Unlike the version of
- /// EscapeText that rewrites a file, this version by default replaces tabs
- /// with spaces.
- std::string EscapeText(StringRef s,
- bool EscapeSpaces = false, bool ReplaceTabs = false);
-
- void AddLineNumbers(Rewriter& R, FileID FID);
-
- void AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID,
- const char *title = nullptr);
-
- /// SyntaxHighlight - Relex the specified FileID and annotate the HTML with
- /// information about keywords, comments, etc.
- void SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP);
-
- /// HighlightMacros - This uses the macro table state from the end of the
- /// file, to reexpand macros and insert (into the HTML) information about the
- /// macro expansions. This won't be perfectly perfect, but it will be
- /// reasonably close.
- void HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP);
-
-} // end html namespace
-} // end clang namespace
-
-#endif
diff --git a/include/clang/Rewrite/Core/RewriteBuffer.h b/include/clang/Rewrite/Core/RewriteBuffer.h
deleted file mode 100644
index d69c69b..0000000
--- a/include/clang/Rewrite/Core/RewriteBuffer.h
+++ /dev/null
@@ -1,117 +0,0 @@
-//===--- RewriteBuffer.h - Buffer rewriting interface -----------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_REWRITEBUFFER_H
-#define LLVM_CLANG_REWRITE_CORE_REWRITEBUFFER_H
-
-#include "clang/Basic/LLVM.h"
-#include "clang/Rewrite/Core/DeltaTree.h"
-#include "clang/Rewrite/Core/RewriteRope.h"
-#include "llvm/ADT/StringRef.h"
-
-namespace clang {
- class Rewriter;
-
-/// RewriteBuffer - As code is rewritten, SourceBuffer's from the original
-/// input with modifications get a new RewriteBuffer associated with them. The
-/// RewriteBuffer captures the modified text itself as well as information used
-/// to map between SourceLocation's in the original input and offsets in the
-/// RewriteBuffer. For example, if text is inserted into the buffer, any
-/// locations after the insertion point have to be mapped.
-class RewriteBuffer {
- friend class Rewriter;
- /// Deltas - Keep track of all the deltas in the source code due to insertions
- /// and deletions.
- DeltaTree Deltas;
- RewriteRope Buffer;
-public:
- typedef RewriteRope::const_iterator iterator;
- iterator begin() const { return Buffer.begin(); }
- iterator end() const { return Buffer.end(); }
- unsigned size() const { return Buffer.size(); }
-
- /// Initialize - Start this rewrite buffer out with a copy of the unmodified
- /// input buffer.
- void Initialize(const char *BufStart, const char *BufEnd) {
- Buffer.assign(BufStart, BufEnd);
- }
- void Initialize(StringRef Input) {
- Initialize(Input.begin(), Input.end());
- }
-
- /// \brief Write to \p Stream the result of applying all changes to the
- /// original buffer.
- /// Note that it isn't safe to use this function to overwrite memory mapped
- /// files in-place (PR17960). Consider using a higher-level utility such as
- /// Rewriter::overwriteChangedFiles() instead.
- ///
- /// The original buffer is not actually changed.
- raw_ostream &write(raw_ostream &Stream) const;
-
- /// RemoveText - Remove the specified text.
- void RemoveText(unsigned OrigOffset, unsigned Size,
- bool removeLineIfEmpty = false);
-
- /// InsertText - Insert some text at the specified point, where the offset in
- /// the buffer is specified relative to the original SourceBuffer. The
- /// text is inserted after the specified location.
- ///
- void InsertText(unsigned OrigOffset, StringRef Str,
- bool InsertAfter = true);
-
-
- /// InsertTextBefore - Insert some text before the specified point, where the
- /// offset in the buffer is specified relative to the original
- /// SourceBuffer. The text is inserted before the specified location. This is
- /// method is the same as InsertText with "InsertAfter == false".
- void InsertTextBefore(unsigned OrigOffset, StringRef Str) {
- InsertText(OrigOffset, Str, false);
- }
-
- /// InsertTextAfter - Insert some text at the specified point, where the
- /// offset in the buffer is specified relative to the original SourceBuffer.
- /// The text is inserted after the specified location.
- void InsertTextAfter(unsigned OrigOffset, StringRef Str) {
- InsertText(OrigOffset, Str);
- }
-
- /// ReplaceText - This method replaces a range of characters in the input
- /// buffer with a new string. This is effectively a combined "remove/insert"
- /// operation.
- void ReplaceText(unsigned OrigOffset, unsigned OrigLength,
- StringRef NewStr);
-
-private: // Methods only usable by Rewriter.
-
- /// getMappedOffset - Given an offset into the original SourceBuffer that this
- /// RewriteBuffer is based on, map it into the offset space of the
- /// RewriteBuffer. If AfterInserts is true and if the OrigOffset indicates a
- /// position where text is inserted, the location returned will be after any
- /// inserted text at the position.
- unsigned getMappedOffset(unsigned OrigOffset,
- bool AfterInserts = false) const{
- return Deltas.getDeltaAt(2*OrigOffset+AfterInserts)+OrigOffset;
- }
-
- /// 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);
- }
-};
-
-} // end namespace clang
-
-#endif
diff --git a/include/clang/Rewrite/Core/RewriteRope.h b/include/clang/Rewrite/Core/RewriteRope.h
deleted file mode 100644
index 5002554..0000000
--- a/include/clang/Rewrite/Core/RewriteRope.h
+++ /dev/null
@@ -1,214 +0,0 @@
-//===--- RewriteRope.h - Rope specialized for rewriter ----------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the RewriteRope class, which is a powerful string class.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_REWRITEROPE_H
-#define LLVM_CLANG_REWRITE_CORE_REWRITEROPE_H
-
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Compiler.h"
-#include <cassert>
-#include <cstddef>
-#include <cstring>
-#include <iterator>
-
-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
- /// through the RopePiece class below.
- struct RopeRefCountString {
- unsigned RefCount;
- char Data[1]; // Variable sized.
-
- void Retain() { ++RefCount; }
-
- void Release() {
- assert(RefCount > 0 && "Reference count is already zero.");
- if (--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.
- ///
- /// For example, we could have a 1M RopePiece and want to insert something
- /// into the middle of it. To do this, we split it into two RopePiece objects
- /// that both refer to the same underlying RopeRefCountString (just with
- /// different offsets) which is a nice constant time operation.
- struct RopePiece {
- llvm::IntrusiveRefCntPtr<RopeRefCountString> StrData;
- unsigned StartOffs;
- unsigned EndOffs;
-
- RopePiece() : StrData(nullptr), StartOffs(0), EndOffs(0) {}
-
- RopePiece(llvm::IntrusiveRefCntPtr<RopeRefCountString> Str, unsigned Start,
- unsigned End)
- : StrData(std::move(Str)), StartOffs(Start), EndOffs(End) {}
-
- 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,
- /// then iterates over RopePieceBTreeLeaf's in a RopePieceBTree.
- class RopePieceBTreeIterator :
- public std::iterator<std::forward_iterator_tag, const char, ptrdiff_t> {
- /// CurNode - The current B+Tree node that we are inspecting.
- const void /*RopePieceBTreeLeaf*/ *CurNode;
- /// CurPiece - The current RopePiece in the B+Tree node that we're
- /// inspecting.
- const RopePiece *CurPiece;
- /// CurChar - The current byte in the RopePiece we are pointing to.
- unsigned CurChar;
- public:
- // begin iterator.
- RopePieceBTreeIterator(const void /*RopePieceBTreeNode*/ *N);
- // end iterator
- RopePieceBTreeIterator()
- : CurNode(nullptr), CurPiece(nullptr), 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;
- else
- MoveToNextPiece();
- return *this;
- }
- inline RopePieceBTreeIterator operator++(int) { // Postincrement
- RopePieceBTreeIterator tmp = *this; ++*this; return tmp;
- }
-
- llvm::StringRef piece() const {
- return llvm::StringRef(&(*CurPiece)[0], CurPiece->size());
- }
-
- void MoveToNextPiece();
- };
-
- //===--------------------------------------------------------------------===//
- // RopePieceBTree Class
- //===--------------------------------------------------------------------===//
-
- class RopePieceBTree {
- void /*RopePieceBTreeNode*/ *Root;
- void operator=(const RopePieceBTree &) = delete;
- public:
- 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);
- };
-
- //===--------------------------------------------------------------------===//
- // 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.
- llvm::IntrusiveRefCntPtr<RopeRefCountString> AllocBuffer;
- unsigned AllocOffs;
- enum { AllocChunkSize = 4080 };
-
-public:
- RewriteRope() : AllocBuffer(nullptr), AllocOffs(AllocChunkSize) {}
- RewriteRope(const RewriteRope &RHS)
- : Chunks(RHS.Chunks), AllocBuffer(nullptr), AllocOffs(AllocChunkSize) {
- }
-
- 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;
- Chunks.insert(Offset, MakeRopeString(Start, End));
- }
-
- void erase(unsigned Offset, unsigned NumBytes) {
- assert(Offset+NumBytes <= size() && "Invalid region to erase!");
- if (NumBytes == 0) return;
- Chunks.erase(Offset, NumBytes);
- }
-
-private:
- RopePiece MakeRopeString(const char *Start, const char *End);
-};
-
-} // end namespace clang
-
-#endif
diff --git a/include/clang/Rewrite/Core/Rewriter.h b/include/clang/Rewrite/Core/Rewriter.h
deleted file mode 100644
index 800372e..0000000
--- a/include/clang/Rewrite/Core/Rewriter.h
+++ /dev/null
@@ -1,195 +0,0 @@
-//===--- Rewriter.h - Code rewriting interface ------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the Rewriter class, which is used for code
-// transformations.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_REWRITER_H
-#define LLVM_CLANG_REWRITE_CORE_REWRITER_H
-
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Rewrite/Core/RewriteBuffer.h"
-#include <cstring>
-#include <map>
-#include <string>
-
-namespace clang {
- class LangOptions;
- class SourceManager;
-
-/// Rewriter - This is the main interface to the rewrite buffers. Its primary
-/// job is to dispatch high-level requests to the low-level RewriteBuffers that
-/// are involved.
-class Rewriter {
- SourceManager *SourceMgr;
- const LangOptions *LangOpts;
- std::map<FileID, RewriteBuffer> RewriteBuffers;
-public:
- struct RewriteOptions {
- /// \brief Given a source range, true to include previous inserts at the
- /// beginning of the range as part of the range itself (true by default).
- bool IncludeInsertsAtBeginOfRange;
- /// \brief Given a source range, true to include previous inserts at the
- /// end of the range as part of the range itself (true by default).
- bool IncludeInsertsAtEndOfRange;
- /// \brief If true and removing some text leaves a blank line
- /// also remove the empty line (false by default).
- bool RemoveLineIfEmpty;
-
- RewriteOptions()
- : IncludeInsertsAtBeginOfRange(true),
- IncludeInsertsAtEndOfRange(true),
- RemoveLineIfEmpty(false) { }
- };
-
- typedef std::map<FileID, RewriteBuffer>::iterator buffer_iterator;
- typedef std::map<FileID, RewriteBuffer>::const_iterator const_buffer_iterator;
-
- explicit Rewriter(SourceManager &SM, const LangOptions &LO)
- : SourceMgr(&SM), LangOpts(&LO) {}
- explicit Rewriter() : SourceMgr(nullptr), LangOpts(nullptr) {}
-
- void setSourceMgr(SourceManager &SM, const LangOptions &LO) {
- SourceMgr = &SM;
- LangOpts = &LO;
- }
- SourceManager &getSourceMgr() const { return *SourceMgr; }
- const LangOptions &getLangOpts() const { return *LangOpts; }
-
- /// isRewritable - Return true if this location is a raw file location, which
- /// is rewritable. Locations from macros, etc are not rewritable.
- static bool isRewritable(SourceLocation Loc) {
- return Loc.isFileID();
- }
-
- /// getRangeSize - Return the size in bytes of the specified range if they
- /// are in the same file. If not, this returns -1.
- int getRangeSize(SourceRange Range,
- RewriteOptions opts = RewriteOptions()) const;
- int getRangeSize(const CharSourceRange &Range,
- RewriteOptions opts = RewriteOptions()) const;
-
- /// getRewrittenText - Return the rewritten form of the text in the specified
- /// range. If the start or end of the range was unrewritable or if they are
- /// in different buffers, this returns an empty string.
- ///
- /// Note that this method is not particularly efficient.
- ///
- std::string getRewrittenText(SourceRange Range) const;
-
- /// InsertText - Insert the specified string at the specified location in the
- /// original buffer. This method returns true (and does nothing) if the input
- /// location was not rewritable, false otherwise.
- ///
- /// \param indentNewLines if true new lines in the string are indented
- /// using the indentation of the source line in position \p Loc.
- bool InsertText(SourceLocation Loc, StringRef Str,
- bool InsertAfter = true, bool indentNewLines = false);
-
- /// InsertTextAfter - Insert the specified string at the specified location in
- /// the original buffer. This method returns true (and does nothing) if
- /// the input location was not rewritable, false otherwise. Text is
- /// inserted after any other text that has been previously inserted
- /// at the some point (the default behavior for InsertText).
- bool InsertTextAfter(SourceLocation Loc, StringRef Str) {
- return InsertText(Loc, Str);
- }
-
- /// \brief Insert the specified string after the token in the
- /// specified location.
- bool InsertTextAfterToken(SourceLocation Loc, StringRef Str);
-
- /// InsertText - Insert the specified string at the specified location in the
- /// original buffer. This method returns true (and does nothing) if the input
- /// location was not rewritable, false otherwise. Text is
- /// inserted before any other text that has been previously inserted
- /// at the some point.
- bool InsertTextBefore(SourceLocation Loc, StringRef Str) {
- return InsertText(Loc, Str, false);
- }
-
- /// RemoveText - Remove the specified text region.
- bool RemoveText(SourceLocation Start, unsigned Length,
- RewriteOptions opts = RewriteOptions());
-
- /// \brief Remove the specified text region.
- bool RemoveText(CharSourceRange range,
- RewriteOptions opts = RewriteOptions()) {
- return RemoveText(range.getBegin(), getRangeSize(range, opts), opts);
- }
-
- /// \brief Remove the specified text region.
- bool RemoveText(SourceRange range, RewriteOptions opts = RewriteOptions()) {
- return RemoveText(range.getBegin(), getRangeSize(range, opts), opts);
- }
-
- /// ReplaceText - This method replaces a range of characters in the input
- /// buffer with a new string. This is effectively a combined "remove/insert"
- /// operation.
- bool ReplaceText(SourceLocation Start, unsigned OrigLength,
- StringRef NewStr);
-
- /// ReplaceText - This method replaces a range of characters in the input
- /// buffer with a new string. This is effectively a combined "remove/insert"
- /// operation.
- bool ReplaceText(SourceRange range, StringRef NewStr) {
- return ReplaceText(range.getBegin(), getRangeSize(range), NewStr);
- }
-
- /// ReplaceText - This method replaces a range of characters in the input
- /// buffer with a new string. This is effectively a combined "remove/insert"
- /// operation.
- bool ReplaceText(SourceRange range, SourceRange replacementRange);
-
- /// \brief Increase indentation for the lines between the given source range.
- /// To determine what the indentation should be, 'parentIndent' is used
- /// that should be at a source location with an indentation one degree
- /// lower than the given range.
- bool IncreaseIndentation(CharSourceRange range, SourceLocation parentIndent);
- bool IncreaseIndentation(SourceRange range, SourceLocation parentIndent) {
- return IncreaseIndentation(CharSourceRange::getTokenRange(range),
- parentIndent);
- }
-
- /// getEditBuffer - This is like getRewriteBufferFor, but always returns a
- /// buffer, and allows you to write on it directly. This is useful if you
- /// want efficient low-level access to apis for scribbling on one specific
- /// FileID's buffer.
- RewriteBuffer &getEditBuffer(FileID FID);
-
- /// getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
- /// If no modification has been made to it, return null.
- const RewriteBuffer *getRewriteBufferFor(FileID FID) const {
- std::map<FileID, RewriteBuffer>::const_iterator I =
- RewriteBuffers.find(FID);
- return I == RewriteBuffers.end() ? nullptr : &I->second;
- }
-
- // Iterators over rewrite buffers.
- buffer_iterator buffer_begin() { return RewriteBuffers.begin(); }
- buffer_iterator buffer_end() { return RewriteBuffers.end(); }
- const_buffer_iterator buffer_begin() const { return RewriteBuffers.begin(); }
- const_buffer_iterator buffer_end() const { return RewriteBuffers.end(); }
-
- /// overwriteChangedFiles - Save all changed files to disk.
- ///
- /// Returns true if any files were not saved successfully.
- /// Outputs diagnostics via the source manager's diagnostic engine
- /// in case of an error.
- bool overwriteChangedFiles();
-
-private:
- unsigned getLocationOffsetAndFileID(SourceLocation Loc, FileID &FID) const;
-};
-
-} // end namespace clang
-
-#endif
diff --git a/include/clang/Rewrite/Core/TokenRewriter.h b/include/clang/Rewrite/Core/TokenRewriter.h
deleted file mode 100644
index 0f71e81..0000000
--- a/include/clang/Rewrite/Core/TokenRewriter.h
+++ /dev/null
@@ -1,79 +0,0 @@
-//===--- TokenRewriter.h - Token-based Rewriter -----------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the TokenRewriter class, which is used for code
-// transformations.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_TOKENREWRITER_H
-#define LLVM_CLANG_REWRITE_CORE_TOKENREWRITER_H
-
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Lex/Token.h"
-#include <list>
-#include <map>
-#include <memory>
-
-namespace clang {
- class LangOptions;
- class ScratchBuffer;
-
- class TokenRewriter {
- /// TokenList - This is the list of raw tokens that make up this file. Each
- /// of these tokens has a unique SourceLocation, which is a FileID.
- std::list<Token> TokenList;
-
- /// TokenRefTy - This is the type used to refer to a token in the TokenList.
- typedef std::list<Token>::iterator TokenRefTy;
-
- /// TokenAtLoc - This map indicates which token exists at a specific
- /// SourceLocation. Since each token has a unique SourceLocation, this is a
- /// one to one map. The token can return its own location directly, to map
- /// backwards.
- std::map<SourceLocation, TokenRefTy> TokenAtLoc;
-
- /// ScratchBuf - This is the buffer that we create scratch tokens from.
- ///
- std::unique_ptr<ScratchBuffer> ScratchBuf;
-
- TokenRewriter(const TokenRewriter &) = delete;
- void operator=(const TokenRewriter &) = delete;
- public:
- /// TokenRewriter - This creates a TokenRewriter for the file with the
- /// specified FileID.
- TokenRewriter(FileID FID, SourceManager &SM, const LangOptions &LO);
- ~TokenRewriter();
-
- typedef std::list<Token>::const_iterator token_iterator;
- token_iterator token_begin() const { return TokenList.begin(); }
- token_iterator token_end() const { return TokenList.end(); }
-
-
- token_iterator AddTokenBefore(token_iterator I, const char *Val);
- token_iterator AddTokenAfter(token_iterator I, const char *Val) {
- assert(I != token_end() && "Cannot insert after token_end()!");
- return AddTokenBefore(++I, Val);
- }
-
- private:
- /// RemapIterator - Convert from token_iterator (a const iterator) to
- /// TokenRefTy (a non-const iterator).
- TokenRefTy RemapIterator(token_iterator I);
-
- /// AddToken - Add the specified token into the Rewriter before the other
- /// position.
- TokenRefTy AddToken(const Token &T, TokenRefTy Where);
- };
-
-
-
-} // end namespace clang
-
-#endif
diff --git a/include/clang/Rewrite/Frontend/ASTConsumers.h b/include/clang/Rewrite/Frontend/ASTConsumers.h
deleted file mode 100644
index c9df889..0000000
--- a/include/clang/Rewrite/Frontend/ASTConsumers.h
+++ /dev/null
@@ -1,48 +0,0 @@
-//===--- ASTConsumers.h - ASTConsumer implementations -----------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// AST Consumers.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_FRONTEND_ASTCONSUMERS_H
-#define LLVM_CLANG_REWRITE_FRONTEND_ASTCONSUMERS_H
-
-#include "clang/Basic/LLVM.h"
-#include <memory>
-#include <string>
-
-namespace clang {
-
-class ASTConsumer;
-class DiagnosticsEngine;
-class LangOptions;
-class Preprocessor;
-
-// ObjC rewriter: attempts to rewrite ObjC constructs into pure C code.
-// This is considered experimental, and only works with Apple's ObjC runtime.
-std::unique_ptr<ASTConsumer>
-CreateObjCRewriter(const std::string &InFile, raw_ostream *OS,
- DiagnosticsEngine &Diags, const LangOptions &LOpts,
- bool SilenceRewriteMacroWarning);
-std::unique_ptr<ASTConsumer>
-CreateModernObjCRewriter(const std::string &InFile, raw_ostream *OS,
- DiagnosticsEngine &Diags, const LangOptions &LOpts,
- bool SilenceRewriteMacroWarning, bool LineInfo);
-
-/// CreateHTMLPrinter - Create an AST consumer which rewrites source code to
-/// HTML with syntax highlighting suitable for viewing in a web-browser.
-std::unique_ptr<ASTConsumer> CreateHTMLPrinter(raw_ostream *OS,
- Preprocessor &PP,
- bool SyntaxHighlight = true,
- bool HighlightMacros = true);
-
-} // end clang namespace
-
-#endif
diff --git a/include/clang/Rewrite/Frontend/FixItRewriter.h b/include/clang/Rewrite/Frontend/FixItRewriter.h
deleted file mode 100644
index 3b1b31e..0000000
--- a/include/clang/Rewrite/Frontend/FixItRewriter.h
+++ /dev/null
@@ -1,132 +0,0 @@
-//===--- FixItRewriter.h - Fix-It Rewriter Diagnostic Client ----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This is a diagnostic client adaptor that performs rewrites as
-// suggested by code modification hints attached to diagnostics. It
-// then forwards any diagnostics to the adapted diagnostic client.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_REWRITE_FRONTEND_FIXITREWRITER_H
-#define LLVM_CLANG_REWRITE_FRONTEND_FIXITREWRITER_H
-
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Edit/EditedSource.h"
-#include "clang/Rewrite/Core/Rewriter.h"
-
-namespace clang {
-
-class SourceManager;
-class FileEntry;
-
-class FixItOptions {
-public:
- FixItOptions() : InPlace(false), FixWhatYouCan(false),
- FixOnlyWarnings(false), Silent(false) { }
-
- virtual ~FixItOptions();
-
- /// \brief This file is about to be rewritten. Return the name of the file
- /// that is okay to write to.
- ///
- /// \param fd out parameter for file descriptor. After the call it may be set
- /// to an open file descriptor for the returned filename, or it will be -1
- /// otherwise.
- ///
- virtual std::string RewriteFilename(const std::string &Filename, int &fd) = 0;
-
- /// True if files should be updated in place. RewriteFilename is only called
- /// if this is false.
- bool InPlace;
-
- /// \brief Whether to abort fixing a file when not all errors could be fixed.
- bool FixWhatYouCan;
-
- /// \brief Whether to only fix warnings and not errors.
- bool FixOnlyWarnings;
-
- /// \brief If true, only pass the diagnostic to the actual diagnostic consumer
- /// if it is an error or a fixit was applied as part of the diagnostic.
- /// It basically silences warnings without accompanying fixits.
- bool Silent;
-};
-
-class FixItRewriter : public DiagnosticConsumer {
- /// \brief The diagnostics machinery.
- DiagnosticsEngine &Diags;
-
- edit::EditedSource Editor;
-
- /// \brief The rewriter used to perform the various code
- /// modifications.
- Rewriter Rewrite;
-
- /// \brief The diagnostic client that performs the actual formatting
- /// of error messages.
- DiagnosticConsumer *Client;
- std::unique_ptr<DiagnosticConsumer> Owner;
-
- /// \brief Turn an input path into an output path. NULL implies overwriting
- /// the original.
- FixItOptions *FixItOpts;
-
- /// \brief The number of rewriter failures.
- unsigned NumFailures;
-
- /// \brief Whether the previous diagnostic was not passed to the consumer.
- bool PrevDiagSilenced;
-
-public:
- typedef Rewriter::buffer_iterator iterator;
-
- /// \brief Initialize a new fix-it rewriter.
- FixItRewriter(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
- const LangOptions &LangOpts, FixItOptions *FixItOpts);
-
- /// \brief Destroy the fix-it rewriter.
- ~FixItRewriter() override;
-
- /// \brief Check whether there are modifications for a given file.
- bool IsModified(FileID ID) const {
- return Rewrite.getRewriteBufferFor(ID) != nullptr;
- }
-
- // Iteration over files with changes.
- iterator buffer_begin() { return Rewrite.buffer_begin(); }
- iterator buffer_end() { return Rewrite.buffer_end(); }
-
- /// \brief Write a single modified source file.
- ///
- /// \returns true if there was an error, false otherwise.
- bool WriteFixedFile(FileID ID, raw_ostream &OS);
-
- /// \brief Write the modified source files.
- ///
- /// \returns true if there was an error, false otherwise.
- bool WriteFixedFiles(
- std::vector<std::pair<std::string, std::string> > *RewrittenFiles=nullptr);
-
- /// IncludeInDiagnosticCounts - This method (whose default implementation
- /// returns true) indicates whether the diagnostics handled by this
- /// DiagnosticConsumer should be included in the number of diagnostics
- /// reported by DiagnosticsEngine.
- bool IncludeInDiagnosticCounts() const override;
-
- /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
- /// capturing it to a log as needed.
- void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
- const Diagnostic &Info) override;
-
- /// \brief Emit a diagnostic via the adapted diagnostic client.
- void Diag(SourceLocation Loc, unsigned DiagID);
-};
-
-}
-
-#endif
diff --git a/include/clang/Rewrite/Frontend/FrontendActions.h b/include/clang/Rewrite/Frontend/FrontendActions.h
deleted file mode 100644
index 6c290e4..0000000
--- a/include/clang/Rewrite/Frontend/FrontendActions.h
+++ /dev/null
@@ -1,83 +0,0 @@
-//===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_FRONTEND_FRONTENDACTIONS_H
-#define LLVM_CLANG_REWRITE_FRONTEND_FRONTENDACTIONS_H
-
-#include "clang/Frontend/FrontendAction.h"
-
-namespace clang {
-class FixItRewriter;
-class FixItOptions;
-
-//===----------------------------------------------------------------------===//
-// AST Consumer Actions
-//===----------------------------------------------------------------------===//
-
-class HTMLPrintAction : public ASTFrontendAction {
-protected:
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
- StringRef InFile) override;
-};
-
-class FixItAction : public ASTFrontendAction {
-protected:
- std::unique_ptr<FixItRewriter> Rewriter;
- std::unique_ptr<FixItOptions> FixItOpts;
-
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
- StringRef InFile) override;
-
- bool BeginSourceFileAction(CompilerInstance &CI,
- StringRef Filename) override;
-
- void EndSourceFileAction() override;
-
- bool hasASTFileSupport() const override { return false; }
-
-public:
- FixItAction();
- ~FixItAction() override;
-};
-
-/// \brief Emits changes to temporary files and uses them for the original
-/// frontend action.
-class FixItRecompile : public WrapperFrontendAction {
-public:
- FixItRecompile(FrontendAction *WrappedAction)
- : WrapperFrontendAction(WrappedAction) {}
-
-protected:
- bool BeginInvocation(CompilerInstance &CI) override;
-};
-
-class RewriteObjCAction : public ASTFrontendAction {
-protected:
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
- StringRef InFile) override;
-};
-
-class RewriteMacrosAction : public PreprocessorFrontendAction {
-protected:
- void ExecuteAction() override;
-};
-
-class RewriteTestAction : public PreprocessorFrontendAction {
-protected:
- void ExecuteAction() override;
-};
-
-class RewriteIncludesAction : public PreprocessorFrontendAction {
-protected:
- void ExecuteAction() override;
-};
-
-} // end namespace clang
-
-#endif
diff --git a/include/clang/Rewrite/Frontend/Rewriters.h b/include/clang/Rewrite/Frontend/Rewriters.h
deleted file mode 100644
index 3ad76df..0000000
--- a/include/clang/Rewrite/Frontend/Rewriters.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//===--- Rewriters.h - Rewriter implementations -------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This header contains miscellaneous utilities for various front-end actions.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_REWRITE_FRONTEND_REWRITERS_H
-#define LLVM_CLANG_REWRITE_FRONTEND_REWRITERS_H
-
-#include "clang/Basic/LLVM.h"
-
-namespace clang {
-class Preprocessor;
-class PreprocessorOutputOptions;
-
-/// RewriteMacrosInInput - Implement -rewrite-macros mode.
-void RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS);
-
-/// DoRewriteTest - A simple test for the TokenRewriter class.
-void DoRewriteTest(Preprocessor &PP, raw_ostream *OS);
-
-/// RewriteIncludesInInput - Implement -frewrite-includes mode.
-void RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS,
- const PreprocessorOutputOptions &Opts);
-
-} // end namespace clang
-
-#endif
OpenPOWER on IntegriCloud