// parameter.cs: Parameter definition.
//
// Author: Miguel de Icaza (miguel@gnu.org)
+// Marek Safar (marek.safar@seznam.cz)
//
// Licensed under the terms of the GNU GPL
//
using System.Reflection;
using System.Reflection.Emit;
using System.Collections;
+using System.Text;
namespace Mono.CSharp {
protected ParameterBuilder builder;
- public ParameterBase (Attributes attrs)
+ protected ParameterBase (Attributes attrs)
: base (attrs)
{
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
if (a.Type == TypeManager.marshal_as_attr_type) {
- UnmanagedMarshal marshal = a.GetMarshal ();
+ UnmanagedMarshal marshal = a.GetMarshal (this);
if (marshal != null) {
builder.SetMarshal (marshal);
- return;
}
- Report.Warning_T (-24, a.Location);
+ return;
+ }
+
+ if (a.Type.IsSubclassOf (TypeManager.security_attr_type)) {
+ a.Error_InvalidSecurityParent ();
return;
}
builder.SetCustomAttribute (cb);
}
- public override bool IsClsCompliaceRequired(DeclSpace ds)
+ public override bool IsClsComplianceRequired()
{
return false;
}
/// <summary>
/// Class for applying custom attributes on the return type
/// </summary>
- public class ReturnParameter: ParameterBase {
+ public class ReturnParameter : ParameterBase {
public ReturnParameter (MethodBuilder mb, Location location):
base (null)
{
builder = mb.DefineParameter (0, ParameterAttributes.None, "");
}
catch (ArgumentOutOfRangeException) {
- Report.Warning_T (-28, location);
+ Report.RuntimeMissingSupport (location, "custom attributes on the return type");
}
}
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
+ }
+
// This occurs after Warning -28
if (builder == null)
return;
}
}
+ public override IResolveContext ResolveContext {
+ get {
+ throw new NotSupportedException ();
+ }
+ }
+
/// <summary>
/// Is never called
/// </summary>
- protected override string[] ValidAttributeTargets {
+ public override string[] ValidAttributeTargets {
get {
return null;
}
/// Class for applying custom attributes on the implicit parameter type
/// of the 'set' method in properties, and the 'add' and 'remove' methods in events.
/// </summary>
- public class ImplicitParameter: ParameterBase {
+ ///
+ // TODO: should use more code from Parameter.ApplyAttributeBuilder
+ public class ImplicitParameter : ParameterBase {
public ImplicitParameter (MethodBuilder mb):
base (null)
{
}
}
+ public override IResolveContext ResolveContext {
+ get {
+ throw new NotSupportedException ();
+ }
+ }
+
/// <summary>
/// Is never called
/// </summary>
- protected override string[] ValidAttributeTargets {
+ public override string[] ValidAttributeTargets {
get {
return null;
}
}
}
+ public class ParamsParameter : Parameter {
+ public ParamsParameter (Expression type, string name, Attributes attrs, Location loc):
+ base (type, name, Parameter.Modifier.PARAMS, attrs, loc)
+ {
+ }
+
+ public override bool Resolve (IResolveContext ec)
+ {
+ if (!base.Resolve (ec))
+ return false;
+
+ if (!parameter_type.IsArray || parameter_type.GetArrayRank () != 1) {
+ Report.Error (225, Location, "The params parameter must be a single dimensional array");
+ return false;
+ }
+ return true;
+ }
+
+ public override void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
+ {
+ base.ApplyAttributes (mb, cb, index);
+
+ CustomAttributeBuilder a = new CustomAttributeBuilder (
+ TypeManager.ConsParamArrayAttribute, new object [0]);
+
+ builder.SetCustomAttribute (a);
+ }
+ }
+
+ public class ArglistParameter : Parameter {
+ // Doesn't have proper type because it's never choosed for better conversion
+ public ArglistParameter () :
+ base (typeof (ArglistParameter), "", Parameter.Modifier.ARGLIST, null, Location.Null)
+ {
+ }
+
+ public override bool Resolve (IResolveContext ec)
+ {
+ return true;
+ }
+
+ public override string GetSignatureForError ()
+ {
+ return "__arglist";
+ }
+ }
/// <summary>
/// Represents a single method parameter
/// </summary>
-
- //TODO: Add location member to this or base class for better error location and all methods simplification.
public class Parameter : ParameterBase {
[Flags]
public enum Modifier : byte {
NONE = 0,
- REF = 1,
- OUT = 2,
+ REF = REFMASK | ISBYREF,
+ OUT = OUTMASK | ISBYREF,
PARAMS = 4,
// This is a flag which says that it's either REF or OUT.
- ISBYREF = 8
+ ISBYREF = 8,
+ ARGLIST = 16,
+ REFMASK = 32,
+ OUTMASK = 64
}
static string[] attribute_targets = new string [] { "param" };
- public readonly Expression TypeName;
+ public Expression TypeName;
public readonly Modifier ModFlags;
- public readonly string Name;
- Type parameter_type;
+ public string Name;
+ public bool IsCaptured;
+ protected Type parameter_type;
+ public readonly Location Location;
+
+ IResolveContext resolve_context;
+
+ Variable var;
+ public Variable Variable {
+ get { return var; }
+ }
+
+#if GMCS_SOURCE
+ GenericConstraints constraints;
+#endif
- public Parameter (Expression type, string name, Modifier mod, Attributes attrs)
+ public Parameter (Expression type, string name, Modifier mod, Attributes attrs, Location loc)
: base (attrs)
{
Name = name;
ModFlags = mod;
TypeName = type;
+ Location = loc;
+ }
+
+ public Parameter (Type type, string name, Modifier mod, Attributes attrs, Location loc)
+ : base (attrs)
+ {
+ Name = name;
+ ModFlags = mod;
+ parameter_type = type;
+ Location = loc;
+ }
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Type == TypeManager.in_attribute_type && ModFlags == Modifier.OUT) {
+ Report.Error (36, a.Location, "An out parameter cannot have the `In' attribute");
+ return;
+ }
+
+ if (a.Type == TypeManager.param_array_type) {
+ Report.Error (674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead");
+ return;
+ }
+
+ if (a.Type == TypeManager.out_attribute_type && (ModFlags & Modifier.REF) == Modifier.REF &&
+ !OptAttributes.Contains (TypeManager.in_attribute_type)) {
+ Report.Error (662, a.Location,
+ "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither");
+ return;
+ }
+
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
+ }
+
+ // TypeManager.default_parameter_value_attribute_type is null if !NET_2_0
+ if (a.Type == TypeManager.default_parameter_value_attribute_type) {
+ object val = a.GetParameterDefaultValue ();
+ if (val != null) {
+ Type t = val.GetType ();
+ if (t.IsArray || TypeManager.IsSubclassOf (t, TypeManager.type_type)) {
+ if (parameter_type == TypeManager.object_type) {
+ if (!t.IsArray)
+ t = TypeManager.type_type;
+
+ Report.Error (1910, a.Location, "Argument of type `{0}' is not applicable for the DefaultValue attribute",
+ TypeManager.CSharpName (t));
+ } else {
+ Report.Error (1909, a.Location, "The DefaultValue attribute is not applicable on parameters of type `{0}'",
+ TypeManager.CSharpName (parameter_type)); ;
+ }
+ return;
+ }
+ }
+
+ if (parameter_type == TypeManager.object_type ||
+ (val == null && !TypeManager.IsValueType (parameter_type)) ||
+ (val != null && TypeManager.TypeToCoreType (val.GetType ()) == parameter_type))
+ builder.SetConstant (val);
+ else
+ Report.Error (1908, a.Location, "The type of the default value should match the type of the parameter");
+ return;
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
+ public override IResolveContext ResolveContext {
+ get {
+ return resolve_context;
+ }
}
// <summary>
// Resolve is used in method definitions
// </summary>
- public bool Resolve (DeclSpace ds, Location l)
+ public virtual bool Resolve (IResolveContext ec)
{
- parameter_type = ds.ResolveType (TypeName, false, l);
+ if (parameter_type != null)
+ return true;
+
+ this.resolve_context = ec;
+
+ TypeExpr texpr = TypeName.ResolveAsTypeTerminal (ec, false);
+ if (texpr == null)
+ return false;
+
+#if GMCS_SOURCE
+ TypeParameterExpr tparam = texpr as TypeParameterExpr;
+ if (tparam != null)
+ constraints = tparam.TypeParameter.Constraints;
+#endif
+
+ parameter_type = texpr.Type;
+
+ if (parameter_type.IsAbstract && parameter_type.IsSealed) {
+ Report.Error (721, Location, "`{0}': static types cannot be used as parameters", GetSignatureForError ());
+ return false;
+ }
if (parameter_type == TypeManager.void_type){
- Report.Error (1536, l, "`void' parameter is not permitted");
+ Report.Error (1536, Location, "Invalid parameter type 'void'");
return false;
}
if ((ModFlags & Parameter.Modifier.ISBYREF) != 0){
if (parameter_type == TypeManager.typed_reference_type ||
parameter_type == TypeManager.arg_iterator_type){
- Report.Error (1601, l,
- "out or ref parameter can not be of type TypedReference or ArgIterator");
+ Report.Error (1601, Location, "Method or delegate parameter cannot be of type `{0}'",
+ GetSignatureForError ());
return false;
}
}
- return parameter_type != null;
+ return true;
+ }
+
+ public void ResolveVariable (ToplevelBlock toplevel, int idx)
+ {
+ if (toplevel.AnonymousMethodHost != null)
+ var = toplevel.AnonymousMethodHost.GetCapturedParameter (this);
+ if (var == null)
+ var = new ParameterVariable (this, idx);
}
public Type ExternalType ()
return parameter_type;
}
}
-
+
+#if GMCS_SOURCE
+ public GenericConstraints GenericConstraints {
+ get {
+ return constraints;
+ }
+ }
+#endif
+
public ParameterAttributes Attributes {
get {
- int flags = ((int) ModFlags) & ~((int) Parameter.Modifier.ISBYREF);
- switch ((Modifier) flags) {
+ switch (ModFlags) {
case Modifier.NONE:
return ParameterAttributes.None;
case Modifier.REF:
return ParameterAttributes.None;
}
}
+
+ public static ParameterAttributes GetParameterAttributes (Modifier mod)
+ {
+ int flags = ((int) mod) & ~((int) Parameter.Modifier.ISBYREF);
+ switch ((Modifier) flags) {
+ case Modifier.NONE:
+ return ParameterAttributes.None;
+ case Modifier.REF:
+ return ParameterAttributes.None;
+ case Modifier.OUT:
+ return ParameterAttributes.Out;
+ case Modifier.PARAMS:
+ return 0;
+ }
+
+ return ParameterAttributes.None;
+ }
public override AttributeTargets AttributeTargets {
get {
}
}
- /// <summary>
- /// Returns the signature for this parameter evaluating it on the
- /// @tc context
- /// </summary>
- public string GetSignature (DeclSpace ds, Location loc)
+ public virtual string GetSignatureForError ()
{
- if (parameter_type == null){
- if (!Resolve (ds, loc))
- return null;
- }
+ string type_name;
+ if (parameter_type != null)
+ type_name = TypeManager.CSharpName (parameter_type);
+ else
+ type_name = TypeName.GetSignatureForError ();
- return ExternalType ().FullName;
+ string mod = GetModifierSignature (ModFlags);
+ if (mod.Length > 0)
+ return String.Concat (mod, ' ', type_name);
+
+ return type_name;
}
- public string GetSignatureForError ()
+ public static string GetModifierSignature (Modifier mod)
{
- string typeName = TypeManager.CSharpName (parameter_type);
- switch (ModFlags & ~Modifier.ISBYREF) {
+ switch (mod) {
case Modifier.OUT:
- return "out " + typeName;
+ return "out";
case Modifier.PARAMS:
- return "params " + typeName;
+ return "params";
case Modifier.REF:
- return "ref " + typeName;
+ return "ref";
+ case Modifier.ARGLIST:
+ return "__arglist";
+ default:
+ return "";
}
- return typeName;
}
- public void DefineParameter (EmitContext ec, MethodBuilder mb, ConstructorBuilder cb, int index, Location loc)
+ public void IsClsCompliant ()
+ {
+ if (AttributeTester.IsClsCompliant (ExternalType ()))
+ return;
+
+ Report.Error (3001, Location, "Argument type `{0}' is not CLS-compliant", GetSignatureForError ());
+ }
+
+ public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
{
- ParameterAttributes par_attr = Attributes;
-
+#if !GMCS_SOURCE || !MS_COMPATIBLE
+ // TODO: It should use mb.DefineGenericParameters
if (mb == null)
- builder = cb.DefineParameter (index, par_attr, Name);
+ builder = cb.DefineParameter (index, Attributes, Name);
else
- builder = mb.DefineParameter (index, par_attr, Name);
-
- if (OptAttributes != null) {
- OptAttributes.Emit (ec, this);
-
- if (par_attr == ParameterAttributes.Out){
- if (OptAttributes.Contains (TypeManager.in_attribute_type, ec))
- Report.Error (36, loc, "Can not use [In] attribute on out parameter");
- }
- }
+ builder = mb.DefineParameter (index, Attributes, Name);
+#endif
+
+ if (OptAttributes != null)
+ OptAttributes.Emit ();
}
- protected override string[] ValidAttributeTargets {
+ public override string[] ValidAttributeTargets {
get {
return attribute_targets;
}
}
+
+ protected class ParameterVariable : Variable
+ {
+ public readonly Parameter Parameter;
+ public readonly int Idx;
+ public readonly bool IsRef;
+
+ public ParameterVariable (Parameter par, int idx)
+ {
+ this.Parameter = par;
+ this.Idx = idx;
+ this.IsRef = (par.ModFlags & Parameter.Modifier.ISBYREF) != 0;
+ }
+
+ public override Type Type {
+ get { return Parameter.ParameterType; }
+ }
+
+ public override bool HasInstance {
+ get { return false; }
+ }
+
+ public override bool NeedsTemporary {
+ get { return false; }
+ }
+
+ public override void EmitInstance (EmitContext ec)
+ {
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ int arg_idx = Idx;
+ if (!ec.MethodIsStatic)
+ arg_idx++;
+
+ ParameterReference.EmitLdArg (ec.ig, arg_idx);
+ }
+
+ public override void EmitAssign (EmitContext ec)
+ {
+ int arg_idx = Idx;
+ if (!ec.MethodIsStatic)
+ arg_idx++;
+
+ if (arg_idx <= 255)
+ ec.ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
+ else
+ ec.ig.Emit (OpCodes.Starg, arg_idx);
+ }
+
+ public override void EmitAddressOf (EmitContext ec)
+ {
+ int arg_idx = Idx;
+
+ if (!ec.MethodIsStatic)
+ arg_idx++;
+
+ if (IsRef) {
+ if (arg_idx <= 255)
+ ec.ig.Emit (OpCodes.Ldarg_S, (byte) arg_idx);
+ else
+ ec.ig.Emit (OpCodes.Ldarg, arg_idx);
+ } else {
+ if (arg_idx <= 255)
+ ec.ig.Emit (OpCodes.Ldarga_S, (byte) arg_idx);
+ else
+ ec.ig.Emit (OpCodes.Ldarga, arg_idx);
+ }
+ }
+ }
+
}
/// <summary>
/// Represents the methods parameters
/// </summary>
- public class Parameters {
+ public class Parameters : ParameterData {
+ // Null object pattern
public Parameter [] FixedParameters;
- public readonly Parameter ArrayParameter;
- string signature;
+ public readonly bool HasArglist;
Type [] types;
- Location loc;
-
- static Parameters empty_parameters;
+ int count;
+
+ public static readonly Parameters EmptyReadOnlyParameters = new Parameters ();
+ static readonly Parameter ArgList = new ArglistParameter ();
+
+#if GMCS_SOURCE
+ public readonly TypeParameter[] TypeParameters;
+#endif
+
+ private Parameters ()
+ {
+ FixedParameters = new Parameter[0];
+ types = new Type [0];
+ }
+
+ public Parameters (Parameter[] parameters, Type[] types)
+ {
+ FixedParameters = parameters;
+ this.types = types;
+ count = types.Length;
+ }
- public Parameters (Parameter [] fixed_parameters, Parameter array_parameter, Location l)
+ public Parameters (Parameter[] parameters)
{
- FixedParameters = fixed_parameters;
- ArrayParameter = array_parameter;
- loc = l;
+ if (parameters == null)
+ throw new ArgumentException ("Use EmptyReadOnlyPatameters");
+
+ FixedParameters = parameters;
+ count = parameters.Length;
+ }
+
+ public Parameters (Parameter[] parameters, bool has_arglist):
+ this (parameters)
+ {
+ HasArglist = has_arglist;
}
/// <summary>
- /// This is used to reuse a set of empty parameters, because they
- /// are common
+ /// Use this method when you merge compiler generated argument with user arguments
/// </summary>
- public static Parameters EmptyReadOnlyParameters {
- get {
- if (empty_parameters == null)
- empty_parameters = new Parameters (null, null, Location.Null);
-
- return empty_parameters;
+ public static Parameters MergeGenerated (Parameters userParams, params Parameter[] compilerParams)
+ {
+ Parameter[] all_params = new Parameter [userParams.count + compilerParams.Length];
+ Type[] all_types = new Type[all_params.Length];
+ userParams.FixedParameters.CopyTo(all_params, 0);
+ userParams.Types.CopyTo (all_types, 0);
+
+ int last_filled = userParams.Count;
+ foreach (Parameter p in compilerParams) {
+ for (int i = 0; i < last_filled; ++i) {
+ while (p.Name == all_params [i].Name) {
+ p.Name = '_' + p.Name;
+ }
+ }
+ all_params [last_filled] = p;
+ all_types [last_filled] = p.ParameterType;
+ ++last_filled;
}
+
+ return new Parameters (all_params, all_types);
}
-
+
public bool Empty {
get {
- return (FixedParameters == null) && (ArrayParameter == null);
+ return count == 0;
}
}
-
- public void ComputeSignature (DeclSpace ds)
- {
- signature = "";
- if (FixedParameters != null){
- for (int i = 0; i < FixedParameters.Length; i++){
- Parameter par = FixedParameters [i];
-
- signature += par.GetSignature (ds, loc);
- }
+
+ public int Count {
+ get {
+ return HasArglist ? count + 1 : count;
}
- //
- // Note: as per the spec, the `params' arguments (ArrayParameter)
- // are not used in the signature computation for a method
- //
}
- void Error_DuplicateParameterName (string name)
+ bool VerifyArgs ()
{
- Report.Error (
- 100, loc, "The parameter name `" + name + "' is a duplicate");
- }
-
- public bool VerifyArgs ()
- {
- int count;
- int i, j;
-
- if (FixedParameters == null)
+ if (count < 2)
return true;
-
- count = FixedParameters.Length;
- string array_par_name = ArrayParameter != null ? ArrayParameter.Name : null;
- for (i = 0; i < count; i++){
+
+ for (int i = 0; i < count; i++){
string base_name = FixedParameters [i].Name;
-
- for (j = i + 1; j < count; j++){
+ for (int j = i + 1; j < count; j++){
if (base_name != FixedParameters [j].Name)
continue;
- Error_DuplicateParameterName (base_name);
- return false;
- }
- if (base_name == array_par_name){
- Error_DuplicateParameterName (base_name);
+ Report.Error (100, FixedParameters [i].Location,
+ "The parameter name `{0}' is a duplicate", base_name);
return false;
}
}
return true;
}
- /// <summary>
- /// Returns the signature of the Parameters evaluated in
- /// the @tc environment
- /// </summary>
- public string GetSignature (DeclSpace ds)
- {
- if (signature == null){
- VerifyArgs ();
- ComputeSignature (ds);
- }
-
- return signature;
- }
/// <summary>
/// Returns the paramenter information based on the name
public Parameter GetParameterByName (string name, out int idx)
{
idx = 0;
- int i = 0;
- if (FixedParameters != null){
- foreach (Parameter par in FixedParameters){
- if (par.Name == name){
- idx = i;
- return par;
- }
- i++;
- }
- }
+ if (count == 0)
+ return null;
+
+ int i = 0;
- if (ArrayParameter != null){
- if (name == ArrayParameter.Name){
+ foreach (Parameter par in FixedParameters){
+ if (par.Name == name){
idx = i;
- return ArrayParameter;
+ return par;
}
+ i++;
}
-
return null;
}
- bool ComputeParameterTypes (DeclSpace ds)
+ public Parameter GetParameterByName (string name)
{
- int extra = (ArrayParameter != null) ? 1 : 0;
- int i = 0;
- int pc;
+ int idx;
- if (FixedParameters == null)
- pc = extra;
- else
- pc = extra + FixedParameters.Length;
+ return GetParameterByName (name, out idx);
+ }
+
+ public bool Resolve (IResolveContext ec)
+ {
+ if (types != null)
+ return true;
- types = new Type [pc];
+ types = new Type [count];
- if (!VerifyArgs ()){
- FixedParameters = null;
+ if (!VerifyArgs ())
return false;
- }
- bool failed = false;
- if (FixedParameters != null){
- foreach (Parameter p in FixedParameters){
- Type t = null;
-
- if (p.Resolve (ds, loc))
- t = p.ExternalType ();
- else
- failed = true;
-
- types [i] = t;
- i++;
+ bool ok = true;
+ Parameter p;
+ for (int i = 0; i < FixedParameters.Length; ++i) {
+ p = FixedParameters [i];
+ if (!p.Resolve (ec)) {
+ ok = false;
+ continue;
}
- }
-
- if (extra > 0){
- if (ArrayParameter.Resolve (ds, loc))
- types [i] = ArrayParameter.ExternalType ();
- else
- failed = true;
+ types [i] = p.ExternalType ();
}
- if (failed){
- types = null;
- return false;
+ return ok;
+ }
+
+ public void ResolveVariable (ToplevelBlock toplevel)
+ {
+ for (int i = 0; i < FixedParameters.Length; ++i) {
+ Parameter p = FixedParameters [i];
+ p.ResolveVariable (toplevel, i);
}
+ }
- return true;
+ public CallingConventions CallingConvention
+ {
+ get {
+ if (HasArglist)
+ return CallingConventions.VarArgs;
+ else
+ return CallingConventions.Standard;
+ }
}
- //
- // This variant is used by Delegates, because they need to
- // resolve/define names, instead of the plain LookupType
- //
- public bool ComputeAndDefineParameterTypes (DeclSpace ds)
+ // Define each type attribute (in/out/ref) and
+ // the argument names.
+ public void ApplyAttributes (MethodBase builder)
{
- int extra = (ArrayParameter != null) ? 1 : 0;
- int i = 0;
- int pc;
+ if (count == 0)
+ return;
- if (FixedParameters == null)
- pc = extra;
- else
- pc = extra + FixedParameters.Length;
-
- types = new Type [pc];
-
- if (!VerifyArgs ()){
- FixedParameters = null;
- return false;
+ MethodBuilder mb = builder as MethodBuilder;
+ ConstructorBuilder cb = builder as ConstructorBuilder;
+
+ for (int i = 0; i < FixedParameters.Length; i++) {
+ FixedParameters [i].ApplyAttributes (mb, cb, i + 1);
}
+ }
- bool ok_flag = true;
-
- if (FixedParameters != null){
- foreach (Parameter p in FixedParameters){
- Type t = null;
-
- if (p.Resolve (ds, loc))
- t = p.ExternalType ();
- else
- ok_flag = false;
-
- types [i] = t;
- i++;
+ public void VerifyClsCompliance ()
+ {
+ foreach (Parameter p in FixedParameters)
+ p.IsClsCompliant ();
+ }
+
+ public string GetSignatureForError ()
+ {
+ StringBuilder sb = new StringBuilder ("(");
+ if (count > 0) {
+ for (int i = 0; i < FixedParameters.Length; ++i) {
+ sb.Append (FixedParameters[i].GetSignatureForError ());
+ if (i < FixedParameters.Length - 1)
+ sb.Append (", ");
}
}
-
- if (extra > 0){
- if (ArrayParameter.Resolve (ds, loc))
- types [i] = ArrayParameter.ExternalType ();
- else
- ok_flag = false;
+
+ if (HasArglist) {
+ if (sb.Length > 1)
+ sb.Append (", ");
+ sb.Append ("__arglist");
}
- //
- // invalidate the cached types
- //
- if (!ok_flag){
- types = null;
+ sb.Append (')');
+ return sb.ToString ();
+ }
+
+ public Type[] Types {
+ get {
+ return types;
}
-
- return ok_flag;
}
-
- /// <summary>
- /// Returns the argument types as an array
- /// </summary>
- static Type [] no_types = new Type [0];
-
- public Type [] GetParameterInfo (DeclSpace ds)
+
+ public Parameter this [int pos]
{
- if (types != null)
- return types;
-
- if (FixedParameters == null && ArrayParameter == null)
- return no_types;
+ get {
+ if (pos >= count && (HasArglist || HasParams)) {
+ if (HasArglist && (pos == 0 || pos >= count))
+ return ArgList;
+ pos = count - 1;
+ }
- if (ComputeParameterTypes (ds) == false){
- types = null;
- return null;
+ return FixedParameters [pos];
}
-
- return types;
}
- /// <summary>
- /// Returns the type of a given parameter, and stores in the `is_out'
- /// boolean whether this is an out or ref parameter.
- ///
- /// Note that the returned type will not contain any dereference in this
- /// case (ie, you get "int" for a ref int instead of "int&"
- /// </summary>
- public Type GetParameterInfo (DeclSpace ds, int idx, out Parameter.Modifier mod)
+ #region ParameterData Members
+
+ public Type ParameterType (int pos)
{
- mod = Parameter.Modifier.NONE;
-
- if (!VerifyArgs ()){
- FixedParameters = null;
- return null;
- }
+ return this [pos].ExternalType ();
+ }
- if (FixedParameters == null && ArrayParameter == null)
- return null;
-
- if (types == null)
- if (ComputeParameterTypes (ds) == false)
- return null;
-
- //
- // If this is a request for the variable lenght arg.
- //
- int array_idx = (FixedParameters != null ? FixedParameters.Length : 0);
- if (idx == array_idx)
- return types [idx];
-
- //
- // Otherwise, it is a fixed parameter
- //
- Parameter p = FixedParameters [idx];
- mod = p.ModFlags;
-
- if ((mod & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0)
- mod |= Parameter.Modifier.ISBYREF;
-
- return p.ParameterType;
- }
-
- public CallingConventions GetCallingConvention ()
- {
- // For now this is the only correc thing to do
- return CallingConventions.Standard;
- }
-
- //
- // The method's attributes are passed in because we need to extract
- // the "return:" attribute from there to apply on the return type
- //
- public void LabelParameters (EmitContext ec,
- MethodBase builder,
- Location loc) {
- //
- // Define each type attribute (in/out/ref) and
- // the argument names.
- //
- int i = 0;
-
- MethodBuilder mb = builder as MethodBuilder;
- ConstructorBuilder cb = builder as ConstructorBuilder;
+ public bool HasParams {
+ get {
+ if (count == 0)
+ return false;
- if (FixedParameters != null) {
- for (i = 0; i < FixedParameters.Length; i++) {
- FixedParameters [i].DefineParameter (ec, mb, cb, i + 1, loc);
- }
+ return FixedParameters [count - 1] is ParamsParameter;
}
+ }
- if (ArrayParameter != null){
- ParameterBuilder pb;
- Parameter array_param = ArrayParameter;
+ public string ParameterName (int pos)
+ {
+ return this [pos].Name;
+ }
- if (mb == null)
- pb = cb.DefineParameter (
- i + 1, array_param.Attributes,
- array_param.Name);
- else
- pb = mb.DefineParameter (
- i + 1, array_param.Attributes,
- array_param.Name);
-
- CustomAttributeBuilder a = new CustomAttributeBuilder (
- TypeManager.cons_param_array_attribute, new object [0]);
-
- pb.SetCustomAttribute (a);
- }
+ public string ParameterDesc (int pos)
+ {
+ return this [pos].GetSignatureForError ();
}
+
+ public Parameter.Modifier ParameterModifier (int pos)
+ {
+ return this [pos].ModFlags;
+ }
+
+ #endregion
}
}