visiting complex<> declarations

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

visiting complex<> declarations

suppamax
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?
Reply | Threaded
Open this post in threaded view
|

Re: visiting complex<> declarations

John McCall
On Feb 20, 2013, at 12:38 PM, suppamax <[hidden email]> wrote:

> 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.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: visiting complex<> declarations

suppamax
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?
Reply | Threaded
Open this post in threaded view
|

Re: visiting complex<> declarations

Vassil Vassilev-2
Hi,
  Maybe you should override shouldVisitTemplateInstantiations.
Vassil
On 2/23/13 1:57 PM, suppamax wrote:
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?




--
View this message in context: http://clang-developers.42468.n3.nabble.com/visiting-complex-declarations-tp4030532p4030596.html
Sent from the Clang Developers mailing list archive at Nabble.com.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: visiting complex<> declarations

suppamax
I tried also overriding shouldVisitTemplateInstantiations, but nothing happened