clang  14.0.0git
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
RewriteRule.h File Reference
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"
#include "clang/Tooling/Refactoring/AtomicChange.h"
#include "clang/Tooling/Transformer/MatchConsumer.h"
#include "clang/Tooling/Transformer/RangeSelector.h"
#include "llvm/ADT/Any.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Error.h"
#include <functional>
#include <string>
#include <utility>
Include dependency graph for RewriteRule.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  clang::transformer::Edit
 A concrete description of a source edit, represented by a character range in the source to be replaced and a corresponding replacement string. More...
 
struct  clang::transformer::ASTEdit
 
struct  clang::transformer::RewriteRule
 Description of a source-code transformation. More...
 
struct  clang::transformer::RewriteRule::Case
 

Namespaces

 clang
 
 clang::transformer
 
 clang::transformer::detail
 The following three functions are a low-level part of the RewriteRule API.
 

Typedefs

using clang::transformer::EditGenerator = MatchConsumer< llvm::SmallVector< Edit, 1 > >
 Maps a match result to a list of concrete edits (with possible failure). More...
 
using clang::transformer::TextGenerator = std::shared_ptr< MatchComputation< std::string > >
 
using clang::transformer::AnyGenerator = MatchConsumer< llvm::Any >
 

Enumerations

enum  clang::transformer::EditKind { clang::transformer::EditKind::Range, clang::transformer::EditKind::AddInclude }
 
enum  clang::transformer::IncludeFormat { clang::transformer::IncludeFormat::Quoted, clang::transformer::IncludeFormat::Angled }
 Format of the path in an include directive – angle brackets or quotes. More...
 

Functions

EditGenerator clang::transformer::edit (ASTEdit E)
 Generates a single (specified) edit. More...
 
EditGenerator clang::transformer::editList (llvm::SmallVector< ASTEdit, 1 > Edits)
 Lifts a list of ASTEdits into an EditGenerator. More...
 
EditGenerator clang::transformer::noEdits ()
 Generates no edits. More...
 
EditGenerator clang::transformer::noopEdit (RangeSelector Anchor)
 Generates a single, no-op edit anchored at the start location of the specified range. More...
 
EditGenerator clang::transformer::ifBound (std::string ID, ASTEdit TrueEdit, ASTEdit FalseEdit)
 Version of ifBound specialized to ASTEdit. More...
 
EditGenerator clang::transformer::ifBound (std::string ID, ASTEdit TrueEdit)
 Version of ifBound that has no "False" branch. More...
 
EditGenerator clang::transformer::flattenVector (SmallVector< EditGenerator, 2 > Generators)
 Flattens a list of generators into a single generator whose elements are the concatenation of the results of the argument generators. More...
 
EditGenerator clang::transformer::detail::injectEdits (ASTEdit E)
 Helper function to construct an EditGenerator. More...
 
EditGenerator clang::transformer::detail::injectEdits (EditGenerator G)
 
template<typename... Ts>
EditGenerator clang::transformer::flatten (Ts &&...Edits)
 
ASTEdit clang::transformer::changeTo (RangeSelector Target, TextGenerator Replacement)
 Replaces a portion of the source text with Replacement. More...
 
ASTEdit clang::transformer::change (RangeSelector Target, TextGenerator Replacement)
 DEPRECATED: use changeTo. More...
 
ASTEdit clang::transformer::changeTo (TextGenerator Replacement)
 Replaces the entirety of a RewriteRule's match with Replacement. More...
 
ASTEdit clang::transformer::change (TextGenerator Replacement)
 DEPRECATED: use changeTo. More...
 
ASTEdit clang::transformer::insertBefore (RangeSelector S, TextGenerator Replacement)
 Inserts Replacement before S, leaving the source selected by \S unchanged. More...
 
ASTEdit clang::transformer::insertAfter (RangeSelector S, TextGenerator Replacement)
 Inserts Replacement after S, leaving the source selected by \S unchanged. More...
 
ASTEdit clang::transformer::remove (RangeSelector S)
 Removes the source selected by S. More...
 
ASTEdit clang::transformer::addInclude (RangeSelector Target, StringRef Header, IncludeFormat Format=IncludeFormat::Quoted)
 Adds an include directive for the given header to the file of Target. More...
 
ASTEdit clang::transformer::addInclude (StringRef Header, IncludeFormat Format=IncludeFormat::Quoted)
 Adds an include directive for the given header to the file associated with RootID. More...
 
template<typename Callable >
ASTEdit clang::transformer::withMetadata (ASTEdit Edit, Callable Metadata)
 
EditGenerator clang::transformer::shrinkTo (RangeSelector outer, RangeSelector inner)
 Assuming that the inner range is enclosed by the outer range, creates precision edits to remove the parts of the outer range that are not included in the inner range. More...
 
RewriteRule clang::transformer::makeRule (ast_matchers::internal::DynTypedMatcher M, EditGenerator Edits, TextGenerator Explanation=nullptr)
 Constructs a simple RewriteRule. More...
 
RewriteRule clang::transformer::makeRule (ast_matchers::internal::DynTypedMatcher M, llvm::SmallVector< ASTEdit, 1 > Edits, TextGenerator Explanation=nullptr)
 Constructs a RewriteRule from multiple ASTEdits. More...
 
RewriteRule clang::transformer::makeRule (ast_matchers::internal::DynTypedMatcher M, ASTEdit Edit, TextGenerator Explanation=nullptr)
 Overload of makeRule for common case of only one edit. More...
 
void clang::transformer::addInclude (RewriteRule &Rule, llvm::StringRef Header, IncludeFormat Format=IncludeFormat::Quoted)
 For every case in Rule, adds an include directive for the given header. More...
 
RewriteRule clang::transformer::applyFirst (ArrayRef< RewriteRule > Rules)
 Applies the first rule whose pattern matches; other rules are ignored. More...
 
EditGenerator clang::transformer::rewriteDescendants (std::string NodeId, RewriteRule Rule)
 Applies Rule to all descendants of the node bound to NodeId. More...
 
ast_matchers::internal::DynTypedMatcher clang::transformer::detail::buildMatcher (const RewriteRule &Rule)
 Builds a single matcher for the rule, covering all of the rule's cases. More...
 
std::vector< ast_matchers::internal::DynTypedMatcher > clang::transformer::detail::buildMatchers (const RewriteRule &Rule)
 Builds a set of matchers that cover the rule. More...
 
SourceLocation clang::transformer::detail::getRuleMatchLoc (const ast_matchers::MatchFinder::MatchResult &Result)
 Gets the beginning location of the source matched by a rewrite rule. More...
 
const RewriteRule::Caseclang::transformer::detail::findSelectedCase (const ast_matchers::MatchFinder::MatchResult &Result, const RewriteRule &Rule)
 Returns the Case of Rule that was selected in the match result. More...
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const Decl &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 The following overload set is a version of rewriteDescendants that operates directly on the AST, rather than generating a Transformer combinator. More...
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const Stmt &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const TypeLoc &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const DynTypedNode &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const Decl &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 The following overload set is a version of rewriteDescendants that operates directly on the AST, rather than generating a Transformer combinator. More...
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const Stmt &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const TypeLoc &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 
llvm::Expected< SmallVector< Edit, 1 > > clang::transformer::detail::rewriteDescendants (const DynTypedNode &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
 

Variables

const char clang::transformer::RootID [] = "___root___"
 

Detailed Description

Defines the RewriteRule class and related functions for creating, modifying and interpreting RewriteRules.

Definition in file RewriteRule.h.