public override MemberSpec InflateMember(TypeParameterInflator inflator) { var fs = (FieldSpec)base.InflateMember(inflator); fs.memberType = inflator.Inflate(memberType); return(fs); }
public virtual MemberSpec InflateMember(TypeParameterInflator inflator) { var inflated = (MemberSpec) MemberwiseClone (); inflated.declaringType = inflator.TypeInstance; if (DeclaringType.IsGenericOrParentIsGeneric) inflated.state |= StateFlags.PendingMetaInflate; #if DEBUG inflated.ID += 1000000; #endif return inflated; }
public override MemberSpec InflateMember(TypeParameterInflator inflator) { var targs = IsGeneric ? MemberDefinition.TypeParameters : TypeSpec.EmptyTypes; // // When inflating nested type from inside the type instance will be same // because type parameters are same for all nested types // if (DeclaringType == inflator.TypeInstance) { return(MakeGenericType(inflator.Context, targs)); } return(new InflatedTypeSpec(inflator.Context, this, inflator.TypeInstance, targs)); }
public AParametersCollection Inflate(TypeParameterInflator inflator) { TypeSpec[] inflated_types = null; bool default_value = false; for (int i = 0; i < Count; ++i) { var inflated_param = inflator.Inflate(types[i]); if (inflated_types == null) { if (inflated_param == types[i]) { continue; } default_value |= FixedParameters[i] is DefaultValueExpression; inflated_types = new TypeSpec[types.Length]; Array.Copy(types, inflated_types, types.Length); } inflated_types[i] = inflated_param; } if (inflated_types == null) { return(this); } var clone = (AParametersCollection)MemberwiseClone(); clone.types = inflated_types; if (default_value) { for (int i = 0; i < Count; ++i) { var dve = clone.FixedParameters[i] as DefaultValueExpression; if (dve != null) { throw new NotImplementedException("net"); // clone.FixedParameters [i].DefaultValue = new DefaultValueExpression (); } } } return(clone); }
// // Creates a nested container in this context for all dynamic compiler generated stuff // internal DynamicSiteClass CreateDynamicSite() { if (dynamic_site_container == null) { var mc = member_context.CurrentMemberDefinition as MemberBase; dynamic_site_container = new DynamicSiteClass(CurrentTypeDefinition.Parent.PartialContainer, mc, member_context.CurrentTypeParameters); CurrentTypeDefinition.Module.AddCompilerGeneratedClass(dynamic_site_container); dynamic_site_container.CreateContainer(); dynamic_site_container.DefineContainer(); dynamic_site_container.Define(); var inflator = new TypeParameterInflator(Module, CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes); var inflated = dynamic_site_container.CurrentType.InflateMember(inflator); CurrentType.MemberCache.AddMember(inflated); } return(dynamic_site_container); }
public FieldSpec CreateCallSiteField(FullNamedExpression type, Location loc) { int index = fields == null ? 0 : fields.Count; Field f = new HoistedField(this, type, Modifiers.PUBLIC | Modifiers.STATIC, "Site" + index.ToString("X"), null, loc); f.Define(); AddField(f); var fs = f.Spec; if (mutator != null) { // // Inflate the field, no need to keep it in MemberCache as it's accessed only once // var inflator = new TypeParameterInflator(instance_type, spec.MemberDefinition.TypeParameters, instance_type.TypeArguments); fs = (FieldSpec)fs.InflateMember(inflator); } return(fs); }
public override TypeSpec AddDelegate(Delegate d) { TypeSpec inflated; base.AddDelegate(d); // Inflated type instance has to be updated manually if (instance_type is InflatedTypeSpec) { var inflator = new TypeParameterInflator(instance_type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes); inflated = (TypeSpec)d.CurrentType.InflateMember(inflator); instance_type.MemberCache.AddMember(inflated); //inflator = new TypeParameterInflator (d.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes); //d.Parent.CurrentType.MemberCache.AddMember (d.CurrentType.InflateMember (inflator)); } else { inflated = d.CurrentType; } return(inflated); }
public override MemberSpec InflateMember (TypeParameterInflator inflator) { var fs = (FieldSpec) base.InflateMember (inflator); fs.memberType = inflator.Inflate (memberType); return fs; }
public AParametersCollection Inflate (TypeParameterInflator inflator) { TypeSpec[] inflated_types = null; bool default_value = false; for (int i = 0; i < Count; ++i) { var inflated_param = inflator.Inflate (types[i]); if (inflated_types == null) { if (inflated_param == types[i]) continue; default_value |= FixedParameters[i].HasDefaultValue; inflated_types = new TypeSpec[types.Length]; Array.Copy (types, inflated_types, types.Length); } else { if (inflated_param == types[i]) continue; default_value |= FixedParameters[i].HasDefaultValue; } inflated_types[i] = inflated_param; } if (inflated_types == null) return this; var clone = (AParametersCollection) MemberwiseClone (); clone.types = inflated_types; // // Default expression is original expression from the parameter // declaration context which can be of nested enum in generic class type. // In such case we end up with expression type of G<T>.E and e.g. parameter // type of G<int>.E and conversion would fail without inflate in this // context. // if (default_value) { clone.parameters = new IParameterData[Count]; for (int i = 0; i < Count; ++i) { var fp = FixedParameters[i]; clone.FixedParameters[i] = fp; if (!fp.HasDefaultValue) continue; var expr = fp.DefaultValue; if (inflated_types[i] == expr.Type) continue; if (expr is DefaultValueExpression) expr = new DefaultValueExpression (new TypeExpression (inflated_types[i], expr.Location), expr.Location); else if (expr is Constant) expr = Constant.CreateConstantFromValue (inflated_types[i], ((Constant) expr).GetValue (), expr.Location); clone.FixedParameters[i] = new ParameterData (fp.Name, fp.ModFlags, expr); } } return clone; }
protected void EmitCall(EmitContext ec, Expression binder, Arguments arguments, bool isStatement) { // // This method generates all internal infrastructure for a dynamic call. The // reason why it's quite complicated is the mixture of dynamic and anonymous // methods. Dynamic itself requires a temporary class (ContainerX) and anonymous // methods can generate temporary storey as well (AnonStorey). Handling MVAR // type parameters rewrite is non-trivial in such case as there are various // combinations possible therefore the mutator is not straightforward. Secondly // we need to keep both MVAR(possibly VAR for anon storey) and type VAR to emit // correct Site field type and its access from EmitContext. // int dyn_args_count = arguments == null ? 0 : arguments.Count; int default_args = isStatement ? 1 : 2; var module = ec.Module; bool has_ref_out_argument = false; var targs = new TypeExpression[dyn_args_count + default_args]; targs[0] = new TypeExpression(module.PredefinedTypes.CallSite.TypeSpec, loc); TypeExpression[] targs_for_instance = null; TypeParameterMutator mutator; var site_container = ec.CreateDynamicSite(); if (context_mvars != null) { TypeParameters tparam; TypeContainer sc = site_container; do { tparam = sc.CurrentTypeParameters; sc = sc.Parent; } while (tparam == null); mutator = new TypeParameterMutator(context_mvars, tparam); if (!ec.IsAnonymousStoreyMutateRequired) { targs_for_instance = new TypeExpression[targs.Length]; targs_for_instance[0] = targs[0]; } } else { mutator = null; } for (int i = 0; i < dyn_args_count; ++i) { Argument a = arguments[i]; if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref) { has_ref_out_argument = true; } var t = a.Type; // Convert any internal type like dynamic or null to object if (t.Kind == MemberKind.InternalCompilerType) { t = ec.BuiltinTypes.Object; } if (targs_for_instance != null) { targs_for_instance[i + 1] = new TypeExpression(t, loc); } if (mutator != null) { t = t.Mutate(mutator); } targs[i + 1] = new TypeExpression(t, loc); } TypeExpr del_type = null; TypeExpr del_type_instance_access = null; if (!has_ref_out_argument) { string d_name = isStatement ? "Action" : "Func"; TypeSpec te = null; Namespace type_ns = module.GlobalRootNamespace.GetNamespace("System", true); if (type_ns != null) { te = type_ns.LookupType(module, d_name, dyn_args_count + default_args, LookupMode.Normal, loc); } if (te != null) { if (!isStatement) { var t = type; if (t.Kind == MemberKind.InternalCompilerType) { t = ec.BuiltinTypes.Object; } if (targs_for_instance != null) { targs_for_instance[targs_for_instance.Length - 1] = new TypeExpression(t, loc); } if (mutator != null) { t = t.Mutate(mutator); } targs[targs.Length - 1] = new TypeExpression(t, loc); } del_type = new GenericTypeExpr(te, new TypeArguments(targs), loc); if (targs_for_instance != null) { del_type_instance_access = new GenericTypeExpr(te, new TypeArguments(targs_for_instance), loc); } else { del_type_instance_access = del_type; } } } // // Create custom delegate when no appropriate predefined delegate has been found // Delegate d; if (del_type == null) { TypeSpec rt = isStatement ? ec.BuiltinTypes.Void : type; Parameter[] p = new Parameter[dyn_args_count + 1]; p[0] = new Parameter(targs[0], "p0", Parameter.Modifier.NONE, null, loc); var site = ec.CreateDynamicSite(); int index = site.Containers == null ? 0 : site.Containers.Count; if (mutator != null) { rt = mutator.Mutate(rt); } for (int i = 1; i < dyn_args_count + 1; ++i) { p[i] = new Parameter(targs[i], "p" + i.ToString("X"), arguments[i - 1].Modifier, null, loc); } d = new Delegate(site, new TypeExpression(rt, loc), Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED, new MemberName("Container" + index.ToString("X")), new ParametersCompiled(p), null); d.CreateContainer(); d.DefineContainer(); d.Define(); d.PrepareEmit(); site.AddTypeContainer(d); // // Add new container to inflated site container when the // member cache already exists // if (site.CurrentType is InflatedTypeSpec && index > 0) { site.CurrentType.MemberCache.AddMember(d.CurrentType); } del_type = new TypeExpression(d.CurrentType, loc); if (targs_for_instance != null) { del_type_instance_access = null; } else { del_type_instance_access = del_type; } } else { d = null; } var site_type_decl = new GenericTypeExpr(module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments(del_type), loc); var field = site_container.CreateCallSiteField(site_type_decl, loc); if (field == null) { return; } if (del_type_instance_access == null) { var dt = d.CurrentType.DeclaringType.MakeGenericType(module, context_mvars.Types); del_type_instance_access = new TypeExpression(MemberCache.GetMember(dt, d.CurrentType), loc); } var instanceAccessExprType = new GenericTypeExpr(module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments(del_type_instance_access), loc); if (instanceAccessExprType.ResolveAsType(ec.MemberContext) == null) { return; } bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired; TypeSpec gt; if (inflate_using_mvar || context_mvars == null) { gt = site_container.CurrentType; } else { gt = site_container.CurrentType.MakeGenericType(module, context_mvars.Types); } // When site container already exists the inflated version has to be // updated manually to contain newly created field if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) { var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes; var inflator = new TypeParameterInflator(module, gt, tparams, gt.TypeArguments); gt.MemberCache.AddMember(field.InflateMember(inflator)); } FieldExpr site_field_expr = new FieldExpr(MemberCache.GetMember(gt, field), loc); BlockContext bc = new BlockContext(ec.MemberContext, null, ec.BuiltinTypes.Void); Arguments args = new Arguments(1); args.Add(new Argument(binder)); StatementExpression s = new StatementExpression(new SimpleAssign(site_field_expr, new Invocation(new MemberAccess(instanceAccessExprType, "Create"), args))); using (ec.With(BuilderContext.Options.OmitDebugInfo, true)) { if (s.Resolve(bc)) { Statement init = new If(new Binary(Binary.Operator.Equality, site_field_expr, new NullLiteral(loc)), s, loc); init.Emit(ec); } args = new Arguments(1 + dyn_args_count); args.Add(new Argument(site_field_expr)); if (arguments != null) { int arg_pos = 1; foreach (Argument a in arguments) { if (a is NamedArgument) { // Name is not valid in this context args.Add(new Argument(a.Expr, a.ArgType)); } else { args.Add(a); } if (inflate_using_mvar && a.Type != targs[arg_pos].Type) { a.Expr.Type = targs[arg_pos].Type; } ++arg_pos; } } Expression target = new DelegateInvocation(new MemberAccess(site_field_expr, "Target", loc).Resolve(bc), args, loc).Resolve(bc); if (target != null) { target.Emit(ec); } } }
public HoistedStoreyClass (TypeDefinition parent, MemberName name, TypeParameters tparams, Modifiers mods, MemberKind kind) : base (parent, name, mods | Modifiers.PRIVATE, kind) { if (tparams != null) { var type_params = name.TypeParameters; var src = new TypeParameterSpec[tparams.Count]; var dst = new TypeParameterSpec[tparams.Count]; for (int i = 0; i < tparams.Count; ++i) { type_params[i] = tparams[i].CreateHoistedCopy (spec); src[i] = tparams[i].Type; dst[i] = type_params[i].Type; } // A copy is not enough, inflate any type parameter constraints // using a new type parameters var inflator = new TypeParameterInflator (this, null, src, dst); for (int i = 0; i < tparams.Count; ++i) { src[i].InflateConstraints (inflator, dst[i]); } mutator = new TypeParameterMutator (tparams, type_params); } }
protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments, bool isStatement) { // // This method generates all internal infrastructure for a dynamic call. The // reason why it's quite complicated is the mixture of dynamic and anonymous // methods. Dynamic itself requires a temporary class (ContainerX) and anonymous // methods can generate temporary storey as well (AnonStorey). Handling MVAR // type parameters rewrite is non-trivial in such case as there are various // combinations possible therefore the mutator is not straightforward. Secondly // we need to keep both MVAR(possibly VAR for anon storey) and type VAR to emit // correct Site field type and its access from EmitContext. // int dyn_args_count = arguments == null ? 0 : arguments.Count; int default_args = isStatement ? 1 : 2; var module = ec.Module; bool has_ref_out_argument = false; var targs = new TypeExpression[dyn_args_count + default_args]; targs[0] = new TypeExpression (module.PredefinedTypes.CallSite.TypeSpec, loc); TypeExpression[] targs_for_instance = null; TypeParameterMutator mutator; var site_container = ec.CreateDynamicSite (); if (context_mvars != null) { TypeParameters tparam; TypeContainer sc = site_container; do { tparam = sc.CurrentTypeParameters; sc = sc.Parent; } while (tparam == null); mutator = new TypeParameterMutator (context_mvars, tparam); if (!ec.IsAnonymousStoreyMutateRequired) { targs_for_instance = new TypeExpression[targs.Length]; targs_for_instance[0] = targs[0]; } } else { mutator = null; } for (int i = 0; i < dyn_args_count; ++i) { Argument a = arguments[i]; if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref) has_ref_out_argument = true; var t = a.Type; // Convert any internal type like dynamic or null to object if (t.Kind == MemberKind.InternalCompilerType) t = ec.BuiltinTypes.Object; if (targs_for_instance != null) targs_for_instance[i + 1] = new TypeExpression (t, loc); if (mutator != null) t = t.Mutate (mutator); targs[i + 1] = new TypeExpression (t, loc); } TypeExpr del_type = null; TypeExpr del_type_instance_access = null; if (!has_ref_out_argument) { string d_name = isStatement ? "Action" : "Func"; TypeExpr te = null; Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true); if (type_ns != null) { te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, LookupMode.Normal, loc); } if (te != null) { if (!isStatement) { var t = type; if (t.Kind == MemberKind.InternalCompilerType) t = ec.BuiltinTypes.Object; if (targs_for_instance != null) targs_for_instance[targs_for_instance.Length - 1] = new TypeExpression (t, loc); if (mutator != null) t = t.Mutate (mutator); targs[targs.Length - 1] = new TypeExpression (t, loc); } del_type = new GenericTypeExpr (te.Type, new TypeArguments (targs), loc); if (targs_for_instance != null) del_type_instance_access = new GenericTypeExpr (te.Type, new TypeArguments (targs_for_instance), loc); else del_type_instance_access = del_type; } } // // Create custom delegate when no appropriate predefined delegate has been found // Delegate d; if (del_type == null) { TypeSpec rt = isStatement ? ec.BuiltinTypes.Void : type; Parameter[] p = new Parameter[dyn_args_count + 1]; p[0] = new Parameter (targs[0], "p0", Parameter.Modifier.NONE, null, loc); var site = ec.CreateDynamicSite (); int index = site.Containers == null ? 0 : site.Containers.Count; if (mutator != null) rt = mutator.Mutate (rt); for (int i = 1; i < dyn_args_count + 1; ++i) { p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc); } d = new Delegate (site, new TypeExpression (rt, loc), Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED, new MemberName ("Container" + index.ToString ("X")), new ParametersCompiled (p), null); d.CreateContainer (); d.DefineContainer (); d.Define (); site.AddTypeContainer (d); del_type = new TypeExpression (d.CurrentType, loc); if (targs_for_instance != null) { del_type_instance_access = null; } else { del_type_instance_access = del_type; } } else { d = null; } var site_type_decl = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type), loc); var field = site_container.CreateCallSiteField (site_type_decl, loc); if (field == null) return; if (del_type_instance_access == null) { var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Types); del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc); } var instanceAccessExprType = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type_instance_access), loc); if (instanceAccessExprType.ResolveAsType (ec.MemberContext) == null) return; bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired; TypeSpec gt; if (inflate_using_mvar || context_mvars == null) { gt = site_container.CurrentType; } else { gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Types); } // When site container already exists the inflated version has to be // updated manually to contain newly created field if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) { var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes; var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments); gt.MemberCache.AddMember (field.InflateMember (inflator)); } FieldExpr site_field_expr = new FieldExpr (MemberCache.GetMember (gt, field), loc); BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void); Arguments args = new Arguments (1); args.Add (new Argument (binder)); StatementExpression s = new StatementExpression (new SimpleAssign (site_field_expr, new Invocation (new MemberAccess (instanceAccessExprType, "Create"), args))); using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) { if (s.Resolve (bc)) { Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc); init.Emit (ec); } args = new Arguments (1 + dyn_args_count); args.Add (new Argument (site_field_expr)); if (arguments != null) { int arg_pos = 1; foreach (Argument a in arguments) { if (a is NamedArgument) { // Name is not valid in this context args.Add (new Argument (a.Expr, a.ArgType)); } else { args.Add (a); } if (inflate_using_mvar && a.Type != targs[arg_pos].Type) a.Expr.Type = targs[arg_pos].Type; ++arg_pos; } } Expression target = new DelegateInvocation (new MemberAccess (site_field_expr, "Target", loc).Resolve (bc), args, loc).Resolve (bc); if (target != null) target.Emit (ec); } }
public override MemberSpec InflateMember (TypeParameterInflator inflator) { var es = (EventSpec) base.InflateMember (inflator); es.MemberType = inflator.Inflate (MemberType); if (backing_field != null) es.backing_field = (FieldSpec) backing_field.InflateMember (inflator); return es; }
public MethodSpec MakeGenericMethod (IMemberContext context, params TypeSpec[] targs) { if (targs == null) throw new ArgumentNullException (); // TODO MemberCache // if (generic_intances != null && generic_intances.TryGetValue (targs, out ginstance)) // return ginstance; //if (generic_intances == null) // generic_intances = new Dictionary<TypeSpec[], Method> (TypeSpecArrayComparer.Default); var inflator = new TypeParameterInflator (context, DeclaringType, GenericDefinition.TypeParameters, targs); var inflated = (MethodSpec) MemberwiseClone (); inflated.declaringType = inflator.TypeInstance; inflated.returnType = inflator.Inflate (returnType); inflated.parameters = parameters.Inflate (inflator); inflated.targs = targs; inflated.constraints = TypeParameterSpec.InflateConstraints (inflator, constraints ?? GenericDefinition.TypeParameters); inflated.state |= StateFlags.PendingMakeMethod; // if (inflated.parent == null) // inflated.parent = parent; //generic_intances.Add (targs, inflated); return inflated; }
public override MemberSpec InflateMember (TypeParameterInflator inflator) { var ms = (MethodSpec) base.InflateMember (inflator); ms.inflatedMetaInfo = null; ms.returnType = inflator.Inflate (returnType); ms.parameters = parameters.Inflate (inflator); if (IsGeneric) ms.constraints = TypeParameterSpec.InflateConstraints (inflator, Constraints); return ms; }
protected virtual void DefineTypeParameters () { var tparams = CurrentTypeParameters; TypeParameterSpec[] base_tparams = null; TypeParameterSpec[] base_decl_tparams = TypeParameterSpec.EmptyTypes; TypeSpec[] base_targs = TypeSpec.EmptyTypes; if (((ModFlags & Modifiers.OVERRIDE) != 0 || IsExplicitImpl)) { MethodSpec base_override = base_method ?? MethodData.implementing; if (base_override != null) { base_tparams = base_override.GenericDefinition.TypeParameters; if (base_override.DeclaringType.IsGeneric) { base_decl_tparams = base_override.DeclaringType.MemberDefinition.TypeParameters; if (base_method != null) { var base_type_parent = CurrentType; while (base_type_parent.BaseType != base_override.DeclaringType) { base_type_parent = base_type_parent.BaseType; } base_targs = base_type_parent.BaseType.TypeArguments; } else { foreach (var iface in Parent.CurrentType.Interfaces) { if (iface == base_override.DeclaringType) { base_targs = iface.TypeArguments; break; } } } } if (base_override.IsGeneric) { ObsoleteAttribute oa; foreach (var base_tp in base_tparams) { oa = base_tp.BaseType.GetAttributeObsolete (); if (oa != null) { AttributeTester.Report_ObsoleteMessage (oa, base_tp.BaseType.GetSignatureForError (), Location, Report); } if (base_tp.InterfacesDefined != null) { foreach (var iface in base_tp.InterfacesDefined) { oa = iface.GetAttributeObsolete (); if (oa != null) { AttributeTester.Report_ObsoleteMessage (oa, iface.GetSignatureForError (), Location, Report); } } } } if (base_decl_tparams.Length != 0) { base_decl_tparams = base_decl_tparams.Concat (base_tparams).ToArray (); base_targs = base_targs.Concat (tparams.Types).ToArray (); } else { base_decl_tparams = base_tparams; base_targs = tparams.Types; } } } } for (int i = 0; i < tparams.Count; ++i) { var tp = tparams [i]; if (base_tparams == null) { tp.ResolveConstraints (this); continue; } // // Copy base constraints for override/explicit methods // var base_tparam = base_tparams [i]; var local_tparam = tp.Type; local_tparam.SpecialConstraint = base_tparam.SpecialConstraint; var inflator = new TypeParameterInflator (this, CurrentType, base_decl_tparams, base_targs); base_tparam.InflateConstraints (inflator, local_tparam); // // Check all type argument constraints for possible collision or unification // introduced by inflating inherited constraints in this context // // Conflict example: // // class A<T> { virtual void Foo<U> () where U : class, T {} } // class B : A<int> { override void Foo<U> {} } // var local_tparam_targs = local_tparam.TypeArguments; if (local_tparam_targs != null) { for (int ii = 0; ii < local_tparam_targs.Length; ++ii) { var ta = local_tparam_targs [ii]; if (!ta.IsClass && !ta.IsStruct) continue; TypeSpec[] unique_tparams = null; for (int iii = ii + 1; iii < local_tparam_targs.Length; ++iii) { // // Remove any identical or unified constraint types // var tparam_checked = local_tparam_targs [iii]; if (TypeSpecComparer.IsEqual (ta, tparam_checked) || TypeSpec.IsBaseClass (ta, tparam_checked, false)) { unique_tparams = new TypeSpec[local_tparam_targs.Length - 1]; Array.Copy (local_tparam_targs, 0, unique_tparams, 0, iii); Array.Copy (local_tparam_targs, iii + 1, unique_tparams, iii, local_tparam_targs.Length - iii - 1); } else if (!TypeSpec.IsBaseClass (tparam_checked, ta, false)) { Constraints.Error_ConflictingConstraints (this, local_tparam, ta, tparam_checked, Location); } } if (unique_tparams != null) { local_tparam_targs = unique_tparams; local_tparam.TypeArguments = local_tparam_targs; continue; } Constraints.CheckConflictingInheritedConstraint (local_tparam, ta, this, Location); } } } if (base_tparams == null && MethodData != null && MethodData.implementing != null) { CheckImplementingMethodConstraints (Parent, spec, MethodData.implementing); } }
// // Creates a nested container in this context for all dynamic compiler generated stuff // internal DynamicSiteClass CreateDynamicSite () { if (dynamic_site_container == null) { var mc = member_context.CurrentMemberDefinition as MemberBase; dynamic_site_container = new DynamicSiteClass (CurrentTypeDefinition.Parent.PartialContainer, mc, member_context.CurrentTypeParameters); CurrentTypeDefinition.Module.AddCompilerGeneratedClass (dynamic_site_container); dynamic_site_container.CreateContainer (); dynamic_site_container.DefineContainer (); dynamic_site_container.Define (); var inflator = new TypeParameterInflator (Module, CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes); var inflated = dynamic_site_container.CurrentType.InflateMember (inflator); CurrentType.MemberCache.AddMember (inflated); } return dynamic_site_container; }
public override MemberSpec InflateMember (TypeParameterInflator inflator) { var ps = (PropertySpec) base.InflateMember (inflator); ps.memberType = inflator.Inflate (memberType); return ps; }
public virtual MemberSpec InflateMember (TypeParameterInflator inflator) { var inflated = (MemberSpec) MemberwiseClone (); inflated.declaringType = inflator.TypeInstance; if (DeclaringType.IsGenericOrParentIsGeneric) inflated.state |= StateFlags.PendingMetaInflate; #if DEBUG inflated.ID += 1000000; #endif return inflated; }
public override MemberSpec InflateMember (TypeParameterInflator inflator) { var spec = (IndexerSpec) base.InflateMember (inflator); spec.parameters = parameters.Inflate (inflator); return spec; }