clang 22.0.0git
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:
[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>
T castAs () const
 Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
template<typename T>
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>
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.
SourceLocation getTemplateKeywordLoc () const
 Get the SourceLocation of the template keyword (if any).
NestedNameSpecifierLoc getPrefix () const
 If this type represents a qualified-id, this returns it's nested name specifier.
SourceLocation getNonPrefixBeginLoc () const
 This returns the position of the type after any elaboration, such as the 'struct' keyword, and name qualifiers.
SourceLocation getNonElaboratedBeginLoc () const
 This returns the position of the type after any elaboration, such as the 'struct' keyword.
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.
void dump () const
void dump (llvm::raw_ostream &, const ASTContext &) const

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 59 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 108 of file TypeLoc.h.

Constructor & Destructor Documentation

◆ TypeLoc() [1/3]

◆ TypeLoc() [2/3]

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

Definition at line 68 of file TypeLoc.h.

References Data, and Ty.

◆ TypeLoc() [3/3]

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

Definition at line 70 of file TypeLoc.h.

References Data, and Ty.

Member Function Documentation

◆ castAs()

◆ copy()

void TypeLoc::copy ( TypeLoc other)

Copies the other type loc into this one.

Definition at line 169 of file TypeLoc.cpp.

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

Referenced by initializeFullCopy(), and initializeFullCopy().

◆ dump() [1/2]

LLVM_DUMP_METHOD void TypeLoc::dump ( ) const

◆ dump() [2/2]

LLVM_DUMP_METHOD void TypeLoc::dump ( llvm::raw_ostream & OS,
const ASTContext & Context ) const

◆ 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 453 of file TypeLoc.cpp.

References getAs(), IgnoreParens(), and TypeLoc().

Referenced by clang::SemaObjC::actOnObjCTypeParam(), and clang::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 442 of file TypeLoc.cpp.

References getAs(), clang::Attr::getLocation(), and clang::isa().

◆ getAs()

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

◆ getAsAdjusted()

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

◆ getBeginLoc()

SourceLocation TypeLoc::getBeginLoc ( ) const

Get the begin source location.

Definition at line 193 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(), Qualified, and TypeLoc().

Referenced by clang::Sema::ActOnAliasDeclaration(), clang::Sema::ActOnCXXTypeConstructExpr(), clang::Sema::ActOnFriendTypeDecl(), clang::SemaObjC::ActOnMethodParmDeclaration(), clang::SemaObjC::ActOnObjCForCollectionStmt(), clang::SemaObjC::actOnObjCTypeParam(), clang::SemaOpenMP::ActOnOMPIteratorExpr(), clang::Sema::ActOnTag(), clang::Sema::ActOnTemplateTypeArgument(), clang::Sema::ActOnVariableDeclarator(), clang::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(), CheckConvertibilityForTypeTraits(), clang::Sema::CheckDeductionGuideDeclarator(), clang::Sema::CheckEnumUnderlyingType(), clang::SemaObjC::CreatePropertyDecl(), clang::Sema::DeduceTemplateSpecializationFromInitializer(), clang::Sema::deduceVarTypeFromInitializer(), clang::ODRDiagsEmitter::diagnoseMismatch(), clang::CodeGen::CodeGenFunction::EmitCXXNewExpr(), EvaluateBinaryTypeTrait(), EvaluateUnaryTypeTrait(), clang::CXXFunctionalCastExpr::getBeginLoc(), clang::CXXTemporaryObjectExpr::getBeginLoc(), GetFullTypeForDeclarator(), clang::DependentNameTypeLoc::getLocalSourceRange(), clang::NestedNameSpecifierLoc::getLocalSourceRange(), getNonElaboratedBeginLoc(), getNonPrefixBeginLoc(), getPointee2TypeText(), clang::getPointeeTypeText(), getSourceRange(), clang::DeclaratorDecl::getTypeSpecStartLoc(), handleAlignedAttr(), handlePreferredTypeAttr(), clang::SemaHLSL::handleResourceTypeAttr(), clang::ASTImporter::Import(), clang::ASTImporter::Import(), clang::Sema::InstantiateFunctionDefinition(), clang::Sema::IsPointerInterconvertibleBaseOf(), clang::CXXScopeSpec::Make(), clang::TreeTransform< Derived >::RebuildQualifiedType(), clang::TreeTransform< Derived >::TransformFunctionProtoType(), clang::TreeTransform< AdjustConstraintDepth >::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 913 of file TypeLoc.cpp.

References getAs(), isNull(), and TypeLoc().

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

◆ getEndLoc()

◆ getFullDataSize()

◆ 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 95 of file TypeLoc.cpp.

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

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 75 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

◆ getNonElaboratedBeginLoc()

SourceLocation TypeLoc::getNonElaboratedBeginLoc ( ) const

This returns the position of the type after any elaboration, such as the 'struct' keyword.

This may be the position of the name qualifiers, 'template' keyword, or the name location otherwise.

Definition at line 530 of file TypeLoc.cpp.

References castAs(), getBeginLoc(), getTypeLocClass(), Qualified, and clang::T.

◆ getNonPrefixBeginLoc()

SourceLocation TypeLoc::getNonPrefixBeginLoc ( ) const

This returns the position of the type after any elaboration, such as the 'struct' keyword, and name qualifiers.

This will the 'template' keyword if present, or the name location otherwise.

Definition at line 497 of file TypeLoc.cpp.

References castAs(), getBeginLoc(), getTemplateKeywordLoc(), getTypeLocClass(), and clang::SourceLocation::isValid().

◆ getOpaqueData()

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

Get the pointer where source information is stored.

Definition at line 143 of file TypeLoc.h.

References Data.

Referenced by clang::TypeLocBuilder::getTypeSourceInfo(), GetTypeSourceInfoForDeclarator(), and clang::NestedNameSpecifierLocBuilder::Make().

◆ getPrefix()

NestedNameSpecifierLoc TypeLoc::getPrefix ( ) const

If this type represents a qualified-id, this returns it's nested name specifier.

For example, for the qualified-id "foo::bar::baz", this returns "foo::bar". Returns null if this type represents an unqualified-id.

Definition at line 474 of file TypeLoc.cpp.

References castAs(), and getTypeLocClass().

Referenced by clang::UsingEnumDecl::getQualifierLoc(), and clang::RecursiveASTVisitor< Derived >::TraverseNestedNameSpecifierLoc().

◆ getSourceRange()

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

Get the full source range.

Definition at line 154 of file TypeLoc.h.

References getBeginLoc(), and getEndLoc().

Referenced by clang::Sema::ActOnFriendTypeDecl(), clang::SemaObjC::actOnObjCTypeArgsAndProtocolQualifiers(), clang::Sema::ActOnVariableDeclarator(), clang::Sema::AddAlignedAttr(), clang::SemaObjC::AdjustParameterTypeForObjCAutoRefCount(), AnalyzeBitFieldAssignment(), clang::applyObjCTypeArgs(), clang::Sema::AttachTypeConstraint(), clang::Sema::BuildBaseInitializer(), clang::SemaObjC::BuildClassMessage(), clang::Sema::BuildCStyleCastExpr(), clang::Sema::BuildCXXFunctionalCastExpr(), clang::Sema::BuildCXXNew(), clang::Sema::BuildDelegatingInitializer(), clang::SemaObjC::BuildObjCBridgedCast(), clang::Sema::BuildPseudoDestructorExpr(), clang::Sema::BuildVAArgExpr(), clang::Sema::CheckBaseSpecifier(), CheckConstexprDeclStmt(), clang::Sema::CheckConversionDeclarator(), clang::Sema::CheckDeductionGuideDeclarator(), clang::Sema::CheckPackExpansion(), clang::Sema::CheckParameter(), clang::Sema::CheckTemplateArgument(), checkTypeParamListConsistency(), clang::Sema::CreateGenericSelectionExpr(), clang::Sema::DeduceTemplateSpecializationFromInitializer(), findTemplateParameter(), clang::TypeOfExprTypeLoc::getLocalSourceRange(), getPointee2TypeText(), clang::getPointeeTypeText(), clang::Sema::getPrintable(), getRangeOfTypeInNestedNameSpecifier(), clang::ObjCMessageExpr::getReceiverRange(), clang::FunctionDecl::getReturnTypeSourceRange(), getTypeRange(), clang::Sema::InstantiateMemInitializers(), clang::TreeTransform< Derived >::TransformFunctionTypeParam(), clang::JSONNodeDumper::Visit(), and clang::TextNodeDumper::Visit().

◆ getTemplateKeywordLoc()

SourceLocation TypeLoc::getTemplateKeywordLoc ( ) const

Get the SourceLocation of the template keyword (if any).

Definition at line 920 of file TypeLoc.cpp.

References getAsAdjusted().

Referenced by getNonPrefixBeginLoc().

◆ getType()

◆ getTypeLocClass()

◆ getTypePtr()

◆ getUnqualifiedLoc()

◆ IgnoreParens()

◆ 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 216 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 222 of file TypeLoc.h.

References copy(), getType(), clang::Other, and TypeLoc().

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 230 of file TypeLoc.h.

References copy(), getFullDataSize(), getType(), clang::Other, and TypeLoc().

◆ isNull()

◆ operator bool()

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

Definition at line 122 of file TypeLoc.h.

References Ty.

◆ operator!=

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

Definition at line 243 of file TypeLoc.h.

References TypeLoc().

◆ operator==

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

Definition at line 239 of file TypeLoc.h.

References Data, Ty, and TypeLoc().

Member Data Documentation

◆ Data

◆ Ty


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