[cfe-dev] [PATCH] add constant expression evaluation to the AST and fix PR2413
akyrtzi at gmail.com
Sat Jun 14 16:13:40 PDT 2008
Eli Friedman wrote:
> On Sat, Jun 14, 2008 at 1:15 PM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
>> 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)
> That doesn't really end up being an issue, I don't think; an
> expression of type float can only have a constant of type float, same
> for complex float/int, same for pointer, (mostly) same for int. (The
> "mostly" comes from the fact that an int might actually be a pointer
> cast to an int; I'll probably end up sending this case through
> TryEvaluateExprPtr as a fallback.)
Hmm, I agree, this isn't much of an issue.
>> 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) ?
> I was considering that at first... it's a better approach in some
> ways, but there's an issue that completely kills this: you can't put
> an APSInt or APFloat into a union. Any suggestions?
Ah, that certainly kills it.
I'm convinced that the interface of the methods is the right one. Not a
major issue, but to avoid code repetition and make maintenance easier,
how about having the implementation of the methods use template
That way, for example, ParenExpr's evaluation, would be in one place
only since it's common for all evaluation methods.
More information about the cfe-dev