24#include "llvm/Support/ErrorHandling.h"
25#include "llvm/Support/MathExtras.h"
41class TypeLocRanger :
public TypeLocVisitor<TypeLocRanger, SourceRange> {
43#define ABSTRACT_TYPELOC(CLASS, PARENT)
44#define TYPELOC(CLASS, PARENT) \
45 SourceRange Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
46 return TyLoc.getLocalSourceRange(); \
48#include "clang/AST/TypeLocNodes.def"
55 return TypeLocRanger().Visit(TL);
62#define ABSTRACT_TYPELOC(CLASS, PARENT)
63#define TYPELOC(CLASS, PARENT) \
64 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
65 return TyLoc.getLocalDataAlignment(); \
67#include "clang/AST/TypeLocNodes.def"
74 if (
Ty.isNull())
return 1;
75 return TypeAligner().Visit(
TypeLoc(
Ty,
nullptr));
82#define ABSTRACT_TYPELOC(CLASS, PARENT)
83#define TYPELOC(CLASS, PARENT) \
84 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
85 return TyLoc.getLocalDataSize(); \
87#include "clang/AST/TypeLocNodes.def"
96 unsigned MaxAlign = 1;
99 MaxAlign = std::max(Align, MaxAlign);
100 Total = llvm::alignTo(Total, Align);
101 Total += TypeSizer().Visit(TyLoc);
104 Total = llvm::alignTo(Total, MaxAlign);
112#define ABSTRACT_TYPELOC(CLASS, PARENT)
113#define TYPELOC(CLASS, PARENT) \
114 TypeLoc Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
115 return TyLoc.getNextTypeLoc(); \
117#include "clang/AST/TypeLocNodes.def"
125 return NextLoc().Visit(TL);
135#define ABSTRACT_TYPELOC(CLASS, PARENT)
136#define TYPELOC(CLASS, PARENT) \
138 CLASS##TypeLoc TLCasted = TL.castAs<CLASS##TypeLoc>(); \
139 TLCasted.initializeLocal(Context, Loc); \
140 TL = TLCasted.getNextTypeLoc(); \
144#include "clang/AST/TypeLocNodes.def"
155 TypeLocCopier(
TypeLoc source) : Source(source) {}
157#define ABSTRACT_TYPELOC(CLASS, PARENT)
158#define TYPELOC(CLASS, PARENT) \
159 void Visit##CLASS##TypeLoc(CLASS##TypeLoc dest) { \
160 dest.copyLocal(Source.castAs<CLASS##TypeLoc>()); \
162#include "clang/AST/TypeLocNodes.def"
186 TypeLocCopier(other).Visit(TL);
212 case FunctionNoProto:
214 case DependentSizedArray:
215 case IncompleteArray:
242 return Last.getLocalSourceRange().getEnd();
245 case DependentSizedArray:
246 case IncompleteArray:
248 case FunctionNoProto:
259 case ObjCObjectPointer:
267 case LValueReference:
268 case RValueReference:
288 static bool isTypeSpec(
TypeLoc _) {
return false; }
290#define ABSTRACT_TYPELOC(CLASS, PARENT)
291#define TYPELOC(CLASS, PARENT) \
292 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
293 return isTypeSpec(TyLoc); \
295#include "clang/AST/TypeLocNodes.def"
308bool TypeSpecTypeLoc::isKind(
const TypeLoc &TL) {
310 return TSTChecker().
Visit(TL);
335 case BuiltinType::Void:
337 case BuiltinType::Bool:
339 case BuiltinType::Char_U:
340 case BuiltinType::Char_S:
342 case BuiltinType::Char8:
344 case BuiltinType::Char16:
346 case BuiltinType::Char32:
348 case BuiltinType::WChar_S:
349 case BuiltinType::WChar_U:
351 case BuiltinType::UChar:
352 case BuiltinType::UShort:
353 case BuiltinType::UInt:
354 case BuiltinType::ULong:
355 case BuiltinType::ULongLong:
356 case BuiltinType::UInt128:
357 case BuiltinType::SChar:
358 case BuiltinType::Short:
359 case BuiltinType::Int:
360 case BuiltinType::Long:
361 case BuiltinType::LongLong:
362 case BuiltinType::Int128:
363 case BuiltinType::Half:
364 case BuiltinType::Float:
365 case BuiltinType::Double:
366 case BuiltinType::LongDouble:
367 case BuiltinType::Float16:
368 case BuiltinType::Float128:
369 case BuiltinType::Ibm128:
370 case BuiltinType::ShortAccum:
371 case BuiltinType::Accum:
372 case BuiltinType::LongAccum:
373 case BuiltinType::UShortAccum:
374 case BuiltinType::UAccum:
375 case BuiltinType::ULongAccum:
376 case BuiltinType::ShortFract:
377 case BuiltinType::Fract:
378 case BuiltinType::LongFract:
379 case BuiltinType::UShortFract:
380 case BuiltinType::UFract:
381 case BuiltinType::ULongFract:
382 case BuiltinType::SatShortAccum:
383 case BuiltinType::SatAccum:
384 case BuiltinType::SatLongAccum:
385 case BuiltinType::SatUShortAccum:
386 case BuiltinType::SatUAccum:
387 case BuiltinType::SatULongAccum:
388 case BuiltinType::SatShortFract:
389 case BuiltinType::SatFract:
390 case BuiltinType::SatLongFract:
391 case BuiltinType::SatUShortFract:
392 case BuiltinType::SatUFract:
393 case BuiltinType::SatULongFract:
394 case BuiltinType::BFloat16:
395 llvm_unreachable(
"Builtin type needs extra local data!");
398 case BuiltinType::NullPtr:
399 case BuiltinType::Overload:
400 case BuiltinType::Dependent:
401 case BuiltinType::BoundMember:
402 case BuiltinType::UnknownAny:
403 case BuiltinType::ARCUnbridgedCast:
404 case BuiltinType::PseudoObject:
405 case BuiltinType::ObjCId:
406 case BuiltinType::ObjCClass:
407 case BuiltinType::ObjCSel:
408#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
409 case BuiltinType::Id:
410#include "clang/Basic/OpenCLImageTypes.def"
411#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
412 case BuiltinType::Id:
413#include "clang/Basic/OpenCLExtensionTypes.def"
414 case BuiltinType::OCLSampler:
415 case BuiltinType::OCLEvent:
416 case BuiltinType::OCLClkEvent:
417 case BuiltinType::OCLQueue:
418 case BuiltinType::OCLReserveID:
419#define SVE_TYPE(Name, Id, SingletonId) \
420 case BuiltinType::Id:
421#include "clang/Basic/AArch64SVEACLETypes.def"
422#define PPC_VECTOR_TYPE(Name, Id, Size) \
423 case BuiltinType::Id:
424#include "clang/Basic/PPCTypes.def"
425#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
426#include "clang/Basic/RISCVVTypes.def"
427#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
428#include "clang/Basic/WebAssemblyReferenceTypes.def"
429 case BuiltinType::BuiltinFn:
430 case BuiltinType::IncompleteMatrixIdx:
431 case BuiltinType::OMPArraySection:
432 case BuiltinType::OMPArrayShaping:
433 case BuiltinType::OMPIterator:
437 llvm_unreachable(
"Invalid BuiltinType Kind!");
442 TL = PTL.getInnerLoc();
447 if (
auto ATL = getAs<AttributedTypeLoc>()) {
448 const Attr *A = ATL.getAttr();
449 if (A && (isa<TypeNullableAttr>(A) || isa<TypeNonNullAttr>(A) ||
450 isa<TypeNullUnspecifiedAttr>(A)))
459 if (
auto qual = getAs<QualifiedTypeLoc>())
466 if (
attr.isQualifier())
return attr;
467 return attr.getModifiedLoc().findExplicitQualifierLoc();
497 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
545 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
553 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
564 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
574 Context,
getTypePtr()->template_arguments(), getArgInfos(), Loc);
580 for (
unsigned i = 0, e = Args.size(); i != e; ++i) {
583 llvm_unreachable(
"Impossible TemplateArgument");
604 TemplateName Template = Args[i].getAsTemplateOrTemplatePattern();
606 Builder.MakeTrivial(Context, DTN->getQualifier(), Loc);
608 Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
611 Context, Builder.getWithLocInContext(Context), Loc,
638 Context,
getTypePtr()->getTypeConstraintArguments(), getArgInfos(), Loc);
645 class GetContainedAutoTypeLocVisitor :
716 TypeLoc Res = GetContainedAutoTypeLocVisitor().Visit(*
this);
Defines the clang::ASTContext interface.
static Decl::Kind getKind(const Decl *D)
Defines the C++ template declaration subclasses.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
static const unsigned TypeLocMaxDataAlign
Defines the clang::TypeLoc interface and its subclasses.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
TypeLoc getOriginalLoc() const
Wrapper for source info for arrays.
TypeLoc getElementLoc() const
Attr - This represents one attribute.
SourceLocation getLocation() const
SourceRange getRange() const
Type source information for an attributed type.
const Attr * getAttr() const
The type attribute.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
SourceRange getLocalSourceRange() const
DeclarationNameInfo getConceptNameInfo() const
void setConceptNameLoc(SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void setFoundDecl(NamedDecl *D)
ConceptDecl * getNamedConcept() const
void setTemplateKWLoc(SourceLocation Loc)
void setLAngleLoc(SourceLocation Loc)
void setNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
void setRAngleLoc(SourceLocation Loc)
void setRParenLoc(SourceLocation Loc)
Type source information for an btf_tag attributed type.
TypeLoc getWrappedLoc() const
const BTFTypeTagAttr * getAttr() const
The btf_type_tag attribute.
SourceRange getLocalSourceRange() const
Wrapper for source info for block pointers.
TypeSpecifierType getWrittenTypeSpec() const
bool needsExtraLocalData() const
WrittenBuiltinSpecs & getWrittenBuiltinSpecs()
const BuiltinType * getTypePtr() const
LocalData * getLocalData() const
SourceLocation getLocation() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void setNameLoc(SourceLocation Loc)
void setElaboratedKeywordLoc(SourceLocation Loc)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Represents a dependent template name that cannot be resolved prior to template instantiation.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void setTemplateKeywordLoc(SourceLocation Loc)
void setElaboratedKeywordLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void setLAngleLoc(SourceLocation Loc)
void setTemplateNameLoc(SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void setElaboratedKeywordLoc(SourceLocation Loc)
TypeLoc getNamedTypeLoc() const
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Wrapper for source info for functions.
TypeLoc getReturnLoc() const
const TypeClass * getTypePtr() const
TypeLoc getInnerLoc() const
Wrapper for source info for member pointers.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
A C++ nested-name-specifier augmented with source location information.
Wraps an ObjCPointerType with source location information.
SourceLocation getStarLoc() const
void setTypeArgsRAngleLoc(SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
unsigned getNumTypeArgs() const
unsigned getNumProtocols() const
void setTypeArgsLAngleLoc(SourceLocation Loc)
void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo)
void setProtocolLAngleLoc(SourceLocation Loc)
void setProtocolRAngleLoc(SourceLocation Loc)
void setHasBaseTypeAsWritten(bool HasBaseType)
void setProtocolLoc(unsigned i, SourceLocation Loc)
unsigned getNumProtocols() const
void setProtocolLoc(unsigned i, SourceLocation Loc)
void setProtocolLAngleLoc(SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void setProtocolRAngleLoc(SourceLocation Loc)
void setNameLoc(SourceLocation Loc)
TypeLoc getPatternLoc() const
TypeLoc getInnerLoc() const
TypeLoc getPointeeLoc() const
Wrapper for source info for pointers.
A (possibly-)qualified type.
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Represents a template name that was expressed as a qualified name.
Wrapper of type source information for a type with non-trivial direct qualifiers.
UnqualTypeLoc getUnqualifiedLoc() const
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
TagDecl * getDecl() const
bool isDefinition() const
True if the tag was defined in this type specifier.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Represents a C++ template name within the type system.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
static void initializeArgLocs(ASTContext &Context, ArrayRef< TemplateArgument > Args, TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc)
RetTy Visit(TypeLoc TyLoc)
Base wrapper for a particular "section" of type source info.
SourceLocation findNullabilityLoc() const
Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier),...
static unsigned getLocalAlignmentForType(QualType Ty)
Returns the alignment of type source info data block for the given type.
TypeLoc findExplicitQualifierLoc() const
Find a type with the location of an explicit type qualifier.
QualType getType() const
Get the type for which this source info wrapper provides information.
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
SourceRange getLocalSourceRange() const
Get the local source range.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
AutoTypeLoc getContainedAutoTypeLoc() const
Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this ...
void copy(TypeLoc other)
Copies the other type loc into this one.
TypeLocClass getTypeLocClass() const
static unsigned getFullDataSizeForType(QualType Ty)
Returns the size of type source info data block for the given type.
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
SourceRange getLocalSourceRange() const
Expr * getUnderlyingExpr() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
QualType getUnmodifiedType() const
A reasonable base class for TypeLocs that correspond to types that are written as a type-specifier.
SourceLocation getNameLoc() const
void setNameLoc(SourceLocation Loc)
SourceLocation getRParenLoc() const
SourceLocation getTypeofLoc() const
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
TypeSpecifierType
Specifies the kind of type.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Location information for a TemplateArgument.