<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Mar 21, 2013 at 9:39 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div class="h5">On Thu, Mar 21, 2013 at 12:27 PM, Abir Basak <span dir="ltr"><<a href="mailto:abirbasak@gmail.com" target="_blank">abirbasak@gmail.com</a>></span> wrote:<br>
</div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br clear="all"><div><div style="font-size:13px;font-family:arial,sans-serif">
I am new to clang AST. I am trying to write a program which rewrites all locations in a TU where template alias are used.</div>
<div style="font-size:13px;font-family:arial,sans-serif"><br></div><div style="font-size:13px;font-family:arial,sans-serif">say, given</div><div style="font-size:13px;font-family:arial,sans-serif">
<br></div><div style="font-size:13px;font-family:arial,sans-serif">1. template<class T,class U = T></div><div style="font-size:13px;font-family:arial,sans-serif">2. class class_1{};</div>
<div style="font-size:13px;font-family:arial,sans-serif">3. template<class U></div><div style="font-size:13px;font-family:arial,sans-serif">4. using alias1 = class_1<U>; </div>
<div style="font-size:13px;font-family:arial,sans-serif"><div>5. template<class T,class U></div><div>6. using alias2 = class_1<T,U>; </div><div>7.</div><div>8. template<class X,class Y = alias1<X> ></div>
<div>9. void foo(...)</div><div>10. {</div><div>11. alias2<int,X> x = ...; <br>12. }</div><div><br></div><div>I am interested to transform all references to template alias to something like typename alias1<X>::type, typename alias2<int,X>::type x = ... etc, and may be optionally remove the 'typename' part if the resulting type is not dependent.</div>
<div>I am using C++ API with RAV, and presently can get all template alias decl using </div>Visit/Traverse TypeAliasTemplateDecl, but has no idea how to get all references to them, such as at line 8 & 11 , irrespective to their name.</div>
</div></div></blockquote><div><br></div></div></div><div>I have not dealt with template aliases yet, but I'd expect it pretty much to work like for any other type declaration:</div><div>In line (8) you have a TemplateTypeParmDecl whose getDefaultArgument will yield a type (not sure which one exactly, I expect something like TemplateSpecializationType), whose declaration will be the TypeAliasDecl.</div>
<div>In line (11) you have a declaration with the given type.</div><div><br></div><div>With RAV, you'll want to visit TypeLoc's and check that those type locs refer to your template alias decl.</div>
<div><br></div><div>Cheers,</div><div>/Manuel</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
<div dir="ltr"><div>
<div style="font-size:13px;font-family:arial,sans-serif"><br></div><div style="font-size:13px;font-family:arial,sans-serif">Any help will be appreciated. </div><div style="font-size:13px;font-family:arial,sans-serif">
Thank you.</div></div>
</div>
<br></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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></blockquote></div><br></div></div>
</blockquote></div>Thank you for the reply. It just worked with TypeLoc.</div><div class="gmail_extra">Now I have a separate problem.<br>How can I get function prototype portion of defaulted/deleted function? </div><div class="gmail_extra">
<br></div><div class="gmail_extra">Say given, a class x, I have a defaulted constructor</div><div class="gmail_extra"><br></div><div class="gmail_extra">class x<br>{</div><div class="gmail_extra"> inline x(x const& bla) noexcept = default</div>
<div class="gmail_extra">};<br clear="all"><div style>I am interested to get source for the function just before = sign, so that i can translate it to</div><div style> inline x(x const& bla) noexcept<br></div><div style>
{</div><div style> }</div><div style>preferably keeping indentation correct.</div><div style><br></div><div style>Thank you</div><div style><br></div>
</div></div>