2 // FormalParameterList.cs: A list of identifiers.
7 // (C) 2003, Cesar 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.
31 using System.Reflection.Emit;
32 using System.Collections;
36 namespace Microsoft.JScript {
38 internal class FormalParam : AST {
40 internal string type_annot;
45 // Must perform semantic analysis on type_annot,
46 // and assign that type value to 'type' if valid.
48 internal Type type = typeof (Object);
50 internal FormalParam (string id, string type_annot, Location location)
51 : base (null, location)
54 this.type_annot = type_annot;
57 public override string ToString ()
59 return id + " " + type_annot;
62 internal override void Emit (EmitContext ec)
66 internal override bool Resolve (Environment env)
68 env.Enter (String.Empty, Symbol.CreateSymbol (id), this);
73 internal class FormalParameterList : AST {
75 internal ArrayList ids;
77 internal FormalParameterList (Location location)
78 : base (null, location)
80 ids = new ArrayList ();
83 internal void Add (string id, string type_annot, Location location)
85 FormalParam p = new FormalParam (id, type_annot, location);
89 public override string ToString ()
91 StringBuilder sb = new StringBuilder ();
93 foreach (FormalParam f in ids)
94 sb.Append (f.ToString () + " ");
96 return sb.ToString ();
99 internal override bool Resolve (Environment env)
102 int i, n = ids.Count;
104 for (i = 0; i < n; i++) {
105 f = (FormalParam) ids [i];
106 f.pos = (byte) (i + 2);
112 internal override void Emit (EmitContext ec)
115 ILGenerator ig = ec.ig;
117 ig.Emit (OpCodes.Ldc_I4, n);
118 ig.Emit (OpCodes.Newarr, typeof (string));
120 for (int i = 0; i < n; i++) {
121 ig.Emit (OpCodes.Dup);
122 ig.Emit (OpCodes.Ldc_I4, i);
123 ig.Emit (OpCodes.Ldstr, ((FormalParam) ids [i]).id);
124 ig.Emit (OpCodes.Stelem_Ref);
129 get { return ids.Count; }
132 internal FormalParam get_element (int i)
134 if (i >= 0 && i < size)
135 return (FormalParam) ids [i];
137 throw new IndexOutOfRangeException ();