From: Craig Topper Date: Thu, 13 Mar 2014 08:12:15 +0000 (+0000) Subject: [C++11] Add 'override' keyword to virtual methods that override their base class. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7031022fea40f717d1e49500d652cbd593e8a880;p=clang [C++11] Add 'override' keyword to virtual methods that override their base class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203769 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchFinder.h b/include/clang/ASTMatchers/ASTMatchFinder.h index db0a83d722..8c8a509596 100644 --- a/include/clang/ASTMatchers/ASTMatchFinder.h +++ b/include/clang/ASTMatchers/ASTMatchFinder.h @@ -228,7 +228,7 @@ selectFirst(StringRef BoundTo, const SmallVectorImpl &Results) { namespace internal { class CollectMatchesCallback : public MatchFinder::MatchCallback { public: - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { Nodes.push_back(Result.Nodes); } SmallVector Nodes; diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index 45c5d7ae6e..23885a18e6 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -192,9 +192,9 @@ public: private: /// Implements MatcherInterface::Matches. - virtual bool matches(const T &Node, - ASTMatchFinder * /* Finder */, - BoundNodesTreeBuilder * /* Builder */) const { + bool matches(const T &Node, + ASTMatchFinder * /* Finder */, + BoundNodesTreeBuilder * /* Builder */) const override { return matchesNode(Node); } }; @@ -265,9 +265,8 @@ public: TypeToQualType(const Matcher &InnerMatcher) : InnerMatcher(InnerMatcher) {} - virtual bool matches(const QualType &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const QualType &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { if (Node.isNull()) return false; return InnerMatcher.matches(*Node, Finder, Builder); @@ -285,9 +284,8 @@ private: explicit ImplicitCastMatcher(const Matcher &From) : From(From) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return From.matches(Node, Finder, Builder); } @@ -528,7 +526,7 @@ public: explicit HasOverloadedOperatorNameMatcher(const StringRef Name) : SingleNodeMatcherInterface(), Name(Name) {} - virtual bool matchesNode(const T &Node) const override { + bool matchesNode(const T &Node) const override { return matchesSpecialized(Node); } @@ -564,9 +562,8 @@ public: explicit HasDeclarationMatcher(const Matcher &InnerMatcher) : InnerMatcher(InnerMatcher) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return matchesSpecialized(Node, Finder, Builder); } @@ -989,7 +986,7 @@ private: template class TrueMatcher : public SingleNodeMatcherInterface { public: - virtual bool matchesNode(const T &Node) const { + bool matchesNode(const T &Node) const override { return true; } }; @@ -1004,9 +1001,8 @@ public: IdMatcher(StringRef ID, const Matcher &InnerMatcher) : ID(ID), InnerMatcher(InnerMatcher) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { bool Result = InnerMatcher.matches(Node, Finder, Builder); if (Result) { Builder->setBinding(ID, &Node); @@ -1052,9 +1048,8 @@ public: explicit HasMatcher(const Matcher &ChildMatcher) : ChildMatcher(ChildMatcher) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return Finder->matchesChildOf( Node, ChildMatcher, Builder, ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses, @@ -1079,9 +1074,8 @@ class ForEachMatcher : public MatcherInterface { explicit ForEachMatcher(const Matcher &ChildMatcher) : ChildMatcher(ChildMatcher) {} - virtual bool matches(const T& Node, - ASTMatchFinder* Finder, - BoundNodesTreeBuilder* Builder) const { + bool matches(const T& Node, ASTMatchFinder* Finder, + BoundNodesTreeBuilder* Builder) const override { return Finder->matchesChildOf( Node, ChildMatcher, Builder, ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses, @@ -1109,8 +1103,8 @@ public: std::vector InnerMatchers) : Func(Func), InnerMatchers(std::move(InnerMatchers)) {} - virtual bool matches(const T &Node, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return Func(ast_type_traits::DynTypedNode::create(Node), Finder, Builder, InnerMatchers); } @@ -1289,9 +1283,8 @@ public: explicit HasDescendantMatcher(const Matcher &DescendantMatcher) : DescendantMatcher(DescendantMatcher) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return Finder->matchesDescendantOf( Node, DescendantMatcher, Builder, ASTMatchFinder::BK_First); } @@ -1313,9 +1306,8 @@ public: explicit HasParentMatcher(const Matcher &ParentMatcher) : ParentMatcher(ParentMatcher) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return Finder->matchesAncestorOf( Node, ParentMatcher, Builder, ASTMatchFinder::AMM_ParentOnly); } @@ -1337,9 +1329,8 @@ public: explicit HasAncestorMatcher(const Matcher &AncestorMatcher) : AncestorMatcher(AncestorMatcher) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return Finder->matchesAncestorOf( Node, AncestorMatcher, Builder, ASTMatchFinder::AMM_All); } @@ -1364,9 +1355,8 @@ class ForEachDescendantMatcher : public MatcherInterface { const Matcher& DescendantMatcher) : DescendantMatcher(DescendantMatcher) {} - virtual bool matches(const T& Node, - ASTMatchFinder* Finder, - BoundNodesTreeBuilder* Builder) const { + bool matches(const T& Node, ASTMatchFinder* Finder, + BoundNodesTreeBuilder* Builder) const override { return Finder->matchesDescendantOf(Node, DescendantMatcher, Builder, ASTMatchFinder::BK_All); } @@ -1389,7 +1379,7 @@ public: explicit ValueEqualsMatcher(const ValueT &ExpectedValue) : ExpectedValue(ExpectedValue) {} - virtual bool matchesNode(const T &Node) const { + bool matchesNode(const T &Node) const override { return Node.getValue() == ExpectedValue; } @@ -1444,9 +1434,8 @@ public: explicit LocMatcher(const Matcher &InnerMatcher) : InnerMatcher(InnerMatcher) {} - virtual bool matches(const TLoc &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const TLoc &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { if (!Node) return false; return InnerMatcher.matches(*extract(Node), Finder, Builder); @@ -1469,9 +1458,8 @@ public: explicit TypeLocTypeMatcher(const Matcher &InnerMatcher) : InnerMatcher(InnerMatcher) {} - virtual bool matches(const TypeLoc &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const TypeLoc &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { if (!Node) return false; return InnerMatcher.matches(Node.getType(), Finder, Builder); @@ -1491,9 +1479,8 @@ public: QualType (T::*TraverseFunction)() const) : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { QualType NextNode = (Node.*TraverseFunction)(); if (NextNode.isNull()) return false; @@ -1515,9 +1502,8 @@ public: TypeLoc (T::*TraverseFunction)() const) : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {} - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { TypeLoc NextNode = (Node.*TraverseFunction)(); if (!NextNode) return false; diff --git a/include/clang/ASTMatchers/ASTMatchersMacros.h b/include/clang/ASTMatchers/ASTMatchersMacros.h index e4394836ec..418e577c34 100644 --- a/include/clang/ASTMatchers/ASTMatchersMacros.h +++ b/include/clang/ASTMatchers/ASTMatchersMacros.h @@ -72,8 +72,8 @@ class matcher_##DefineMatcher##Matcher : public MatcherInterface { \ public: \ explicit matcher_##DefineMatcher##Matcher() {} \ - virtual bool matches(const Type &Node, ASTMatchFinder *Finder, \ - BoundNodesTreeBuilder *Builder) const; \ + bool matches(const Type &Node, ASTMatchFinder *Finder, \ + BoundNodesTreeBuilder *Builder) const override; \ }; \ } \ inline internal::Matcher DefineMatcher() { \ @@ -109,8 +109,8 @@ explicit matcher_##DefineMatcher##OverloadId##Matcher( \ const ParamType &A##Param) \ : Param(A##Param) {} \ - virtual bool matches(const Type &Node, ASTMatchFinder *Finder, \ - BoundNodesTreeBuilder *Builder) const; \ + bool matches(const Type &Node, ASTMatchFinder *Finder, \ + BoundNodesTreeBuilder *Builder) const override; \ \ private: \ const ParamType Param; \ @@ -154,8 +154,8 @@ matcher_##DefineMatcher##OverloadId##Matcher(const ParamType1 &A##Param1, \ const ParamType2 &A##Param2) \ : Param1(A##Param1), Param2(A##Param2) {} \ - virtual bool matches(const Type &Node, ASTMatchFinder *Finder, \ - BoundNodesTreeBuilder *Builder) const; \ + bool matches(const Type &Node, ASTMatchFinder *Finder, \ + BoundNodesTreeBuilder *Builder) const override; \ \ private: \ const ParamType1 Param1; \ @@ -203,8 +203,8 @@ template \ class matcher_##DefineMatcher##Matcher : public MatcherInterface { \ public: \ - virtual bool matches(const NodeType &Node, ASTMatchFinder *Finder, \ - BoundNodesTreeBuilder *Builder) const; \ + bool matches(const NodeType &Node, ASTMatchFinder *Finder, \ + BoundNodesTreeBuilder *Builder) const override; \ }; \ } \ inline internal::PolymorphicMatcherWithParam0< \ @@ -242,8 +242,8 @@ explicit matcher_##DefineMatcher##OverloadId##Matcher( \ const ParamType &A##Param) \ : Param(A##Param) {} \ - virtual bool matches(const NodeType &Node, ASTMatchFinder *Finder, \ - BoundNodesTreeBuilder *Builder) const; \ + bool matches(const NodeType &Node, ASTMatchFinder *Finder, \ + BoundNodesTreeBuilder *Builder) const override; \ \ private: \ const ParamType Param; \ @@ -289,8 +289,8 @@ matcher_##DefineMatcher##OverloadId##Matcher(const ParamType1 &A##Param1, \ const ParamType2 &A##Param2) \ : Param1(A##Param1), Param2(A##Param2) {} \ - virtual bool matches(const NodeType &Node, ASTMatchFinder *Finder, \ - BoundNodesTreeBuilder *Builder) const; \ + bool matches(const NodeType &Node, ASTMatchFinder *Finder, \ + BoundNodesTreeBuilder *Builder) const override; \ \ private: \ const ParamType1 Param1; \ diff --git a/lib/ASTMatchers/ASTMatchFinder.cpp b/lib/ASTMatchers/ASTMatchFinder.cpp index b2911a3be2..3e9d3d2a1c 100644 --- a/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/lib/ASTMatchers/ASTMatchFinder.cpp @@ -407,36 +407,36 @@ public: return Visitor.findMatch(Node); } - virtual bool classIsDerivedFrom(const CXXRecordDecl *Declaration, - const Matcher &Base, - BoundNodesTreeBuilder *Builder); + bool classIsDerivedFrom(const CXXRecordDecl *Declaration, + const Matcher &Base, + BoundNodesTreeBuilder *Builder) override; // Implements ASTMatchFinder::matchesChildOf. - virtual bool matchesChildOf(const ast_type_traits::DynTypedNode &Node, - const DynTypedMatcher &Matcher, - BoundNodesTreeBuilder *Builder, - TraversalKind Traversal, - BindKind Bind) { + bool matchesChildOf(const ast_type_traits::DynTypedNode &Node, + const DynTypedMatcher &Matcher, + BoundNodesTreeBuilder *Builder, + TraversalKind Traversal, + BindKind Bind) override { if (ResultCache.size() > MaxMemoizationEntries) ResultCache.clear(); return memoizedMatchesRecursively(Node, Matcher, Builder, 1, Traversal, Bind); } // Implements ASTMatchFinder::matchesDescendantOf. - virtual bool matchesDescendantOf(const ast_type_traits::DynTypedNode &Node, - const DynTypedMatcher &Matcher, - BoundNodesTreeBuilder *Builder, - BindKind Bind) { + bool matchesDescendantOf(const ast_type_traits::DynTypedNode &Node, + const DynTypedMatcher &Matcher, + BoundNodesTreeBuilder *Builder, + BindKind Bind) override { if (ResultCache.size() > MaxMemoizationEntries) ResultCache.clear(); return memoizedMatchesRecursively(Node, Matcher, Builder, INT_MAX, TK_AsIs, Bind); } // Implements ASTMatchFinder::matchesAncestorOf. - virtual bool matchesAncestorOf(const ast_type_traits::DynTypedNode &Node, - const DynTypedMatcher &Matcher, - BoundNodesTreeBuilder *Builder, - AncestorMatchMode MatchMode) { + bool matchesAncestorOf(const ast_type_traits::DynTypedNode &Node, + const DynTypedMatcher &Matcher, + BoundNodesTreeBuilder *Builder, + AncestorMatchMode MatchMode) override { // Reset the cache outside of the recursive call to make sure we // don't invalidate any iterators. if (ResultCache.size() > MaxMemoizationEntries) @@ -466,7 +466,7 @@ public: } // Implements ASTMatchFinder::getASTContext. - virtual ASTContext &getASTContext() const { return *ActiveASTContext; } + ASTContext &getASTContext() const override { return *ActiveASTContext; } bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return true; } @@ -573,7 +573,7 @@ private: : Context(Context), Callback(Callback) {} - virtual void visitMatch(const BoundNodes& BoundNodesView) { + void visitMatch(const BoundNodes& BoundNodesView) override { Callback->run(MatchFinder::MatchResult(BoundNodesView, Context)); } @@ -746,7 +746,7 @@ public: : Finder(Finder), ParsingDone(ParsingDone) {} private: - virtual void HandleTranslationUnit(ASTContext &Context) { + void HandleTranslationUnit(ASTContext &Context) override { if (ParsingDone != NULL) { ParsingDone->run(); }