5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, 2004 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.
32 using System.Reflection.Emit;
33 using System.Collections;
35 namespace Microsoft.JScript {
37 internal class This : AST {
43 internal override bool Resolve (IdentificationTable context)
45 throw new NotImplementedException ();
48 internal override void Emit (EmitContext ec)
50 throw new NotImplementedException ();
54 internal class BooleanLiteral : Exp {
58 internal BooleanLiteral (AST parent, bool val)
64 public override string ToString ()
66 return val.ToString ();
69 internal override bool Resolve (IdentificationTable context)
74 internal override bool Resolve (IdentificationTable context, bool no_effect)
76 this.no_effect = no_effect;
80 internal override void Emit (EmitContext ec)
82 ILGenerator ig = ec.ig;
85 ig.Emit (OpCodes.Ldc_I4_1);
87 ig.Emit (OpCodes.Ldc_I4_0);
89 ig.Emit (OpCodes.Box, typeof (System.Boolean));
92 ig.Emit (OpCodes.Pop);
96 public class NumericLiteral : Exp {
100 internal NumericLiteral (AST parent, double val)
102 this.parent = parent;
106 public override string ToString ()
108 return val.ToString ();
111 internal override bool Resolve (IdentificationTable context)
116 internal override bool Resolve (IdentificationTable context, bool no_effect)
118 this.no_effect = no_effect;
119 return Resolve (context);
122 internal override void Emit (EmitContext ec)
124 ILGenerator ig = ec.ig;
125 if (parent is Unary && (parent as Unary).oper == JSToken.Minus)
126 ig.Emit (OpCodes.Ldc_R8, (double) (val * -1));
128 ig.Emit (OpCodes.Ldc_R8, (double) val);
129 ig.Emit (OpCodes.Box, typeof (System.Double));
131 ig.Emit (OpCodes.Pop);
135 public class ObjectLiteral : Exp {
137 internal ArrayList elems;
139 internal ObjectLiteral (ArrayList elems)
144 internal ObjectLiteral (AST parent)
146 this.parent = parent;
147 elems = new ArrayList ();
150 internal override bool Resolve (IdentificationTable context, bool no_effect)
152 this.no_effect = no_effect;
153 return Resolve (context);
156 internal override bool Resolve (IdentificationTable context)
159 foreach (AST ast in elems)
160 r &= ast.Resolve (context);
164 internal override void Emit (EmitContext ec)
166 ILGenerator ig = ec.ig;
168 ig.Emit (OpCodes.Ldarg_0);
169 ig.Emit (OpCodes.Ldfld, typeof (ScriptObject).GetField ("engine"));
170 ig.Emit (OpCodes.Call, typeof (Microsoft.JScript.Vsa.VsaEngine).GetMethod ("GetOriginalObjectConstructor"));
171 ig.Emit (OpCodes.Call, typeof (ObjectConstructor).GetMethod ("ConstructObject"));
173 foreach (ObjectLiteralItem item in elems) {
174 ig.Emit (OpCodes.Dup);
176 ig.Emit (OpCodes.Call, typeof (JSObject).GetMethod ("SetMemberValue2"));
179 ig.Emit (OpCodes.Pop);
182 internal void Add (ObjectLiteralItem item)
188 internal class ObjectLiteralItem : AST {
189 internal string property_name;
192 internal ObjectLiteralItem (object obj)
195 property_name = obj.ToString ();
198 internal override bool Resolve (IdentificationTable context)
200 return exp.Resolve (context);
203 internal override void Emit (EmitContext ec)
205 ec.ig.Emit (OpCodes.Ldstr, property_name);
210 public class PropertyName {
212 internal string Name {
214 set { name = value; }
218 internal class RegExpLiteral : AST {
220 internal string flags;
222 internal RegExpLiteral (string re, string flags)
228 internal override bool Resolve (IdentificationTable context)
230 throw new NotImplementedException ();
233 internal override void Emit (EmitContext ec)
235 throw new NotImplementedException ();