<div class="gmail_quote">2012/8/17 Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Fri, Aug 17, 2012 at 9:34 PM, Victor Vicente de Carvalho<br>
<<a href="mailto:victor.v.carvalho@gmail.com">victor.v.carvalho@gmail.com</a>> wrote:<br>
> Hello Manuel,<br>
><br>
> Sadly, no. I'm struggling with some problems now:<br>
><br>
> 1 - How do I detect and generate the class name for nested classes?  I'm<br>
> using  CXXConstructorDecl getNameAsString() but it only returns to me the<br>
> name of the enclosing class.<br>
<br>
</div>As Jends said, getQualifiedNameAsString.<br>
<div class="im"><br></div></blockquote><div><br></div><div>Thanks! It worked</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">

> 2 - I would like to not replace constructor initializers that were set up<br>
> with macros with their values:<br>
><br>
> #define MACRO 10<br>
><br>
> Class::Class() : myval(MACRO)<br>
><br>
> after I rewrite the outputted code is:<br>
><br>
> Class::Class() : mvyal(10)<br>
><br>
> Is there a way to avoid this? I've tried to use<br>
> Compiler.getPreprocessor().SetMacroExpansionOnlyInDirectives() but this<br>
> simply removes the myval definition from the generated AST<br>
<br>
</div>Source locations have the notion of an expansion and a spelling<br>
location. To get the code that was originally written, you'll need to<br>
fiddle around with those. In your case, MACRO is the expansion<br>
location of the literal 10.<br>
<div class="im"><br>
> 3 - Variables that are default initialized on the header are stored with it.<br>
> This is a problem as the compiler complains when I rewrite the source file<br>
> with the initialization on the source but it was previously defined on the<br>
> header. Is there to detect if the default initializer is on the method<br>
> definition or in the method declaration?<br>
<br>
</div>I would assume so - I don't where to look of the top of my head though.<br>
<div class="im"><br>
><br>
> 4 - I've found a bug on the DeclPrinter class, and fixed it. The attachment<br>
> is the patch.<br>
<br>
</div>I suggest you send an email to cfe-commits with the subject [PATCH]<br>
Fix problem with DeclPrinter, containing the patch and what was wrong<br>
(and ideally an automated regression test ;)<br>
<div class="im"><br>
><br>
> 5 - The current way i'm using to replace the old constructor declaration<br>
> with the new declaration is with a new range:<br>
><br>
> SourceRange rng(d->getSourceRange().getBegin(),<br>
> d->getBody()->getSourceRange().getBegin().getLocWithOffset(-1));<br>
><br>
> This was the only way I've managed to get the correct end of the end of the<br>
> initializer list. This is an inconvenience as I would like to not process<br>
> the body and hence make the tool faster, but if I disable body parsing I<br>
> can't get its SourceRange.<br>
<br>
</div>As far as I understand (and I might well be wrong there) skipping body<br>
parsing has some very concrete use cases, and source-to-source<br>
transformations is not on of them...<br>
<br>
Cheers,<br>
/Manuel<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>Manuel, I think I've been thinking the wrong way. As the only thing I need is to reorder the initialization, I do not need to mess with the original source like I was doing and just concatenate the reordered, original CXXCtorInitializer string data. So I've been wondering how I'm supposed to recover the source string based on a SourceLocation. Should I use SourceManager's getCharacterData? There is a way to recover the entire string based on a sourceRange?</div>
<div><br></div><div>Cheers,</div><div><br></div><div>Victor</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb">
<div class="h5">
><br>
><br>
> 2012/8/17 Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>><br>
>><br>
>> Hi Victor,<br>
>><br>
>> if I remember correctly we've been talking in IRC - have all your<br>
>> issues been resolved?<br>
>><br>
>> Cheers,<br>
>> /Manuel<br>
>><br>
>> On Thu, Aug 9, 2012 at 5:22 AM, Victor Vicente de Carvalho<br>
>> <<a href="mailto:victor.v.carvalho@gmail.com">victor.v.carvalho@gmail.com</a>> wrote:<br>
>> > Hello,<br>
>> ><br>
>> > In the past month I've been working in a clang tool to refactor the<br>
>> > fields<br>
>> > which are declared on a class constructor to match the order declared on<br>
>> > the<br>
>> > header file, hence resolving the annoying Wreorder warning. After a<br>
>> > series<br>
>> > of difficulties finally I have something that is close to the ideal, and<br>
>> > would like to someone more acquainted with clang internals to check if<br>
>> > it's<br>
>> > the best form to implement this.<br>
>> ><br>
>> > Also, I've got some problems that are still remaining:<br>
>> ><br>
>> > 1 - I've been following the samples I've managed to find through the<br>
>> > internet, but every time I try to run the tool using the following<br>
>> > command<br>
>> > line (I'm intentionally not providing any include paths as I don't want<br>
>> > to<br>
>> > std to be parsed):<br>
>> ><br>
>> > ../cpp-fixya <SOURCE.CPP>  --<br>
>> ><br>
>> > I get the following errros:<br>
>> ><br>
>> > <premain>: CommandLine Error: Argument 'version' defined more than once!<br>
>> > <premain>: CommandLine Error: Argument 'print-all-options' defined more<br>
>> > than<br>
>> > once!<br>
>> > <premain>: CommandLine Error: Argument 'print-options' defined more than<br>
>> > once!<br>
>> > <premain>: CommandLine Error: Argument 'help-hidden' defined more than<br>
>> > once!<br>
>> > <premain>: CommandLine Error: Argument 'help' defined more than once!<br>
>> > <premain>: CommandLine Error: Argument 'debug-only' defined more than<br>
>> > once!<br>
>> > <premain>: CommandLine Error: Argument 'debug-buffer-size' defined more<br>
>> > than<br>
>> > once!<br>
>> > <premain>: CommandLine Error: Argument 'debug' defined more than once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'version' defined more than once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'print-all-options' defined more<br>
>> > than<br>
>> > once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'print-options' defined more than<br>
>> > once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'help-hidden' defined more than<br>
>> > once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'help' defined more than once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'debug-only' defined more than<br>
>> > once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'debug-buffer-size' defined more<br>
>> > than<br>
>> > once!<br>
>> > cpp-fixya: CommandLine Error: Argument 'debug' defined more than once!<br>
>> ><br>
>> ><br>
>> > 2 - I haven't found a way to determine the class name for nested<br>
>> > classes.<br>
>> > How would be the best way to detect and generate the correct naming to a<br>
>> > nested class? I've been using:<br>
>> ><br>
>> > d->getNameAsString()<br>
>> ><br>
>> > but it only returns the enclosing class<br>
>> ><br>
>> ><br>
>> > 3 - How do I determine if a class declaration is on a header or a source<br>
>> > file? I mean that because if it's a source-only declaration (i.e.<br>
>> > private<br>
>> > classes) the c++ compiler wont accept constructors in the form:<br>
>> ><br>
>> > Constructor::Constructor()  : <init_declrs> {<br>
>> > }<br>
>> ><br>
>> > only in the form:<br>
>> ><br>
>> > Constructor()  : <init_declrs> {<br>
>> > }<br>
>> ><br>
>> ><br>
>> > Here is the code:<br>
>> ><br>
>> > <a href="https://gist.github.com/3300494" target="_blank">https://gist.github.com/3300494</a><br>
>> ><br>
>> ><br>
>> > Thanks in advance,<br>
>> ><br>
>> ><br>
>> > Victor<br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > cfe-dev mailing list<br>
>> > <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>