[cfe-dev] Problem using ast matchers macros

Gabor Kozar kozargabor at gmail.com
Tue Sep 24 14:52:00 PDT 2013


Actually, the problem is that you're passing a matcher as argument,
while you've defined your matchers to accept FieldDecl (the 3rd
argument for the AST_MATCHER_P macro) - but the compiler already told
you this.



So I don't really see what you're confused about. For that matter, nor
can I really tell what you're trying to do in your matcher
expression... What is it that you're trying to express here?



--
Gábor Kozár -- ShdNx
kozargabor at gmail.com





On Tue, Sep 24, 2013, at 17:02, Vane, Edwin wrote:

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.

_______________________________________________

cfe-dev mailing list

[1]cfe-dev at cs.uiuc.edu

[2]http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

References

1. mailto:cfe-dev at cs.uiuc.edu
2. http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130924/5365ccdd/attachment.html>


More information about the cfe-dev mailing list