Report.Error (1547, loc, "Keyword `void' cannot be used in this context");
}
- public virtual void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
+ public virtual void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type target, bool expl)
{
if (Type.FullName == target.FullName){
Report.ExtraInformation (loc,
Expression e = (this is EnumConstant) ? ((EnumConstant)this).Child : this;
bool b = Convert.ExplicitNumericConversion (e, target) != null;
- if (b || Convert.ExplicitReferenceConversionExists (Type, target) || Convert.ExplicitUnsafe (e, target) != null) {
- Report.Error (266, loc, "Cannot implicitly convert type `{0}' to `{1}'. An explicit conversion exists (are you missing a cast?)",
+ if (b ||
+ Convert.ExplicitReferenceConversionExists (Type, target) ||
+ Convert.ExplicitUnsafe (e, target) != null ||
+ (ec != null && Convert.UserDefinedConversion (ec, this, target, Location.Null, true) != null))
+ {
+ Report.Error (266, loc, "Cannot implicitly convert type `{0}' to `{1}'. " +
+ "An explicit conversion exists (are you missing a cast?)",
TypeManager.CSharpName (Type), TypeManager.CSharpName (target));
return;
}
TypeManager.CSharpName (target));
}
- protected static void Error_TypeDoesNotContainDefinition (Location loc, Type type, string name)
+ public static void Error_TypeDoesNotContainDefinition (Location loc, Type type, string name)
{
Report.Error (117, loc, "`{0}' does not contain a definition for `{1}'",
TypeManager.CSharpName (type), name);
type = null;
}
- /// <summary>
- /// Returns a literalized version of a literal FieldInfo
- /// </summary>
- ///
- /// <remarks>
- /// The possible return values are:
- /// IntConstant, UIntConstant
- /// LongLiteral, ULongConstant
- /// FloatConstant, DoubleConstant
- /// StringConstant
- ///
- /// The value returned is already resolved.
- /// </remarks>
- public static Constant Constantify (object v, Type t)
- {
- if (t == TypeManager.int32_type)
- return new IntConstant ((int) v, Location.Null);
- else if (t == TypeManager.uint32_type)
- return new UIntConstant ((uint) v, Location.Null);
- else if (t == TypeManager.int64_type)
- return new LongConstant ((long) v, Location.Null);
- else if (t == TypeManager.uint64_type)
- return new ULongConstant ((ulong) v, Location.Null);
- else if (t == TypeManager.float_type)
- return new FloatConstant ((float) v, Location.Null);
- else if (t == TypeManager.double_type)
- return new DoubleConstant ((double) v, Location.Null);
- else if (t == TypeManager.string_type)
- return new StringConstant ((string) v, Location.Null);
- else if (t == TypeManager.short_type)
- return new ShortConstant ((short)v, Location.Null);
- else if (t == TypeManager.ushort_type)
- return new UShortConstant ((ushort)v, Location.Null);
- else if (t == TypeManager.sbyte_type)
- return new SByteConstant ((sbyte)v, Location.Null);
- else if (t == TypeManager.byte_type)
- return new ByteConstant ((byte)v, Location.Null);
- else if (t == TypeManager.char_type)
- return new CharConstant ((char)v, Location.Null);
- else if (t == TypeManager.bool_type)
- return new BoolConstant ((bool) v, Location.Null);
- else if (t == TypeManager.decimal_type)
- return new DecimalConstant ((decimal) v, Location.Null);
- else if (TypeManager.IsEnumType (t)){
- Type real_type = TypeManager.TypeToCoreType (v.GetType ());
- if (real_type == t)
- real_type = System.Enum.GetUnderlyingType (real_type);
-
- Constant e = Constantify (v, real_type);
-
- return new EnumConstant (e, t);
- } else if (v == null && !TypeManager.IsValueType (t))
- return new NullLiteral (Location.Null);
- else
- throw new Exception ("Unknown type for constant (" + t +
- "), details: " + v);
- }
-
/// <summary>
/// Returns a fully formed expression after a MemberLookup
/// </summary>
name, AllMemberTypes, AllBindingFlags, loc);
}
- public static Expression MethodLookup (EmitContext ec, Type queried_type,
+ public static Expression MethodLookup (Type container_type, Type queried_type,
string name, Location loc)
{
- return MemberLookup (ec.ContainerType, null, queried_type, name,
+ return MemberLookup (container_type, null, queried_type, name,
MemberTypes.Method, AllBindingFlags, loc);
}
return new Nullable.OperatorTrueOrFalse (e, is_true, loc).Resolve (ec);
#endif
- operator_group = MethodLookup (ec, e.Type, is_true ? "op_True" : "op_False", loc);
+ operator_group = MethodLookup (ec.ContainerType, e.Type, is_true ? "op_True" : "op_False", loc);
if (operator_group == null)
return null;
//
converted = Expression.GetOperatorTrue (ec, e, loc);
if (converted == null){
- e.Error_ValueCannotBeConverted (loc, TypeManager.bool_type, false);
+ e.Error_ValueCannotBeConverted (ec, loc, TypeManager.bool_type, false);
return null;
}
return converted;
target = Convert.ImplicitConversion (ec, source, TypeManager.uint64_type, loc);
if (target == null) {
- source.Error_ValueCannotBeConverted (loc, TypeManager.int32_type, false);
+ source.Error_ValueCannotBeConverted (ec, loc, TypeManager.int32_type, false);
return null;
}
}
return child.GetValue ();
}
- public override Constant Reduce (bool inCheckedContext, Type target_type)
+ public override Constant ConvertExplicitly (bool inCheckedContext, Type target_type)
{
- return child.Reduce (inCheckedContext, target_type);
+ // FIXME: check that 'type' can be converted to 'target_type' first
+ return child.ConvertExplicitly (inCheckedContext, target_type);
}
public override Constant Increment ()
return child.Increment ();
}
- public override bool IsDefaultValue
- {
+ public override bool IsDefaultValue {
get { return child.IsDefaultValue; }
}
- public override bool IsNegative
- {
+ public override bool IsNegative {
get { return child.IsNegative; }
}
child.Emit (ec);
}
- public override Constant ToType (Type type)
+ public override Constant ConvertImplicitly (Type target_type)
{
- return child.ToType (type);
+ // FIXME: Do we need to check user conversions?
+ if (!Convert.ImplicitStandardConversionExists (this, target_type))
+ return null;
+ return child.ConvertImplicitly (target_type);
}
}
public override string AsString ()
{
- return Child.AsString ();
- }
-
- public override DoubleConstant ConvertToDouble ()
- {
- return Child.ConvertToDouble ();
- }
-
- public override FloatConstant ConvertToFloat ()
- {
- return Child.ConvertToFloat ();
- }
-
- public override ULongConstant ConvertToULong ()
- {
- return Child.ConvertToULong ();
- }
-
- public override LongConstant ConvertToLong ()
- {
- return Child.ConvertToLong ();
- }
-
- public override UIntConstant ConvertToUInt ()
- {
- return Child.ConvertToUInt ();
- }
-
- public override IntConstant ConvertToInt ()
- {
- return Child.ConvertToInt ();
+ string value = System.Enum.GetName (type, Child.GetValue ());
+ return value == null ? "0" : value;
}
public override Constant Increment()
}
}
- public override Constant Reduce(bool inCheckedContext, Type target_type)
+ public override Constant ConvertExplicitly(bool inCheckedContext, Type target_type)
{
if (Child.Type == target_type)
return Child;
- return Child.Reduce (inCheckedContext, target_type);
+ return Child.ConvertExplicitly (inCheckedContext, target_type);
}
- public override Constant ToType (Type type)
+ public override Constant ConvertImplicitly (Type type)
{
if (Type == type) {
// This is workaround of mono bug. It can be removed when the latest corlib spreads enough
return this;
if (type.UnderlyingSystemType != Child.Type)
- Child = Child.ToType (type.UnderlyingSystemType);
+ Child = Child.ConvertImplicitly (type.UnderlyingSystemType);
return this;
}
return null;
}
- return Child.ToType (type);
+ return Child.ConvertImplicitly(type);
}
}
public static string RemoveGenericArity (string name)
{
int start = 0;
- StringBuilder sb = new StringBuilder ();
- while (start < name.Length) {
+ StringBuilder sb = null;
+ do {
int pos = name.IndexOf ('`', start);
if (pos < 0) {
+ if (start == 0)
+ return name;
+
sb.Append (name.Substring (start));
break;
}
+ if (sb == null)
+ sb = new StringBuilder ();
sb.Append (name.Substring (start, pos-start));
pos++;
pos++;
start = pos;
- }
+ } while (start < name.Length);
return sb.ToString ();
}
{
return resolved_to != null && resolved_to.Type != null &&
resolved_to.Type.Name == Name &&
- (ec.DeclContainer.LookupType (Name, loc, /* ignore_cs0104 = */ true) != null);
+ (ec.DeclContainer.LookupNamespaceOrType (Name, loc, /* ignore_cs0104 = */ true) != null);
}
public override Expression DoResolve (EmitContext ec)
return fne.ResolveAsTypeStep (ec, silent);
int errors = Report.Errors;
- fne = ec.DeclContainer.LookupType (Name, loc, /*ignore_cs0104=*/ false);
+ fne = ec.DeclContainer.LookupNamespaceOrType (Name, loc, /*ignore_cs0104=*/ false);
if (fne != null) {
if (fne.Type == null)
// TODO: I am still not convinced about this. If someone else will need it
// implement this as virtual property in MemberCore hierarchy
- string GetMemberType (MemberCore mc)
+ public static string GetMemberType (MemberCore mc)
{
- if (mc is PropertyBase)
+ if (mc is Property)
return "property";
if (mc is Indexer)
return "indexer";
return "method";
if (mc is EnumMember)
return "enum";
+ if (mc is Event)
+ return "event";
return "type";
}
Methods = new MethodBase [mi.Length];
mi.CopyTo (Methods, 0);
eclass = ExprClass.MethodGroup;
- type = TypeManager.object_type;
+
+ // Set the type to something that will never be useful, which will
+ // trigger the proper conversions.
+ type = typeof (MethodGroupExpr);
loc = l;
}
ic.CheckObsoleteness (loc);
}
- return ic.Value;
+ return ic.CreateConstantReference (loc);
}
if (t.IsPointer && !ec.InUnsafe) {
LocalTemporary temp;
bool prepared;
- internal static PtrHashtable AccessorTable = new PtrHashtable ();
-
public PropertyExpr (Type containerType, PropertyInfo pi, Location l)
{
PropertyInfo = pi;
// We also perform the permission checking here, as the PropertyInfo does not
// hold the information for the accessibility of its setter/getter
//
- // TODO: can use TypeManager.GetProperty to boost performance
+ // TODO: Refactor to use some kind of cache together with GetPropertyFromAccessor
void ResolveAccessors (Type containerType)
{
FindAccessors (containerType);
if (md != null)
md.SetMemberIsUsed ();
- AccessorTable [getter] = PropertyInfo;
is_static = getter.IsStatic;
}
if (md != null)
md.SetMemberIsUsed ();
- AccessorTable [setter] = PropertyInfo;
is_static = setter.IsStatic;
}
}
bool is_static;
MethodInfo add_accessor, remove_accessor;
- internal static PtrHashtable AccessorTable = new PtrHashtable ();
-
public EventExpr (EventInfo ei, Location loc)
{
EventInfo = ei;
add_accessor = TypeManager.GetAddMethod (ei);
remove_accessor = TypeManager.GetRemoveMethod (ei);
- if (add_accessor != null)
- AccessorTable [add_accessor] = ei;
- if (remove_accessor != null)
- AccessorTable [remove_accessor] = ei;
-
if (add_accessor.IsStatic || remove_accessor.IsStatic)
is_static = true;
if (EventInfo.DeclaringType == ec.ContainerType ||
TypeManager.IsNestedChildOf(ec.ContainerType, EventInfo.DeclaringType)) {
- MemberInfo mi = TypeManager.GetPrivateFieldOfEvent (EventInfo);
+ EventField mi = TypeManager.GetEventField (EventInfo);
if (mi != null) {
- MemberExpr ml = (MemberExpr) ExprClassFromMemberInfo (ec.ContainerType, mi, loc);
+ if (!ec.IsInObsoleteScope)
+ mi.CheckObsoleteness (loc);
- if (ml == null) {
- Report.Error (-200, loc, "Internal error!!");
- return null;
- }
+ FieldExpr ml = new FieldExpr (mi.FieldBuilder, loc);
InstanceExpression = null;
public void EmitAddOrRemove (EmitContext ec, Expression source)
{
- BinaryDelegate source_del = (BinaryDelegate) source;
+ BinaryDelegate source_del = source as BinaryDelegate;
+ if (source_del == null) {
+ Emit (ec);
+ return;
+ }
Expression handler = source_del.Right;
Argument arg = new Argument (handler, Argument.AType.Expression);