[cfe-dev] Return type of statement

Chris Lattner clattner at apple.com
Mon Jan 5 18:22:01 PST 2009


On Jan 5, 2009, at 6:10 PM, Ted Kremenek wrote:

> Alexei,
>
> Statements that evalute to a value are known as expressions.
> Expressions are represented by the Expr class (which subclasses
> Stmt).  The method Expr::getType() will return the information you
> want.  I recommend looking at the Clang sources for example uses of
> this method.

Try something like:

Stmt *S = ...

if (Expr *E = dyn_cast<Expr>(S))
   if (E->getType() == ... )
     ...

If something is a statement but not an expr, it doesn't produce a  
value (things like "if" or "break").

-Chris

>
>
> On Jan 5, 2009, at 5:43 PM, Alexei Svitkine
> <alexei.svitkine at gmail.com> wrote:
>
>> I am starting a project that will use clang. I'm asking to be pointed
>> in the right direction with a question I have. Here goes.
>>
>> Given a context (ie a source file) and a statement somewhere in that
>> file, what's the easiest way to find the return type of that  
>> statement
>> with clang?
>>
>> For example, for an assignment, it's the type of the variable, for a
>> function call, it's the return type, but obviously there are more
>> complicated examples in C semantics.
>>
>> Surely, clang must be aware of this information, so what's the  
>> easiest
>> way to get at it (using code)?
>>
>> -Alexei Svitkine
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list