protected Event(TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs) : base(parent, type, mod_flags, parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface : parent.PartialContainer.Kind == MemberKind.Struct ? AllowedModifiersStruct : AllowedModifiersClass, name, attrs) { }
public PropertyBase (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, Modifiers allowed_mod, MemberName name, Attributes attrs) : base (parent, type, mod_flags, allowed_mod, name, attrs) { }
public AnonymousMethodMethod (TypeDefinition parent, AnonymousExpression am, AnonymousMethodStorey storey, TypeExpr return_type, Modifiers mod, MemberName name, ParametersCompiled parameters) : base (parent, return_type, mod | Modifiers.COMPILER_GENERATED, name, parameters, null) { this.AnonymousMethod = am; this.Storey = storey; Parent.PartialContainer.Members.Add (this); Block = new ToplevelBlock (am.block, parameters); }
protected MemberBase (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, Modifiers def_mod, MemberName name, Attributes attrs) : base (parent, name, attrs) { this.Parent = parent; this.type_expr = type; if (name != MemberName.Null) ModFlags = ModifiersExtensions.Check (allowed_mod, mod, def_mod, Location, Report); }
TypeSpec CheckRecursiveDefinition (TypeDefinition tc) { if (InTransit != null) return spec; InTransit = tc; if (base_type != null) { var ptc = base_type.MemberDefinition as TypeDefinition; if (ptc != null && ptc.CheckRecursiveDefinition (this) != null) return base_type; } if (iface_exprs != null) { foreach (var iface in iface_exprs) { // the interface might not have been resolved, prevents a crash, see #442144 if (iface == null) continue; var ptc = iface.MemberDefinition as Interface; if (ptc != null && ptc.CheckRecursiveDefinition (this) != null) return iface; } } if (!IsTopLevel && Parent.PartialContainer.CheckRecursiveDefinition (this) != null) return spec; InTransit = null; return null; }
public virtual void AddPartial (TypeDefinition next_part) { MemberCore mc; (PartialContainer ?? this).defined_names.TryGetValue (next_part.Basename, out mc); AddPartial (next_part, mc as TypeDefinition); }
public static Method Create (TypeDefinition parent, FullNamedExpression returnType, Modifiers mod, MemberName name, ParametersCompiled parameters, Attributes attrs) { var m = new Method (parent, returnType, mod, name, parameters, attrs); if ((mod & Modifiers.PARTIAL) != 0) { const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL; if ((mod & invalid_partial_mod) != 0) { m.Report.Error (750, m.Location, "A partial method cannot define access modifier or any of abstract, extern, new, override, sealed, or virtual modifiers"); mod &= ~invalid_partial_mod; } if ((parent.ModFlags & Modifiers.PARTIAL) == 0) { m.Report.Error (751, m.Location, "A partial method must be declared within a partial class or partial struct"); } } if ((mod & Modifiers.STATIC) == 0 && parameters.HasExtensionMethodType) { m.Report.Error (1105, m.Location, "`{0}': Extension methods must be declared static", m.GetSignatureForError ()); } return m; }
public Method (TypeDefinition parent, FullNamedExpression return_type, Modifiers mod, MemberName name, ParametersCompiled parameters, Attributes attrs) : base (parent, return_type, mod, parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface : parent.PartialContainer.Kind == MemberKind.Struct ? AllowedModifiersStruct | Modifiers.ASYNC : AllowedModifiersClass | Modifiers.ASYNC, name, attrs, parameters) { }
public void DefineOverride (TypeDefinition container) { if (implementing == null) return; if (!member.IsExplicitImpl) return; container.TypeBuilder.DefineMethodOverride (builder, (MethodInfo) implementing.GetMetaInfo ()); }
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 Constructor (TypeDefinition parent, string name, Modifiers mod, Attributes attrs, ParametersCompiled args, Location loc) : base (parent, null, mod, AllowedModifiers, new MemberName (name, loc), attrs, args) { }
public void AddTypeContainer (TypeContainer current_container, TypeDefinition tc) { if (current_container == tc){ Console.Error.WriteLine ("Internal error: inserting container into itself"); return; } if (undo_actions == null) undo_actions = new List<Action> (); var existing = current_container.Containers.FirstOrDefault (l => l.Basename == tc.Basename); if (existing != null) { current_container.RemoveContainer (existing); undo_actions.Add (() => current_container.AddTypeContainer (existing)); } undo_actions.Add (() => current_container.RemoveContainer (tc)); }
public InteractiveMethod(TypeDefinition parent, FullNamedExpression returnType, Modifiers mod, ParametersCompiled parameters) : base(parent, returnType, mod, new MemberName("Host"), parameters, null) { }
public override void Emit (TypeDefinition parent) { if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 && !Compiler.Settings.WriteMetadataOnly) { block = new ToplevelBlock (Compiler, ParameterInfo, Location) { IsCompilerGenerated = true }; FabricateBodyStatement (); } base.Emit (parent); }
public EventProperty (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs) : base (parent, type, mod_flags, name, attrs) { }
public MethodCore (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name, Attributes attrs, ParametersCompiled parameters) : base (parent, type, mod, allowed_mod, name, attrs) { this.parameters = parameters; }
protected MethodOrOperator (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name, Attributes attrs, ParametersCompiled parameters) : base (parent, type, mod, allowed_mod, name, attrs, parameters) { }
// // Creates partial MethodBuilder for the method when has generic parameters used // as arguments or return type // public MethodBuilder DefineMethodBuilder (TypeDefinition container) { if (builder != null) throw new InternalErrorException (); builder = container.TypeBuilder.DefineMethod (full_name, flags, method.CallingConventions); return builder; }
protected Method (TypeDefinition parent, FullNamedExpression return_type, Modifiers mod, Modifiers amod, MemberName name, ParametersCompiled parameters, Attributes attrs) : base (parent, return_type, mod, amod, name, attrs, parameters) { }
// // Creates full MethodBuilder for the method // public MethodBuilder DefineMethodBuilder (TypeDefinition container, ParametersCompiled param) { DefineMethodBuilder (container); builder.SetReturnType (method.ReturnType.GetMetaInfo ()); builder.SetParameters (param.GetMetaInfo ()); return builder; }
public void AddPartialPart (TypeDefinition part) { if (Kind != MemberKind.Class) return; if (class_partial_parts == null) class_partial_parts = new List<TypeDefinition> (); class_partial_parts.Add (part); }
// // Emits the code // public void Emit (TypeDefinition parent) { DefineOverride (parent); var mc = (IMemberContext) method; method.ParameterInfo.ApplyAttributes (mc, MethodBuilder); ToplevelBlock block = method.Block; if (block != null) { BlockContext bc = new BlockContext (mc, block, method.ReturnType); if (block.Resolve (null, bc, method)) { debug_builder = member.Parent.CreateMethodSymbolEntry (); EmitContext ec = method.CreateEmitContext (MethodBuilder.GetILGenerator (), debug_builder); block.Emit (ec); } } }
protected void AddPartial (TypeDefinition next_part, TypeDefinition existing) { next_part.ModFlags |= Modifiers.PARTIAL; if (existing == null) { AddTypeContainer (next_part); return; } if ((existing.ModFlags & Modifiers.PARTIAL) == 0) { if (existing.Kind != next_part.Kind) { AddTypeContainer (next_part); } else { Report.SymbolRelatedToPreviousError (next_part); Error_MissingPartialModifier (existing); } return; } if (existing.Kind != next_part.Kind) { Report.SymbolRelatedToPreviousError (existing); Report.Error (261, next_part.Location, "Partial declarations of `{0}' must be all classes, all structs or all interfaces", next_part.GetSignatureForError ()); } if ((existing.ModFlags & Modifiers.AccessibilityMask) != (next_part.ModFlags & Modifiers.AccessibilityMask) && ((existing.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) == 0 && (next_part.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) == 0)) { Report.SymbolRelatedToPreviousError (existing); Report.Error (262, next_part.Location, "Partial declarations of `{0}' have conflicting accessibility modifiers", next_part.GetSignatureForError ()); } var tc_names = existing.CurrentTypeParameters; if (tc_names != null) { for (int i = 0; i < tc_names.Count; ++i) { var tp = next_part.MemberName.TypeParameters[i]; if (tc_names[i].MemberName.Name != tp.MemberName.Name) { Report.SymbolRelatedToPreviousError (existing.Location, ""); Report.Error (264, next_part.Location, "Partial declarations of `{0}' must have the same type parameter names in the same order", next_part.GetSignatureForError ()); break; } if (tc_names[i].Variance != tp.Variance) { Report.SymbolRelatedToPreviousError (existing.Location, ""); Report.Error (1067, next_part.Location, "Partial declarations of `{0}' must have the same type parameter variance modifiers", next_part.GetSignatureForError ()); break; } } } if ((next_part.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) != 0) { existing.ModFlags |= next_part.ModFlags & ~(Modifiers.DEFAULT_ACCESS_MODIFER | Modifiers.AccessibilityMask); } else if ((existing.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) != 0) { existing.ModFlags &= ~(Modifiers.DEFAULT_ACCESS_MODIFER | Modifiers.AccessibilityMask); existing.ModFlags |= next_part.ModFlags; } else { existing.ModFlags |= next_part.ModFlags; } existing.Definition.Modifiers = existing.ModFlags; if (next_part.attributes != null) { if (existing.attributes == null) existing.attributes = next_part.attributes; else existing.attributes.AddAttributes (next_part.attributes.Attrs); } next_part.PartialContainer = existing; if (containers == null) containers = new List<TypeContainer> (); containers.Add (next_part); }
public void EmitJs (TypeDefinition parent, JsEmitContext jec) { var mc = (IMemberContext) method; method.ParameterInfo.ApplyAttributes (mc, MethodBuilder); ToplevelBlock block = method.Block; if (block != null) { BlockContext bc = new BlockContext (mc, block, method.ReturnType); if (block.Resolve (null, bc, method)) { block.EmitBlockJs (jec, false, false); } } }
public InterfaceMemberBase (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name, Attributes attrs) : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs) { IsInterface = parent.Kind == MemberKind.Interface; IsExplicitImpl = (MemberName.ExplicitInterface != null); explicit_mod_flags = mod; }
public Destructor (TypeDefinition parent, Modifiers mod, ParametersCompiled parameters, Attributes attrs, Location l) : base (parent, null, mod, AllowedModifiers, new MemberName (MetadataName, l), attrs, parameters) { ModFlags &= ~Modifiers.PRIVATE; ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE; }
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); } }
public virtual void Emit (TypeDefinition parent) { method_data.Emit (parent); if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated) Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (method_data.MethodBuilder); if (((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)) Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (method_data.MethodBuilder); if (ReturnType.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location); Module.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder); } else if (ReturnType.HasDynamicElement) { return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location); Module.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder, ReturnType, Location); } if (OptAttributes != null) OptAttributes.Emit (); if (declarative_security != null) { foreach (var de in declarative_security) { #if STATIC method_data.MethodBuilder.__AddDeclarativeSecurity (de); #else method_data.MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value); #endif } } block = null; }
public AnonymousMethodStorey (ExplicitBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind) : base (parent, MakeMemberName (host, name, parent.Module.CounterAnonymousContainers, tparams, block.StartLocation), tparams, 0, kind) { OriginalSourceBlock = block; ID = parent.Module.CounterAnonymousContainers++; }
public Operator (TypeDefinition parent, OpType type, FullNamedExpression ret_type, Modifiers mod_flags, ParametersCompiled parameters, ToplevelBlock block, Attributes attrs, Location loc) : base (parent, ret_type, mod_flags, AllowedModifiers, new MemberName (GetMetadataName (type), loc), attrs, parameters) { OperatorType = type; Block = block; }