diff options
Diffstat (limited to 'mcs/mcs/parameter.cs')
-rw-r--r-- | mcs/mcs/parameter.cs | 106 |
1 files changed, 28 insertions, 78 deletions
diff --git a/mcs/mcs/parameter.cs b/mcs/mcs/parameter.cs index 8d441b138d7..9d782796cb2 100644 --- a/mcs/mcs/parameter.cs +++ b/mcs/mcs/parameter.cs @@ -24,10 +24,12 @@ namespace Mono.CSharp { public abstract class ParameterBase : Attributable { protected ParameterBuilder builder; + public readonly Location Location; - protected ParameterBase (Attributes attrs) + protected ParameterBase (Attributes attrs, Location loc) : base (attrs) { + Location = loc; } public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb) @@ -48,7 +50,7 @@ namespace Mono.CSharp { builder.SetCustomAttribute (cb); } - public override bool IsClsComplianceRequired() + public override bool IsClsComplianceRequired(DeclSpace ds) { return false; } @@ -59,13 +61,13 @@ namespace Mono.CSharp { /// </summary> public class ReturnParameter : ParameterBase { public ReturnParameter (MethodBuilder mb, Location location): - base (null) + base (null, location) { try { builder = mb.DefineParameter (0, ParameterAttributes.None, ""); } catch (ArgumentOutOfRangeException) { - Report.RuntimeMissingSupport (location, "custom attributes on the return type"); + Report.RuntimeMissingSupport (Location, "custom attributes on the return type"); } } @@ -88,12 +90,6 @@ namespace Mono.CSharp { } } - public override IResolveContext ResolveContext { - get { - throw new NotSupportedException (); - } - } - /// <summary> /// Is never called /// </summary> @@ -111,8 +107,8 @@ namespace Mono.CSharp { /// // TODO: should use more code from Parameter.ApplyAttributeBuilder public class ImplicitParameter : ParameterBase { - public ImplicitParameter (MethodBuilder mb): - base (null) + public ImplicitParameter (MethodBuilder mb, Location loc): + base (null, loc) { builder = mb.DefineParameter (1, ParameterAttributes.None, ""); } @@ -123,12 +119,6 @@ namespace Mono.CSharp { } } - public override IResolveContext ResolveContext { - get { - throw new NotSupportedException (); - } - } - /// <summary> /// Is never called /// </summary> @@ -145,7 +135,7 @@ namespace Mono.CSharp { { } - public override bool Resolve (IResolveContext ec) + public override bool Resolve (EmitContext ec) { if (!base.Resolve (ec)) return false; @@ -157,9 +147,9 @@ namespace Mono.CSharp { return true; } - public override void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index) + public override void ApplyAttributes (EmitContext ec, MethodBuilder mb, ConstructorBuilder cb, int index) { - base.ApplyAttributes (mb, cb, index); + base.ApplyAttributes (ec, mb, cb, index); CustomAttributeBuilder a = new CustomAttributeBuilder ( TypeManager.ConsParamArrayAttribute, new object [0]); @@ -175,7 +165,7 @@ namespace Mono.CSharp { { } - public override bool Resolve (IResolveContext ec) + public override bool Resolve (EmitContext ec) { return true; } @@ -207,28 +197,25 @@ namespace Mono.CSharp { public Expression TypeName; public readonly Modifier ModFlags; - public string Name; + public readonly string Name; protected Type parameter_type; - public readonly Location Location; - IResolveContext resolve_context; + EmitContext ec; // because ApplyAtrribute doesn't have ec public Parameter (Expression type, string name, Modifier mod, Attributes attrs, Location loc) - : base (attrs) + : base (attrs, loc) { Name = name; ModFlags = mod; TypeName = type; - Location = loc; } public Parameter (Type type, string name, Modifier mod, Attributes attrs, Location loc) - : base (attrs) + : base (attrs, loc) { Name = name; ModFlags = mod; parameter_type = type; - Location = loc; } public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb) @@ -244,7 +231,7 @@ namespace Mono.CSharp { } if (a.Type == TypeManager.out_attribute_type && (ModFlags & Modifier.REF) == Modifier.REF && - !OptAttributes.Contains (TypeManager.in_attribute_type)) { + !OptAttributes.Contains (TypeManager.in_attribute_type, ec)) { Report.Error (662, a.Location, "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither"); return; @@ -257,27 +244,21 @@ namespace Mono.CSharp { base.ApplyAttributeBuilder (a, cb); } - public override IResolveContext ResolveContext { - get { - return resolve_context; - } - } - // <summary> // Resolve is used in method definitions // </summary> - public virtual bool Resolve (IResolveContext ec) + public virtual bool Resolve (EmitContext ec) { if (parameter_type != null) return true; - this.resolve_context = ec; + this.ec = ec; TypeExpr texpr = TypeName.ResolveAsTypeTerminal (ec, false); if (texpr == null) return false; - parameter_type = texpr.Type; + parameter_type = texpr.ResolveType (ec); if (parameter_type.IsAbstract && parameter_type.IsSealed) { Report.Error (721, Location, "`{0}': static types cannot be used as parameters", GetSignatureForError ()); @@ -377,7 +358,7 @@ namespace Mono.CSharp { Report.Error (3001, Location, "Argument type `{0}' is not CLS-compliant", GetSignatureForError ()); } - public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index) + public virtual void ApplyAttributes (EmitContext ec, MethodBuilder mb, ConstructorBuilder cb, int index) { if (mb == null) builder = cb.DefineParameter (index, Attributes, Name); @@ -385,7 +366,7 @@ namespace Mono.CSharp { builder = mb.DefineParameter (index, Attributes, Name); if (OptAttributes != null) - OptAttributes.Emit (); + OptAttributes.Emit (ec, this); } public override string[] ValidAttributeTargets { @@ -413,15 +394,8 @@ namespace Mono.CSharp { 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[] parameters) + public Parameters (Parameter [] parameters) { if (parameters == null) throw new ArgumentException ("Use EmptyReadOnlyPatameters"); @@ -436,31 +410,6 @@ namespace Mono.CSharp { HasArglist = has_arglist; } - /// <summary> - /// Use this method when you merge compiler generated argument with user arguments - /// </summary> - 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 count == 0; @@ -522,15 +471,16 @@ namespace Mono.CSharp { return GetParameterByName (name, out idx); } - public bool Resolve (IResolveContext ec) + public bool Resolve (EmitContext ec) { if (types != null) return true; types = new Type [count]; - if (!VerifyArgs ()) + if (ec != null && !VerifyArgs ()){ return false; + } bool ok = true; Parameter p; @@ -558,7 +508,7 @@ namespace Mono.CSharp { // Define each type attribute (in/out/ref) and // the argument names. - public void ApplyAttributes (MethodBase builder) + public void ApplyAttributes (EmitContext ec, MethodBase builder) { if (count == 0) return; @@ -567,7 +517,7 @@ namespace Mono.CSharp { ConstructorBuilder cb = builder as ConstructorBuilder; for (int i = 0; i < FixedParameters.Length; i++) { - FixedParameters [i].ApplyAttributes (mb, cb, i + 1); + FixedParameters [i].ApplyAttributes (ec, mb, cb, i + 1); } } |