Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / SimpleAST / ConditionExpression.cs
blob3ad685cd19aad0e99f6cac1258d6f163100048f7
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST
17 using System;
18 using System.Reflection.Emit;
19 using System.Collections;
21 /// <summary>
22 /// Summary description for ConditionExpression.
23 /// </summary>
24 [CLSCompliant(false)]
25 public class ConditionExpression : Expression
27 private OpCode _operation = OpCodes.Brfalse_S;
28 private ArrayList _trueStmts;
29 private ArrayList _falseStmts;
30 private Expression _left;
31 private Expression _right;
33 public ConditionExpression( Expression left ) : this(OpCodes.Brfalse_S, left)
37 public ConditionExpression( OpCode operation, Expression left ) : this(operation, left, null)
41 public ConditionExpression( OpCode operation, Expression left, Expression right )
43 _trueStmts = new ArrayList();
44 _falseStmts = new ArrayList();
46 _operation = operation;
47 _left = left;
48 _right = right;
51 public void AddTrueStatement( Statement stmt )
53 _trueStmts.Add( stmt );
56 public void AddFalseStatement( Statement stmt )
58 _falseStmts.Add( stmt );
61 public override void Emit(IEasyMember member, ILGenerator gen)
63 if (OpCodes.Brfalse.Equals(_operation) ||
64 OpCodes.Brfalse_S.Equals(_operation) ||
65 OpCodes.Brtrue.Equals(_operation) ||
66 OpCodes.Brtrue_S.Equals(_operation) )
68 // Unary operators
69 _left.Emit(member, gen);
71 else
73 // Binary operators
74 _left.Emit(member, gen);
75 _right.Emit(member, gen);
78 Label truePart = gen.DefineLabel();
79 Label exitPart = gen.DefineLabel();
81 gen.Emit(_operation, truePart);
83 if (_falseStmts.Count != 0)
85 foreach(Statement stmt in _falseStmts)
87 stmt.Emit(member, gen);
91 gen.Emit(OpCodes.Br_S, exitPart);
93 gen.MarkLabel(truePart);
94 if (_trueStmts.Count != 0)
96 foreach(Statement stmt in _trueStmts)
98 stmt.Emit(member, gen);
102 gen.MarkLabel(exitPart);