From 4c7736ec76fb35fe83eb4144137cf14df1c6d056 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 24 Jul 2013 15:28:33 +0000 Subject: [PATCH] Sema: Minor const fixups and control flow tidying. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187047 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Initialization.h | 6 +- lib/Sema/SemaDeclCXX.cpp | 160 ++++++++++++---------------- lib/Sema/SemaInit.cpp | 8 +- 3 files changed, 74 insertions(+), 100 deletions(-) diff --git a/include/clang/Sema/Initialization.h b/include/clang/Sema/Initialization.h index d695e33a64..cd11fce90c 100644 --- a/include/clang/Sema/Initialization.h +++ b/include/clang/Sema/Initialization.h @@ -274,7 +274,7 @@ public: /// \brief Create the initialization entity for a base class subobject. static InitializedEntity InitializeBase(ASTContext &Context, - CXXBaseSpecifier *Base, + const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase); /// \brief Create the initialization entity for a delegated constructor. @@ -359,9 +359,9 @@ public: } /// \brief Retrieve the base specifier. - CXXBaseSpecifier *getBaseSpecifier() const { + const CXXBaseSpecifier *getBaseSpecifier() const { assert(getKind() == EK_Base && "Not a base specifier"); - return reinterpret_cast(Base & ~0x1); + return reinterpret_cast(Base & ~0x1); } /// \brief Return whether the base is an inherited virtual base. diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 015133041f..3df0472df6 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1218,8 +1218,7 @@ bool Sema::isCurrentClassName(const IdentifierInfo &II, Scope *, if (CurDecl && CurDecl->getIdentifier()) return &II == CurDecl->getIdentifier(); - else - return false; + return false; } /// \brief Determine whether the given class is a base class of the given @@ -2292,21 +2291,20 @@ namespace { // Callback to only accept typo corrections that can be a valid C++ member // intializer: either a non-static field member or a base class. class MemInitializerValidatorCCC : public CorrectionCandidateCallback { - public: +public: explicit MemInitializerValidatorCCC(CXXRecordDecl *ClassDecl) : ClassDecl(ClassDecl) {} - virtual bool ValidateCandidate(const TypoCorrection &candidate) { + bool ValidateCandidate(const TypoCorrection &candidate) LLVM_OVERRIDE { if (NamedDecl *ND = candidate.getCorrectionDecl()) { if (FieldDecl *Member = dyn_cast(ND)) return Member->getDeclContext()->getRedeclContext()->Equals(ClassDecl); - else - return isa(ND); + return isa(ND); } return false; } - private: +private: CXXRecordDecl *ClassDecl; }; @@ -2753,9 +2751,9 @@ Sema::BuildBaseInitializer(QualType BaseType, TypeSourceInfo *BaseTInfo, return Diag(BaseLoc, diag::err_base_init_direct_and_virtual) << BaseType << BaseTInfo->getTypeLoc().getLocalSourceRange(); - CXXBaseSpecifier *BaseSpec = const_cast(DirectBaseSpec); + const CXXBaseSpecifier *BaseSpec = DirectBaseSpec; if (!BaseSpec) - BaseSpec = const_cast(VirtualBaseSpec); + BaseSpec = VirtualBaseSpec; // Initialize the base. bool InitList = true; @@ -3494,12 +3492,12 @@ static void PopulateKeysForFields(FieldDecl *Field, SmallVectorImpl IdealInits.push_back(Field); } -static void *GetKeyForBase(ASTContext &Context, QualType BaseType) { - return const_cast(Context.getCanonicalType(BaseType).getTypePtr()); +static const void *GetKeyForBase(ASTContext &Context, QualType BaseType) { + return Context.getCanonicalType(BaseType).getTypePtr(); } -static void *GetKeyForMember(ASTContext &Context, - CXXCtorInitializer *Member) { +static const void *GetKeyForMember(ASTContext &Context, + CXXCtorInitializer *Member) { if (!Member->isAnyMemberInitializer()) return GetKeyForBase(Context, QualType(Member->getBaseClass(), 0)); @@ -3563,7 +3561,7 @@ static void DiagnoseBaseOrMemInitializerOrder( CXXCtorInitializer *PrevInit = 0; for (unsigned InitIndex = 0; InitIndex != Inits.size(); ++InitIndex) { CXXCtorInitializer *Init = Inits[InitIndex]; - void *InitKey = GetKeyForMember(SemaRef.Context, Init); + const void *InitKey = GetKeyForMember(SemaRef.Context, Init); // Scan forward to try to find this initializer in the idealized // initializers list. @@ -3689,7 +3687,7 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl, // Mapping for the duplicate initializers check. // For member initializers, this is keyed with a FieldDecl*. // For base initializers, this is keyed with a Type*. - llvm::DenseMap Members; + llvm::DenseMap Members; // Mapping for the inconsistent anonymous-union initializers check. RedundantUnionMap MemberUnions; @@ -3707,7 +3705,8 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl, CheckRedundantUnionInit(*this, Init, MemberUnions)) HadError = true; } else if (Init->isBaseInitializer()) { - void *Key = GetKeyForBase(Context, QualType(Init->getBaseClass(), 0)); + const void *Key = + GetKeyForBase(Context, QualType(Init->getBaseClass(), 0)); if (CheckRedundantInit(*this, Init, Members[Key])) HadError = true; } else { @@ -3779,7 +3778,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location, << Field->getDeclName() << FieldType); - MarkFunctionReferenced(Location, const_cast(Dtor)); + MarkFunctionReferenced(Location, Dtor); DiagnoseUseOfDecl(Dtor, Location); } @@ -3812,7 +3811,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location, << Base->getSourceRange(), Context.getTypeDeclType(ClassDecl)); - MarkFunctionReferenced(Location, const_cast(Dtor)); + MarkFunctionReferenced(Location, Dtor); DiagnoseUseOfDecl(Dtor, Location); } @@ -3848,7 +3847,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location, SourceRange(), DeclarationName(), 0); } - MarkFunctionReferenced(Location, const_cast(Dtor)); + MarkFunctionReferenced(Location, Dtor); DiagnoseUseOfDecl(Dtor, Location); } } @@ -3871,8 +3870,8 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, public: NonAbstractTypeDiagnoser(unsigned DiagID, AbstractDiagSelID SelID) : TypeDiagnoser(DiagID == 0), DiagID(DiagID), SelID(SelID) { } - - virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { + + void diagnose(Sema &S, SourceLocation Loc, QualType T) LLVM_OVERRIDE { if (Suppressed) return; if (SelID == -1) S.Diag(Loc, DiagID) << T; @@ -6608,11 +6607,10 @@ namespace { // Callback to only accept typo corrections that are namespaces. class NamespaceValidatorCCC : public CorrectionCandidateCallback { - public: - virtual bool ValidateCandidate(const TypoCorrection &candidate) { - if (NamedDecl *ND = candidate.getCorrectionDecl()) { +public: + bool ValidateCandidate(const TypoCorrection &candidate) LLVM_OVERRIDE { + if (NamedDecl *ND = candidate.getCorrectionDecl()) return isa(ND) || isa(ND); - } return false; } }; @@ -7046,35 +7044,35 @@ void Sema::HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow) { // be possible for this to happen, because...? } +namespace { class UsingValidatorCCC : public CorrectionCandidateCallback { public: UsingValidatorCCC(bool HasTypenameKeyword, bool IsInstantiation) : HasTypenameKeyword(HasTypenameKeyword), IsInstantiation(IsInstantiation) {} - virtual bool ValidateCandidate(const TypoCorrection &Candidate) { - if (NamedDecl *ND = Candidate.getCorrectionDecl()) { - if (isa(ND)) - return false; - // Completely unqualified names are invalid for a 'using' declaration. - bool droppedSpecifier = Candidate.WillReplaceSpecifier() && - !Candidate.getCorrectionSpecifier(); - if (droppedSpecifier) - return false; - else if (isa(ND)) - return HasTypenameKeyword || !IsInstantiation; - else - return !HasTypenameKeyword; - } else { - // Keywords are not valid here. + bool ValidateCandidate(const TypoCorrection &Candidate) LLVM_OVERRIDE { + NamedDecl *ND = Candidate.getCorrectionDecl(); + + // Keywords are not valid here. + if (!ND || isa(ND)) return false; - } + + // Completely unqualified names are invalid for a 'using' declaration. + if (Candidate.WillReplaceSpecifier() && !Candidate.getCorrectionSpecifier()) + return false; + + if (isa(ND)) + return HasTypenameKeyword || !IsInstantiation; + + return !HasTypenameKeyword; } private: bool HasTypenameKeyword; bool IsInstantiation; }; +} // end anonymous namespace /// Builds a using declaration. /// @@ -11584,47 +11582,29 @@ void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation DefaultLoc) { ResolveExceptionSpec(DefaultLoc, MD->getType()->castAs()); + if (MD->isInvalidDecl()) + return; + switch (Member) { - case CXXDefaultConstructor: { - CXXConstructorDecl *CD = cast(MD); - if (!CD->isInvalidDecl()) - DefineImplicitDefaultConstructor(DefaultLoc, CD); + case CXXDefaultConstructor: + DefineImplicitDefaultConstructor(DefaultLoc, + cast(MD)); break; - } - - case CXXCopyConstructor: { - CXXConstructorDecl *CD = cast(MD); - if (!CD->isInvalidDecl()) - DefineImplicitCopyConstructor(DefaultLoc, CD); + case CXXCopyConstructor: + DefineImplicitCopyConstructor(DefaultLoc, cast(MD)); break; - } - - case CXXCopyAssignment: { - if (!MD->isInvalidDecl()) - DefineImplicitCopyAssignment(DefaultLoc, MD); + case CXXCopyAssignment: + DefineImplicitCopyAssignment(DefaultLoc, MD); break; - } - - case CXXDestructor: { - CXXDestructorDecl *DD = cast(MD); - if (!DD->isInvalidDecl()) - DefineImplicitDestructor(DefaultLoc, DD); + case CXXDestructor: + DefineImplicitDestructor(DefaultLoc, cast(MD)); break; - } - - case CXXMoveConstructor: { - CXXConstructorDecl *CD = cast(MD); - if (!CD->isInvalidDecl()) - DefineImplicitMoveConstructor(DefaultLoc, CD); + case CXXMoveConstructor: + DefineImplicitMoveConstructor(DefaultLoc, cast(MD)); break; - } - - case CXXMoveAssignment: { - if (!MD->isInvalidDecl()) - DefineImplicitMoveAssignment(DefaultLoc, MD); + case CXXMoveAssignment: + DefineImplicitMoveAssignment(DefaultLoc, MD); break; - } - case CXXInvalid: llvm_unreachable("Invalid special member."); } @@ -11805,13 +11785,13 @@ bool Sema::CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange) { } /// \brief Determine whether the given declaration is a static data member. -static bool isStaticDataMember(Decl *D) { - VarDecl *Var = dyn_cast_or_null(D); - if (!Var) - return false; - - return Var->isStaticDataMember(); +static bool isStaticDataMember(const Decl *D) { + if (const VarDecl *Var = dyn_cast_or_null(D)) + return Var->isStaticDataMember(); + + return false; } + /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse /// an initializer for the out-of-line declaration 'Dcl'. The scope /// is a fresh scope pushed for just this purpose. @@ -12130,8 +12110,6 @@ void DelegatingCycleHelper(CXXConstructorDecl* Ctor, llvm::SmallSet &Invalid, llvm::SmallSet &Current, Sema &S) { - llvm::SmallSet::iterator CI = Current.begin(), - CE = Current.end(); if (Ctor->isInvalidDecl()) return; @@ -12156,8 +12134,7 @@ void DelegatingCycleHelper(CXXConstructorDecl* Ctor, // We know that beyond here, we aren't chaining into a cycle. if (!Target || !Target->isDelegatingConstructor() || Target->isInvalidDecl() || Valid.count(TCanonical)) { - for (CI = Current.begin(), CE = Current.end(); CI != CE; ++CI) - Valid.insert(*CI); + Valid.insert(Current.begin(), Current.end()); Current.clear(); // We've hit a cycle. } else if (TCanonical == Canonical || Invalid.count(TCanonical) || @@ -12184,8 +12161,7 @@ void DelegatingCycleHelper(CXXConstructorDecl* Ctor, } } - for (CI = Current.begin(), CE = Current.end(); CI != CE; ++CI) - Invalid.insert(*CI); + Invalid.insert(Current.begin(), Current.end()); Current.clear(); } else { DelegatingCycleHelper(Target, Valid, Invalid, Current, S); @@ -12196,16 +12172,15 @@ void DelegatingCycleHelper(CXXConstructorDecl* Ctor, void Sema::CheckDelegatingCtorCycles() { llvm::SmallSet Valid, Invalid, Current; - llvm::SmallSet::iterator CI = Current.begin(), - CE = Current.end(); - for (DelegatingCtorDeclsType::iterator I = DelegatingCtorDecls.begin(ExternalSource), E = DelegatingCtorDecls.end(); I != E; ++I) DelegatingCycleHelper(*I, Valid, Invalid, Current, *this); - for (CI = Invalid.begin(), CE = Invalid.end(); CI != CE; ++CI) + for (llvm::SmallSet::iterator CI = Invalid.begin(), + CE = Invalid.end(); + CI != CE; ++CI) (*CI)->setInvalidDecl(); } @@ -12421,8 +12396,7 @@ Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const FunctionDecl *D) { if (D->hasAttr()) { if (D->hasAttr()) return CFT_HostDevice; - else - return CFT_Device; + return CFT_Device; } return CFT_Host; diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index cc0829ef67..ce8612512e 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -2455,10 +2455,10 @@ InitializedEntity::InitializedEntity(ASTContext &Context, unsigned Index, } } -InitializedEntity InitializedEntity::InitializeBase(ASTContext &Context, - CXXBaseSpecifier *Base, - bool IsInheritedVirtualBase) -{ +InitializedEntity +InitializedEntity::InitializeBase(ASTContext &Context, + const CXXBaseSpecifier *Base, + bool IsInheritedVirtualBase) { InitializedEntity Result; Result.Kind = EK_Base; Result.Parent = 0; -- 2.40.0