PendingImplementation (TypeContainer container, MissingInterfacesInfo[] missing_ifaces, MethodSpec[] abstract_methods, int total) { var type_builder = container.Definition; this.container = container; pending_implementations = new TypeAndMethods [total]; int i = 0; if (abstract_methods != null) { int count = abstract_methods.Length; pending_implementations [i].methods = new MethodSpec [count]; pending_implementations [i].need_proxy = new MethodSpec [count]; pending_implementations [i].methods = abstract_methods; pending_implementations [i].found = new MethodData [count]; pending_implementations [i].type = type_builder; ++i; } foreach (MissingInterfacesInfo missing in missing_ifaces) { var iface = missing.Type; var mi = MemberCache.GetInterfaceMethods (iface); int count = mi.Count; pending_implementations [i].type = iface; pending_implementations [i].optional = missing.Optional; pending_implementations [i].methods = mi; pending_implementations [i].found = new MethodData [count]; pending_implementations [i].need_proxy = new MethodSpec [count]; i++; } }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Target == AttributeTargets.ReturnValue) { if (return_attributes == null) return_attributes = new ReturnParameter (this, InvokeBuilder.MethodBuilder, Location); return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa); return; } base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.CLSCompliant) { method.Compiler.Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead"); } // This occurs after Warning -28 if (builder == null) return; base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
protected void CheckReservedNameConflict (string prefix, MethodSpec accessor) { string name; AParametersCollection parameters; if (accessor != null) { name = accessor.Name; parameters = accessor.Parameters; } else { name = prefix + ShortName; if (IsExplicitImpl) name = MemberName.Left + "." + name; if (this is Indexer) { parameters = ((Indexer) this).ParameterInfo; if (prefix[0] == 's') { var data = new IParameterData[parameters.Count + 1]; Array.Copy (parameters.FixedParameters, data, data.Length - 1); data[data.Length - 1] = new ParameterData ("value", Parameter.Modifier.NONE); var types = new TypeSpec[data.Length]; Array.Copy (parameters.Types, types, data.Length - 1); types[data.Length - 1] = member_type; parameters = new ParametersImported (data, types, false); } } else { if (prefix[0] == 's') parameters = ParametersCompiled.CreateFullyResolved (new[] { member_type }); else parameters = ParametersCompiled.EmptyReadOnlyParameters; } } var conflict = MemberCache.FindMember (Parent.Definition, new MemberFilter (name, 0, MemberKind.Method, parameters, null), BindingRestriction.DeclaredOnly | BindingRestriction.NoAccessors); if (conflict != null) { Report.SymbolRelatedToPreviousError (conflict); Report.Error (82, Location, "A member `{0}' is already reserved", conflict.GetSignatureForError ()); } }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { #if false if (a.Type == pa.MarshalAs) { UnmanagedMarshal marshal = a.GetMarshal (this); if (marshal != null) { builder.SetMarshal (marshal); } return; } #endif if (a.HasSecurityAttribute) { a.Error_InvalidSecurityParent (); return; } if (a.Type == pa.Dynamic) { a.Error_MisusedDynamicAttribute (); return; } builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); }
protected override bool CheckBase () { if (!base.CheckBase ()) return false; if ((caching_flags & Flags.MethodOverloadsExist) != 0) CheckForDuplications (); if (IsExplicitImpl) return true; // For System.Object only if (Parent.BaseType == null) return true; MemberSpec candidate; bool overrides = false; var base_member = FindBaseMember (out candidate, ref overrides); if ((ModFlags & Modifiers.OVERRIDE) != 0) { if (base_member == null) { if (candidate == null) { if (this is Method && ((Method)this).ParameterInfo.IsEmpty && MemberName.Name == Destructor.MetadataName && MemberName.Arity == 0) { Report.Error (249, Location, "Do not override `{0}'. Use destructor syntax instead", "object.Finalize()"); } else { Report.Error (115, Location, "`{0}' is marked as an override but no suitable {1} found to override", GetSignatureForError (), SimpleName.GetMemberType (this)); } } else { Report.SymbolRelatedToPreviousError (candidate); if (this is Event) Report.Error (72, Location, "`{0}': cannot override because `{1}' is not an event", GetSignatureForError (), TypeManager.GetFullNameSignature (candidate)); else if (this is PropertyBase) Report.Error (544, Location, "`{0}': cannot override because `{1}' is not a property", GetSignatureForError (), TypeManager.GetFullNameSignature (candidate)); else Report.Error (505, Location, "`{0}': cannot override because `{1}' is not a method", GetSignatureForError (), TypeManager.GetFullNameSignature (candidate)); } return false; } // // Handles ambiguous overrides // if (candidate != null) { Report.SymbolRelatedToPreviousError (candidate); Report.SymbolRelatedToPreviousError (base_member); // Get member definition for error reporting var m1 = MemberCache.GetMember (base_member.DeclaringType.GetDefinition (), base_member); var m2 = MemberCache.GetMember (candidate.DeclaringType.GetDefinition (), candidate); Report.Error (462, Location, "`{0}' cannot override inherited members `{1}' and `{2}' because they have the same signature when used in type `{3}'", GetSignatureForError (), m1.GetSignatureForError (), m2.GetSignatureForError (), Parent.GetSignatureForError ()); } if (!CheckOverrideAgainstBase (base_member)) return false; ObsoleteAttribute oa = base_member.GetAttributeObsolete (); if (oa != null) { if (OptAttributes == null || !OptAttributes.Contains (Module.PredefinedAttributes.Obsolete)) { Report.SymbolRelatedToPreviousError (base_member); Report.Warning (672, 1, Location, "Member `{0}' overrides obsolete member `{1}'. Add the Obsolete attribute to `{0}'", GetSignatureForError (), base_member.GetSignatureForError ()); } } else { if (OptAttributes != null && OptAttributes.Contains (Module.PredefinedAttributes.Obsolete)) { Report.SymbolRelatedToPreviousError (base_member); Report.Warning (809, 1, Location, "Obsolete member `{0}' overrides non-obsolete member `{1}'", GetSignatureForError (), base_member.GetSignatureForError ()); } } base_method = base_member as MethodSpec; return true; } if (base_member == null && candidate != null && (!(candidate is IParametersMember) || !(this is IParametersMember))) base_member = candidate; if (base_member == null) { if ((ModFlags & Modifiers.NEW) != 0) { if (base_member == null) { Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ()); } } } else { if ((ModFlags & Modifiers.NEW) == 0) { ModFlags |= Modifiers.NEW; if (!IsCompilerGenerated) { Report.SymbolRelatedToPreviousError (base_member); if (!IsInterface && (base_member.Modifiers & (Modifiers.ABSTRACT | Modifiers.VIRTUAL | Modifiers.OVERRIDE)) != 0) { Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (), base_member.GetSignatureForError ()); } else { Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended", GetSignatureForError (), base_member.GetSignatureForError ()); } } } if (!IsInterface && base_member.IsAbstract && !overrides) { Report.SymbolRelatedToPreviousError (base_member); Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'", GetSignatureForError (), base_member.GetSignatureForError ()); } } return true; }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { base.ApplyAttributeBuilder (a, ctor, cdata, pa); // // When struct constains fixed fixed and struct layout has explicitly // set CharSet, its value has to be propagated to compiler generated // fixed types // if (a.Type == pa.StructLayout) { var value = a.GetNamedValue ("CharSet"); if (value == null) return; for (int i = 0; i < Members.Count; ++i) { FixedField ff = Members [i] as FixedField; if (ff == null) continue; ff.CharSet = (CharSet) System.Enum.Parse (typeof (CharSet), value.GetValue ().ToString ()); } } }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.IsValidSecurityAttribute ()) { a.ExtractSecurityPermissionSet (ctor, ref declarative_security); return; } if (a.Type == pa.StructLayout) { PartialContainer.HasStructLayout = true; if (a.IsExplicitLayoutKind ()) PartialContainer.HasExplicitLayout = true; } if (a.Type == pa.Dynamic) { a.Error_MisusedDynamicAttribute (); return; } base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
public void SetCustomAttribute (MethodSpec ctor, byte[] data) { FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), data); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Target == AttributeTargets.Method) { foreach (var m in members) { var c = m as Constructor; if (c == null) continue; if (c.IsPrimaryConstructor) { c.ApplyAttributeBuilder (a, ctor, cdata, pa); return; } } throw new InternalErrorException (); } if (has_normal_indexers && a.Type == pa.DefaultMember) { Report.Error (646, a.Location, "Cannot specify the `DefaultMember' attribute on type containing an indexer"); return; } if (a.Type == pa.Required) { Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types"); return; } TypeBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); }
public override bool Define () { if (!base.Define ()) return false; if (!CheckBase ()) return false; MemberKind kind; if (this is Operator) kind = MemberKind.Operator; else if (this is Destructor) kind = MemberKind.Destructor; else kind = MemberKind.Method; string explicit_name; if (IsPartialDefinition) { caching_flags &= ~Flags.Excluded_Undetected; caching_flags |= Flags.Excluded; // Add to member cache only when a partial method implementation has not been found yet if ((caching_flags & Flags.PartialDefinitionExists) != 0) return true; if (IsExplicitImpl) return true; explicit_name = null; } else { MethodData = new MethodData (this, ModFlags, flags, this, base_method); if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName))) return false; explicit_name = MethodData.MetadataName; } spec = new MethodSpec (kind, Parent.Definition, this, ReturnType, parameters, ModFlags); if (MemberName.Arity > 0) spec.IsGeneric = true; Parent.MemberCache.AddMember (this, explicit_name, spec); return true; }
public static bool CheckImplementingMethodConstraints (TypeContainer container, MethodSpec method, MethodSpec baseMethod) { var tparams = method.Constraints; var base_tparams = baseMethod.Constraints; for (int i = 0; i < tparams.Length; ++i) { if (!tparams[i].HasSameConstraintsImplementation (base_tparams[i])) { container.Compiler.Report.SymbolRelatedToPreviousError (method); container.Compiler.Report.SymbolRelatedToPreviousError (baseMethod); // Using container location because the interface can be implemented // by base class container.Compiler.Report.Error (425, container.Location, "The constraints for type parameter `{0}' of method `{1}' must match the constraints for type parameter `{2}' of interface method `{3}'. Consider using an explicit interface implementation instead", tparams[i].GetSignatureForError (), method.GetSignatureForError (), base_tparams[i].GetSignatureForError (), baseMethod.GetSignatureForError ()); return false; } } return true; }
protected virtual void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { throw new NotSupportedException ("You forgot to define special attribute target handling"); }
// // Creates the ConstructorBuilder // public override bool Define () { if (ConstructorBuilder != null) return true; if (!CheckAbstractAndExtern (block != null)) return false; // Check if arguments were correct. if (!CheckBase ()) return false; if (Parent.PrimaryConstructorParameters != null && !IsPrimaryConstructor && !IsStatic) { if (Parent.Kind == MemberKind.Struct && Initializer is ConstructorThisInitializer && Initializer.Arguments == null) { Report.Error (8043, Location, "`{0}': Structs with primary constructor cannot specify default constructor initializer", GetSignatureForError ()); } else if (Initializer == null || Initializer is ConstructorBaseInitializer) { Report.Error (8037, Location, "`{0}': Instance constructor of type with primary constructor must specify `this' constructor initializer", GetSignatureForError ()); } } var ca = ModifiersExtensions.MethodAttr (ModFlags) | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName; ConstructorBuilder = Parent.TypeBuilder.DefineConstructor ( ca, CallingConventions, parameters.GetMetaInfo ()); spec = new MethodSpec (MemberKind.Constructor, Parent.Definition, this, Compiler.BuiltinTypes.Void, parameters, ModFlags); Parent.MemberCache.AddMember (spec); if (block != null) { // It's here only to report an error if (block.IsIterator) { member_type = Compiler.BuiltinTypes.Void; Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags); } if (Compiler.Settings.WriteMetadataOnly) block = null; } return true; }
protected override Expression DoResolve (ResolveContext ec) { eclass = ExprClass.Value; // FIXME: Hack var caller_builder = (Constructor) ec.MemberContext; // // Spec mandates that constructor initializer will not have `this' access // using (ec.Set (ResolveContext.Options.BaseInitializer)) { if (argument_list != null) { bool dynamic; argument_list.Resolve (ec, out dynamic); if (dynamic) { ec.Report.Error (1975, loc, "The constructor call cannot be dynamically dispatched within constructor initializer"); return null; } } type = ec.CurrentType; if (this is ConstructorBaseInitializer) { if (ec.CurrentType.BaseType == null) return this; type = ec.CurrentType.BaseType; if (ec.CurrentType.IsStruct) { ec.Report.Error (522, loc, "`{0}': Struct constructors cannot call base constructors", caller_builder.GetSignatureForError ()); return this; } } else { // // It is legal to have "this" initializers that take no arguments // in structs // // struct D { public D (int a) : this () {} // if (ec.CurrentType.IsStruct && argument_list == null) return this; } base_ctor = ConstructorLookup (ec, type, ref argument_list, loc); } if (base_ctor != null && base_ctor.MemberDefinition == caller_builder.Spec.MemberDefinition) { ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself", caller_builder.GetSignatureForError ()); } return this; }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.Conditional) { Error_ConditionalAttributeIsNotValid (); return; } base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Target == AttributeTargets.ReturnValue) { if (return_attributes == null) return_attributes = new ReturnParameter (this, MethodBuilder, Location); return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa); return; } if (a.Type == pa.MethodImpl) { if ((ModFlags & Modifiers.ASYNC) != 0 && (a.GetMethodImplOptions () & MethodImplOptions.Synchronized) != 0) { Report.Error (4015, a.Location, "`{0}': Async methods cannot use `MethodImplOptions.Synchronized'", GetSignatureForError ()); } is_external_implementation = a.IsInternalCall (); } else if (a.Type == pa.DllImport) { const Modifiers extern_static = Modifiers.EXTERN | Modifiers.STATIC; if ((ModFlags & extern_static) != extern_static) { Report.Error (601, a.Location, "The DllImport attribute must be specified on a method marked `static' and `extern'"); } is_external_implementation = true; } if (a.IsValidSecurityAttribute ()) { a.ExtractSecurityPermissionSet (ctor, ref declarative_security); return; } if (MethodBuilder != null) MethodBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); }
protected override Expression DoResolve (ResolveContext ec) { eclass = ExprClass.Value; // FIXME: Hack var caller_builder = (Constructor) ec.MemberContext; // // Spec mandates that constructor initializer will not have `this' access // using (ec.Set (ResolveContext.Options.BaseInitializer)) { if (argument_list != null) { bool dynamic; argument_list.Resolve (ec, out dynamic); // If actionscript, convert dynamic constructor arguments to type System.Object. if (dynamic && ec.FileType == SourceFileType.PlayScript) { var ctors = MemberCache.FindMembers (ec.CurrentType.BaseType, Constructor.ConstructorName, true); if (ctors != null) { if (argument_list.AsTryResolveDynamicArgs(ec, ctors)) { dynamic = false; } } } if (dynamic) { ec.Report.Error (1975, loc, "The constructor call cannot be dynamically dispatched within constructor initializer"); return null; } } type = ec.CurrentType; if (this is ConstructorBaseInitializer) { if (ec.CurrentType.BaseType == null) return this; type = ec.CurrentType.BaseType; if (ec.CurrentType.IsStruct) { ec.Report.Error (522, loc, "`{0}': Struct constructors cannot call base constructors", caller_builder.GetSignatureForError ()); return this; } } else { // // It is legal to have "this" initializers that take no arguments // in structs, they are just no-ops. // // struct D { public D (int a) : this () {} // if (ec.CurrentType.IsStruct && argument_list == null) return this; } base_ctor = ConstructorLookup (ec, type, ref argument_list, loc); } if (base_ctor != null && base_ctor.MemberDefinition == caller_builder.Spec.MemberDefinition) { ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself", caller_builder.GetSignatureForError ()); } return this; }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.Conditional) { if (IsExplicitImpl) { Error_ConditionalAttributeIsNotValid (); return; } if ((ModFlags & Modifiers.OVERRIDE) != 0) { Report.Error (243, Location, "Conditional not valid on `{0}' because it is an override method", GetSignatureForError ()); return; } if (ReturnType.Kind != MemberKind.Void) { Report.Error (578, Location, "Conditional not valid on `{0}' because its return type is not void", GetSignatureForError ()); return; } if (IsInterface) { Report.Error (582, Location, "Conditional not valid on interface members"); return; } if (MethodData.implementing != null) { Report.SymbolRelatedToPreviousError (MethodData.implementing.DeclaringType); Report.Error (629, Location, "Conditional member `{0}' cannot implement interface member `{1}'", GetSignatureForError (), TypeManager.CSharpSignature (MethodData.implementing)); return; } for (int i = 0; i < parameters.Count; ++i) { if ((parameters.FixedParameters [i].ModFlags & Parameter.Modifier.OUT) != 0) { Report.Error (685, Location, "Conditional method `{0}' cannot have an out parameter", GetSignatureForError ()); return; } } } if (a.Type == pa.Extension) { a.Error_MisusedExtensionAttribute (); return; } base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.IsValidSecurityAttribute ()) { a.ExtractSecurityPermissionSet (ctor, ref declarative_security); return; } if (a.Type == pa.MethodImpl) { is_external_implementation = a.IsInternalCall (); } ConstructorBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.FieldOffset) { status |= Status.HAS_OFFSET; if (!Parent.PartialContainer.HasExplicitLayout) { Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)"); return; } if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) { Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields"); return; } } if (a.Type == pa.FixedBuffer) { Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead"); return; } #if false if (a.Type == pa.MarshalAs) { UnmanagedMarshal marshal = a.GetMarshal (this); if (marshal != null) { FieldBuilder.SetMarshal (marshal); } return; } #endif if ((a.HasSecurityAttribute)) { a.Error_InvalidSecurityParent (); return; } if (a.Type == pa.Dynamic) { a.Error_MisusedDynamicAttribute (); return; } FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); }
// // Creates the ConstructorBuilder // public override bool Define () { if (ConstructorBuilder != null) return true; if (!CheckAbstractAndExtern (block != null)) return false; // Check if arguments were correct. if (!CheckBase ()) return false; var ca = ModifiersExtensions.MethodAttr (ModFlags) | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName; ConstructorBuilder = Parent.TypeBuilder.DefineConstructor ( ca, CallingConventions, parameters.GetMetaInfo ()); spec = new MethodSpec (MemberKind.Constructor, Parent.Definition, this, Compiler.BuiltinTypes.Void, parameters, ModFlags); Parent.MemberCache.AddMember (spec); if (block != null) { // It's here only to report an error if (block.IsIterator) { member_type = Compiler.BuiltinTypes.Void; Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags); } if (Compiler.Settings.WriteMetadataOnly) block = null; } return true; }
// // Creates a proxy base method call inside this container for hoisted base member calls // public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method) { Method proxy_method; // // One proxy per base method is enough // if (hoisted_base_call_proxies == null) { hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> (); proxy_method = null; } else { hoisted_base_call_proxies.TryGetValue (method, out proxy_method); } if (proxy_method == null) { string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count); MemberName member_name; TypeArguments targs = null; TypeSpec return_type = method.ReturnType; var local_param_types = method.Parameters.Types; if (method.IsGeneric) { // // Copy all base generic method type parameters info // var hoisted_tparams = method.GenericDefinition.TypeParameters; var tparams = new TypeParameters (); targs = new TypeArguments (); targs.Arguments = new TypeSpec[hoisted_tparams.Length]; for (int i = 0; i < hoisted_tparams.Length; ++i) { var tp = hoisted_tparams[i]; var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null); tparams.Add (local_tp); targs.Add (new SimpleName (tp.Name, Location)); targs.Arguments[i] = local_tp.Type; } member_name = new MemberName (name, tparams, Location); // // Mutate any method type parameters from original // to newly created hoisted version // var mutator = new TypeParameterMutator (hoisted_tparams, tparams); return_type = mutator.Mutate (return_type); local_param_types = mutator.Mutate (local_param_types); } else { member_name = new MemberName (name); } var base_parameters = new Parameter[method.Parameters.Count]; for (int i = 0; i < base_parameters.Length; ++i) { var base_param = method.Parameters.FixedParameters[i]; base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location), base_param.Name, base_param.ModFlags, null, Location); base_parameters[i].Resolve (this, i); } var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types); if (method.Parameters.HasArglist) { cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location); cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve (); } // Compiler generated proxy proxy_method = new Method (this, new TypeExpression (return_type, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN, member_name, cloned_params, null); var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) { IsCompilerGenerated = true }; var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location); mg.InstanceExpression = new BaseThis (method.DeclaringType, Location); if (targs != null) mg.SetTypeArguments (rc, targs); // Get all the method parameters and pass them as arguments var real_base_call = new Invocation (mg, block.GetAllParametersArguments ()); Statement statement; if (method.ReturnType.Kind == MemberKind.Void) statement = new StatementExpression (real_base_call); else statement = new Return (real_base_call, Location); block.AddStatement (statement); proxy_method.Block = block; members.Add (proxy_method); proxy_method.Define (); proxy_method.PrepareEmit (); hoisted_base_call_proxies.Add (method, proxy_method); } return proxy_method.Spec; }
public MethodData (InterfaceMemberBase member, Modifiers modifiers, MethodAttributes flags, IMethodData method, MethodSpec parent_method) : this (member, modifiers, flags, method) { this.parent_method = parent_method; }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.AttributeUsage) { if (!BaseType.IsAttribute && spec.BuiltinType != BuiltinTypeSpec.Type.Attribute) { Report.Error (641, a.Location, "Attribute `{0}' is only valid on classes derived from System.Attribute", a.GetSignatureForError ()); } } if (a.Type == pa.Conditional && !BaseType.IsAttribute) { Report.Error (1689, a.Location, "Attribute `System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute classes"); return; } if (a.Type == pa.ComImport && !attributes.Contains (pa.Guid)) { a.Error_MissingGuidAttribute (); return; } if (a.Type == pa.Extension) { a.Error_MisusedExtensionAttribute (); return; } if (a.Type.IsConditionallyExcluded (this, Location)) return; base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
public bool Define (TypeDefinition container, string method_full_name) { PendingImplementation pending = container.PendingImplementations; MethodSpec ambig_iface_method; bool optional = false; if (pending != null) { implementing = pending.IsInterfaceMethod (method.MethodName, member.InterfaceType, this, out ambig_iface_method, ref optional); if (member.InterfaceType != null) { if (implementing == null) { if (member is PropertyBase) { container.Compiler.Report.Error (550, method.Location, "`{0}' is an accessor not found in interface member `{1}{2}'", method.GetSignatureForError (), member.InterfaceType.GetSignatureForError (), member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.'))); } else { container.Compiler.Report.Error (539, method.Location, "`{0}.{1}' in explicit interface declaration is not a member of interface", member.InterfaceType.GetSignatureForError (), member.ShortName); } return false; } if (implementing.IsAccessor && !method.IsAccessor) { container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.Error (683, method.Location, "`{0}' explicit method implementation cannot implement `{1}' because it is an accessor", member.GetSignatureForError (), implementing.GetSignatureForError ()); return false; } } else { if (implementing != null) { if (!method.IsAccessor) { if (implementing.IsAccessor) { container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.Error (470, method.Location, "Method `{0}' cannot implement interface accessor `{1}'", method.GetSignatureForError (), TypeManager.CSharpSignature (implementing)); } } else if (implementing.DeclaringType.IsInterface) { if (!implementing.IsAccessor) { container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.Error (686, method.Location, "Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation", method.GetSignatureForError (), TypeManager.CSharpSignature (implementing), container.GetSignatureForError ()); } else { PropertyBase.PropertyMethod pm = method as PropertyBase.PropertyMethod; if (pm != null && pm.HasCustomAccessModifier && (pm.ModFlags & Modifiers.PUBLIC) == 0) { container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.Error (277, method.Location, "Accessor `{0}' must be declared public to implement interface member `{1}'", method.GetSignatureForError (), implementing.GetSignatureForError ()); } } } } } } else { ambig_iface_method = null; } // // For implicit implementations, make sure we are public, for // explicit implementations, make sure we are private. // if (implementing != null){ if (member.IsExplicitImpl) { if (method.ParameterInfo.HasParams && !implementing.Parameters.HasParams) { container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.Error (466, method.Location, "`{0}': the explicit interface implementation cannot introduce the params modifier", method.GetSignatureForError ()); } if (ambig_iface_method != null) { container.Compiler.Report.SymbolRelatedToPreviousError (ambig_iface_method); container.Compiler.Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.Warning (473, 2, method.Location, "Explicit interface implementation `{0}' matches more than one interface member. Consider using a non-explicit implementation instead", method.GetSignatureForError ()); } } else { // // Setting implementin to null inside this block will trigger a more // verbose error reporting for missing interface implementations // if (implementing.DeclaringType.IsInterface) { // // If this is an interface method implementation, // check for public accessibility // if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public) { implementing = null; } else if (optional && (container.Interfaces == null || !container.Definition.Interfaces.Contains (implementing.DeclaringType))) { // // We are not implementing interface when base class already implemented it // implementing = null; } } else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { // We may never be private. implementing = null; } else if ((modifiers & Modifiers.OVERRIDE) == 0) { // // We may be protected if we're overriding something. // implementing = null; } } // // Static is not allowed // if ((modifiers & Modifiers.STATIC) != 0){ implementing = null; } } // // If implementing is still valid, set flags // if (implementing != null){ // // When implementing interface methods, set NewSlot // unless, we are overwriting a method. // if ((modifiers & Modifiers.OVERRIDE) == 0 && implementing.DeclaringType.IsInterface) { flags |= MethodAttributes.NewSlot; } flags |= MethodAttributes.Virtual | MethodAttributes.HideBySig; // Set Final unless we're virtual, abstract or already overriding a method. if ((modifiers & (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE)) == 0) flags |= MethodAttributes.Final; // // clear the pending implementation flag (requires explicit methods to be defined first) // pending.ImplementMethod (method.MethodName, member.InterfaceType, this, member.IsExplicitImpl, out ambig_iface_method, ref optional); // // Update indexer accessor name to match implementing abstract accessor // if (!implementing.DeclaringType.IsInterface && !member.IsExplicitImpl && implementing.IsAccessor) method_full_name = implementing.MemberDefinition.Name; } full_name = method_full_name; declaring_type = container.Definition; return true; }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.ComImport && !attributes.Contains (pa.Guid)) { a.Error_MissingGuidAttribute (); return; } base.ApplyAttributeBuilder (a, ctor, cdata, pa); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (a.Type == pa.CLSCompliant || a.Type == pa.Obsolete || a.Type == pa.Conditional) { Report.Error (1667, a.Location, "Attribute `{0}' is not valid on property or event accessors. It is valid on `{1}' declarations only", a.Type.GetSignatureForError (), a.GetValidTargets ()); return; } if (a.IsValidSecurityAttribute ()) { a.ExtractSecurityPermissionSet (ctor, ref declarative_security); return; } if (a.Target == AttributeTargets.Method) { method_data.MethodBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); return; } if (a.Target == AttributeTargets.ReturnValue) { if (return_attributes == null) return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location); return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa); return; } ApplyToExtraTarget (a, ctor, cdata, pa); }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { if (has_normal_indexers && a.Type == pa.DefaultMember) { Report.Error (646, a.Location, "Cannot specify the `DefaultMember' attribute on type containing an indexer"); return; } if (a.Type == pa.Required) { Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types"); return; } TypeBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata); }
protected virtual void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { // We ignore this error in AS as attributes are always applied to getters/setters (seems like a missing feature in C#). if (a.Location.SourceFile != null && a.Location.SourceFile.FileType == SourceFileType.PlayScript) return; throw new NotSupportedException ("You forgot to define special attribute target handling"); }