5 // Cesar Octavio Lopez Nataren
7 // (C) 2003, Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Reflection;
34 using System.Collections;
36 namespace Microsoft.JScript {
38 public class FunctionObject : ScriptFunction {
41 internal string type_annot;
42 internal Type return_type;
43 internal FormalParameterList parameters;
46 internal FunctionObject (string name)
51 internal FunctionObject (MethodInfo info)
54 this.name = info.Name;
55 this.attr = info.Attributes;
56 this.return_type = info.ReturnType;
59 internal FunctionObject (string name, FormalParameterList p, string ret_type, Block body)
63 // 1) Must collect the attributes given.
64 // 2) Check if they are semantically correct.
65 // 3) Assign those values to 'attr'.
67 this.attr = MethodAttributes.Public | MethodAttributes.Static;
72 this.type_annot = ret_type;
74 // FIXME: Must check that return_type it's a valid type,
75 // and assign that to 'return_type' field.
77 this.return_type = typeof (void);
82 internal FunctionObject ()
84 this.parameters = new FormalParameterList ();
87 public override string ToString ()
89 StringBuilder sb = new StringBuilder ();
91 sb.Append ("function ");
95 if (parameters != null)
96 sb.Append (this.parameters.ToString ());
99 if (return_type != null && return_type != typeof (void))
100 sb.Append (" : " + return_type);
104 sb.Append (body.ToString ());
106 sb.Append (" [native code]");
110 return sb.ToString ();
113 internal Type [] params_types ()
115 if (parameters == null)
117 new Type [] {typeof (Object), typeof (Microsoft.JScript.Vsa.VsaEngine)};
120 ArrayList p = parameters.ids;
124 Type [] types = new Type [size];
126 types [0] = typeof (Object);
127 types [1] = typeof (Microsoft.JScript.Vsa.VsaEngine);
129 for (i = 2; i < size; i++)
130 types [i] = ((FormalParam) p [i - 2]).type;