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::RoundUpToAlignment(Total, Align);
84 Total += TypeSizer().Visit(TyLoc);
87 Total = llvm::RoundUpToAlignment(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::RoundUpToAlignment(reinterpret_cast<uintptr_t>(
Data),
155 reinterpret_cast<uintptr_t
>(other.
Data)
156 == llvm::RoundUpToAlignment(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 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 case BuiltinType::OCLImage1d:
337 case BuiltinType::OCLImage1dArray:
338 case BuiltinType::OCLImage1dBuffer:
339 case BuiltinType::OCLImage2d:
340 case BuiltinType::OCLImage2dArray:
341 case BuiltinType::OCLImage3d:
342 case BuiltinType::OCLSampler:
343 case BuiltinType::OCLEvent:
344 case BuiltinType::BuiltinFn:
348 llvm_unreachable(
"Invalid BuiltinType Kind!");
353 TL = PTL.getInnerLoc();
358 if (
auto attributedLoc = getAs<AttributedTypeLoc>()) {
362 return attributedLoc.getAttrNameLoc();
376 getTypePtr()->getTypeArgsAsWritten()[i], Loc));
434 for (
unsigned i = 0, e = NumArgs; i != e; ++i) {
437 llvm_unreachable(
"Impossible TemplateArgument");
460 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
462 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)
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceLocation findNullabilityLoc() const
RetTy Visit(TypeLoc TyLoc)
WrittenBuiltinSpecs & getWrittenBuiltinSpecs()
void setTemplateKeywordLoc(SourceLocation Loc)
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.
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)
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 ...
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
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)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
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
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. The SourceManager can decode this to get at the full include stack...
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
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
void setTypeArgsLAngleLoc(SourceLocation Loc)
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.
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
unsigned getFullDataSize() const
Returns the size of the type source info data block.
BoundNodesTreeBuilder *const Builder
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
isNull - Return true if this QualType doesn't point to a type yet.
void setElaboratedKeywordLoc(SourceLocation Loc)