namespace Mono.CSharp {
+ public enum Kind {
+ Root,
+ Struct,
+ Class,
+ Interface
+ }
+
/// <summary>
/// This is the base class for structs and classes.
/// </summary>
- public class TypeContainer : DeclSpace, IMemberContainer {
+ public abstract class TypeContainer : DeclSpace, IMemberContainer {
+
+ // Whether this is a struct, class or interface
+ public readonly Kind Kind;
+
// Holds a list of classes and structures
ArrayList types;
// Holds the list of
ArrayList interfaces;
- // Holds order in which interfaces must be closed
- ArrayList interface_order;
-
// Holds the methods.
ArrayList methods;
// Holds the iterators
ArrayList iterators;
+ // Holds the parts of a partial class;
+ ArrayList parts;
+
// The emit context for toplevel objects.
EmitContext ec;
Type GenericType;
- public TypeContainer ():
- this (null, null, MemberName.Null, null, new Location (-1)) {
- }
-
public TypeContainer (NamespaceEntry ns, TypeContainer parent,
- MemberName name, Attributes attrs, Location l)
+ MemberName name, Attributes attrs, Kind kind, Location l)
: base (ns, parent, name, attrs, l)
{
+ this.Kind = kind;
+
types = new ArrayList ();
base_class_name = null;
}
+ // <summary>
+ // Used to report back to the user the result of a declaration
+ // in the current declaration space
+ // </summary>
+ public void CheckDef (AdditionResult result, string name, Location loc)
+ {
+ if (result == AdditionResult.Success)
+ return;
+
+ switch (result){
+ case AdditionResult.NameExists:
+ Report.Error (102, loc, "The container `{0}' already " +
+ "contains a definition for `{1}'",
+ Name, name);
+ break;
+
+ //
+ // This is handled only for static Constructors, because
+ // in reality we handle these by the semantic analysis later
+ //
+ case AdditionResult.MethodExists:
+ Report.Error (111, loc, "Class `{0}' already defines a " +
+ "member called '{1}' with the same parameter " +
+ "types (more than one default constructor)",
+ Name, name);
+ break;
+
+ case AdditionResult.EnclosingClash:
+ Report.Error (542, loc, "Member names cannot be the same " +
+ "as their enclosing type");
+ break;
+
+ case AdditionResult.NotAConstructor:
+ Report.Error (1520, loc, "Class, struct, or interface method " +
+ "must have a return type");
+ break;
+
+ case AdditionResult.Error:
+ // Error has already been reported.
+ break;
+ }
+ }
+
public AdditionResult AddConstant (Const constant)
{
AdditionResult res;
return AdditionResult.Success;
}
- public AdditionResult AddClass (Class c)
+ public AdditionResult AddClass (TypeContainer c)
{
AdditionResult res;
string name = c.Basename;
return AdditionResult.Success;
}
- public AdditionResult AddStruct (Struct s)
+ public AdditionResult AddStruct (TypeContainer s)
{
AdditionResult res;
string name = s.Basename;
return AdditionResult.Success;
}
- public AdditionResult AddInterface (Interface iface)
+ public AdditionResult AddInterface (TypeContainer iface)
{
AdditionResult res;
string name = iface.Basename;
iterators.Add (i);
}
+ public void AddType (TypeContainer tc)
+ {
+ types.Add (tc);
+ }
+
+ public void AddPart (ClassPart part)
+ {
+ if (parts == null)
+ parts = new ArrayList ();
+
+ parts.Add (part);
+ }
+
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
if (a.Type == TypeManager.default_member_type) {
}
}
- public void RegisterOrder (Interface iface)
- {
- if (interface_order == null)
- interface_order = new ArrayList ();
-
- interface_order.Add (iface);
- }
-
public ArrayList Types {
get {
return types;
}
}
+ public ArrayList Parts {
+ get {
+ return parts;
+ }
+ }
+
public virtual TypeAttributes TypeAttr {
get {
return Modifiers.TypeAttr (ModFlags, this);
}
/// <remarks>
- /// The pending methods that need to be implemented (interfaces or abstract methods)
+ /// The pending methods that need to be implemented
+ // (interfaces or abstract methods)
/// </remarks>
public PendingImplementation Pending;
+ public abstract void Register ();
+
+ public abstract PendingImplementation GetPendingImplementations ();
+
+ TypeExpr[] GetPartialBases (out TypeExpr parent, out bool error)
+ {
+ ArrayList ifaces = new ArrayList ();
+
+ parent = null;
+ Location parent_loc = Location.Null;
+
+ foreach (ClassPart part in parts) {
+ TypeExpr new_parent;
+ TypeExpr[] new_ifaces;
+
+ new_ifaces = part.GetClassBases (out new_parent, out error);
+ if (error)
+ return null;
+
+ if ((parent != null) && (new_parent != null) &&
+ !parent.Equals (new_parent)) {
+ Report.Error (263, part.Location,
+ "Partial declarations of `{0}' must " +
+ "not specify different base classes",
+ Name);
+
+ if (!Location.IsNull (parent_loc))
+ Report.LocationOfPreviousError (parent_loc);
+
+ error = true;
+ return null;
+ }
+
+ if ((parent == null) && (new_parent != null)) {
+ parent = new_parent;
+ parent_loc = part.Location;
+ }
+
+ if (new_ifaces == null)
+ continue;
+
+ foreach (TypeExpr iface in new_ifaces) {
+ bool found = false;
+ foreach (TypeExpr old_iface in ifaces) {
+ if (old_iface.Equals (iface)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ ifaces.Add (iface);
+ }
+ }
+
+ error = false;
+
+ TypeExpr[] retval = new TypeExpr [ifaces.Count];
+ ifaces.CopyTo (retval, 0);
+ return retval;
+ }
+
+ TypeExpr[] GetNormalBases (out TypeExpr parent, out bool error)
+ {
+ parent = null;
+
+ int count = Bases.Count;
+ int start, i, j;
+
+ if (Kind == Kind.Class){
+ TypeExpr name = ResolveTypeExpr (
+ (Expression) Bases [0], false, Location);
+
+ if (name == null){
+ error = true;
+ return null;
+ }
+
+ if (name.IsClass){
+ parent = name;
+ start = 1;
+ } else {
+ start = 0;
+ }
+ } else {
+ start = 0;
+ }
+
+ TypeExpr [] ifaces = new TypeExpr [count-start];
+
+ for (i = start, j = 0; i < count; i++, j++){
+ Expression name = (Expression) Bases [i];
+ TypeExpr resolved = ResolveTypeExpr (name, false, Location);
+ if (resolved == null) {
+ error = true;
+ return null;
+ }
+
+ ifaces [j] = resolved;
+ }
+
+ error = false;
+ return ifaces;
+ }
+
/// <summary>
/// This function computes the Base class and also the
/// list of interfaces that the class or struct @c implements.
/// The @parent argument is set to the parent object or null
/// if this is `System.Object'.
/// </summary>
- TypeExpr [] GetClassBases (bool is_class, bool is_iface, out bool error)
+ TypeExpr [] GetClassBases (out TypeExpr parent, out bool error)
{
ArrayList bases = Bases;
- int count;
int start, j, i;
error = false;
- if (is_class || is_iface)
- parent_type = null;
+ if (Kind == Kind.Struct)
+ parent = TypeManager.system_valuetype_expr;
else
- parent_type = TypeManager.system_valuetype_expr;
+ parent = null;
+
+ TypeExpr[] ifaces;
+ TypeExpr new_parent;
- if (bases == null){
- if (is_class){
+ if (parts != null)
+ ifaces = GetPartialBases (out new_parent, out error);
+ else if (Bases == null){
+ if (Kind == Kind.Class){
if (RootContext.StdLib)
- parent_type = TypeManager.system_object_expr;
+ parent = TypeManager.system_object_expr;
else if (Name != "System.Object")
- parent_type = TypeManager.system_object_expr;
+ parent = TypeManager.system_object_expr;
} else {
//
// If we are compiling our runtime,
// parent is `System.Object'.
//
if (!RootContext.StdLib && Name == "System.ValueType")
- parent_type = TypeManager.system_object_expr;
+ parent = TypeManager.system_object_expr;
}
return null;
- }
+ } else
+ ifaces = GetNormalBases (out new_parent, out error);
+
+ if (error)
+ return null;
//
// Bases should be null if there are no bases at all
//
- count = bases.Count;
-
- if (is_class){
- TypeExpr name = ResolveTypeExpr ((Expression) bases [0], false, Location);
-
- if (name == null){
- error = true;
- return null;
- }
+ if (Kind == Kind.Class){
+ if (new_parent != null)
+ parent = new_parent;
+ else
+ parent = TypeManager.system_object_expr;
- if (name is TypeParameterExpr){
+ if (parent is TypeParameterExpr){
Report.Error (
- 689, name.Location,
+ 689, parent.Location,
"Type parameter `{0}' can not be used as a " +
- "base class or interface", name.Name);
+ "base class or interface", parent.Name);
error = true;
return null;
}
- if (IsGeneric && name.IsAttribute){
+ if (IsGeneric && parent.IsAttribute){
Report.Error (
- 698, name.Location,
+ 698, parent.Location,
"A generic type cannot derive from `{0}' " +
- "because it is an attribute class", name.Name);
+ "because it is an attribute class",
+ parent.Name);
error = true;
return null;
}
- if (name.IsClass){
- parent_type = name;
- start = 1;
- } else {
- parent_type = TypeManager.system_object_expr;
- start = 0;
- }
- if (name.IsSealed){
+ if (parent.IsSealed){
string detail = "";
-
- if (name.IsValueType)
+
+ if (parent.IsValueType)
detail = " (a class can not inherit from a struct/enum)";
Report.Error (509, "class `"+ Name +
"': Cannot inherit from sealed class `"+
- name.Name + "'" + detail);
+ parent.Name + "'" + detail);
error = true;
return null;
}
- if (!parent_type.CanInheritFrom ()){
+ if (!parent.CanInheritFrom ()){
Report.Error (644, Location,
"`{0}' cannot inherit from special class `{1}'",
Name, parent_type.Name);
return null;
}
- if (!parent_type.AsAccessible (this, ModFlags))
+ if (!parent.AsAccessible (this, ModFlags))
Report.Error (60, Location,
"Inconsistent accessibility: base class `" +
- name.Name + "' is less accessible than class `" +
+ parent.Name + "' is less accessible than class `" +
Name + "'");
-
- } else {
- start = 0;
}
- if (parent_type != null)
- base_class_name = parent_type.Name;
+ if (parent != null)
+ base_class_name = parent.Name;
- TypeExpr [] ifaces = new TypeExpr [count-start];
+ if (ifaces == null)
+ return null;
- for (i = start, j = 0; i < count; i++, j++){
- Expression name = (Expression) bases [i];
- TypeExpr resolved = ResolveTypeExpr (name, false, Location);
+ int count = ifaces != null ? ifaces.Length : 0;
- if (resolved == null)
- return null;
-
- bases [i] = resolved;
+ for (i = 0; i < count; i++) {
+ TypeExpr iface = (TypeExpr) ifaces [i];
- if (is_class == false && !resolved.IsInterface){
- Report.Error (527, "In Struct `" + Name + "', type `"+
- name +"' is not an interface");
+ if ((Kind != Kind.Class) && !iface.IsInterface){
+ string what = Kind == Kind.Struct ?
+ "Struct" : "Interface";
+
+ Report.Error (527, Location,
+ "In {0} `{1}', type `{2}' is not "+
+ "an interface", what, Name, iface.Name);
error = true;
return null;
}
-
- if (resolved.IsClass) {
- if (parent_type != null){
- Report.Error (527, "In Class `" + Name + "', type `"+
- name+"' is not an interface");
+
+ if (iface.IsClass) {
+ if (parent != null){
+ Report.Error (527, Location,
+ "In Class `{0}', `{1}' is not " +
+ "an interface", Name, iface.Name);
error = true;
return null;
}
}
-
- for (int x = 0; x < j; x++) {
- if (resolved.Equals (ifaces [x])) {
- Report.Error (528, "`" + name + "' is already listed in interface list");
+
+ for (int x = 0; x < i; x++) {
+ if (iface.Equals (ifaces [x])) {
+ Report.Error (528, Location,
+ "`{0}' is already listed in " +
+ "interface list", iface.Name);
error = true;
return null;
}
}
- if (is_iface &&
- !resolved.AsAccessible (Parent, ModFlags))
+ if ((Kind == Kind.Interface) &&
+ !iface.AsAccessible (Parent, ModFlags))
Report.Error (61, Location,
- "Inconsistent accessibility: base interface `" +
- name + "' is less accessible than interface `" +
- Name + "'");
-
- ifaces [j] = resolved;
+ "Inconsistent accessibility: base " +
+ "interface `{0}' is less accessible " +
+ "than interface `{1}'", iface.Name,
+ Name);
}
return TypeManager.ExpandInterfaces (ifaces);
public override TypeBuilder DefineType ()
{
TypeExpr parent;
- bool is_class, is_iface;
if (TypeBuilder != null)
return TypeBuilder;
InTransit = true;
- if (this is Interface) {
- is_iface = true;
- is_class = false;
- } else {
- is_iface = false;
- if (this is Class)
- is_class = true;
- else
- is_class = false;
- }
-
ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
- ifaces = GetClassBases (is_class, is_iface, out error);
+ ifaces = GetClassBases (out parent_type, out error);
if (error)
return null;
}
}
- if (!is_class && TypeManager.value_type == null)
+ if ((Kind == Kind.Struct) && TypeManager.value_type == null)
throw new Exception ();
TypeAttributes type_attributes = TypeAttr;
// be specified.
//
- if (!is_class && !is_iface && !have_nonstatic_fields){
+ if ((Kind == Kind.Struct) && !have_nonstatic_fields){
TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
FieldAttributes.Private);
}
} else if (!(this is Iterator))
RootContext.RegisterOrder (this);
- if (!DoDefineType ()) {
+ if (!DefineNestedTypes ()) {
error = true;
return null;
}
- if (Interfaces != null) {
- foreach (Interface iface in Interfaces)
- if (iface.DefineType () == null) {
- error = true;
- return null;
+ InTransit = false;
+ return TypeBuilder;
}
+
+ protected virtual bool DefineNestedTypes ()
+ {
+ if (Interfaces != null) {
+ foreach (TypeContainer iface in Interfaces)
+ if (iface.DefineType () == null)
+ return false;
}
if (Types != null) {
foreach (TypeContainer tc in Types)
- if (tc.DefineType () == null) {
- error = true;
- return null;
- }
+ if (tc.DefineType () == null)
+ return false;
}
if (Delegates != null) {
foreach (Delegate d in Delegates)
- if (d.DefineType () == null) {
- error = true;
- return null;
- }
+ if (d.DefineType () == null)
+ return false;
}
if (Enums != null) {
foreach (Enum en in Enums)
- if (en.DefineType () == null) {
- error = true;
- return null;
- }
+ if (en.DefineType () == null)
+ return false;
}
- InTransit = false;
- return TypeBuilder;
+ if (Parts != null) {
+ foreach (ClassPart part in Parts) {
+ part.TypeBuilder = TypeBuilder;
+ part.parent_type = parent_type;
+ }
}
- protected virtual bool DoDefineType ()
- {
return true;
}
} else if (mc is MethodCore)
((MethodCore) mc).OverridesSomething = true;
- if (!mc.Define (this)){
+ if (!mc.Define ()){
remove_list.Add (mc);
continue;
}
foreach (Indexer i in Indexers) {
string name;
- i.Define (this);
+ i.Define ();
name = i.IndexerName;
parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
#endif
- if (interface_order != null){
- foreach (Interface iface in interface_order)
- if ((iface.ModFlags & Modifiers.NEW) == 0)
- iface.DefineMembers (this);
- else
- Error_KeywordNotAllowed (iface.Location);
- }
-
if (RootContext.WarningLevel > 1){
Type ptype;
if (fields != null)
DefineMembers (fields, defined_names);
- if (this is Class){
+ if ((Kind == Kind.Class) && !(this is ClassPart)){
if (instance_constructors == null){
if (default_constructor == null)
DefineDefaultConstructor (false);
DefineDefaultConstructor (true);
}
- if (this is Struct){
+ if (Kind == Kind.Struct){
//
// Structs can not have initialized instance
// fields
ReportStructInitializedInstanceError ();
}
- if (!(this is Interface))
- Pending = PendingImplementation.GetPendingImplementations (this);
+ Pending = GetPendingImplementations ();
+
+ if (parts != null) {
+ foreach (ClassPart part in parts) {
+ if (!part.DefineMembers (this))
+ return false;
+ }
+ }
//
// Constructors are not in the defined_names array
DefineMembers (instance_constructors, null);
if (default_static_constructor != null)
- default_static_constructor.Define (this);
-
+ default_static_constructor.Define ();
+
if (methods != null)
DefineMembers (methods, defined_names);
#if CACHE
+ if (!(this is ClassPart))
member_cache = new MemberCache (this);
#endif
+ if (parts != null) {
+ foreach (ClassPart part in parts)
+ part.member_cache = member_cache;
+ }
+
if (iterators != null) {
foreach (Iterator iterator in iterators) {
if (iterator.DefineType () == null)
return true;
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
- if (interface_order != null){
- foreach (Interface iface in interface_order)
- if ((iface.ModFlags & Modifiers.NEW) == 0)
- iface.Define (this);
+ if (parts != null) {
+ foreach (ClassPart part in parts) {
+ if (!part.Define ())
+ return false;
+ }
}
return true;
if (interfaces != null) {
int len = interfaces.Count;
for (int i = 0; i < len; i++) {
- Interface iface = (Interface) interfaces [i];
+ TypeContainer iface = (TypeContainer) interfaces [i];
if ((iface.ModFlags & modflags) == 0)
continue;
{
if (constants != null)
foreach (Const con in constants)
- con.Emit (this);
+ con.Emit ();
return;
}
/// Emits the code, this step is performed after all
/// the types, enumerations, constructors
/// </summary>
- public void Emit ()
+ public void EmitType ()
{
if (OptAttributes != null)
OptAttributes.Emit (ec, this);
- Emit (this);
+ Emit ();
if (instance_constructors != null) {
if (TypeBuilder.IsSubclassOf (TypeManager.attribute_type) && IsClsCompliaceRequired (this)) {
bool has_compliant_args = false;
foreach (Constructor c in instance_constructors) {
- c.Emit (this);
+ c.Emit ();
if (has_compliant_args)
continue;
Report.Error_T (3015, Location, GetSignatureForError ());
} else {
foreach (Constructor c in instance_constructors)
- c.Emit (this);
+ c.Emit ();
}
}
if (default_static_constructor != null)
- default_static_constructor.Emit (this);
+ default_static_constructor.Emit ();
if (methods != null)
foreach (Method m in methods)
- m.Emit (this);
+ m.Emit ();
if (operators != null)
foreach (Operator o in operators)
- o.Emit (this);
+ o.Emit ();
if (properties != null)
foreach (Property p in properties)
- p.Emit (this);
+ p.Emit ();
if (indexers != null){
foreach (Indexer ix in indexers)
- ix.Emit (this);
+ ix.Emit ();
if (IndexerName != null) {
CustomAttributeBuilder cb = EmitDefaultMemberAttr ();
TypeBuilder.SetCustomAttribute (cb);
if (fields != null)
foreach (Field f in fields)
- f.Emit (this);
+ f.Emit ();
if (events != null){
foreach (Event e in Events)
- e.Emit (this);
+ e.Emit ();
}
if (delegates != null) {
foreach (Delegate d in Delegates) {
- d.Emit (this);
+ d.Emit ();
}
}
if (enums != null) {
foreach (Enum e in enums) {
- e.Emit (this);
+ e.Emit ();
}
}
- if (Pending != null)
+ if (parts != null) {
+ foreach (ClassPart part in parts)
+ part.EmitType ();
+ }
+
+ if ((Pending != null) && !(this is ClassPart))
if (Pending.VerifyPendingMethods ())
return;
if (iterators != null)
foreach (Iterator iterator in iterators)
- iterator.Emit ();
+ iterator.EmitType ();
// if (types != null)
// foreach (TypeContainer tc in types)
foreach (Enum en in Enums)
en.CloseType ();
- if (interface_order != null){
- foreach (Interface iface in interface_order)
- iface.CloseType ();
- }
-
if (Types != null){
foreach (TypeContainer tc in Types)
- if (tc is Struct)
+ if (tc.Kind == Kind.Struct)
tc.CloseType ();
foreach (TypeContainer tc in Types)
- if (!(tc is Struct))
+ if (tc.Kind != Kind.Struct)
tc.CloseType ();
}
initialized_static_fields = null;
constants = null;
interfaces = null;
- interface_order = null;
methods = null;
events = null;
indexers = null;
}
}
- if (this is Struct){
+ if (Kind == Kind.Struct){
if ((flags & va) != 0){
Modifiers.Error_InvalidModifier (loc, "virtual or abstract");
ok = false;
/// checks whether the `interface_type' is a base inteface implementation.
/// Then it checks whether `name' exists in the interface type.
/// </summary>
- public bool VerifyImplements (Type interface_type, string full, string name, Location loc)
+ public virtual bool VerifyImplements (Type interface_type, string full,
+ string name, Location loc)
{
bool found = false;
bool IMemberContainer.IsInterface {
get {
- return this is Interface;
+ return Kind == Kind.Interface;
}
}
}
- public class ClassOrStruct : TypeContainer {
+ public class PartialContainer : TypeContainer {
+
+ public readonly Namespace Namespace;
+ public readonly int OriginalModFlags;
+ public readonly int AllowedModifiers;
+ public readonly TypeAttributes DefaultTypeAttributes;
+
+ static PartialContainer Create (NamespaceEntry ns, TypeContainer parent,
+ MemberName name, int mod_flags, Kind kind,
+ Location loc)
+ {
+ PartialContainer pc;
+ DeclSpace ds = (DeclSpace) RootContext.Tree.Decls [name];
+ if (ds != null) {
+ pc = ds as PartialContainer;
+
+ if (pc == null) {
+ Report.Error (
+ 260, ds.Location, "Missing partial modifier " +
+ "on declaration of type `{0}'; another " +
+ "partial implementation of this type exists",
+ name);
+
+ Report.LocationOfPreviousError (loc);
+ return null;
+ }
+
+ if (pc.Kind != kind) {
+ Report.Error (
+ 261, loc, "Partial declarations of `{0}' " +
+ "must be all classes, all structs or " +
+ "all interfaces", name);
+ return null;
+ }
+
+ if (pc.OriginalModFlags != mod_flags) {
+ Report.Error (
+ 262, loc, "Partial declarations of `{0}' " +
+ "have conflicting accessibility modifiers",
+ name);
+ return null;
+ }
+
+ return pc;
+ }
+
+ pc = new PartialContainer (ns, parent, name, mod_flags, kind, loc);
+ RootContext.Tree.RecordDecl (name.GetName (true), pc);
+ parent.AddType (pc);
+ pc.Register ();
+ return pc;
+ }
+
+ 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);
+ if (pc == null) {
+ // An error occured; create a dummy container, but don't
+ // register it.
+ pc = new PartialContainer (ns, parent, name, mod, kind, loc);
+ }
+
+ ClassPart part = new ClassPart (ns, pc, mod, attrs, kind, loc);
+ pc.AddPart (part);
+ return part;
+ }
+
+ protected PartialContainer (NamespaceEntry ns, TypeContainer parent,
+ MemberName name, int mod, Kind kind, Location l)
+ : base (ns, parent, name, null, kind, l)
+ {
+ this.Namespace = ns.NS;
+
+ switch (kind) {
+ case Kind.Class:
+ AllowedModifiers = Class.AllowedModifiers;
+ DefaultTypeAttributes = Class.DefaultTypeAttributes;
+ break;
+
+ case Kind.Struct:
+ AllowedModifiers = Struct.AllowedModifiers;
+ DefaultTypeAttributes = Struct.DefaultTypeAttributes;
+ break;
+
+ case Kind.Interface:
+ AllowedModifiers = Interface.AllowedModifiers;
+ DefaultTypeAttributes = Interface.DefaultTypeAttributes;
+ break;
+
+ default:
+ throw new InvalidOperationException ();
+ }
+
+ int accmods;
+ if (parent.Parent == null)
+ accmods = Modifiers.INTERNAL;
+ else
+ accmods = Modifiers.PRIVATE;
+
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ this.OriginalModFlags = mod;
+ }
+
+ public override void Register ()
+ {
+ if (Kind == Kind.Interface)
+ Parent.AddInterface (this);
+ else if (Kind == Kind.Class)
+ Parent.AddClass (this);
+ else if (Kind == Kind.Struct)
+ Parent.AddStruct (this);
+ else
+ throw new InvalidOperationException ();
+ }
+
+ public override PendingImplementation GetPendingImplementations ()
+ {
+ return PendingImplementation.GetPendingImplementations (this);
+ }
+
+ public ClassPart AddPart (NamespaceEntry ns, int mod, Attributes attrs,
+ Location l)
+ {
+ ClassPart part = new ClassPart (ns, this, mod, attrs, Kind, l);
+ AddPart (part);
+ return part;
+ }
+
+ public override TypeAttributes TypeAttr {
+ get {
+ return base.TypeAttr | DefaultTypeAttributes;
+ }
+ }
+ }
+
+ public class ClassPart : TypeContainer {
+ public readonly PartialContainer PartialContainer;
+ public readonly bool IsPartial;
+
+ public ClassPart (NamespaceEntry ns, PartialContainer parent,
+ int mod, Attributes attrs, Kind kind, Location l)
+ : base (ns, parent.Parent, parent.MemberName, attrs, kind, l)
+ {
+ this.PartialContainer = parent;
+ this.IsPartial = true;
+
+ int accmods;
+ if (parent.Parent == null)
+ accmods = Modifiers.INTERNAL;
+ else
+ accmods = Modifiers.PRIVATE;
+
+ this.ModFlags = Modifiers.Check (
+ parent.AllowedModifiers, mod, accmods, l);
+ }
+
+ public override void Register ()
+ {
+ }
+
+ public override PendingImplementation GetPendingImplementations ()
+ {
+ return PartialContainer.Pending;
+ }
+
+ public override bool VerifyImplements (Type interface_type, string full,
+ string name, Location loc)
+ {
+ return PartialContainer.VerifyImplements (
+ interface_type, full, name, loc);
+ }
+ }
+
+ public abstract class ClassOrStruct : TypeContainer {
bool hasExplicitLayout = false;
- public ClassOrStruct (NamespaceEntry ns, TypeContainer parent, MemberName name,
- Attributes attrs, Location l)
- : base (ns, parent, name, attrs, l)
+
+ public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
+ MemberName name, Attributes attrs, Kind kind,
+ Location l)
+ : base (ns, parent, name, attrs, kind, l)
{
}
+ public override PendingImplementation GetPendingImplementations ()
+ {
+ return PendingImplementation.GetPendingImplementations (this);
+ }
+
protected override void VerifyMembers (EmitContext ec)
{
if (Fields != null) {
public Class (NamespaceEntry ns, TypeContainer parent, MemberName name,
int mod, Attributes attrs, Location l)
- : base (ns, parent, name, attrs, l)
+ : base (ns, parent, name, attrs, Kind.Class, l)
{
int accmods;
}
}
+ public override void Register ()
+ {
+ CheckDef (Parent.AddClass (this), Name, Location);
+ }
+
+ public const TypeAttributes DefaultTypeAttributes =
+ TypeAttributes.AutoLayout | TypeAttributes.Class;
+
//
// FIXME: How do we deal with the user specifying a different
// layout?
//
public override TypeAttributes TypeAttr {
get {
- return base.TypeAttr | TypeAttributes.AutoLayout | TypeAttributes.Class;
+ return base.TypeAttr | DefaultTypeAttributes;
}
}
}
public Struct (NamespaceEntry ns, TypeContainer parent, MemberName name,
int mod, Attributes attrs, Location l)
- : base (ns, parent, name, attrs, l)
+ : base (ns, parent, name, attrs, Kind.Struct, l)
{
int accmods;
}
}
+ public override void Register ()
+ {
+ CheckDef (Parent.AddStruct (this), Name, Location);
+ }
+
+ public const TypeAttributes DefaultTypeAttributes =
+ TypeAttributes.SequentialLayout |
+ TypeAttributes.Sealed |
+ TypeAttributes.BeforeFieldInit;
//
// FIXME: Allow the user to specify a different set of attributes
//
public override TypeAttributes TypeAttr {
get {
- return base.TypeAttr |
- TypeAttributes.SequentialLayout |
- TypeAttributes.Sealed |
- TypeAttributes.BeforeFieldInit;
+ return base.TypeAttr | DefaultTypeAttributes;
}
}
}
public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name,
int mod, Attributes attrs, Location l)
- : base (ns, parent, name, attrs, l)
+ : base (ns, parent, name, attrs, Kind.Interface, l)
{
int accmods;
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
}
+ public override void Register ()
+ {
+ CheckDef (Parent.AddInterface (this), Name, Location);
+ }
+
+ public override PendingImplementation GetPendingImplementations ()
+ {
+ return null;
+ }
+
public override AttributeTargets AttributeTargets {
get {
return AttributeTargets.Interface;
}
}
- public override TypeAttributes TypeAttr {
- get {
- return base.TypeAttr |
+ public const TypeAttributes DefaultTypeAttributes =
TypeAttributes.AutoLayout |
TypeAttributes.Abstract |
TypeAttributes.Interface;
+
+ public override TypeAttributes TypeAttr {
+ get {
+ return base.TypeAttr | DefaultTypeAttributes;
}
}
}
public abstract class MethodCore : MemberBase {
public readonly Parameters Parameters;
public readonly GenericMethod GenericMethod;
+ public readonly DeclSpace ds;
protected Block block;
- public DeclSpace ds;
//
// Parameters, cached for semantic analysis.
static string[] attribute_targets = new string [] { "method", "return" };
- public MethodCore (DeclSpace ds, Expression type, int mod, int allowed_mod,
- bool is_interface, MemberName name, Attributes attrs,
- Parameters parameters, Location loc)
- : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
+ 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, type, mod, allowed_mod, Modifiers.PRIVATE, name,
+ attrs, loc)
{
Parameters = parameters;
- IsInterface = is_interface;
- this.ds = ds;
- this.GenericMethod = ds as GenericMethod;
+ IsInterface = is_iface;
+ this.GenericMethod = generic;
+
+ if (generic != null)
+ ds = generic;
+ else
+ ds = parent;
}
//
{
// Check if arguments were correct
parameter_types = Parameters.GetParameterInfo (ds);
- if ((parameter_types == null) || !CheckParameters (ds, parameter_types))
+ if ((parameter_types == null) ||
+ !CheckParameters (ds, parameter_types))
return false;
parameter_info = new InternalParameters (ds, Parameters);
//
// return_type can be "null" for VOID values.
//
- public Method (DeclSpace ds, Expression return_type, int mod, bool is_iface,
+ public Method (TypeContainer parent, GenericMethod generic,
+ Expression return_type, int mod, bool is_iface,
MemberName name, Parameters parameters, Attributes attrs,
Location l)
- : base (ds, return_type, mod,
+ : base (parent, generic, return_type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, attrs, parameters, l)
{
//
// Checks our base implementation if any
//
- protected override bool CheckBase (TypeContainer container)
+ protected override bool CheckBase ()
{
- base.CheckBase (container);
+ base.CheckBase ();
// Check whether arguments were correct.
if (!DoDefineParameters ())
//
// Check in our class for dups
//
- ArrayList ar = container.Methods;
+ ArrayList ar = Parent.Methods;
if (ar != null) {
int arLen = ar.Count;
for (int i = 0; i < arLen; i++) {
Method m = (Method) ar [i];
- if (IsDuplicateImplementation (container, m))
+ if (IsDuplicateImplementation (Parent, m))
return false;
}
}
// Verify if the parent has a type with the same name, and then
// check whether we have to create a new slot for it or not.
//
- Type ptype = container.TypeBuilder.BaseType;
+ Type ptype = Parent.TypeBuilder.BaseType;
// ptype is only null for System.Object while compiling corlib.
if (ptype != null) {
// an incorrect warning in corlib.
//
if (! IsExplicitImpl) {
- parent_method = (MethodInfo)((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
- container.TypeBuilder, Name, ParameterTypes, false);
+ parent_method = (MethodInfo)((IMemberContainer)Parent).Parent.MemberCache.FindMemberToOverride (
+ Parent.TypeBuilder, Name, ParameterTypes, false);
}
if (parent_method != null) {
string name = parent_method.DeclaringType.Name + "." +
parent_method.Name;
- if (!CheckMethodAgainstBase (container, flags, parent_method, name))
+ if (!CheckMethodAgainstBase (Parent, flags, parent_method, name))
return false;
if ((ModFlags & Modifiers.NEW) == 0) {
if (!parent_ret.Equals (MemberType)) {
Report.Error (
- 508, Location, container.MakeName (Name) + ": cannot " +
+ 508, Location, Parent.MakeName (Name) + ": cannot " +
"change return type when overriding " +
"inherited member " + name);
return false;
ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (parent_method);
if (oa != null) {
Report.SymbolRelatedToPreviousError (parent_method);
- Report.Warning_T (672, Location, GetSignatureForError (container));
+ Report.Warning_T (672, Location, GetSignatureForError (Parent));
}
} else {
if (!OverridesSomething && ((ModFlags & Modifiers.NEW) != 0))
- WarningNotHiding (container);
+ WarningNotHiding (Parent);
if ((ModFlags & Modifiers.OVERRIDE) != 0){
Report.Error (115, Location,
- container.MakeName (Name) +
+ Parent.MakeName (Name) +
" no suitable methods found to override");
}
}
} else if ((ModFlags & Modifiers.NEW) != 0)
- WarningNotHiding (container);
+ WarningNotHiding (Parent);
return true;
}
//
// Creates the type
//
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
- if (!DoDefineBase (container))
+ if (!DoDefineBase ())
return false;
- DeclSpace decl;
MethodBuilder mb = null;
if (GenericMethod != null) {
- mb = container.TypeBuilder.DefineGenericMethod (Name, flags);
- if (!GenericMethod.Define (container, mb))
+ mb = Parent.TypeBuilder.DefineGenericMethod (Name, flags);
+ if (!GenericMethod.Define (mb))
return false;
- decl = GenericMethod;
- } else
- decl = container;
+ }
- if (!DoDefine (decl, container))
+ if (!DoDefine (ds))
return false;
- if (!CheckBase (container))
+ if (!CheckBase ())
return false;
MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
this, mb, GenericMethod);
- if (!MethodData.Define (container))
+ if (!MethodData.Define (Parent))
return false;
//
//
if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
Iterator iterator = new Iterator (
- container, Name, MemberType, ParameterTypes,
+ Parent, Name, MemberType, ParameterTypes,
ParameterInfo, ModFlags, block, Location);
- if (!iterator.Define ())
+ if (!iterator.DefineIterator ())
return false;
block = iterator.Block;
if (Name == "Main" &&
((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint &&
(RootContext.MainClass == null ||
- RootContext.MainClass == container.TypeBuilder.FullName)){
+ RootContext.MainClass == Parent.TypeBuilder.FullName)){
if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
if (RootContext.EntryPoint == null) {
- if (container.IsGeneric){
+ if (Parent.IsGeneric){
Report.Error (-201, Location,
"Entry point can not be defined in a generic class");
}
//
// Emits the code
//
- public override void Emit (TypeContainer container)
+ public override void Emit ()
{
- MethodData.Emit (container, this);
- base.Emit (container);
+ MethodData.Emit (Parent, this);
+ base.Emit ();
Block = null;
MethodData = null;
}
public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
{
- return new EmitContext (tc, ds, Location, ig, ReturnType, ModFlags, false);
+ return new EmitContext (
+ tc, ds, Location, ig, ReturnType, ModFlags, false);
}
public ObsoleteAttribute GetObsoleteAttribute ()
// The spec claims that static is not permitted, but
// my very own code has static constructors.
//
- public Constructor (DeclSpace ds, string name, int mod, Parameters args,
+ public Constructor (TypeContainer ds, string name, int mod, Parameters args,
ConstructorInitializer init, Location l)
- : base (ds, null, mod, AllowedModifiers, false,
+ : base (ds, null, null, mod, AllowedModifiers, false,
new MemberName (name), null, args, l)
{
Initializer = init;
ConstructorBuilder.SetCustomAttribute (cb);
}
- protected override bool CheckBase (TypeContainer container)
+ protected override bool CheckBase ()
{
- base.CheckBase (container);
+ base.CheckBase ();
// Check whether arguments were correct.
if (!DoDefineParameters ())
if ((ModFlags & Modifiers.STATIC) != 0)
return true;
- if (container is Struct && ParameterTypes.Length == 0) {
+ if (Parent.Kind == Kind.Struct && ParameterTypes.Length == 0) {
Report.Error (568, Location,
"Structs can not contain explicit parameterless " +
"constructors");
//
// Check in our class for dups
//
- ArrayList ar = container.InstanceConstructors;
+ ArrayList ar = Parent.InstanceConstructors;
if (ar != null) {
int arLen = ar.Count;
for (int i = 0; i < arLen; i++) {
Constructor m = (Constructor) ar [i];
- if (IsDuplicateImplementation (container, m))
+ if (IsDuplicateImplementation (Parent, m))
return false;
}
}
//
// Creates the ConstructorBuilder
//
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
MethodAttributes ca = (MethodAttributes.RTSpecialName |
MethodAttributes.SpecialName);
}
// Check if arguments were correct.
- if (!CheckBase (container))
+ if (!CheckBase ())
return false;
- ConstructorBuilder = container.TypeBuilder.DefineConstructor (
- ca, GetCallingConvention (container is Class), ParameterTypes);
+ ConstructorBuilder = Parent.TypeBuilder.DefineConstructor (
+ ca, GetCallingConvention (Parent.Kind == Kind.Class),
+ ParameterTypes);
if ((ModFlags & Modifiers.UNSAFE) != 0)
ConstructorBuilder.InitLocals = false;
//
// Emits the code
//
- public override void Emit (TypeContainer container)
+ public override void Emit ()
{
ILGenerator ig = ConstructorBuilder.GetILGenerator ();
- EmitContext ec = new EmitContext (container, Location, ig, null, ModFlags, true);
+ EmitContext ec = new EmitContext (Parent, Location, ig, null, ModFlags, true);
//
// extern methods have no bodies
}
if ((ModFlags & Modifiers.STATIC) == 0){
- if (container is Class && Initializer == null)
+ if (Parent.Kind == Kind.Class && Initializer == null)
Initializer = new ConstructorBaseInitializer (
null, Parameters.EmptyReadOnlyParameters, Location);
!Location.IsNull (Location) &&
!Location.IsNull (block.EndLocation) &&
(Location.SymbolDocument != null)) {
- sw.OpenMethod (container, ConstructorBuilder, Location, block.EndLocation);
+ sw.OpenMethod (Parent, ConstructorBuilder, Location, block.EndLocation);
generate_debugging = true;
}
//
// Classes can have base initializers and instance field initializers.
//
- if (container is Class){
+ if (Parent.Kind == Kind.Class){
if ((ModFlags & Modifiers.STATIC) == 0){
//
// do not emit field initializers, they are initialized in the other constructor
//
if (!(Initializer != null && Initializer is ConstructorThisInitializer))
- container.EmitFieldInitializers (ec);
+ Parent.EmitFieldInitializers (ec);
}
}
if (Initializer != null) {
- Initializer.CheckObsoleteAttribute (container, Location);
+ Initializer.CheckObsoleteAttribute (Parent, Location);
Initializer.Emit (ec);
}
if ((ModFlags & Modifiers.STATIC) != 0)
- container.EmitFieldInitializers (ec);
+ Parent.EmitFieldInitializers (ec);
if (OptAttributes != null)
OptAttributes.Emit (ec, this);
// If this is a non-static `struct' constructor and doesn't have any
// initializer, it must initialize all of the struct's fields.
- if ((container is Struct) && ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
- Block.AddThisVariable (container, Location);
+ if ((Parent.Kind == Kind.Struct) &&
+ ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
+ Block.AddThisVariable (Parent, Location);
ec.EmitTopBlock (block, ParameterInfo, Location);
if (generate_debugging)
sw.CloseMethod ();
- base.Emit (container);
+ base.Emit ();
block = null;
}
public class Destructor : Method {
- public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
+ public Destructor (TypeContainer ds, Expression return_type, int mod, string name,
Parameters parameters, Attributes attrs, Location l)
- : base (ds, return_type, mod, false, new MemberName (name),
+ : base (ds, null, return_type, mod, false, new MemberName (name),
parameters, attrs, l)
{ }
//
// The constructor is only exposed to our children
//
- protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod,
- MemberName name, Attributes attrs, Location loc)
- : base (name, attrs, loc)
+ protected MemberBase (TypeContainer parent, Expression type, int mod,
+ int allowed_mod, int def_mod, MemberName name,
+ Attributes attrs, Location loc)
+ : base (parent, name, attrs, loc)
{
explicit_mod_flags = mod;
Type = type;
ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
}
- protected virtual bool CheckBase (TypeContainer container)
+ protected virtual bool CheckBase ()
{
- if ((container is Struct) || (RootContext.WarningLevel > 3)){
- if ((ModFlags & Modifiers.PROTECTED) != 0 && (container.ModFlags & Modifiers.SEALED) != 0){
- if (container is Struct){
+ if ((Parent.Kind == Kind.Struct) || (RootContext.WarningLevel > 3)){
+ if ((ModFlags & Modifiers.PROTECTED) != 0 && (Parent.ModFlags & Modifiers.SEALED) != 0){
+ if (Parent.Kind == Kind.Struct){
Report.Error (666, Location, "Protected member in struct declaration");
return false;
} else
- Report.Warning (628, Location, "Member " + container.MakeName (Name) + " protected in sealed class");
+ Report.Warning (628, Location, "Member " + Parent.MakeName (Name) + " protected in sealed class");
}
}
return true;
return !error;
}
- protected virtual bool DoDefineBase (TypeContainer container)
+ protected virtual bool DoDefineBase ()
{
if (Name == null)
Name = "this";
MethodAttributes.NewSlot |
MethodAttributes.Virtual;
} else {
- if (!container.MethodModifiersValid (ModFlags, Name, Location))
+ if (!Parent.MethodModifiersValid (ModFlags, Name, Location))
return false;
flags = Modifiers.MethodAttr (ModFlags);
return true;
}
- protected virtual bool DoDefine (DeclSpace decl, TypeContainer container)
+ protected virtual bool DoDefine (DeclSpace decl)
{
// Lookup Type, verify validity
MemberType = decl.ResolveType (Type, false, Location);
if (MemberType == null)
return false;
- if ((container.ModFlags & Modifiers.SEALED) != 0){
+ if ((Parent.ModFlags & Modifiers.SEALED) != 0){
if ((ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0){
Report.Error (549, Location, "Virtual method can not be contained in sealed class");
return false;
}
// verify accessibility
- if (!container.AsAccessible (MemberType, ModFlags)) {
+ if (!Parent.AsAccessible (MemberType, ModFlags)) {
if (this is Property)
Report.Error (53, Location,
"Inconsistent accessibility: property type `" +
return false;
}
- if (MemberType.IsPointer && !UnsafeOK (container))
+ if (MemberType.IsPointer && !UnsafeOK (Parent))
return false;
//
ShortName = Name;
if (ExplicitInterfaceName != null) {
- InterfaceType = container.ResolveType (
+ InterfaceType = Parent.ResolveType (
ExplicitInterfaceName, false, Location);
if (InterfaceType == null)
return false;
// Compute the full name that we need to export.
Name = InterfaceType.FullName + "." + ShortName;
- if (!container.VerifyImplements (InterfaceType, ShortName, Name, Location))
+ if (!Parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
return false;
Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
//
// The constructor is only exposed to our children
//
- protected FieldBase (Expression type, int mod, int allowed_mod, MemberName name,
- object init, Attributes attrs, Location loc)
- : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
+ protected FieldBase (TypeContainer parent, Expression type, int mod,
+ int allowed_mod, MemberName name, object init,
+ Attributes attrs, Location loc)
+ : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE,
+ name, attrs, loc)
{
this.init = init;
}
return init_expr;
}
- protected override bool DoDefine (DeclSpace ds, TypeContainer container)
+ protected override bool DoDefine (DeclSpace ds)
{
- if (!base.DoDefine (ds, container))
+ if (!base.DoDefine (ds))
return false;
if (MemberType == TypeManager.void_type) {
Modifiers.UNSAFE |
Modifiers.READONLY;
- public Field (Expression type, int mod, string name, Object expr_or_array_init,
- Attributes attrs, Location loc)
- : base (type, mod, AllowedModifiers, new MemberName (name),
+ 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)
{
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
- MemberType = container.ResolveType (Type, false, Location);
+ MemberType = Parent.ResolveType (Type, false, Location);
if (MemberType == null)
return false;
- CheckBase (container);
+ CheckBase ();
- if (!container.AsAccessible (MemberType, ModFlags)) {
+ if (!Parent.AsAccessible (MemberType, ModFlags)) {
Report.Error (52, Location,
"Inconsistent accessibility: field type `" +
TypeManager.CSharpName (MemberType) + "' is less " +
return false;
}
- if (MemberType.IsPointer && !UnsafeOK (container))
+ if (MemberType.IsPointer && !UnsafeOK (Parent))
return false;
if (RootContext.WarningLevel > 1){
- Type ptype = container.TypeBuilder.BaseType;
+ Type ptype = Parent.TypeBuilder.BaseType;
// ptype is only null for System.Object while compiling corlib.
if (ptype != null){
(vt == TypeManager.float_type) ||
(!vt.IsValueType))){
Report.Error (
- 677, Location, container.MakeName (Name) +
+ 677, Location, Parent.MakeName (Name) +
" A volatile field can not be of type `" +
TypeManager.CSharpName (vt) + "'");
return false;
FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
- if (container is Struct &&
+ if (Parent.Kind == Kind.Struct &&
((fa & FieldAttributes.Static) == 0) &&
- MemberType == container.TypeBuilder &&
+ MemberType == Parent.TypeBuilder &&
!TypeManager.IsBuiltinType (MemberType)){
- Report.Error (523, Location, "Struct member `" + container.Name + "." + Name +
+ Report.Error (523, Location, "Struct member `" + Parent.Name + "." + Name +
"' causes a cycle in the structure layout");
return false;
}
try {
- FieldBuilder = container.TypeBuilder.DefineField (
+ FieldBuilder = Parent.TypeBuilder.DefineField (
Name, MemberType, Modifiers.FieldAttr (ModFlags));
TypeManager.RegisterFieldBase (FieldBuilder, this);
return true;
}
- public override void Emit (TypeContainer tc)
+ public override void Emit ()
{
if (OptAttributes != null) {
- EmitContext ec = new EmitContext (tc, Location, null, FieldBuilder.FieldType, ModFlags);
+ EmitContext ec = new EmitContext (
+ Parent, Location, null, FieldBuilder.FieldType,
+ ModFlags);
OptAttributes.Emit (ec, this);
}
- base.Emit (tc);
+ base.Emit ();
}
}
}
}
- public override EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+ public override EmitContext CreateEmitContext (TypeContainer tc,
+ ILGenerator ig)
{
- return new EmitContext (tc, method.ds, method.Location, ig, ReturnType, method.ModFlags, false);
+ return new EmitContext (
+ tc, method.ds, method.Location, ig, ReturnType,
+ method.ModFlags, false);
}
public override ObsoleteAttribute GetObsoleteAttribute ()
protected EmitContext ec;
- public PropertyBase (DeclSpace ds, Expression type, int mod_flags,
+ public PropertyBase (TypeContainer parent, Expression type, int mod_flags,
int allowed_mod, bool is_iface, MemberName name,
Parameters parameters, Attributes attrs,
Location loc)
- : base (ds, type, mod_flags, allowed_mod, is_iface, name,
+ : base (parent, null, type, mod_flags, allowed_mod, is_iface, name,
attrs, parameters, loc)
{
}
}
}
- protected override bool DoDefine (DeclSpace decl, TypeContainer container)
+ protected override bool DoDefine (DeclSpace decl)
{
- if (!base.DoDefine (decl, container))
+ if (!base.DoDefine (decl))
return false;
if (MemberType == TypeManager.arg_iterator_type || MemberType == TypeManager.typed_reference_type) {
return false;
}
- ec = new EmitContext (container, Location, null, MemberType, ModFlags);
+ ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
return true;
}
//
// Checks our base implementation if any
//
- protected override bool CheckBase (TypeContainer container)
+ protected override bool CheckBase ()
{
- base.CheckBase (container);
+ base.CheckBase ();
// Check whether arguments were correct.
if (!DoDefineParameters ())
//
// Check in our class for dups
//
- ArrayList ar = container.Properties;
+ ArrayList ar = Parent.Properties;
if (ar != null) {
int arLen = ar.Count;
for (int i = 0; i < arLen; i++) {
Property m = (Property) ar [i];
- if (IsDuplicateImplementation (container, m))
+ if (IsDuplicateImplementation (Parent, m))
return false;
}
}
string name, base_name;
report_name = "this";
- name = TypeManager.IndexerPropertyName (container.TypeBuilder);
+ name = TypeManager.IndexerPropertyName (Parent.TypeBuilder);
ms = new MethodSignature (name, null, ParameterTypes);
- base_name = TypeManager.IndexerPropertyName (container.TypeBuilder.BaseType);
+ base_name = TypeManager.IndexerPropertyName (Parent.TypeBuilder.BaseType);
base_ms = new MethodSignature (base_name, null, ParameterTypes);
} else {
report_name = Name;
// Verify if the parent has a type with the same name, and then
// check whether we have to create a new slot for it or not.
//
- Type ptype = container.TypeBuilder.BaseType;
+ Type ptype = Parent.TypeBuilder.BaseType;
// ptype is only null for System.Object while compiling corlib.
if (ptype == null) {
if ((ModFlags & Modifiers.NEW) != 0)
- WarningNotHiding (container);
+ WarningNotHiding (Parent);
return true;
}
// an incorrect warning in corlib.
//
if (! IsExplicitImpl) {
- parent_member = ((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
- container.TypeBuilder, Name, ParameterTypes, true);
+ parent_member = ((IMemberContainer)Parent).Parent.MemberCache.FindMemberToOverride (
+ Parent.TypeBuilder, Name, ParameterTypes, true);
}
if (parent_member is PropertyInfo) {
else
throw new Exception ("Internal error!");
- if (!CheckMethodAgainstBase (container, flags, parent_method, name))
+ if (!CheckMethodAgainstBase (Parent, flags, parent_method, name))
return false;
if ((ModFlags & Modifiers.NEW) == 0) {
if (parent_type != MemberType) {
Report.Error (
- 508, Location, container.MakeName (Name) + ": cannot " +
+ 508, Location, Parent.MakeName (Name) + ": cannot " +
"change return type when overriding " +
"inherited member " + name);
return false;
}
} else if (parent_member == null){
if ((ModFlags & Modifiers.NEW) != 0)
- WarningNotHiding (container);
+ WarningNotHiding (Parent);
if ((ModFlags & Modifiers.OVERRIDE) != 0){
if (this is Indexer)
Report.Error (115, Location,
- container.MakeName (Name) +
+ Parent.MakeName (Name) +
" no suitable indexers found to override");
else
Report.Error (115, Location,
- container.MakeName (Name) +
+ Parent.MakeName (Name) +
" no suitable properties found to override");
return false;
}
return true;
}
- public override void Emit (TypeContainer tc)
+ public override void Emit ()
{
//
// The PropertyBuilder can be null for explicit implementations, in that
OptAttributes.Emit (ec, this);
if (Get != null)
- Get.Emit (tc);
+ Get.Emit (Parent);
if (Set != null)
- Set.Emit (tc);
+ Set.Emit (Parent);
- base.Emit (tc);
+ base.Emit ();
}
protected override string[] ValidAttributeTargets {
const int AllowedInterfaceModifiers =
Modifiers.NEW;
- public Property (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
- MemberName name, Attributes attrs, Accessor get_block,
- Accessor set_block, Location loc)
- : base (ds, type, mod_flags,
+ 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,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
loc)
Set = new SetMethod (this, set_block);
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
- if (!DoDefineBase (container))
+ if (!DoDefineBase ())
return false;
- if (!DoDefine (container, container))
+ if (!DoDefine (Parent))
return false;
- if (!CheckBase (container))
+ if (!CheckBase ())
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
if (Get != null) {
- GetBuilder = Get.Define (container);
+ GetBuilder = Get.Define (Parent);
if (GetBuilder == null)
return false;
//
if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
Iterator iterator = new Iterator (
- container, "get", MemberType,
+ Parent, "get", MemberType,
TypeManager.NoTypes, Get.ParameterInfo,
ModFlags, Get.Block, Location);
- if (!iterator.Define ())
+ if (!iterator.DefineIterator ())
return false;
Get.Block = iterator.Block;
}
}
if (Set != null) {
- SetBuilder = Set.Define (container);
+ SetBuilder = Set.Define (Parent);
if (SetBuilder == null)
return false;
PropertyAttributes.SpecialName;
if (!IsExplicitImpl){
- PropertyBuilder = container.TypeBuilder.DefineProperty (
+ PropertyBuilder = Parent.TypeBuilder.DefineProperty (
Name, prop_attr, MemberType, null);
if (Get != null)
if (!TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder)) {
Report.Error (
111, Location,
- "Class `" + container.Name +
+ "Class `" + Parent.Name +
"' already contains a definition for the property `" +
Name + "'");
return false;
static string[] attribute_targets = new string [] { "event", "property" };
- public EventProperty (DeclSpace ds, Expression type, int mod_flags,
+ 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 (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+ : base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
{
Add = new AddDelegateMethod (this, add);
Remove = new RemoveDelegateMethod (this, remove);
static string[] attribute_targets = new string [] { "event", "field", "method" };
- public EventField (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
- MemberName name, Object init, Attributes attrs, Location loc)
- : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+ 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)
{
Add = new AddDelegateMethod (this);
Remove = new RemoveDelegateMethod (this);
}
}
- public override EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+ public override EmitContext CreateEmitContext (TypeContainer tc,
+ ILGenerator ig)
{
- return new EmitContext (tc, method.ds, Location, ig, ReturnType, method.ModFlags, false);
+ return new EmitContext (
+ tc, method.Parent, Location, ig, ReturnType,
+ method.ModFlags, false);
}
public override string GetSignatureForError (TypeContainer tc)
public override ObsoleteAttribute GetObsoleteAttribute ()
{
- return method.GetObsoleteAttribute (method.ds);
+ return method.GetObsoleteAttribute (method.Parent);
}
protected override string[] ValidAttributeTargets {
protected DelegateMethod Add, Remove;
public MyEventBuilder EventBuilder;
public MethodBuilder AddBuilder, RemoveBuilder;
- public DeclSpace ds;
MethodData AddData, RemoveData;
- public Event (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
- MemberName name, Object init, Attributes attrs, Location loc)
- : base (type, mod_flags,
+ public Event (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 ? AllowedInterfaceModifiers : AllowedModifiers,
name, init, attrs, loc)
{
IsInterface = is_iface;
- this.ds = ds;
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
}
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
EventAttributes e_attr;
e_attr = EventAttributes.None;
;
- if (!DoDefineBase (container))
+ if (!DoDefineBase ())
return false;
- if (!DoDefine (container, container))
+ if (!DoDefine (Parent))
return false;
if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
- Report.Error (74, Location, "'" + container.Name + "." + Name +
+ Report.Error (74, Location, "'" + Parent.Name + "." + Name +
"': abstract event can not have an initializer");
return false;
}
if (!TypeManager.IsDelegateType (MemberType)) {
- Report.Error (66, Location, "'" + container.Name + "." + Name +
+ Report.Error (66, Location, "'" + Parent.Name + "." + Name +
"' : event must be of a delegate type");
return false;
}
Parameter [] parms = new Parameter [1];
parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
InternalParameters ip = new InternalParameters (
- container, new Parameters (parms, null, Location));
+ Parent, new Parameters (parms, null, Location));
- if (!CheckBase (container))
+ if (!CheckBase ())
return false;
//
// Now define the accessors
//
- AddBuilder = Add.Define (container, ip);
+ AddBuilder = Add.Define (Parent, ip);
if (AddBuilder == null)
return false;
- RemoveBuilder = Remove.Define (container, ip);
+ RemoveBuilder = Remove.Define (Parent, ip);
if (RemoveBuilder == null)
return false;
if (!IsExplicitImpl){
EventBuilder = new MyEventBuilder (this,
- container.TypeBuilder, Name, e_attr, MemberType);
+ Parent.TypeBuilder, Name, e_attr, MemberType);
if (Add.Block == null && Remove.Block == null &&
!IsInterface) {
- FieldBuilder = container.TypeBuilder.DefineField (
+ FieldBuilder = Parent.TypeBuilder.DefineField (
Name, MemberType,
FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
TypeManager.RegisterPrivateFieldOfEvent (
if (!TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder)) {
Report.Error (111, Location,
- "Class `" + container.Name +
+ "Class `" + Parent.Name +
"' already contains a definition for the event `" +
Name + "'");
return false;
return true;
}
- public override void Emit (TypeContainer tc)
+ public override void Emit ()
{
if (OptAttributes != null) {
- EmitContext ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
+ EmitContext ec = new EmitContext (
+ Parent, Location, null, MemberType, ModFlags);
OptAttributes.Emit (ec, this);
}
if (!IsInterface) {
- Add.Emit (tc);
- Remove.Emit (tc);
+ Add.Emit (Parent);
+ Remove.Emit (Parent);
}
- base.Emit (tc);
+ base.Emit ();
}
public override string GetSignatureForError ()
//
// Are we implementing an interface ?
//
- public Indexer (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
- MemberName name, Parameters parameters, Attributes attrs,
- Accessor get_block, Accessor set_block, Location loc)
- : base (ds, type, mod_flags,
+ public Indexer (TypeContainer parent, Expression type, int mod_flags,
+ bool is_iface, MemberName name, Parameters parameters,
+ Attributes attrs, Accessor get_block, Accessor set_block,
+ Location loc)
+ : base (parent, type, mod_flags,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, parameters, attrs, loc)
{
Set = new SetIndexerMethod (this, parameters, set_block);
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
PropertyAttributes prop_attr =
PropertyAttributes.RTSpecialName |
PropertyAttributes.SpecialName;
- if (!DoDefineBase (container))
+ if (!DoDefineBase ())
return false;
- if (!DoDefine (container, container))
+ if (!DoDefine (Parent))
return false;
if (OptAttributes != null) {
Name = ShortName;
}
- if (!CheckNameCollision (container))
+ if (!CheckNameCollision (Parent))
return false;
- if (!CheckBase (container))
+ if (!CheckBase ())
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
if (Get != null){
- GetBuilder = Get.Define (container);
+ GetBuilder = Get.Define (Parent);
if (GetBuilder == null)
return false;
}
if (Set != null){
- SetBuilder = Set.Define (container);
+ SetBuilder = Set.Define (Parent);
if (SetBuilder == null)
return false;
}
// explicit interface implementation.
//
if (!IsExplicitImpl) {
- PropertyBuilder = container.TypeBuilder.DefineProperty (
+ PropertyBuilder = Parent.TypeBuilder.DefineProperty (
IndexerName, prop_attr, MemberType, ParameterTypes);
if (Get != null)
static string[] attribute_targets = new string [] { "method", "return" };
- public Operator (OpType type, Expression ret_type, int mod_flags,
- Expression arg1type, string arg1name,
+ public Operator (TypeContainer parent, OpType type, Expression ret_type,
+ int mod_flags, Expression arg1type, string arg1name,
Expression arg2type, string arg2name,
Block block, Attributes attrs, Location loc)
- : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC,
- MemberName.Null, attrs, loc)
+ : base (parent, ret_type, mod_flags, AllowedModifiers,
+ Modifiers.PUBLIC, MemberName.Null, attrs, loc)
{
OperatorType = type;
Name = "op_" + OperatorType;
return true;
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
int length = 1;
MethodName = "op_" + OperatorType;
Report.Error (
558, Location,
"User defined operators `" +
- Prototype (container) +
+ Prototype (Parent) +
"' must be declared static and public");
return false;
}
Parameter.Modifier.NONE, null);
OperatorMethod = new Method (
- container, ReturnType, ModFlags, false,
+ Parent, null, ReturnType, ModFlags, false,
new MemberName (MethodName),
new Parameters (param_list, null, Location),
OptAttributes, Location);
OperatorMethod.Block = Block;
OperatorMethod.IsOperator = true;
- OperatorMethod.Define (container);
+ OperatorMethod.Define ();
if (OperatorMethod.MethodBuilder == null)
return false;
return true;
}
- public override void Emit (TypeContainer container)
+ public override void Emit ()
{
//
// abstract or extern methods have no bodies
if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
return;
- OperatorMethod.Emit (container);
+ OperatorMethod.Emit ();
Block = null;
}
public class CSharpParser {
NamespaceEntry current_namespace;
TypeContainer current_container;
+ TypeContainer current_class;
IIteratorContainer iterator_container;
/// </summary>
bool create_toplevel_block;
- /// <summary>
- /// <summary>
- /// Current interface is used by the various declaration
- /// productions in the interface declaration to "add"
- /// the interfaces as we find them.
- /// </summary>
- Interface current_interface;
-
Delegate current_delegate;
/// <summary>
%token WHERE
%token WHILE
%token ARGLIST
+%token PARTIAL
/* C# keywords which are not really keywords */
%token GET "get"
Report.Error_T (134, lexer.Location);
}
- current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
- }
+ current_namespace = new NamespaceEntry (
+ current_namespace, file, (string) $3, lexer.Location);
+ }
namespace_body opt_semicolon
{
current_namespace = current_namespace.Parent;
struct_declaration
: opt_attributes
opt_modifiers
+ opt_partial
STRUCT member_name
{
- Struct new_struct;
- MemberName full_struct_name = MakeName ((MemberName) $4);
+ MemberName name = MakeName ((MemberName) $5);
+ bool partial = (bool) $3;
+
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, Kind.Struct, lexer.Location);
+
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ current_class = new Struct (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, lexer.Location);
+
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
- new_struct = new Struct (current_namespace, current_container, full_struct_name,
- (int) $2, (Attributes) $1, lexer.Location);
- current_container = new_struct;
- RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
lexer.ConstraintsParsing = true;
}
opt_class_base
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
+
+ if ($7 != null)
+ current_class.Bases = (ArrayList) $7;
+
+ CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
+ current_class.Location);
+
+ current_class.Register ();
}
struct_body
opt_semicolon
{
- Struct new_struct = (Struct) current_container;
-
- CheckDef (new_struct.SetParameterInfo ((ArrayList) $7), new_struct.Name, new_struct.Location);
-
- if ($6 != null)
- new_struct.Bases = (ArrayList) $6;
+ $$ = current_class;
current_container = current_container.Parent;
- CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
- $$ = new_struct;
+ current_class = current_container;
}
- | opt_attributes opt_modifiers STRUCT error {
+ | opt_attributes opt_modifiers opt_partial STRUCT error {
CheckIdentifierToken (yyToken);
}
;
Location l = constant.Location;
Const c = new Const (
- (Expression) $4, (string) constant.identifier,
+ current_class, (Expression) $4, (string) constant.identifier,
(Expression) constant.expression_or_array_initializer, (int) $2,
(Attributes) $1, l);
foreach (VariableDeclaration var in (ArrayList) $4){
Location l = var.Location;
- Field field = new Field (type, mod, var.identifier,
+ Field field = new Field (current_class, type, mod, var.identifier,
var.expression_or_array_initializer,
(Attributes) $1, l);
GenericMethod generic = null;
if (name.TypeArguments != null) {
- generic = new GenericMethod (current_namespace, current_container,
+ generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ }
- method = new Method (generic, (Expression) $3, (int) $2, false, name,
- (Parameters) $6, (Attributes) $1, lexer.Location);
- } else
- method = new Method (current_container, (Expression) $3, (int) $2,
- false, name, (Parameters) $6, (Attributes) $1,
- lexer.Location);
+ method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
+ name, (Parameters) $6, (Attributes) $1, lexer.Location);
current_local_parameters = (Parameters) $6;
Method method;
GenericMethod generic = null;
if (name.TypeArguments != null) {
- generic = new GenericMethod (current_namespace, current_container,
+ generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ }
- method = new Method (generic, TypeManager.system_void_expr, (int) $2,
- false, name, (Parameters) $6, (Attributes) $1,
- lexer.Location);
- } else
- method = new Method (current_container, TypeManager.system_void_expr,
- (int) $2, false, name, (Parameters) $6,
- (Attributes) $1, lexer.Location);
+ method = new Method (current_class, generic, TypeManager.system_void_expr,
+ (int) $2, false, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
current_local_parameters = (Parameters) $6;
Modifiers.Name ((int) $4)));
MemberName name = (MemberName) $4;
- Method method = new Method (current_container, TypeManager.system_void_expr,
+ Method method = new Method (current_class, null, TypeManager.system_void_expr,
0, false, name, (Parameters) $6, (Attributes) $1,
lexer.Location);
interface_declaration
: opt_attributes
opt_modifiers
+ opt_partial
INTERFACE member_name
{
- Interface new_interface;
- MemberName full_interface_name = MakeName ((MemberName) $4);
+ MemberName name = MakeName ((MemberName) $5);
+ bool partial = (bool) $3;
- new_interface = new Interface (current_namespace, current_container, full_interface_name,
- (int) $2, (Attributes) $1, lexer.Location);
- if (current_interface != null) {
- Location l = lexer.Location;
- Report.Error (-2, l, "Internal compiler error: interface inside interface");
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, Kind.Interface, lexer.Location);
+
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ current_class = new Interface (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, lexer.Location);
+
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
}
- current_interface = new_interface;
- current_container = new_interface;
- RootContext.Tree.RecordDecl (
- full_interface_name.GetName (true), new_interface);
+
lexer.ConstraintsParsing = true;
}
opt_class_base
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
+
+ if ($7 != null)
+ current_class.Bases = (ArrayList) $7;
+
+ CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
+ current_class.Name, current_class.Location);
+
+ current_class.Register ();
}
interface_body opt_semicolon
{
- Interface new_interface = (Interface) current_interface;
-
- CheckDef (new_interface.SetParameterInfo ((ArrayList) $7), new_interface.Name, new_interface.Location);
- if ($6 != null)
- new_interface.Bases = (ArrayList) $6;
+ $$ = current_class;
- current_interface = null;
current_container = current_container.Parent;
- CheckDef (current_container.AddInterface (new_interface),
- new_interface.Name, new_interface.Location);
+ current_class = current_container;
}
- | opt_attributes opt_modifiers INTERFACE error {
+ | opt_attributes opt_modifiers opt_partial INTERFACE error {
CheckIdentifierToken (yyToken);
}
;
{
Method m = (Method) $1;
- CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
+ CheckDef (current_container.AddMethod (m), m.Name, m.Location);
}
| interface_property_declaration
{
Property p = (Property) $1;
- CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
+ CheckDef (current_container.AddProperty (p), p.Name, p.Location);
}
| interface_event_declaration
{
if ($1 != null){
Event e = (Event) $1;
- CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
+ CheckDef (current_container.AddEvent (e), e.Name, lexer.Location);
}
}
| interface_indexer_declaration
{
Indexer i = (Indexer) $1;
- current_interface.AddIndexer (i);
+ current_container.AddIndexer (i);
}
;
GenericMethod generic = null;
if (name.TypeArguments != null) {
- generic = new GenericMethod (current_namespace, current_container,
+ generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ }
- $$ = new Method (generic, (Expression) $3, (int) $2, true, name,
- (Parameters) $6, (Attributes) $1, lexer.Location);
- } else
- $$ = new Method (current_container, (Expression) $3, (int) $2, true,
- name, (Parameters) $6, (Attributes) $1,
- lexer.Location);
+ $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
+ (Parameters) $6, (Attributes) $1, lexer.Location);
}
| opt_attributes opt_new VOID namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
GenericMethod generic = null;
if (name.TypeArguments != null) {
- generic = new GenericMethod (current_namespace, current_container,
+ generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ }
- $$ = new Method (generic, TypeManager.system_void_expr, (int) $2,
- true, name, (Parameters) $6, (Attributes) $1,
- lexer.Location);
- } else
- $$ = new Method (current_container, TypeManager.system_void_expr,
- (int) $2, true, name, (Parameters) $6,
- (Attributes) $1, lexer.Location);
+ $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
+ true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
}
;
{
InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
- $$ = new Property (current_container, (Expression) $3, (int) $2, true,
+ $$ = new Property (current_class, (Expression) $3, (int) $2, true,
new MemberName ((string) $4), (Attributes) $1,
pinfo.Get, pinfo.Set, lexer.Location);
}
interface_event_declaration
: opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
{
- $$ = new EventField (current_container, (Expression) $4, (int) $2, true,
+ $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
new MemberName ((string) $5), null,
(Attributes) $1, lexer.Location);
}
{
InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
- $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
+ $$ = new Indexer (current_class, (Expression) $3, (int) $2, true,
MemberName.Null, (Parameters) $6, (Attributes) $1,
info.Get, info.Set, lexer.Location);
}
{
OperatorDeclaration decl = (OperatorDeclaration) $3;
- Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
- decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
+ Operator op = new Operator (
+ current_class, decl.optype, decl.ret_type, (int) $2, decl.arg1type,
+ decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
+ (Attributes) $1, decl.location);
if (SimpleIteratorContainer.Simple.Yields)
op.SetYields ();
opt_constructor_initializer
{
Location l = (Location) oob_stack.Pop ();
- $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
+ $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
(ConstructorInitializer) $6, l);
}
;
}
Method d = new Destructor (
- current_container, TypeManager.system_void_expr, m, "Finalize",
+ current_class, TypeManager.system_void_expr, m, "Finalize",
new Parameters (null, null, l), (Attributes) $1, l);
d.Block = (Block) $7;
MemberName name = new MemberName (var.identifier);
- Event e = new EventField (current_container, (Expression) $4, (int) $2,
+ Event e = new EventField (current_class, (Expression) $4, (int) $2,
false, name,
var.expression_or_array_initializer,
(Attributes) $1, lexer.Location);
if (name.TypeArguments != null)
syntax_error (lexer.Location, "an event can't have type arguments");
- Event e = new EventProperty (current_container, (Expression) $4, (int) $2,
+ Event e = new EventProperty (current_class, (Expression) $4, (int) $2,
false, name, null, (Attributes) $1,
(Accessor) pair.First, (Accessor) pair.Second,
loc);
else
name = MemberName.Null;
- indexer = new Indexer (current_container, decl.type, (int) $2, false,
+ indexer = new Indexer (current_class, decl.type, (int) $2, false,
name, decl.param_list, (Attributes) $1,
get_block, set_block, loc);
class_declaration
: opt_attributes
opt_modifiers
+ opt_partial
CLASS member_name
{
- Class new_class;
+ MemberName name = MakeName ((MemberName) $5);
+ bool partial = (bool) $3;
- MemberName name = MakeName ((MemberName) $4);
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, Kind.Class, lexer.Location);
- new_class = new Class (current_namespace, current_container, name, (int) $2,
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ current_class = new Class (
+ current_namespace, current_container, name, (int) $2,
(Attributes) $1, lexer.Location);
- current_container = new_class;
- RootContext.Tree.RecordDecl (name.GetName (true), new_class);
+
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
lexer.ConstraintsParsing = true;
}
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
+
+ if ($7 != null) {
+ if (current_class.Name == "System.Object") {
+ Report.Error (537, current_class.Location,
+ "The class System.Object cannot have a base " +
+ "class or implement an interface.");
+ }
+ current_class.Bases = (ArrayList) $7;
+ }
+
+ CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
+ current_class.Name, current_class.Location);
+
+ current_class.Register ();
}
class_body
opt_semicolon
{
- Class new_class = (Class) current_container;
-
- CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
- if ($6 != null) {
- if (new_class.Name == "System.Object") {
- Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
- }
+ $$ = current_class;
- new_class.Bases = (ArrayList) $6;
- }
current_container = current_container.Parent;
- CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
-
- $$ = new_class;
+ current_class = current_container;
}
;
+opt_partial
+ : /* empty */
+ { $$ = (bool) false; }
+ | PARTIAL
+ { $$ = (bool) true; }
+ ;
+
opt_modifiers
: /* empty */ { $$ = (int) 0; }
| modifiers
void
CheckDef (DeclSpace.AdditionResult result, string name, Location l)
{
- if (result == DeclSpace.AdditionResult.Success)
- return;
-
- switch (result){
- case DeclSpace.AdditionResult.NameExists:
- Report.Error (102, l, "The container `" + current_container.Name +
- "' already contains a definition for `"+
- name + "'");
- break;
-
-
- //
- // This is handled only for static Constructors, because
- // in reality we handle these by the semantic analysis later
- //
- case DeclSpace.AdditionResult.MethodExists:
- Report.Error (
- 111, l, "Class `"+current_container.Name+
- "' already defines a member called '" +
- name + "' with the same parameter types (more than one default constructor)");
- break;
-
- case DeclSpace.AdditionResult.EnclosingClash:
- Report.Error (542, l, "Member names cannot be the same as their enclosing type");
- break;
-
- case DeclSpace.AdditionResult.NotAConstructor:
- Report.Error (1520, l, "Class, struct, or interface method must have a return type");
- break;
-
- case DeclSpace.AdditionResult.Error:
- // Error has already been reported.
- break;
- }
+ current_container.CheckDef (result, name, l);
}
void