Skip to content

Commit

Permalink
2004-11-10 Martin Baulig <martin@ximian.com>
Browse files Browse the repository at this point in the history
	* class.cs (TypeContainer.DefineType): Call
	TypeBuilder.DefineGenericParameters() before resolving the type
	parameters.
	(MethodData.parent_method): New protected field.
	(MethodData..ctor): Added `MethodInfo parent_method' argument.
	(MethodData.Define): Compute `parent_method'.

	* decl.cs
	(MemberCore.GetObsoleteAttribute): Don't create a new EmitContext.
	(MemberCore.GetClsCompliantAttributeValue): Likewise.
	(DeclSpace.ec): New protected field; store the EmitContext here.
	(DeclSpace.EmitContext): New public property.
	(DeclSpace.ResolveType): Un-comment from the [Obsolte] attribute.
	(DeclSpace.ResolveNestedType): New public method.
	(DeclSpace.ResolveTypeExpr): Just call ResolveAsTypeTerminal() here.
	(DeclSpace.NestedAccessible): Added `Type tb' argument.
	(DeclSpace.FamilyAccessible): Likewise.
	(DeclSpace.FindType): Call ResolveNestedType() for nested types.
	(DeclSpace.GetClsCompliantAttributeValue): Don't create a new
	EmitContext.

	* delegate.cs (Delegate.Define): Store the EmitContext in the `ec'
	field.

	* enum.cs (Enum.Define): Store the EmitContext in the `ec' field.
	(Enum.Emit): Don't create a new EmitContext.

svn path=/trunk/mcs/; revision=35925
  • Loading branch information
Martin Baulig committed Nov 9, 2004
1 parent 1a79dad commit a17130c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 109 deletions.
29 changes: 29 additions & 0 deletions mcs/gmcs/ChangeLog
@@ -1,3 +1,32 @@
2004-11-10 Martin Baulig <martin@ximian.com>

* class.cs (TypeContainer.DefineType): Call
TypeBuilder.DefineGenericParameters() before resolving the type
parameters.
(MethodData.parent_method): New protected field.
(MethodData..ctor): Added `MethodInfo parent_method' argument.
(MethodData.Define): Compute `parent_method'.

* decl.cs
(MemberCore.GetObsoleteAttribute): Don't create a new EmitContext.
(MemberCore.GetClsCompliantAttributeValue): Likewise.
(DeclSpace.ec): New protected field; store the EmitContext here.
(DeclSpace.EmitContext): New public property.
(DeclSpace.ResolveType): Un-comment from the [Obsolte] attribute.
(DeclSpace.ResolveNestedType): New public method.
(DeclSpace.ResolveTypeExpr): Just call ResolveAsTypeTerminal() here.
(DeclSpace.NestedAccessible): Added `Type tb' argument.
(DeclSpace.FamilyAccessible): Likewise.
(DeclSpace.FindType): Call ResolveNestedType() for nested types.
(DeclSpace.GetClsCompliantAttributeValue): Don't create a new
EmitContext.

* delegate.cs (Delegate.Define): Store the EmitContext in the `ec'
field.

* enum.cs (Enum.Define): Store the EmitContext in the `ec' field.
(Enum.Emit): Don't create a new EmitContext.

2004-10-18 Martin Baulig <martin@ximian.com>

* statement.cs (Fixed.Resolve): Don't access the TypeExpr's
Expand Down
43 changes: 24 additions & 19 deletions mcs/gmcs/class.cs
Expand Up @@ -1210,27 +1210,28 @@ public override TypeBuilder DefineType ()
TypeManager.AddUserType (Name, TypeBuilder, this);

if (IsGeneric) {
int offset = CountTypeParameters - CurrentTypeParameters.Length;
foreach (TypeParameter type_param in CurrentTypeParameters) {
if (!type_param.Resolve (this)) {
error = true;
return null;
}
}

CurrentType = new ConstructedType (
Name, TypeParameters, Location);

string[] param_names = new string [TypeParameters.Length];
for (int i = 0; i < TypeParameters.Length; i++)
param_names [i] = TypeParameters [i].Name;

GenericTypeParameterBuilder[] gen_params;

gen_params = TypeBuilder.DefineGenericParameters (param_names);

int offset = CountTypeParameters - CurrentTypeParameters.Length;
for (int i = offset; i < gen_params.Length; i++)
CurrentTypeParameters [i - offset].Define (gen_params [i]);

foreach (TypeParameter type_param in CurrentTypeParameters) {
if (!type_param.Resolve (this)) {
error = true;
return null;
}
}

for (int i = offset; i < gen_params.Length; i++)
CurrentTypeParameters [i - offset].DefineConstraints ();

CurrentType = new ConstructedType (Name, TypeParameters, Location);
}

if (IsGeneric) {
Expand Down Expand Up @@ -3828,7 +3829,7 @@ public override bool Define ()
flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;

MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
this, mb, GenericMethod);
this, mb, GenericMethod, parent_method);

if (!MethodData.Define (Parent))
return false;
Expand Down Expand Up @@ -4614,6 +4615,7 @@ public class MethodData {
protected int modifiers;
protected MethodAttributes flags;
protected Type declaring_type;
protected MethodInfo parent_method;

EmitContext ec;

Expand Down Expand Up @@ -4644,11 +4646,12 @@ public class MethodData {
public MethodData (MemberBase member, InternalParameters parameters,
int modifiers, MethodAttributes flags,
IMethodData method, MethodBuilder builder,
GenericMethod generic)
GenericMethod generic, MethodInfo parent_method)
: this (member, parameters, modifiers, flags, method)
{
this.builder = builder;
this.GenericMethod = generic;
this.parent_method = parent_method;
}

static string RemoveArity (string name)
Expand Down Expand Up @@ -4811,10 +4814,10 @@ public bool Define (TypeContainer container)
bool is_override = member.IsExplicitImpl |
((modifiers & Modifiers.OVERRIDE) != 0);

is_override &= IsImplementing;
if (implementing != null)
parent_method = implementing;

if (!GenericMethod.DefineType (
ec, builder, implementing, is_override))
if (!GenericMethod.DefineType (ec, builder, parent_method, is_override))
return false;
}

Expand Down Expand Up @@ -5213,6 +5216,8 @@ protected virtual bool DoDefine (DeclSpace decl)
return false;

InterfaceType = iface_texpr.ResolveType (ec);
if (InterfaceType == null)
return false;

if (InterfaceType.IsClass) {
Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
Expand Down Expand Up @@ -5481,6 +5486,8 @@ public override bool Define()

MemberType = texpr.ResolveType (ec);
ec.InUnsafe = old_unsafe;
if (MemberType == null)
return false;

if (!CheckBase ())
return false;
Expand Down Expand Up @@ -6867,10 +6874,8 @@ protected override InternalParameters GetParameterInfo (EmitContext ec)

return new InternalParameters (types, set_formal_params);
}

}


const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Expand Down
112 changes: 32 additions & 80 deletions mcs/gmcs/decl.cs
Expand Up @@ -350,11 +350,8 @@ public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
if (OptAttributes == null)
return null;

// TODO: remove this allocation
EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
null, null, ds.ModFlags, false);

Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
Attribute obsolete_attr = OptAttributes.Search (
TypeManager.obsolete_attribute_type, ds.EmitContext);
if (obsolete_attr == null)
return null;

Expand Down Expand Up @@ -407,9 +404,7 @@ protected bool IsExposedFromAssembly (DeclSpace ds)
bool GetClsCompliantAttributeValue (DeclSpace ds)
{
if (OptAttributes != null) {
EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
null, null, ds.ModFlags, false);
Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ds.EmitContext);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
return cls_attribute.GetClsCompliantAttributeValue (ds);
Expand Down Expand Up @@ -482,6 +477,9 @@ public abstract class DeclSpace : MemberCore, IAlias {
/// </summary>
public TypeExpr CurrentType;

// The emit context for toplevel objects.
protected EmitContext ec;

//
// This is the namespace in which this typecontainer
// was declared. We use this to resolve names.
Expand Down Expand Up @@ -596,6 +594,12 @@ public MemberCore GetDefinition (string name)
}
}

public EmitContext EmitContext {
get {
return ec;
}
}

/// <summary>
/// Looks up the alias for the name
/// </summary>
Expand Down Expand Up @@ -686,30 +690,15 @@ EmitContext GetTypeResolveEmitContext (TypeContainer parent, Location loc)
// <summary>
// Looks up the type, as parsed into the expression `e'.
// </summary>
//[Obsolete ("This method is going away soon")]
[Obsolete ("This method is going away soon")]
public Type ResolveType (Expression e, bool silent, Location loc)
{
TypeExpr d = ResolveTypeExpr (e, silent, loc);
if (d == null)
return null;

return ResolveType (d, loc);
return d == null ? null : d.Type;
}

public Type ResolveType (TypeExpr d, Location loc)
public Type ResolveNestedType (Type t, Location loc)
{
if (!d.CheckAccessLevel (this)) {
Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", d.Name);
return null;
}

Type t = d.ResolveType (type_resolve_ec);
if (t == null)
return null;

if (d is UnboundTypeExpression)
return t;

TypeContainer tc = TypeManager.LookupTypeContainer (t);
if ((tc != null) && tc.IsGeneric) {
if (!IsGeneric) {
Expand All @@ -721,10 +710,14 @@ public Type ResolveType (TypeExpr d, Location loc)
return null;
}

ConstructedType ctype = new ConstructedType (
t, TypeParameters, loc);
TypeParameter[] args;
if (this is GenericMethod)
args = Parent.TypeParameters;
else
args = TypeParameters;

t = ctype.ResolveType (type_resolve_ec);
ConstructedType ctype = new ConstructedType (t, args, loc);
t = ctype.ResolveType (ec);
}

return t;
Expand All @@ -744,50 +737,13 @@ public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
else
type_resolve_ec.ContainerType = TypeBuilder;

int errors = Report.Errors;

TypeExpr d = e.ResolveAsTypeTerminal (type_resolve_ec, silent);

if ((d != null) && (d.eclass == ExprClass.Type))
return d;

if (silent || (Report.Errors != errors))
return null;

if (e is SimpleName){
SimpleName s = new SimpleName (((SimpleName) e).Name, loc);
d = s.ResolveAsTypeTerminal (type_resolve_ec, silent);

if ((d == null) || (d.Type == null)) {
Report.Error (246, loc, "Cannot find type `{0}'", e);
return null;
}

int num_args = TypeManager.GetNumberOfTypeArguments (d.Type);

if (num_args == 0) {
Report.Error (308, loc,
"The non-generic type `{0}' cannot " +
"be used with type arguments.",
TypeManager.CSharpName (d.Type));
return null;
}

Report.Error (305, loc,
"Using the generic type `{0}' " +
"requires {1} type arguments",
TypeManager.GetFullName (d.Type), num_args);
return null;
}

Report.Error (246, loc, "Cannot find type `{0}'", e);
return null;
return e.ResolveAsTypeTerminal (type_resolve_ec, silent);
}

public bool CheckAccessLevel (Type check_type)
{
TypeBuilder tb;
if (this is GenericMethod)
if ((this is GenericMethod) || (this is Iterator))
tb = Parent.TypeBuilder;
else
tb = TypeBuilder;
Expand All @@ -802,7 +758,7 @@ public bool CheckAccessLevel (Type check_type)
return true; // FIXME

TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;

//
// Broken Microsoft runtime, return public for arrays, no matter what
// the accessibility is for their underlying class, and they return
Expand All @@ -822,7 +778,6 @@ public bool CheckAccessLevel (Type check_type)
// However, this is invoked again later -- so safe to return true.
// May also be null when resolving top-level attributes.
return true;

//
// This test should probably use the declaringtype.
//
Expand All @@ -832,7 +787,7 @@ public bool CheckAccessLevel (Type check_type)
return true;

case TypeAttributes.NestedPrivate:
return NestedAccessible (check_type);
return NestedAccessible (tb, check_type);

case TypeAttributes.NestedFamily:
//
Expand All @@ -857,7 +812,7 @@ public bool CheckAccessLevel (Type check_type)

}

protected bool NestedAccessible (Type check_type)
protected bool NestedAccessible (Type tb, Type check_type)
{
string check_type_name = check_type.FullName;

Expand All @@ -868,21 +823,20 @@ protected bool NestedAccessible (Type check_type)
string container = check_type_name.Substring (0, cio + 1);

// Ensure that type_name ends with a '+' so that it can match 'container', if necessary
string type_name = TypeBuilder.FullName + "+";
string type_name = tb.FullName + "+";

// If the current class is nested inside the container of check_type,
// we can access check_type even if it is private or protected.
return type_name.StartsWith (container);
}

protected bool FamilyAccessible (Type check_type)
protected bool FamilyAccessible (Type tb, Type check_type)
{
Type declaring = check_type.DeclaringType;
if (TypeBuilder == declaring ||
TypeBuilder.IsSubclassOf (declaring))
if (tb == declaring || TypeManager.IsFamilyAccessible (tb, declaring))
return true;

return NestedAccessible (check_type);
return NestedAccessible (tb, check_type);
}

// Access level of a type.
Expand Down Expand Up @@ -1120,7 +1074,7 @@ public Type FindType (Location loc, string name)
return null;

if ((t != null) && containing_ds.CheckAccessLevel (t))
return t;
return ResolveNestedType (t, loc);

current_type = current_type.BaseType;
}
Expand Down Expand Up @@ -1248,8 +1202,6 @@ public bool GetClsCompliantAttributeValue ()
caching_flags &= ~Flags.HasCompliantAttribute_Undetected;

if (OptAttributes != null) {
EmitContext ec = new EmitContext (Parent, this, Location,
null, null, ModFlags, false);
Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
Expand Down
5 changes: 1 addition & 4 deletions mcs/gmcs/delegate.cs
Expand Up @@ -142,8 +142,7 @@ public override bool Define ()
{
MethodAttributes mattr;
int i;
EmitContext ec = new EmitContext (this, this, Location, null,
null, ModFlags, false);
ec = new EmitContext (this, this, Location, null, null, ModFlags, false);

if (IsGeneric) {
foreach (TypeParameter type_param in TypeParameters)
Expand Down Expand Up @@ -394,8 +393,6 @@ public override bool Define ()
public override void Emit ()
{
if (OptAttributes != null) {
EmitContext ec = new EmitContext (
Parent, this, Location, null, null, ModFlags, false);
Parameters.LabelParameters (ec, InvokeBuilder, Location);
OptAttributes.Emit (ec, this);
}
Expand Down

0 comments on commit a17130c

Please sign in to comment.