From 0826a5617885bef2559c8213ec52685786ff0506 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Thu, 7 Jul 2022 11:48:34 +0800 Subject: [PATCH] [NFC] make ASTContext:isSame* methods const --- clang/include/clang/AST/ASTContext.h | 26 ++++++++------------------ clang/lib/AST/ASTContext.cpp | 16 +++++++--------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 7db6af9..9229362 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -260,7 +260,7 @@ class ASTContext : public RefCountedBase { mutable llvm::FoldingSet DeducedTemplateSpecializationTypes; mutable llvm::FoldingSet AtomicTypes; - llvm::FoldingSet AttributedTypes; + mutable llvm::FoldingSet AttributedTypes; mutable llvm::FoldingSet PipeTypes; mutable llvm::FoldingSet BitIntTypes; mutable llvm::FoldingSet DependentBitIntTypes; @@ -1306,11 +1306,11 @@ public: /// declaration of a function with an exception specification is permitted /// and preserved. Other type sugar (for instance, typedefs) is not. QualType getFunctionTypeWithExceptionSpec( - QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI); + QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) const; /// Determine whether two function types are the same, ignoring /// exception specifications in cases where they're part of the type. - bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U); + bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U) const; /// Change the exception specification on a function once it is /// delay-parsed, instantiated, or computed. @@ -1597,9 +1597,8 @@ public: QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; - QualType getAttributedType(attr::Kind attrKind, - QualType modifiedType, - QualType equivalentType); + QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, + QualType equivalentType) const; QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr, QualType Wrapped); @@ -2654,25 +2653,16 @@ public: bool hasSameTemplateName(const TemplateName &X, const TemplateName &Y) const; /// Determine whether the two declarations refer to the same entity. - /// - /// FIXME: isSameEntity is not const due to its implementation calls - /// hasSameFunctionTypeIgnoringExceptionSpec which may alter this. - bool isSameEntity(const NamedDecl *X, const NamedDecl *Y); + bool isSameEntity(const NamedDecl *X, const NamedDecl *Y) const; /// Determine whether two template parameter lists are similar enough /// that they may be used in declarations of the same template. - /// - /// FIXME: isSameTemplateParameterList is not const since it calls - /// isSameTemplateParameter. bool isSameTemplateParameterList(const TemplateParameterList *X, - const TemplateParameterList *Y); + const TemplateParameterList *Y) const; /// Determine whether two template parameters are similar enough /// that they may be used in declarations of the same template. - /// - /// FIXME: isSameTemplateParameterList is not const since it calls - /// isSameEntity. - bool isSameTemplateParameter(const NamedDecl *X, const NamedDecl *Y); + bool isSameTemplateParameter(const NamedDecl *X, const NamedDecl *Y) const; /// Retrieve the "canonical" template argument. /// diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e64135c..aced0ab 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3166,7 +3166,7 @@ void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD, /// declaration of a function with an exception specification is permitted /// and preserved. Other type sugar (for instance, typedefs) is not. QualType ASTContext::getFunctionTypeWithExceptionSpec( - QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) { + QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI) const { // Might have some parens. if (const auto *PT = dyn_cast(Orig)) return getParenType( @@ -3194,7 +3194,7 @@ QualType ASTContext::getFunctionTypeWithExceptionSpec( } bool ASTContext::hasSameFunctionTypeIgnoringExceptionSpec(QualType T, - QualType U) { + QualType U) const { return hasSameType(T, U) || (getLangOpts().CPlusPlus17 && hasSameType(getFunctionTypeWithExceptionSpec(T, EST_None), @@ -4703,7 +4703,7 @@ QualType ASTContext::getUnresolvedUsingType( QualType ASTContext::getAttributedType(attr::Kind attrKind, QualType modifiedType, - QualType equivalentType) { + QualType equivalentType) const { llvm::FoldingSetNodeID id; AttributedType::Profile(id, attrKind, modifiedType, equivalentType); @@ -6219,7 +6219,7 @@ bool ASTContext::hasSameTemplateName(const TemplateName &X, } bool ASTContext::isSameTemplateParameter(const NamedDecl *X, - const NamedDecl *Y) { + const NamedDecl *Y) const { if (X->getKind() != Y->getKind()) return false; @@ -6270,8 +6270,8 @@ bool ASTContext::isSameTemplateParameter(const NamedDecl *X, TY->getTemplateParameters()); } -bool ASTContext::isSameTemplateParameterList(const TemplateParameterList *X, - const TemplateParameterList *Y) { +bool ASTContext::isSameTemplateParameterList( + const TemplateParameterList *X, const TemplateParameterList *Y) const { if (X->size() != Y->size()) return false; @@ -6374,7 +6374,7 @@ static bool hasSameOverloadableAttrs(const FunctionDecl *A, return true; } -bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) { +bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const { if (X == Y) return true; @@ -6481,8 +6481,6 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) { if (getLangOpts().CPlusPlus17 && XFPT && YFPT && (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) || isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) && - // FIXME: We could make isSameEntity const after we make - // hasSameFunctionTypeIgnoringExceptionSpec const. hasSameFunctionTypeIgnoringExceptionSpec(XT, YT)) return true; return false; -- 2.7.4