* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / FunctionObject.cs
index 2c82f54ffbf673dd48d0b9d850ff19fffd9b2355..270dd70ad6af9d5125965c0fe11c266b85b7a8f0 100644 (file)
@@ -35,19 +35,33 @@ using System.Collections;
 
 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'.
@@ -65,34 +79,22 @@ namespace Microsoft.JScript {
                        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 ()
@@ -117,5 +119,15 @@ namespace Microsoft.JScript {
                                return types;
                        }
                }
+
+               void ICanModifyContext.PopulateContext (Environment env, string ns)
+               {
+                       ((ICanModifyContext) body).PopulateContext (env, ns);
+               }
+
+               void ICanModifyContext.EmitDecls (EmitContext ec)
+               {
+                       ((ICanModifyContext) body).EmitDecls (ec);
+               }               
        }
 }