public override Expression DoResolve (EmitContext ec)
{
- if (left == null)
- return null;
-
if ((oper == Operator.Subtraction) && (left is ParenthesizedExpression)) {
left = ((ParenthesizedExpression) left).Expr;
left = left.Resolve (ec, ResolveFlags.VariableOrValue | ResolveFlags.Type);
/// representation.
/// </summary>
public class ParameterReference : Expression, IAssignMethod, IMemoryLocation, IVariable {
- Parameter par;
- string name;
+ Parameters pars;
+ String name;
int idx;
Block block;
VariableInfo vi;
+ public Parameter.Modifier mod;
public bool is_ref, is_out, prepared;
public bool IsOut {
LocalTemporary temp;
- public ParameterReference (Parameter par, Block block, int idx, Location loc)
+ public ParameterReference (Parameters pars, Block block, int idx, string name, Location loc)
{
- this.par = par;
- this.name = par.Name;
+ this.pars = pars;
this.block = block;
this.idx = idx;
+ this.name = name;
this.loc = loc;
eclass = ExprClass.Variable;
}
+ public ParameterReference (InternalParameters pars, Block block, int idx, Location loc)
+ : this (pars.Parameters, block, idx, pars.ParameterName (idx), loc)
+ { }
+
public VariableInfo VariableInfo {
get { return vi; }
}
public bool VerifyFixed ()
{
// A parameter is fixed if it's a value parameter (i.e., no modifier like out, ref, param).
- return par.ModFlags == Parameter.Modifier.NONE;
+ return mod == Parameter.Modifier.NONE;
}
public bool IsAssigned (EmitContext ec, Location loc)
return true;
Report.Error (269, loc,
- "Use of unassigned out parameter `{0}'", par.Name);
+ "Use of unassigned out parameter `{0}'", name);
return false;
}
protected void DoResolveBase (EmitContext ec)
{
- if (!par.Resolve (ec)) {
- //TODO:
- }
-
- type = par.ParameterType;
- Parameter.Modifier mod = par.ModFlags;
+ type = pars.GetParameterInfo (ec, idx, out mod);
is_ref = (mod & Parameter.Modifier.ISBYREF) != 0;
- is_out = (mod & Parameter.Modifier.OUT) == Parameter.Modifier.OUT;
+ is_out = (mod & Parameter.Modifier.OUT) != 0;
eclass = ExprClass.Variable;
if (is_out)
if (ec.CurrentAnonymousMethod != null){
if (is_ref){
Report.Error (1628, Location, "Cannot use ref or out parameter `{0}' inside an anonymous method block",
- par.Name);
+ name);
return;
}
ILGenerator ig = ec.ig;
int arg_idx = idx;
- if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
- ec.EmitParameter (name, leave_copy, prepared, ref temp);
+ if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
+ if (leave_copy)
+ throw new InternalErrorException ();
+
+ ec.EmitParameter (name);
return;
}
public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
- prepared = prepare_for_load;
if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
- ec.EmitAssignParameter (name, source, leave_copy, prepare_for_load, ref temp);
+ ec.EmitAssignParameter (name, source, leave_copy, prepare_for_load);
return;
}
ILGenerator ig = ec.ig;
int arg_idx = idx;
-
+ prepared = prepare_for_load;
if (!ec.MethodIsStatic)
arg_idx++;
get {
switch (ArgType) {
case AType.Out:
- return Parameter.Modifier.OUT;
+ return Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF;
case AType.Ref:
- return Parameter.Modifier.REF;
+ return Parameter.Modifier.REF | Parameter.Modifier.ISBYREF;
default:
return Parameter.Modifier.NONE;
if (pd_count != arg_count)
return false;
} else {
- if (!pd.HasParams)
+ if (pd.ParameterModifier (count) != Parameter.Modifier.PARAMS)
return false;
}
Argument a = (Argument) arguments [i];
Parameter.Modifier a_mod = a.Modifier &
- (unchecked (~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK)));
+ (unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF)));
Parameter.Modifier p_mod = pd.ParameterModifier (i) &
- (unchecked (~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK)));
+ (unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF)));
if (a_mod == p_mod) {
if (!Convert.ImplicitConversionExists (ec,
a.Expr,
pd.ParameterType (i)))
- return false;
-
+ return false;
+
if ((a_mod & Parameter.Modifier.ISBYREF) != 0) {
Type pt = pd.ParameterType (i);
/// Determines if the candidate method is applicable (section 14.4.2.1)
/// to the given set of arguments
/// </summary>
- public static bool IsApplicable (EmitContext ec, ArrayList arguments, int arg_count,
- MethodBase candidate)
+ static bool IsApplicable (EmitContext ec, ArrayList arguments, int arg_count,
+ MethodBase candidate)
{
ParameterData pd = TypeManager.GetParameterData (candidate);
Argument a = (Argument) arguments [i];
Parameter.Modifier a_mod = a.Modifier &
- ~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK);
-
+ unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF));
Parameter.Modifier p_mod = pd.ParameterModifier (i) &
- ~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK | Parameter.Modifier.PARAMS);
-
- if (a_mod == p_mod) {
- Type pt = pd.ParameterType (i);
+ unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF));
+ if (a_mod == p_mod ||
+ (a_mod == Parameter.Modifier.NONE && p_mod == Parameter.Modifier.PARAMS)) {
if (a_mod == Parameter.Modifier.NONE) {
- if (!TypeManager.IsEqual (a.Type, pt) &&
- !Convert.ImplicitConversionExists (ec, a.Expr, pt))
+ if (!TypeManager.IsEqual (a.Type, pd.ParameterType (i)) && !Convert.ImplicitConversionExists (ec,
+ a.Expr,
+ pd.ParameterType (i)))
return false;
- continue;
- }
+ }
- if (pt != a.Type)
- return false;
+ if ((a_mod & Parameter.Modifier.ISBYREF) != 0) {
+ Type pt = pd.ParameterType (i);
+
+ if (!pt.IsByRef)
+ pt = TypeManager.GetReferenceType (pt);
+
+ if (pt != a.Type)
+ return false;
+ }
} else
return false;
}
return true;
}
- static internal bool IsAncestralType (Type first_type, Type second_type)
+ static private bool IsAncestralType (Type first_type, Type second_type)
{
return first_type != second_type &&
(second_type.IsSubclassOf (first_type) ||
method_params, null, may_fail, loc))
return null;
- if (method == null)
- return null;
-
- MethodBase the_method = method;
- if (the_method.Mono_IsInflatedMethod) {
- the_method = the_method.GetGenericMethodDefinition ();
-
- if ((method is MethodInfo) &&
- !ConstraintChecker.CheckConstraints (ec, the_method, method, loc))
- return null;
+ if (method != null) {
+ MethodBase the_method = method;
+ if (the_method.Mono_IsInflatedMethod)
+ the_method = the_method.GetGenericMethodDefinition ();
+ IMethodData data = TypeManager.GetMethod (the_method);
+ if (data != null)
+ data.SetMemberIsUsed ();
}
-
- IMethodData data = TypeManager.GetMethod (the_method);
- if (data != null)
- data.SetMemberIsUsed ();
-
return method;
}
if (array_type_expr == null)
return false;
- type = array_type_expr.ResolveType (ec);
+ type = array_type_expr.ResolveType (ec);
+
+ if (!type.IsArray) {
+ Error (622, "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
+ return false;
+ }
underlying_type = TypeManager.GetElementType (type);
dimensions = type.GetArrayRank ();