2 // VariableDeclaration.cs: The AST representation of a VariableDeclaration.
5 // Cesar Octavio Lopez Nataren
7 // (C) 2003, Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
12 using System.Reflection;
13 using System.Reflection.Emit;
15 namespace Microsoft.JScript {
17 public abstract class Decl : AST {
18 internal FieldInfo field_info;
19 internal LocalBuilder local_builder;
22 public class VariableDeclaration : Decl {
26 internal string type_annot;
29 internal VariableDeclaration (AST parent, string id, string t, AST init)
35 this.type = typeof (System.Object);
38 // FIXME: resolve the type annotations
39 this.type = typeof (System.Object);
44 public override string ToString ()
46 StringBuilder sb = new StringBuilder ();
49 sb.Append (":" + type_annot);
53 sb.Append (val.ToString ());
55 return sb.ToString ();
58 internal override void Emit (EmitContext ec)
62 TypeBuilder type = ec.type_builder;
64 field = type.DefineField (id, this.type,
65 FieldAttributes.Public |
66 FieldAttributes.Static);
68 field_info = CodeGenerator.assembly_builder.GetType ("JScript 0").GetField (id);
72 ec.gc_ig.Emit (OpCodes.Stsfld, field);
75 ILGenerator ig = ec.ig;
76 local_builder = ig.DeclareLocal (type);
80 ig.Emit (OpCodes.Stloc, local_builder);
85 internal override bool Resolve (IdentificationTable context)
90 r = ((Exp) val).Resolve (context, false);
92 r = val.Resolve (context);
93 context.Enter (id, this);