Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FunctionObject.cs « Microsoft.JScript « Microsoft.JScript « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6dd7790d4cab575416fcc58b7ea54919f635dc4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// FunctionObject.cs:
//
// Author:
//	Cesar Octavio Lopez Nataren
//
// (C) 2003, Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
//

using System;
using System.Text;
using System.Reflection;
using System.Collections;

namespace Microsoft.JScript {

	public class FunctionObject : ScriptFunction {

		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)
		{
			//
			// FIXME: 
			// 1) Must collect the attributes given.
			// 2) Check if they are semantically correct.
			// 3) Assign those values to 'attr'.
			//
			this.attr = MethodAttributes.Public | MethodAttributes.Static;

			this.name = name;
			this.parameters = p;

			this.type_annot = ret_type;
			//
			// FIXME: Must check that return_type it's a valid type,
			// and assign that to 'return_type' field.
			//
			this.return_type = typeof (void);

			this.body = body;
		}
	    
		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 ();		
		}

		internal Type [] params_types ()
		{
			if (parameters == null)
				return 
					new Type [] {typeof (Object), typeof (Microsoft.JScript.Vsa.VsaEngine)};
			else {
				int i, size;
				ArrayList p = parameters.ids;

				size = p.Count + 2;

				Type [] types = new Type [size];

				types [0] = typeof (Object);
				types [1] = typeof (Microsoft.JScript.Vsa.VsaEngine);

				for (i = 2; i < size; i++)
					types [i] = ((FormalParam) p [i - 2]).type;

				return types;
			}
		}
	}
}