<html><head></head><body class="ApplePlainTextBody" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">On 1 Aug 2012, at 14:44, Nick Beer wrote:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">Consider the following code: <br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">#include <stddef.h> <br></blockquote><blockquote type="cite">void foo() { <br></blockquote><blockquote type="cite"> size_t a; <br></blockquote><blockquote type="cite">} <br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">If I were to get the FunctionDecl cursor and then visit its children, I<br></blockquote><blockquote type="cite">would get the following tree:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">FunctionDecl <br></blockquote><blockquote type="cite">CompoundStmt <br></blockquote><blockquote type="cite"> DeclStmt <br></blockquote><blockquote type="cite"> VarDecl <br></blockquote><blockquote type="cite"> TypeRef <br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">What I really want is to be able to walk up the tree, instead of only down. <br></blockquote><br>I'm afraid I'm stumped. My suggestion of using<br>clang_getCursor{Lexical,Semantic}Parent won't work. With the example<br>code you gave, each cursor's parents are: (Lexical Parent, Semantic<br>Parent)<br><br>FunctionDecl [TranslationUnit, TranslationUnit]<br> CompoundStmt [None, FunctionDecl]<br> DeclStmt [None, None]<br> VarDecl [FunctionDecl, FunctionDecl]<br> TypeRef [None, None]<br><br>I don't really know the AST API, so I can't say whether the above parent<br>values are correct or a bug. My (naive) expectation was that the lexical<br>parent was always the cursor immediately preceding in that hierarchy,<br>but maybe there's a reason it isn't so.<br><br>Cheers,<br>Dave.<br><br></body></html>