clang 17.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
clang::TypeLoc Class Reference

Base wrapper for a particular "section" of type source info. More...

#include "clang/AST/TypeLoc.h"

Inheritance diagram for clang::TypeLoc:
Inheritance graph
[legend]

Public Types

enum  TypeLocClass { Qualified }
 The kinds of TypeLocs. More...
 

Public Member Functions

 TypeLoc ()=default
 
 TypeLoc (QualType ty, void *opaqueData)
 
 TypeLoc (const Type *ty, void *opaqueData)
 
template<typename T >
castAs () const
 Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
 
template<typename T >
getAs () const
 Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired type.
 
template<typename T >
getAsAdjusted () const
 Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired type.
 
TypeLocClass getTypeLocClass () const
 
bool isNull () const
 
 operator bool () const
 
QualType getType () const
 Get the type for which this source info wrapper provides information.
 
const TypegetTypePtr () const
 
void * getOpaqueData () const
 Get the pointer where source information is stored.
 
SourceLocation getBeginLoc () const
 Get the begin source location.
 
SourceLocation getEndLoc () const
 Get the end source location.
 
SourceRange getSourceRange () const LLVM_READONLY
 Get the full source range.
 
SourceRange getLocalSourceRange () const
 Get the local source range.
 
unsigned getFullDataSize () const
 Returns the size of the type source info data block.
 
TypeLoc getNextTypeLoc () const
 Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next TypeLoc is for "int".
 
UnqualTypeLoc getUnqualifiedLoc () const
 Skips past any qualifiers, if this is qualified.
 
TypeLoc IgnoreParens () const
 
TypeLoc findExplicitQualifierLoc () const
 Find a type with the location of an explicit type qualifier.
 
AutoTypeLoc getContainedAutoTypeLoc () const
 Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this type.
 
void initialize (ASTContext &Context, SourceLocation Loc) const
 Initializes this to state that every location in this type is the given location.
 
void initializeFullCopy (TypeLoc Other)
 Initializes this by copying its information from another TypeLoc of the same type.
 
void initializeFullCopy (TypeLoc Other, unsigned Size)
 Initializes this by copying its information from another TypeLoc of the same type.
 
void copy (TypeLoc other)
 Copies the other type loc into this one.
 
SourceLocation findNullabilityLoc () const
 Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier), if there is one.
 

Static Public Member Functions

static unsigned getFullDataSizeForType (QualType Ty)
 Returns the size of type source info data block for the given type.
 
static unsigned getLocalAlignmentForType (QualType Ty)
 Returns the alignment of type source info data block for the given type.
 

Protected Attributes

const void * Ty = nullptr
 
void * Data = nullptr
 

Friends

bool operator== (const TypeLoc &LHS, const TypeLoc &RHS)
 
bool operator!= (const TypeLoc &LHS, const TypeLoc &RHS)
 

Detailed Description

Base wrapper for a particular "section" of type source info.

A client should use the TypeLoc subclasses through castAs()/getAs() in order to get at the actual information.

Definition at line 58 of file TypeLoc.h.

Member Enumeration Documentation

◆ TypeLocClass

The kinds of TypeLocs.

Equivalent to the Type::TypeClass enum, except it also defines a Qualified enum that corresponds to the QualifiedLoc class.

Enumerator
Qualified 

Definition at line 107 of file TypeLoc.h.

Constructor & Destructor Documentation

◆ TypeLoc() [1/3]

clang::TypeLoc::TypeLoc ( )
default

◆ TypeLoc() [2/3]

clang::TypeLoc::TypeLoc ( QualType  ty,
void *  opaqueData 
)
inline

Definition at line 67 of file TypeLoc.h.

◆ TypeLoc() [3/3]

clang::TypeLoc::TypeLoc ( const Type ty,
void *  opaqueData 
)
inline

Definition at line 69 of file TypeLoc.h.

Member Function Documentation

◆ castAs()

template<typename T >
T clang::TypeLoc::castAs ( ) const
inline

◆ copy()

void TypeLoc::copy ( TypeLoc  other)

Copies the other type loc into this one.

Definition at line 167 of file TypeLoc.cpp.

References Data, getFullDataSize(), getNextTypeLoc(), getType(), memcpy(), and TypeLocMaxDataAlign.

Referenced by initializeFullCopy().

◆ findExplicitQualifierLoc()

TypeLoc TypeLoc::findExplicitQualifierLoc ( ) const

Find a type with the location of an explicit type qualifier.

The result, if non-null, will be one of: QualifiedTypeLoc AtomicTypeLoc AttributedTypeLoc, for those type attributes that behave as qualifiers

Definition at line 457 of file TypeLoc.cpp.

References clang::ast_matchers::attr, getAs(), and IgnoreParens().

Referenced by clang::Sema::actOnObjCTypeParam(), and applyObjCTypeArgs().

◆ findNullabilityLoc()

SourceLocation TypeLoc::findNullabilityLoc ( ) const

Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier), if there is one.

Definition at line 446 of file TypeLoc.cpp.

References clang::Attr::getLocation().

◆ getAs()

template<typename T >
T clang::TypeLoc::getAs ( ) const
inline

◆ getAsAdjusted()

template<typename T >
T clang::TypeLoc::getAsAdjusted
inline

Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired type.

It will consider type adjustments from a type that was written as a T to another type that is still canonically a T (ignores parens, attributes, elaborated types, etc).

Definition at line 2636 of file TypeLoc.h.

References getAs().

Referenced by clang::Sema::ActOnBlockArguments(), clang::TemplateDeclInstantiator::adjustForRewrite(), checkAttributesAfterMerging(), clang::Sema::CheckDeductionGuideDeclarator(), findTypeLocationForBlockDecl(), clang::Sema::getReturnTypeLoc(), implicitObjectParamIsLifetimeBound(), clang::Expr::isFlexibleArrayMemberLike(), and clang::TreeTransform< Derived >::TransformNestedNameSpecifierLoc().

◆ getBeginLoc()

SourceLocation TypeLoc::getBeginLoc ( ) const

Get the begin source location.

Definition at line 191 of file TypeLoc.cpp.

References castAs(), clang::SourceRange::getBegin(), getLocalSourceRange(), getNextTypeLoc(), getTypeLocClass(), clang::InheritingConcreteTypeLoc< Base, Derived, TypeClass >::getTypePtr(), clang::FunctionProtoType::hasTrailingReturn(), isNull(), clang::SourceLocation::isValid(), and Qualified.

Referenced by clang::Sema::ActOnAliasDeclaration(), clang::Sema::ActOnCXXTypeConstructExpr(), clang::Sema::ActOnExplicitInstantiation(), clang::Sema::ActOnMethodDeclaration(), clang::Sema::ActOnObjCForCollectionStmt(), clang::Sema::actOnObjCTypeParam(), clang::Sema::ActOnOMPIteratorExpr(), clang::Sema::ActOnTag(), clang::Sema::ActOnTemplateTypeArgument(), applyObjCTypeArgs(), clang::Sema::AttachTypeConstraint(), clang::Sema::BuildBaseInitializer(), clang::Sema::BuildBuiltinBitCastExpr(), clang::Sema::BuildCXXTypeConstructExpr(), clang::Sema::BuildDeclaratorGroup(), clang::Sema::BuildPseudoDestructorExpr(), clang::Sema::BuildVAArgExpr(), clang::Sema::CheckBaseSpecifier(), CheckConstexprDeclStmt(), clang::Sema::CheckDeductionGuideDeclarator(), clang::Sema::CheckEnumUnderlyingType(), clang::Sema::CheckFriendTypeDecl(), clang::Sema::CreatePropertyDecl(), clang::Sema::DeduceTemplateSpecializationFromInitializer(), clang::Sema::deduceVarTypeFromInitializer(), clang::ODRDiagsEmitter::diagnoseMismatch(), clang::CXXScopeSpec::Extend(), clang::CXXBaseSpecifier::getBaseTypeLoc(), clang::CXXFunctionalCastExpr::getBeginLoc(), clang::CXXTemporaryObjectExpr::getBeginLoc(), clang::TemplateTypeParmDecl::getDefaultArgumentLoc(), GetFullTypeForDeclarator(), clang::NestedNameSpecifierLoc::getLocalSourceRange(), clang::DependentNameTypeLoc::getLocalSourceRange(), clang::DependentTemplateSpecializationTypeLoc::getLocalSourceRange(), getPointeeTypeText(), getSourceRange(), clang::DeclaratorDecl::getTypeSpecStartLoc(), handleAlignedAttr(), clang::ASTImporter::Import(), clang::PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(), clang::ASTRecordReader::readNestedNameSpecifierLoc(), clang::TreeTransform< Derived >::RebuildQualifiedType(), ReplaceWithClasstype(), ReplaceWithInstancetype(), clang::TreeTransform< Derived >::TransformFunctionProtoType(), clang::TreeTransform< Derived >::TransformNestedNameSpecifierLoc(), clang::TreeTransform< Derived >::TransformType(), clang::TreeTransform< Derived >::TransformTypeWithDeducedTST(), clang::tooling::RecursiveSymbolVisitor< T >::VisitTypedefTypeLoc(), and clang::tooling::RecursiveSymbolVisitor< T >::VisitTypeLoc().

◆ getContainedAutoTypeLoc()

AutoTypeLoc TypeLoc::getContainedAutoTypeLoc ( ) const

Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this type.

This looks through declarators like pointer types, but not through decltype or typedefs.

Definition at line 715 of file TypeLoc.cpp.

References getAs(), and isNull().

Referenced by clang::Sema::ActOnNonTypeTemplateParameter(), and InventTemplateParameter().

◆ getEndLoc()

SourceLocation TypeLoc::getEndLoc ( ) const

◆ getFullDataSize()

unsigned clang::TypeLoc::getFullDataSize ( ) const
inline

◆ getFullDataSizeForType()

unsigned TypeLoc::getFullDataSizeForType ( QualType  Ty)
static

Returns the size of type source info data block for the given type.

Returns the size of the type source info data block.

Definition at line 93 of file TypeLoc.cpp.

References getLocalAlignmentForType(), getNextTypeLoc(), getType(), isNull(), and Ty.

Referenced by clang::ASTContext::adjustExceptionSpec(), clang::ASTContext::CreateTypeSourceInfo(), and getFullDataSize().

◆ getLocalAlignmentForType()

unsigned TypeLoc::getLocalAlignmentForType ( QualType  Ty)
static

Returns the alignment of type source info data block for the given type.

Returns the alignment of the type source info data block.

Definition at line 73 of file TypeLoc.cpp.

References Ty, and TypeLoc().

Referenced by getFullDataSizeForType(), and clang::QualifiedTypeLoc::getUnqualifiedLoc().

◆ getLocalSourceRange()

SourceRange clang::TypeLoc::getLocalSourceRange ( ) const
inline

◆ getNextTypeLoc()

TypeLoc clang::TypeLoc::getNextTypeLoc ( ) const
inline

◆ getOpaqueData()

void * clang::TypeLoc::getOpaqueData ( ) const
inline

◆ getSourceRange()

SourceRange clang::TypeLoc::getSourceRange ( ) const
inline

◆ getType()

QualType clang::TypeLoc::getType ( ) const
inline

◆ getTypeLocClass()

TypeLocClass clang::TypeLoc::getTypeLocClass ( ) const
inline

◆ getTypePtr()

const Type * clang::TypeLoc::getTypePtr ( ) const
inline

◆ getUnqualifiedLoc()

UnqualTypeLoc clang::TypeLoc::getUnqualifiedLoc ( ) const
inline

◆ IgnoreParens()

TypeLoc clang::TypeLoc::IgnoreParens ( ) const
inline

◆ initialize()

void clang::TypeLoc::initialize ( ASTContext Context,
SourceLocation  Loc 
) const
inline

Initializes this to state that every location in this type is the given location.

This method exists to provide a simple transition for code that relies on location-less types.

Definition at line 196 of file TypeLoc.h.

Referenced by clang::ASTContext::getTrivialTypeSourceInfo().

◆ initializeFullCopy() [1/2]

void clang::TypeLoc::initializeFullCopy ( TypeLoc  Other)
inline

Initializes this by copying its information from another TypeLoc of the same type.

Definition at line 202 of file TypeLoc.h.

References copy(), and getType().

Referenced by clang::Sema::ActOnBlockArguments(), and FixInvalidVariablyModifiedTypeLoc().

◆ initializeFullCopy() [2/2]

void clang::TypeLoc::initializeFullCopy ( TypeLoc  Other,
unsigned  Size 
)
inline

Initializes this by copying its information from another TypeLoc of the same type.

The given size must be the full data size.

Definition at line 210 of file TypeLoc.h.

References copy(), getFullDataSize(), and getType().

◆ isNull()

bool clang::TypeLoc::isNull ( ) const
inline

◆ operator bool()

clang::TypeLoc::operator bool ( ) const
inlineexplicit

Definition at line 121 of file TypeLoc.h.

References Ty.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const TypeLoc LHS,
const TypeLoc RHS 
)
friend

Definition at line 223 of file TypeLoc.h.

◆ operator==

bool operator== ( const TypeLoc LHS,
const TypeLoc RHS 
)
friend

Definition at line 219 of file TypeLoc.h.

Member Data Documentation

◆ Data

void* clang::TypeLoc::Data = nullptr
protected

◆ Ty

const void* clang::TypeLoc::Ty = nullptr
protected

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