//===--- ASTSelection.h - Clang refactoring library -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLING_REFACTORING_ASTSELECTION_H #define LLVM_CLANG_TOOLING_REFACTORING_ASTSELECTION_H #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/Stmt.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" #include "llvm/Support/raw_ostream.h" #include <optional> #include <vector> namespace clang { class ASTContext; namespace tooling { enum class SourceSelectionKind { … }; /// Represents a selected AST node. /// /// AST selection is represented using a tree of \c SelectedASTNode. The tree /// follows the top-down shape of the actual AST. Each selected node has /// a selection kind. The kind might be none as the node itself might not /// actually be selected, e.g. a statement in macro whose child is in a macro /// argument. struct SelectedASTNode { … }; /// Traverses the given ASTContext and creates a tree of selected AST nodes. /// /// \returns std::nullopt if no nodes are selected in the AST, or a selected AST /// node that corresponds to the TranslationUnitDecl otherwise. std::optional<SelectedASTNode> findSelectedASTNodes(const ASTContext &Context, SourceRange SelectionRange); /// An AST selection value that corresponds to a selection of a set of /// statements that belong to one body of code (like one function). /// /// For example, the following selection in the source. /// /// \code /// void function() { /// // selection begin: /// int x = 0; /// { /// // selection end /// x = 1; /// } /// x = 2; /// } /// \endcode /// /// Would correspond to a code range selection of statements "int x = 0" /// and the entire compound statement that follows it. /// /// A \c CodeRangeASTSelection value stores references to the full /// \c SelectedASTNode tree and should not outlive it. class CodeRangeASTSelection { … }; } // end namespace tooling } // end namespace clang #endif // LLVM_CLANG_TOOLING_REFACTORING_ASTSELECTION_H