AST-dump

Hi,

Default, copy, and move constructors are provided implicitly (under various conditions - obviously if you have members that aren’t default, copy, or move constructible, you might not/cannot get all of those)

Ok, but this keeps giving me trouble. I’ve used the isImplicit() matcher to avoid those implicit constructors, but it isn’t working how I need yet.

recordDecl(
unless(hasMethod(constructorDecl(
allOf(hasAnyParameter(anything()), unless(isImplicit()))

I know I shouldn’t use the -ast-dump-xml option, but look at this. If I have a class like this:

class E{
public:
E(){int a = 3;};
int e;
};

This is the dump of the constructor:

CompoundStmt 0xd7d81a8 <./ABC.h:4:6, col:17> `-DeclStmt 0xd7d8198 `-VarDecl 0xd7d8150 a 'int' `-IntegerLiteral 0xd7d8180 'int' 3

And this case is working fine. But when the class is this other way:

class E{
public:
E();
int e;
};

E::E(){
int a = 3;
}

The dump creates two CXXConstructors, I suppose one for the declaration and the other for the definition:

CompoundStmt 0xc7de378 <./ABC.h:8:7, line:10:1> `-DeclStmt 0xc7de368 `-VarDecl 0xc7de320 a 'int' `-IntegerLiteral 0xc7de350 'int' 3

And this is the case my matcher is not retrieving the class E. I don’t know if clang it’s considering that first CxxConstructor as implicit… The only difference I can see is the “used” attribute. I’ve tried creating a simple matcher to use the isUsed() method of Decl class:

namespace clang{
namespace ast_matchers{
AST_MATCHER(Decl, isUsed)
{
return Node.isUsed();
}
}
}

but, this is having no influence.

Maybe, I’m ignoring something.

Thanks,

Pedro.

El dia 28 may 2013 18:18, David Blaikie dblaikie@gmail.com escribió:

Well, try filtering out declarations that are not first declarations - it looks to me that would solve your issue.
I think you’ll need to create a new matcher for this. In fact, this might be useful to implement generally and contribute to Clang. I believe there is a base class for redeclarable AST nodes, but can’t remember the exact name - you should use that for your matcher.

Hi,

Default, copy, and move constructors are provided implicitly (under
various conditions - obviously if you have members that aren't default,
copy, or move constructible, you might not/cannot get all of those)

Ok, but this keeps giving me trouble. I've used the isImplicit() matcher
to avoid those implicit constructors, but it isn't working how I need yet.

recordDecl(
    unless(hasMethod(constructorDecl(
                allOf(hasAnyParameter(anything()), unless(isImplicit()))

I know I shouldn't use the -ast-dump-xml option, but look at this. If I
have a class like this:

class E{
    public:
        E(){int a = 3;};
        int e;
};

This is the dump of the constructor:

<CXXConstructor used="1" ptr="0xd7d8070" name="E" prototype="true">
   <FunctionProtoType ptr="0xd7d8040" canonical="0xd7d8040">
    <BuiltinType ptr="0xd7d7c30" canonical="0xd7d7c30"/>
    <parameters/>
   </FunctionProtoType>
   <Stmt>
CompoundStmt 0xd7d81a8 <./ABC.h:4:6, col:17>
`-DeclStmt 0xd7d8198 <col:7, col:16>
  `-VarDecl 0xd7d8150 <col:7, col:15> a 'int'
    `-IntegerLiteral 0xd7d8180 <col:15> 'int' 3

   </Stmt>
  </CXXConstructor>

And this case is working fine. But when the class is this other way:

class E{
    public:
        E();
        int e;
};

E::E(){
   int a = 3;
}

The dump creates two CXXConstructors, I suppose one for the declaration
and the other for the definition:

<CXXConstructor ptr="0xc7de070" name="E" prototype="true">
   <FunctionProtoType ptr="0xc7de040" canonical="0xc7de040">
    <BuiltinType ptr="0xc7ddc30" canonical="0xc7ddc30"/>
    <parameters/>
   </FunctionProtoType>
  </CXXConstructor>

....

<CXXConstructor used="1" ptr="0xc7de270" name="E" previous="0xc7de070"
prototype="true">
  <FunctionProtoType ptr="0xc7de040" canonical="0xc7de040">
   <BuiltinType ptr="0xc7ddc30" canonical="0xc7ddc30"/>
   <parameters/>
  </FunctionProtoType>
  <Stmt>
CompoundStmt 0xc7de378 <./ABC.h:8:7, line:10:1>
`-DeclStmt 0xc7de368 <line:9:2, col:11>
  `-VarDecl 0xc7de320 <col:2, col:10> a 'int'
    `-IntegerLiteral 0xc7de350 <col:10> 'int' 3

  </Stmt>
</CXXConstructor>

And this is the case my matcher is not retrieving the class E.

FYI, the matcher you proposed above works fine in that example for me (I
get a match on "::E").