[cfe-dev] AST-dump
David Blaikie
dblaikie at gmail.com
Tue May 28 09:18:33 PDT 2013
On Tue, May 28, 2013 at 2:07 AM, Pedro Delgado Perez
<pedro.delgado at uca.es>wrote:
> That seems like an approach that works. I don't know that there's a
> different common property. Why's the default constructor different from the
> copy constructor here?
>
> First of all, sorry but I made a mistake in the example:
>
> class A{
> 1. A(){...}
> 2. A(int a){...}
> 3. *A(const A& a){... ...}*
> };
>
> What I mean is that I need to find if there is at least one constructor
> that explicitly overloads the default constructor so that if I delete the
> default constructor the compiler won't provide the default constructor. So,
> my question was totally erroneous as the copy constructor does overload the
> default constructor if provided, but I don't want to take it into account
> if it wasn't explicitly provided.
>
> A better question is: which are the kind of constructors that the compiler
> provides if no constructors are explicitly supplied? Only the default and
> the copy constructor (in some situations)?
>
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)
> If "unless(allOf(... ...))" is the best solution, could someone enumerate
> the kind of constructors I must to indicate in that matcher?
>
> I'd suggest to not use ast-dump-xml any more. It's basically deprecated,
> and hopefully it'll be removed soon. -ast-dump gives you all the
> information (and more).
>
> Ok, I didn't know it.
>
> ... you can see that one is the default constructor and the other one is
> the copy constructor. If you just put "G g;" into the code instead of the
> second class, you'll also see that a simple use of G already triggers the
> copy constructor to appear. Others are probably better able to explain
> exactly when a copy constructor is created.
>
> Further information will be well received.
>
> Regards,
>
> Pedro.
> *El dia 27 may 2013 12:24, Manuel Klimek <klimek at google.com> escribió:*
>
> Hi Pedro,
> first, please always send those mails also to cfe-dev. There are people
> who are much more knowledgable about the AST on that list, and you'll often
> get better answers faster that way :)
> On Mon, May 27, 2013 at 10:00 AM, Pedro Delgado Perez <
> pedro.delgado at uca.es> wrote:
>
>> Sorry Manuel, but I prefer to ask you all the things I don't know before
>> you reply me:
>>
>> How do I know that a CXXConstructorDecl is a "simple" constructor of a
>> class. I mean, I want to find all the constructors in a class, but not the
>> copy, the move or things like this constructors. I'm not able to find this
>> in the documentation. To clarify this, I'm going to put an example:
>>
>> class A{
>> 1. A(){...}
>> 2. A(int a){...}
>> 3. A(const &a){... ...}
>> };
>>
>> I want to look only for 1 and 2 and not for 3 when I ask:
>> recordDecl(hasMethod(constructDecl(...)));
>>
>> What can I do? Do I have to write "unless(allOf(isCopyConstructor(),
>> isMoveConstructor()...))" for each type of existing constructors?
>>
> That seems like an approach that works. I don't know that there's a
> different common property. Why's the default constructor different from the
> copy constructor here?
>
>
>> Thanks,
>>
>> Pedro.
>>
>>
>>
>> Hi Manuel,
>>
>> I would like to ask you something about the AST built by Clang if you
>> don't mind. I've just have a look at your video of introduction to Clang
>> AST (By the way, nice tutorial!) and I think that you may have an answer
>> for my trouble.
>>
>> Look, I was trying to look for classes that had only the default
>> constructor through ASTMatchers. Well, I tested my matcher with the next
>> classes:
>>
>> class G{
>> public:
>> G():a(1){}
>> int a;
>> virtual int ma(int arg);
>> };
>>
>> class L: *public G*{
>> public:
>> L(){v = 1;}
>> int b;
>> int h;
>> virtual int ma(int arg);
>> private:
>> int v;
>> int f();
>> };
>>
>> My matcher only retrieved the class 'L' and not the 'G'. I was wondering
>> what would be the problem when I had a look to the ast-dump-xml option:
>>
>> I'd suggest to not use ast-dump-xml any more. It's basically deprecated,
> and hopefully it'll be removed soon. -ast-dump gives you all the
> information (and more).
>
>> <CXXRecord ptr="0xd695f30" name="G" typeptr="0xd695f80">
>> <CXXRecord ptr="0xd695fd0" name="G" typeptr="0xd695f80"/>
>> <AccessSpec ptr="0xd696020" access="public"/>
>> *<CXXConstructor* used="1" ptr="0xd696080" name="G" prototype="true">
>> <FunctionProtoType ptr="0xd696050" canonical="0xd696050">
>> <BuiltinType ptr="0xd695c40" canonical="0xd695c40"/>
>> <parameters/>
>> </FunctionProtoType>
>> <Stmt>
>> CompoundStmt 0xd696450 <tst.cpp:7:10, col:11>
>> </Stmt>
>> </CXXConstructor>
>>
>> ....
>>
>> *<CXXConstructor* ptr="0xd6aefc0" name="G" prototype="true"
>> inline="true">
>> <FunctionProtoType ptr="0xd6af050" canonical="0xd6af030"
>> exception_spec="unevaluated">
>> <BuiltinType ptr="0xd695c40" canonical="0xd695c40"/>
>> <parameters>
>> <LValueReferenceType ptr="0xd696240" canonical="0xd696240">
>> <QualType const="true">
>> <RecordType ptr="0xd695f80" canonical="0xd695f80">
>> <CXXRecord ref="0xd695f30"/>
>> </RecordType>
>> </QualType>
>> </LValueReferenceType>
>> </parameters>
>> </FunctionProtoType>
>> <ParmVar ptr="0xd6af070" name="" initstyle="c">
>> <LValueReferenceType ptr="0xd696240" canonical="0xd696240">
>> <QualType const="true">
>> <RecordType ptr="0xd695f80" canonical="0xd695f80">
>> <CXXRecord ref="0xd695f30"/>
>> </RecordType>
>> </QualType>
>> </LValueReferenceType>
>> </ParmVar>
>> </CXXConstructor>
>> </CXXRecord>
>>
>> Why class 'G' has two constructors? If I change the test program in order
>> that class 'L' doesn't inherits from class 'G', this doesn't happen (class
>> 'G' only has one constructor in the ast-dump-xml) Could you lend me a hand?
>>
>> If you look at -ast-dump:
> $ clang -cc1 -ast-dump t4.cc
> <snip>
> |-CXXRecordDecl 0x37faf80 <t4.cc:1:1, line:6:1> class G
> <snip>
> | |-CXXConstructorDecl 0x37fb1c0 <line:3:3, col:15> G 'void (void)'
> | | |-CXXCtorInitializer Field 0x37fb290 'a' 'int'
> | | | |-IntegerLiteral 0x382d018 <col:11> 'int' 1
> | | `-CompoundStmt 0x382d0a0 <col:14, col:15>
> <snip>
> | `-CXXConstructorDecl 0x382da70 <col:7> G 'void (const class G &)' inline
> | `-ParmVarDecl 0x382f820 <col:7> 'const class G &'
> <snip>
> ... you can see that one is the default constructor and the other one is
> the copy constructor. If you just put "G g;" into the code instead of the
> second class, you'll also see that a simple use of G already triggers the
> copy constructor to appear. Others are probably better able to explain
> exactly when a copy constructor is created.
> cheers,
> /Manuel
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> 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/20130528/6c85224b/attachment.html>
More information about the cfe-dev
mailing list