5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Reflection
;
34 using System
.Reflection
.Emit
;
36 namespace Microsoft
.JScript
{
38 public class Relational
: BinaryOp
{
40 internal Relational (AST parent
, AST left
, AST right
, JSToken op
)
41 : base (left
, right
, op
)
46 public Relational (int operatorTok
)
47 : base (null, null, (JSToken
) operatorTok
)
51 public double EvaluateRelational (object v1
, object v2
)
57 public static double JScriptCompare (object v1
, object v2
)
59 throw new NotImplementedException ();
62 public override string ToString ()
64 StringBuilder sb
= new StringBuilder ();
66 sb
.Append (left
.ToString ());
68 if (op
!= JSToken
.None
)
72 sb
.Append (right
.ToString ());
74 return sb
.ToString ();
77 internal override bool Resolve (IdentificationTable context
)
80 left
.Resolve (context
);
83 right
.Resolve (context
);
88 internal override bool Resolve (IdentificationTable context
, bool no_effect
)
90 this.no_effect
= no_effect
;
91 return Resolve (context
);
94 internal override void Emit (EmitContext ec
)
96 ILGenerator ig
= ec
.ig
;
98 if (op
== JSToken
.None
&& right
== null) {
101 } else if (op
== JSToken
.InstanceOf
) {
106 ig
.Emit (OpCodes
.Call
, typeof (InstanceOf
).GetMethod ("JScriptInstanceof"));
108 } else if (op
== JSToken
.In
) {
113 ig
.Emit (OpCodes
.Call
, typeof (In
).GetMethod ("JScriptIn"));
116 Type t
= typeof (Relational
);
117 LocalBuilder loc
= ig
.DeclareLocal (t
);
118 ConstructorInfo ctr_info
;
121 case JSToken
.GreaterThan
:
122 ig
.Emit (OpCodes
.Ldc_I4_S
, (byte) 57);
124 case JSToken
.LessThan
:
125 ig
.Emit (OpCodes
.Ldc_I4_S
, (byte) 58);
127 case JSToken
.LessThanEqual
:
128 ig
.Emit (OpCodes
.Ldc_I4_S
, (byte) 59);
130 case JSToken
.GreaterThanEqual
:
131 ig
.Emit (OpCodes
.Ldc_I4_S
, (byte) 60);
135 ctr_info
= typeof (Relational
).GetConstructor (new Type
[] { typeof (Int32) }
);
136 ig
.Emit (OpCodes
.Newobj
, ctr_info
);
137 ig
.Emit (OpCodes
.Stloc
, loc
);
138 ig
.Emit (OpCodes
.Ldloc
, loc
);
145 ig
.Emit (OpCodes
.Call
, t
.GetMethod ("EvaluateRelational"));
148 ig
.Emit (OpCodes
.Ldc_I4_0
);
149 ig
.Emit (OpCodes
.Conv_R8
);
152 a
= ig
.DefineLabel ();
153 b
= ig
.DefineLabel ();
156 case JSToken
.GreaterThan
:
157 ig
.Emit (OpCodes
.Bgt_S
, a
);
159 case JSToken
.LessThan
:
160 ig
.Emit (OpCodes
.Blt_S
, a
);
162 case JSToken
.LessThanEqual
:
163 ig
.Emit (OpCodes
.Ble_S
, a
);
165 case JSToken
.GreaterThanEqual
:
166 ig
.Emit (OpCodes
.Bge_S
, a
);
170 ig
.Emit (OpCodes
.Ldc_I4_0
);
171 ig
.Emit (OpCodes
.Br_S
, b
);
173 ig
.Emit (OpCodes
.Ldc_I4_1
);
177 ig
.Emit (OpCodes
.Pop
);
179 ig
.Emit (OpCodes
.Box
, typeof (bool));