(other == TypeManager.int32_type) ||
(other == TypeManager.int64_type))
Error_OperatorAmbiguous (loc, oper, l, r);
- else {
- left = ForceConversion (ec, left, TypeManager.uint64_type);
- right = ForceConversion (ec, right, TypeManager.uint64_type);
- }
type = TypeManager.uint64_type;
} else if (IsOfType (ec, l, r, TypeManager.int64_type, check_user_conv)){
//
/// </summary>
static int BetterConversion (EmitContext ec, Argument a, Type p, Type q, Location loc)
{
- Type argument_type = TypeManager.TypeToCoreType (a.Type);
+ Type argument_type = a.Type;
Expression argument_expr = a.Expr;
- // p = TypeManager.TypeToCoreType (p);
- // q = TypeManager.TypeToCoreType (q);
-
if (argument_type == null)
throw new Exception ("Expression of type " + a.Expr +
" does not resolve its type");
if (argument_type == q)
return 0;
+ //
+ // Now probe whether an implicit constant expression conversion
+ // can be used.
+ //
+ // An implicit constant expression conversion permits the following
+ // conversions:
+ //
+ // * A constant-expression of type `int' can be converted to type
+ // sbyte, byute, short, ushort, uint, ulong provided the value of
+ // of the expression is withing the range of the destination type.
+ //
+ // * A constant-expression of type long can be converted to type
+ // ulong, provided the value of the constant expression is not negative
+ //
+ // FIXME: Note that this assumes that constant folding has
+ // taken place. We dont do constant folding yet.
+ //
+
+ if (argument_expr is IntConstant){
+ IntConstant ei = (IntConstant) argument_expr;
+ int value = ei.Value;
+
+ if (p == TypeManager.sbyte_type){
+ if (value >= SByte.MinValue && value <= SByte.MaxValue)
+ return 1;
+ } else if (p == TypeManager.byte_type){
+ if (q == TypeManager.sbyte_type &&
+ value >= SByte.MinValue && value <= SByte.MaxValue)
+ return 0;
+ else if (Byte.MinValue >= 0 && value <= Byte.MaxValue)
+ return 1;
+ } else if (p == TypeManager.short_type){
+ if (value >= Int16.MinValue && value <= Int16.MaxValue)
+ return 1;
+ } else if (p == TypeManager.ushort_type){
+ if (q == TypeManager.short_type &&
+ value >= Int16.MinValue && value <= Int16.MaxValue)
+ return 0;
+ else if (value >= UInt16.MinValue && value <= UInt16.MaxValue)
+ return 1;
+ } else if (p == TypeManager.int32_type){
+ if (value >= Int32.MinValue && value <= Int32.MaxValue)
+ return 1;
+ } else if (p == TypeManager.uint32_type){
+ //
+ // we can optimize this case: a positive int32
+ // always fits on a uint32
+ //
+ if (value >= 0)
+ return 1;
+ } else if (p == TypeManager.uint64_type){
+ //
+ // we can optimize this case: a positive int32
+ // always fits on a uint64
+ //
+
+ //
+ // This special case is needed because csc behaves like this.
+ // int -> uint is better than int -> ulong!
+ //
+ if (q == TypeManager.uint32_type)
+ return 0;
+
+ if (q == TypeManager.int64_type)
+ return 0;
+ else if (value >= 0)
+ return 1;
+ } else if (p == TypeManager.int64_type){
+ return 1;
+ }
+ } else if (argument_type == TypeManager.int64_type && argument_expr is LongConstant){
+ LongConstant lc = (LongConstant) argument_expr;
+
+ if (p == TypeManager.uint64_type){
+ if (lc.Value > 0)
+ return 1;
+ }
+ }
+
if (q == null) {
Expression tmp = Convert.ImplicitConversion (ec, argument_expr, p, loc);
/// 0 if candidate ain't better
/// 1 if candidate is better than the current best match
/// </remarks>
- static int BetterFunction (EmitContext ec, MethodGroupExpr me, ArrayList args,
+ static int BetterFunction (EmitContext ec, ArrayList args,
MethodBase candidate, bool candidate_params,
MethodBase best, bool best_params,
Location loc)
for (int j = 0; j < argument_count; ++j) {
Argument a = (Argument) args [j];
- Type t = TypeManager.TypeToCoreType (
- candidate_pd.ParameterType (j));
+ Type t = candidate_pd.ParameterType (j);
if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
if (candidate_params)
best_pd = GetParameterData (best);
int rating1 = 0, rating2 = 0;
-
+
for (int j = 0; j < argument_count; ++j) {
int x, y;
Argument a = (Argument) args [j];
- Type ct = TypeManager.TypeToCoreType (
- candidate_pd.ParameterType (j));
- Type bt = TypeManager.TypeToCoreType (
- best_pd.ParameterType (j));
+ Type ct = candidate_pd.ParameterType (j);
+ Type bt = best_pd.ParameterType (j);
if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
if (candidate_params)
if (method != null)
method_params = (bool) candidate_to_form [method];
- int x = BetterFunction (ec, me, Arguments,
+ int x = BetterFunction (ec, Arguments,
candidate, cand_params,
method, method_params,
loc);
// continue;
bool cand_params = (bool) candidate_to_form [candidate];
- int x = BetterFunction (ec, me, Arguments,
+ int x = BetterFunction (ec, Arguments,
method, best_params,
candidate, cand_params,
loc);
member_lookup = MemberLookup (
ec, expr_type, expr_type, Identifier, loc);
if ((member_lookup == null) && (args != null)) {
- string lookup_id = MemberName.MakeName (Identifier, args);
+ string lookup_id = Identifier + "!" + args.Count;
member_lookup = MemberLookup (
ec, expr_type, expr_type, lookup_id, loc);
}
else
fname = full_expr.Identifier;
- fname = MemberName.MakeName (fname, args);
-
if (full_expr.Expr is SimpleName) {
string full_name = String.Concat (((SimpleName) full_expr.Expr).Name, ".", fname);
Type fully_qualified = ec.DeclSpace.FindType (loc, full_name);
Expression member_lookup;
string lookup_id;
- lookup_id = MemberName.MakeName (Identifier, args);
+ if (args != null)
+ lookup_id = Identifier + "!" + args.Count;
+ else
+ lookup_id = Identifier;
member_lookup = MemberLookupFinal (
ec, expr_type, expr_type, lookup_id, loc);
if (member_lookup == null)
public override string ToString ()
{
- return expr + "." + MemberName.MakeName (Identifier, args);
+ if (args != null)
+ return expr + "." + Identifier + "!" + args.Count;
+ else
+ return expr + "." + Identifier;
}
}
return null;
}
- Constant c = count as Constant;
- // TODO: because we don't have property IsNegative
- if (c != null && c.ConvertToUInt () == null) {
- // "Cannot use a negative size with stackalloc"
- Report.Error_T (247, loc);
- return null;
- }
-
if (ec.CurrentBranching.InCatch () ||
ec.CurrentBranching.InFinally (true)) {
Error (255,