[Mono-dev] Question about LiftedBinaryOperator in mcs source

Charles-Henri Gros charles-henri.gros at m4x.org
Fri Jan 11 18:49:41 UTC 2013


Hi,
I'm working on project that uses Mono as its C# parser. It uses the AST 
that comes from calling "Resolve".

I'm having trouble understanding what happens to LiftedBinaryOperator.

In particular, this code seems strange:

             if (left_orig is NullLiteral) {
                 left = right;

One of the effects of this assignment is that, if a user operator is 
involved, the corresponding UserOperatorCall will have "right" as both 
of its arguments.
If I replace the assignment with, say:
                 left = LiftedNull.Create (right.Type, left.Location);
I get parse errors.
It seems that at least one of the goals is to trigger a check for "left 
!= right".

Another mysterious thing I noticed is that, in the AST for code like:
int i;
int ?oi;

i + oi;

the AST is a LiftedBinaryOperator where "right" is an Unwrap with type 
int (this part I understand), while "left" is an EmptyCast with type 
"int?", which I find mysterious. It looks like the "EmitOperator" call 
casts it back to its original type:
             if (left.Type.IsNullableType) {
                 l = NullableInfo.GetUnderlyingType (left.Type);
                 left = EmptyCast.Create (left, l);
             }

It would be great if you could explains how all this works.

Thanks!

-- 
Charles-Henri Gros
Coverity, Inc.


More information about the Mono-devel-list mailing list