help: from Stmt object to Decl

Message: 1
Date: Wed, 28 Jan 2015 02:04:24 +0100
From: mobi phil <mobi@mobiphil.com>
To: ??? <wuming_81@163.com>
Cc: clang-list <cfe-dev@cs.uiuc.edu>
Subject: Re: [cfe-dev] help: from Stmt object to Decl
Message-ID:
<CAGMoNKt2tGEjtycqKPd=cAyMLJXDfZXw=xwRCk6csM5YrsnhPQ@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

i.e how could I get the FunctionDecl object ?

though not sure exactly what you would like to do, and what do you mean you
get the BinaryOperator here is a hint based on my "poor" experience. There
are to ways to find objects in AST:
-> using the visitor pattern
-> dynamic matchers. My favorite is to use the one based on matcher
strings.

For this one you may use the clang-query tool or the tool I wrote cmatch (
https://github.com/mobiphil/cmatch), or look in the code how they query the
AST tree for certain types of nodes.

mobi phil, Thanks ! I will use VisitStmt.
But I have another question:
   How to get namespace name of a function ?
if this function is CXXMethodDecl, I use CXXRecordDecl to get a NamespaceDecl object, then I will get the namespace name.
if this function is a global function, I do not know howto.

mobi phil, Thanks ! I will use VisitStmt.

But I have another question:

   How to get namespace name of a function ?

if this function is CXXMethodDecl, I use CXXRecordDecl to get a NamespaceDecl object, then I will get the namespace name.

if this function is a global function, I do not know howto.

do not know at the moment, but general advice: play with the dynamic
matchers and the completion mechanism. That is how I learned a lot about
the relationship between objects (nodes) in the AST. There is not too much
documentation, but the clang-query or cmatch will tell you a lot about the
relationship between AST nodes.