* *.cs: Only ResolveContext implements IMemberContext.
svn path=/trunk/mcs/; revision=140512
+2009-08-24 Marek Safar <marek.safar@gmail.com>
+
+ * *.cs: Only ResolveContext implements IMemberContext.
+
2009-08-21 Marek Safar <marek.safar@gmail.com>
* *.cs: Renamed IResolveContext to IMemberContext.
if (ec.HasSet (EmitContext.Options.FieldInitializerScope))
flags |= EmitContext.Options.FieldInitializerScope;
- if (ec.InUnsafe)
+ if (ec.IsUnsafe)
flags |= EmitContext.Options.UnsafeScope;
// HACK: Flag with 0 cannot be set
field_infos.Add (fi);
}
- if (obsolete_attr != null && !context.IsInObsoleteScope)
+ if (obsolete_attr != null && !context.IsObsolete)
AttributeTester.Report_ObsoleteMessage (obsolete_attr, member.GetSignatureForError (), member.Location);
}
get { return tc.Parent; }
}
- public bool IsInObsoleteScope {
- get { return tc.IsInObsoleteScope; }
+ public bool IsObsolete {
+ get { return tc.IsObsolete; }
}
- public bool IsInUnsafeScope {
- get { return tc.IsInUnsafeScope; }
+ public bool IsUnsafe {
+ get { return tc.IsUnsafe; }
}
public bool IsStatic {
if (iface_exprs != null) {
foreach (TypeExpr iface in iface_exprs) {
ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (iface.Type);
- if ((oa != null) && !IsInObsoleteScope)
+ if ((oa != null) && !IsObsolete)
AttributeTester.Report_ObsoleteMessage (
oa, iface.GetSignatureForError (), Location);
if (base_type != null) {
ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
- if (obsolete_attr != null && !IsInObsoleteScope)
+ if (obsolete_attr != null && !IsObsolete)
AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
GenericTypeExpr ct = base_type as GenericTypeExpr;
parent_method = implementing;
EmitContext ec = method.CreateEmitContext (null);
- if (!GenericMethod.DefineType (ec, builder, parent_method, is_override))
+ if (!GenericMethod.DefineType (ec.MemberContext, builder, parent_method, is_override))
return false;
}
{
base.DoMemberTypeIndependentChecks ();
- if (!Parent.IsInUnsafeScope)
+ if (!Parent.IsUnsafe)
Expression.UnsafeError (Location);
if (Parent.PartialContainer.Kind != Kind.Struct) {
//
TypeContainer CurrentTypeDefinition { get; }
- bool IsInObsoleteScope { get; }
- bool IsInUnsafeScope { get; }
+ bool IsObsolete { get; }
+ bool IsUnsafe { get; }
bool IsStatic { get; }
ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc);
/// An Emit Context is created for each body of code (from methods,
/// properties bodies, indexer bodies or constructor bodies)
/// </summary>
- public class EmitContext : IMemberContext {
+ public class EmitContext {
[Flags]
public enum Options
get { return MemberContext.CurrentTypeDefinition; }
}
- public bool InUnsafe {
- get { return HasSet (Options.UnsafeScope) || MemberContext.IsInUnsafeScope; }
- }
-
public bool HasSet (Options options)
{
return (this.flags & options) == options;
return new FlagsHandle (this, Options.DoFlowAnalysis | Options.OmitStructFlowAnalysis, newflags);
}
- // IResolveContext.IsInObsoleteScope
- public bool IsInObsoleteScope {
- get {
- // Disables obsolete checks when probing is on
- return IsInProbingMode || MemberContext.IsInObsoleteScope;
- }
- }
-
- public bool IsInProbingMode {
- get { return (flags & Options.ProbingMode) != 0; }
- }
-
- bool IMemberContext.IsInUnsafeScope {
- get { return InUnsafe; }
- }
-
public bool IsStatic {
get { return MemberContext.IsStatic; }
}
return return_value;
}
-
- #region IResolveContext Members
-
- public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
- {
- return MemberContext.LookupExtensionMethod (extensionType, name, loc);
- }
-
- public FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
- {
- return MemberContext.LookupNamespaceOrType (name, loc, ignore_cs0104);
- }
-
- public FullNamedExpression LookupNamespaceAlias (string name)
- {
- return MemberContext.LookupNamespaceAlias (name);
- }
-
- #endregion
}
- public class ResolveContext : EmitContext
+ public class ResolveContext : EmitContext, IMemberContext
{
//
// Holds a varible used during collection or object initialization.
get { return (flags & Options.DoFlowAnalysis) != 0; }
}
+ public bool IsInProbingMode {
+ get { return (flags & Options.ProbingMode) != 0; }
+ }
+
public bool IsVariableCapturingRequired {
get {
return !IsInProbingMode && (CurrentBranching == null || !CurrentBranching.CurrentUsageVector.IsUnreachable);
return local.Block.Toplevel != CurrentBlock.Toplevel;
}
+
+ #region IMemberContext Members
+
+ public bool IsObsolete {
+ get {
+ // Disables obsolete checks when probing is on
+ return IsInProbingMode || MemberContext.IsObsolete;
+ }
+ }
+
+ public bool IsUnsafe {
+ get { return HasSet (Options.UnsafeScope) || MemberContext.IsUnsafe; }
+ }
+
+ public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+ {
+ return MemberContext.LookupExtensionMethod (extensionType, name, loc);
+ }
+
+ public FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
+ {
+ return MemberContext.LookupNamespaceOrType (name, loc, ignore_cs0104);
+ }
+
+ public FullNamedExpression LookupNamespaceAlias (string name)
+ {
+ return MemberContext.LookupNamespaceAlias (name);
+ }
+
+ #endregion
}
get { return RootContext.ToplevelTypes; }
}
- public bool IsInObsoleteScope {
+ public bool IsObsolete {
get { return false; }
}
- public bool IsInUnsafeScope {
+ public bool IsUnsafe {
get { return false; }
}
return new EnumConstant (i, target_type);
}
- if (ec.InUnsafe) {
+ if (ec.IsUnsafe) {
if (expr_type.IsPointer){
if (target_type == TypeManager.void_ptr_type)
return EmptyCast.Create (expr, target_type);
return ne;
}
- if (ec.InUnsafe){
+ if (ec.IsUnsafe){
ne = ExplicitUnsafe (expr, target_type);
if (ne != null)
return ne;
if (ne != null)
return ne;
- if (ec.InUnsafe && expr.Type == TypeManager.void_ptr_type && target_type.IsPointer)
+ if (ec.IsUnsafe && expr.Type == TypeManager.void_ptr_type && target_type.IsPointer)
return EmptyCast.Create (expr, target_type);
expr.Error_ValueCannotBeConverted (ec, l, target_type, true);
get { return Parent; }
}
- public bool IsInObsoleteScope {
+ public bool IsObsolete {
get {
if (GetObsoleteAttribute () != null)
return true;
- return Parent == null ? false : Parent.IsInObsoleteScope;
+ return Parent == null ? false : Parent.IsObsolete;
}
}
- public bool IsInUnsafeScope {
+ public bool IsUnsafe {
get {
if ((ModFlags & Modifiers.UNSAFE) != 0)
return true;
- return Parent == null ? false : Parent.IsInUnsafeScope;
+ return Parent == null ? false : Parent.IsUnsafe;
}
}
const int partial_modifiers = Modifiers.STATIC | Modifiers.UNSAFE;
if (method_a.IsPartialDefinition == method_b.IsPartialImplementation) {
if ((method_a.ModFlags & partial_modifiers) == (method_b.ModFlags & partial_modifiers) ||
- method_a.Parent.IsInUnsafeScope && method_b.Parent.IsInUnsafeScope) {
+ method_a.Parent.IsUnsafe && method_b.Parent.IsUnsafe) {
if (method_a.IsPartialImplementation) {
method_a.SetPartialDefinition (method_b);
entries.RemoveAt (i);
if (!silent) { // && !(te is TypeParameterExpr)) {
ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (te.Type);
- if (obsolete_attr != null && !ec.IsInObsoleteScope) {
+ if (obsolete_attr != null && !ec.IsObsolete) {
AttributeTester.Report_ObsoleteMessage (obsolete_attr, te.GetSignatureForError (), Location);
}
}
// TODO: Same problem as in class.cs, TypeTerminal does not
// always do all necessary checks
ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (left.Type);
- if (oa != null && !ec.IsInObsoleteScope) {
+ if (oa != null && !ec.IsObsolete) {
AttributeTester.Report_ObsoleteMessage (oa, left.GetSignatureForError (), loc);
}
// Check ObsoleteAttribute on the best method
//
ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (the_method);
- if (oa != null && !ec.IsInObsoleteScope)
+ if (oa != null && !ec.IsObsolete)
AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
IMethodData data = TypeManager.GetMethod (the_method);
return false;
}
- if (has_unsafe_arg && !ec.InUnsafe) {
+ if (has_unsafe_arg && !ec.IsUnsafe) {
if (!may_fail)
UnsafeError (loc);
return false;
{
IConstant ic = TypeManager.GetConstant (constant);
if (ic.ResolveValue ()) {
- if (!ec.IsInObsoleteScope)
+ if (!ec.IsObsolete)
ic.CheckObsoleteness (loc);
}
FieldInfo fi = TypeManager.GetGenericFieldDefinition (FieldInfo);
Type t = fi.FieldType;
- if (t.IsPointer && !ec.InUnsafe) {
+ if (t.IsPointer && !ec.IsUnsafe) {
UnsafeError (loc);
}
if (eclass != ExprClass.Invalid)
return this;
- if (!ec.IsInObsoleteScope) {
+ if (!ec.IsObsolete) {
FieldBase f = TypeManager.GetField (FieldInfo);
if (f != null) {
f.CheckObsoleteness (loc);
Error_CannotCallAbstractBase (TypeManager.GetFullNameSignature (PropertyInfo));
}
- if (PropertyInfo.PropertyType.IsPointer && !ec.InUnsafe){
+ if (PropertyInfo.PropertyType.IsPointer && !ec.IsUnsafe){
UnsafeError (loc);
}
- if (!ec.IsInObsoleteScope) {
+ if (!ec.IsObsolete) {
PropertyBase pb = TypeManager.GetProperty (PropertyInfo);
if (pb != null) {
pb.CheckObsoleteness (loc);
Error_CannotCallAbstractBase (TypeManager.GetFullNameSignature (PropertyInfo));
}
- if (PropertyInfo.PropertyType.IsPointer && !ec.InUnsafe) {
+ if (PropertyInfo.PropertyType.IsPointer && !ec.IsUnsafe) {
UnsafeError (loc);
}
- if (!ec.IsInObsoleteScope) {
+ if (!ec.IsObsolete) {
PropertyBase pb = TypeManager.GetProperty (PropertyInfo);
if (pb != null) {
pb.CheckObsoleteness (loc);
EventField mi = TypeManager.GetEventField (EventInfo);
if (mi != null) {
- if (!ec.IsInObsoleteScope)
+ if (!ec.IsObsolete)
mi.CheckObsoleteness (loc);
if ((mi.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0 && !ec.HasSet (EmitContext.Options.CompoundAssignmentScope))
return null;
}
- if (!ec.IsInObsoleteScope) {
+ if (!ec.IsObsolete) {
EventField ev = TypeManager.GetEventField (EventInfo);
if (ev != null) {
ev.CheckObsoleteness (loc);
Expression ResolveAddressOf (ResolveContext ec)
{
- if (!ec.InUnsafe)
+ if (!ec.IsUnsafe)
UnsafeError (loc);
Expr = Expr.DoResolveLValue (ec, EmptyExpression.UnaryAddress);
if (expr == null)
return null;
- if (!ec.InUnsafe)
+ if (!ec.IsUnsafe)
UnsafeError (loc);
if (!expr.Type.IsPointer) {
return c;
}
- if (type.IsPointer && !ec.InUnsafe) {
+ if (type.IsPointer && !ec.IsUnsafe) {
UnsafeError (loc);
} else if (TypeManager.IsDynamicType (expr.Type)) {
Arguments arg = new Arguments (1);
}
if (type.IsPointer){
- if (!ec.InUnsafe){
+ if (!ec.IsUnsafe){
UnsafeError (loc);
return null;
}
if (typearg == TypeManager.void_type) {
Report.Error (673, loc, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
- } else if (typearg.IsPointer && !ec.InUnsafe){
+ } else if (typearg.IsPointer && !ec.IsUnsafe){
UnsafeError (loc);
} else if (texpr is DynamicTypeExpr) {
Report.Error (1962, QueriedType.Location,
return null;
}
- if (!ec.InUnsafe) {
+ if (!ec.IsUnsafe) {
Report.Error (233, loc,
"`{0}' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf)",
TypeManager.CSharpName (type_queried));
}
type = TypeManager.GetElementType (t);
- if (type.IsPointer && !ec.InUnsafe) {
+ if (type.IsPointer && !ec.IsUnsafe) {
UnsafeError (ea.Location);
}
}
type = TypeManager.TypeToCoreType (pi.PropertyType);
- if (type.IsPointer && !ec.InUnsafe)
+ if (type.IsPointer && !ec.IsUnsafe)
UnsafeError (loc);
MethodInfo accessor;
if (type == null)
throw new InternalErrorException ("Couldn't create computed type " + ltype + dim);
- if (type.IsPointer && !ec.IsInUnsafeScope){
+ if (type.IsPointer && !ec.IsUnsafe){
UnsafeError (loc);
}
throw new NotImplementedException ();
}
- public bool DefineType (EmitContext ec, MethodBuilder mb,
+ public bool DefineType (IMemberContext ec, MethodBuilder mb,
MethodInfo implementing, bool is_override)
{
throw new NotImplementedException ();
protected abstract string GetSignatureForError ();
protected abstract void Report_SymbolRelatedToPreviousError ();
- public static bool CheckConstraints (EmitContext ec, MethodBase definition,
+ public static bool CheckConstraints (IMemberContext ec, MethodBase definition,
MethodBase instantiated, Location loc)
{
MethodConstraintChecker checker = new MethodConstraintChecker (
/// <summary>
/// We're called from MethodData.Define() after creating the MethodBuilder.
/// </summary>
- public bool DefineType (EmitContext ec, MethodBuilder mb,
+ public bool DefineType (IMemberContext ec, MethodBuilder mb,
MethodInfo implementing, bool is_override)
{
for (int i = 0; i < TypeParameters.Length; i++)
get { return SlaveDeclSpace; }
}
- public bool IsInObsoleteScope {
- get { return SlaveDeclSpace.IsInObsoleteScope; }
+ public bool IsObsolete {
+ get { return SlaveDeclSpace.IsObsolete; }
}
- public bool IsInUnsafeScope {
- get { return SlaveDeclSpace.IsInUnsafeScope; }
+ public bool IsUnsafe {
+ get { return SlaveDeclSpace.IsUnsafe; }
}
public bool IsStatic {
//
// System.Linq.Expressions.ParameterExpression type
//
- public static TypeExpr ResolveParameterExpressionType (EmitContext ec, Location location)
+ public static TypeExpr ResolveParameterExpressionType (IMemberContext ec, Location location)
{
if (parameter_expr_tree_type != null)
return parameter_expr_tree_type;
return false;
}
- if (VariableType.IsPointer && !ec.InUnsafe)
+ if (VariableType.IsPointer && !ec.IsUnsafe)
Expression.UnsafeError (Location);
return true;
// If some parent block was unsafe, we remain unsafe even if this block
// isn't explicitly marked as such.
- using (ec.With (EmitContext.Options.UnsafeScope, ec.InUnsafe | Unsafe)) {
+ using (ec.With (EmitContext.Options.UnsafeScope, ec.IsUnsafe | Unsafe)) {
flags |= Flags.VariablesInitialized;
if (variables != null) {
public override bool Resolve (BlockContext ec)
{
- if (!ec.InUnsafe){
+ if (!ec.IsUnsafe){
Expression.UnsafeError (loc);
return false;
}