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" 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;
98 unsigned Align = getLocalAlignmentForType(TyLoc.
getType());
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),
177 llvm::alignTo(reinterpret_cast<uintptr_t>(other.
Data),
186 TypeLocCopier(other).Visit(TL);
206 case FunctionNoProto:
208 case DependentSizedArray:
209 case IncompleteArray:
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);
308 if (getRParenLoc().isValid())
309 return SourceRange(getTypeofLoc(), getRParenLoc());
317 if (needsExtraLocalData())
319 switch (getTypePtr()->getKind()) {
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 llvm_unreachable(
"Builtin type needs extra local data!");
381 case BuiltinType::NullPtr:
382 case BuiltinType::Overload:
383 case BuiltinType::Dependent:
384 case BuiltinType::BoundMember:
385 case BuiltinType::UnknownAny:
386 case BuiltinType::ARCUnbridgedCast:
387 case BuiltinType::PseudoObject:
388 case BuiltinType::ObjCId:
389 case BuiltinType::ObjCClass:
390 case BuiltinType::ObjCSel:
391 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 392 case BuiltinType::Id: 393 #include "clang/Basic/OpenCLImageTypes.def" 394 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 395 case BuiltinType::Id: 396 #include "clang/Basic/OpenCLExtensionTypes.def" 397 case BuiltinType::OCLSampler:
398 case BuiltinType::OCLEvent:
399 case BuiltinType::OCLClkEvent:
400 case BuiltinType::OCLQueue:
401 case BuiltinType::OCLReserveID:
402 #define SVE_TYPE(Name, Id, SingletonId) \ 403 case BuiltinType::Id: 404 #include "clang/Basic/AArch64SVEACLETypes.def" 405 case BuiltinType::BuiltinFn:
406 case BuiltinType::OMPArraySection:
410 llvm_unreachable(
"Invalid BuiltinType Kind!");
415 TL = PTL.getInnerLoc();
420 if (
auto ATL = getAs<AttributedTypeLoc>()) {
421 const Attr *A = ATL.getAttr();
422 if (A && (isa<TypeNullableAttr>(A) || isa<TypeNonNullAttr>(A) ||
423 isa<TypeNullUnspecifiedAttr>(A)))
432 if (
auto qual = getAs<QualifiedTypeLoc>())
439 if (attr.isQualifier())
return attr;
440 return attr.getModifiedLoc().findExplicitQualifierLoc();
454 if (!getNumProtocols())
return;
456 setProtocolLAngleLoc(Loc);
457 setProtocolRAngleLoc(Loc);
458 for (
unsigned i = 0, e = getNumProtocols(); i != e; ++i)
459 setProtocolLoc(i, Loc);
464 setHasBaseTypeAsWritten(
true);
465 setTypeArgsLAngleLoc(Loc);
466 setTypeArgsRAngleLoc(Loc);
467 for (
unsigned i = 0, e = getNumTypeArgs(); i != e; ++i) {
470 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
472 setProtocolLAngleLoc(Loc);
473 setProtocolRAngleLoc(Loc);
474 for (
unsigned i = 0, e = getNumProtocols(); i != e; ++i)
475 setProtocolLoc(i, Loc);
488 return getAttr() ? getAttr()->getRange() :
SourceRange();
504 this->setUnderlyingTInfo(
510 setElaboratedKeywordLoc(Loc);
512 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
518 setElaboratedKeywordLoc(Loc);
520 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
528 setElaboratedKeywordLoc(Loc);
529 if (getTypePtr()->getQualifier()) {
531 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
536 setTemplateKeywordLoc(Loc);
537 setTemplateNameLoc(Loc);
541 getTypePtr()->getArgs(),
550 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
553 llvm_unreachable(
"Impossible TemplateArgument");
576 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
578 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
596 getLocalData()->ConceptNameLoc);
601 setTemplateKWLoc(Loc);
602 setConceptNameLoc(Loc);
603 setFoundDecl(
nullptr);
607 getTypePtr()->getArgs(),
615 class GetContainedAutoTypeLocVisitor :
682 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.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
The template argument is an expression, and we've not resolved it to one of the other forms yet...
RetTy Visit(TypeLoc TyLoc)
Defines the C++ template declaration subclasses.
SourceRange getLocalSourceRange() const
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
TypeLoc getOriginalLoc() const
SourceLocation getEndLoc() const
Get the end source location.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
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
A reasonable base class for TypeLocs that correspond to types that are written as a type-specifier...
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.
__DEVICE__ int max(int __a, int __b)
DeclarationNameInfo getConceptNameInfo() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Wrapper for source info for functions.
SourceLocation findNullabilityLoc() const
Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier), if there is one.
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, which defaults to the empty location.
SourceLocation getBeginLoc() const
Get the begin source location.
Type source information for an attributed type.
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...
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Represents a C++ template name within the type system.
Defines the clang::TypeLoc interface and its subclasses.
SourceLocation getEnd() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
TypeLoc getInnerLoc() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
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
Encodes a location in the source.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Represents the declaration of a struct/union/class/enum.
static QualType getUnderlyingType(const SubRegion *R)
SourceLocation getLocation() const
static const unsigned TypeLocMaxDataAlign
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.
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...
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...
TypeLoc getPointeeLoc() const
static void initializeArgLocs(ASTContext &Context, unsigned NumArgs, const TemplateArgument *Args, TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc)
TypeLocClass getTypeLocClass() const
The template argument is a type.
The template argument is actually a parameter pack.
UnqualTypeLoc getUnqualifiedLoc() const
ArgKind getKind() const
Return the kind of stored template argument.
Defines the clang::SourceLocation class and associated facilities.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
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.
Location information for a TemplateArgument.
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.
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...
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Wrapper for source info for pointers.
SourceLocation getBegin() const
Wrapper for source info for block pointers.
Attr - This represents one attribute.
SourceLocation getLocation() const