clang 22.0.0git
clang::tooling::CodeRangeASTSelection Class Reference

An AST selection value that corresponds to a selection of a set of statements that belong to one body of code (like one function). More...

#include "clang/Tooling/Refactoring/ASTSelection.h"

Public Member Functions

 CodeRangeASTSelection (CodeRangeASTSelection &&)=default
CodeRangeASTSelectionoperator= (CodeRangeASTSelection &&)=default
ArrayRef< SelectedASTNode::ReferenceTypegetParents ()
 Returns the parent hierarchy (top to bottom) for the selected nodes.
size_t size () const
 Returns the number of selected statements.
const Stmtoperator[] (size_t I) const
bool isInFunctionLikeBodyOfCode () const
 Returns true when a selected code range is in a function-like body of code, like a function, method or a block.
const DeclgetFunctionLikeNearestParent () const
 Returns the nearest function-like parent declaration or null if such declaration doesn't exist.

Static Public Member Functions

static std::optional< CodeRangeASTSelectioncreate (SourceRange SelectionRange, const SelectedASTNode &ASTSelection)

Detailed Description

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.

void function() {
// selection begin:
int x = 0;
{
// selection end
x = 1;
}
x = 2;
}

Would correspond to a code range selection of statements "int x = 0" and the entire compound statement that follows it.

A CodeRangeASTSelection value stores references to the full SelectedASTNode tree and should not outlive it.

Definition at line 96 of file ASTSelection.h.

Constructor & Destructor Documentation

◆ CodeRangeASTSelection()

clang::tooling::CodeRangeASTSelection::CodeRangeASTSelection ( CodeRangeASTSelection && )
default

Member Function Documentation

◆ create()

◆ getFunctionLikeNearestParent()

const Decl * CodeRangeASTSelection::getFunctionLikeNearestParent ( ) const

Returns the nearest function-like parent declaration or null if such declaration doesn't exist.

Definition at line 441 of file ASTSelection.cpp.

References clang::DynTypedNode::get(), and isFunctionLikeDeclaration().

◆ getParents()

ArrayRef< SelectedASTNode::ReferenceType > clang::tooling::CodeRangeASTSelection::getParents ( )
inline

Returns the parent hierarchy (top to bottom) for the selected nodes.

Definition at line 102 of file ASTSelection.h.

◆ isInFunctionLikeBodyOfCode()

bool CodeRangeASTSelection::isInFunctionLikeBodyOfCode ( ) const

Returns true when a selected code range is in a function-like body of code, like a function, method or a block.

This function can be used to test against selected expressions that are located outside of a function, e.g. global variable initializers, default argument values, or even template arguments.

Use the getFunctionLikeNearestParent to get the function-like parent declaration.

Definition at line 419 of file ASTSelection.cpp.

References clang::DynTypedNode::get(), clang::isa(), and isFunctionLikeDeclaration().

◆ operator=()

CodeRangeASTSelection & clang::tooling::CodeRangeASTSelection::operator= ( CodeRangeASTSelection && )
default

◆ operator[]()

const Stmt * clang::tooling::CodeRangeASTSelection::operator[] ( size_t I) const
inline

Definition at line 111 of file ASTSelection.h.

◆ size()

size_t clang::tooling::CodeRangeASTSelection::size ( ) const
inline

Returns the number of selected statements.

Definition at line 105 of file ASTSelection.h.


The documentation for this class was generated from the following files: