2 // parameter.cs: Parameter definition.
4 // Author: Miguel de Icaza (miguel@gnu.org)
6 // Licensed under the terms of the GNU GPL
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
13 namespace Mono.CSharp {
16 using System.Reflection;
17 using System.Collections;
20 /// Represents a single method parameter
22 public class Parameter {
23 public enum Modifier : byte {
30 public readonly string Type;
31 public readonly string Name;
32 public readonly Modifier ModFlags;
33 public Attributes OptAttributes;
35 public Parameter (string type, string name, Modifier mod, Attributes attrs)
40 OptAttributes = attrs;
43 public ParameterAttributes Attributes {
47 return ParameterAttributes.None;
49 return ParameterAttributes.None;
51 return ParameterAttributes.Out;
56 return ParameterAttributes.None;
60 string ModSignature ()
72 // This should not happen.
77 /// Returns the signature for this parameter evaluating it on the
80 public string GetSignature (TypeContainer tc)
82 Type t = tc.LookupType (Type, false);
87 return ModSignature () + t.FullName;
92 /// Represents the methods parameters
94 public class Parameters {
95 public Parameter [] FixedParameters;
96 public readonly Parameter ArrayParameter;
100 static Parameters empty_parameters;
102 public Parameters (Parameter [] fixed_parameters, Parameter array_parameter)
104 FixedParameters = fixed_parameters;
105 ArrayParameter = array_parameter;
109 /// This is used to reuse a set of empty parameters, because they
112 public static Parameters GetEmptyReadOnlyParameters ()
114 if (empty_parameters == null)
115 empty_parameters = new Parameters (null, null);
117 return empty_parameters;
122 return (FixedParameters == null) && (ArrayParameter == null);
126 public void ComputeSignature (TypeContainer tc)
129 if (FixedParameters != null){
130 for (int i = 0; i < FixedParameters.Length; i++){
131 Parameter par = FixedParameters [i];
133 signature += par.GetSignature (tc);
137 // Note: as per the spec, the `params' arguments (ArrayParameter)
138 // are not used in the signature computation for a method
142 public bool VerifyArgs (TypeContainer tc)
147 if (FixedParameters == null)
150 count = FixedParameters.Length;
151 for (i = 0; i < count; i++){
152 for (j = i + 1; j < count; j++){
153 if (FixedParameters [i].Name != FixedParameters [j].Name)
156 100, "The parameter name `" + FixedParameters [i].Name +
165 /// Returns the signature of the Parameters evaluated in
166 /// the @tc environment
168 public string GetSignature (TypeContainer tc)
170 if (signature == null){
172 ComputeSignature (tc);
179 /// Returns the paramenter information based on the name
181 public Parameter GetParameterByName (string name, out int idx)
185 if (FixedParameters == null)
189 foreach (Parameter par in FixedParameters){
190 if (par.Name == name){
197 if (ArrayParameter != null)
198 if (name == ArrayParameter.Name){
200 return ArrayParameter;
208 /// Returns the argument types as an array
210 public Type [] GetParameterInfo (TypeContainer tc)
215 if (FixedParameters == null)
218 int extra = (ArrayParameter != null) ? 1 : 0;
220 int pc = FixedParameters.Length + extra;
222 types = new Type [pc];
224 if (!VerifyArgs (tc)){
225 FixedParameters = null;
229 foreach (Parameter p in FixedParameters){
230 Type t = tc.LookupType (p.Type, false);
232 if ((p.ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0){
233 t = Type.GetType (t.FullName + "&");
240 types [i] = tc.LookupType (ArrayParameter.Type, false);
245 public CallingConventions GetCallingConvention ()
247 if (ArrayParameter != null)
248 return CallingConventions.VarArgs;
250 return CallingConventions.Standard;