* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / FunctionObject.cs
index 6dd7790d4cab575416fcc58b7ea54919f635dc4d..270dd70ad6af9d5125965c0fe11c266b85b7a8f0 100644 (file)
@@ -7,6 +7,27 @@
 // (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;
@@ -14,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'.
@@ -44,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 ()
@@ -96,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);
+               }               
        }
 }