23 using namespace clang;
26 assert(S &&
"Expecting non-null pointer.");
31 assert(II &&
"Expecting non-null pointer.");
37 auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
38 ID.AddInteger(
Result.first->second);
63 for (
unsigned i = 0; i < NumArgs; ++i) {
94 assert(NNS &&
"Expecting non-null pointer.");
146 llvm_unreachable(
"Expected valid TemplateArgument");
173 assert(TPL &&
"Expecting non-null pointer.");
175 ID.AddInteger(TPL->
size());
176 for (
auto *ND : TPL->
asArray()) {
191 const unsigned unsigned_bits =
sizeof(unsigned) *
CHAR_BIT;
192 const unsigned size = Bools.size();
193 const unsigned remainder = size % unsigned_bits;
194 const unsigned loops = size / unsigned_bits;
195 auto I = Bools.rbegin();
197 for (
unsigned i = 0; i <
remainder; ++i) {
202 ID.AddInteger(value);
204 for (
unsigned i = 0; i < loops; ++i) {
206 for (
unsigned j = 0; j < unsigned_bits; ++j) {
211 ID.AddInteger(value);
214 assert(I == Bools.rend());
216 return ID.ComputeHash();
224 llvm::FoldingSetNodeID &ID;
228 ODRDeclVisitor(llvm::FoldingSetNodeID &ID,
ODRHash &Hash)
229 : ID(ID), Hash(Hash) {}
260 void Visit(
const Decl *D) {
265 void VisitNamedDecl(
const NamedDecl *D) {
267 Inherited::VisitNamedDecl(D);
270 void VisitValueDecl(
const ValueDecl *D) {
271 if (!isa<FunctionDecl>(D)) {
274 Inherited::VisitValueDecl(D);
277 void VisitVarDecl(
const VarDecl *D) {
280 const bool HasInit = D->
hasInit();
285 Inherited::VisitVarDecl(D);
290 Inherited::VisitParmVarDecl(D);
295 Inherited::VisitAccessSpecDecl(D);
302 Inherited::VisitStaticAssertDecl(D);
305 void VisitFieldDecl(
const FieldDecl *D) {
316 Inherited::VisitFieldDecl(D);
323 Inherited::VisitFunctionDecl(D);
329 Inherited::VisitCXXMethodDecl(D);
335 Inherited::VisitTypedefNameDecl(D);
339 Inherited::VisitTypedefDecl(D);
343 Inherited::VisitTypeAliasDecl(D);
358 const bool hasDefaultArgument =
361 if (hasDefaultArgument) {
366 Inherited::VisitTemplateTypeParmDecl(D);
371 const bool hasDefaultArgument =
374 if (hasDefaultArgument) {
379 Inherited::VisitNonTypeTemplateParmDecl(D);
384 const bool hasDefaultArgument =
387 if (hasDefaultArgument) {
392 Inherited::VisitTemplateTemplateParmDecl(D);
398 Inherited::VisitTemplateDecl(D);
403 Inherited::VisitRedeclarableTemplateDecl(D);
408 Inherited::VisitFunctionTemplateDecl(D);
413 Inherited::VisitEnumConstantDecl(D);
427 case Decl::AccessSpec:
428 case Decl::CXXConstructor:
429 case Decl::CXXDestructor:
430 case Decl::CXXMethod:
431 case Decl::EnumConstant:
434 case Decl::FunctionTemplate:
435 case Decl::StaticAssert:
436 case Decl::TypeAlias:
444 assert(D &&
"Expecting non-null pointer.");
446 ODRDeclVisitor(ID, *
this).Visit(D);
451 "Expected non-null record to be a definition.");
455 if (isa<ClassTemplateSpecializationDecl>(DC)) {
468 Decls.push_back(SubDecl);
469 if (
auto *Function = dyn_cast<FunctionDecl>(SubDecl)) {
471 Function->getODRHash();
476 ID.AddInteger(Decls.size());
477 for (
auto SubDecl : Decls) {
488 auto Bases = Record->
bases();
489 for (
auto Base : Bases) {
491 ID.AddInteger(
Base.isVirtual());
492 ID.AddInteger(
Base.getAccessSpecifierAsWritten());
498 assert(Function &&
"Expecting non-null pointer.");
503 if (isa<ClassTemplateSpecializationDecl>(DC))
return;
504 if (
auto *F = dyn_cast<FunctionDecl>(DC)) {
505 if (F->isFunctionTemplateSpecialization()) {
506 if (!isa<CXXMethodDecl>(DC))
return;
519 if (SpecializationArgs) {
520 ID.AddInteger(SpecializationArgs->size());
526 if (
const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
556 auto *Body = Function->
getBody();
579 assert(isa<EnumConstantDecl>(SubDecl) &&
"Unexpected Decl");
580 Decls.push_back(SubDecl);
584 ID.AddInteger(Decls.size());
585 for (
auto SubDecl : Decls) {
592 assert(D &&
"Expecting non-null pointer.");
595 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
607 class ODRTypeVisitor :
public TypeVisitor<ODRTypeVisitor> {
609 llvm::FoldingSetNodeID &ID;
613 ODRTypeVisitor(llvm::FoldingSetNodeID &ID,
ODRHash &Hash)
614 : ID(ID), Hash(Hash) {}
659 void Visit(
const Type *T) {
664 void VisitType(
const Type *T) {}
675 VisitAdjustedType(T);
678 void VisitArrayType(
const ArrayType *T) {
718 VisitFunctionType(T);
726 VisitFunctionType(T);
740 VisitReferenceType(T);
744 VisitReferenceType(T);
750 VisitQualifiers(UnderlyingType.getQualifiers());
753 dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
754 UnderlyingType = Underlying->getDecl()->getUnderlyingType();
758 dyn_cast<ElaboratedType>(UnderlyingType.getTypePtr())) {
759 UnderlyingType = Underlying->getNamedType();
765 AddType(UnderlyingType.getTypePtr());
769 void VisitTagType(
const TagType *T) {
774 void VisitRecordType(
const RecordType *T) { VisitTagType(T); }
775 void VisitEnumType(
const EnumType *T) { VisitTagType(T); }
785 VisitTypeWithKeyword(T);
788 void VisitDependentTemplateSpecializationType(
796 VisitTypeWithKeyword(T);
802 VisitTypeWithKeyword(T);
824 assert(T &&
"Expecting non-null pointer.");
825 ODRTypeVisitor(ID, *
this).Visit(T);
838 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.
Represents a function declaration or definition.
Smart pointer class that efficiently represents Objective-C method names.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
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.
An instance of this object exists for each enum constant that is defined.
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.
Represents a variable declaration or definition.
Declaration of a redeclarable template.
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
Represents a parameter to a function.
The collection of all-type qualifiers we support.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
QualType getOriginalType() const
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists...
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...
Represents a member of a struct/union/class.
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
An rvalue reference type, per C++11 [dcl.ref].
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)
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
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
const Expr * getInitExpr() const
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
Expr * getSizeExpr() const
QualType getPointeeTypeAsWritten() 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...
Represents the declaration of a typedef-name via a C++11 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...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Represents an array type in C++ whose size is a value-dependent expression.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
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.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isDefaulted() const
Whether this function is defaulted per C++0x.
unsigned getAsOpaqueValue() const
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
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...
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
void AddDeclarationName(DeclarationName Name)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isFileContext() const
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...
Qualifiers Quals
The local qualifiers.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A helper class for Type nodes having an ElaboratedTypeKeyword.
ArraySizeModifier getSizeModifier() const
An lvalue reference type, per C++11 [dcl.ref].
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...
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...
Decl::Kind getDeclKind() const
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.
bool isParameterPack() const
Returns whether this is a parameter pack.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
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 isScoped() const
Returns true if this is a C++11 scoped enumeration.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
unsigned getODRHash()
Returns ODRHash of the function.
Qualifiers getIndexTypeQualifiers() const
TypeClass getTypeClass() const
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS)
ArrayRef< TemplateArgument > template_arguments() const
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Represents a C++11 static_assert declaration.
void AddSubDecl(const Decl *D)
void AddEnumDecl(const EnumDecl *Enum)
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
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
NestedNameSpecifier * getQualifier() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The base class of all kinds of template declarations (e.g., class, function, etc.).
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
Returns true if a variable with function scope is a static local variable.
Base for LValueReferenceType and RValueReferenceType.
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
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'.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
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.
static bool isWhitelistedDecl(const Decl *D, const DeclContext *Parent)
QualType getDefaultArgument() const
Retrieve the default argument, if any.
A set of overloaded template declarations.
This represents a decl that may have 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.
Declaration of a template function.
bool isDeletedAsWritten() const
QualType getType() const
Return the type wrapped by this type source info.
A single template declaration.
const IdentifierInfo * getIdentifier() const