2002-05-06 Miguel de Icaza <miguel@ximian.com>
+ * ecore.cs (StandardConversionExists): Augment with missing code:
+ deal with IntConstant, LongConstants and Enumerations.
+
* assign.cs: Report the error, instead of failing silently
* rootcontext.cs (AddGlobalAttributes): Track attributes on the
if (StandardConversionExists (a.original_source, target_type))
return this;
- Error_CannotConvertImplicit (l, source_type, target_type);
+ Error_CannotConvertImplicit (l, a.original_source.Type, target_type);
return null;
}
}
return true;
// First numeric conversions
-
+
if (expr_type == TypeManager.sbyte_type){
//
// From sbyte to short, int, long, float, double.
}
+ if (expr is IntConstant){
+ int value = ((IntConstant) expr).Value;
+
+ if (target_type == TypeManager.sbyte_type){
+ if (value >= SByte.MinValue && value <= SByte.MaxValue)
+ return true;
+ } else if (target_type == TypeManager.byte_type){
+ if (Byte.MinValue >= 0 && value <= Byte.MaxValue)
+ return true;
+ } else if (target_type == TypeManager.short_type){
+ if (value >= Int16.MinValue && value <= Int16.MaxValue)
+ return true;
+ } else if (target_type == TypeManager.ushort_type){
+ if (value >= UInt16.MinValue && value <= UInt16.MaxValue)
+ return true;
+ } else if (target_type == TypeManager.uint32_type){
+ if (value >= 0)
+ return true;
+ } else if (target_type == TypeManager.uint64_type){
+ //
+ // we can optimize this case: a positive int32
+ // always fits on a uint64. But we need an opcode
+ // to do it.
+ //
+ if (value >= 0)
+ return true;
+ }
+
+ if (value == 0 && expr is IntLiteral && TypeManager.IsEnumType (target_type))
+ return true;
+ }
+
+ if (expr is LongConstant && target_type == TypeManager.uint64_type){
+ //
+ // Try the implicit constant expression conversion
+ // from long to ulong, instead of a nice routine,
+ // we just inline it
+ //
+ long v = ((LongConstant) expr).Value;
+ if (v > 0)
+ return true;
+ }
+
+ if (target_type.IsSubclassOf (TypeManager.enum_type) && expr is IntLiteral){
+ IntLiteral i = (IntLiteral) expr;
+
+ if (i.Value == 0)
+ return true;
+ }
return false;
}