Go to the documentation of this file.
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/MathExtras.h"
31 using namespace clang;
41 class 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);
206 case FunctionNoProto:
208 case DependentSizedArray:
209 case IncompleteArray:
236 return Last.getLocalSourceRange().getEnd();
239 case DependentSizedArray:
240 case IncompleteArray:
242 case FunctionNoProto:
254 case LValueReference:
255 case RValueReference:
273 static bool isTypeSpec(
TypeLoc _) {
return false; }
275 #define ABSTRACT_TYPELOC(CLASS, PARENT)
276 #define TYPELOC(CLASS, PARENT) \
277 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
278 return isTypeSpec(TyLoc); \
280 #include "clang/AST/TypeLocNodes.def"
293 bool TypeSpecTypeLoc::isKind(
const TypeLoc &TL) {
295 return TSTChecker().
Visit(TL);
320 case BuiltinType::Void:
322 case BuiltinType::Bool:
324 case BuiltinType::Char_U:
325 case BuiltinType::Char_S:
327 case BuiltinType::Char8:
329 case BuiltinType::Char16:
331 case BuiltinType::Char32:
333 case BuiltinType::WChar_S:
334 case BuiltinType::WChar_U:
336 case BuiltinType::UChar:
337 case BuiltinType::UShort:
338 case BuiltinType::UInt:
339 case BuiltinType::ULong:
340 case BuiltinType::ULongLong:
341 case BuiltinType::UInt128:
342 case BuiltinType::SChar:
343 case BuiltinType::Short:
344 case BuiltinType::Int:
345 case BuiltinType::Long:
346 case BuiltinType::LongLong:
347 case BuiltinType::Int128:
348 case BuiltinType::Half:
349 case BuiltinType::Float:
350 case BuiltinType::Double:
351 case BuiltinType::LongDouble:
352 case BuiltinType::Float16:
353 case BuiltinType::Float128:
354 case BuiltinType::ShortAccum:
355 case BuiltinType::Accum:
356 case BuiltinType::LongAccum:
357 case BuiltinType::UShortAccum:
358 case BuiltinType::UAccum:
359 case BuiltinType::ULongAccum:
360 case BuiltinType::ShortFract:
361 case BuiltinType::Fract:
362 case BuiltinType::LongFract:
363 case BuiltinType::UShortFract:
364 case BuiltinType::UFract:
365 case BuiltinType::ULongFract:
366 case BuiltinType::SatShortAccum:
367 case BuiltinType::SatAccum:
368 case BuiltinType::SatLongAccum:
369 case BuiltinType::SatUShortAccum:
370 case BuiltinType::SatUAccum:
371 case BuiltinType::SatULongAccum:
372 case BuiltinType::SatShortFract:
373 case BuiltinType::SatFract:
374 case BuiltinType::SatLongFract:
375 case BuiltinType::SatUShortFract:
376 case BuiltinType::SatUFract:
377 case BuiltinType::SatULongFract:
378 case BuiltinType::BFloat16:
379 llvm_unreachable(
"Builtin type needs extra local data!");
382 case BuiltinType::NullPtr:
383 case BuiltinType::Overload:
384 case BuiltinType::Dependent:
385 case BuiltinType::BoundMember:
386 case BuiltinType::UnknownAny:
387 case BuiltinType::ARCUnbridgedCast:
388 case BuiltinType::PseudoObject:
389 case BuiltinType::ObjCId:
390 case BuiltinType::ObjCClass:
391 case BuiltinType::ObjCSel:
392 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
393 case BuiltinType::Id:
394 #include "clang/Basic/OpenCLImageTypes.def"
395 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
396 case BuiltinType::Id:
397 #include "clang/Basic/OpenCLExtensionTypes.def"
398 case BuiltinType::OCLSampler:
399 case BuiltinType::OCLEvent:
400 case BuiltinType::OCLClkEvent:
401 case BuiltinType::OCLQueue:
402 case BuiltinType::OCLReserveID:
403 #define SVE_TYPE(Name, Id, SingletonId) \
404 case BuiltinType::Id:
405 #include "clang/Basic/AArch64SVEACLETypes.def"
406 #define PPC_VECTOR_TYPE(Name, Id, Size) \
407 case BuiltinType::Id:
408 #include "clang/Basic/PPCTypes.def"
409 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
410 #include "clang/Basic/RISCVVTypes.def"
411 case BuiltinType::BuiltinFn:
412 case BuiltinType::IncompleteMatrixIdx:
413 case BuiltinType::OMPArraySection:
414 case BuiltinType::OMPArrayShaping:
415 case BuiltinType::OMPIterator:
419 llvm_unreachable(
"Invalid BuiltinType Kind!");
424 TL = PTL.getInnerLoc();
429 if (
auto ATL = getAs<AttributedTypeLoc>()) {
430 const Attr *A = ATL.getAttr();
431 if (A && (isa<TypeNullableAttr>(A) || isa<TypeNonNullAttr>(A) ||
432 isa<TypeNullUnspecifiedAttr>(A)))
441 if (
auto qual = getAs<QualifiedTypeLoc>())
448 if (attr.isQualifier())
return attr;
449 return attr.getModifiedLoc().findExplicitQualifierLoc();
479 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
521 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
529 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
540 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
559 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
562 llvm_unreachable(
"Impossible TemplateArgument");
585 Builder.MakeTrivial(Context, DTN->getQualifier(), Loc);
587 Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
590 Context, Builder.getWithLocInContext(Context), Loc,
624 class GetContainedAutoTypeLocVisitor :
691 TypeLoc Res = GetContainedAutoTypeLocVisitor().Visit(*
this);
void setTemplateKeywordLoc(SourceLocation Loc)
TypeLoc getInnerLoc() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
__DEVICE__ int max(int __a, int __b)
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Wrapper for source info for block pointers.
A trivial tuple used to represent a source range.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Wrapper for source info for pointers.
void copy(TypeLoc other)
Copies the other type loc into this one.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
TypeOfTypeLocInfo * getLocalData() const
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
void setFoundDecl(NamedDecl *D)
TypeSpecifierType getWrittenTypeSpec() const
Encodes a location in the source.
SourceLocation getBegin() const
SourceLocation getLocation() const
A (possibly-)qualified type.
void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo)
static const unsigned TypeLocMaxDataAlign
void setRAngleLoc(SourceLocation Loc)
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
bool isDefinition() const
True if the tag was defined in this type specifier.
static unsigned getFullDataSizeForType(QualType Ty)
Returns the size of type source info data block for the given type.
const Attr * getAttr() const
The type attribute.
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getNameLoc() const
TypeLoc getElementLoc() const
void setNameLoc(SourceLocation Loc)
const BuiltinType * getTypePtr() const
void setProtocolLoc(unsigned i, SourceLocation Loc)
void setProtocolLoc(unsigned i, SourceLocation Loc)
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
void setElaboratedKeywordLoc(SourceLocation Loc)
void setProtocolRAngleLoc(SourceLocation Loc)
void setProtocolLAngleLoc(SourceLocation Loc)
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
SourceLocation getBeginLoc() const
Get the begin source location.
Wrapper for source info for functions.
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
TypeSourceInfo * UnderlyingTInfo
void setHasBaseTypeAsWritten(bool HasBaseType)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
ArgKind getKind() const
Return the kind of stored template argument.
Wrapper of type source information for a type with non-trivial direct qualifiers.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
void setTemplateKWLoc(SourceLocation Loc)
unsigned getNumProtocols() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TagDecl * getDecl() const
Represents a template argument.
void setRAngleLoc(SourceLocation Loc)
TypeLoc getInnerLoc() const
AutoTypeLoc getContainedAutoTypeLoc() const
Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this ...
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
unsigned getNumProtocols() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Represents the declaration of a struct/union/class/enum.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Type source information for an attributed type.
A C++ nested-name-specifier augmented with source location information.
bool needsExtraLocalData() const
Wrapper for source info for member pointers.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
void setTemplateNameLoc(SourceLocation Loc)
Class that aids in the construction of nested-name-specifiers along with source-location information ...
static Decl::Kind getKind(const Decl *D)
void setLAngleLoc(SourceLocation Loc)
SourceLocation findNullabilityLoc() const
Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier),...
void setElaboratedKeywordLoc(SourceLocation Loc)
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
DeclarationNameInfo getConceptNameInfo() const
Represents a dependent template name that cannot be resolved prior to template instantiation.
void setProtocolLAngleLoc(SourceLocation Loc)
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
void setConceptNameLoc(SourceLocation Loc)
SourceRange getLocalSourceRange() const
Get the local source range.
SourceRange getRange() const
TypeLoc getNamedTypeLoc() const
unsigned getFullDataSize() const
Returns the size of the type source info data block.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
SourceRange getLocalSourceRange() const
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
A reasonable base class for TypeLocs that correspond to types that are written as a type-specifier.
Represents a C++ template name within the type system.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
void setElaboratedKeywordLoc(SourceLocation Loc)
Base wrapper for a particular "section" of type source info.
QualType getType() const
Get the type for which this source info wrapper provides information.
Represents a template name that was expressed as a qualified name.
TypeLoc getPatternLoc() const
void setTypeArgsRAngleLoc(SourceLocation Loc)
static unsigned getLocalAlignmentForType(QualType Ty)
Returns the alignment of type source info data block for the given type.
Wrapper for source info for arrays.
TypeLoc IgnoreParens() const
TypeLoc getPointeeLoc() const
TypeLoc getOriginalLoc() const
TypeLocClass getTypeLocClass() const
@ Type
The template argument is a type.
Dataflow Directional Tag Classes.
@ Template
The template argument is a template name that was provided for a template template parameter.
void setNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Expr * getUnderlyingExpr() const
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
bool isValid() const
Return true if this is a valid SourceLocation object.
Attr - This represents one attribute.
static void initializeArgLocs(ASTContext &Context, unsigned NumArgs, const TemplateArgument *Args, TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc)
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
SourceRange getLocalSourceRange() const
TypeLoc findExplicitQualifierLoc() const
Find a type with the location of an explicit type qualifier.
QualType getUnderlyingType() const
void setNameLoc(SourceLocation Loc)
SourceLocation getRParenLoc() const
TypeLoc getReturnLoc() const
void setProtocolRAngleLoc(SourceLocation Loc)
UnqualTypeLoc getUnqualifiedLoc() const
void setNameLoc(SourceLocation Loc)
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
void setTypeArgsLAngleLoc(SourceLocation Loc)
const TypeClass * getTypePtr() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
WrittenBuiltinSpecs & getWrittenBuiltinSpecs()
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
ConceptDecl * getNamedConcept() const
SourceLocation getTypeofLoc() const
unsigned getNumArgs() const
unsigned getNumTypeArgs() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
SourceLocation getLocation() const
void setLAngleLoc(SourceLocation Loc)
Location information for a TemplateArgument.
RetTy Visit(TypeLoc TyLoc)
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
QualType getAsType() const
Retrieve the type for a type template argument.
@ Pack
The template argument is actually a parameter pack.
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
TypeSpecifierType
Specifies the kind of type.
unsigned getNumArgs() const