// (C) 2003, Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
namespace Microsoft.JScript {
-
- public abstract class Decl : AST {
- internal FieldInfo field_info;
- internal LocalBuilder local_builder;
- }
-
- public class VariableDeclaration : Decl {
+
+ public class VariableDeclaration : AST {
internal string id;
internal Type type;
- internal string type_annot;
+ internal string type_annot = String.Empty;
internal AST val;
+ internal FieldInfo field_info;
+ internal LocalBuilder local_builder;
+
internal VariableDeclaration (AST parent, string id, string t, AST init)
{
this.parent = parent;
}
this.val = init;
}
-
+
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
sb.Append (id);
- sb.Append (":" + type_annot);
- sb.Append (" = ");
+ if (type_annot != String.Empty) {
+ sb.Append (":" + type_annot);
+ sb.Append (" = ");
+ }
if (val != null)
sb.Append (val.ToString ());
internal override void Emit (EmitContext ec)
{
- if (parent == null) {
- FieldBuilder field;
+ ILGenerator ig = ec.ig;
+
+ if (parent == null || (parent.GetType () != typeof (FunctionDeclaration)
+ && parent.GetType () != typeof (FunctionExpression))) {
+ FieldBuilder field_builder;
TypeBuilder type = ec.type_builder;
- field = type.DefineField (id, this.type,
- FieldAttributes.Public |
- FieldAttributes.Static);
-
- field_info = CodeGenerator.assembly_builder.GetType ("JScript 0").GetField (id);
+ field_builder = type.DefineField (id, this.type, FieldAttributes.Public | FieldAttributes.Static);
+ field_info = field_builder;
if (val != null) {
val.Emit (ec);
- ec.gc_ig.Emit (OpCodes.Stsfld, field);
+ ig.Emit (OpCodes.Stsfld, field_builder);
}
} else {
- ILGenerator ig = ec.ig;
local_builder = ig.DeclareLocal (type);
-
+
if (val != null) {
val.Emit (ec);
ig.Emit (OpCodes.Stloc, local_builder);
{
bool r = true;
if (val != null)
- if (val is Exp)
- r = ((Exp) val).Resolve (context, false);
- else
- r = val.Resolve (context);
+ r = val.Resolve (context);
context.Enter (id, this);
return r;
}