visiting complex<> declarations

Hi all,

I am trying to get familiar with clang's AST.

I want to parse some code that includes statements like

complex<double> c1(1.1, 3.6);
complex<double> c2(34.3, 8.7);
complex<double> c3;
c3 = c1 + c2;

In my ASTVisitor class I have

bool VisitVarDecl(VarDecl *v) {
  ...
  return true;
}

bool VisitBinaryOperator(BinaryOperator* bo) {
  ...
  return true;
}

These visiting functions work for floating point variables and arrays, but
they're not used when complex data are met.

Can you please help me clarifying?

The VarDecl visitor should certainly work. The BinaryOperator visitor
won't work because std::complex<T> is not a builtin type and its operators
are not builtin operators; you'll need to visit CXXOperatorCallExprs.

If this were the C99 _Complex T type, you'd still see BinaryOperator
expressions.

John.

I added

  bool VisitCXXOperatorCallExprs(CXXOperatorCallExpr *e) {
    llvm::errs() << "Visiting cxxoperatorcall" << "\n";
    return true;
  }

in
class MyASTVisitor : public RecursiveASTVisitor<MyASTVisitor>
but I don't see the desired print.
Also

  bool VisitVarDecl(VarDecl *v) {
    llvm::errs() << "Visiting declaration of variable " <<
v->getDeclName().getAsString() << "\n";
    return true;
  }

is inactive regarding complex<> variable declaration, while it works fine
for float variables.

Any other suggestion?

Hi,
   Maybe you should override shouldVisitTemplateInstantiations <http://clang.llvm.org/doxygen/classclang_1_1RecursiveASTVisitor.html#ab3f2f514d030ebfffe6742a66eb31363>.
Vassil

I tried also overriding shouldVisitTemplateInstantiations, but nothing
happened