namespace Microsoft.JScript {
- public class FunctionObject : ScriptFunction {
+ public class FunctionObject : ScriptFunction, ICanModifyContext {
- internal MethodAttributes attr;
- internal string name;
internal string type_annot;
- internal Type return_type;
- internal FormalParameterList parameters;
internal Block body;
- internal FunctionObject (string name, FormalParameterList p, string ret_type, Block body)
+ internal Location location;
+
+ internal FunctionObject (string name)
+ {
+ this._prototype = ObjectConstructor.Ctr.ConstructObject ();
+ this.name = name;
+ }
+
+ internal FunctionObject (MethodInfo info)
+ {
+ this._prototype = ObjectConstructor.Ctr.ConstructObject ();
+ this.method = info;
+ this.name = info.Name;
+ this.attr = info.Attributes;
+ this.return_type = info.ReturnType;
+ }
+
+ internal FunctionObject (string name, FormalParameterList p, string ret_type, Block body, Location location)
{
+ this._prototype = ObjectConstructor.Ctr.ConstructObject ();
//
- // FIXME:
+ // FIXME
// 1) Must collect the attributes given.
// 2) Check if they are semantically correct.
// 3) Assign those values to 'attr'.
this.return_type = typeof (void);
this.body = body;
+ this.location = location;
+ }
+
+ public override int length {
+ get {
+ if (this.parameters != null)
+ return this.parameters.ids.Count;
+ else
+ return base.length;
+ }
+ set { base.length = value; }
}
internal FunctionObject ()
{
- this.parameters = new FormalParameterList ();
- }
-
- public override string ToString ()
- {
- StringBuilder sb = new StringBuilder ();
-
- sb.Append ("function ");
- sb.Append (name + " ");
- sb.Append ("(");
-
- if (parameters != null)
- sb.Append (this.parameters.ToString ());
-
- sb.Append (")");
- sb.Append (" : " + return_type);
- sb.Append ("{");
-
- if (body != null)
- sb.Append (body.ToString ());
-
- sb.Append ("}");
-
- return sb.ToString ();
+ this.parameters = new FormalParameterList (location);
}
internal Type [] params_types ()
return types;
}
}
+
+ void ICanModifyContext.PopulateContext (Environment env, string ns)
+ {
+ ((ICanModifyContext) body).PopulateContext (env, ns);
+ }
+
+ void ICanModifyContext.EmitDecls (EmitContext ec)
+ {
+ ((ICanModifyContext) body).EmitDecls (ec);
+ }
}
}