[cfe-dev] create not a member of clang::ast_type_traits::DynTypedNode::BaseConverter<const clang::Stmt**, void>

Farzad Sadeghi via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 24 06:33:14 PDT 2016


Hi,
Before we begin, I'm fairly new to both llvm and C++ so sorry if the
question is really
simple or something along the same lines.
I'm trying to get the parents of a node I got off of a node matched by
`ASTMatcher`(I need the parent info for further processing). Basically
what I'm doing is I'm getting the context and then according to the
docs i should  call the `getParents` member function from `ASTContext`
to get the parent nodes. My original node is a `CallExpr` but i cast
it into a `Stmt` to be able to use the `getParents` on it. Heere's
what my code looks like:

    if (CResult.Nodes.getNodeAs<clang::CallExpr>("allcalls") != nullptr)
    {
      const CallExpr *CallRes =
CResult.Nodes.getNodeAs<clang::CallExpr>("allcalls");

      const Stmt *CallResStmt =
CResult.Nodes.getNodeAs<clang::Stmt>("allcalls");

      ASTContext *const CallContext = CResult.Context;

      ASTContext::DynTypedNodeList Nodelist =
CallContext->ASTContext::getParents(&CallResStmt);
    }

when i try to build it, though I get this:

    In file included from /usr/local/include/clang/AST/ASTContext.h:18:0,
                     from /usr/local/include/clang/AST/AST.h:18,
                     from tokenizer.cpp:11:
    /usr/local/include/clang/AST/ASTTypeTraits.h: In instantiation of
‘static clang::ast_type_traits::DynTypedNode
clang::ast_type_traits::DynTypedNode::create(const T&) [with T = const
clang::Stmt**]’:
    /usr/local/include/clang/AST/ASTContext.h:541:60:   required from
‘clang::ASTContext::DynTypedNodeList
clang::ASTContext::getParents(const NodeT&) [with NodeT = const
clang::Stmt**]’
    tokenizer.cpp:477:95:   required from here
    /usr/local/include/clang/AST/ASTTypeTraits.h:215:36: error:
‘create’ is not a member of
‘clang::ast_type_traits::DynTypedNode::BaseConverter<const
clang::Stmt**, void>’
         return BaseConverter<T>::create(Node);

The part the error mentions is here in `ASTTypeTraits.h`:

    class DynTypedNode {
    public:
      /// \brief Creates a \c DynTypedNode from \c Node.
      template <typename T>
      static DynTypedNode create(const T &Node) {
        return BaseConverter<T>::create(Node);
      }

what am I doing wrong? should my `MatchCallback` inherit `create` from
another class or it's something else I've missed?
I'm using version 3.9.0svn which i built with g++ 5.3.1 . I use g++ to
compile the code too.

-- 
Farzad Sadeghi



More information about the cfe-dev mailing list