//
// Author:
// Miguel de Icaza (miguel@ximian.com)
+// Marek Safar (marek.safar@seznam.cz)
//
// (C) 2001, 2002, 2003 Ximian, Inc.
// (C) 2003, 2004 Novell, Inc.
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 {
- Parameters pars;
- String name;
+ Parameter par;
+ 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 (Parameters pars, Block block, int idx, string name, Location loc)
+ public ParameterReference (Parameter par, Block block, int idx, Location loc)
{
- this.pars = pars;
+ this.par = par;
+ this.name = par.Name;
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 mod == Parameter.Modifier.NONE;
+ return par.ModFlags == Parameter.Modifier.NONE;
}
public bool IsAssigned (EmitContext ec, Location loc)
return true;
Report.Error (269, loc,
- "Use of unassigned out parameter `{0}'", name);
+ "Use of unassigned out parameter `{0}'", par.Name);
return false;
}
protected void DoResolveBase (EmitContext ec)
{
- type = pars.GetParameterInfo (ec, idx, out mod);
+ if (!par.Resolve (ec)) {
+ //TODO:
+ }
+
+ type = par.ParameterType;
+ Parameter.Modifier mod = par.ModFlags;
is_ref = (mod & Parameter.Modifier.ISBYREF) != 0;
- is_out = (mod & Parameter.Modifier.OUT) != 0;
+ is_out = (mod & Parameter.Modifier.OUT) == Parameter.Modifier.OUT;
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",
- name);
+ par.Name);
return;
}
ILGenerator ig = ec.ig;
int arg_idx = idx;
- if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
- if (leave_copy)
- throw new InternalErrorException ();
-
- ec.EmitParameter (name);
+ if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
+ ec.EmitParameter (name, leave_copy, prepared, ref temp);
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);
+ ec.EmitAssignParameter (name, source, leave_copy, prepare_for_load, ref temp);
return;
}
ILGenerator ig = ec.ig;
int arg_idx = idx;
- prepared = prepare_for_load;
+
if (!ec.MethodIsStatic)
arg_idx++;
}
}
+ public override string ToString ()
+ {
+ return "ParameterReference[" + name + "]";
+ }
}
/// <summary>
get {
switch (ArgType) {
case AType.Out:
- return Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF;
+ return Parameter.Modifier.OUT;
case AType.Ref:
- return Parameter.Modifier.REF | Parameter.Modifier.ISBYREF;
+ return Parameter.Modifier.REF;
default:
return Parameter.Modifier.NONE;
return !candidate_params && best_params;
}
- static bool IsOverride (MethodBase cand_method, MethodBase base_method)
+ internal static bool IsOverride (MethodBase cand_method, MethodBase base_method)
{
if (!IsAncestralType (base_method.DeclaringType, cand_method.DeclaringType))
return false;
return union;
}
- public static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
+ public static bool IsParamsMethodApplicable (EmitContext ec,
ArrayList arguments, int arg_count,
- ref MethodBase candidate)
+ MethodBase candidate)
{
return IsParamsMethodApplicable (
- ec, me, arguments, arg_count, false, ref candidate) ||
+ ec, arguments, arg_count, candidate, false) ||
IsParamsMethodApplicable (
- ec, me, arguments, arg_count, true, ref candidate);
+ ec, arguments, arg_count, candidate, true);
}
- static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
- ArrayList arguments, int arg_count,
- bool do_varargs, ref MethodBase candidate)
- {
- return IsParamsMethodApplicable (
- ec, arguments, arg_count, candidate, do_varargs);
- }
-
/// <summary>
/// Determines if the candidate method, if a params method, is applicable
/// in its expanded form to the given set of arguments
if (pd_count != arg_count)
return false;
} else {
- if (pd.ParameterModifier (count) != Parameter.Modifier.PARAMS)
+ if (!pd.HasParams)
return false;
}
Argument a = (Argument) arguments [i];
Parameter.Modifier a_mod = a.Modifier &
- (unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF)));
+ (unchecked (~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK)));
Parameter.Modifier p_mod = pd.ParameterModifier (i) &
- (unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF)));
+ (unchecked (~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK)));
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);
return true;
}
- public static bool IsApplicable (EmitContext ec, MethodGroupExpr me,
- ArrayList arguments, int arg_count,
- ref MethodBase candidate)
- {
- return IsApplicable (ec, arguments, arg_count, candidate);
- }
-
/// <summary>
/// Determines if the candidate method is applicable (section 14.4.2.1)
/// to the given set of arguments
/// </summary>
- static bool IsApplicable (EmitContext ec, ArrayList arguments, int arg_count,
- MethodBase candidate)
+ public 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 &
- unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF));
+ ~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK);
+
Parameter.Modifier p_mod = pd.ParameterModifier (i) &
- unchecked (~(Parameter.Modifier.OUT | Parameter.Modifier.REF));
+ ~(Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK | Parameter.Modifier.PARAMS);
- if (a_mod == p_mod ||
- (a_mod == Parameter.Modifier.NONE && p_mod == Parameter.Modifier.PARAMS)) {
- if (a_mod == Parameter.Modifier.NONE) {
- if (!Convert.ImplicitConversionExists (ec,
- a.Expr,
- pd.ParameterType (i)))
- return false;
- }
-
- if ((a_mod & Parameter.Modifier.ISBYREF) != 0) {
- Type pt = pd.ParameterType (i);
+ if (a_mod == p_mod) {
+ Type pt = pd.ParameterType (i);
- if (!pt.IsByRef)
- pt = TypeManager.GetReferenceType (pt);
-
- if (pt != a.Type)
+ if (a_mod == Parameter.Modifier.NONE) {
+ if (!Convert.ImplicitConversionExists (ec, a.Expr, pt))
return false;
+ continue;
}
+
+ if (pt != a.Type)
+ return false;
} else
return false;
}
return true;
}
- static private bool IsAncestralType (Type first_type, Type second_type)
+ static internal bool IsAncestralType (Type first_type, Type second_type)
{
return first_type != second_type &&
(second_type.IsSubclassOf (first_type) ||
// Is candidate applicable in normal form?
//
bool is_applicable = IsApplicable (
- ec, me, Arguments, arg_count, ref methods [i]);
+ ec, Arguments, arg_count, methods [i]);
if (!is_applicable &&
(IsParamsMethodApplicable (
- ec, me, Arguments, arg_count, ref methods [i]))) {
+ ec, Arguments, arg_count, methods [i]))) {
MethodBase candidate = methods [i];
if (candidate_to_form == null)
candidate_to_form = new PtrHashtable ();
public static void Error_WrongNumArguments (Location loc, String name, int arg_count)
{
Report.Error (1501, loc, "No overload for method `{0}' takes `{1}' arguments",
- name, arg_count);
+ name, arg_count.ToString ());
}
static void Error_InvokeOnDelegate (Location loc)
Parameter.Modifier mod = expected_par.ParameterModifier (idx);
+ string index = (idx + 1).ToString ();
if (mod != Parameter.Modifier.ARGLIST && mod != a.Modifier) {
if ((mod & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) == 0)
Report.Error (1615, loc, "Argument `{0}' should not be passed with the `{1}' keyword",
- idx + 1, Parameter.GetModifierSignature (a.Modifier));
+ index, Parameter.GetModifierSignature (a.Modifier));
else
Report.Error (1620, loc, "Argument `{0}' must be passed with the `{1}' keyword",
- idx + 1, Parameter.GetModifierSignature (mod));
+ index, Parameter.GetModifierSignature (mod));
} else {
Report.Error (1503, loc, "Argument {0}: Cannot convert from `{1}' to `{2}'",
- idx + 1, Argument.FullDesc (a), expected_par.ParameterDesc (idx));
+ index, Argument.FullDesc (a), expected_par.ParameterDesc (idx));
}
}
return null;
}
+ //
+ // Checks whether the type is an interface that has the
+ // [ComImport, CoClass] attributes and must be treated
+ // specially
+ //
+ public Expression CheckComImport (EmitContext ec)
+ {
+ if (!type.IsInterface)
+ return null;
+
+ //
+ // Turn the call into:
+ // (the-interface-stated) (new class-referenced-in-coclassattribute ())
+ //
+ Type real_class = AttributeTester.GetCoClassAttribute (type);
+ if (real_class == null)
+ return null;
+
+ New proxy = new New (new TypeExpression (real_class, loc), Arguments, loc);
+ Cast cast = new Cast (new TypeExpression (type, loc), proxy, loc);
+ return cast.Resolve (ec);
+ }
+
public override Expression DoResolve (EmitContext ec)
{
//
}
if (type.IsInterface || type.IsAbstract){
+ RequestedType = CheckComImport (ec);
+ if (RequestedType != null)
+ return RequestedType;
+
Report.SymbolRelatedToPreviousError (type);
Report.Error (144, loc, "Cannot create an instance of the abstract class or interface `{0}'", TypeManager.CSharpName (type));
return null;
if (array_type_expr == null)
return false;
- 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;
- }
+ type = array_type_expr.ResolveType (ec);
underlying_type = TypeManager.GetElementType (type);
dimensions = type.GetArrayRank ();
{
FullNamedExpression new_expr = expr.ResolveAsTypeStep (ec, silent);
- if (new_expr == null) {
- Report.Error (234, "No such name or typespace {0}", expr);
+ if (new_expr == null)
return null;
- }
if (new_expr is Namespace) {
Namespace ns = (Namespace) new_expr;
Type t = ea.Expr.Type;
if (t.GetArrayRank () != ea.Arguments.Count){
Report.Error (22, ea.Location, "Wrong number of indexes `{0}' inside [], expected `{1}'",
- ea.Arguments.Count, t.GetArrayRank ());
+ ea.Arguments.Count.ToString (), t.GetArrayRank ().ToString ());
return null;
}
}
public override string Name {
- get {
- return left + dim;
- }
+ get { return left + dim; }
}
public override string FullName {
- get {
- return type.FullName;
- }
+ get { return type.FullName; }
+ }
+
+ public override string GetSignatureForError ()
+ {
+ return left.GetSignatureForError () + dim;
}
}