18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/raw_ostream.h"
20 using namespace clang;
29 class TypeLocRanger :
public TypeLocVisitor<TypeLocRanger, SourceRange> {
31 #define ABSTRACT_TYPELOC(CLASS, PARENT)
32 #define TYPELOC(CLASS, PARENT) \
33 SourceRange Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
34 return TyLoc.getLocalSourceRange(); \
36 #include "clang/AST/TypeLocNodes.def"
42 return TypeLocRanger().Visit(TL);
48 #define ABSTRACT_TYPELOC(CLASS, PARENT)
49 #define TYPELOC(CLASS, PARENT) \
50 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
51 return TyLoc.getLocalDataAlignment(); \
53 #include "clang/AST/TypeLocNodes.def"
60 return TypeAligner().Visit(
TypeLoc(Ty,
nullptr));
66 #define ABSTRACT_TYPELOC(CLASS, PARENT)
67 #define TYPELOC(CLASS, PARENT) \
68 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
69 return TyLoc.getLocalDataSize(); \
71 #include "clang/AST/TypeLocNodes.def"
79 unsigned MaxAlign = 1;
82 MaxAlign =
std::max(Align, MaxAlign);
83 Total = llvm::alignTo(Total, Align);
84 Total += TypeSizer().Visit(TyLoc);
87 Total = llvm::alignTo(Total, MaxAlign);
94 #define ABSTRACT_TYPELOC(CLASS, PARENT)
95 #define TYPELOC(CLASS, PARENT) \
96 TypeLoc Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
97 return TyLoc.getNextTypeLoc(); \
99 #include "clang/AST/TypeLocNodes.def"
106 return NextLoc().Visit(TL);
116 #define ABSTRACT_TYPELOC(CLASS, PARENT)
117 #define TYPELOC(CLASS, PARENT) \
119 CLASS##TypeLoc TLCasted = TL.castAs<CLASS##TypeLoc>(); \
120 TLCasted.initializeLocal(Context, Loc); \
121 TL = TLCasted.getNextTypeLoc(); \
125 #include "clang/AST/TypeLocNodes.def"
134 TypeLocCopier(
TypeLoc source) : Source(source) { }
136 #define ABSTRACT_TYPELOC(CLASS, PARENT)
137 #define TYPELOC(CLASS, PARENT) \
138 void Visit##CLASS##TypeLoc(CLASS##TypeLoc dest) { \
139 dest.copyLocal(Source.castAs<CLASS##TypeLoc>()); \
141 #include "clang/AST/TypeLocNodes.def"
152 if (reinterpret_cast<uintptr_t>(
Data) ==
153 llvm::alignTo(reinterpret_cast<uintptr_t>(
Data),
156 llvm::alignTo(reinterpret_cast<uintptr_t>(other.
Data),
165 TypeLocCopier(other).Visit(TL);
185 case FunctionNoProto:
187 case DependentSizedArray:
188 case IncompleteArray:
218 case DependentSizedArray:
219 case IncompleteArray:
221 case FunctionNoProto:
233 case LValueReference:
234 case RValueReference:
252 static bool isTypeSpec(
TypeLoc _) {
return false; }
254 #define ABSTRACT_TYPELOC(CLASS, PARENT)
255 #define TYPELOC(CLASS, PARENT) \
256 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
257 return isTypeSpec(TyLoc); \
259 #include "clang/AST/TypeLocNodes.def"
272 bool TypeSpecTypeLoc::isKind(
const TypeLoc &TL) {
274 return TSTChecker().
Visit(TL);
293 case BuiltinType::Void:
295 case BuiltinType::Bool:
297 case BuiltinType::Char_U:
298 case BuiltinType::Char_S:
300 case BuiltinType::Char16:
302 case BuiltinType::Char32:
304 case BuiltinType::WChar_S:
305 case BuiltinType::WChar_U:
307 case BuiltinType::UChar:
308 case BuiltinType::UShort:
309 case BuiltinType::UInt:
310 case BuiltinType::ULong:
311 case BuiltinType::ULongLong:
312 case BuiltinType::UInt128:
313 case BuiltinType::SChar:
314 case BuiltinType::Short:
315 case BuiltinType::Int:
316 case BuiltinType::Long:
317 case BuiltinType::LongLong:
318 case BuiltinType::Int128:
319 case BuiltinType::Half:
320 case BuiltinType::Float:
321 case BuiltinType::Double:
322 case BuiltinType::LongDouble:
323 case BuiltinType::Float128:
324 llvm_unreachable(
"Builtin type needs extra local data!");
327 case BuiltinType::NullPtr:
328 case BuiltinType::Overload:
329 case BuiltinType::Dependent:
330 case BuiltinType::BoundMember:
331 case BuiltinType::UnknownAny:
332 case BuiltinType::ARCUnbridgedCast:
333 case BuiltinType::PseudoObject:
334 case BuiltinType::ObjCId:
335 case BuiltinType::ObjCClass:
336 case BuiltinType::ObjCSel:
337 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
338 case BuiltinType::Id:
339 #include "clang/Basic/OpenCLImageTypes.def"
340 case BuiltinType::OCLSampler:
341 case BuiltinType::OCLEvent:
342 case BuiltinType::OCLClkEvent:
343 case BuiltinType::OCLQueue:
344 case BuiltinType::OCLNDRange:
345 case BuiltinType::OCLReserveID:
346 case BuiltinType::BuiltinFn:
347 case BuiltinType::OMPArraySection:
351 llvm_unreachable(
"Invalid BuiltinType Kind!");
356 TL = PTL.getInnerLoc();
361 if (
auto attributedLoc = getAs<AttributedTypeLoc>()) {
365 return attributedLoc.getAttrNameLoc();
373 if (
auto qual = getAs<QualifiedTypeLoc>())
380 if (attr.isQualifier())
return attr;
381 return attr.getModifiedLoc().findExplicitQualifierLoc();
400 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
458 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
461 llvm_unreachable(
"Impossible TemplateArgument");
484 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
486 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
static unsigned getFullDataSizeForType(QualType Ty)
Returns the size of type source info data block for the given type.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
A (possibly-)qualified type.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceLocation findNullabilityLoc() const
Find the location of the nullability specifier (__nonnull, __nullable, or __null_unspecifier), if there is one.
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()
void setTemplateKeywordLoc(SourceLocation Loc)
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Expr * getUnderlyingExpr() const
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.
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)
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...
const TemplateArgument * getArgs() const
Retrieve the template arguments.
void setElaboratedKeywordLoc(SourceLocation Loc)
SourceRange getLocalSourceRange() const
Get the local source range.
unsigned getNumProtocols() const
SourceLocation getBeginLoc() const
Get the begin source location.
void setRAngleLoc(SourceLocation Loc)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
bool needsExtraLocalData() const
SourceLocation getRParenLoc() const
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
void setProtocolLoc(unsigned i, SourceLocation Loc)
SourceLocation getTypeofLoc() const
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Class that aids in the construction of nested-name-specifiers along with 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...
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
void setTemplateNameLoc(SourceLocation Loc)
Type source information for an attributed type.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
ArgKind getKind() const
Return the kind of stored template argument.
Represents a C++ template name within the type system.
Defines the clang::TypeLoc interface and its subclasses.
QualType getType() const
Get the type for which this source info wrapper provides information.
bool hasTrailingReturn() const
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.
void setHasBaseTypeAsWritten(bool HasBaseType)
void initializeLocal(ASTContext &Context, SourceLocation Loc)
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
TypeSourceInfo * UnderlyingTInfo
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
const TypeClass * getTypePtr() const
void initializeLocal(ASTContext &Context, SourceLocation Loc)
SourceLocation getEndLoc() const
Get the end source location.
void setLAngleLoc(SourceLocation Loc)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
void initializeLocal(ASTContext &Context, SourceLocation Loc)
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.
void setProtocolRAngleLoc(SourceLocation Loc)
TypeOfTypeLocInfo * getLocalData() const
unsigned getNumTypeArgs() const
static const unsigned TypeLocMaxDataAlign
void setElaboratedKeywordLoc(SourceLocation Loc)
TypeLocClass getTypeLocClass() const
TypeSpecifierType getWrittenTypeSpec() const
SourceLocation getBegin() const
void setTypeArgsLAngleLoc(SourceLocation Loc)
TypeLoc findExplicitQualifierLoc() const
Find a type with the location of an explicit type qualifier.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
Represents a template name that was expressed as a qualified name.
The template argument is a pack expansion of a template name that was provided for a template templat...
TypeLoc IgnoreParens() const
QualType getUnderlyingType() const
void setNameLoc(SourceLocation Loc)
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
static void initializeArgLocs(ASTContext &Context, unsigned NumArgs, const TemplateArgument *Args, TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc)
unsigned getNumArgs() const
NestedNameSpecifier * getQualifier() const
void setTypeArgsRAngleLoc(SourceLocation Loc)
The template argument is a type.
const BuiltinType * getTypePtr() const
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.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
BoundNodesTreeBuilder *const Builder
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)
void copy(TypeLoc other)
Copies the other type loc into this one.
void setProtocolLAngleLoc(SourceLocation Loc)
SourceRange getLocalSourceRange() const
A trivial tuple used to represent a source range.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void setElaboratedKeywordLoc(SourceLocation Loc)