23 #include "llvm/Support/ErrorHandling.h" 24 #include "llvm/Support/MathExtras.h" 30 using namespace clang;
40 class TypeLocRanger :
public TypeLocVisitor<TypeLocRanger, SourceRange> {
42 #define ABSTRACT_TYPELOC(CLASS, PARENT) 43 #define TYPELOC(CLASS, PARENT) \ 44 SourceRange Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 45 return TyLoc.getLocalSourceRange(); \ 47 #include "clang/AST/TypeLocNodes.def" 54 return TypeLocRanger().Visit(TL);
61 #define ABSTRACT_TYPELOC(CLASS, PARENT) 62 #define TYPELOC(CLASS, PARENT) \ 63 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 64 return TyLoc.getLocalDataAlignment(); \ 66 #include "clang/AST/TypeLocNodes.def" 74 return TypeAligner().Visit(
TypeLoc(Ty,
nullptr));
81 #define ABSTRACT_TYPELOC(CLASS, PARENT) 82 #define TYPELOC(CLASS, PARENT) \ 83 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 84 return TyLoc.getLocalDataSize(); \ 86 #include "clang/AST/TypeLocNodes.def" 95 unsigned MaxAlign = 1;
97 unsigned Align = getLocalAlignmentForType(TyLoc.
getType());
98 MaxAlign =
std::max(Align, MaxAlign);
99 Total = llvm::alignTo(Total, Align);
100 Total += TypeSizer().Visit(TyLoc);
103 Total = llvm::alignTo(Total, MaxAlign);
111 #define ABSTRACT_TYPELOC(CLASS, PARENT) 112 #define TYPELOC(CLASS, PARENT) \ 113 TypeLoc Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 114 return TyLoc.getNextTypeLoc(); \ 116 #include "clang/AST/TypeLocNodes.def" 124 return NextLoc().Visit(TL);
134 #define ABSTRACT_TYPELOC(CLASS, PARENT) 135 #define TYPELOC(CLASS, PARENT) \ 137 CLASS##TypeLoc TLCasted = TL.castAs<CLASS##TypeLoc>(); \ 138 TLCasted.initializeLocal(Context, Loc); \ 139 TL = TLCasted.getNextTypeLoc(); \ 143 #include "clang/AST/TypeLocNodes.def" 154 TypeLocCopier(
TypeLoc source) : Source(source) {}
156 #define ABSTRACT_TYPELOC(CLASS, PARENT) 157 #define TYPELOC(CLASS, PARENT) \ 158 void Visit##CLASS##TypeLoc(CLASS##TypeLoc dest) { \ 159 dest.copyLocal(Source.castAs<CLASS##TypeLoc>()); \ 161 #include "clang/AST/TypeLocNodes.def" 172 if (reinterpret_cast<uintptr_t>(Data) ==
173 llvm::alignTo(reinterpret_cast<uintptr_t>(Data),
176 llvm::alignTo(reinterpret_cast<uintptr_t>(other.
Data),
185 TypeLocCopier(other).Visit(TL);
205 case FunctionNoProto:
207 case DependentSizedArray:
208 case IncompleteArray:
238 case DependentSizedArray:
239 case IncompleteArray:
241 case FunctionNoProto:
253 case LValueReference:
254 case RValueReference:
272 static bool isTypeSpec(
TypeLoc _) {
return false; }
274 #define ABSTRACT_TYPELOC(CLASS, PARENT) 275 #define TYPELOC(CLASS, PARENT) \ 276 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 277 return isTypeSpec(TyLoc); \ 279 #include "clang/AST/TypeLocNodes.def" 292 bool TypeSpecTypeLoc::isKind(
const TypeLoc &TL) {
294 return TSTChecker().
Visit(TL);
301 if (getRParenLoc().isValid())
302 return SourceRange(getTypeofLoc(), getRParenLoc());
310 if (needsExtraLocalData())
312 switch (getTypePtr()->getKind()) {
313 case BuiltinType::Void:
315 case BuiltinType::Bool:
317 case BuiltinType::Char_U:
318 case BuiltinType::Char_S:
320 case BuiltinType::Char8:
322 case BuiltinType::Char16:
324 case BuiltinType::Char32:
326 case BuiltinType::WChar_S:
327 case BuiltinType::WChar_U:
329 case BuiltinType::UChar:
330 case BuiltinType::UShort:
331 case BuiltinType::UInt:
332 case BuiltinType::ULong:
333 case BuiltinType::ULongLong:
334 case BuiltinType::UInt128:
335 case BuiltinType::SChar:
336 case BuiltinType::Short:
337 case BuiltinType::Int:
338 case BuiltinType::Long:
339 case BuiltinType::LongLong:
340 case BuiltinType::Int128:
341 case BuiltinType::Half:
342 case BuiltinType::Float:
343 case BuiltinType::Double:
344 case BuiltinType::LongDouble:
345 case BuiltinType::Float16:
346 case BuiltinType::Float128:
347 case BuiltinType::ShortAccum:
348 case BuiltinType::Accum:
349 case BuiltinType::LongAccum:
350 case BuiltinType::UShortAccum:
351 case BuiltinType::UAccum:
352 case BuiltinType::ULongAccum:
353 case BuiltinType::ShortFract:
354 case BuiltinType::Fract:
355 case BuiltinType::LongFract:
356 case BuiltinType::UShortFract:
357 case BuiltinType::UFract:
358 case BuiltinType::ULongFract:
359 case BuiltinType::SatShortAccum:
360 case BuiltinType::SatAccum:
361 case BuiltinType::SatLongAccum:
362 case BuiltinType::SatUShortAccum:
363 case BuiltinType::SatUAccum:
364 case BuiltinType::SatULongAccum:
365 case BuiltinType::SatShortFract:
366 case BuiltinType::SatFract:
367 case BuiltinType::SatLongFract:
368 case BuiltinType::SatUShortFract:
369 case BuiltinType::SatUFract:
370 case BuiltinType::SatULongFract:
371 llvm_unreachable(
"Builtin type needs extra local data!");
374 case BuiltinType::NullPtr:
375 case BuiltinType::Overload:
376 case BuiltinType::Dependent:
377 case BuiltinType::BoundMember:
378 case BuiltinType::UnknownAny:
379 case BuiltinType::ARCUnbridgedCast:
380 case BuiltinType::PseudoObject:
381 case BuiltinType::ObjCId:
382 case BuiltinType::ObjCClass:
383 case BuiltinType::ObjCSel:
384 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 385 case BuiltinType::Id: 386 #include "clang/Basic/OpenCLImageTypes.def" 387 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 388 case BuiltinType::Id: 389 #include "clang/Basic/OpenCLExtensionTypes.def" 390 case BuiltinType::OCLSampler:
391 case BuiltinType::OCLEvent:
392 case BuiltinType::OCLClkEvent:
393 case BuiltinType::OCLQueue:
394 case BuiltinType::OCLReserveID:
395 case BuiltinType::BuiltinFn:
396 case BuiltinType::OMPArraySection:
400 llvm_unreachable(
"Invalid BuiltinType Kind!");
405 TL = PTL.getInnerLoc();
410 if (
auto ATL = getAs<AttributedTypeLoc>()) {
411 const Attr *A = ATL.getAttr();
412 if (A && (isa<TypeNullableAttr>(A) || isa<TypeNonNullAttr>(A) ||
413 isa<TypeNullUnspecifiedAttr>(A)))
422 if (
auto qual = getAs<QualifiedTypeLoc>())
429 if (attr.isQualifier())
return attr;
430 return attr.getModifiedLoc().findExplicitQualifierLoc();
444 if (!getNumProtocols())
return;
446 setProtocolLAngleLoc(Loc);
447 setProtocolRAngleLoc(Loc);
448 for (
unsigned i = 0, e = getNumProtocols(); i != e; ++i)
449 setProtocolLoc(i, Loc);
454 setHasBaseTypeAsWritten(
true);
455 setTypeArgsLAngleLoc(Loc);
456 setTypeArgsRAngleLoc(Loc);
457 for (
unsigned i = 0, e = getNumTypeArgs(); i != e; ++i) {
460 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
462 setProtocolLAngleLoc(Loc);
463 setProtocolRAngleLoc(Loc);
464 for (
unsigned i = 0, e = getNumProtocols(); i != e; ++i)
465 setProtocolLoc(i, Loc);
481 this->setUnderlyingTInfo(
487 setElaboratedKeywordLoc(Loc);
489 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
495 setElaboratedKeywordLoc(Loc);
497 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
505 setElaboratedKeywordLoc(Loc);
506 if (getTypePtr()->getQualifier()) {
508 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
513 setTemplateKeywordLoc(Loc);
514 setTemplateNameLoc(Loc);
518 getTypePtr()->getArgs(),
527 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
530 llvm_unreachable(
"Impossible TemplateArgument");
553 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
555 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...
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...
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.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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.
__DEVICE__ int max(int __a, int __b)
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.