<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Yes those lines represent nodes. You do not necessarily need ASTContext to look at a node’s descendants: you can just use the node’s methods. </div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Were these sugar (= syntax-only) type nodes, you could iterate over the child of each successive node via `desugar()`, and successively desugar while searching for a Type subclass T via `getAs<T>()`. </div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">But pointee types/array element types are of course not sugar: they are distinct semantic entities, so desugar/getAs won’t will not pass through them. Hence your problem.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Fortunately there seems to be a `getPointeeOrArrayElementType()` to help peel off the semantic layers you want to look through, analogous to `desugar()` — but unfortunately there is not a `getAs` analog for this case, so you have to write the search manually. </div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Something like this should work (not tested):</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">```</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class="">PointerType *getInnermostPointerType(const Type *T) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> const PointerType *res = nullptr;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> while (true) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> const Type *pointeeOrElement = T->getPointeeOrArrayElementType();</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> if (pointeeOrElement == T)</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> // T is neither a pointer nor array type: we’re done.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> break;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> // T is a pointer or array type.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> if (isa<PointerType>(T)) </div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> res = cast<PointerType>(T);</div><p style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; min-height: 14px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> // iterate T, keep looking</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> T = pointeeOrElement;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""> return res;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">```</div><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 30, 2020, at 2:12 PM, Pratyush Das via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi,<div class=""><br class=""></div><div class="">If I dump() a clang::Type object, I can see this AST representation - </div><div class=""><br class=""></div><div class=""><font face="monospace" class="">ConstantArrayType 0x555562830ea0 'const char **const [0]' 0 <br class="">`-QualType 0x555562830c81 'const char **const' const<br class=""> `-PointerType 0x555562830c80 'const char **'<br class=""> `-PointerType 0x5555627ed2a0 'const char *'<br class=""> `-QualType 0x5555627ec7d1 'const char' const<br class=""> `-BuiltinType 0x5555627ec7d0 'char'</font></div><div class=""><br class=""></div><div class=""><div class="">Is there a way to use the ASTContext to iterate over each node? (Do each of those lines represent a node?)</div><div class=""><br class=""></div><div class="">My motivation is to get the inner most PointerType object.</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">Pratyush Das<br class=""></div></div></div></div></div></div></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>