ISBYREF = 8,
REFMASK = 32,
OUTMASK = 64,
+ SignatureMask = REFMASK | OUTMASK,
This = 128
}
get {
return parameter_type;
}
+ set {
+ parameter_type = value;
+ }
}
public FullNamedExpression TypeExpression {
if (attributes != null)
attributes.AttachTo (this, rc);
- var expr = texpr.ResolveAsTypeTerminal (rc, false);
- if (expr == null)
+ parameter_type = texpr.ResolveAsType (rc);
+ if (parameter_type == null)
return null;
this.idx = index;
- texpr = expr;
- parameter_type = texpr.Type;
if ((modFlags & Parameter.Modifier.ISBYREF) != 0 && parameter_type.IsSpecialRuntimeType) {
rc.Module.Compiler.Report.Error (1601, Location, "Method or delegate parameter cannot be of type `{0}'",
}
if (TypeSpecComparer.IsEqual (default_expr.Type, parameter_type) ||
- (default_expr is NullConstant && TypeManager.IsReferenceType (parameter_type) && !parameter_type.IsGenericParameter) ||
+ (default_expr is NullConstant && TypeSpec.IsReferenceType (parameter_type) && !parameter_type.IsGenericParameter) ||
parameter_type.BuiltinType == BuiltinTypeSpec.Type.Object) {
return;
}
}
}
+ public void Error_DuplicateName (Report r)
+ {
+ r.Error (100, Location, "The parameter name `{0}' is a duplicate", Name);
+ }
+
public virtual string GetSignatureForError ()
{
string type_name;
var def_value = DefaultValue;
Constant c = def_value != null ? def_value.Child as Constant : default_expr as Constant;
if (c != null) {
- if (default_expr.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
+ if (c.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
pa.DecimalConstant.EmitAttribute (builder, (decimal) c.GetValue (), c.Location);
} else {
builder.SetConstant (c.GetValue ());
expr_tree_variable = (TemporaryVariableReference) expr_tree_variable.Resolve (ec);
Arguments arguments = new Arguments (2);
- arguments.Add (new Argument (new TypeOf (
- new TypeExpression (parameter_type, Location), Location)));
+ arguments.Add (new Argument (new TypeOf (parameter_type, Location)));
arguments.Add (new Argument (new StringConstant (ec.BuiltinTypes, Name, Location)));
return new SimpleAssign (ExpressionTreeVariableReference (),
Expression.CreateExpressionFactoryCall (ec, "Parameter", null, arguments, Location));
public void Emit (EmitContext ec)
{
- int arg_idx = idx;
- if (!ec.IsStatic)
- arg_idx++;
-
- ParameterReference.EmitLdArg (ec, arg_idx);
+ ec.EmitArgumentLoad (idx);
}
public void EmitAssign (EmitContext ec)
{
- int arg_idx = idx;
- if (!ec.IsStatic)
- arg_idx++;
-
- if (arg_idx <= 255)
- ec.Emit (OpCodes.Starg_S, (byte) arg_idx);
- else
- ec.Emit (OpCodes.Starg, arg_idx);
+ ec.EmitArgumentStore (idx);
}
public void EmitAddressOf (EmitContext ec)
{
- int arg_idx = idx;
-
- if (!ec.IsStatic)
- arg_idx++;
-
- bool is_ref = (ModFlags & Modifier.ISBYREF) != 0;
- if (is_ref) {
- ParameterReference.EmitLdArg (ec, arg_idx);
+ if ((ModFlags & Modifier.ISBYREF) != 0) {
+ ec.EmitArgumentLoad (idx);
} else {
- if (arg_idx <= 255)
- ec.Emit (OpCodes.Ldarga_S, (byte) arg_idx);
- else
- ec.Emit (OpCodes.Ldarga, arg_idx);
+ ec.EmitArgumentAddress (idx);
}
}
//
public static TypeExpr ResolveParameterExpressionType (IMemberContext ec, Location location)
{
- TypeSpec p_type = ec.Module.PredefinedTypes.ParameterExpression.Resolve (location);
+ TypeSpec p_type = ec.Module.PredefinedTypes.ParameterExpression.Resolve ();
return new TypeExpression (p_type, location);
}
return -1;
}
+ public string GetSignatureForDocumentation ()
+ {
+ if (IsEmpty)
+ return string.Empty;
+
+ StringBuilder sb = new StringBuilder ("(");
+ for (int i = 0; i < Count; ++i) {
+ if (i != 0)
+ sb.Append (",");
+
+ sb.Append (types [i].GetSignatureForDocumentation ());
+
+ if ((parameters[i].ModFlags & Parameter.Modifier.ISBYREF) != 0)
+ sb.Append ("@");
+ }
+ sb.Append (")");
+
+ return sb.ToString ();
+ }
+
public string GetSignatureForError ()
{
return GetSignatureForError ("(", ")", Count);
null);
}
+ public void CheckConstraints (IMemberContext mc)
+ {
+ foreach (Parameter p in parameters) {
+ //
+ // It's null for compiler generated types or special types like __arglist
+ //
+ if (p.TypeExpression != null)
+ ConstraintChecker.Check (mc, p.Type, p.TypeExpression.Location);
+ }
+ }
+
//
// Returns non-zero value for equal CLS parameter signatures
//
return parameters;
}
+ //
+ // Parameters checks for members which don't have a block
+ //
+ public void CheckParameters (MemberCore member)
+ {
+ for (int i = 0; i < parameters.Length; ++i) {
+ var name = parameters[i].Name;
+ for (int ii = i + 1; ii < parameters.Length; ++ii) {
+ if (parameters[ii].Name == name)
+ this[ii].Error_DuplicateName (member.Compiler.Report);
+ }
+ }
+ }
+
public bool Resolve (IMemberContext ec)
{
if (types != null)
}
}
- if (!expr.IsNull && TypeManager.IsReferenceType (parameter_type) && parameter_type.BuiltinType != BuiltinTypeSpec.Type.String) {
+ if (!expr.IsNull && TypeSpec.IsReferenceType (parameter_type) && parameter_type.BuiltinType != BuiltinTypeSpec.Type.String) {
rc.Report.Error (1763, Location,
"Optional parameter `{0}' of type `{1}' can only be initialized with `null'",
p.Name, parameter_type.GetSignatureForError ());