[cfe-dev] Problem using ast matchers macros

Daniel QuiƱones Lopez kaos09 at hotmail.com
Mon Sep 23 08:18:29 PDT 2013


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/20130923/8b1f5592/attachment.html>


More information about the cfe-dev mailing list