//
// Author:
// Miguel de Icaza (miguel@ximian.com)
+// Marek Safar (marek.safar@seznam.cz)
//
// (C) 2001, 2002, 2003 Ximian, Inc.
//
/// </summary>
public void Error (int error, string s)
{
- if (loc.IsNull)
- Report.Error (error, s);
- else
- Report.Error (error, loc, s);
+ Report.Error (error, loc, s);
}
- // Not nice but we have broken hierarchy
- public virtual void CheckMarshallByRefAccess (Type container) {}
+ // Not nice but we have broken hierarchy.
+ public virtual void CheckMarshalByRefAccess ()
+ {
+ }
+
+ public virtual bool GetAttributableValue (Type valueType, out object value)
+ {
+ Attribute.Error_AttributeArgumentNotValid (loc);
+ value = null;
+ return false;
+ }
public virtual string GetSignatureForError ()
{
// This is used if the expression should be resolved as a type or namespace name.
// the default implementation fails.
//
- public FullNamedExpression ResolveAsTypeStep (EmitContext ec)
- {
- return ResolveAsTypeStep (ec, false);
- }
-
- public virtual FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
+ public virtual FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
return null;
}
// value will be returned if the expression is not a type
// reference
//
- public TypeExpr ResolveAsTypeTerminal (EmitContext ec)
+ public virtual TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
{
- return ResolveAsTypeTerminal (ec, false);
+ TypeExpr te = ResolveAsBaseTerminal (ec, silent);
+ if (te == null)
+ return null;
+
+ ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (te.Type);
+ if (obsolete_attr != null && !ec.IsInObsoleteScope) {
+ AttributeTester.Report_ObsoleteMessage (obsolete_attr, te.GetSignatureForError (), Location);
+ }
+
+ // Constrains don't need to be checked for overrides
+ GenericMethod gm = ec.GenericDeclContainer as GenericMethod;
+ if (gm != null && (gm.ModFlags & Modifiers.OVERRIDE) != 0) {
+ te.loc = loc;
+ return te;
+ }
+
+ ConstructedType ct = te as ConstructedType;
+ if ((ct != null) && !ct.CheckConstraints (ec))
+ return null;
+
+ return te;
}
- public virtual TypeExpr ResolveAsTypeTerminal (EmitContext ec, bool silent)
+ public TypeExpr ResolveAsBaseTerminal (IResolveContext ec, bool silent)
{
int errors = Report.Errors;
FullNamedExpression fne = ResolveAsTypeStep (ec, silent);
- if (fne == null)
+ if (fne == null){
+ if (!silent && errors == Report.Errors)
+ Report.Error (118, loc, "Expecting a type.");
return null;
+ }
if (fne.eclass != ExprClass.Type) {
- if (!silent && (errors == Report.Errors))
+ if (!silent && errors == Report.Errors)
fne.Error_UnexpectedKind (null, "type", loc);
return null;
}
TypeExpr te = fne as TypeExpr;
- if (!te.CheckAccessLevel (ec.DeclSpace)) {
+ if (!te.CheckAccessLevel (ec.DeclContainer)) {
+ Report.SymbolRelatedToPreviousError (te.Type);
ErrorIsInaccesible (loc, TypeManager.CSharpName (te.Type));
return null;
}
- ConstructedType ct = te as ConstructedType;
- if ((ct != null) && !ec.ResolvingTypeTree && !ec.ResolvingGenericMethod &&
- !ct.CheckConstraints (ec))
- return null;
-
te.loc = loc;
return te;
}
}
+ protected void Error_CannotAssign (string to, string roContext)
+ {
+ Report.Error (1656, loc, "Cannot assign to `{0}' because it is a `{1}'",
+ to, roContext);
+ }
+
+ public static void Error_VoidInvalidInTheContext (Location loc)
+ {
+ Report.Error (1547, loc, "Keyword `void' cannot be used in this context");
+ }
+
public virtual void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
{
- if (Type.Name == target.Name){
+ if (Type.FullName == target.FullName){
Report.ExtraInformation (loc,
String.Format (
"The type {0} has two conflicting definitions, one comes from {1} and the other from {2}",
- Type.Name, Type.Assembly.FullName, target.Assembly.FullName));
+ Type.FullName, Type.Assembly.FullName, target.Assembly.FullName));
}
TypeManager.CSharpName (type), name);
}
- ResolveFlags ExprClassToResolveFlags ()
+ ResolveFlags ExprClassToResolveFlags
{
- switch (eclass) {
- case ExprClass.Type:
- case ExprClass.Namespace:
- return ResolveFlags.Type;
+ get {
+ switch (eclass) {
+ case ExprClass.Type:
+ case ExprClass.Namespace:
+ return ResolveFlags.Type;
- case ExprClass.MethodGroup:
- return ResolveFlags.MethodGroup;
+ case ExprClass.MethodGroup:
+ return ResolveFlags.MethodGroup;
- case ExprClass.Value:
- case ExprClass.Variable:
- case ExprClass.PropertyAccess:
- case ExprClass.EventAccess:
- case ExprClass.IndexerAccess:
- return ResolveFlags.VariableOrValue;
+ case ExprClass.Value:
+ case ExprClass.Variable:
+ case ExprClass.PropertyAccess:
+ case ExprClass.EventAccess:
+ case ExprClass.IndexerAccess:
+ return ResolveFlags.VariableOrValue;
- default:
- throw new Exception ("Expression " + GetType () +
- " ExprClass is Invalid after resolve");
+ default:
+ throw new Exception ("Expression " + GetType () +
+ " ExprClass is Invalid after resolve");
+ }
}
-
}
/// <summary>
if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type)
return ResolveAsTypeStep (ec, false);
- bool old_do_flow_analysis = ec.DoFlowAnalysis;
- bool old_omit_struct_analysis = ec.OmitStructFlowAnalysis;
+ bool do_flow_analysis = ec.DoFlowAnalysis;
+ bool omit_struct_analysis = ec.OmitStructFlowAnalysis;
if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
- ec.DoFlowAnalysis = false;
+ do_flow_analysis = false;
if ((flags & ResolveFlags.DisableStructFlowAnalysis) != 0)
- ec.OmitStructFlowAnalysis = true;
+ omit_struct_analysis = true;
Expression e;
- bool intermediate = (flags & ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
- if (this is SimpleName)
- e = ((SimpleName) this).DoResolve (ec, intermediate);
-
- else
- e = DoResolve (ec);
-
- ec.DoFlowAnalysis = old_do_flow_analysis;
- ec.OmitStructFlowAnalysis = old_omit_struct_analysis;
+ using (ec.WithFlowAnalysis (do_flow_analysis, omit_struct_analysis)) {
+ if (this is SimpleName) {
+ bool intermediate = (flags & ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
+ e = ((SimpleName) this).DoResolve (ec, intermediate);
+ } else {
+ e = DoResolve (ec);
+ }
+ }
if (e == null)
return null;
- if ((flags & e.ExprClassToResolveFlags ()) == 0) {
+ if ((flags & e.ExprClassToResolveFlags) == 0) {
e.Error_UnexpectedKind (flags, loc);
return null;
}
public Constant ResolveAsConstant (EmitContext ec, MemberCore mc)
{
Expression e = Resolve (ec);
- if (e != null) {
- Constant c = e as Constant;
- if (c != null)
- return c;
-
- EmptyCast empty = e as EmptyCast;
- if (empty != null) {
- c = empty.Child as Constant;
- if (c != null) {
- // TODO: not sure about this maybe there is easier way how to use EmptyCast
- if (e.Type.IsEnum)
- c.Type = e.Type;
-
- return c;
- }
- }
+ if (e == null)
+ return null;
+
+ Constant c = e as Constant;
+ if (c != null)
+ return c;
+
+ Type constant_type = null;
+ if (mc is MemberBase) {
+ constant_type = ((MemberBase)mc).MemberType;
}
- Const.Error_ExpressionMustBeConstant (loc, mc.GetSignatureForError ());
+ Const.Error_ExpressionMustBeConstant (constant_type, loc, mc.GetSignatureForError ());
return null;
}
public Expression ResolveLValue (EmitContext ec, Expression right_side, Location loc)
{
int errors = Report.Errors;
+ bool out_access = right_side == EmptyExpression.OutAccess;
+
Expression e = DoResolveLValue (ec, right_side);
+ if (e != null && out_access && !(e is IMemoryLocation)) {
+ // FIXME: There's no problem with correctness, the 'Expr = null' handles that.
+ // Enabling this 'throw' will "only" result in deleting useless code elsewhere,
+
+ //throw new InternalErrorException ("ResolveLValue didn't return an IMemoryLocation: " +
+ // e.GetType () + " " + e.GetSignatureForError ());
+ e = null;
+ }
+
if (e == null) {
- if (errors == Report.Errors)
- Report.Error (131, loc, "The left-hand side of an assignment or mutating operation must be a variable, property or indexer");
+ if (errors == Report.Errors) {
+ if (out_access)
+ Report.Error (1510, loc, "A ref or out argument must be an assignable variable");
+ else
+ Report.Error (131, loc, "The left-hand side of an assignment or mutating operation must be a variable, property or indexer");
+ }
return null;
}
- if (e != null){
- if (e.eclass == ExprClass.Invalid)
- throw new Exception ("Expression " + e +
- " ExprClass is Invalid after resolve");
+ if (e.eclass == ExprClass.Invalid)
+ throw new Exception ("Expression " + e + " ExprClass is Invalid after resolve");
- if (e.eclass == ExprClass.MethodGroup) {
- ((MethodGroupExpr) e).ReportUsageError ();
- return null;
- }
-
- if ((e.type == null) && !(e is ConstructedType))
- throw new Exception ("Expression " + e +
- " did not set its type after Resolve");
+ if (e.eclass == ExprClass.MethodGroup) {
+ ((MethodGroupExpr) e).ReportUsageError ();
+ return null;
}
+ if ((e.type == null) && !(e is ConstructedType))
+ throw new Exception ("Expression " + e + " did not set its type after Resolve");
+
return e;
}
-
+
/// <summary>
/// Emits the code for the expression
/// </summary>
/// Returns a fully formed expression after a MemberLookup
/// </summary>
///
- public static Expression ExprClassFromMemberInfo (EmitContext ec, MemberInfo mi, Location loc)
+ public static Expression ExprClassFromMemberInfo (Type containerType, MemberInfo mi, Location loc)
{
if (mi is EventInfo)
return new EventExpr ((EventInfo) mi, loc);
else if (mi is FieldInfo)
return new FieldExpr ((FieldInfo) mi, loc);
else if (mi is PropertyInfo)
- return new PropertyExpr (ec, (PropertyInfo) mi, loc);
+ return new PropertyExpr (containerType, (PropertyInfo) mi, loc);
else if (mi is Type){
return new TypeExpression ((System.Type) mi, loc);
}
// FIXME: Potential optimization, have a static ArrayList
//
- public static Expression MemberLookup (EmitContext ec, Type queried_type, string name,
+ public static Expression MemberLookup (Type container_type, Type queried_type, string name,
MemberTypes mt, BindingFlags bf, Location loc)
{
- return MemberLookup (ec, ec.ContainerType, null, queried_type, name, mt, bf, loc);
+ return MemberLookup (container_type, null, queried_type, name, mt, bf, loc);
}
//
// `qualifier_type' or null to lookup members in the current class.
//
- public static Expression MemberLookup (EmitContext ec, Type container_type,
+ public static Expression MemberLookup (Type container_type,
Type qualifier_type, Type queried_type,
string name, MemberTypes mt,
BindingFlags bf, Location loc)
{
almostMatchedMembers.Clear ();
- MemberInfo [] mi = TypeManager.MemberLookup (
- container_type, qualifier_type, queried_type, mt, bf, name,
- almostMatchedMembers);
+ MemberInfo [] mi = TypeManager.MemberLookup (container_type, qualifier_type,
+ queried_type, mt, bf, name, almostMatchedMembers);
if (mi == null)
return null;
- int count = mi.Length;
+ if (mi.Length > 1) {
+ bool is_interface = qualifier_type != null && qualifier_type.IsInterface;
+ MemberInfo non_method = null;
+ ArrayList methods = new ArrayList (2);
+
+ foreach (MemberInfo m in mi) {
+ if (m is MethodBase) {
+ methods.Add (m);
+ continue;
+ }
+
+ if (non_method == null) {
+ non_method = m;
+ continue;
+ }
+
+ if (!is_interface)
+ continue;
+
+ Report.SymbolRelatedToPreviousError (m);
+ Report.SymbolRelatedToPreviousError (non_method);
+ Report.Error (229, loc, "Ambiguity between `{0}' and `{1}'",
+ TypeManager.GetFullNameSignature (m), TypeManager.GetFullNameSignature (non_method));
+ return null;
+ }
+
+ if (non_method != null && is_interface) {
+ MethodBase method = (MethodBase)methods[0];
+ Report.SymbolRelatedToPreviousError (method);
+ Report.SymbolRelatedToPreviousError (non_method);
+ Report.Warning (467, 2, loc, "Ambiguity between method `{0}' and non-method `{1}'. Using method `{0}'",
+ TypeManager.CSharpSignature (method), TypeManager.GetFullNameSignature (non_method));
+ }
+
+ if (methods.Count == 0)
+ return new MethodGroupExpr (mi, loc);
+
+ return new MethodGroupExpr (methods, loc);
+ }
if (mi [0] is MethodBase)
return new MethodGroupExpr (mi, loc);
- if (count > 1)
- return null;
-
- return ExprClassFromMemberInfo (ec, mi [0], loc);
+ return ExprClassFromMemberInfo (container_type, mi [0], loc);
}
public const MemberTypes AllMemberTypes =
BindingFlags.Static |
BindingFlags.Instance;
- public static Expression MemberLookup (EmitContext ec, Type queried_type,
+ public static Expression MemberLookup (Type container_type, Type queried_type,
string name, Location loc)
{
- return MemberLookup (ec, ec.ContainerType, null, queried_type, name,
+ return MemberLookup (container_type, null, queried_type, name,
AllMemberTypes, AllBindingFlags, loc);
}
- public static Expression MemberLookup (EmitContext ec, Type qualifier_type,
+ public static Expression MemberLookup (Type container_type, Type qualifier_type,
Type queried_type, string name, Location loc)
{
- if (ec.ResolvingTypeTree)
- return MemberLookup (ec, ec.ContainerType, qualifier_type,
- queried_type, name, MemberTypes.NestedType,
- AllBindingFlags, loc);
- else
- return MemberLookup (ec, ec.ContainerType, qualifier_type,
- queried_type, name, AllMemberTypes,
- AllBindingFlags, loc);
+ return MemberLookup (container_type, qualifier_type, queried_type,
+ name, AllMemberTypes, AllBindingFlags, loc);
}
public static Expression MethodLookup (EmitContext ec, Type queried_type,
string name, Location loc)
{
- return MemberLookup (ec, ec.ContainerType, null, queried_type, name,
+ return MemberLookup (ec.ContainerType, null, queried_type, name,
MemberTypes.Method, AllBindingFlags, loc);
}
/// find it.
/// </summary>
public static Expression MemberLookupFinal (EmitContext ec, Type qualifier_type,
- Type queried_type, string name,
- Location loc)
+ Type queried_type, string name, Location loc)
{
return MemberLookupFinal (ec, qualifier_type, queried_type, name,
AllMemberTypes, AllBindingFlags, loc);
int errors = Report.Errors;
- e = MemberLookup (ec, ec.ContainerType, qualifier_type, queried_type,
- name, mt, bf, loc);
+ e = MemberLookup (ec.ContainerType, qualifier_type, queried_type, name, mt, bf, loc);
if (e == null && errors == Report.Errors)
// No errors were reported by MemberLookup, but there was an error.
- MemberLookupFailed (ec, qualifier_type, queried_type, name, null, true, loc);
+ MemberLookupFailed (ec.ContainerType, qualifier_type, queried_type, name, null, true, loc);
return e;
}
- public static void MemberLookupFailed (EmitContext ec, Type qualifier_type,
+ public static void MemberLookupFailed (Type container_type, Type qualifier_type,
Type queried_type, string name,
string class_name, bool complain_if_none_found,
Location loc)
if (qualifier_type == null) {
Report.Error (38, loc, "Cannot access a nonstatic member of outer type `{0}' via nested type `{1}'",
TypeManager.CSharpName (m.DeclaringType),
- TypeManager.CSharpName (ec.ContainerType));
- } else if (qualifier_type != ec.ContainerType &&
- TypeManager.IsNestedFamilyAccessible (ec.ContainerType, declaring_type)) {
+ TypeManager.CSharpName (container_type));
+
+ } else if (qualifier_type != container_type &&
+ TypeManager.IsNestedFamilyAccessible (container_type, declaring_type)) {
// Although a derived class can access protected members of
// its base class it cannot do so through an instance of the
// base class (CS1540). If the qualifier_type is a base of the
// ec.ContainerType and the lookup succeeds with the latter one,
// then we are in this situation.
- Error_CannotAccessProtected (loc, m, qualifier_type, ec.ContainerType);
+ Error_CannotAccessProtected (loc, m, qualifier_type, container_type);
} else {
+ Report.SymbolRelatedToPreviousError (m);
ErrorIsInaccesible (loc, TypeManager.GetFullNameSignature (m));
}
}
return;
}
- MemberInfo[] lookup = TypeManager.MemberLookup (queried_type, null, queried_type,
- AllMemberTypes, AllBindingFlags |
- BindingFlags.NonPublic, name, null);
+ MemberInfo[] lookup = null;
+ if (queried_type == null) {
+ class_name = "global::";
+ } else {
+ lookup = TypeManager.MemberLookup (queried_type, null, queried_type,
+ AllMemberTypes, AllBindingFlags |
+ BindingFlags.NonPublic, name, null);
+ }
if (lookup == null) {
if (!complain_if_none_found)
BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, null);
if (name == ".ctor" && ml.Count == 0)
{
- Report.Error (143, loc, String.Format ("The type `{0}' has no constructors defined", TypeManager.CSharpName (queried_type)));
+ Report.Error (143, loc, "The type `{0}' has no constructors defined", TypeManager.CSharpName (queried_type));
return;
}
+ Report.SymbolRelatedToPreviousError (lookup [0]);
ErrorIsInaccesible (loc, TypeManager.GetFullNameSignature (lookup [0]));
}
/// <summary>
/// Reports that we were expecting `expr' to be of class `expected'
/// </summary>
- public void Error_UnexpectedKind (EmitContext ec, string expected, Location loc)
+ public void Error_UnexpectedKind (DeclSpace ds, string expected, Location loc)
{
- Error_UnexpectedKind (ec, expected, ExprClassName, loc);
+ Error_UnexpectedKind (ds, expected, ExprClassName, loc);
}
- public void Error_UnexpectedKind (EmitContext ec, string expected, string was, Location loc)
+ public void Error_UnexpectedKind (DeclSpace ds, string expected, string was, Location loc)
{
string name = GetSignatureForError ();
- if (ec != null)
- name = ec.DeclSpace.GetSignatureForError () + '.' + name;
+ if (ds != null)
+ name = ds.GetSignatureForError () + '.' + name;
Report.Error (118, loc, "`{0}' is a `{1}' but a `{2}' was expected",
name, was, expected);
{
Expression target;
- bool old_checked = ec.CheckState;
- ec.CheckState = true;
-
- target = Convert.ImplicitConversion (ec, source, TypeManager.int32_type, loc);
- if (target == null){
- target = Convert.ImplicitConversion (ec, source, TypeManager.uint32_type, loc);
- if (target == null){
+ using (ec.With (EmitContext.Flags.CheckState, true)) {
+ target = Convert.ImplicitConversion (ec, source, TypeManager.int32_type, loc);
+ if (target == null)
+ target = Convert.ImplicitConversion (ec, source, TypeManager.uint32_type, loc);
+ if (target == null)
target = Convert.ImplicitConversion (ec, source, TypeManager.int64_type, loc);
- if (target == null){
- target = Convert.ImplicitConversion (ec, source, TypeManager.uint64_type, loc);
- if (target == null)
- source.Error_ValueCannotBeConverted (loc, TypeManager.int32_type, false);
- }
+ if (target == null)
+ target = Convert.ImplicitConversion (ec, source, TypeManager.uint64_type, loc);
+
+ if (target == null) {
+ source.Error_ValueCannotBeConverted (loc, TypeManager.int32_type, false);
+ return null;
}
- }
- ec.CheckState = old_checked;
+ }
//
// Only positive constants are allowed at compile time
///
/// </summary>
public class EmptyCast : Expression {
- protected Expression child;
-
- public Expression Child {
- get {
- return child;
- }
- }
+ protected readonly Expression child;
public EmptyCast (Expression child, Type return_type)
{
{
child.Emit (ec);
}
+
+ public override bool GetAttributableValue (Type valueType, out object value)
+ {
+ return child.GetAttributableValue (valueType, out value);
+ }
+
}
/// <summary>
/// This is a numeric cast to a Decimal
public override bool IsDefaultValue {
get {
- throw new NotImplementedException ();
+ return true;
}
}
}
}
- public override Constant Reduce (EmitContext ec, Type target_type)
+ public override Constant Reduce (bool inCheckedContext, Type target_type)
{
if (type == target_type)
- return child.Reduce (ec, target_type);
+ return child.Reduce (inCheckedContext, target_type);
return null;
}
Child.Emit (ec);
}
+ public override bool GetAttributableValue (Type valueType, out object value)
+ {
+ value = GetTypedValue ();
+ return true;
+ }
+
public override string GetSignatureForError()
{
return TypeManager.CSharpName (Type);
}
}
- public override Constant Reduce(EmitContext ec, Type target_type)
+ public override Constant Reduce(bool inCheckedContext, Type target_type)
{
if (Child.Type == target_type)
return Child;
- return Child.Reduce (ec, target_type);
+ return Child.Reduce (inCheckedContext, target_type);
}
public override Constant ToType (Type type, Location loc)
return this;
}
- if (!Convert.ImplicitStandardConversionExists (Convert.ConstantEC, this, type)){
+ if (!Convert.ImplicitStandardConversionExists (this, type)){
Error_ValueCannotBeConverted (loc, type, false);
return null;
}
return this;
}
+ public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ {
+ if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess)
+ Report.Error (445, loc, "Cannot modify the result of an unboxing conversion");
+ return base.DoResolveLValue (ec, right_side);
+ }
+
public override void Emit (EmitContext ec)
{
Type t = type;
ILGenerator ig = ec.ig;
base.Emit (ec);
- if (t.IsGenericParameter)
+ if (t.IsGenericParameter || t.IsGenericType && t.IsValueType)
ig.Emit (OpCodes.Unbox_Any, t);
else {
ig.Emit (OpCodes.Unbox, t);
Report.Error (236, l,
"A field initializer cannot reference the nonstatic field, method, or property `{0}'",
name);
- else {
- if (name.LastIndexOf ('.') > 0)
- name = name.Substring (name.LastIndexOf ('.') + 1);
-
+ else
Report.Error (
120, l, "`{0}': An object reference is required for the nonstatic field, method or property",
name);
- }
}
public bool IdenticalNameAndTypeName (EmitContext ec, Expression resolved_to, Location loc)
{
return resolved_to != null && resolved_to.Type != null &&
resolved_to.Type.Name == Name &&
- (ec.DeclSpace.LookupType (Name, loc, /* ignore_cs0104 = */ true) != null);
+ (ec.DeclContainer.LookupType (Name, loc, /* ignore_cs0104 = */ true) != null);
}
public override Expression DoResolve (EmitContext ec)
return false;
while (parent != null) {
- if (parent.IsGenericInstance)
- parent = parent.GetGenericTypeDefinition ();
-
+ parent = TypeManager.DropGenericTypeArguments (parent);
if (TypeManager.IsNestedChildOf (t, parent))
return true;
return false;
}
- FullNamedExpression ResolveNested (EmitContext ec, Type t)
+ FullNamedExpression ResolveNested (IResolveContext ec, Type t)
{
if (!t.IsGenericTypeDefinition)
return null;
- DeclSpace ds = ec.DeclSpace;
+ DeclSpace ds = ec.DeclContainer;
while (ds != null) {
if (IsNestedChild (t, ds.TypeBuilder))
break;
return null;
}
- public override FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
+ public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
- FullNamedExpression fne = ec.DeclSpace.LookupGeneric (Name, loc);
+ FullNamedExpression fne = ec.GenericDeclContainer.LookupGeneric (Name, loc);
if (fne != null)
return fne.ResolveAsTypeStep (ec, silent);
int errors = Report.Errors;
- fne = ec.DeclSpace.LookupType (Name, loc, /*ignore_cs0104=*/ false);
+ fne = ec.DeclContainer.LookupType (Name, loc, /*ignore_cs0104=*/ false);
if (fne != null) {
if (fne.Type == null)
FullNamedExpression nested = ResolveNested (ec, fne.Type);
if (nested != null)
- return nested.ResolveAsTypeStep (ec);
+ return nested.ResolveAsTypeStep (ec, false);
if (Arguments != null) {
ConstructedType ct = new ConstructedType (fne, Arguments, loc);
- return ct.ResolveAsTypeStep (ec);
+ return ct.ResolveAsTypeStep (ec, false);
}
return fne;
if (silent || errors != Report.Errors)
return null;
- MemberCore mc = ec.DeclSpace.GetDefinition (Name);
+ MemberCore mc = ec.DeclContainer.GetDefinition (Name);
if (mc != null) {
- Error_UnexpectedKind (ec, "type", GetMemberType (mc), loc);
- } else {
- NamespaceEntry.Error_NamespaceNotFound (loc, Name);
+ Error_UnexpectedKind (ec.DeclContainer, "type", GetMemberType (mc), loc);
+ return null;
}
+ string ns = ec.DeclContainer.NamespaceEntry.NS.Name;
+ string fullname = (ns.Length > 0) ? ns + "." + Name : Name;
+ foreach (Assembly a in RootNamespace.Global.Assemblies) {
+ Type type = a.GetType (fullname);
+ if (type != null) {
+ Report.SymbolRelatedToPreviousError (type);
+ Expression.ErrorIsInaccesible (loc, fullname);
+ return null;
+ }
+ }
+
+ NamespaceEntry.Error_NamespaceNotFound (loc, Name);
return null;
}
if (current_block != null){
LocalInfo vi = current_block.GetLocalInfo (Name);
if (vi != null){
+ if (Arguments != null) {
+ Report.Error (307, loc,
+ "The variable `{0}' cannot be used with type arguments",
+ Name);
+ return null;
+ }
+
LocalVariableReference var = new LocalVariableReference (ec.CurrentBlock, Name, loc);
if (right_side != null) {
return var.ResolveLValue (ec, right_side, loc);
ParameterReference pref = current_block.Toplevel.GetParameterReference (Name, loc);
if (pref != null) {
+ if (Arguments != null) {
+ Report.Error (307, loc,
+ "The variable `{0}' cannot be used with type arguments",
+ Name);
+ return null;
+ }
+
if (right_side != null)
return pref.ResolveLValue (ec, right_side, loc);
else
// Stage 2: Lookup members
//
- DeclSpace lookup_ds = ec.DeclSpace;
+ DeclSpace lookup_ds = ec.DeclContainer;
Type almost_matched_type = null;
ArrayList almost_matched = null;
do {
if (lookup_ds.TypeBuilder == null)
break;
- e = MemberLookup (ec, lookup_ds.TypeBuilder, Name, loc);
+ e = MemberLookup (ec.ContainerType, lookup_ds.TypeBuilder, Name, loc);
if (e != null)
break;
} while (lookup_ds != null);
if (e == null && ec.ContainerType != null)
- e = MemberLookup (ec, ec.ContainerType, Name, loc);
+ e = MemberLookup (ec.ContainerType, ec.ContainerType, Name, loc);
if (e == null) {
if (almost_matched == null && almostMatchedMembers.Count > 0) {
almostMatchedMembers = almost_matched;
if (almost_matched_type == null)
almost_matched_type = ec.ContainerType;
- MemberLookupFailed (ec, null, almost_matched_type, ((SimpleName) this).Name, ec.DeclSpace.Name, true, loc);
+ MemberLookupFailed (ec.ContainerType, null, almost_matched_type, ((SimpleName) this).Name, ec.DeclContainer.Name, true, loc);
return null;
}
- if (e is TypeExpr)
- return e;
+ if (e is TypeExpr) {
+ if (Arguments == null)
+ return e;
+
+ ConstructedType ct = new ConstructedType (
+ (FullNamedExpression) e, Arguments, loc);
+ return ct.ResolveAsTypeStep (ec, false);
+ }
if (e is MemberExpr) {
MemberExpr me = (MemberExpr) e;
if (!me.IsStatic &&
(!intermediate || !IdenticalNameAndTypeName (ec, me, loc))) {
Error_ObjectRefRequired (ec, loc, me.GetSignatureForError ());
- return null;
+ return EmptyExpression.Null;
}
//
Error (103, "The name `" + Name +
"' does not exist in the class `" +
- ec.DeclSpace.Name + "'");
+ ec.DeclContainer.Name + "'");
}
public override string ToString ()
/// section 10.8.1 (Fully Qualified Names).
/// </summary>
public abstract class FullNamedExpression : Expression {
- public override FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
+ public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
return this;
}
/// Expression that evaluates to a type
/// </summary>
public abstract class TypeExpr : FullNamedExpression {
- override public FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
+ override public FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
TypeExpr t = DoResolveAsTypeStep (ec);
if (t == null)
override public Expression DoResolve (EmitContext ec)
{
- return ResolveAsTypeTerminal (ec);
+ return ResolveAsTypeTerminal (ec, false);
}
override public void Emit (EmitContext ec)
return true;
}
- protected abstract TypeExpr DoResolveAsTypeStep (EmitContext ec);
-
- public Type ResolveType (EmitContext ec)
- {
- TypeExpr t = ResolveAsTypeTerminal (ec);
- if (t == null)
- return null;
-
- if (ec.TestObsoleteMethodUsage) {
- ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (t.Type);
- if (obsolete_attr != null) {
- AttributeTester.Report_ObsoleteMessage (obsolete_attr, Name, Location);
- }
- }
-
- return t.Type;
- }
+ protected abstract TypeExpr DoResolveAsTypeStep (IResolveContext ec);
public abstract string Name {
get;
loc = l;
}
- protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
+ {
+ return this;
+ }
+
+ public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
{
return this;
}
/// by the parser to setup the core types. A TypeLookupExpression is always
/// classified as a type.
/// </summary>
- public class TypeLookupExpression : TypeExpr {
- string name;
+ public sealed class TypeLookupExpression : TypeExpr {
+ readonly string name;
public TypeLookupExpression (string name)
{
this.name = name;
+ eclass = ExprClass.Type;
}
- static readonly char [] dot_array = { '.' };
- protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
{
- if (type != null)
- return this;
+ // It's null for corlib compilation only
+ if (type == null)
+ return DoResolveAsTypeStep (ec);
+
+ return this;
+ }
+ static readonly char [] dot_array = { '.' };
+ protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
+ {
// If name is of the form `N.I', first lookup `N', then search a member `I' in it.
string rest = null;
string lookup_name = name;
lookup_name = name.Substring (0, pos);
}
- FullNamedExpression resolved = RootNamespace.Global.Lookup (ec.DeclSpace, lookup_name, Location.Null);
+ FullNamedExpression resolved = RootNamespace.Global.Lookup (ec.DeclContainer, lookup_name, Location.Null);
if (resolved != null && rest != null) {
// Now handle the rest of the the name.
Namespace ns = resolved as Namespace;
element = elements [i++];
lookup_name += "." + element;
- resolved = ns.Lookup (ec.DeclSpace, element, Location.Null);
+ resolved = ns.Lookup (ec.DeclContainer, element, Location.Null);
}
if (resolved != null && resolved is TypeExpr) {
Type t = ((TypeExpr) resolved).Type;
while (t != null) {
- if (!ec.DeclSpace.CheckAccessLevel (t)) {
+ if (!ec.DeclContainer.CheckAccessLevel (t)) {
resolved = null;
lookup_name = t.FullName;
break;
}
if (!(resolved is TypeExpr)) {
- resolved.Error_UnexpectedKind (ec, "type", loc);
+ resolved.Error_UnexpectedKind (ec.DeclContainer, "type", loc);
return null;
}
- type = ((TypeExpr) resolved).ResolveType (ec);
+ type = resolved.Type;
return this;
}
loc = l;
}
- protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
{
Expression expr;
if (name.Left != null) {
Expression lexpr = name.Left.GetTypeExpression ();
- expr = new MemberAccess (lexpr, name.Basename, loc);
+ expr = new MemberAccess (lexpr, name.Basename);
} else {
expr = new SimpleName (name.Basename, loc);
}
- FullNamedExpression fne = expr.ResolveAsTypeStep (ec);
+ FullNamedExpression fne = expr.ResolveAsTypeStep (ec, false);
if (fne == null)
return null;
get { return name; }
}
- protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
{
- texpr = alias.ResolveAsTypeTerminal (ec);
+ texpr = alias.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
return null;
- Type type = texpr.ResolveType (ec);
+ Type type = texpr.Type;
int num_args = TypeManager.GetNumberOfTypeArguments (type);
if (args != null) {
}
ConstructedType ctype = new ConstructedType (type, args, loc);
- return ctype.ResolveAsTypeTerminal (ec);
+ return ctype.ResolveAsTypeTerminal (ec, false);
} else if (num_args > 0) {
Report.Error (305, loc,
"Using the generic type `{0}' " +
return null;
}
- return new TypeExpression (type, loc);
+ return texpr;
}
public override bool CheckAccessLevel (DeclSpace ds)
"with an instance reference, qualify it with a type name instead", name);
}
- protected bool CheckIntermediateModification ()
- {
- if (!InstanceExpression.Type.IsValueType)
- return true;
-
- if (InstanceExpression is UnboxCast) {
- Report.Error (445, loc, "Cannot modify the result of an unboxing conversion");
- return false;
- }
-
- if (!(InstanceExpression is IMemoryLocation)) {
- Report.Error (1612, loc, "Cannot modify the return value of `{0}' because it is not a variable",
- InstanceExpression.GetSignatureForError ());
- return false;
- }
-
- return true;
- }
-
// TODO: possible optimalization
// Cache resolved constant result in FieldBuilder <-> expression map
public virtual Expression ResolveMemberAccess (EmitContext ec, Expression left, Location loc,
if (left is TypeExpr) {
if (!IsStatic) {
- SimpleName.Error_ObjectRefRequired (ec, loc, Name);
+ SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return null;
}
return;
if (InstanceExpression == EmptyExpression.Null) {
- SimpleName.Error_ObjectRefRequired (ec, loc, Name);
+ SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return;
}
if (InstanceExpression is IMemoryLocation) {
((IMemoryLocation) InstanceExpression).AddressOf (ec, AddressOp.LoadStore);
} else {
- LocalTemporary t = new LocalTemporary (ec, InstanceExpression.Type);
+ LocalTemporary t = new LocalTemporary (InstanceExpression.Type);
InstanceExpression.Emit (ec);
t.Store (ec);
t.AddressOf (ec, AddressOp.Store);
ArrayList list = new ArrayList ();
foreach (MethodBase mb in Methods) {
MethodInfo mi = mb as MethodInfo;
- if ((mi == null) || !mi.HasGenericParameters)
+ if ((mi == null) || !mi.IsGenericMethod)
continue;
Type[] gen_params = mi.GetGenericArguments ();
MethodGroupExpr new_mg = new MethodGroupExpr (list, Location);
new_mg.InstanceExpression = InstanceExpression;
new_mg.HasTypeArguments = true;
+ new_mg.IsBase = IsBase;
return new_mg;
}
public override Expression ResolveMemberAccess (EmitContext ec, Expression left, Location loc,
SimpleName original)
{
- FieldInfo fi = FieldInfo.Mono_GetGenericFieldDefinition ();
+ FieldInfo fi = TypeManager.GetGenericFieldDefinition (FieldInfo);
Type t = fi.FieldType;
return null;
}
- if (ic.ResolveValue ())
- ic.CheckObsoleteness (loc);
+ if (ic.ResolveValue ()) {
+ if (!ec.IsInObsoleteScope)
+ ic.CheckObsoleteness (loc);
+ }
return ic.Value;
}
override public Expression DoResolve (EmitContext ec)
{
- if (ec.InRefOutArgumentResolving && FieldInfo.IsInitOnly && !ec.IsConstructor && FieldInfo.FieldType.IsValueType) {
- if (FieldInfo.FieldType is TypeBuilder) {
- if (FieldInfo.IsStatic)
- Report.Error (1651, loc, "Fields of static readonly field `{0}' cannot be passed ref or out (except in a static constructor)",
- GetSignatureForError ());
- else
- Report.Error (1649, loc, "Members of readonly field `{0}.{1}' cannot be passed ref or out (except in a constructor)",
- TypeManager.CSharpName (DeclaringType), Name);
- } else {
- if (FieldInfo.IsStatic)
- Report.Error (199, loc, "A static readonly field `{0}' cannot be passed ref or out (except in a static constructor)",
- Name);
- else
- Report.Error (192, loc, "A readonly field `{0}' cannot be passed ref or out (except in a constructor)",
- Name);
- }
- return null;
- }
+ return DoResolve (ec, false, false);
+ }
+ Expression DoResolve (EmitContext ec, bool lvalue_instance, bool out_access)
+ {
if (!FieldInfo.IsStatic){
if (InstanceExpression == null){
//
// This can happen when referencing an instance field using
// a fully qualified type expression: TypeName.InstanceField = xxx
//
- SimpleName.Error_ObjectRefRequired (ec, loc, FieldInfo.Name);
+ SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return null;
}
// Resolve the field's instance expression while flow analysis is turned
// off: when accessing a field "a.b", we must check whether the field
// "a.b" is initialized, not whether the whole struct "a" is initialized.
- InstanceExpression = InstanceExpression.Resolve (
- ec, ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis);
+
+ if (lvalue_instance) {
+ using (ec.With (EmitContext.Flags.DoFlowAnalysis, false)) {
+ Expression right_side =
+ out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
+ InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side, loc);
+ }
+ } else {
+ ResolveFlags rf = ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;
+ InstanceExpression = InstanceExpression.Resolve (ec, rf);
+ }
+
if (InstanceExpression == null)
return null;
+
+ InstanceExpression.CheckMarshalByRefAccess ();
}
if (!in_initializer && !ec.IsFieldInitializer) {
ObsoleteAttribute oa;
FieldBase f = TypeManager.GetField (FieldInfo);
if (f != null) {
- f.CheckObsoleteness (loc);
+ if (!ec.IsInObsoleteScope)
+ f.CheckObsoleteness (loc);
+
// To be sure that type is external because we do not register generated fields
} else if (!(FieldInfo.DeclaringType is TypeBuilder)) {
oa = AttributeTester.GetMemberObsoleteAttribute (FieldInfo);
return this;
}
- void Report_AssignToReadonly (bool is_instance)
- {
- string msg;
-
- if (is_instance)
- msg = "A readonly field cannot be assigned to (except in a constructor or a variable initializer)";
- else
- msg = "A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)";
+ static readonly int [] codes = {
+ 191, // instance, write access
+ 192, // instance, out access
+ 198, // static, write access
+ 199, // static, out access
+ 1648, // member of value instance, write access
+ 1649, // member of value instance, out access
+ 1650, // member of value static, write access
+ 1651 // member of value static, out access
+ };
+
+ static readonly string [] msgs = {
+ /*0191*/ "A readonly field `{0}' cannot be assigned to (except in a constructor or a variable initializer)",
+ /*0192*/ "A readonly field `{0}' cannot be passed ref or out (except in a constructor)",
+ /*0198*/ "A static readonly field `{0}' cannot be assigned to (except in a static constructor or a variable initializer)",
+ /*0199*/ "A static readonly field `{0}' cannot be passed ref or out (except in a static constructor)",
+ /*1648*/ "Members of readonly field `{0}' cannot be modified (except in a constructor or a variable initializer)",
+ /*1649*/ "Members of readonly field `{0}' cannot be passed ref or out (except in a constructor)",
+ /*1650*/ "Fields of static readonly field `{0}' cannot be assigned to (except in a static constructor or a variable initializer)",
+ /*1651*/ "Fields of static readonly field `{0}' cannot be passed ref or out (except in a static constructor)"
+ };
+
+ // The return value is always null. Returning a value simplifies calling code.
+ Expression Report_AssignToReadonly (Expression right_side)
+ {
+ int i = 0;
+ if (right_side == EmptyExpression.OutAccess || right_side == EmptyExpression.LValueMemberOutAccess)
+ i += 1;
+ if (IsStatic)
+ i += 2;
+ if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess)
+ i += 4;
+ Report.Error (codes [i], loc, msgs [i], GetSignatureForError ());
- Report.Error (is_instance ? 191 : 198, loc, msg);
+ return null;
}
override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
if ((var != null) && (var.VariableInfo != null))
var.VariableInfo.SetFieldAssigned (ec, FieldInfo.Name);
- Expression e = DoResolve (ec);
+ bool lvalue_instance = !FieldInfo.IsStatic && FieldInfo.DeclaringType.IsValueType;
+ bool out_access = right_side == EmptyExpression.OutAccess || right_side == EmptyExpression.LValueMemberOutAccess;
- if (e == null)
- return null;
+ Expression e = DoResolve (ec, lvalue_instance, out_access);
- if (!FieldInfo.IsStatic && !CheckIntermediateModification ())
+ if (e == null)
return null;
FieldBase fb = TypeManager.GetField (FieldInfo);
if (fb != null)
fb.SetAssigned ();
- if (!FieldInfo.IsInitOnly)
- return this;
-
- //
- // InitOnly fields can only be assigned in constructors
- //
-
- if (ec.IsConstructor){
- if (IsStatic && !ec.IsStatic)
- Report_AssignToReadonly (false);
-
- Type ctype;
- if (ec.TypeContainer.CurrentType != null)
- ctype = ec.TypeContainer.CurrentType;
- else
- ctype = ec.ContainerType;
+ if (FieldInfo.IsInitOnly) {
+ // InitOnly fields can only be assigned in constructors or initializers
+ if (!ec.IsFieldInitializer && !ec.IsConstructor)
+ return Report_AssignToReadonly (right_side);
+
+ if (ec.IsConstructor) {
+ Type ctype = ec.TypeContainer.CurrentType;
+ if (ctype == null)
+ ctype = ec.ContainerType;
+
+ // InitOnly fields cannot be assigned-to in a different constructor from their declaring type
+ if (!TypeManager.IsEqual (ctype, FieldInfo.DeclaringType))
+ return Report_AssignToReadonly (right_side);
+ // static InitOnly fields cannot be assigned-to in an instance constructor
+ if (IsStatic && !ec.IsStatic)
+ return Report_AssignToReadonly (right_side);
+ // instance constructors can't modify InitOnly fields of other instances of the same type
+ if (!IsStatic && !(InstanceExpression is This))
+ return Report_AssignToReadonly (right_side);
+ }
+ }
- if (TypeManager.IsEqual (ctype, FieldInfo.DeclaringType))
- return this;
+ if (right_side == EmptyExpression.OutAccess &&
+ !IsStatic && !(InstanceExpression is This) && DeclaringType.IsSubclassOf (TypeManager.mbr_type)) {
+ Report.SymbolRelatedToPreviousError (DeclaringType);
+ Report.Warning (197, 1, loc,
+ "Passing `{0}' as ref or out or taking its address may cause a runtime exception because it is a field of a marshal-by-reference class",
+ GetSignatureForError ());
}
- Report_AssignToReadonly (!IsStatic);
-
- return null;
+ return this;
}
- public override void CheckMarshallByRefAccess (Type container)
+ public override void CheckMarshalByRefAccess ()
{
- if (!IsStatic && Type.IsValueType && !container.IsSubclassOf (TypeManager.mbr_type) && DeclaringType.IsSubclassOf (TypeManager.mbr_type)) {
+ if (!IsStatic && Type.IsValueType && !(InstanceExpression is This) && DeclaringType.IsSubclassOf (TypeManager.mbr_type)) {
Report.SymbolRelatedToPreviousError (DeclaringType);
- Report.Error (1690, loc, "Cannot call methods, properties, or indexers on `{0}' because it is a value type member of a marshal-by-reference class",
- GetSignatureForError ());
+ Report.Warning (1690, 1, loc, "Cannot call methods, properties, or indexers on `{0}' because it is a value type member of a marshal-by-reference class",
+ GetSignatureForError ());
}
}
return variable != null && InstanceExpression.Type.IsValueType && variable.VerifyFixed ();
}
- public override int GetHashCode()
+ public override int GetHashCode ()
{
return FieldInfo.GetHashCode ();
}
ILGenerator ig = ec.ig;
bool is_volatile = false;
- FieldInfo the_fi = FieldInfo.Mono_GetGenericFieldDefinition ();
- if (the_fi is FieldBuilder){
- FieldBase f = TypeManager.GetField (the_fi);
- if (f != null){
- if ((f.ModFlags & Modifiers.VOLATILE) != 0)
- is_volatile = true;
-
- f.SetMemberIsUsed ();
- }
- }
+ FieldBase f = TypeManager.GetField (FieldInfo);
+ if (f != null){
+ if ((f.ModFlags & Modifiers.VOLATILE) != 0)
+ is_volatile = true;
+
+ f.SetMemberIsUsed ();
+ }
if (FieldInfo.IsStatic){
if (is_volatile)
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
if (!FieldInfo.IsStatic) {
- temp = new LocalTemporary (ec, this.Type);
+ temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
prepared = prepare_for_load;
if (is_readonly && !ec.IsConstructor){
- Report_AssignToReadonly (!is_static);
+ Report_AssignToReadonly (source);
return;
}
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
if (!FieldInfo.IsStatic) {
- temp = new LocalTemporary (ec, this.Type);
+ temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
- if (FieldInfo is FieldBuilder){
- FieldBase f = TypeManager.GetField (FieldInfo);
- if (f != null){
- if ((f.ModFlags & Modifiers.VOLATILE) != 0)
- ig.Emit (OpCodes.Volatile);
+ FieldBase f = TypeManager.GetField (FieldInfo);
+ if (f != null){
+ if ((f.ModFlags & Modifiers.VOLATILE) != 0)
+ ig.Emit (OpCodes.Volatile);
- f.SetAssigned ();
- }
- }
+ f.SetAssigned ();
+ }
if (is_static)
ig.Emit (OpCodes.Stsfld, FieldInfo);
else
ig.Emit (OpCodes.Stfld, FieldInfo);
- if (temp != null)
+ if (temp != null) {
temp.Emit (ec);
+ temp.Release (ec);
+ }
}
public override void Emit (EmitContext ec)
public void AddressOf (EmitContext ec, AddressOp mode)
{
ILGenerator ig = ec.ig;
-
- if (FieldInfo is FieldBuilder){
- FieldBase f = TypeManager.GetField (FieldInfo);
- if (f != null){
- if ((f.ModFlags & Modifiers.VOLATILE) != 0){
- Report.Warning (420, 1, loc, "`{0}': A volatile fields cannot be passed using a ref or out parameter",
+
+ FieldBase f = TypeManager.GetField (FieldInfo);
+ if (f != null){
+ if ((f.ModFlags & Modifiers.VOLATILE) != 0){
+ Report.Warning (420, 1, loc, "`{0}': A volatile fields cannot be passed using a ref or out parameter",
f.GetSignatureForError ());
- return;
- }
-
- if ((mode & AddressOp.Store) != 0)
- f.SetAssigned ();
- if ((mode & AddressOp.Load) != 0)
- f.SetMemberIsUsed ();
+ return;
}
- }
+
+ if ((mode & AddressOp.Store) != 0)
+ f.SetAssigned ();
+ if ((mode & AddressOp.Load) != 0)
+ f.SetMemberIsUsed ();
+ }
//
// Handle initonly fields specially: make a copy and then
if (FieldInfo.IsStatic){
ig.Emit (OpCodes.Ldsflda, FieldInfo);
} else {
- EmitInstance (ec, false);
+ if (!prepared)
+ EmitInstance (ec, false);
ig.Emit (OpCodes.Ldflda, FieldInfo);
}
}
internal static PtrHashtable AccessorTable = new PtrHashtable ();
- public PropertyExpr (EmitContext ec, PropertyInfo pi, Location l)
+ public PropertyExpr (Type containerType, PropertyInfo pi, Location l)
{
PropertyInfo = pi;
eclass = ExprClass.PropertyAccess;
type = TypeManager.TypeToCoreType (pi.PropertyType);
- ResolveAccessors (ec);
+ ResolveAccessors (containerType);
}
public override string Name {
void FindAccessors (Type invocation_type)
{
- BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
+ const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Instance |
BindingFlags.DeclaredOnly;
// We also perform the permission checking here, as the PropertyInfo does not
// hold the information for the accessibility of its setter/getter
//
- void ResolveAccessors (EmitContext ec)
+ // TODO: can use TypeManager.GetProperty to boost performance
+ void ResolveAccessors (Type containerType)
{
- FindAccessors (ec.ContainerType);
+ FindAccessors (containerType);
if (getter != null) {
- MethodInfo the_getter = getter;
- if (the_getter.Mono_IsInflatedMethod)
- the_getter = the_getter.GetGenericMethodDefinition ();
+ MethodBase the_getter = TypeManager.DropGenericMethodArguments (getter);
IMethodData md = TypeManager.GetMethod (the_getter);
if (md != null)
md.SetMemberIsUsed ();
}
if (setter != null) {
- MethodInfo the_setter = setter;
- if (the_setter.Mono_IsInflatedMethod)
- the_setter = the_setter.GetGenericMethodDefinition ();
+ MethodBase the_setter = TypeManager.DropGenericMethodArguments (setter);
IMethodData md = TypeManager.GetMethod (the_setter);
if (md != null)
md.SetMemberIsUsed ();
}
}
- bool InstanceResolve (EmitContext ec, bool must_do_cs1540_check)
+ bool InstanceResolve (EmitContext ec, bool lvalue_instance, bool must_do_cs1540_check)
{
if (is_static) {
InstanceExpression = null;
}
if (InstanceExpression == null) {
- SimpleName.Error_ObjectRefRequired (ec, loc, PropertyInfo.Name);
+ SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return false;
}
- InstanceExpression = InstanceExpression.DoResolve (ec);
+ if (lvalue_instance)
+ InstanceExpression = InstanceExpression.ResolveLValue (ec, EmptyExpression.LValueMemberAccess, loc);
+ else
+ InstanceExpression = InstanceExpression.DoResolve (ec);
if (InstanceExpression == null)
return false;
-
- InstanceExpression.CheckMarshallByRefAccess (ec.ContainerType);
- if (must_do_cs1540_check && InstanceExpression != EmptyExpression.Null &&
- InstanceExpression.Type != ec.ContainerType &&
- ec.ContainerType.IsSubclassOf (PropertyInfo.DeclaringType) &&
- InstanceExpression.Type.IsSubclassOf (PropertyInfo.DeclaringType)) {
- Error_CannotAccessProtected (loc, PropertyInfo, InstanceExpression.Type, ec.ContainerType);
- return false;
+ InstanceExpression.CheckMarshalByRefAccess ();
+
+ if (must_do_cs1540_check && (InstanceExpression != EmptyExpression.Null) &&
+ !TypeManager.IsInstantiationOfSameGenericType (InstanceExpression.Type, ec.ContainerType) &&
+ TypeManager.IsFamilyAccessible (ec.ContainerType, PropertyInfo.DeclaringType) &&
+ !TypeManager.IsFamilyAccessible (InstanceExpression.Type, ec.ContainerType)) {
+ Error_CannotAccessProtected (loc, PropertyInfo, InstanceExpression.Type, ec.ContainerType);
+ return false;
}
return true;
return this;
if (getter != null){
- if (TypeManager.GetArgumentTypes (getter).Length != 0){
+ if (TypeManager.GetParameterData (getter).Count != 0){
Error_PropertyNotFound (getter, true);
return null;
}
Report.Error (271, loc, "The property or indexer `{0}' cannot be used in this context because the get accessor is inaccessible",
TypeManager.CSharpSignature (getter));
}
- else
+ else {
+ Report.SymbolRelatedToPreviousError (getter);
ErrorIsInaccesible (loc, TypeManager.CSharpSignature (getter));
+ }
return null;
}
-
- if (!InstanceResolve (ec, must_do_cs1540_check))
+
+ if (!InstanceResolve (ec, false, must_do_cs1540_check))
return null;
//
override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
{
+ if (right_side == EmptyExpression.OutAccess) {
+ Report.Error (206, loc, "A property or indexer `{0}' may not be passed as an out or ref parameter",
+ GetSignatureForError ());
+ return null;
+ }
+
+ if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess) {
+ Report.Error (1612, loc, "Cannot modify the return value of `{0}' because it is not a variable",
+ GetSignatureForError ());
+ return null;
+ }
+
if (setter == null){
//
// The following condition happens if the PropertyExpr was
//
if (getter == null)
return null;
-
- Report.Error (200, loc, " Property or indexer `{0}' cannot be assigned to (it is read only)",
- TypeManager.GetFullNameSignature (PropertyInfo));
+ Report.Error (200, loc, "Property or indexer `{0}' cannot be assigned to (it is read only)",
+ GetSignatureForError ());
return null;
}
- if (TypeManager.GetArgumentTypes (setter).Length != 1){
+ if (TypeManager.GetParameterData (setter).Count != 1){
Error_PropertyNotFound (setter, false);
return null;
}
Report.Error (272, loc, "The property or indexer `{0}' cannot be used in this context because the set accessor is inaccessible",
TypeManager.CSharpSignature (setter));
}
- else
+ else {
+ Report.SymbolRelatedToPreviousError (setter);
ErrorIsInaccesible (loc, TypeManager.CSharpSignature (setter));
+ }
return null;
}
-
- if (!InstanceResolve (ec, must_do_cs1540_check))
+
+ if (!InstanceResolve (ec, PropertyInfo.DeclaringType.IsValueType, must_do_cs1540_check))
return null;
//
return null;
}
- //
- // Check that we are not making changes to a temporary memory location
- //
- if (InstanceExpression != null && !CheckIntermediateModification ())
- return null;
-
return this;
}
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
if (!is_static) {
- temp = new LocalTemporary (ec, this.Type);
+ temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
if (!is_static) {
- temp = new LocalTemporary (ec, this.Type);
+ temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
} else if (leave_copy) {
source.Emit (ec);
if (!is_static) {
- temp = new LocalTemporary (ec, this.Type);
+ temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
my_source = temp;
Invocation.EmitCall (ec, IsBase, IsStatic, InstanceExpression, setter, args, loc, false, prepared);
- if (temp != null)
+ if (temp != null) {
temp.Emit (ec);
+ temp.Release (ec);
+ }
}
}
bool is_static;
MethodInfo add_accessor, remove_accessor;
+
+ internal static PtrHashtable AccessorTable = new PtrHashtable ();
public EventExpr (EventInfo ei, Location loc)
{
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;
MemberInfo mi = TypeManager.GetPrivateFieldOfEvent (EventInfo);
if (mi != null) {
- MemberExpr ml = (MemberExpr) ExprClassFromMemberInfo (ec, mi, loc);
+ MemberExpr ml = (MemberExpr) ExprClassFromMemberInfo (ec.ContainerType, mi, loc);
if (ml == null) {
Report.Error (-200, loc, "Internal error!!");
}
if (InstanceExpression == null) {
- SimpleName.Error_ObjectRefRequired (ec, loc, EventInfo.Name);
+ SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return false;
}
// This is using the same mechanism as the CS1540 check in PropertyExpr.
// However, in the Event case, we reported a CS0122 instead.
//
- if (must_do_cs1540_check && InstanceExpression != EmptyExpression.Null) {
- if ((InstanceExpression.Type != ec.ContainerType) &&
- ec.ContainerType.IsSubclassOf (InstanceExpression.Type)) {
- ErrorIsInaccesible (loc, TypeManager.CSharpSignature (EventInfo));
- return false;
- }
+ if (must_do_cs1540_check && InstanceExpression != EmptyExpression.Null &&
+ InstanceExpression.Type != ec.ContainerType &&
+ ec.ContainerType.IsSubclassOf (InstanceExpression.Type)) {
+ Report.SymbolRelatedToPreviousError (EventInfo);
+ ErrorIsInaccesible (loc, TypeManager.CSharpSignature (EventInfo));
+ return false;
}
return true;
bool must_do_cs1540_check;
if (!(IsAccessorAccessible (ec.ContainerType, add_accessor, out must_do_cs1540_check) &&
IsAccessorAccessible (ec.ContainerType, remove_accessor, out must_do_cs1540_check))) {
+ Report.SymbolRelatedToPreviousError (EventInfo);
ErrorIsInaccesible (loc, TypeManager.CSharpSignature (EventInfo));
return null;
}