clang 20.0.0git
Classes | Public Member Functions | Static Public Member Functions | List of all members
clang::ast_matchers::dynamic::VariantMatcher Class Reference

A variant matcher object. More...

#include "clang/ASTMatchers/Dynamic/VariantValue.h"

Classes

class  PolymorphicPayload
 
class  SinglePayload
 
class  VariadicOpPayload
 

Public Member Functions

 VariantMatcher ()
 A null matcher.
 
void reset ()
 Makes the matcher the "null" matcher.
 
bool isNull () const
 Whether the matcher is null.
 
std::optional< DynTypedMatcher > getSingleMatcher () const
 Return a single matcher, if there is no ambiguity.
 
template<class T >
bool hasTypedMatcher () const
 Determines if the contained matcher can be converted to Matcher<T>.
 
bool hasTypedMatcher (ASTNodeKind NK) const
 
bool isConvertibleTo (ASTNodeKind Kind, unsigned *Specificity) const
 Determines if the contained matcher can be converted to Kind.
 
template<class T >
ast_matchers::internal::Matcher< TgetTypedMatcher () const
 Return this matcher as a Matcher<T>.
 
DynTypedMatcher getTypedMatcher (ASTNodeKind NK) const
 
std::string getTypeAsString () const
 String representation of the type of the value.
 

Static Public Member Functions

static VariantMatcher SingleMatcher (const DynTypedMatcher &Matcher)
 Clones the provided matcher.
 
static VariantMatcher PolymorphicMatcher (std::vector< DynTypedMatcher > Matchers)
 Clones the provided matchers.
 
static VariantMatcher VariadicOperatorMatcher (DynTypedMatcher::VariadicOperator Op, std::vector< VariantMatcher > Args)
 Creates a 'variadic' operator matcher.
 

Detailed Description

A variant matcher object.

The purpose of this object is to abstract simple and polymorphic matchers into a single object type. Polymorphic matchers might be implemented as a list of all the possible overloads of the matcher. VariantMatcher knows how to select the appropriate overload when needed. To get a real matcher object out of a VariantMatcher you can do:

Definition at line 105 of file VariantValue.h.

Constructor & Destructor Documentation

◆ VariantMatcher()

clang::ast_matchers::dynamic::VariantMatcher::VariantMatcher ( )

A null matcher.

Definition at line 225 of file VariantValue.cpp.

Referenced by PolymorphicMatcher(), SingleMatcher(), and VariadicOperatorMatcher().

Member Function Documentation

◆ getSingleMatcher()

std::optional< DynTypedMatcher > clang::ast_matchers::dynamic::VariantMatcher::getSingleMatcher ( ) const

Return a single matcher, if there is no ambiguity.

Returns
the matcher, if there is only one matcher. An empty Optional, if the underlying matcher is a polymorphic matcher with more than one representation.

Definition at line 244 of file VariantValue.cpp.

◆ getTypeAsString()

std::string clang::ast_matchers::dynamic::VariantMatcher::getTypeAsString ( ) const

String representation of the type of the value.

If the underlying matcher is a polymorphic one, the string will show all the types.

Definition at line 250 of file VariantValue.cpp.

Referenced by clang::ast_matchers::dynamic::VariantValue::getTypeAsString().

◆ getTypedMatcher() [1/2]

template<class T >
ast_matchers::internal::Matcher< T > clang::ast_matchers::dynamic::VariantMatcher::getTypedMatcher ( ) const
inline

Return this matcher as a Matcher<T>.

Handles the different types (Single, Polymorphic) accordingly. Asserts that hasTypedMatcher<T>() is true.

Definition at line 211 of file VariantValue.h.

Referenced by clang::ast_matchers::dynamic::internal::MapAnyOfMatcherDescriptor::create().

◆ getTypedMatcher() [2/2]

DynTypedMatcher clang::ast_matchers::dynamic::VariantMatcher::getTypedMatcher ( ASTNodeKind  NK) const
inline

Definition at line 217 of file VariantValue.h.

References hasTypedMatcher().

◆ hasTypedMatcher() [1/2]

template<class T >
bool clang::ast_matchers::dynamic::VariantMatcher::hasTypedMatcher ( ) const
inline

Determines if the contained matcher can be converted to Matcher<T>.

For the Single case, it returns true if it can be converted to Matcher<T>. For the Polymorphic case, it returns true if one, and only one, of the overloads can be converted to Matcher<T>. If there are more than one that can, the result would be ambiguous and false is returned.

Definition at line 185 of file VariantValue.h.

References hasTypedMatcher().

Referenced by clang::ast_matchers::dynamic::internal::MapAnyOfMatcherDescriptor::create(), getTypedMatcher(), and hasTypedMatcher().

◆ hasTypedMatcher() [2/2]

bool clang::ast_matchers::dynamic::VariantMatcher::hasTypedMatcher ( ASTNodeKind  NK) const
inline

Definition at line 189 of file VariantValue.h.

◆ isConvertibleTo()

bool clang::ast_matchers::dynamic::VariantMatcher::isConvertibleTo ( ASTNodeKind  Kind,
unsigned Specificity 
) const
inline

Determines if the contained matcher can be converted to Kind.

Parameters
Kindthe requested destination type.
Specificityvalue corresponding to the "specificity" of the conversion.

Definition at line 200 of file VariantValue.h.

References Kind.

Referenced by clang::ast_matchers::dynamic::VariantValue::isConvertibleTo().

◆ isNull()

bool clang::ast_matchers::dynamic::VariantMatcher::isNull ( ) const
inline

Whether the matcher is null.

Definition at line 167 of file VariantValue.h.

Referenced by clang::ast_matchers::dynamic::internal::OverloadedMatcherDescriptor::create().

◆ PolymorphicMatcher()

VariantMatcher clang::ast_matchers::dynamic::VariantMatcher::PolymorphicMatcher ( std::vector< DynTypedMatcher >  Matchers)
static

Clones the provided matchers.

They should be the result of a polymorphic matcher.

Definition at line 232 of file VariantValue.cpp.

References VariantMatcher().

Referenced by clang::ast_matchers::dynamic::internal::outvalueToVariantMatcher().

◆ reset()

void clang::ast_matchers::dynamic::VariantMatcher::reset ( )

Makes the matcher the "null" matcher.

Definition at line 248 of file VariantValue.cpp.

◆ SingleMatcher()

VariantMatcher clang::ast_matchers::dynamic::VariantMatcher::SingleMatcher ( const DynTypedMatcher &  Matcher)
static

◆ VariadicOperatorMatcher()

VariantMatcher clang::ast_matchers::dynamic::VariantMatcher::VariadicOperatorMatcher ( DynTypedMatcher::VariadicOperator  Op,
std::vector< VariantMatcher Args 
)
static

Creates a 'variadic' operator matcher.

It will bind to the appropriate type on getTypedMatcher<T>().

Definition at line 237 of file VariantValue.cpp.

References VariantMatcher().

Referenced by clang::ast_matchers::dynamic::internal::VariadicOperatorMatcherDescriptor::create().


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