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" 173 if (reinterpret_cast<uintptr_t>(
Data) ==
174 llvm::alignTo(reinterpret_cast<uintptr_t>(
Data),
176 reinterpret_cast<uintptr_t>(other.
Data) ==
177 llvm::alignTo(reinterpret_cast<uintptr_t>(other.
Data),
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:
344 case BuiltinType::Int:
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 case BuiltinType::BuiltinFn:
410 case BuiltinType::IncompleteMatrixIdx:
411 case BuiltinType::OMPArraySection:
412 case BuiltinType::OMPArrayShaping:
413 case BuiltinType::OMPIterator:
417 llvm_unreachable(
"Invalid BuiltinType Kind!");
422 TL = PTL.getInnerLoc();
427 if (
auto ATL = getAs<AttributedTypeLoc>()) {
428 const Attr *A = ATL.getAttr();
429 if (A && (isa<TypeNullableAttr>(A) || isa<TypeNonNullAttr>(A) ||
430 isa<TypeNullUnspecifiedAttr>(A)))
439 if (
auto qual = getAs<QualifiedTypeLoc>())
446 if (attr.isQualifier())
return attr;
447 return attr.getModifiedLoc().findExplicitQualifierLoc();
477 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
519 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
527 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
538 Builder.MakeTrivial(Context,
getTypePtr()->getQualifier(), Loc);
557 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
560 llvm_unreachable(
"Impossible TemplateArgument");
583 Builder.MakeTrivial(Context, DTN->getQualifier(), Loc);
585 Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
588 Context, Builder.getWithLocInContext(Context), Loc,
622 class GetContainedAutoTypeLocVisitor :
689 TypeLoc Res = GetContainedAutoTypeLocVisitor().Visit(*
this);
Defines the clang::ASTContext interface.
static unsigned getFullDataSizeForType(QualType Ty)
Returns the size of type source info data block for the given type.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
const TypeClass * getTypePtr() const
A (possibly-)qualified type.
const BuiltinType * getTypePtr() const
unsigned getNumArgs() const
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
void setConceptNameLoc(SourceLocation Loc)
__DEVICE__ int max(int __a, int __b)
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
RetTy Visit(TypeLoc TyLoc)
WrittenBuiltinSpecs & getWrittenBuiltinSpecs()
Defines the C++ template declaration subclasses.
The base class of the type hierarchy.
SourceRange getLocalSourceRange() const
void setLAngleLoc(SourceLocation Loc)
void setTemplateKeywordLoc(SourceLocation Loc)
The template argument is a declaration that was provided for a pointer, reference,...
TypeLoc getOriginalLoc() const
SourceLocation getEndLoc() const
Get the end source location.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
SourceLocation getRParenLoc() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Wrapper for source info for member pointers.
Wrapper of type source information for a type with non-trivial direct qualifiers.
Represents an empty template argument, e.g., one that has not been deduced.
TypeSpecifierType
Specifies the kind of type.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
TypeLoc getNamedTypeLoc() const
void setProtocolRAngleLoc(SourceLocation Loc)
ConceptDecl * getNamedConcept() const
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
A reasonable base class for TypeLocs that correspond to types that are written as a type-specifier.
void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo)
bool needsExtraLocalData() const
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Base wrapper for a particular "section" of type source info.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
Represents a dependent template name that cannot be resolved prior to template instantiation.
TypeLoc getInnerLoc() const
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
bool isDefinition() const
True if the tag was defined in this type specifier.
void setElaboratedKeywordLoc(SourceLocation Loc)
DeclarationNameInfo getConceptNameInfo() const
void setProtocolLoc(unsigned i, SourceLocation Loc)
void setNameLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
unsigned getNumProtocols() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Wrapper for source info for functions.
void setNameLoc(SourceLocation Loc)
void setProtocolLoc(unsigned i, SourceLocation Loc)
SourceLocation findNullabilityLoc() const
Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier),...
Class that aids in the construction of nested-name-specifiers along with source-location information ...
SourceRange getLocalSourceRange() const
Get the local source range.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
void setTemplateNameLoc(SourceLocation Loc)
TagDecl * getDecl() const
SourceLocation getBeginLoc() const
Get the begin source location.
Type source information for an attributed type.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
void setFoundDecl(NamedDecl *D)
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
void setTemplateKWLoc(SourceLocation Loc)
Represents a C++ template name within the type system.
Defines the clang::TypeLoc interface and its subclasses.
void setNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
void setHasBaseTypeAsWritten(bool HasBaseType)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
TypeLoc getInnerLoc() const
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
TypeSourceInfo * UnderlyingTInfo
TypeLoc getReturnLoc() const
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Wrapper for source info for arrays.
AutoTypeLoc getContainedAutoTypeLoc() const
Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this ...
TypeLoc getPatternLoc() const
TypeLoc IgnoreParens() const
void setLAngleLoc(SourceLocation Loc)
const Attr * getAttr() const
The type attribute.
Encodes a location in the source.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void setProtocolLAngleLoc(SourceLocation Loc)
Represents the declaration of a struct/union/class/enum.
void setProtocolRAngleLoc(SourceLocation Loc)
SourceLocation getLocation() const
static const unsigned TypeLocMaxDataAlign
SourceRange getRange() const
void setElaboratedKeywordLoc(SourceLocation Loc)
TypeLoc findExplicitQualifierLoc() const
Find a type with the location of an explicit type qualifier.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
unsigned getFullDataSize() const
Returns the size of the type source info data block.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
TypeLoc getElementLoc() const
Defines various enumerations that describe declaration and type specifiers.
void setTypeArgsLAngleLoc(SourceLocation Loc)
SourceLocation getTypeofLoc() const
Represents a template argument.
Represents a template name that was expressed as a qualified name.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
QualType getType() const
Get the type for which this source info wrapper provides information.
The template argument is a pack expansion of a template name that was provided for a template templat...
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
TypeOfTypeLocInfo * getLocalData() const
SourceRange getLocalSourceRange() const
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
void setNameLoc(SourceLocation Loc)
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
TypeLoc getPointeeLoc() const
static void initializeArgLocs(ASTContext &Context, unsigned NumArgs, const TemplateArgument *Args, TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc)
TypeLocClass getTypeLocClass() const
void setTypeArgsRAngleLoc(SourceLocation Loc)
The template argument is a type.
unsigned getNumArgs() const
The template argument is actually a parameter pack.
UnqualTypeLoc getUnqualifiedLoc() const
void setRAngleLoc(SourceLocation Loc)
ArgKind getKind() const
Return the kind of stored template argument.
Defines the clang::SourceLocation class and associated facilities.
The template argument is a template name that was provided for a template template parameter.
static unsigned getLocalAlignmentForType(QualType Ty)
Returns the alignment of type source info data block for the given type.
unsigned getNumProtocols() const
Location information for a TemplateArgument.
SourceLocation getNameLoc() const
QualType getUnderlyingType() const
unsigned getNumTypeArgs() const
static Decl::Kind getKind(const Decl *D)
QualType getAsType() const
Retrieve the type for a type template argument.
void copy(TypeLoc other)
Copies the other type loc into this one.
void setProtocolLAngleLoc(SourceLocation Loc)
TypeSpecifierType getWrittenTypeSpec() const
A trivial tuple used to represent a source range.
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Expr * getUnderlyingExpr() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Wrapper for source info for pointers.
SourceLocation getBegin() const
Wrapper for source info for block pointers.
void setElaboratedKeywordLoc(SourceLocation Loc)
Attr - This represents one attribute.
SourceLocation getLocation() const