[cfe-dev] [PATCH] add constant expression evaluation to the AST and fix PR2413
Chris Lattner
clattner at apple.com
Sat Jun 21 16:11:15 PDT 2008
On Jun 14, 2008, at 4:13 PM, Argiris Kirtzidis wrote:
>> 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
> specializations ?
> That way, for example, ParenExpr's evaluation, would be in one place
> only since it's common for all evaluation methods.
How about a discriminated union, something like this:
class AnyValue {
enum { Undefined, Int, Float, ComplexInt, ComplexFloat } Kind;
void *Data[ sizeof(2*max(APInt, APFloat))/sizeof(void*)];
};
The default ctor would initialize the enum to undefined. When it
becomes one kind or another, placement new could be used to set up the
body, and the dtor could use placement destroy to destroy it (based on
the enum).
-Chris
More information about the cfe-dev
mailing list