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),
178 memcpy(Data, other.
Data, getFullDataSize());
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::Char16:
322 case BuiltinType::Char32:
324 case BuiltinType::WChar_S:
325 case BuiltinType::WChar_U:
327 case BuiltinType::UChar:
328 case BuiltinType::UShort:
329 case BuiltinType::UInt:
330 case BuiltinType::ULong:
331 case BuiltinType::ULongLong:
332 case BuiltinType::UInt128:
333 case BuiltinType::SChar:
334 case BuiltinType::Short:
335 case BuiltinType::Int:
336 case BuiltinType::Long:
337 case BuiltinType::LongLong:
338 case BuiltinType::Int128:
339 case BuiltinType::Half:
340 case BuiltinType::Float:
341 case BuiltinType::Double:
342 case BuiltinType::LongDouble:
343 case BuiltinType::Float16:
344 case BuiltinType::Float128:
345 llvm_unreachable(
"Builtin type needs extra local data!");
348 case BuiltinType::NullPtr:
349 case BuiltinType::Overload:
350 case BuiltinType::Dependent:
351 case BuiltinType::BoundMember:
352 case BuiltinType::UnknownAny:
353 case BuiltinType::ARCUnbridgedCast:
354 case BuiltinType::PseudoObject:
355 case BuiltinType::ObjCId:
356 case BuiltinType::ObjCClass:
357 case BuiltinType::ObjCSel:
358 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 359 case BuiltinType::Id: 360 #include "clang/Basic/OpenCLImageTypes.def" 361 case BuiltinType::OCLSampler:
362 case BuiltinType::OCLEvent:
363 case BuiltinType::OCLClkEvent:
364 case BuiltinType::OCLQueue:
365 case BuiltinType::OCLReserveID:
366 case BuiltinType::BuiltinFn:
367 case BuiltinType::OMPArraySection:
371 llvm_unreachable(
"Invalid BuiltinType Kind!");
376 TL = PTL.getInnerLoc();
381 if (
auto attributedLoc = getAs<AttributedTypeLoc>()) {
385 return attributedLoc.getAttrNameLoc();
393 if (
auto qual = getAs<QualifiedTypeLoc>())
400 if (attr.isQualifier())
return attr;
401 return attr.getModifiedLoc().findExplicitQualifierLoc();
415 if (!getNumProtocols())
return;
417 setProtocolLAngleLoc(Loc);
418 setProtocolRAngleLoc(Loc);
419 for (
unsigned i = 0, e = getNumProtocols(); i != e; ++i)
420 setProtocolLoc(i, Loc);
425 setHasBaseTypeAsWritten(
true);
426 setTypeArgsLAngleLoc(Loc);
427 setTypeArgsRAngleLoc(Loc);
428 for (
unsigned i = 0, e = getNumTypeArgs(); i != e; ++i) {
431 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
433 setProtocolLAngleLoc(Loc);
434 setProtocolRAngleLoc(Loc);
435 for (
unsigned i = 0, e = getNumProtocols(); i != e; ++i)
436 setProtocolLoc(i, Loc);
452 this->setUnderlyingTInfo(
458 setElaboratedKeywordLoc(Loc);
460 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
466 setElaboratedKeywordLoc(Loc);
468 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
476 setElaboratedKeywordLoc(Loc);
477 if (getTypePtr()->getQualifier()) {
479 Builder.
MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
484 setTemplateKeywordLoc(Loc);
485 setTemplateNameLoc(Loc);
489 getTypePtr()->getArgs(),
498 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
501 llvm_unreachable(
"Impossible TemplateArgument");
524 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
526 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
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)
static const unsigned TypeLocMaxDataAlign
TypeLoc findExplicitQualifierLoc() const
Find a type with the location of an explicit type qualifier.
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.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
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