But why the source location for the first initializer is completely messed up? I've just tried to dump the construct xml using clang -dump-ast-xml, and that's what I've got:<div><br></div><div><div><CXXConstructor ptr="0x4c664c0" name="Plane" previous="0x4c65000" prototype="true"></div>
<div> <FunctionProtoType ptr="0x4c64ae0" canonical="0x4c64ae0"></div><div> <BuiltinType ptr="0x4c254a0" canonical="0x4c254a0"/></div><div> <parameters></div><div>
<LValueReferenceType ptr="0x4c5df40" canonical="0x4c5df40"></div><div> <QualType const="true"></div><div> <RecordType ptr="0x4c5d820" canonical="0x4c5d820"></div>
<div> <CXXRecord ref="0x4c5d790"/></div><div> </RecordType></div><div> </QualType></div><div> </LValueReferenceType></div><div> <BuiltinType ptr="0x4c25640" canonical="0x4c25640"/></div>
<div> </parameters></div><div> </FunctionProtoType></div><div> <ParmVar ptr="0x4c66270" name="normal" initstyle="c"></div><div> <LValueReferenceType ptr="0x4c5df40" canonical="0x4c5df40"></div>
<div> <QualType const="true"></div><div> <RecordType ptr="0x4c5d820" canonical="0x4c5d820"></div><div> <CXXRecord ref="0x4c5d790"/></div><div> </RecordType></div>
<div> </QualType></div><div> </LValueReferenceType></div><div> </ParmVar></div><div> <ParmVar ptr="0x4c662e0" name="d" initstyle="c"></div><div> <BuiltinType ptr="0x4c25640" canonical="0x4c25640"/></div>
<div> </ParmVar></div><div> <Stmt></div><div>(CompoundStmt 0x4c666d8 <Plane.cpp:27:55, line:29:1>)</div><div><br></div><div> </Stmt></div><div> </CXXConstructor></div><div><br></div><div>for the folowing constructor:</div>
<div><br></div><div><div>Plane::Plane (const Vector3& normal, float d) : d(d) {</div><div> this->normal.set(normal).nor();</div><div>}</div></div><div><br></div><div>Somehow I'm not being able to recover the initializer list, nor the correct SourceLocation for it.</div>
<div><br></div><div><br></div><div>Victor</div><div><br><div class="gmail_quote">2012/8/19 Philip Craig <span dir="ltr"><<a href="mailto:philipjcraig@gmail.com" target="_blank">philipjcraig@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Aug 20, 2012 at 2:10 AM, James Dennett <<a href="mailto:james.dennett@gmail.com">james.dennett@gmail.com</a>> wrote:<br>
> On Sun, Aug 19, 2012 at 12:15 AM, Philip Craig <<a href="mailto:philipjcraig@gmail.com">philipjcraig@gmail.com</a>> wrote:<br>
>> On Sun, Aug 19, 2012 at 1:52 PM, Victor Vicente de Carvalho<br>
>> <<a href="mailto:victor.v.carvalho@gmail.com">victor.v.carvalho@gmail.com</a>> wrote:<br>
>>> Hi Manuel,<br>
>>><br>
>>> my rewrite basing only in source replacements is complete, but now I'm<br>
>>> facing some strange side effects on some files. Consider the example:<br>
>>><br>
>>> header ----------<br>
>>><br>
>>> #include <B.h> // B defines a simple class named B<br>
>>><br>
>>> class A {<br>
>>> public:<br>
>>> A();<br>
>>><br>
>>> float x;<br>
>>> B b;<br>
>>> };<br>
>>><br>
>>> source ---------------<br>
>>><br>
>>> A::A() : x(0) {<br>
>>> }<br>
>>><br>
>>><br>
>>> the strange behavior that I'm having is that if in the header file "x" is<br>
>>> declared before "b", when processing the source location for the initializer<br>
>>> list on CXXConstructorDecl*, the source location for it get's completely<br>
>>> wrong pointing to right before the constructor name: "A::". If i declare "b"<br>
>>> before "x" then the source location points to "A::A() : " which was<br>
>>> expected. Also, the method getNumCtorInitializers on this declaration is<br>
>>> returning to me 2 ( should be 1 as only x is being initialized ), but if<br>
>>> decide to initialize b I'm __still__ getting 2. Also, node that the class<br>
>>> I'm parsing does not have a base class, and I'm providing the correct<br>
>>> includes as the tool run fine and exits returning 0. I'm a bit lost here,<br>
>>> any comments are welcome. I could upload on gist the current tool source,<br>
>>> cmake and sample code I'm using to test it if someone is willing to try.<br>
>>><br>
>>> I've also tried to dump the ast and verify it but the initalizer list is not<br>
>>> showing up so I don't know what might be happening.<br>
>><br>
>> The AST for the constructor looks like this:<br>
>><br>
>> CXXConstructorDecl <A.cc:2:1-3:1><br>
>> NestedNameSpecifier <2:1-2> A::<br>
>> RecordType <2:1><br>
>> DeclarationName <2:4> A<br>
>> FunctionProtoType <-6><br>
>> BuiltinType void <><br>
>> CXXCtorInitializer <2:10-13><br>
>> FieldDeclRef <2:10> A::x<br>
>> ImplicitCastExpr <2:12><br>
>> IntegerLiteral <2:12> 0<br>
>> CXXCtorInitializer <2:4><br>
>> FieldDeclRef <2:4> A::b<br>
>> CompoundStmt <2:15-3:1><br>
>><br>
>> Reversing the order of x and b just reverses the order of the two<br>
>> CXXCtorInitializer in the AST.<br>
>><br>
>> So it looks like clang always creates implicit initializers for<br>
>> members that aren't explicitly initialized, but it has no way of<br>
>> flagging them as implicit. I don't know the expected way of<br>
>> determining which are implicit, maybe checking for a NULL getInit().<br>
><br>
> CXXCtorInitializer::isWritten "Returns true if this initializer is<br>
> explicitly written in the source code."<br>
<br>
</div></div>Thanks, I missed that. I see RecursiveASTVisitor is already checking<br>
that, but only to skip over getInit(). Would it make sense for RAV to<br>
skip over the CXXCtorInitializer completely unless<br>
shouldVisitImplicitCode() is true?<br>
</blockquote></div><br></div></div>