<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Ok, thanks. Now it compiles. However, I have the following code:<br><br>ArrayRef<ast_type_traits::DynTypedNode> pv = Context->getParents<MemberExpr>(*member);<br><br>size_t size = pv.size();<br> <br> if(size > 0){<br> llvm::outs() << "Size: " << size << "\n";<br> <br> for(auto it: pv)<br> llvm::outs() << "NodeKind: " << it.getNodeKind().asStringRef() << "\n";<br><br> if (const CXXMethodDecl* MD = (pv[size-1]).get<CXXMethodDecl>()) {<br> llvm::outs() << "A method\n";<br> }<br> }<br><br>And the output is:<br><br>Size: 1<br>NodeKind: ImplicitCastExprSize<br> <br> <br>Do you know why? I supposed it would be a CXXMethodDecl or a CXXRecordDecl. The code I'm using to check the program is just:<br><br>class A{<br> public:<br> int get_a(){ return a;}<br> private:<br> int a;<br>};<br><br><br><br><div><hr id="stopSpelling">From: klimek@google.com<br>Date: Tue, 23 Feb 2016 16:47:09 +0000<br>Subject: Re: [cfe-dev] How to use clang::ast_type_traits::DynTypedNode?<br>To: pedretti_86@hotmail.com; jonathan@codesourcery.com; cfe-dev@lists.llvm.org<br><br><div dir="ltr">Oh sorry, I didn't realize you actually have DynTypedNode. DynTypedNode has a get<T> method to retrieve a pointer to the underlying type.</div><br><div class="ecxgmail_quote"><div dir="ltr">On Tue, Feb 23, 2016 at 5:44 PM victor <<a href="mailto:pedretti_86@hotmail.com">pedretti_86@hotmail.com</a>> wrote:<br></div><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">
<div><div dir="ltr">Hi Jonathan,<br><br>Something is failing. I have this:</div></div><div><div dir="ltr"><br><br>ArrayRef<ast_type_traits::DynTypedNode> pv = Context->getParents<MemberExpr>(*member);<br><br></div></div><div><div dir="ltr">size_t size = pv.size();<br> <br>if(size > 0){</div></div><div><div dir="ltr"><br> if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {}<br>}<br><br></div></div><div><div dir="ltr">The compiler says:<br><br>/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<br> type 'const clang::ast_type_traits::DynTypedNode *'<br> return To::classof(&Val);<br> ^~~~<br><br><br><div></div></div></div><div><div dir="ltr"><div>> Subject: Re: [cfe-dev] How to use clang::ast_type_traits::DynTypedNode?<br></div></div></div><div><div dir="ltr"><div>> To: <a href="mailto:pedretti_86@hotmail.com" target="_blank">pedretti_86@hotmail.com</a>; <a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>; <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>> From: <a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>> Date: Tue, 23 Feb 2016 09:13:21 -0700</div></div></div><div><div dir="ltr"><div><br>> <br>> <br>> <br>> On 2/23/16 9:07 AM, victor via cfe-dev wrote:<br>> > Thanks for answering, Manuel.<br>> ><br>> > However, your code didn't work:<br>> ><br>> > clases_file.cpp:35:22: error: variable 'MD' with type 'const auto *'<br>> > has incompatible initializer of type 'const clang::CXXMethodDecl'<br>> > if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(pv[size-1])) {<br>> ><br>> > ^<br>> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>> <br>> You need to take the address of it as dyn_cast works on pointers, not <br>> references:<br>> <br>> if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {<br>> <br>> <br>> Jon<br>> <br>> -- <br>> Jon Roelofs<br>> <a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>> CodeSourcery / Mentor Embedded<br></div></div></div></blockquote></div></div> </div></body>
</html>