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 class VariableDeclaration : AST {
21 internal string type_annot;
24 internal FieldInfo field_info;
25 internal LocalBuilder local_builder;
27 internal VariableDeclaration (AST parent, string id, string t, AST init)
33 this.type = typeof (System.Object);
36 // FIXME: resolve the type annotations
37 this.type = typeof (System.Object);
42 public override string ToString ()
44 StringBuilder sb = new StringBuilder ();
47 sb.Append (":" + type_annot);
51 sb.Append (val.ToString ());
53 return sb.ToString ();
56 internal override void Emit (EmitContext ec)
58 ILGenerator ig = ec.ig;
61 FieldBuilder field_builder;
62 TypeBuilder type = ec.type_builder;
64 field_builder = type.DefineField (id, this.type, FieldAttributes.Public | FieldAttributes.Static);
65 field_info = field_builder;
69 ig.Emit (OpCodes.Stsfld, field_builder);
72 local_builder = ig.DeclareLocal (type);
76 ig.Emit (OpCodes.Stloc, local_builder);
81 internal override bool Resolve (IdentificationTable context)
85 r = val.Resolve (context);
86 context.Enter (id, this);