22 #include "llvm/Support/ErrorHandling.h" 23 #include "llvm/Support/MathExtras.h" 29 using namespace clang;
39 class TypeLocRanger :
public TypeLocVisitor<TypeLocRanger, SourceRange> {
41 #define ABSTRACT_TYPELOC(CLASS, PARENT) 42 #define TYPELOC(CLASS, PARENT) \ 43 SourceRange Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 44 return TyLoc.getLocalSourceRange(); \ 46 #include "clang/AST/TypeLocNodes.def" 53 return TypeLocRanger().Visit(TL);
60 #define ABSTRACT_TYPELOC(CLASS, PARENT) 61 #define TYPELOC(CLASS, PARENT) \ 62 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 63 return TyLoc.getLocalDataAlignment(); \ 65 #include "clang/AST/TypeLocNodes.def" 73 return TypeAligner().Visit(
TypeLoc(Ty,
nullptr));
80 #define ABSTRACT_TYPELOC(CLASS, PARENT) 81 #define TYPELOC(CLASS, PARENT) \ 82 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 83 return TyLoc.getLocalDataSize(); \ 85 #include "clang/AST/TypeLocNodes.def" 94 unsigned MaxAlign = 1;
96 unsigned Align = getLocalAlignmentForType(TyLoc.
getType());
97 MaxAlign =
std::max(Align, MaxAlign);
98 Total = llvm::alignTo(Total, Align);
99 Total += TypeSizer().Visit(TyLoc);
102 Total = llvm::alignTo(Total, MaxAlign);
110 #define ABSTRACT_TYPELOC(CLASS, PARENT) 111 #define TYPELOC(CLASS, PARENT) \ 112 TypeLoc Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 113 return TyLoc.getNextTypeLoc(); \ 115 #include "clang/AST/TypeLocNodes.def" 123 return NextLoc().Visit(TL);
133 #define ABSTRACT_TYPELOC(CLASS, PARENT) 134 #define TYPELOC(CLASS, PARENT) \ 136 CLASS##TypeLoc TLCasted = TL.castAs<CLASS##TypeLoc>(); \ 137 TLCasted.initializeLocal(Context, Loc); \ 138 TL = TLCasted.getNextTypeLoc(); \ 142 #include "clang/AST/TypeLocNodes.def" 153 TypeLocCopier(
TypeLoc source) : Source(source) {}
155 #define ABSTRACT_TYPELOC(CLASS, PARENT) 156 #define TYPELOC(CLASS, PARENT) \ 157 void Visit##CLASS##TypeLoc(CLASS##TypeLoc dest) { \ 158 dest.copyLocal(Source.castAs<CLASS##TypeLoc>()); \ 160 #include "clang/AST/TypeLocNodes.def" 171 if (reinterpret_cast<uintptr_t>(Data) ==
172 llvm::alignTo(reinterpret_cast<uintptr_t>(Data),
175 llvm::alignTo(reinterpret_cast<uintptr_t>(other.
Data),
184 TypeLocCopier(other).Visit(TL);
204 case FunctionNoProto:
206 case DependentSizedArray:
207 case IncompleteArray:
237 case DependentSizedArray:
238 case IncompleteArray:
240 case FunctionNoProto:
252 case LValueReference:
253 case RValueReference:
271 static bool isTypeSpec(
TypeLoc _) {
return false; }
273 #define ABSTRACT_TYPELOC(CLASS, PARENT) 274 #define TYPELOC(CLASS, PARENT) \ 275 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 276 return isTypeSpec(TyLoc); \ 278 #include "clang/AST/TypeLocNodes.def" 291 bool TypeSpecTypeLoc::isKind(
const TypeLoc &TL) {
293 return TSTChecker().
Visit(TL);
300 if (getRParenLoc().isValid())
301 return SourceRange(getTypeofLoc(), getRParenLoc());
309 if (needsExtraLocalData())
311 switch (getTypePtr()->getKind()) {
312 case BuiltinType::Void:
314 case BuiltinType::Bool:
316 case BuiltinType::Char_U:
317 case BuiltinType::Char_S:
319 case BuiltinType::Char8:
321 case BuiltinType::Char16:
323 case BuiltinType::Char32:
325 case BuiltinType::WChar_S:
326 case BuiltinType::WChar_U:
328 case BuiltinType::UChar:
329 case BuiltinType::UShort:
330 case BuiltinType::UInt:
331 case BuiltinType::ULong:
332 case BuiltinType::ULongLong:
333 case BuiltinType::UInt128:
334 case BuiltinType::SChar:
335 case BuiltinType::Short:
336 case BuiltinType::Int:
337 case BuiltinType::Long:
338 case BuiltinType::LongLong:
339 case BuiltinType::Int128:
340 case BuiltinType::Half:
341 case BuiltinType::Float:
342 case BuiltinType::Double:
343 case BuiltinType::LongDouble:
344 case BuiltinType::Float16:
345 case BuiltinType::Float128:
346 case BuiltinType::ShortAccum:
347 case BuiltinType::Accum:
348 case BuiltinType::LongAccum:
349 case BuiltinType::UShortAccum:
350 case BuiltinType::UAccum:
351 case BuiltinType::ULongAccum:
352 case BuiltinType::ShortFract:
353 case BuiltinType::Fract:
354 case BuiltinType::LongFract:
355 case BuiltinType::UShortFract:
356 case BuiltinType::UFract:
357 case BuiltinType::ULongFract:
358 case BuiltinType::SatShortAccum:
359 case BuiltinType::SatAccum:
360 case BuiltinType::SatLongAccum:
361 case BuiltinType::SatUShortAccum:
362 case BuiltinType::SatUAccum:
363 case BuiltinType::SatULongAccum:
364 case BuiltinType::SatShortFract:
365 case BuiltinType::SatFract:
366 case BuiltinType::SatLongFract:
367 case BuiltinType::SatUShortFract:
368 case BuiltinType::SatUFract:
369 case BuiltinType::SatULongFract:
370 llvm_unreachable(
"Builtin type needs extra local data!");
373 case BuiltinType::NullPtr:
374 case BuiltinType::Overload:
375 case BuiltinType::Dependent:
376 case BuiltinType::BoundMember:
377 case BuiltinType::UnknownAny:
378 case BuiltinType::ARCUnbridgedCast:
379 case BuiltinType::PseudoObject:
380 case BuiltinType::ObjCId:
381 case BuiltinType::ObjCClass:
382 case BuiltinType::ObjCSel:
383 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 384 case BuiltinType::Id: 385 #include "clang/Basic/OpenCLImageTypes.def" 386 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 387 case BuiltinType::Id: 388 #include "clang/Basic/OpenCLExtensionTypes.def" 389 case BuiltinType::OCLSampler:
390 case BuiltinType::OCLEvent:
391 case BuiltinType::OCLClkEvent:
392 case BuiltinType::OCLQueue:
393 case BuiltinType::OCLReserveID:
394 case BuiltinType::BuiltinFn:
395 case BuiltinType::OMPArraySection:
399 llvm_unreachable(
"Invalid BuiltinType Kind!");
404 TL = PTL.getInnerLoc();
409 if (
auto ATL = getAs<AttributedTypeLoc>()) {
410 const Attr *A = ATL.getAttr();
411 if (A && (isa<TypeNullableAttr>(A) || isa<TypeNonNullAttr>(A) ||
412 isa<TypeNullUnspecifiedAttr>(A)))
421 if (
auto qual = getAs<QualifiedTypeLoc>())
428 if (attr.isQualifier())
return attr;
429 return attr.getModifiedLoc().findExplicitQualifierLoc();
443 if (!getNumProtocols())
return;
445 setProtocolLAngleLoc(Loc);
446 setProtocolRAngleLoc(Loc);
447 for (
unsigned i = 0, e = getNumProtocols();
i != e; ++
i)
448 setProtocolLoc(
i, Loc);
453 setHasBaseTypeAsWritten(
true);
454 setTypeArgsLAngleLoc(Loc);
455 setTypeArgsRAngleLoc(Loc);
456 for (
unsigned i = 0, e = getNumTypeArgs();
i != e; ++
i) {
459 getTypePtr()->getTypeArgsAsWritten()[
i], Loc));
461 setProtocolLAngleLoc(Loc);
462 setProtocolRAngleLoc(Loc);
463 for (
unsigned i = 0, e = getNumProtocols();
i != e; ++
i)
464 setProtocolLoc(
i, Loc);
480 this->setUnderlyingTInfo(
486 setElaboratedKeywordLoc(Loc);
488 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
494 setElaboratedKeywordLoc(Loc);
496 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
504 setElaboratedKeywordLoc(Loc);
505 if (getTypePtr()->getQualifier()) {
507 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
512 setTemplateKeywordLoc(Loc);
513 setTemplateNameLoc(Loc);
517 getTypePtr()->getArgs(),
526 for (
unsigned i = 0, e = NumArgs;
i != e; ++
i) {
529 llvm_unreachable(
"Impossible TemplateArgument");
552 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
554 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
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)
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
SourceLocation getEndLoc() const
Get the end source location.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
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.
A reasonable base class for TypeLocs that correspond to types that are written as a type-specifier...
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.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
__DEVICE__ int max(int __a, int __b)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
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.
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)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
Encodes a location in the source.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
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.
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
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.
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.
SourceLocation getBegin() const
Attr - This represents one attribute.