<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">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><div>I tried using getSingleStepDesugaredType with this code:</div><div>namespace Test<br>{<br>   typedef int X;<br>   typedef X Y;<br>   typedef Y Z;<br>}</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><br></div><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>