(ConstraintChecker.CheckConstraints): If a type parameter has the
`struct' constraint, the type must be a non-nullable valuetype.
+2006-02-11 Marek Safar <marek.safar@seznam.cz>
+
+ First of prerequisites for new partial classs implemention.
+
+ * attribute.cs (Attributable): Extended by ResolveContext;
+ Attributes finally have correct context for resolving in all cases.
+ (AttachTo): Attribute owner is assigned here.
+
+ * codegen.cs (IResolveContext): Introduce new interface to hold
+ all information needed in resolving phase.
+ (EmitContext): Implements IResolveContext; more clean-up needed here.
+
+ * decl.cs (MemberCore): Implemented IResolveContext.
+
+ * anonymous.cs, attribute.cs, class.cs, codegen.cs, const.cs,
+ decl.cs, ecore.cs, enum.cs, expression.cs, iterators.cs, namespace.cs,
+ parameter.cs, statement.cs, tree.cs, typemanager.cs:
+ Refactored to use new IResolveContext instead of EmitContext; cleanup
+
2006-02-10 Martin Baulig <martin@ximian.com>
* typemanager.cs
TypeManager.AddUserType (this);
if (Parts != null) {
- ec = null;
foreach (ClassPart part in Parts) {
part.TypeBuilder = TypeBuilder;
- part.ec = new EmitContext (this, part, Mono.CSharp.Location.Null, null, null, ModFlags);
- part.ec.ContainerType = TypeBuilder;
}
- } else {
- //
- // Normally, we create the EmitContext here.
- // The only exception is if we're an Iterator - in this case,
- // we already have the `ec', so we don't want to create a new one.
- //
- if (ec == null)
- ec = new EmitContext (this, this, Mono.CSharp.Location.Null, null, null, ModFlags);
- ec.ContainerType = TypeBuilder;
}
if (IsGeneric) {
}
foreach (TypeParameter type_param in TypeParameters) {
- if (!type_param.DefineType (ec)) {
+ if (!type_param.DefineType (this)) {
error = true;
return false;
}
}
foreach (TypeParameter type_param in TypeParameters)
- if (!type_param.CheckDependencies (ec)) {
+ if (!type_param.CheckDependencies ()) {
error = true;
return false;
}
if (current_type != null) {
- current_type = current_type.ResolveAsTypeTerminal (ec, false);
+ current_type = current_type.ResolveAsTypeTerminal (this, false);
if (current_type == null) {
error = true;
return false;
}
- CurrentType = current_type.ResolveType (ec);
+ CurrentType = current_type.ResolveType (this);
}
return true;
if (iface_exprs != null) {
foreach (TypeExpr iface in iface_exprs) {
ConstructedType ct = iface as ConstructedType;
- if ((ct != null) && !ct.CheckConstraints (ec))
+ if ((ct != null) && !ct.CheckConstraints (this))
return false;
}
}
if (base_type != null) {
ConstructedType ct = base_type as ConstructedType;
- if ((ct != null) && !ct.CheckConstraints (ec))
+ if ((ct != null) && !ct.CheckConstraints (this))
return false;
}
if (CurrentType != null) {
GenericType = CurrentType;
-
- ec.ContainerType = GenericType;
}
indexers = null;
operators = null;
iterators = null;
- ec = null;
default_constructor = null;
default_static_constructor = null;
type_bases = null;
if (new_constraints == null)
continue;
- if (!current_params [i].UpdateConstraints (ec, new_constraints)) {
+ if (!current_params [i].UpdateConstraints (this, new_constraints)) {
Report.Error (265, Location, "Partial declarations of `{0}' have " +
"inconsistent constraints for type parameter `{1}'.",
MemberName.GetTypeName (), current_params [i].Name);
}
foreach (TypeParameter type_param in PartialContainer.TypeParameters) {
- if (!type_param.DefineType (ec))
+ if (!type_param.DefineType (this))
return false;
}
}
in_transit = true;
+ // TODO: IResolveContext here
EmitContext ec = new EmitContext (this, Parent, Location, null, MemberType, ModFlags);
value = initializer.ResolveAsConstant (ec, this);
in_transit = false;
readonly int count_type_params;
readonly int count_current_type_params;
- // The emit context for toplevel objects.
- protected EmitContext ec;
-
//
// Whether we are Generic
//
if (TypeBuilder != null)
return TypeBuilder;
- ec = new EmitContext (this, this, this, Location, null, null, ModFlags, false);
-
if (IsGeneric) {
foreach (TypeParameter type_param in TypeParameters)
if (!type_param.Resolve (this))
if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
Namespace system = RootNamespace.Global.GetNamespace ("System", true);
TypeExpr expr = system.Lookup (this, "MulticastDelegate", Location) as TypeExpr;
- TypeManager.multicast_delegate_type = expr.ResolveType (ec);
+ TypeManager.multicast_delegate_type = expr.ResolveType (this);
}
if (TypeManager.multicast_delegate_type == null)
Expression current = new SimpleName (
MemberName.Basename, TypeParameters, Location);
- current = current.ResolveAsTypeTerminal (ec, false);
+ current = current.ResolveAsTypeTerminal (this, false);
if (current == null)
return null;
if (IsGeneric) {
foreach (TypeParameter type_param in TypeParameters)
- type_param.DefineType (ec);
+ type_param.DefineType (this);
}
- if (ec == null)
- throw new InternalErrorException ("Define called before DefineType?");
-
// FIXME: POSSIBLY make this static, as it is always constant
//
Type [] const_arg_types = new Type [2];
// First, call the `out of band' special method for
// defining recursively any types we need:
- if (!Parameters.Resolve (ec))
+ if (!Parameters.Resolve (this))
return false;
//
}
}
- ReturnType = ReturnType.ResolveAsTypeTerminal (ec, false);
+ ReturnType = ReturnType.ResolveAsTypeTerminal (this, false);
if (ReturnType == null)
return false;
Parameter.Modifier.NONE, null, Location);
Parameters async_parameters = new Parameters (async_params);
- async_parameters.Resolve (ec);
+ async_parameters.Resolve (this);
async_parameters.ApplyAttributes (BeginInvokeBuilder);
TypeManager.RegisterMethod (BeginInvokeBuilder, async_parameters);
}
Parameters end_parameters = new Parameters (end_params);
- end_parameters.Resolve (ec);
+ end_parameters.Resolve (this);
TypeManager.RegisterMethod (EndInvokeBuilder, end_parameters);
return ResolveNamespaceOrType (ec, silent);
}
- public FullNamedExpression ResolveNamespaceOrType (IResolveContext ec, bool silent)
+ public FullNamedExpression ResolveNamespaceOrType (IResolveContext rc, bool silent)
{
- FullNamedExpression new_expr = expr.ResolveAsTypeStep (ec, silent);
+ FullNamedExpression new_expr = expr.ResolveAsTypeStep (rc, silent);
if (new_expr == null)
return null;
if (new_expr is Namespace) {
Namespace ns = (Namespace) new_expr;
- FullNamedExpression retval = ns.Lookup (ec.DeclContainer, lookup_id, loc);
+ FullNamedExpression retval = ns.Lookup (rc.DeclContainer, lookup_id, loc);
if ((retval != null) && (args != null))
- retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec, false);
+ retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (rc, false);
if (!silent && retval == null)
Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
Identifier, ns.FullName);
return retval;
}
- TypeExpr tnew_expr = new_expr.ResolveAsTypeTerminal (ec, false);
+ TypeExpr tnew_expr = new_expr.ResolveAsTypeTerminal (rc, false);
if (tnew_expr == null)
return null;
- Type expr_type = tnew_expr.ResolveType (ec);
+ Type expr_type = tnew_expr.ResolveType (rc);
if (expr_type.IsPointer){
Error (23, "The `.' operator can not be applied to pointer operands (" +
}
Expression member_lookup = MemberLookup (
- ec.DeclContainer.TypeBuilder, expr_type, expr_type, lookup_id,
+ rc.DeclContainer.TypeBuilder, expr_type, expr_type, lookup_id,
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
int errors = Report.Errors;
- MemberLookupFailed (ec.DeclContainer.TypeBuilder, expr_type, expr_type, lookup_id, null, false, loc);
+ MemberLookupFailed (rc.DeclContainer.TypeBuilder, expr_type, expr_type, lookup_id, null, false, loc);
if (!silent && errors == Report.Errors) {
Report.Error (426, loc, "The nested type `{0}' does not exist in the type `{1}'",
}
if (!(member_lookup is TypeExpr)) {
- new_expr.Error_UnexpectedKind (ec.DeclContainer, "type", loc);
+ new_expr.Error_UnexpectedKind (rc.DeclContainer, "type", loc);
return null;
}
- TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (ec, false);
+ TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (rc, false);
if (texpr == null)
return null;
if (the_args != null) {
ConstructedType ctype = new ConstructedType (texpr.Type, the_args, loc);
- return ctype.ResolveAsTypeStep (ec, false);
+ return ctype.ResolveAsTypeStep (rc, false);
}
return texpr;
/// <summary>
/// Resolve the constraints into actual types.
/// </summary>
- public bool ResolveTypes (EmitContext ec)
+ public bool ResolveTypes (IResolveContext ec)
{
if (resolved_types)
return true;
/// where T : class
/// where U : T, struct
/// </summary>
- public bool CheckDependencies (EmitContext ec)
+ public bool CheckDependencies ()
{
foreach (TypeParameterExpr expr in type_param_constraints) {
- if (!CheckDependencies (expr.TypeParameter, ec))
+ if (!CheckDependencies (expr.TypeParameter))
return false;
}
return true;
}
- bool CheckDependencies (TypeParameter tparam, EmitContext ec)
+ bool CheckDependencies (TypeParameter tparam)
{
Constraints constraints = tparam.Constraints;
if (constraints == null)
return true;
foreach (TypeParameterExpr expr in constraints.type_param_constraints) {
- if (!CheckDependencies (expr.TypeParameter, ec))
+ if (!CheckDependencies (expr.TypeParameter))
return false;
}
/// method. To do that, we're called on each of the implementing method's
/// type parameters.
/// </summary>
- public bool CheckInterfaceMethod (EmitContext ec, GenericConstraints gc)
+ public bool CheckInterfaceMethod (GenericConstraints gc)
{
if (gc.Attributes != attrs)
return false;
/// Note that we may have circular dependencies on type parameters - this
/// is why Resolve() and ResolveType() are separate.
/// </summary>
- public bool ResolveType (EmitContext ec)
+ public bool ResolveType (IResolveContext ec)
{
if (constraints != null) {
if (!constraints.ResolveTypes (ec)) {
/// process. We're called after everything is fully resolved and actually
/// register the constraints with SRE and the TypeManager.
/// </summary>
- public bool DefineType (EmitContext ec)
+ public bool DefineType (IResolveContext ec)
{
return DefineType (ec, null, null, false);
}
/// The `builder', `implementing' and `is_override' arguments are only
/// applicable to method type parameters.
/// </summary>
- public bool DefineType (EmitContext ec, MethodBuilder builder,
+ public bool DefineType (IResolveContext ec, MethodBuilder builder,
MethodInfo implementing, bool is_override)
{
if (!ResolveType (ec))
if (constraints != null) {
if (temp_gc == null)
ok = false;
- else if (!constraints.CheckInterfaceMethod (ec, gc))
+ else if (!constraints.CheckInterfaceMethod (gc))
ok = false;
} else {
if (!is_override && (temp_gc != null))
/// where T : class
/// where U : T, struct
/// </summary>
- public bool CheckDependencies (EmitContext ec)
+ public bool CheckDependencies ()
{
if (constraints != null)
- return constraints.CheckDependencies (ec);
+ return constraints.CheckDependencies ();
return true;
}
/// check that they're the same.
/// con
/// </summary>
- public bool UpdateConstraints (EmitContext ec, Constraints new_constraints)
+ public bool UpdateConstraints (IResolveContext ec, Constraints new_constraints)
{
if (type == null)
throw new InvalidOperationException ();
if (!new_constraints.ResolveTypes (ec))
return false;
- return constraints.CheckInterfaceMethod (ec, new_constraints);
+ return constraints.CheckInterfaceMethod (new_constraints);
}
public void EmitAttributes ()
public override bool Define ()
{
- ec = new EmitContext (this, this, this, Location, null, null, ModFlags, false);
-
for (int i = 0; i < TypeParameters.Length; i++)
if (!TypeParameters [i].Resolve (this))
return false;
return false;
for (int i = 0; i < TypeParameters.Length; i++) {
- if (!TypeParameters [i].ResolveType (ec))
+ if (!TypeParameters [i].ResolveType (this))
return false;
}
Expression generic_enumerator_type;
Expression generic_enumerable_type;
TypeArguments generic_args;
+ EmitContext ec;
protected enum State {
Uninitialized = -2,
public RootTypes ()
: base (null, null, MemberName.Null, null, Kind.Root)
{
- ec = new EmitContext (this, null, this, Location.Null, null, null, 0, false);
}
public override PendingImplementation GetPendingImplementations ()