18 #include "llvm/Support/ErrorHandling.h"
19 using namespace clang;
28 class TypeLocRanger :
public TypeLocVisitor<TypeLocRanger, SourceRange> {
30 #define ABSTRACT_TYPELOC(CLASS, PARENT)
31 #define TYPELOC(CLASS, PARENT) \
32 SourceRange Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
33 return TyLoc.getLocalSourceRange(); \
35 #include "clang/AST/TypeLocNodes.def"
41 return TypeLocRanger().Visit(TL);
47 #define ABSTRACT_TYPELOC(CLASS, PARENT)
48 #define TYPELOC(CLASS, PARENT) \
49 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
50 return TyLoc.getLocalDataAlignment(); \
52 #include "clang/AST/TypeLocNodes.def"
59 return TypeAligner().Visit(
TypeLoc(Ty,
nullptr));
65 #define ABSTRACT_TYPELOC(CLASS, PARENT)
66 #define TYPELOC(CLASS, PARENT) \
67 unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
68 return TyLoc.getLocalDataSize(); \
70 #include "clang/AST/TypeLocNodes.def"
78 unsigned MaxAlign = 1;
81 MaxAlign =
std::max(Align, MaxAlign);
82 Total = llvm::alignTo(Total, Align);
83 Total += TypeSizer().Visit(TyLoc);
86 Total = llvm::alignTo(Total, MaxAlign);
93 #define ABSTRACT_TYPELOC(CLASS, PARENT)
94 #define TYPELOC(CLASS, PARENT) \
95 TypeLoc Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
96 return TyLoc.getNextTypeLoc(); \
98 #include "clang/AST/TypeLocNodes.def"
105 return NextLoc().Visit(TL);
115 #define ABSTRACT_TYPELOC(CLASS, PARENT)
116 #define TYPELOC(CLASS, PARENT) \
118 CLASS##TypeLoc TLCasted = TL.castAs<CLASS##TypeLoc>(); \
119 TLCasted.initializeLocal(Context, Loc); \
120 TL = TLCasted.getNextTypeLoc(); \
124 #include "clang/AST/TypeLocNodes.def"
133 TypeLocCopier(
TypeLoc source) : Source(source) { }
135 #define ABSTRACT_TYPELOC(CLASS, PARENT)
136 #define TYPELOC(CLASS, PARENT) \
137 void Visit##CLASS##TypeLoc(CLASS##TypeLoc dest) { \
138 dest.copyLocal(Source.castAs<CLASS##TypeLoc>()); \
140 #include "clang/AST/TypeLocNodes.def"
151 if (reinterpret_cast<uintptr_t>(
Data) ==
152 llvm::alignTo(reinterpret_cast<uintptr_t>(
Data),
155 llvm::alignTo(reinterpret_cast<uintptr_t>(other.
Data),
164 TypeLocCopier(other).Visit(TL);
184 case FunctionNoProto:
186 case DependentSizedArray:
187 case IncompleteArray:
217 case DependentSizedArray:
218 case IncompleteArray:
220 case FunctionNoProto:
232 case LValueReference:
233 case RValueReference:
251 static bool isTypeSpec(
TypeLoc _) {
return false; }
253 #define ABSTRACT_TYPELOC(CLASS, PARENT)
254 #define TYPELOC(CLASS, PARENT) \
255 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
256 return isTypeSpec(TyLoc); \
258 #include "clang/AST/TypeLocNodes.def"
271 bool TypeSpecTypeLoc::isKind(
const TypeLoc &TL) {
273 return TSTChecker().
Visit(TL);
292 case BuiltinType::Void:
294 case BuiltinType::Bool:
296 case BuiltinType::Char_U:
297 case BuiltinType::Char_S:
299 case BuiltinType::Char16:
301 case BuiltinType::Char32:
303 case BuiltinType::WChar_S:
304 case BuiltinType::WChar_U:
306 case BuiltinType::UChar:
307 case BuiltinType::UShort:
308 case BuiltinType::UInt:
309 case BuiltinType::ULong:
310 case BuiltinType::ULongLong:
311 case BuiltinType::UInt128:
312 case BuiltinType::SChar:
313 case BuiltinType::Short:
314 case BuiltinType::Int:
315 case BuiltinType::Long:
316 case BuiltinType::LongLong:
317 case BuiltinType::Int128:
318 case BuiltinType::Half:
319 case BuiltinType::Float:
320 case BuiltinType::Double:
321 case BuiltinType::LongDouble:
322 case BuiltinType::Float128:
323 llvm_unreachable(
"Builtin type needs extra local data!");
326 case BuiltinType::NullPtr:
327 case BuiltinType::Overload:
328 case BuiltinType::Dependent:
329 case BuiltinType::BoundMember:
330 case BuiltinType::UnknownAny:
331 case BuiltinType::ARCUnbridgedCast:
332 case BuiltinType::PseudoObject:
333 case BuiltinType::ObjCId:
334 case BuiltinType::ObjCClass:
335 case BuiltinType::ObjCSel:
336 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
337 case BuiltinType::Id:
338 #include "clang/Basic/OpenCLImageTypes.def"
339 case BuiltinType::OCLSampler:
340 case BuiltinType::OCLEvent:
341 case BuiltinType::OCLClkEvent:
342 case BuiltinType::OCLQueue:
343 case BuiltinType::OCLReserveID:
344 case BuiltinType::BuiltinFn:
345 case BuiltinType::OMPArraySection:
349 llvm_unreachable(
"Invalid BuiltinType Kind!");
354 TL = PTL.getInnerLoc();
359 if (
auto attributedLoc = getAs<AttributedTypeLoc>()) {
363 return attributedLoc.getAttrNameLoc();
371 if (
auto qual = getAs<QualifiedTypeLoc>())
378 if (attr.isQualifier())
return attr;
379 return attr.getModifiedLoc().findExplicitQualifierLoc();
409 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
467 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
470 llvm_unreachable(
"Impossible TemplateArgument");
493 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
495 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 setProtocolRAngleLoc(SourceLocation Loc)
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...
unsigned getNumProtocols() const
void setElaboratedKeywordLoc(SourceLocation Loc)
SourceRange getLocalSourceRange() const
Get the local source range.
unsigned getNumProtocols() const
SourceLocation getBeginLoc() const
Get the begin source location.
void setProtocolLoc(unsigned i, SourceLocation Loc)
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
void setNameLoc(SourceLocation Loc)
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)
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)
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)
void setProtocolLAngleLoc(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
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)