[cfe-dev] How to use clang::ast_type_traits::DynTypedNode?

victor via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 24 02:27:05 PST 2016


Hi again,

I think I have understood that I have to contiunue using "getParents" in a loop until reaching the outermost parent. Something like:

while ( the current node has parents){
    current node =  parent of the current node
}

Then, I have tried to translate this into code:

ArrayRef<ast_type_traits::DynTypedNode> pv = Context->getParents<MemberExpr>(*member);

while ( (
               Context->getParents<(&pv[0])->getNodeKind()>((&p[0)->get<(&pv[0])->getNodeKind()>()
            ).size() > 0){
       pv = Context->getParents<(&pv[0])->getNodeKind()>((&p[0)->get<(&pv[0])->getNodeKind()>();
}

The problem here is:

error: no matching member function for call to 'get'
                                        ((&pv[size-1])->get<(&pv[size-1])->getNodeKind()>());
                                         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm-3.6/include/clang/AST/ASTTypeTraits.h:222:12: note: candidate template ignored: invalid explicitly-specified argument for
      template parameter 'T'
  const T *get() const {


How can I indicate the kind of node to "get"?

Thanks.

From: klimek at google.com
Date: Tue, 23 Feb 2016 16:47:09 +0000
Subject: Re: [cfe-dev] How to use clang::ast_type_traits::DynTypedNode?
To: pedretti_86 at hotmail.com; jonathan at codesourcery.com; cfe-dev at lists.llvm.org

Oh sorry, I didn't realize you actually have DynTypedNode. DynTypedNode has a get<T> method to retrieve a pointer to the underlying type.
On Tue, Feb 23, 2016 at 5:44 PM victor <pedretti_86 at hotmail.com> wrote:



Hi Jonathan,

Something is failing. I have this:

ArrayRef<ast_type_traits::DynTypedNode> pv = Context->getParents<MemberExpr>(*member);

size_t size = pv.size();
                
if(size > 0){
     if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {}
}

The compiler says:

/usr/lib/llvm-3.6/include/llvm/Support/Casting.h:56:24: error: cannot initialize a parameter of type 'const clang::Decl *' with an rvalue of
      type 'const clang::ast_type_traits::DynTypedNode *'
    return To::classof(&Val);
                       ^~~~


> Subject: Re: [cfe-dev] How to use clang::ast_type_traits::DynTypedNode?
> To: pedretti_86 at hotmail.com; klimek at google.com; cfe-dev at lists.llvm.org
> From: jonathan at codesourcery.com
> Date: Tue, 23 Feb 2016 09:13:21 -0700
> 
> 
> 
> On 2/23/16 9:07 AM, victor via cfe-dev wrote:
> > Thanks for answering, Manuel.
> >
> > However, your code didn't work:
> >
> >     clases_file.cpp:35:22: error: variable 'MD' with type 'const auto *'
> >     has incompatible initializer of type 'const clang::CXXMethodDecl'
> >     if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(pv[size-1])) {
> >
> >                                  ^
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> You need to take the address of it as dyn_cast works on pointers, not 
> references:
> 
>    if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {
> 
> 
> Jon
> 
> -- 
> Jon Roelofs
> jonathan at codesourcery.com
> CodeSourcery / Mentor Embedded
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160224/0bfcba92/attachment.html>


More information about the cfe-dev mailing list