23 using namespace clang;
26 assert(S &&
"Expecting non-null pointer.");
31 assert(II &&
"Expecting non-null pointer.");
54 for (
unsigned i = 0; i < NumArgs; ++i) {
85 assert(NNS &&
"Expecting non-null pointer.");
137 llvm_unreachable(
"Expected valid TemplateArgument");
162 assert(TPL &&
"Expecting non-null pointer.");
164 ID.AddInteger(TPL->
size());
165 for (
auto *ND : TPL->
asArray()) {
181 const unsigned unsigned_bits =
sizeof(unsigned) *
CHAR_BIT;
182 const unsigned size = Bools.size();
183 const unsigned remainder = size % unsigned_bits;
184 const unsigned loops = size / unsigned_bits;
185 auto I = Bools.rbegin();
187 for (
unsigned i = 0; i <
remainder; ++i) {
192 ID.AddInteger(value);
194 for (
unsigned i = 0; i < loops; ++i) {
196 for (
unsigned j = 0; j < unsigned_bits; ++j) {
201 ID.AddInteger(value);
204 assert(I == Bools.rend());
206 return ID.ComputeHash();
214 llvm::FoldingSetNodeID &ID;
218 ODRDeclVisitor(llvm::FoldingSetNodeID &ID,
ODRHash &Hash)
219 : ID(ID), Hash(Hash) {}
250 void Visit(
const Decl *D) {
255 void VisitNamedDecl(
const NamedDecl *D) {
257 Inherited::VisitNamedDecl(D);
260 void VisitValueDecl(
const ValueDecl *D) {
261 if (!isa<FunctionDecl>(D)) {
264 Inherited::VisitValueDecl(D);
267 void VisitVarDecl(
const VarDecl *D) {
270 const bool HasInit = D->
hasInit();
275 Inherited::VisitVarDecl(D);
280 Inherited::VisitParmVarDecl(D);
285 Inherited::VisitAccessSpecDecl(D);
292 Inherited::VisitStaticAssertDecl(D);
295 void VisitFieldDecl(
const FieldDecl *D) {
306 Inherited::VisitFieldDecl(D);
324 Inherited::VisitFunctionDecl(D);
331 Inherited::VisitCXXMethodDecl(D);
337 Inherited::VisitTypedefNameDecl(D);
341 Inherited::VisitTypedefDecl(D);
345 Inherited::VisitTypeAliasDecl(D);
360 const bool hasDefaultArgument =
363 if (hasDefaultArgument) {
367 Inherited::VisitTemplateTypeParmDecl(D);
372 const bool hasDefaultArgument =
375 if (hasDefaultArgument) {
379 Inherited::VisitNonTypeTemplateParmDecl(D);
384 const bool hasDefaultArgument =
387 if (hasDefaultArgument) {
391 Inherited::VisitTemplateTemplateParmDecl(D);
405 case Decl::AccessSpec:
406 case Decl::CXXConstructor:
407 case Decl::CXXDestructor:
408 case Decl::CXXMethod:
411 case Decl::StaticAssert:
412 case Decl::TypeAlias:
420 assert(D &&
"Expecting non-null pointer.");
423 ODRDeclVisitor(ID, *
this).Visit(D);
428 "Expected non-null record to be a definition.");
432 if (isa<ClassTemplateSpecializationDecl>(DC)) {
443 for (
const Decl *SubDecl : Record->
decls()) {
445 Decls.push_back(SubDecl);
449 ID.AddInteger(Decls.size());
450 for (
auto SubDecl : Decls) {
461 auto Bases = Record->
bases();
462 for (
auto Base : Bases) {
464 ID.AddInteger(
Base.isVirtual());
465 ID.AddInteger(
Base.getAccessSpecifierAsWritten());
470 assert(Function &&
"Expecting non-null pointer.");
476 if (!Function->
hasBody())
return;
477 if (!Function->
getBody())
return;
480 if (isa<CXXMethodDecl>(Function))
return;
487 if (isa<ClassTemplateSpecializationDecl>(DC))
return;
488 if (
auto *F = dyn_cast<FunctionDecl>(DC))
489 if (F->isFunctionTemplateSpecialization())
return;
505 assert(D &&
"Expecting non-null pointer.");
507 auto Result = DeclMap.insert(std::make_pair(D, DeclMap.size()));
508 ID.AddInteger(
Result.first->second);
517 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
525 class ODRTypeVisitor :
public TypeVisitor<ODRTypeVisitor> {
527 llvm::FoldingSetNodeID &ID;
531 ODRTypeVisitor(llvm::FoldingSetNodeID &ID,
ODRHash &Hash)
532 : ID(ID), Hash(Hash) {}
577 void Visit(
const Type *T) {
582 void VisitType(
const Type *T) {}
593 VisitAdjustedType(T);
596 void VisitArrayType(
const ArrayType *T) {
636 VisitFunctionType(T);
644 VisitFunctionType(T);
650 VisitQualifiers(UnderlyingType.getQualifiers());
652 dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
653 UnderlyingType = Underlying->getDecl()->getUnderlyingType();
655 AddType(UnderlyingType.getTypePtr());
659 void VisitTagType(
const TagType *T) {
664 void VisitRecordType(
const RecordType *T) { VisitTagType(T); }
665 void VisitEnumType(
const EnumType *T) { VisitTagType(T); }
675 VisitTypeWithKeyword(T);
678 void VisitDependentTemplateSpecializationType(
686 VisitTypeWithKeyword(T);
692 VisitTypeWithKeyword(T);
714 assert(T &&
"Expecting non-null pointer.");
715 auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size()));
716 ID.AddInteger(
Result.first->second);
723 ODRTypeVisitor(ID, *
this).Visit(T);
736 Bools.push_back(Value);
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
const Type * Ty
The locally-unqualified type.
An instance of this class is created to represent a function declaration or definition.
Smart pointer class that efficiently represents Objective-C method names.
void AddFunctionDecl(const FunctionDecl *Function)
A (possibly-)qualified type.
void AddBoolean(bool value)
unsigned getNumBases() const
Retrieves the number of base classes of this class.
QualType getDecayedType() const
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes...
void Profile(llvm::FoldingSetNodeID &ID) const
Stmt - This represents one statement.
Expr * getBitWidth() const
void AddQualType(QualType T)
FunctionType - C99 6.7.5.3 - Function Declarators.
TypedefDecl - Represents the declaration of a typedef-name via the 'typedef' type specifier...
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
Represents a qualified type name for which the type name is dependent.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Decl - This represents one declaration (or definition), e.g.
TagDecl * getDecl() const
ArrayRef< NamedDecl * > asArray()
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
The base class of the type hierarchy.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
A container of type source information.
bool isEmpty() const
Evaluates true when this declaration name is empty.
TemplateTypeParmDecl * getDecl() const
A template template parameter that has been substituted for some other template name.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
size_t param_size() const
QualType getElementType() const
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
An identifier, stored as an IdentifierInfo*.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
QualType getReturnType() const
unsigned getNumParams() const
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Represents an empty template argument, e.g., one that has not been deduced.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
A namespace, stored as a NamespaceDecl*.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
void AddTemplateArgument(TemplateArgument TA)
bool hasDefinition() const
ParmVarDecl - Represents a parameter to a function.
The collection of all-type qualifiers we support.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
QualType getOriginalType() const
static bool isWhitelistedDecl(const Decl *D, const CXXRecordDecl *Record)
One of these records is kept for each identifier that is lexed.
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
StringLiteral * getMessage()
Expr * getAsExpr() const
Retrieve the template argument as an expression.
ArrayRef< QualType > getParamTypes() const
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
void AddTemplateParameterList(const TemplateParameterList *TPL)
Represents an access specifier followed by colon ':'.
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
ArrayRef< ParmVarDecl * > parameters() const
bool isUnarySelector() const
bool isBitField() const
Determines whether this field is a bitfield.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
A qualified template name, where the qualification is kept to describe the source code as written...
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
void AddDecl(const Decl *D)
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
#define remainder(__x, __y)
QualType getPointeeType() const
Expr * getSizeExpr() const
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
Expr * getSizeExpr() const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void AddTemplateName(TemplateName Name)
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
Represents a prototype with parameter type info, e.g.
A dependent template name that has not been resolved to a template (or set of templates).
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
Represents an array type in C++ whose size is a value-dependent expression.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
unsigned getNumArgs() const
Retrieve the number of template arguments.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
bool isDefaulted() const
Whether this function is defaulted per C++0x.
unsigned getAsOpaqueValue() const
const FunctionProtoType * T
Declaration of a template type parameter.
unsigned getIndex() const
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
void AddDeclarationName(DeclarationName Name)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
DeclContext * getDeclContext()
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash &Hash) const
Calculate a unique representation for a statement that is stable across compiler invocations.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
A namespace alias, stored as a NamespaceAliasDecl*.
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body (definition).
Qualifiers Quals
The local qualifiers.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A helper class for Type nodes having an ElaboratedTypeKeyword.
ArraySizeModifier getSizeModifier() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
unsigned getNumArgs() const
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
A type, stored as a Type*.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
A template template parameter pack that has been substituted for a template template argument pack...
IdentifierInfo * getCXXLiteralIdentifier() const
getCXXLiteralIdentifier - If this name is the name of a literal operator, retrieve the identifier ass...
ElaboratedTypeKeyword getKeyword() const
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
QualType getAdjustedType() const
QualType getReturnType() const
bool isPure() const
Whether this virtual function is pure, i.e.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
void AddType(const Type *T)
void AddIdentifierInfo(const IdentifierInfo *II)
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Represents a static or instance method of a struct/union/class.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isParameterPack() const
unsigned pack_size() const
The number of template arguments in the given template argument pack.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Qualifiers getIndexTypeQualifiers() const
TypeClass getTypeClass() const
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS)
ArrayRef< TemplateArgument > template_arguments() const
Represents a C++11 static_assert declaration.
void AddSubDecl(const Decl *D)
Represents a pointer type decayed from an array or function type.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Represents a template argument.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Dataflow Directional Tag Classes.
ExtInfo getExtInfo() const
const TemplateArgument & getArgument() const
NestedNameSpecifier * getQualifier() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The template argument is a pack expansion of a template name that was provided for a template templat...
QualType getUnderlyingType() const
AccessSpecifier getAccess() const
const Expr * getInit() const
void AddCXXRecordDecl(const CXXRecordDecl *Record)
DeclarationName - The name of a declaration.
bool isKeywordSelector() const
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
A type that was preceded by the 'template' keyword, stored as a Type*.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
unsigned getNumArgs() const
Retrieve the number of template arguments.
const llvm::APInt & getSize() const
bool isStaticLocal() const
isStaticLocal - Returns true if a variable with function scope is a static local variable.
The template argument is a type.
The template argument is actually a parameter pack.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
TypedefNameDecl * getDecl() const
ArgKind getKind() const
Return the kind of stored template argument.
unsigned getDepth() const
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Represents a C++ struct/union/class.
Represents a template specialization type whose template cannot be resolved, e.g. ...
ArrayRef< TemplateArgument > template_arguments() const
The template argument is a template name that was provided for a template template parameter...
Represents a C array with an unspecified size.
QualType getNamedType() const
Retrieve the type named by the qualified-id.
bool isNull() const
Determine whether this is the empty selector.
Declaration of a class template.
This class is used for builtin types like 'int'.
void AddStmt(const Stmt *S)
QualType getAsType() const
Retrieve the type for a type template argument.
Represents a type template specialization; the template must be a class template, a type alias templa...
bool isDeleted() const
Whether this function has been deleted.
QualType getDefaultArgument() const
Retrieve the default argument, if any.
A set of overloaded template declarations.
NamedDecl - This represents a decl with a name.
Represents a C array with a specified size that is not an integer-constant-expression.
A simple visitor class that helps create declaration visitors.
The global specifier '::'. There is no stored value.
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.
Represents the canonical version of C arrays with a specified constant size.
bool isDeletedAsWritten() const
QualType getType() const
Return the type wrapped by this type source info.
A single template declaration.
const IdentifierInfo * getIdentifier() const