[cfe-dev] Problem using ast matchers macros

Vane, Edwin edwin.vane at intel.com
Tue Sep 24 08:02:00 PDT 2013


The source of the failure is where you have SameType(recordDecl(...)). You'll notice in the reference that recordDecl() returns a Matcher<Decl>. So your SameType() matcher is going to receive a 'Decl' as input. You'll need to explicitly change this into a FieldDecl. I'm afraid I don't know exactly what you're trying to match or what IHD is so I can't tell if there's a more fundamental error here.

From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] On Behalf Of Daniel QuiƱones Lopez
Sent: Monday, September 23, 2013 11:18 AM
To: cfe-dev at cs.uiuc.edu
Subject: [cfe-dev] Problem using ast matchers macros

I'm trying to implement an ast matcher for the IHD (hidden variable deletion) operator. For this purpose, i also define two matchers using the ast macros. The code is as follows:
namespace clang{
    namespace ast_matchers{
      using namespace clang::ast_matchers::internal;

         // Checks that two FieldDecl nodes have the same type
        AST_MATCHER_P(FieldDecl, SameType, FieldDecl, f)
        {
          return Node.getType() == f.getType();
        }

        // Checks that two FieldDecl nodes have the same name
        AST_MATCHER_P(FieldDecl, SameName, FieldDecl, f)
        {
          return Node.getName() == f.getName();
        }


    }
}
And the code for the IHD operator is:
DeclarationMatcher IHD__Matcher = recordDecl(
                                                              has(
                                                                 fieldDecl().bind("IHD")
                                                              ),
                                                              isDerivedFrom(
                                                                 SameName(
                                                                    SameType(
                                                                       recordDecl(
                                                                          has(
                                                                            fieldDecl()
                                                                          )
                                                                        )
                                                                    )
                                                                 )
                                                              )
                                                           );
The problem is that when i compile i get the following errors:
clang++ -I/usr/local/include  -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -Woverloaded-virtual -Wcast-qual -fno-rtti   -c -o IHD_operator.o IHD_operator.cpp
IHD_operator.cpp:83:6: error: no matching function for call to 'SameType'
                                        SameType(
                                        ^~~~~~~~
IHD_operator.cpp:39:28: note: candidate function not viable: no known conversion from 'clang::ast_matchers::internal::BindableMatcher<clang::Decl>' to
      'const clang::FieldDecl' for 1st argument
                AST_MATCHER_P(FieldDecl, SameType, FieldDecl, f)
                                         ^
/usr/local/include/clang/ASTMatchers/ASTMatchersMacros.h:86:32: note: expanded from macro 'AST_MATCHER_P'
  AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, 0)
                               ^
/usr/local/include/clang/ASTMatchers/ASTMatchersMacros.h:104:34: note: expanded from macro 'AST_MATCHER_P_OVERLOAD'
  inline internal::Matcher<Type> DefineMatcher(const ParamType &Param) {       \
                                 ^
1 error generated.
make: *** [IHD_operator.o] Error 1
I don't know why is trying to make a conversion to FieldDecl from Decl if it is supose to be receiving a FieldDecl type param.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130924/4594085b/attachment.html>


More information about the cfe-dev mailing list