public class Cast : Expression {
Expression target_type;
Expression expr;
+ bool runtime_cast;
public Cast (Expression cast_type, Expression expr, Location loc)
{
this.target_type = cast_type;
this.expr = expr;
this.loc = loc;
+ runtime_cast = false;
}
public Expression TargetType {
}
}
+ public bool IsRuntimeCast\r
+ {
+ get {
+ return runtime_cast;
+ }
+ set{
+ runtime_cast = value;
+ }
+ }
+
/// <summary>
/// Attempts to do a compile-time folding of a constant cast.
/// </summary>
int errors = Report.Errors;
type = ec.DeclSpace.ResolveType (target_type, false, Location);
-
+
if (type == null)
return null;
return e;
}
- expr = ConvertExplicit (ec, expr, type, loc);
+ expr = ConvertExplicit (ec, expr, type, runtime_cast, loc);
return expr;
}
~(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 (a_mod == Parameter.Modifier.NONE)
if (! (ImplicitConversionExists (ec, a.Expr, ptype) || RuntimeConversionExists (ec, a.Expr, ptype)) )
return false;
ParameterData pd = GetParameterData (candidate);
Parameters ps = GetFullParameters (candidate);
-
if (ps == null) {
ps_count = 0;
po_count = 0;
}
- else
- {
+ else {
ps_count = ps.CountStandardParams();
po_count = ps.CountOptionalParams();
}
if (arg_count != pd.Count)
return false;
}
- else
- {
+ else {
if ((arg_count < ps_count) || (arg_count > pd_count))
return false;
}
i--;
Argument a = (Argument) arguments [i];
- if (a.ArgType == Argument.AType.NoArg)
- {
+ if (a.ArgType == Argument.AType.NoArg) {
Parameter p = (Parameter) ps.FixedParameters[i];
a = new Argument (p.ParameterInitializer, Argument.AType.Expression);
param_type = p.ParameterInitializer.Type;
}
- else
- {
+ else {
param_type = pd.ParameterType (i);
if (ps != null) {
Parameter p = (Parameter) ps.FixedParameters[i];
-
- if ((p.ModFlags & Parameter.Modifier.REF) != 0)
- {
+ bool IsDelegate = TypeManager.IsDelegateType (param_type);
+
+ if (IsDelegate) {
+ if (a.ArgType == Argument.AType.AddressOf) {
+ a = new Argument ((Expression) a.Expr, Argument.AType.Expression);
+ ArrayList args = new ArrayList();
+ args.Add (a);
+ string param_name = pd.ParameterDesc(i).Replace('+', '.');
+ Expression pname = MonoBASIC.Parser.DecomposeQI (param_name, Location.Null);
+
+
+ New temp_new = new New ((Expression)pname, args, Location.Null);
+ Expression del_temp = temp_new.DoResolve(ec);
+
+ if (del_temp == null)
+ return false;
+
+ a = new Argument (del_temp, Argument.AType.Expression);
+ if (!a.Resolve(ec, Location.Null))\r
+ return false;
+ }
+ }
+ else {
+ if (a.ArgType == Argument.AType.AddressOf)
+ return false;
+ }
+
+ if ((p.ModFlags & Parameter.Modifier.REF) != 0) {
a = new Argument (a.Expr, Argument.AType.Ref);
if (!a.Resolve(ec,Location.Null))
return false;
}
}
}
-
+\r
if (!CheckParameterAgainstArgument (ec, pd, i, a, param_type))
return (false);
}
}
- else
- {
+ else {
// If we have no arguments AND the first parameter is optional
// we must check for a candidate (the loop above wouldn't)
if (po_count > 0) {
}
// We've found a candidate, so we exchange the dummy NoArg arguments
// with new arguments containing the default value for that parameter
+
ArrayList newarglist = new ArrayList();
for (int i = 0; i < arg_count; i++) {
Argument a = (Argument) arguments [i];
if (a.ArgType == Argument.AType.NoArg){
a = new Argument (p.ParameterInitializer, Argument.AType.Expression);
a.Resolve(ec, Location.Null);
- }
-
- if ((p != null) && ((p.ModFlags & Parameter.Modifier.REF) != 0))
- {
+ }
+
+ // ToDo - This part is getting resolved second time within this function
+ // This is a costly operation
+ // The earlier resoved result should be used here.
+ // Has to be done during compiler optimization.
+ if (a.ArgType == Argument.AType.AddressOf) {
+ param_type = pd.ParameterType (i);
+ bool IsDelegate = TypeManager.IsDelegateType (param_type);
+
+ a = new Argument ((Expression) a.Expr, Argument.AType.Expression);
+ ArrayList args = new ArrayList();
+ args.Add (a);
+ string param_name = pd.ParameterDesc(i).Replace('+', '.');
+ Expression pname = MonoBASIC.Parser.DecomposeQI (param_name, Location.Null);
+
+ New temp_new = new New ((Expression)pname, args, Location.Null);
+ Expression del_temp = temp_new.DoResolve(ec);
+
+ if (del_temp == null)
+ return false;
+
+ a = new Argument (del_temp, Argument.AType.Expression);
+ if (!a.Resolve(ec, Location.Null))\r
+ return false;
+ }
+
+ if ((p != null) && ((p.ModFlags & Parameter.Modifier.REF) != 0)) {
a.ArgType = Argument.AType.Ref;
a.Resolve(ec, Location.Null);
}
newarglist.Add(a);
int n = pd_count - arg_count;
- if (n > 0)
- {
- for (int x = 0; x < n; x++)
- {
+ if (n > 0) {
+ for (int x = 0; x < n; x++) {
Parameter op = (Parameter) ps.FixedParameters[x + arg_count];
Argument b = new Argument (op.ParameterInitializer, Argument.AType.Expression);
b.Resolve(ec, Location.Null);
{
if ((a.ArgType == Argument.AType.NoArg) && (!(expr is MethodGroupExpr)))
Report.Error (999, "This item cannot have empty arguments");
-
+
+
if (!a.Resolve (ec, loc))
return null;
}
//
Expression value_target;
bool value_target_set = false;
+ public bool isDelegate = false;
public New (Expression requested_type, ArrayList arguments, Location l)
{
public override Expression DoResolve (EmitContext ec)
{
- type = ec.DeclSpace.ResolveType (RequestedType, false, loc);
+ if (this.isDelegate) {
+ // if its a delegate resolve the type of RequestedType first
+ Expression dtype = RequestedType.Resolve(ec);
+ string ts = (dtype.Type.ToString()).Replace ('+','.');
+ dtype = Mono.MonoBASIC.Parser.DecomposeQI (ts, Location.Null);
+
+ type = ec.DeclSpace.ResolveType (dtype, false, loc);
+ }
+ else
+ type = ec.DeclSpace.ResolveType (RequestedType, false, loc);
if (type == null)
return null;
if (expr is SimpleName){
SimpleName child_expr = (SimpleName) expr;
-
+
Expression new_expr = new SimpleName (child_expr.Name + "." + Identifier, loc);
- return new_expr.Resolve (ec, flags);
+ if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type)
+ return new_expr.Resolve (ec, flags);
+ else
+ return new_expr.Resolve (ec, flags | ResolveFlags.MethodGroup | ResolveFlags.VariableOrValue);
}
int errors = Report.Errors;