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)
57 string name
= ((ReferenceExpression
) condition
).Name
.Substring(1);
58 condition
= new MethodInvocationExpression(
59 new MemberReferenceExpression(new SuperLiteralExpression(), "TryGetParameter"),
60 new StringLiteralExpression(name
)
63 MemberReferenceExpression isNull
=
64 new MemberReferenceExpression(condition
, "_IsIgnoreNullReferencingNotNullObject_");
69 private static bool IsTryGetParameterInvocation(Expression condition
)
71 ReferenceExpression expression
= condition
as ReferenceExpression
;
72 if (expression
== null)
75 return expression
.Name
.StartsWith("?");