<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Nov 30, 2015 at 12:48 PM, Daniel Dilts <span dir="ltr"><<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Mon, Nov 30, 2015 at 11:12 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Mon, Nov 30, 2015 at 10:51 AM, Daniel Dilts via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div>I tried this with:</div><div>auto t = type.getTypePtr();</div><div>auto tt = dyn_cast<TypedefType>(t);<br>while(tt) {</div><div>  tt->getDecl()->dumpColor();</div><div>  auto x = tt->getDecl()->getNameAsString();</div><div>  tt = dyn_cast<TypedefType>(tt->desugar().getTypePtr());</div><div>}</div><div><br></div><div>It appeared to work fine when the typedef was at global scope, but when I put the typedef in a namespace the first dyn_cast returned nullptr.</div></div></blockquote><div><br></div></span><div>Right, in that case you will have an ElaboratedType representing the nested name specifier written in the source, which desugars to the TypedefType. Clang has a very rich modeling of type sugar, and you should expect to see things other than TypedefTypes in your walk.</div><div><br></div><div>Depending on what you're trying to do, you might want to consider visiting the type with a RecursiveASTVisitor or repeatedly calling getSingleStepDesugaredType to walk the desugarings of the type, or changing your dyn_cast<TypedefType>(x) calls into x.getAs<TypedefType>() (which will find the minimally-desugared typedef type in the single-step desugaring sequence for x).<br></div></div></div></div></blockquote><div><br></div></span><div>I tried using getSingleStepDesugaredType with this code:</div><div>namespace Test<br>{<span class=""><br>   typedef int X;<br>   typedef X Y;<br>   typedef Y Z;<br>}</span></div><div>Test::Z i;</div><div><br></div><div><br></div><div>std::vector<std::string> names;<br>names.push_back(type.getAsString());<br>while(true)<br> {<br>  type = type.getSingleStepDesugaredType(*result.Context);<br>  names.push_back(type.getAsString());<br>}</div><div><br></div><div>getAsString() on the QualType returned this chain:</div><div>Test::Z</div><div>Z</div><div>Y</div><div>X</div><div>int</div><div><br></div><div>Ideally I would get this:</div><div>Test::Z</div><div>Test::Y</div><div>Test::X</div><div>int</div></div></div></div></blockquote><div><br></div><div>You could check if each type is a TypedefType, grab its TypedefNameDecl, and get the corresponding fully-qualified name. Clang's type sugar nodes track how the type was written, and that's what you're seeing above.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>How would I use a RecursiveASTVisitor to walk just the type?  I can figure it out for an entire AST.</div></div></div></div>
</blockquote></div><br></div><div class="gmail_extra">The same way, but start the recursion by calling TraverseType instead of TraverseDecl. Note that this will recursively visit all of the AST "owned" by that type, which may be more than you want.</div></div>