[cfe-commits] PATCH: add-override-specifier tool
Manuel Klimek
klimek at google.com
Mon Jul 16 02:19:42 PDT 2012
+ AST_MATCHER(clang::CXXMethodDecl, isOverrideMissing) {
+ bool IsCanonicalDecl = Node.isCanonicalDecl();
+ bool VirtualMethod = Node.isVirtual();
+ bool IsDestructor = llvm::isa<CXXDestructorDecl>(Node);
+ bool OverridesMethods = (Node.size_overridden_methods() > 0);
+ bool HasOverrideAttr = Node.hasAttr<OverrideAttr>();
+ return IsCanonicalDecl && VirtualMethod && !IsDestructor &&
+ OverridesMethods && !HasOverrideAttr;
This is a perfect match for the matchers: goal would be to have 1
matcher for each attribute, and we can add a isOverrideMissing
function that returns method(isCanonicalDecl(), isVirtual(), ...);
+class AddOverrideAttributeCallback : public MatchFinder::MatchCallback {
This sounds like it would be the perfect fit to the
RefactoringCallbacks which Daniel just checked in (r160255).
We need that quite frequently, and unfortunately it's hard to get
right - we'll probably want to get it more right in the future (for
example, if there's a // comment before the { this will just add to
the comment).
Cheers,
/Manuel
On Sun, Jul 15, 2012 at 7:04 PM, Philip Dunstan <phil at philipdunstan.com> wrote:
> Hi
>
> This is a patch to add a new tool to the clang tools directory to add the
> C++11 override specifier to member functions where appropriate. That is,
> member functions that override a virtual function from a base class and that
> are not already marked up with the override specifier. This tool uses the
> ASTMatchers framework (with a custom matcher) recently integrated from the
> tooling branch.
>
> I'm aware of the recent conversation on cfe-dev regarding C++11 migration
> tools. There was some talk there of possibly locating these types of tools
> separate from the main repository. If there is such a repository I can
> rebase the patch to that location.
>
> Phil
> --
> Philip Dunstan
> phil at philipdunstan.com
> www.philipdunstan.com
More information about the cfe-commits
mailing list