1 namespace Castle
.MonoRail
.Views
.Brail
3 using Boo
.Lang
.Compiler
.Ast
;
4 using Boo
.Lang
.Compiler
.Steps
;
7 /// We need to handle the following code:
11 /// However, because ?Op will return an IgnoreNull object, we can't just
12 /// use the default boo behavior, but need to fix it up
14 public class FixTryGetParameterConditionalChecks
: AbstractNamespaceSensitiveTransformerCompilerStep
16 public override void Run()
21 public override void OnBinaryExpression(BinaryExpression node
)
23 if(node
.Operator
!=BinaryOperatorType
.Equality
)
26 if(IsTryGetParameterInvocation(node
.Left
) ==false &&
27 IsTryGetParameterInvocation(node
.Right
) == false )
30 MethodInvocationExpression mie
= new MethodInvocationExpression();
31 ReferenceExpression expression
= AstUtil
.CreateReferenceExpression("Castle.MonoRail.Views.Brail.IgnoreNull.AreEqual");
32 mie
.Target
= expression
;
33 mie
.Arguments
.Add(node
.Left
);
34 mie
.Arguments
.Add(node
.Right
);
36 ReplaceCurrentNode(mie
);
40 public override void OnIfStatement(IfStatement node
)
42 base.OnIfStatement(node
);
43 node
.Condition
= FixCondition(node
.Condition
);
46 public override void OnUnlessStatement(UnlessStatement node
)
48 base.OnUnlessStatement(node
);
49 node
.Condition
= FixCondition(node
.Condition
);
52 private Expression
FixCondition(Expression condition
)
54 if (IsTryGetParameterInvocation(condition
) == false)
58 TypeofExpression typeofExpression
= new TypeofExpression();
59 typeofExpression
.Type
= CodeBuilder
.CreateTypeReference(typeof(IgnoreNull
));
61 BinaryExpression be
= new BinaryExpression(BinaryOperatorType
.TypeTest
, condition
,
64 return new UnaryExpression(UnaryOperatorType
.LogicalNot
, be
);
67 private static bool IsTryGetParameterInvocation(Expression condition
)
69 ReferenceExpression expression
= condition
as ReferenceExpression
;
70 if (expression
== null)
73 return expression
.Name
.StartsWith("?");