[cfe-dev] [PATCH] add constant expression evaluation to the AST and fix PR2413

Argiris Kirtzidis akyrtzi at gmail.com
Sat Jun 14 13:15:53 PDT 2008

Hi Eli,

Eli Friedman wrote:
> On Sun, Jun 8, 2008 at 7:05 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> Attached patch adds some capability to the AST to evaluate constant
>> expressions more general than integer constant expressions.  It then
>> uses that capability to remove the hack added for
>> Sema/darwin-align-cast.c, which fixes PR2413.

Having a general way to evaluate constant expressions is a great idea 
and very useful for consumers.
However, having


doesn't seem to me that it "scales" well. There's going to be a lot of 
code duplication between all those functions and there isn't a way for 
the consumer to do action based on the type of the constant:

if (expr is integer)
else if (expr is float)

How about having a single "EvaluateConstantExpr" method, that accepts a 
structure that can hold all the possible values in a union (APSInt, 
APFloat, etc.) plus an enum that can indicate what is the type of the 
value returned (vt_int, vt_float, vt_complex, etc) ?

To indicate a non constant expression, it could return a vt_notConstant 
enum, or it could be implemented as "TryEvaluateConstantExpr" and return 
false in that case.


More information about the cfe-dev mailing list