if (TypeManager.IsValueType (probe_type)){
Report.Error (77, loc, "The as operator should be used with a reference type only (" +
- TypeManager.MonoBASIC_Name (probe_type) + " is a value type");
+ TypeManager.MonoBASIC_Name (probe_type) + " is a value type)");
return null;
}
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;
}
if (method == null)
{
- Error (-6,
- "Could not find any applicable function for this argument list");
+ Error (30455,
+ "Could not find any applicable function to invoke for this argument list");
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 (type.IsInterface || type.IsAbstract){
Error (
- 144, "It is not possible to create instances of interfaces " +
- "or abstract classes");
+ 30376, "It is not possible to create instances of Interfaces " +
+ "or classes marked as MustInherit");
return null;
}
void Error_IncorrectArrayInitializer ()
{
- Error (178, "Incorrectly structured array initializer");
+ Error (30567, "Incorrectly structured array initializer");
}
public bool CheckIndices (EmitContext ec, ArrayList probe, int idx, bool specified_dims)
Enum en = TypeManager.LookupEnum (decl_type);
Constant c;
- if (en != null)
+ if (en != null) {
c = Constantify (o, en.UnderlyingType);
- else
+ return new EnumConstant (c, en.UnderlyingType);
+ }
+ else {
c = Constantify (o, enum_member.Type);
+ return new EnumConstant (c, enum_member.Type);
+ }
+
- return new EnumConstant (c, decl_type);
}
Expression exp = Constantify (o, t);
if (IdenticalNameAndTypeName (ec, left_original, loc))
return member_lookup;
- if (left_is_explicit) {
+ /*if (left_is_explicit) {
error176 (loc, me.Name);
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);
}
- //
- // TODO: I mailed Ravi about this, and apparently we can get rid
- // of this and put it in the right place.
- //
- // Handle enums here when they are in transit.
- // Note that we cannot afford to hit MemberLookup in this case because
- // it will fail to find any members at all
- //
-
int errors = Report.Errors;
Type expr_type = expr.Type;
- if ((expr is TypeExpr) && (expr_type.IsSubclassOf (TypeManager.enum_type))){
-
- Enum en = TypeManager.LookupEnum (expr_type);
-
- if (en != null) {
- object value = en.LookupEnumValue (ec, Identifier, loc);
-
- if (value != null){
- Constant c = Constantify (value, en.UnderlyingType);
- return new EnumConstant (c, expr_type);
- }
- }
- }
if (expr_type.IsPointer){
Error (23, "The '.' operator can not be applied to pointer operands (" +
BindingFlags.NonPublic, Identifier);
if (lookup == null)
- Error (117, "'" + expr_type + "' does not contain a definition for '" + Identifier + "'");
+ Error (30456, "'" + expr_type + "' does not contain a definition for '" + Identifier + "'");
else
{
if ((expr_type != ec.ContainerType) &&
"qualifier must be of type '" + TypeManager.MonoBASIC_Name (ec.ContainerType) + "' " +
"(or derived from it)");
else
- Error (122, "'" + expr_type + "." + Identifier + "' " +
+ Error (30390, "'" + expr_type + "." + Identifier + "' " +
"is inaccessible because of its protection level");
} else
- Error (122, "'" + expr_type + "." + Identifier + "' " +
+ Error (30390, "'" + expr_type + "." + Identifier + "' " +
"is inaccessible because of its protection level");
}
return null;
}
+ if ((expr is TypeExpr) && (expr_type.IsSubclassOf (TypeManager.enum_type))) {
+ Enum en = TypeManager.LookupEnum (expr_type);
+
+ if (en != null) {
+ object value = en.LookupEnumValue (ec, Identifier, loc);
+ expr_type = TypeManager.int32_type;
+ if (value != null) {
+ Constant c = Constantify (value, en.UnderlyingType);
+ return new EnumConstant (c, en.UnderlyingType);
+ }
+ }
+ }
+
if (member_lookup is TypeExpr){
member_lookup.Resolve (ec, ResolveFlags.Type);
+
return member_lookup;
} else if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type)
return null;
// The following DoResolve/DoResolveLValue will do the definite assignment
// check.
-
if (right_side != null)
member_lookup = member_lookup.DoResolveLValue (ec, right_side);
else
AllMemberTypes, AllBindingFlags, loc);
if (member_lookup == null) {
- Error (117,
+ Error (30456,
TypeManager.MonoBASIC_Name (base_type) + " does not " +
"contain a definition for '" + member + "'");
return null;