}
}
- public class MethodArrayList: MemberCoreArrayList
+ public class MethodArrayList : MemberCoreArrayList
{
[Flags]
enum CachedMethods {
{
base.DefineContainerMembers ();
- if ((RootContext.WarningLevel >= 3) && HasEquals && !HasGetHashCode) {
- Report.Warning (659, container.Location, "`{0}' overrides Object.Equals(object) but does not override Object.GetHashCode()", container.GetSignatureForError ());
+ if (HasEquals && !HasGetHashCode) {
+ Report.Warning (659, 3, container.Location, "`{0}' overrides Object.Equals(object) but does not override Object.GetHashCode()", container.GetSignatureForError ());
}
}
}
- public sealed class IndexerArrayList: MemberCoreArrayList
+ public sealed class IndexerArrayList : MemberCoreArrayList
{
/// <summary>
/// The indexer name for this container
//
void CheckPairedOperators ()
{
- Hashtable pairs = new Hashtable (null, null);
+ IDictionary pairs = new HybridDictionary ();
Operator true_op = null;
Operator false_op = null;
bool has_equality_or_inequality = false;
if (has_equality_or_inequality && (RootContext.WarningLevel > 2)) {
if (container.Methods == null || !container.Methods.HasEquals)
- Report.Warning (660, container.Location, "`{0}' defines operator == or operator != but does not override Object.Equals(object o)", container.GetSignatureForError ());
+ Report.Warning (660, 2, container.Location, "`{0}' defines operator == or operator != but does not override Object.Equals(object o)", container.GetSignatureForError ());
if (container.Methods == null || !container.Methods.HasGetHashCode)
- Report.Warning (661, container.Location, "`{0}' defines operator == or operator != but does not override Object.GetHashCode()", container.GetSignatureForError ());
+ Report.Warning (661, 2, container.Location, "`{0}' defines operator == or operator != but does not override Object.GetHashCode()", container.GetSignatureForError ());
}
}
GenericTypeParameterBuilder[] gen_params;
public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
- Attributes attrs, Kind kind, Location l)
- : base (ns, parent, name, attrs, l)
+ Attributes attrs, Kind kind)
+ : base (ns, parent, name, attrs)
{
if (parent != null && parent != RootContext.Tree.Types && parent.NamespaceEntry != ns)
throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");
public bool AddToMemberContainer (MemberCore symbol)
{
- return AddToContainer (symbol, symbol.Name);
+ return AddToContainer (symbol, symbol.MemberName.MethodName);
}
- bool AddToTypeContainer (DeclSpace ds)
+ protected virtual bool AddToTypeContainer (DeclSpace ds)
{
- // Parent == null ==> this == RootContext.Tree.Types
- return AddToContainer (ds, (Parent == null) ? ds.Name : ds.Basename);
+ return AddToContainer (ds, ds.Basename);
}
public void AddConstant (Const constant)
enums.Add (e);
}
- public void AddClassOrStruct (TypeContainer c)
+ public bool AddClassOrStruct (TypeContainer c)
{
if (!AddToTypeContainer (c))
- return;
+ return false;
types.Add (c);
+ return true;
}
public void AddDelegate (Delegate d)
methods.Add (method);
}
+ //
+ // Do not use this method: use AddMethod.
+ //
+ // This is only used by iterators.
+ //
+ public void AppendMethod (Method method)
+ {
+ if (!AddToMemberContainer (method))
+ return;
+
+ if (methods == null)
+ methods = new MethodArrayList (this);
+
+ methods.Add (method);
+ }
+
public void AddConstructor (Constructor c)
{
if (c.Name != MemberName.Name) {
if (c.IsDefault ()){
if (default_constructor != null) {
Report.SymbolRelatedToPreviousError (default_constructor);
- Report.Error (111, c.Location, Error111, c.Location, c.GetSignatureForError ());
+ Report.Error (111, c.Location, Error111, c.GetSignatureForError ());
return;
}
default_constructor = c;
}
}
- public void AddInterface (TypeContainer iface)
+ public bool AddInterface (TypeContainer iface)
{
if (!AddToTypeContainer (iface))
- return;
+ return false;
if (interfaces == null) {
interfaces = new MemberCoreArrayList ();
}
interfaces.Add (iface);
+ return true;
}
public void AddField (FieldMember field)
fields.Add (field);
- if (field.HasInitializer)
- RegisterFieldForInitialization (field);
-
if ((field.ModFlags & Modifiers.STATIC) != 0)
return;
first_nonstatic_field.Parent != field.Parent &&
RootContext.WarningLevel >= 3) {
Report.SymbolRelatedToPreviousError (first_nonstatic_field.Parent);
- Report.Warning (282, field.Location,
+ Report.Warning (282, 3, field.Location,
"struct instance field `{0}' found in different declaration from instance field `{1}'",
field.GetSignatureForError (), first_nonstatic_field.GetSignatureForError ());
}
}
}
- public virtual void RegisterFieldForInitialization (FieldMember field)
+ public bool IsComImport {
+ get {
+ if (OptAttributes == null)
+ return false;
+
+ return OptAttributes.Contains (TypeManager.comimport_attr_type, EmitContext);
+ }
+ }
+
+ public virtual void RegisterFieldForInitialization (FieldBase field)
{
if ((field.ModFlags & Modifiers.STATIC) != 0){
if (initialized_static_fields == null)
- initialized_static_fields = new ArrayList ();
+ initialized_static_fields = new ArrayList (4);
initialized_static_fields.Add (field);
} else {
if (initialized_fields == null)
- initialized_fields = new ArrayList ();
+ initialized_fields = new ArrayList (4);
initialized_fields.Add (field);
}
public virtual bool EmitFieldInitializers (EmitContext ec)
{
ArrayList fields;
- Expression instance_expr;
if (ec.IsStatic){
fields = initialized_static_fields;
- instance_expr = null;
} else {
fields = initialized_fields;
- instance_expr = new This (Location.Null).Resolve (ec);
}
if (fields == null)
return true;
- foreach (FieldMember f in fields){
- Expression e = f.GetInitializerExpression (ec);
- if (e == null)
- return false;
-
- Location l = f.Location;
- FieldExpr fe = new FieldExpr (f.FieldBuilder, l, true);
- fe.InstanceExpression = instance_expr;
-
- ExpressionStatement a = new Assign (fe, e, l);
-
- a = a.ResolveStatement (ec);
- if (a == null)
- return false;
-
- Constant c = e as Constant;
- if (c != null) {
- if (c.IsDefaultValue)
- continue;
- }
-
- a.EmitStatement (ec);
+ foreach (FieldBase f in fields) {
+ f.EmitInitializer (ec);
}
-
return true;
}
c = new Constructor (constructor_parent, MemberName.Name, mods,
Parameters.EmptyReadOnlyParameters,
- new ConstructorBaseInitializer (null, Location),
+ new GeneratedBaseInitializer (Location),
Location);
AddConstructor (c);
ArrayList ifaces = new ArrayList ();
base_class = null;
- Location base_loc = Location.Null;
foreach (ClassPart part in parts) {
TypeExpr new_base_class;
if ((base_class != null) && (new_base_class != null) &&
!base_class.Equals (new_base_class)) {
+ Report.SymbolRelatedToPreviousError (base_class.Location, "");
Report.Error (263, part.Location,
"Partial declarations of `{0}' must " +
"not specify different base classes",
Name);
- if (!Location.IsNull (base_loc))
- Report.LocationOfPreviousError (base_loc);
-
return null;
}
if ((base_class == null) && (new_base_class != null)) {
base_class = new_base_class;
- base_loc = part.Location;
}
if (new_ifaces == null)
/// The @base_class argument is set to the base object or null
/// if this is `System.Object'.
/// </summary>
- TypeExpr [] GetClassBases (out TypeExpr base_class)
+ protected virtual TypeExpr [] GetClassBases (out TypeExpr base_class)
{
int i;
if (base_class is TypeParameterExpr){
Report.Error (
689, base_class.Location,
- "Type parameter `{0}' can not be used as a " +
- "base class or interface", base_class.Name);
+ "Cannot derive from `{0}' because it is a type parameter",
+ base_class.GetSignatureForError ());
error = true;
return null;
}
if (!TypeManager.MayBecomeEqualGenericInstances (iface, t, infered, null))
continue;
- Report.Error (
- 695, Location,
+ Report.Error (695, Location,
"`{0}' cannot implement both `{1}' and `{2}' " +
- "because they may unify for some type " +
- "parameter substitutions",
- TypeManager.GetFullName (TypeBuilder),
- iface, t);
+ "because they may unify for some type parameter substitutions",
+ TypeManager.CSharpName (TypeBuilder), TypeManager.CSharpName (iface),
+ TypeManager.CSharpName (t));
return false;
}
return null;
}
- TypeManager.AddUserType (Name, TypeBuilder, this);
+ TypeManager.AddUserType (this);
if (Parts != null) {
ec = null;
foreach (ClassPart part in Parts) {
part.TypeBuilder = TypeBuilder;
- part.ptype = ptype;
part.ec = new EmitContext (part, Mono.CSharp.Location.Null, null, null, ModFlags);
part.ec.ContainerType = TypeBuilder;
}
return null;
}
+ //
+ // GetClassBases calls ResolveBaseTypeExpr() on the various type expressions involved,
+ // which in turn should have called DefineType()s on base types if necessary.
+ //
+ // None of the code below should trigger DefineType()s on classes that we depend on.
+ // Thus, we are eligible to be on the topological sort `type_container_resolve_order'.
+ //
+ // Let's do it as soon as possible, since code below can call DefineType() on classes
+ // that depend on us to be populated before they are.
+ //
+ if (!(this is Iterator))
+ RootContext.RegisterOrder (this);
+
if (base_type == null) {
if (Kind == Kind.Class){
if (RootContext.StdLib)
}
}
+ // Avoid attributes check when parent is not set
+ TypeResolveEmitContext.TestObsoleteMethodUsage = false;
+
if (base_type != null) {
// FIXME: I think this should be ...ResolveType (Parent.EmitContext).
// However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
- ptype = base_type.ResolveType (TypeResolveEmitContext);
- if (ptype == null) {
+ FullNamedExpression fne = base_type.ResolveAsTypeStep (TypeResolveEmitContext);
+ if ((fne == null) || (fne.Type == null)) {
error = true;
return null;
}
- ptype = base_type.Type;
+ ptype = fne.Type;
if (IsGeneric && TypeManager.IsAttributeType (ptype)) {
Report.Error (698, base_type.Location,
return null;
}
- if (ptype != null)
+ if (ptype != null) {
TypeBuilder.SetParent (ptype);
+ }
+
+ // Attribute is undefined at the begining of corlib compilation
+ if (TypeManager.obsolete_attribute_type != null) {
+ TypeResolveEmitContext.TestObsoleteMethodUsage = GetObsoleteAttribute () == null;
+ if (ptype != null && TypeResolveEmitContext.TestObsoleteMethodUsage) {
+ CheckObsoleteType (base_type);
+ }
+ }
// add interfaces that were not added at type creation
if (iface_exprs != null) {
TypeManager.RegisterBuilder (TypeBuilder, ifaces);
}
- if (!(this is Iterator))
- RootContext.RegisterOrder (this);
- else if (!ResolveType ()) {
+ if (this is Iterator && !ResolveType ()) {
error = true;
return null;
}
public bool ResolveType ()
{
+ if ((base_type != null) &&
+ (base_type.ResolveType (TypeResolveEmitContext) == null)) {
+ error = true;
+ return false;
+ }
+
if (!IsGeneric)
return true;
}
}
- int offset = CountTypeParameters - CurrentTypeParameters.Length;
- for (int i = offset; i < gen_params.Length; i++)
- CurrentTypeParameters [i - offset].DefineConstraints ();
-
foreach (TypeParameter type_param in TypeParameters) {
if (!type_param.DefineType (ec)) {
error = true;
return false;
}
- CurrentType = current_type.Type;
+ CurrentType = current_type.ResolveType (ec);
}
return true;
Type parent = ptype;
if (parent != null) {
- if (parent.IsGenericInstance)
- parent = parent.GetGenericTypeDefinition ();
-
+ parent = TypeManager.DropGenericTypeArguments (parent);
TypeContainer ptc = TypeManager.LookupTypeContainer (parent);
if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
return false;
if (iface_exprs != null) {
foreach (TypeExpr iface in iface_exprs) {
- Type itype = iface.Type;
-
- if (itype.IsGenericInstance)
- itype = itype.GetGenericTypeDefinition ();
-
+ Type itype = TypeManager.DropGenericTypeArguments (iface.Type);
TypeContainer ptc = TypeManager.LookupTypeContainer (itype);
if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
return false;
/// <summary>
/// Populates our TypeBuilder with fields and methods
/// </summary>
- public override bool DefineMembers (TypeContainer container)
+ public override bool DefineMembers ()
{
if (members_defined)
return members_defined_ok;
- if (!base.DefineMembers (container))
+ if (!base.DefineMembers ())
return false;
members_defined_ok = DoDefineMembers ();
MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
if (conflict_symbol == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
- Report.Warning (109, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
+ 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) {
Report.SymbolRelatedToPreviousError (conflict_symbol);
- Report.Warning (108, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+ Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
}
}
if (parts != null) {
foreach (ClassPart part in parts) {
- if (!part.DefineMembers (this))
+ if (!part.DefineMembers ())
return false;
}
}
}
foreach (Iterator iterator in iterators) {
- if (!iterator.DefineMembers (this))
+ if (!iterator.DefineMembers ())
return false;
}
}
void ReportStructInitializedInstanceError ()
{
- string n = TypeBuilder.FullName;
-
foreach (Field f in initialized_fields){
Report.Error (573, Location,
"`{0}': Structs cannot have instance field initializers",
{
ArrayList members = new ArrayList ();
- DefineMembers (null);
+ DefineMembers ();
if (methods != null) {
int len = methods.Count;
continue;
if (!mc.IsUsed) {
- Report.Warning (169, mc.Location, "The private {0} `{1}' is never used", member_type, mc.GetSignatureForError ());
+ Report.Warning (169, 3, mc.Location, "The private {0} `{1}' is never used", member_type, mc.GetSignatureForError ());
}
}
}
if (!f.IsUsed){
if ((f.caching_flags & Flags.IsAssigned) == 0)
Report.Warning (169, 3, f.Location, "The private field `{0}' is never used", f.GetSignatureForError ());
- else
- Report.Warning (414, 3, f.Location, "The private field `{0}' is assigned but its value is never used",
+ else {
+#if NET_2_0
+ const int error_code = 414;
+#else
+ const int error_code = 169;
+#endif
+ Report.Warning (error_code, 3, f.Location, "The private field `{0}' is assigned but its value is never used",
f.GetSignatureForError ());
+ }
continue;
}
if ((f.caching_flags & Flags.IsAssigned) != 0)
continue;
- Report.Warning (649, f.Location, "Field `{0}' is never assigned to, and will always have its default value `{1}'",
+ Report.Warning (649, 4, f.Location, "Field `{0}' is never assigned to, and will always have its default value `{1}'",
f.GetSignatureForError (), f.Type.Type.IsValueType ? Activator.CreateInstance (f.Type.Type).ToString() : "null");
}
}
/// Emits the code, this step is performed after all
/// the types, enumerations, constructors
/// </summary>
- public void EmitType ()
+ public virtual void EmitType ()
{
if (OptAttributes != null)
OptAttributes.Emit (ec, this);
+ if (IsGeneric && !(this is ClassPart)) {
+ int offset = CountTypeParameters - CurrentTypeParameters.Length;
+ for (int i = offset; i < gen_params.Length; i++)
+ CurrentTypeParameters [i - offset].EmitAttributes (ec);
+ }
+
//
// Structs with no fields need to have at least one byte.
// The right thing would be to set the PackingSize in a DefineType
if (default_static_constructor != null)
default_static_constructor.Emit ();
- if (methods != null)
+ if (methods != null){
foreach (Method m in methods)
m.Emit ();
+ }
if (operators != null)
foreach (Operator o in operators)
}
if (!Parent.IsClsComplianceRequired (ds)) {
- Report.Error (3018, Location, "`{0}' cannot be marked as CLS-Compliant because it is a member of non CLS-Compliant type `{1}'",
+ Report.Error (3018, Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
GetSignatureForError (), Parent.GetSignatureForError ());
}
return true;
foreach (DictionaryEntry entry in defined_names) {
MemberCore mc = (MemberCore)entry.Value;
- if (!mc.IsClsComplianceRequired (this))
+ if (!mc.IsClsComplianceRequired (mc.Parent))
continue;
- string name = (string)entry.Key;
+ string name = (string) entry.Key;
string basename = name.Substring (name.LastIndexOf ('.') + 1);
string lcase = basename.ToLower (System.Globalization.CultureInfo.InvariantCulture);
continue;
if (found is MemberInfo) {
- if (basename == ((MemberInfo)found).Name)
+ if (basename == ((MemberInfo) found).Name)
continue;
- Report.SymbolRelatedToPreviousError ((MemberInfo)found);
+ Report.SymbolRelatedToPreviousError ((MemberInfo) found);
} else {
Report.SymbolRelatedToPreviousError ((MemberCore) found);
}
- Report.Error (3005, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
+ Report.Warning (3005, 1, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
}
}
return false;
}
- protected override void VerifyObsoleteAttribute()
+ public virtual void Mark_HasEquals ()
{
- CheckUsageOfObsoleteAttribute (TypeBuilder.BaseType);
-
- if (ifaces == null)
- return;
+ Methods.HasEquals = true;
+ }
- foreach (Type iface in ifaces) {
- CheckUsageOfObsoleteAttribute (iface);
- }
+ public virtual void Mark_HasGetHashCode ()
+ {
+ Methods.HasGetHashCode = true;
}
//
public readonly int OriginalModFlags;
public readonly int AllowedModifiers;
public readonly TypeAttributes DefaultTypeAttributes;
+ public ListDictionary DeclarativeSecurity;
static PartialContainer Create (NamespaceEntry ns, TypeContainer parent,
- MemberName member_name, int mod_flags, Kind kind,
- Location loc)
+ MemberName member_name, int mod_flags, Kind kind)
{
- PartialContainer pc;
- DeclSpace ds = RootContext.Tree.GetDecl (member_name);
- if (ds != null) {
- pc = ds as PartialContainer;
- if (pc == null) {
- Report.LocationOfPreviousError (loc);
- Report.Error (260, ds.Location,
- "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
- member_name.GetTypeName());
-
- return null;
- }
+ if (!CheckModFlags (0, mod_flags, member_name))
+ return null;
+ PartialContainer pc = RootContext.Tree.GetDecl (member_name) as PartialContainer;
+ if (pc != null) {
if (pc.Kind != kind) {
Report.Error (
- 261, loc, "Partial declarations of `{0}' " +
- "must be all classes, all structs or " +
- "all interfaces", member_name.GetTypeName ());
+ 261, member_name.Location,
+ "Partial declarations of `{0}' must be all classes, " +
+ "all structs or all interfaces",
+ member_name.GetTypeName ());
return null;
}
- if (pc.OriginalModFlags != mod_flags) {
- Report.Error (
- 262, loc, "Partial declarations of `{0}' " +
- "have conflicting accessibility modifiers",
- member_name.GetTypeName ());
+ if (!CheckModFlags (pc.OriginalModFlags, mod_flags, member_name))
return null;
- }
+ pc.ModFlags |= (mod_flags & pc.AllowedModifiers);
if (pc.IsGeneric) {
if (pc.CountTypeParameters != member_name.CountTypeArguments) {
Report.Error (
- 264, loc, "Partial declarations of `{0}' " +
- "must have the same type parameter names in " +
- "the same order", member_name.GetTypeName ());
+ 264, member_name.Location,
+ "Partial declarations of `{0}' must have the " +
+ "same type parameter names in the same order",
+ member_name.GetTypeName ());
return null;
}
- string[] pc_names = pc.MemberName.TypeArguments.GetDeclarations ();
- string[] names = member_name.TypeArguments.GetDeclarations ();
+ TypeParameterName[] pc_names = pc.MemberName.TypeArguments.GetDeclarations ();
+ TypeParameterName[] names = member_name.TypeArguments.GetDeclarations ();
for (int i = 0; i < pc.CountTypeParameters; i++) {
- if (pc_names [i] == names [i])
+ if (pc_names [i].Name == names [i].Name)
continue;
Report.Error (
- 264, loc, "Partial declarations of `{0}' " +
- "must have the same type parameter names in " +
- "the same order", member_name.GetTypeName ());
+ 264, member_name.Location,
+ "Partial declarations of `{0}' must have the " +
+ "same type parameter names in the same order",
+ member_name.GetTypeName ());
return null;
}
}
if (parent is ClassPart)
parent = ((ClassPart) parent).PartialContainer;
- pc = new PartialContainer (ns.NS, parent, member_name, mod_flags, kind, loc);
- RootContext.Tree.RecordDecl (ns.NS, member_name, pc);
+ pc = new PartialContainer (ns.NS, parent, member_name, mod_flags, kind);
- if (kind == Kind.Interface)
- parent.AddInterface (pc);
- else if (kind == Kind.Class || kind == Kind.Struct)
- parent.AddClassOrStruct (pc);
- else
+ if (kind == Kind.Interface) {
+ if (!parent.AddInterface (pc))
+ return null;
+ } else if (kind == Kind.Class || kind == Kind.Struct) {
+ if (!parent.AddClassOrStruct (pc))
+ return null;
+ } else {
throw new InvalidOperationException ();
-
+ }
+ RootContext.Tree.RecordDecl (ns.NS, member_name, pc);
// This is needed to define our type parameters; we define the constraints later.
pc.SetParameterInfo (null);
return pc;
}
+ static bool CheckModFlags (int flags_org, int flags, MemberName member_name)
+ {
+ // Check (abstract|static|sealed) sanity.
+ int tmp = (flags_org | flags) & (Modifiers.ABSTRACT | Modifiers.SEALED | Modifiers.STATIC);
+ if ((tmp & Modifiers.ABSTRACT) != 0) {
+ if ((tmp & (Modifiers.STATIC | Modifiers.SEALED)) != 0) {
+ Report.Error (
+ 418, member_name.Location,
+ "`{0}': an abstract class cannot be sealed or static", member_name.ToString ());
+ return false;
+ }
+ } else if (tmp == (Modifiers.SEALED | Modifiers.STATIC)) {
+ Report.Error (441, member_name.Location, "`{0}': a class cannot be both static and sealed", member_name.ToString ());
+ return false;
+ }
+
+ if (flags_org == 0)
+ return true;
+
+ // Check conflicts.
+ if (0 != ((flags_org ^ flags) & (0xFFFFFFFF ^ (Modifiers.SEALED | Modifiers.ABSTRACT)))) {
+ Report.Error (
+ 262, member_name.Location, "Partial declarations of `{0}' " +
+ "have conflicting accessibility modifiers",
+ member_name.GetName ());
+ return false;
+ }
+ return true;
+ }
+
public static ClassPart CreatePart (NamespaceEntry ns, TypeContainer parent,
MemberName name, int mod, Attributes attrs,
Kind kind, Location loc)
{
- PartialContainer pc = Create (ns, parent, name, mod, kind, loc);
+ PartialContainer pc = Create (ns, parent, name, mod, kind);
if (pc == null) {
// An error occured; create a dummy container, but don't
// register it.
- pc = new PartialContainer (ns.NS, parent, name, mod, kind, loc);
+ pc = new PartialContainer (ns.NS, parent, name, mod, kind);
}
- ClassPart part = new ClassPart (ns, pc, parent, mod, attrs, kind, loc);
+ ClassPart part = new ClassPart (ns, pc, parent, mod, attrs, kind);
pc.AddPart (part);
return part;
}
protected PartialContainer (Namespace ns, TypeContainer parent,
- MemberName name, int mod, Kind kind, Location l)
- : base (null, parent, name, null, kind, l)
+ MemberName name, int mod, Kind kind)
+ : base (null, parent, name, null, kind)
{
this.Namespace = ns;
else
accmods = Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ // FIXME: remove this nasty fix for bug #77370 when
+ // we get good AllowModifiersProp implementation.
+ if ((mod & Modifiers.STATIC) != 0) {
+ AllowedModifiers |= Modifiers.STATIC;
+ AllowedModifiers &= ~ (Modifiers.ABSTRACT | Modifiers.SEALED);
+ }
+
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
this.OriginalModFlags = mod;
}
+ public override void EmitType ()
+ {
+ base.EmitType ();
+
+ if (DeclarativeSecurity != null) {
+ foreach (DictionaryEntry de in DeclarativeSecurity) {
+ TypeBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+ }
+ }
+ }
+
public override PendingImplementation GetPendingImplementations ()
{
return PendingImplementation.GetPendingImplementations (this);
}
+ public override bool MarkForDuplicationCheck ()
+ {
+ return true;
+ }
+
protected override TypeAttributes TypeAttr {
get {
return base.TypeAttr | DefaultTypeAttributes;
Constraints[] constraints;
public ClassPart (NamespaceEntry ns, PartialContainer pc, TypeContainer parent,
- int mod, Attributes attrs, Kind kind, Location l)
- : base (ns, parent, pc.MemberName, attrs, kind, l)
+ int mod, Attributes attrs, Kind kind)
+ : base (ns, parent, pc.MemberName, attrs, kind)
{
this.PartialContainer = pc;
this.IsPartial = true;
else
accmods = Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (pc.AllowedModifiers, mod, accmods, l);
+ this.ModFlags = Modifiers.Check (pc.AllowedModifiers, mod, accmods, pc.MemberName.Location);
if (pc.IsGeneric)
constraints = new Constraints [pc.CountCurrentTypeParameters];
}
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (false)) {
+ if (PartialContainer.DeclarativeSecurity == null)
+ PartialContainer.DeclarativeSecurity = new ListDictionary ();
+
+ a.ExtractSecurityPermissionSet (PartialContainer.DeclarativeSecurity);
+ return;
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
public override PendingImplementation GetPendingImplementations ()
{
return PartialContainer.Pending;
return false;
}
- for (int i = 0; i < current_params.Length; i++)
- current_params [i].DefineConstraints ();
-
foreach (TypeParameter type_param in PartialContainer.TypeParameters) {
if (!type_param.DefineType (ec))
return false;
return true;
}
- public override void RegisterFieldForInitialization (FieldMember field)
+ public override void RegisterFieldForInitialization (FieldBase field)
{
PartialContainer.RegisterFieldForInitialization (field);
}
throw new InternalErrorException ("Should not get here");
}
+ public override void Mark_HasEquals ()
+ {
+ PartialContainer.Mark_HasEquals ();
+ }
+
+ public override void Mark_HasGetHashCode ()
+ {
+ PartialContainer.Mark_HasGetHashCode ();
+ }
}
public abstract class ClassOrStruct : TypeContainer {
ListDictionary declarative_security;
public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
- MemberName name, Attributes attrs, Kind kind,
- Location l)
- : base (ns, parent, name, attrs, kind, l)
+ MemberName name, Attributes attrs, Kind kind)
+ : base (ns, parent, name, attrs, kind)
{
}
/// </summary>
public sealed class StaticClass: Class {
public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
- Attributes attrs, Location l)
- : base (ns, parent, name, mod, attrs, l)
+ Attributes attrs)
+ : base (ns, parent, name, mod, attrs)
{
if (RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotStandardized (l, "static classes");
+ Report.FeatureIsNotStandardized (Location, "static classes");
}
}
foreach (MemberCore m in list) {
if (m is Operator) {
- Report.Error (715, m.Location, "`{0}': static classes cannot contain user-defined operators", m.GetSignatureForError ());
+ Report.Error (715, m.Location, "`{0}': Static classes cannot contain user-defined operators", m.GetSignatureForError ());
continue;
}
- if ((m.ModFlags & Modifiers.PROTECTED) != 0)
- Report.Warning (-628, 4, m.Location, "`{0}': new protected member declared in static class", m.GetSignatureForError ());
+ if (m is Destructor) {
+ Report.Error (711, m.Location, "`{0}': Static classes cannot contain destructor", GetSignatureForError ());
+ continue;
+ }
+
+ if ((m.ModFlags & Modifiers.PROTECTED) != 0) {
+ Report.Error (1057, m.Location, "`{0}': Static classes cannot contain protected members", m.GetSignatureForError ());
+ continue;
+ }
if (m is Indexer) {
Report.Error (720, m.Location, "`{0}': cannot declare indexers in a static class", m.GetSignatureForError ());
continue;
}
- if (m is Destructor) {
- Report.Error (711, m.Location, "`{0}': Static classes cannot contain destructor", GetSignatureForError ());
- continue;
- }
Report.Error (708, m.Location, "`{0}': cannot declare instance members in a static class", m.GetSignatureForError ());
}
Modifiers.UNSAFE;
public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
- Attributes attrs, Location l)
- : base (ns, parent, name, attrs, Kind.Class, l)
+ Attributes attrs)
+ : base (ns, parent, name, attrs, Kind.Class)
{
this.ModFlags = mod;
}
if (ptype != TypeManager.attribute_type &&
!ptype.IsSubclassOf (TypeManager.attribute_type) &&
TypeBuilder.FullName != "System.Attribute") {
- Report.Error (641, a.Location, "Attribute `{0}' is only valid on classes derived from System.Attribute", a.Name);
+ Report.Error (641, a.Location, "Attribute `{0}' is only valid on classes derived from System.Attribute", a.GetSignatureForError ());
}
}
Modifiers.PRIVATE;
public Struct (NamespaceEntry ns, TypeContainer parent, MemberName name,
- int mod, Attributes attrs, Location l)
- : base (ns, parent, name, attrs, Kind.Struct, l)
+ int mod, Attributes attrs)
+ : base (ns, parent, name, attrs, Kind.Struct)
{
int accmods;
else
accmods = Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
this.ModFlags |= Modifiers.SEALED;
}
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name,
- int mod, Attributes attrs, Location l)
- : base (ns, parent, name, attrs, Kind.Interface, l)
+ public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
+ Attributes attrs)
+ : base (ns, parent, name, attrs, Kind.Interface)
{
int accmods;
else
accmods = Modifiers.PRIVATE;
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, name.Location);
}
public override PendingImplementation GetPendingImplementations ()
public abstract class MethodCore : MemberBase {
public readonly Parameters Parameters;
- public readonly GenericMethod GenericMethod;
protected ToplevelBlock block;
- //
- // Parameters, cached for semantic analysis.
- //
- protected InternalParameters parameter_info;
- protected Type [] parameter_types;
-
// Whether this is an operator method.
public Operator IsOperator;
public MethodCore (TypeContainer parent, GenericMethod generic,
Expression type, int mod, int allowed_mod, bool is_iface,
- MemberName name, Attributes attrs, Parameters parameters,
- Location loc)
- : base (parent, generic != null ? generic : (DeclSpace) parent,
- type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
+ MemberName name, Attributes attrs, Parameters parameters)
+ : base (parent, generic, type, mod, allowed_mod, Modifiers.PRIVATE,
+ name, attrs)
{
Parameters = parameters;
IsInterface = is_iface;
- this.GenericMethod = generic;
}
//
//
public Type [] ParameterTypes {
get {
- return parameter_types;
+ return Parameters.Types;
}
}
- public InternalParameters ParameterInfo
+ public Parameters ParameterInfo
{
get {
- return parameter_info;
+ return Parameters;
}
}
+
+ public override EmitContext EmitContext {
+ get { return ds.EmitContext; }
+ }
public ToplevelBlock Block {
get {
// Is null for System.Object while compiling corlib and base interfaces
if (Parent.BaseCache == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
- Report.Warning (109, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
+ Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
}
return true;
}
return false;
}
- if (RootContext.WarningLevel > 2) {
- if (Name == "Equals" && parameter_types.Length == 1 && parameter_types [0] == TypeManager.object_type)
- Parent.Methods.HasEquals = true;
- else if (Name == "GetHashCode" && parameter_types.Length == 0)
- Parent.Methods.HasGetHashCode = true;
- }
+ if (Name == "Equals" && Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type)
+ Parent.Mark_HasEquals ();
+ else if (Name == "GetHashCode" && Parameters.Empty)
+ Parent.Mark_HasGetHashCode ();
if ((ModFlags & Modifiers.OVERRIDE) != 0) {
ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (base_method);
if (conflict_symbol == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
- Report.Warning (109, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
+ Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
}
return true;
}
return true;
Report.SymbolRelatedToPreviousError (conflict_symbol);
- Report.Warning (108, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+ Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
}
ModFlags |= Modifiers.NEW;
Report.SymbolRelatedToPreviousError (base_method);
if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
- if (RootContext.WarningLevel >= 2)
- Report.Warning (114, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ 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 (), TypeManager.CSharpSignature (base_method));
} else {
- Report.Warning (108, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+ Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
GetSignatureForError (), TypeManager.CSharpSignature (base_method));
}
}
/// </summary>
protected abstract MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type);
- protected virtual bool DoDefineParameters ()
+ protected bool DoDefineParameters ()
{
EmitContext ec = ds.EmitContext;
if (ec == null)
bool old_unsafe = ec.InUnsafe;
ec.InUnsafe = InUnsafe;
- // Check if arguments were correct
- parameter_types = Parameters.GetParameterInfo (ec);
- ec.InUnsafe = old_unsafe;
-
- if ((parameter_types == null) ||
- !CheckParameters (ds, parameter_types))
- return false;
+ ec.ResolvingGenericMethod = GenericMethod != null;
- TypeParameter[] tparam = ds.IsGeneric ? ds.TypeParameters : null;
- parameter_info = new InternalParameters (parameter_types, Parameters, tparam);
+ bool old_obsolete = ec.TestObsoleteMethodUsage;
+ if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute () != null)
+ ec.TestObsoleteMethodUsage = false;
- Parameter array_param = Parameters.ArrayParameter;
- if ((array_param != null) &&
- (!array_param.ParameterType.IsArray ||
- (array_param.ParameterType.GetArrayRank () != 1))) {
- Report.Error (225, Location, "The params parameter must be a single dimensional array");
+ // Check if arguments were correct
+ if (!Parameters.Resolve (ec))
return false;
- }
- return true;
- }
+ ec.ResolvingGenericMethod = false;
+ ec.InUnsafe = old_unsafe;
+ ec.TestObsoleteMethodUsage = old_obsolete;
- void error_425 (Type old, Type t, string name)
- {
- Report.Error (425, Location,
- "The constraints of type parameter `{0}' " +
- "of method `{1}' must match the constraints for " +
- "type parameter `{2}' of method `{3}'",
- TypeManager.CSharpName (old), Name,
- TypeManager.CSharpName (t), name);
+ return CheckParameters (ParameterTypes);
}
- protected override bool CheckGenericOverride (MethodInfo method, string name)
+ bool CheckParameters (Type [] parameters)
{
- ParameterData pd = TypeManager.GetParameterData (method);
-
- for (int i = 0; i < ParameterTypes.Length; i++) {
- GenericConstraints ogc = pd.GenericConstraints (i);
- GenericConstraints gc = ParameterInfo.GenericConstraints (i);
-
- if ((gc == null) && (ogc == null))
- continue;
-
- Type ot = pd.ParameterType (i);
- Type t = ParameterTypes [i];
-
- if (!((gc != null) && (ogc != null))) {
- error_425 (ot, t, name);
- return false;
- }
+ bool error = false;
- if ((gc.Attributes != ogc.Attributes) ||
- (gc.HasClassConstraint != ogc.HasClassConstraint)) {
- error_425 (ot, t, name);
+ foreach (Type partype in parameters){
+ if (partype == TypeManager.void_type) {
+ Report.Error (
+ 1547, Location, "Keyword 'void' cannot " +
+ "be used in this context");
return false;
}
- if (ogc.HasClassConstraint &&
- !ogc.ClassConstraint.Equals (gc.ClassConstraint)) {
- error_425 (ot, t, name);
- return false;
+ if (partype.IsPointer){
+ if (!UnsafeOK (ds))
+ error = true;
+ if (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
+ error = true;
}
- Type[] oct = ogc.InterfaceConstraints;
- Type[] ct = gc.InterfaceConstraints;
-
- if (oct.Length != ct.Length) {
- error_425 (ot, t, name);
- return false;
- }
+ if (ds.AsAccessible (partype, ModFlags))
+ continue;
- for (int j = 0; j < oct.Length; j++)
- if (!oct [j].Equals (ct [j])) {
- error_425 (ot, t, name);
- return false;
- }
+ if (this is Indexer)
+ Report.Error (55, Location,
+ "Inconsistent accessibility: parameter type `" +
+ TypeManager.CSharpName (partype) + "' is less " +
+ "accessible than indexer `" + GetSignatureForError () + "'");
+ else if ((this is Method) && ((Method) this).IsOperator != null)
+ Report.Error (57, Location,
+ "Inconsistent accessibility: parameter type `" +
+ TypeManager.CSharpName (partype) + "' is less " +
+ "accessible than operator `" + GetSignatureForError () + "'");
+ else
+ Report.Error (51, Location,
+ "Inconsistent accessibility: parameter type `" +
+ TypeManager.CSharpName (partype) + "' is less " +
+ "accessible than method `" + GetSignatureForError () + "'");
+ error = true;
}
- return true;
+ return !error;
}
public override string[] ValidAttributeTargets {
GetSignatureForError ());
}
- AttributeTester.AreParametersCompliant (Parameters.FixedParameters, Location);
+ Parameters.VerifyClsCompliance ();
return true;
}
- bool MayUnify (MethodCore first, MethodCore second)
- {
- int a_type_params = 0;
- if (first.GenericMethod != null)
- a_type_params = first.GenericMethod.CountTypeParameters;
-
- int b_type_params = 0;
- if (second.GenericMethod != null)
- b_type_params = second.GenericMethod.CountTypeParameters;
-
- if (a_type_params != b_type_params)
- return false;
-
- Type[] class_infered, method_infered;
- if (Parent.CountTypeParameters > 0)
- class_infered = new Type [Parent.CountTypeParameters];
- else
- class_infered = null;
-
- if (a_type_params > 0)
- method_infered = new Type [a_type_params];
- else
- method_infered = null;
-
- return TypeManager.MayBecomeEqualGenericInstances (
- first.ParameterTypes, second.ParameterTypes, class_infered, method_infered);
- }
-
protected bool IsDuplicateImplementation (MethodCore method)
{
- if ((method == this) ||
- (method.MemberName.GetTypeName () != MemberName.GetTypeName ()))
+ if (method == this || !(method.MemberName.Equals (MemberName)))
return false;
Type[] param_types = method.ParameterTypes;
- if (param_types == null)
+ // This never happen. Rewrite this as Equal
+ if (param_types == null && ParameterTypes == null)
+ return true;
+ if (param_types == null || ParameterTypes == null)
return false;
if (param_types.Length != ParameterTypes.Length)
return false;
+ if (method.Parameters.HasArglist != Parameters.HasArglist)
+ return false;
+
bool equal = true;
- bool may_unify = MayUnify (this, method);
for (int i = 0; i < param_types.Length; i++) {
if (param_types [i] != ParameterTypes [i])
}
if (IsExplicitImpl && (method.InterfaceType != InterfaceType))
- equal = may_unify = false;
+ equal = false;
// TODO: make operator compatible with MethodCore to avoid this
if (this is Operator && method is Operator) {
if (MemberType != method.MemberType)
- equal = may_unify = false;
+ equal = false;
}
if (equal) {
//
// Try to report 663: method only differs on out/ref
//
- ParameterData info = ParameterInfo;
- ParameterData other_info = method.ParameterInfo;
+ Parameters info = ParameterInfo;
+ Parameters other_info = method.ParameterInfo;
for (int i = 0; i < info.Count; i++){
+ try {
if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
Report.SymbolRelatedToPreviousError (method);
Report.Error (663, Location, "`{0}': Methods cannot differ only on their use of ref and out on a parameters",
GetSignatureForError ());
return false;
+ }} catch {
+ Console.WriteLine ("Method is: {0} {1}", method.Location, method);
+ Console.WriteLine ("this is: {0} {1}", Location, this);
}
}
Report.Error (111, Location, TypeContainer.Error111, GetSignatureForError ());
return true;
- } else if (may_unify) {
- Report.Error (408, Location,
- "`{0}' cannot define overload members that " +
- "may unify for some type parameter substitutions",
- Parent.MemberName);
- return true;
}
return false;
}
- public override bool IsUsed
- {
- get {
- if (IsExplicitImpl)
- return true;
-
- return base.IsUsed;
- }
+ public override bool IsUsed {
+ get { return IsExplicitImpl || base.IsUsed; }
}
//
get { return "M:"; }
}
- protected override void VerifyObsoleteAttribute()
- {
- base.VerifyObsoleteAttribute ();
-
- if (parameter_types == null)
- return;
-
- foreach (Type type in parameter_types) {
- CheckUsageOfObsoleteAttribute (type);
- }
- }
}
public class SourceMethod : ISourceMethod
this.builder = builder;
CodeGen.SymbolWriter.OpenMethod (
- file, this, start.Row, 0, end.Row, 0);
+ file, this, start.Row, start.Column, end.Row, start.Column);
}
public string Name {
return null;
Location start_loc = block.StartLocation;
- if (Location.IsNull (start_loc))
+ if (start_loc.IsNull)
return null;
Location end_loc = block.EndLocation;
- if (Location.IsNull (end_loc))
+ if (end_loc.IsNull)
return null;
ISourceFile file = start_loc.SourceFile;
//
public Method (TypeContainer parent, GenericMethod generic,
Expression return_type, int mod, bool is_iface,
- MemberName name, Parameters parameters, Attributes attrs,
- Location l)
+ MemberName name, Parameters parameters, Attributes attrs)
: base (parent, generic, return_type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- is_iface, name, attrs, parameters, l)
+ is_iface, name, attrs, parameters)
{
}
TypeManager.CSharpSignature(b) + "'");
}
- public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
+ bool IsEntryPoint (MethodBuilder b, Parameters pinfo)
{
if (b.ReturnType != TypeManager.void_type &&
b.ReturnType != TypeManager.int32_type)
return;
}
- for (int i = 0; i < parameter_info.Count; ++i) {
- if ((parameter_info.ParameterModifier (i) & Parameter.Modifier.OUT) != 0) {
+ for (int i = 0; i < ParameterInfo.Count; ++i) {
+ if ((ParameterInfo.ParameterModifier (i) & Parameter.Modifier.OUTMASK) != 0) {
Report.Error (685, Location, "Conditional method `{0}' cannot have an out parameter", GetSignatureForError ());
return;
}
if (GenericMethod != null) {
string method_name = MemberName.Name;
- if (IsExplicitImpl)
- method_name = TypeManager.GetFullName (InterfaceType) + "." + method_name;
+ if (IsExplicitImpl) {
+ method_name = TypeManager.CSharpName (InterfaceType) +
+ '.' + method_name;
+ }
mb = Parent.TypeBuilder.DefineGenericMethod (method_name, flags);
if (!GenericMethod.Define (mb))
if (IsOperator != null)
flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
- MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
- this, mb, GenericMethod, base_method);
+ MethodData = new MethodData (this, ModFlags, flags, this, mb, GenericMethod, base_method);
if (!MethodData.Define (Parent))
return false;
//
if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
Iterator iterator = new Iterator (
- this, Parent, ParameterInfo, ModFlags);
+ this, Parent, GenericMethod, ModFlags);
if (!iterator.DefineIterator ())
return false;
}
} else {
if (RootContext.WarningLevel >= 4)
- Report.Warning (28, Location, "`{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder));
+ Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder));
}
}
protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
{
MethodInfo mi = (MethodInfo) container.BaseCache.FindMemberToOverride (
- container.TypeBuilder, Name, ParameterTypes, false);
+ container.TypeBuilder, Name, ParameterTypes, GenericMethod, false);
if (mi == null)
return null;
if (!base.VerifyClsCompliance (ds))
return false;
- if (parameter_types.Length > 0) {
+ if (ParameterInfo.Count > 0) {
ArrayList al = (ArrayList)ds.MemberCache.Members [Name];
if (al.Count > 1)
ds.MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
public CallingConventions CallingConventions {
get {
- CallingConventions cc = Parameters.GetCallingConvention ();
+ CallingConventions cc = Parameters.CallingConvention;
if (Parameters.HasArglist)
block.HasVarargs = true;
return ec;
}
- public ObsoleteAttribute GetObsoleteAttribute ()
- {
- return GetObsoleteAttribute (ds);
- }
-
/// <summary>
/// Returns true if method has conditional attribute and the conditions is not defined (method is excluded).
/// </summary>
return true;
}
- public void Emit (EmitContext ec)
+ public virtual void Emit (EmitContext ec)
{
if (base_constructor != null){
ec.Mark (loc, false);
}
}
+ class GeneratedBaseInitializer: ConstructorBaseInitializer {
+ public GeneratedBaseInitializer (Location loc):
+ base (null, loc)
+ {
+ }
+
+ public override void Emit(EmitContext ec)
+ {
+ bool old = ec.TestObsoleteMethodUsage;
+ ec.TestObsoleteMethodUsage = false;
+ base.Emit (ec);
+ ec.TestObsoleteMethodUsage = old;
+ }
+ }
+
public class ConstructorThisInitializer : ConstructorInitializer {
public ConstructorThisInitializer (ArrayList argument_list, Location l) :
base (argument_list, l)
// my very own code has static constructors.
//
public Constructor (TypeContainer ds, string name, int mod, Parameters args,
- ConstructorInitializer init, Location l)
+ ConstructorInitializer init, Location loc)
: base (ds, null, null, mod, AllowedModifiers, false,
- new MemberName (name), null, args, l)
+ new MemberName (name, loc), null, args)
{
Initializer = init;
}
public bool IsDefault ()
{
if ((ModFlags & Modifiers.STATIC) != 0)
- return (Parameters.FixedParameters == null ? true : Parameters.Empty) &&
- (Parameters.ArrayParameter == null ? true : Parameters.Empty);
+ return Parameters.Empty;
- else
- return (Parameters.FixedParameters == null ? true : Parameters.Empty) &&
- (Parameters.ArrayParameter == null ? true : Parameters.Empty) &&
+ return Parameters.Empty &&
(Initializer is ConstructorBaseInitializer) &&
(Initializer.Arguments == null);
}
}
if ((RootContext.WarningLevel >= 4) && ((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.PROTECTED) != 0)) {
- Report.Warning (628, Location, "`{0}': new protected member declared in sealed class", GetSignatureForError ());
+ Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class", GetSignatureForError ());
}
return true;
if ((ModFlags & Modifiers.UNSAFE) != 0)
ConstructorBuilder.InitLocals = false;
+
+ if (Parent.IsComImport) {
+ if (!IsDefault ()) {
+ Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
+ Parent.GetSignatureForError ());
+ return false;
+ }
+ ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
+ }
TypeManager.AddMethod (ConstructorBuilder, this);
- //
- // HACK because System.Reflection.Emit is lame
- //
- TypeManager.RegisterMethod (ConstructorBuilder, ParameterInfo, ParameterTypes);
-
return true;
}
public override void Emit ()
{
EmitContext ec = CreateEmitContext (null, null);
+ if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute () != null)
+ ec.TestObsoleteMethodUsage = false;
// If this is a non-static `struct' constructor and doesn't have any
// initializer, it must initialize all of the struct's fields.
((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
Block.AddThisVariable (Parent, Location);
- if (block != null)
- block.ResolveMeta (ec, ParameterInfo);
+ if (block != null) {
+ if (!block.ResolveMeta (ec, ParameterInfo))
+ block = null;
+ }
if ((ModFlags & Modifiers.STATIC) == 0){
if (Parent.Kind == Kind.Class && Initializer == null)
- Initializer = new ConstructorBaseInitializer (
- null, Location);
+ Initializer = new GeneratedBaseInitializer (Location);
//
ec.IsStatic = false;
}
- Parameters.LabelParameters (ec, ConstructorBuilder);
+ Parameters.ApplyAttributes (ec, ConstructorBuilder);
SourceMethod source = SourceMethod.Create (
Parent, ConstructorBuilder, block);
}
}
if (Initializer != null) {
- if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute (Parent) != null)
- ec.TestObsoleteMethodUsage = false;
-
Initializer.Emit (ec);
}
if (OptAttributes != null)
OptAttributes.Emit (ec, this);
- ec.EmitTopBlock (this, block, ParameterInfo);
+ ec.EmitTopBlock (this, block);
if (source != null)
source.CloseMethod ();
return false;
}
- if (parameter_types.Length > 0) {
+ if (ParameterInfo.Count > 0) {
ArrayList al = (ArrayList)ds.MemberCache.Members [".ctor"];
if (al.Count > 3)
ds.MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
if (ds.TypeBuilder.IsSubclassOf (TypeManager.attribute_type)) {
- foreach (Type param in parameter_types) {
+ foreach (Type param in ParameterTypes) {
if (param.IsArray) {
return true;
}
public System.Reflection.CallingConventions CallingConventions {
get {
- CallingConventions cc = Parameters.GetCallingConvention ();
+ CallingConventions cc = Parameters.CallingConvention;
if (Parent.Kind == Kind.Class)
if ((ModFlags & Modifiers.STATIC) == 0)
return new EmitContext (Parent, Location, ig_, null, ModFlags, true);
}
- public ObsoleteAttribute GetObsoleteAttribute ()
- {
- return GetObsoleteAttribute (Parent);
- }
-
public bool IsExcluded(EmitContext ec)
{
return false;
CallingConventions CallingConventions { get; }
Location Location { get; }
MemberName MethodName { get; }
- Type[] ParameterTypes { get; }
Type ReturnType { get; }
GenericMethod GenericMethod { get; }
+ Parameters ParameterInfo { get; }
Attributes OptAttributes { get; }
ToplevelBlock Block { get; set; }
readonly IMethodData method;
- //
- // The return type of this method
- //
public readonly GenericMethod GenericMethod;
- public readonly InternalParameters ParameterInfo;
//
// Are we implementing an interface ?
}
}
- public MethodData (MemberBase member, InternalParameters parameters,
+ public MethodData (MemberBase member,
int modifiers, MethodAttributes flags, IMethodData method)
{
this.member = member;
- this.ParameterInfo = parameters;
this.modifiers = modifiers;
this.flags = flags;
this.method = method;
}
- public MethodData (MemberBase member, InternalParameters parameters,
+ public MethodData (MemberBase member,
int modifiers, MethodAttributes flags,
IMethodData method, MethodBuilder builder,
GenericMethod generic, MethodInfo parent_method)
- : this (member, parameters, modifiers, flags, method)
+ : this (member, modifiers, flags, method)
{
this.builder = builder;
this.GenericMethod = generic;
string name = method.MethodName.Basename;
string method_name = method.MethodName.FullName;
- Type[] ParameterTypes = method.ParameterTypes;
-
if (container.Pending != null){
if (member is Indexer) // TODO: test it, but it should work without this IF
implementing = container.Pending.IsInterfaceIndexer (
- member.InterfaceType, method.ReturnType, ParameterInfo);
+ member.InterfaceType, method.ReturnType, method.ParameterInfo);
else
implementing = container.Pending.IsInterfaceMethod (
- member.InterfaceType, name, method.ReturnType, ParameterInfo);
+ member.InterfaceType, name, method.ReturnType, method.ParameterInfo);
if (member.InterfaceType != null){
if (implementing == null){
}
return false;
}
- if (implementing.IsSpecialName && !((member is PropertyBase || member is EventProperty))) {
+ if (implementing.IsSpecialName && !(method is AbstractPropertyEventMethod)) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (683, method.Location, "`{0}' explicit method implementation cannot implement `{1}' because it is an accessor",
member.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
return false;
}
- method_name = TypeManager.GetFullName (member.InterfaceType) + "." + method_name;
+ method_name = TypeManager.GetFullName (member.InterfaceType) +
+ '.' + method_name;
} else {
- if (implementing != null && method is AbstractPropertyEventMethod && !implementing.IsSpecialName) {
- Report.SymbolRelatedToPreviousError (implementing);
- 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 ());
- return false;
+ if (implementing != null) {
+ AbstractPropertyEventMethod prop_method = method as AbstractPropertyEventMethod;
+ if (prop_method != null) {
+ if (!implementing.IsSpecialName) {
+ Report.SymbolRelatedToPreviousError (implementing);
+ 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 ());
+ return false;
+ }
+ PropertyBase.PropertyMethod pm = prop_method as PropertyBase.PropertyMethod;
+ if (pm != null && pm.HasCustomAccessModifier && (pm.ModFlags & Modifiers.PUBLIC) == 0) {
+ Report.SymbolRelatedToPreviousError (implementing);
+ Report.Error (277, method.Location, "Accessor `{0}' must be declared public to implement interface member `{1}'",
+ method.GetSignatureForError (), TypeManager.CSharpSignature (implementing, true));
+ return false;
+ }
+ }
}
}
}
//
if ((modifiers & Modifiers.STATIC) != 0){
implementing = null;
- Modifiers.Error_InvalidModifier (method.Location, "static");
}
}
}
EmitContext ec = method.CreateEmitContext (container, null);
+ if (method.GetObsoleteAttribute () != null || container.GetObsoleteAttribute () != null)
+ ec.TestObsoleteMethodUsage = false;
- DefineMethodBuilder (ec, container, method_name, ParameterTypes);
+ DefineMethodBuilder (ec, container, method_name, method.ParameterInfo.Types);
if (builder == null)
return false;
if (member is Indexer) {
container.Pending.ImplementIndexer (
member.InterfaceType, builder, method.ReturnType,
- ParameterInfo, member.IsExplicitImpl);
+ method.ParameterInfo, member.IsExplicitImpl);
} else
container.Pending.ImplementMethod (
member.InterfaceType, name, method.ReturnType,
- ParameterInfo, member.IsExplicitImpl);
+ method.ParameterInfo, member.IsExplicitImpl);
if (member.IsExplicitImpl)
container.TypeBuilder.DefineMethodOverride (
builder, implementing);
}
- TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes);
TypeManager.AddMethod (builder, method);
if (GenericMethod != null) {
else
ec = method.CreateEmitContext (container, null);
- if (method.GetObsoleteAttribute () != null || container.GetObsoleteAttribute (container) != null)
+ if (method.GetObsoleteAttribute () != null || container.GetObsoleteAttribute () != null)
ec.TestObsoleteMethodUsage = false;
+ method.ParameterInfo.ApplyAttributes (ec, MethodBuilder);
+
Attributes OptAttributes = method.OptAttributes;
if (OptAttributes != null)
OptAttributes.Emit (ec, kind);
- if (member is MethodCore)
- ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder);
-
+ if (GenericMethod != null)
+ GenericMethod.EmitAttributes (ec);
+
ToplevelBlock block = method.Block;
SourceMethod source = SourceMethod.Create (
if (member is Destructor)
EmitDestructor (ec, block);
else
- ec.EmitTopBlock (method, block, ParameterInfo);
+ ec.EmitTopBlock (method, block);
if (source != null)
source.CloseMethod ();
ig.BeginExceptionBlock ();
ec.ReturnLabel = finish;
ec.HasReturnLabel = true;
- ec.EmitTopBlock (method, block, null);
+ ec.EmitTopBlock (method, block);
// ig.MarkLabel (finish);
ig.BeginFinallyBlock ();
// TODO: Should derive from MethodCore
public class Destructor : Method {
- public Destructor (TypeContainer ds, Expression return_type, int mod, string name,
- Parameters parameters, Attributes attrs, Location l)
- : base (ds, null, return_type, mod, false, new MemberName (name),
- parameters, attrs, l)
+ public Destructor (TypeContainer ds, Expression return_type, int mod,
+ string name, Parameters parameters, Attributes attrs,
+ Location l)
+ : base (ds, null, return_type, mod, false, new MemberName (name, l),
+ parameters, attrs)
{ }
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
public MethodAttributes flags;
public readonly DeclSpace ds;
+ public readonly GenericMethod GenericMethod;
protected readonly int explicit_mod_flags;
//
public string ShortName {
get { return MemberName.Name; }
- set {
- SetMemberName (new MemberName (MemberName.Left, value));
- }
+ set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
+ }
+
+ public new TypeContainer Parent {
+ get { return (TypeContainer) base.Parent; }
}
//
EmitContext ec = ds.EmitContext;
bool old_unsafe = ec.InUnsafe;
ec.InUnsafe = InUnsafe;
+ ec.ResolvingGenericMethod = GenericMethod != null;
Type = Type.ResolveAsTypeTerminal (ec);
+ ec.ResolvingGenericMethod = false;
ec.InUnsafe = old_unsafe;
-
- member_type = Type == null ? null : Type.Type;
+ if (Type != null) {
+ member_type = Type.Type;
+ }
}
return member_type;
}
//
// The constructor is only exposed to our children
//
- protected MemberBase (TypeContainer parent, DeclSpace ds, Expression type, int mod,
- int allowed_mod, int def_mod, MemberName name,
- Attributes attrs, Location loc)
- : base (parent, name, attrs, loc)
+ protected MemberBase (TypeContainer parent, GenericMethod generic,
+ Expression type, int mod, int allowed_mod, int def_mod,
+ MemberName name, Attributes attrs)
+ : base (parent, name, attrs)
{
- this.ds = ds;
+ this.ds = generic != null ? generic : (DeclSpace) parent;
explicit_mod_flags = mod;
Type = type;
- ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
+ ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, Location);
IsExplicitImpl = (MemberName.Left != null);
+ GenericMethod = generic;
}
protected virtual bool CheckBase ()
((Parent.ModFlags & Modifiers.SEALED) != 0) &&
((ModFlags & Modifiers.PROTECTED) != 0) &&
((ModFlags & Modifiers.OVERRIDE) == 0) && (Name != "Finalize")) {
- Report.Warning (628, Location, "`{0}': new protected member declared in sealed class", GetSignatureForError ());
+ Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class", GetSignatureForError ());
}
return true;
}
- protected abstract bool CheckGenericOverride (MethodInfo method, string name);
-
- protected virtual bool CheckParameters (DeclSpace ds, Type [] parameters)
- {
- bool error = false;
-
- foreach (Type partype in parameters){
- if (partype == TypeManager.void_type) {
- Report.Error (
- 1547, Location, "Keyword 'void' cannot " +
- "be used in this context");
- return false;
- }
-
- if (partype.IsPointer){
- if (!UnsafeOK (ds))
- error = true;
- if (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
- error = true;
- }
-
- if (ds.AsAccessible (partype, ModFlags))
- continue;
-
- if (this is Indexer)
- Report.Error (55, Location,
- "Inconsistent accessibility: parameter type `" +
- TypeManager.CSharpName (partype) + "' is less " +
- "accessible than indexer `" + GetSignatureForError () + "'");
- else if ((this is Method) && ((Method) this).IsOperator != null)
- Report.Error (57, Location,
- "Inconsistent accessibility: parameter type `" +
- TypeManager.CSharpName (partype) + "' is less " +
- "accessible than operator `" + GetSignatureForError () + "'");
- else
- Report.Error (51, Location,
- "Inconsistent accessibility: parameter type `" +
- TypeManager.CSharpName (partype) + "' is less " +
- "accessible than method `" + GetSignatureForError () + "'");
- error = true;
- }
-
- return !error;
- }
-
protected virtual bool DoDefineBase ()
{
EmitContext ec = Parent.EmitContext;
}
if (IsExplicitImpl) {
- Expression expr = MemberName.Left.GetTypeExpression (Location);
+ Expression expr = MemberName.Left.GetTypeExpression ();
TypeExpr iface_texpr = expr.ResolveAsTypeTerminal (ec);
if (iface_texpr == null)
return false;
- InterfaceType = iface_texpr.Type;
+ InterfaceType = iface_texpr.ResolveType (ec);
if (!InterfaceType.IsInterface) {
Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
if (MemberType == null)
return false;
+ CheckObsoleteType (Type);
+
if ((Parent.ModFlags & Modifiers.SEALED) != 0 &&
(ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0) {
Report.Error (549, Location, "New virtual member `{0}' is declared in a sealed class `{1}'",
return false;
if (IsExplicitImpl) {
- Expression expr = MemberName.Left.GetTypeExpression (Location);
+ Expression expr = MemberName.Left.GetTypeExpression ();
TypeExpr texpr = expr.ResolveAsTypeTerminal (ec);
if (texpr == null)
return false;
return false;
}
- protected override void VerifyObsoleteAttribute()
- {
- CheckUsageOfObsoleteAttribute (MemberType);
- }
}
//
abstract public class FieldBase : MemberBase {
public FieldBuilder FieldBuilder;
public Status status;
+ protected Expression initializer;
[Flags]
public enum Status : byte {
/// </summary>
public MemberInfo conflict_symbol;
- //
- // The constructor is only exposed to our children
- //
protected FieldBase (TypeContainer parent, Expression type, int mod,
- int allowed_mod, MemberName name, object init,
- Attributes attrs, Location loc)
- : base (parent, parent, type, mod, allowed_mod, Modifiers.PRIVATE,
- name, attrs, loc)
+ int allowed_mod, MemberName name, Attributes attrs)
+ : base (parent, null, type, mod, allowed_mod, Modifiers.PRIVATE,
+ name, attrs)
{
- this.init = init;
}
public override AttributeTargets AttributeTargets {
FieldBuilder.SetCustomAttribute (cb);
}
- //
- // Whether this field has an initializer.
- //
- public bool HasInitializer {
- get {
- return init != null;
- }
- }
+ public void EmitInitializer (EmitContext ec)
+ {
+ // Replace DeclSpace because of partial classes
+ ec.DeclSpace = EmitContext.DeclSpace;
- protected readonly Object init;
- // Private.
- Expression init_expr;
- bool init_expr_initialized = false;
+ ec.IsFieldInitializer = true;
+ initializer = initializer.Resolve (ec);
+ ec.IsFieldInitializer = false;
+ if (initializer == null)
+ return;
+ FieldExpr fe = new FieldExpr (FieldBuilder, Location, true);
+ if ((ModFlags & Modifiers.STATIC) == 0)
+ fe.InstanceExpression = new This (Location).Resolve (ec);
- protected override bool CheckGenericOverride (MethodInfo method, string name)
- {
- return true;
- }
+ ExpressionStatement a = new Assign (fe, initializer, Location);
- //
- // Resolves and returns the field initializer.
- //
- public Expression GetInitializerExpression (EmitContext ec)
- {
- if (init_expr_initialized)
- return init_expr;
+ a = a.ResolveStatement (ec);
+ if (a == null)
+ return;
- Expression e;
- if (init is Expression)
- e = (Expression) init;
- else
- e = new ArrayCreation (Type, "", (ArrayList)init, Location);
+ Constant c = initializer as Constant;
+ if (c != null && CanElideInitializer (c))
+ return;
- // TODO: Any reason why we are using parent EC ?
- EmitContext parent_ec = Parent.EmitContext;
+ a.EmitStatement (ec);
+ }
- bool old_is_static = parent_ec.IsStatic;
- bool old_is_ctor = parent_ec.IsConstructor;
- parent_ec.IsStatic = ec.IsStatic;
- parent_ec.IsConstructor = ec.IsConstructor;
- parent_ec.IsFieldInitializer = true;
- e = e.DoResolve (parent_ec);
- parent_ec.IsFieldInitializer = false;
- parent_ec.IsStatic = old_is_static;
- parent_ec.IsConstructor = old_is_ctor;
+ bool CanElideInitializer (Constant c)
+ {
+ if (MemberType == c.Type)
+ return c.IsDefaultValue;
- init_expr = e;
- init_expr_initialized = true;
+ if (c.Type == TypeManager.null_type)
+ return true;
- return init_expr;
+ return false;
}
protected override bool CheckBase ()
conflict_symbol = Parent.FindBaseMemberWithSameName (Name, false);
if (conflict_symbol == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
- Report.Warning (109, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
+ Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
}
return true;
}
if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0) {
Report.SymbolRelatedToPreviousError (conflict_symbol);
- Report.Warning (108, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+ Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
}
return true;
}
+ public Expression Initializer {
+ set {
+ if (value != null) {
+ this.initializer = value;
+ Parent.RegisterFieldForInitialization (this);
+ }
+ }
+ }
+
protected virtual bool IsFieldClsCompliant {
get {
if (FieldBuilder == null)
}
}
- public abstract class FieldMember: FieldBase
+ public abstract class FieldMember : FieldBase
{
protected FieldMember (TypeContainer parent, Expression type, int mod,
- int allowed_mod, MemberName name, object init, Attributes attrs, Location loc)
- : base (parent, type, mod, allowed_mod | Modifiers.ABSTRACT, name, init, attrs, loc)
+ int allowed_mod, MemberName name, Attributes attrs)
+ : base (parent, type, mod, allowed_mod | Modifiers.ABSTRACT, name, attrs)
{
if ((mod & Modifiers.ABSTRACT) != 0)
- Report.Error (681, loc, "The modifier 'abstract' is not valid on fields. Try using a property instead");
+ Report.Error (681, Location, "The modifier 'abstract' is not valid on fields. Try using a property instead");
}
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
if (ec == null)
throw new InternalErrorException ("FieldMember.Define called too early");
- if (MemberType == null)
+ if (MemberType == null || Type == null)
return false;
+ CheckObsoleteType (Type);
+
if (MemberType == TypeManager.void_type) {
Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
return false;
/// <summary>
/// Fixed buffer implementation
/// </summary>
- public class FixedField: FieldMember, IFixedBuffer
+ public class FixedField : FieldMember, IFixedBuffer
{
public const string FixedElementName = "FixedElementField";
static int GlobalCounter = 0;
public FixedField (TypeContainer parent, Expression type, int mod, string name,
Expression size_expr, Attributes attrs, Location loc):
- base (parent, type, mod, AllowedModifiers, new MemberName (name), null, attrs, loc)
+ base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
{
if (RootContext.Version == LanguageVersion.ISO_1)
Report.FeatureIsNotStandardized (loc, "fixed size buffers");
public override bool Define()
{
+#if !NET_2_0
+ if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) != 0)
+ Report.Warning (-23, 1, Location, "Only private or internal fixed sized buffers are supported by .NET 1.x");
+#endif
+
if (Parent.Kind != Kind.Struct) {
Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
GetSignatureForError ());
return false;
}
- Expression e = size_expr.Resolve (Parent.EmitContext);
- if (e == null)
+ Constant c = size_expr.ResolveAsConstant (Parent.EmitContext, this);
+ if (c == null)
return false;
- Constant c = e as Constant;
- if (c == null) {
- Report.Error (133, Location, "The expression being assigned to `{0}' must be constant", GetSignatureForError ());
- return false;
- }
-
IntConstant buffer_size_const = c.ToInt (Location);
if (buffer_size_const == null)
return false;
Modifiers.READONLY;
public Field (TypeContainer parent, Expression type, int mod, string name,
- Object expr_or_array_init, Attributes attrs, Location loc)
- : base (parent, type, mod, AllowedModifiers, new MemberName (name),
- expr_or_array_init, attrs, loc)
+ Attributes attrs, Location loc)
+ : base (parent, type, mod, AllowedModifiers, new MemberName (name, loc),
+ attrs)
{
}
TypeManager.RegisterFieldBase (FieldBuilder, this);
}
catch (ArgumentException) {
- Report.Warning (-24, Location, "The Microsoft runtime is unable to use [void|void*] as a field type, try using the Mono runtime.");
+ Report.Warning (-24, 1, Location, "The Microsoft runtime is unable to use [void|void*] as a field type, try using the Mono runtime.");
return false;
}
// Ooouh Martin, templates are missing here.
// When it will be possible move here a lot of child code and template method type.
- public abstract class AbstractPropertyEventMethod: MemberCore, IMethodData {
+ public abstract class AbstractPropertyEventMethod : MemberCore, IMethodData {
protected MethodData method_data;
protected ToplevelBlock block;
protected ListDictionary declarative_security;
ReturnParameter return_attributes;
public AbstractPropertyEventMethod (MemberBase member, string prefix)
- : base (null, SetupName (prefix, member), null, member.Location)
+ : base (member.Parent, SetupName (prefix, member, member.Location), null)
{
this.prefix = prefix;
IsDummy = true;
public AbstractPropertyEventMethod (MemberBase member, Accessor accessor,
string prefix)
- : base (null, SetupName (prefix, member),
- accessor.Attributes, accessor.Location)
+ : base (member.Parent, SetupName (prefix, member, accessor.Location),
+ accessor.Attributes)
{
this.prefix = prefix;
this.block = accessor.Block;
}
- static MemberName SetupName (string prefix, MemberBase member)
+ static MemberName SetupName (string prefix, MemberBase member, Location loc)
{
- return new MemberName (member.MemberName.Left, prefix + member.ShortName);
+ return new MemberName (member.MemberName.Left, prefix + member.ShortName, loc);
}
public void UpdateName (MemberBase member)
{
- SetMemberName (SetupName (prefix, member));
+ SetMemberName (SetupName (prefix, member, Location));
}
#region IMethodData Members
}
}
- public abstract ObsoleteAttribute GetObsoleteAttribute ();
- public abstract Type[] ParameterTypes { get; }
+ public Type[] ParameterTypes {
+ get {
+ return ParameterInfo.Types;
+ }
+ }
+
+ public abstract Parameters ParameterInfo { get ; }
public abstract Type ReturnType { get; }
public abstract EmitContext CreateEmitContext(TypeContainer tc, ILGenerator ig);
public bool IsDuplicateImplementation (MethodCore method)
{
- if (Name != method.Name)
+ if (!MemberName.Equals (method.MemberName))
return false;
Type[] param_types = method.ParameterTypes;
get { throw new InvalidOperationException ("Unexpected attempt to get doc comment from " + this.GetType () + "."); }
}
- protected override void VerifyObsoleteAttribute()
- {
- }
-
}
//
//
abstract public class PropertyBase : MethodCore {
- public class GetMethod: PropertyMethod
+ public class GetMethod : PropertyMethod
{
static string[] attribute_targets = new string [] { "method", "return" };
{
base.Define (container);
- method_data = new MethodData (method, method.ParameterInfo, ModFlags, flags, this);
+ method_data = new MethodData (method, ModFlags, flags, this);
if (!method_data.Define (container))
return null;
}
}
+ public override Parameters ParameterInfo {
+ get {
+ return Parameters.EmptyReadOnlyParameters;
+ }
+ }
+
public override string[] ValidAttributeTargets {
get {
return attribute_targets;
}
}
- public class SetMethod: PropertyMethod {
+ public class SetMethod : PropertyMethod {
static string[] attribute_targets = new string [] { "method", "param", "return" };
ImplicitParameter param_attr;
+ protected Parameters parameters;
public SetMethod (MethodCore method):
base (method, "set_")
base.ApplyAttributeBuilder (a, cb);
}
- protected virtual InternalParameters GetParameterInfo (EmitContext ec)
+ public override Parameters ParameterInfo {
+ get {
+ return parameters;
+ }
+ }
+
+ protected virtual void DefineParameters ()
{
Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (method.Type, "value", Parameter.Modifier.NONE, null, method.Location);
- Parameters parameters = new Parameters (parms, null);
-
- bool old_unsafe = ec.InUnsafe;
- ec.InUnsafe = InUnsafe;
- Type [] types = parameters.GetParameterInfo (ec);
- ec.InUnsafe = old_unsafe;
-
- return new InternalParameters (types, parameters);
+ parms [0] = new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, Location);
+ parameters = new Parameters (parms);
+ parameters.Resolve (null);
}
public override MethodBuilder Define (TypeContainer container)
{
if (container.EmitContext == null)
throw new InternalErrorException ("SetMethod.Define called too early");
-
+
+ DefineParameters ();
+ if (IsDummy)
+ return null;
+
base.Define (container);
-
- method_data = new MethodData (method, GetParameterInfo (container.EmitContext), ModFlags, flags, this);
+
+ method_data = new MethodData (method, ModFlags, flags, this);
if (!method_data.Define (container))
return null;
return method_data.MethodBuilder;
}
- public override Type[] ParameterTypes {
- get {
- return new Type[] { method.MemberType };
- }
- }
-
public override Type ReturnType {
get {
return TypeManager.void_type;
static string[] attribute_targets = new string [] { "property" };
- public abstract class PropertyMethod: AbstractPropertyEventMethod {
+ public abstract class PropertyMethod : AbstractPropertyEventMethod {
protected readonly MethodCore method;
protected MethodAttributes flags;
bool yields;
: base (method, prefix)
{
this.method = method;
- Parent = method.Parent;
}
public PropertyMethod (MethodCore method, Accessor accessor, string prefix)
: base (method, accessor, prefix)
{
this.method = method;
- Parent = method.Parent;
this.ModFlags = accessor.ModFlags;
yields = accessor.Yields;
return method.IsClsComplianceRequired (ds);
}
- public InternalParameters ParameterInfo
- {
- get {
- return method_data.ParameterInfo;
- }
- }
-
public virtual MethodBuilder Define (TypeContainer container)
{
if (!method.CheckAbstractAndExtern (block != null))
// Setup iterator if we are one
//
if (yields) {
- Iterator iterator = new Iterator (this,
- Parent, method.ParameterInfo, ModFlags);
+ Iterator iterator = new Iterator (this, Parent as TypeContainer, null, ModFlags);
if (!iterator.DefineIterator ())
return null;
}
}
- public override Type[] ParameterTypes {
- get {
- return TypeManager.NoTypes;
- }
- }
-
public override EmitContext CreateEmitContext (TypeContainer tc,
ILGenerator ig)
{
public override ObsoleteAttribute GetObsoleteAttribute ()
{
- return method.GetObsoleteAttribute (method.ds);
+ return method.GetObsoleteAttribute ();
}
public override string GetSignatureForError()
public PropertyBase (TypeContainer parent, Expression type, int mod_flags,
int allowed_mod, bool is_iface, MemberName name,
- Parameters parameters, Attributes attrs,
- Location loc)
+ Parameters parameters, Attributes attrs)
: base (parent, null, type, mod_flags, allowed_mod, is_iface, name,
- attrs, parameters, loc)
+ attrs, parameters)
{
}
protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
{
PropertyInfo base_property = container.BaseCache.FindMemberToOverride (
- container.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
+ container.TypeBuilder, Name, ParameterTypes, null, true) as PropertyInfo;
if (base_property == null)
return null;
const int AllowedInterfaceModifiers =
Modifiers.NEW;
- public Property (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, MemberName name, Attributes attrs,
- Accessor get_block, Accessor set_block, Location loc)
- : base (parent, type, mod_flags,
+ public Property (TypeContainer ds, Expression type, int mod, bool is_iface,
+ MemberName name, Attributes attrs, Accessor get_block,
+ Accessor set_block)
+ : base (ds, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
- loc)
+ is_iface, name, Parameters.EmptyReadOnlyParameters, attrs)
{
if (get_block == null)
Get = new GetMethod (this);
return false;
}
+ SetBuilder = Set.Define (Parent);
if (!Set.IsDummy) {
- SetBuilder = Set.Define (Parent);
if (SetBuilder == null)
return false;
-
- SetBuilder.DefineParameter (1, ParameterAttributes.None, "value");
}
// FIXME - PropertyAttributes.HasDefault ?
-
- PropertyAttributes prop_attr = PropertyAttributes.None;
- if (!IsInterface)
- prop_attr |= PropertyAttributes.RTSpecialName |
- PropertyAttributes.SpecialName;
- PropertyBuilder = Parent.TypeBuilder.DefineProperty (
- Name, prop_attr, MemberType, null);
-
- if (!Get.IsDummy)
- PropertyBuilder.SetGetMethod (GetBuilder);
-
- if (!Set.IsDummy)
- PropertyBuilder.SetSetMethod (SetBuilder);
+ PropertyBuilder = Parent.TypeBuilder.DefineProperty (
+ MemberName.ToString (), PropertyAttributes.None, MemberType, null);
+
+ if (!Get.IsDummy)
+ PropertyBuilder.SetGetMethod (GetBuilder);
+
+ if (!Set.IsDummy)
+ PropertyBuilder.SetSetMethod (SetBuilder);
- TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder);
return true;
}
}
static string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
public EventProperty (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, MemberName name, Object init,
- Attributes attrs, Accessor add, Accessor remove,
- Location loc)
- : base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
+ bool is_iface, MemberName name,
+ Attributes attrs, Accessor add, Accessor remove)
+ : base (parent, type, mod_flags, is_iface, name, attrs)
{
Add = new AddDelegateMethod (this, add);
Remove = new RemoveDelegateMethod (this, remove);
/// <summary>
/// Event is declared like field.
/// </summary>
- public class EventField: Event {
+ public class EventField : Event {
static string[] attribute_targets = new string [] { "event", "field", "method" };
static string[] attribute_targets_interface = new string[] { "event", "method" };
public EventField (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, MemberName name, Object init,
- Attributes attrs, Location loc)
- : base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
+ bool is_iface, MemberName name,
+ Attributes attrs)
+ : base (parent, type, mod_flags, is_iface, name, attrs)
{
Add = new AddDelegateMethod (this);
Remove = new RemoveDelegateMethod (this);
base.ApplyAttributeBuilder (a, cb);
}
+ public override bool Define()
+ {
+ if (!base.Define ())
+ return false;
+
+ if (initializer != null) {
+ if (((ModFlags & Modifiers.ABSTRACT) != 0)) {
+ Report.Error (74, Location, "`{0}': abstract event cannot have an initializer",
+ GetSignatureForError ());
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public override string[] ValidAttributeTargets {
get {
return IsInterface ? attribute_targets_interface : attribute_targets;
return method.IsClsComplianceRequired (ds);
}
- public MethodBuilder Define (TypeContainer container, InternalParameters ip)
+ public MethodBuilder Define (TypeContainer container)
{
- method_data = new MethodData (method, ip, method.ModFlags,
+ method_data = new MethodData (method, method.ModFlags,
method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
if (!method_data.Define (container))
return null;
MethodBuilder mb = method_data.MethodBuilder;
- mb.DefineParameter (1, ParameterAttributes.None, "value");
+ ParameterInfo.ApplyAttributes (Parent.EmitContext, mb);
return mb;
}
protected abstract MethodInfo DelegateMethodInfo { get; }
- public override Type[] ParameterTypes {
- get {
- return new Type[] { method.MemberType };
- }
- }
-
public override Type ReturnType {
get {
return TypeManager.void_type;
public override ObsoleteAttribute GetObsoleteAttribute ()
{
- return method.GetObsoleteAttribute (method.Parent);
+ return method.GetObsoleteAttribute ();
}
public override string[] ValidAttributeTargets {
return attribute_targets;
}
}
+
+ public override Parameters ParameterInfo {
+ get {
+ return method.parameters;
+ }
+ }
+
}
public DelegateMethod Add, Remove;
public MyEventBuilder EventBuilder;
public MethodBuilder AddBuilder, RemoveBuilder;
+ Parameters parameters;
- public Event (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, MemberName name, Object init, Attributes attrs,
- Location loc)
+ protected Event (TypeContainer parent, Expression type, int mod_flags,
+ bool is_iface, MemberName name, Attributes attrs)
: base (parent, type, mod_flags,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- name, init, attrs, loc)
+ name, attrs)
{
IsInterface = is_iface;
}
if (!DoDefine ())
return false;
- if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
- Report.Error (74, Location, "`" + GetSignatureForError () +
- "': abstract event cannot have an initializer");
- return false;
- }
-
if (!TypeManager.IsDelegateType (MemberType)) {
Report.Error (66, Location, "`{0}': event must be of a delegate type", GetSignatureForError ());
return false;
ec.InUnsafe = InUnsafe;
Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null, Location);
- Parameters parameters = new Parameters (parms, null);
- Type [] types = parameters.GetParameterInfo (ec);
- InternalParameters ip = new InternalParameters (types, parameters);
+ parms [0] = new Parameter (MemberType, "value", Parameter.Modifier.NONE, null, Location);
+ parameters = new Parameters (parms);
+ parameters.Resolve (null);
ec.InUnsafe = old_unsafe;
// Now define the accessors
//
- AddBuilder = Add.Define (Parent, ip);
+ AddBuilder = Add.Define (Parent);
if (AddBuilder == null)
return false;
- RemoveBuilder = Remove.Define (Parent, ip);
+ RemoveBuilder = Remove.Define (Parent);
if (RemoveBuilder == null)
return false;
public class Indexer : PropertyBase, IIteratorContainer {
- class GetIndexerMethod: GetMethod
+ class GetIndexerMethod : GetMethod
{
public GetIndexerMethod (MethodCore method):
base (method)
{
}
- public override Type[] ParameterTypes {
+ public override Parameters ParameterInfo {
get {
- return method.ParameterTypes;
+ return method.ParameterInfo;
}
}
}
class SetIndexerMethod: SetMethod
{
- readonly Parameters parameters;
-
public SetIndexerMethod (MethodCore method):
base (method)
{
}
- public SetIndexerMethod (MethodCore method, Parameters parameters, Accessor accessor):
+ public SetIndexerMethod (MethodCore method, Accessor accessor):
base (method, accessor)
{
- this.parameters = parameters;
}
- public override Type[] ParameterTypes {
- get {
- int top = method.ParameterTypes.Length;
- Type [] set_pars = new Type [top + 1];
- method.ParameterTypes.CopyTo (set_pars, 0);
- set_pars [top] = method.MemberType;
- return set_pars;
- }
- }
-
- protected override InternalParameters GetParameterInfo (EmitContext ec)
+ protected override void DefineParameters ()
{
- Parameter [] fixed_parms = parameters.FixedParameters;
-
- if (fixed_parms == null){
- throw new Exception ("We currently do not support only array arguments in an indexer at: " + method.Location);
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
- //
- // Here is the problem: the `value' parameter has
- // to come *after* the array parameter in the declaration
- // like this:
- // X (object [] x, Type value)
- // .param [0]
- //
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-
- }
-
+ Parameter [] fixed_parms = method.Parameters.FixedParameters;
Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
fixed_parms.CopyTo (tmp, 0);
tmp [fixed_parms.Length] = new Parameter (
- method.Type, "value", Parameter.Modifier.NONE, null, method.Location);
+ method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location);
- Parameters set_formal_params = new Parameters (tmp, null);
- Type [] types = set_formal_params.GetParameterInfo (ec);
-
- return new InternalParameters (types, set_formal_params);
+ parameters = new Parameters (tmp);
+ parameters.Resolve (null);
}
}
//
public Indexer (TypeContainer parent, Expression type, MemberName name, int mod,
bool is_iface, Parameters parameters, Attributes attrs,
- Accessor get_block, Accessor set_block, Location loc)
+ Accessor get_block, Accessor set_block)
: base (parent, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- is_iface, name, parameters, attrs, loc)
+ is_iface, name, parameters, attrs)
{
if (get_block == null)
Get = new GetIndexerMethod (this);
if (set_block == null)
Set = new SetIndexerMethod (this);
else
- Set = new SetIndexerMethod (this, parameters, set_block);
+ Set = new SetIndexerMethod (this, set_block);
}
public override bool Define ()
{
- PropertyAttributes prop_attr =
- PropertyAttributes.RTSpecialName |
- PropertyAttributes.SpecialName;
-
if (!DoDefineBase ())
return false;
//
if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
Iterator iterator = new Iterator (
- Get, Parent, Get.ParameterInfo, ModFlags);
+ Get, Parent, null, ModFlags);
if (!iterator.DefineIterator ())
return false;
}
}
+ SetBuilder = Set.Define (Parent);
if (!Set.IsDummy){
- SetBuilder = Set.Define (Parent);
if (SetBuilder == null)
return false;
}
//
Parameter [] p = Parameters.FixedParameters;
if (p != null) {
+ // TODO: should be done in parser and it needs to do cycle
if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
Report.Error (631, Location, "ref and out are not valid in this context");
return false;
}
-
- int i;
-
- for (i = 0; i < p.Length; ++i) {
- if (!Get.IsDummy)
- GetBuilder.DefineParameter (
- i + 1, p [i].Attributes, p [i].Name);
-
- if (!Set.IsDummy)
- SetBuilder.DefineParameter (
- i + 1, p [i].Attributes, p [i].Name);
- }
-
- if (!Set.IsDummy)
- SetBuilder.DefineParameter (
- i + 1, ParameterAttributes.None, "value");
-
- if (i != ParameterTypes.Length) {
- Parameter array_param = Parameters.ArrayParameter;
-
- SetBuilder.DefineParameter (
- i + 1, array_param.Attributes, array_param.Name);
- }
}
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
- Name, prop_attr, MemberType, ParameterTypes);
+ Name, PropertyAttributes.None, MemberType, ParameterTypes);
if (!Get.IsDummy)
PropertyBuilder.SetGetMethod (GetBuilder);
int mod_flags, Parameters parameters,
ToplevelBlock block, Attributes attrs, Location loc)
: base (parent, null, ret_type, mod_flags, AllowedModifiers, false,
- new MemberName ("op_" + type), attrs, parameters, loc)
+ new MemberName ("op_" + type, loc), attrs, parameters)
{
OperatorType = type;
Block = block;
}
}
- protected override bool CheckGenericOverride (MethodInfo method, string name)
- {
- return true;
- }
-
protected override bool CheckForDuplications()
{
ArrayList ar = Parent.Operators;
OperatorMethod = new Method (
Parent, null, Type, ModFlags, false, MemberName,
- Parameters, OptAttributes, Location);
+ Parameters, OptAttributes);
OperatorMethod.Block = Block;
OperatorMethod.IsOperator = this;
OperatorMethodBuilder = OperatorMethod.MethodBuilder;
- parameter_types = OperatorMethod.ParameterTypes;
+ Type[] parameter_types = OperatorMethod.ParameterTypes;
Type declaring_type = OperatorMethod.MethodData.DeclaringType;
Type return_type = OperatorMethod.ReturnType;
Type first_arg_type = parameter_types [0];
Report.Error (564, Location, "Overloaded shift operator must have the type of the first operand be the containing type, and the type of the second operand must be int");
return false;
}
- } else if (Parameters.FixedParameters.Length == 1) {
+ } else if (Parameters.Count == 1) {
// Checks for Unary operators
if (OperatorType == OpType.Increment || OperatorType == OpType.Decrement) {
}
} else {
- if (OperatorType == OpType.BitwiseAnd &&
- (first_arg_type != return_type || first_arg_type != parameter_types [1])) {
- Report.Error (217, Location, "In order to be applicable as a short circuit operator a user-defined logical operator ('{0}') " +
- "must have the same return type as the type of its 2 parameters", GetSignatureForError ());
- return false;
- }
-
// Checks for Binary operators
if (first_arg_type != declaring_type &&
RetType = ret_type;
if (parameters == null)
- Parameters = TypeManager.NoTypes;
+ Parameters = Type.EmptyTypes;
else
Parameters = parameters;
}
Type [] args;
if (mi != null)
- args = TypeManager.GetArgumentTypes (mi);
+ args = TypeManager.GetParameterData (mi).Types;
else
args = TypeManager.GetArgumentTypes (pi);
Type [] sigp = sig.Parameters;