ArrayList type_bases;
- // Attributes for this type
- protected Attributes attributes;
-
// Information in the case we are an attribute type
public AttributeTargets Targets = AttributeTargets.All;
//
public string IndexerName;
- public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Location l)
- : base (ns, parent, name, l)
+ Type GenericType;
+
+ public TypeContainer ():
+ this (null, null, "", null, new Location (-1)) {
+ }
+
+ public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
{
- string n;
types = new ArrayList ();
- if (parent == null)
- n = "";
- else
- n = parent.Name;
-
base_class_name = null;
-
- //Console.WriteLine ("New class " + name + " inside " + n);
}
public AdditionResult AddConstant (Const constant)
if (methods == null)
methods = new ArrayList ();
- if (method.Name.IndexOf (".") != -1)
+ if (method.Name.IndexOf ('.') != -1)
methods.Insert (0, method);
else
methods.Add (method);
public AdditionResult AddProperty (Property prop)
{
AdditionResult res;
- string basename = prop.Name;
- string fullname = Name + "." + basename;
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+ if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
+ return res;
+
+ if (prop.Get != null) {
+ if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
+ return res;
+ }
+
+ if (prop.Set != null) {
+ if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
return res;
+ }
if (properties == null)
properties = new ArrayList ();
- if (prop.Name.IndexOf (".") != -1)
+ if (prop.Name.IndexOf ('.') != -1)
properties.Insert (0, prop);
else
properties.Add (prop);
+
+ return AdditionResult.Success;
+ }
+
+ AdditionResult AddProperty (Property prop, string basename)
+ {
+ AdditionResult res;
+ string fullname = Name + "." + basename;
+
+ if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+ return res;
+
DefineName (fullname, prop);
return AdditionResult.Success;
return AdditionResult.Success;
}
- public AdditionResult AddIndexer (Indexer i)
+ public void AddIndexer (Indexer i)
{
if (indexers == null)
indexers = new ArrayList ();
indexers.Insert (0, i);
else
indexers.Add (i);
-
- return AdditionResult.Success;
}
public AdditionResult AddOperator (Operator op)
operators.Add (op);
+ string basename = op.Name;
+ string fullname = Name + "." + basename;
+ if (!defined_names.Contains (fullname))
+ {
+ DefineName (fullname, op);
+ }
return AdditionResult.Success;
}
}
}
- public Attributes OptAttributes {
- get {
- return attributes;
- }
- }
-
public bool HaveStaticConstructor {
get {
return have_static_constructor;
public bool EmitFieldInitializers (EmitContext ec)
{
ArrayList fields;
- ILGenerator ig = ec.ig;
Expression instance_expr;
if (ec.IsStatic){
void DefineDefaultConstructor (bool is_static)
{
Constructor c;
- int mods = 0;
- c = new Constructor (this, Basename, Parameters.EmptyReadOnlyParameters,
+ // The default constructor is public
+ // If the class is abstract, the default constructor is protected
+ // The default static constructor is private
+
+ int mods = Modifiers.PUBLIC;
+ if (is_static)
+ mods = Modifiers.STATIC | Modifiers.PRIVATE;
+ else if ((ModFlags & Modifiers.ABSTRACT) != 0)
+ mods = Modifiers.PROTECTED;
+
+ c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
new ConstructorBaseInitializer (
null, Parameters.EmptyReadOnlyParameters,
Location),
Location);
- if (is_static)
- mods = Modifiers.STATIC;
-
- c.ModFlags = mods;
-
AddConstructor (c);
- c.Block = new Block (null);
+ c.Block = new ToplevelBlock (null, Location);
}
return null;
}
- ModuleBuilder builder = CodeGen.ModuleBuilder;
+ ModuleBuilder builder = CodeGen.Module.Builder;
TypeBuilder = builder.DefineType (
Name, type_attributes, ptype, null);
}
if (IsGeneric) {
+ CurrentType = new ConstructedType (
+ Name, CurrentTypeParameters, Location);
+
foreach (TypeParameter type_param in TypeParameters)
type_param.Define (TypeBuilder);
}
if (fields != null)
DefineMembers (fields, defined_names);
- if ((RootContext.WarningLevel >= 4) && (fields != null)) {
- foreach (Field f in fields) {
- if (((f.ModFlags & Modifiers.READONLY) != 0) && !f.IsAssigned)
- Report.Warning (649, "Field `" + MakeFQN (Name, f.Name) + "; is never " +
- "assigned and will ever have its default value");
- }
- }
-
if (this is Class){
if (instance_constructors == null){
if (default_constructor == null)
if (delegates != null)
DefineMembers (delegates, defined_names);
+ if (CurrentType != null) {
+ GenericType = CurrentType.ResolveType (ec);
+
+ ec.ContainerType = GenericType;
+ }
+
+
#if CACHE
if (TypeBuilder.BaseType != null)
parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
MemberFilter filter, object criteria)
{
- ArrayList members = new ArrayList ();
+ ArrayList members = null;
int modflags = 0;
if ((bf & BindingFlags.Public) != 0)
if ((mt & MemberTypes.Field) != 0) {
if (fields != null) {
- foreach (Field f in fields) {
+ int len = fields.Count;
+ for (int i = 0; i < len; i++) {
+ Field f = (Field) fields [i];
+
if ((f.ModFlags & modflags) == 0)
continue;
if ((f.ModFlags & static_mask) != static_flags)
continue;
FieldBuilder fb = f.FieldBuilder;
- if (fb != null && filter (fb, criteria) == true)
+ if (fb != null && filter (fb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (fb);
}
}
+ }
if (constants != null) {
- foreach (Const con in constants) {
+ int len = constants.Count;
+ for (int i = 0; i < len; i++) {
+ Const con = (Const) constants [i];
+
if ((con.ModFlags & modflags) == 0)
continue;
if ((con.ModFlags & static_mask) != static_flags)
continue;
FieldBuilder fb = con.FieldBuilder;
- if (fb != null && filter (fb, criteria) == true)
+ if (fb != null && filter (fb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (fb);
}
}
}
+ }
if ((mt & MemberTypes.Method) != 0) {
if (methods != null) {
- foreach (Method m in methods) {
+ int len = methods.Count;
+ for (int i = 0; i < len; i++) {
+ Method m = (Method) methods [i];
+
if ((m.ModFlags & modflags) == 0)
continue;
if ((m.ModFlags & static_mask) != static_flags)
MethodBuilder mb = m.MethodBuilder;
- if (mb != null && filter (mb, criteria) == true)
+ if (mb != null && filter (mb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (mb);
}
}
+ }
+
+ if (operators != null) {
+ int len = operators.Count;
+ for (int i = 0; i < len; i++) {
+ Operator o = (Operator) operators [i];
- if (operators != null){
- foreach (Operator o in operators) {
if ((o.ModFlags & modflags) == 0)
continue;
if ((o.ModFlags & static_mask) != static_flags)
continue;
MethodBuilder ob = o.OperatorMethodBuilder;
- if (ob != null && filter (ob, criteria) == true)
+ if (ob != null && filter (ob, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (ob);
}
}
+ }
+
+ if (properties != null) {
+ int len = properties.Count;
+ for (int i = 0; i < len; i++) {
+ Property p = (Property) properties [i];
- if (properties != null){
- foreach (Property p in properties){
if ((p.ModFlags & modflags) == 0)
continue;
if ((p.ModFlags & static_mask) != static_flags)
MethodBuilder b;
b = p.GetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
+ }
b = p.SetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
}
}
+ }
+
+ if (indexers != null) {
+ int len = indexers.Count;
+ for (int i = 0; i < len; i++) {
+ Indexer ix = (Indexer) indexers [i];
- if (indexers != null){
- foreach (Indexer ix in indexers){
if ((ix.ModFlags & modflags) == 0)
continue;
if ((ix.ModFlags & static_mask) != static_flags)
MethodBuilder b;
b = ix.GetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
+ }
b = ix.SetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
}
}
}
+ }
if ((mt & MemberTypes.Event) != 0) {
- if (events != null)
- foreach (Event e in events) {
+ if (events != null) {
+ int len = events.Count;
+ for (int i = 0; i < len; i++) {
+ Event e = (Event) events [i];
+
if ((e.ModFlags & modflags) == 0)
continue;
if ((e.ModFlags & static_mask) != static_flags)
continue;
MemberInfo eb = e.EventBuilder;
- if (eb != null && filter (eb, criteria) == true)
+ if (eb != null && filter (eb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (e.EventBuilder);
}
}
+ }
+ }
if ((mt & MemberTypes.Property) != 0){
- if (properties != null)
- foreach (Property p in properties) {
+ if (properties != null) {
+ int len = properties.Count;
+ for (int i = 0; i < len; i++) {
+ Property p = (Property) properties [i];
+
if ((p.ModFlags & modflags) == 0)
continue;
if ((p.ModFlags & static_mask) != static_flags)
MemberInfo pb = p.PropertyBuilder;
if (pb != null && filter (pb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (p.PropertyBuilder);
}
}
+ }
+
+ if (indexers != null) {
+ int len = indexers.Count;
+ for (int i = 0; i < len; i++) {
+ Indexer ix = (Indexer) indexers [i];
- if (indexers != null)
- foreach (Indexer ix in indexers) {
if ((ix.ModFlags & modflags) == 0)
continue;
if ((ix.ModFlags & static_mask) != static_flags)
MemberInfo ib = ix.PropertyBuilder;
if (ib != null && filter (ib, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (ix.PropertyBuilder);
}
}
}
+ }
if ((mt & MemberTypes.NestedType) != 0) {
- if (types != null){
- foreach (TypeContainer t in types) {
+ if (types != null) {
+ int len = types.Count;
+ for (int i = 0; i < len; i++) {
+ TypeContainer t = (TypeContainer) types [i];
+
if ((t.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = t.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
+ }
+
+ if (enums != null) {
+ int len = enums.Count;
+ for (int i = 0; i < len; i++) {
+ Enum en = (Enum) enums [i];
- if (enums != null){
- foreach (Enum en in enums){
if ((en.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = en.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
+ }
+
+ if (delegates != null) {
+ int len = delegates.Count;
+ for (int i = 0; i < len; i++) {
+ Delegate d = (Delegate) delegates [i];
- if (delegates != null){
- foreach (Delegate d in delegates){
if ((d.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = d.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
+ }
+
+ if (interfaces != null) {
+ int len = interfaces.Count;
+ for (int i = 0; i < len; i++) {
+ Interface iface = (Interface) interfaces [i];
- if (interfaces != null){
- foreach (Interface iface in interfaces){
if ((iface.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = iface.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
}
+ }
if ((mt & MemberTypes.Constructor) != 0){
if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
- foreach (Constructor c in instance_constructors){
+ int len = instance_constructors.Count;
+ for (int i = 0; i < len; i++) {
+ Constructor c = (Constructor) instance_constructors [i];
+
ConstructorBuilder cb = c.ConstructorBuilder;
- if (cb != null)
- if (filter (cb, criteria) == true)
+ if (cb != null && filter (cb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (cb);
}
}
+ }
if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null)){
ConstructorBuilder cb =
default_static_constructor.ConstructorBuilder;
- if (cb != null)
- if (filter (cb, criteria) == true)
+ if (cb != null && filter (cb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (cb);
}
}
+ }
//
// Lookup members in parent if requested.
//
if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
+ if (list.Count > 0) {
+ if (members == null)
+ members = new ArrayList ();
+
members.AddRange (list);
}
+ }
Timer.StopTimer (TimerType.TcFindMembers);
+ if (members == null)
+ return MemberList.Empty;
+ else
return new MemberList (members);
}
{
if (constants != null)
foreach (Const con in constants)
- con.EmitConstant (this);
+ con.Emit (this);
return;
}
if (RootContext.WarningLevel >= 3) {
if (fields != null){
foreach (Field f in fields) {
- if ((f.ModFlags & Modifiers.PUBLIC) != 0)
+ if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
continue;
- if (f.status == 0){
+ if ((f.status & Field.Status.USED) == 0){
Report.Warning (
169, f.Location, "Private field " +
MakeName (f.Name) + " is never used");
public override void CloseType ()
{
+ if (Created)
+ return;
+
try {
- if (!Created){
Created = true;
TypeBuilder.CreateType ();
- }
} catch (TypeLoadException){
//
// This is fine, the code still created the type
if (Delegates != null)
foreach (Delegate d in Delegates)
d.CloseType ();
+
+ types = null;
+ properties = null;
+ enums = null;
+ delegates = null;
+ fields = null;
+ initialized_fields = null;
+ initialized_static_fields = null;
+ constants = null;
+ interfaces = null;
+ interface_order = null;
+ methods = null;
+ events = null;
+ indexers = null;
+ operators = null;
+ ec = null;
+ default_constructor = null;
+ default_static_constructor = null;
+ type_bases = null;
+ OptAttributes = null;
+ ifaces = null;
+ parent_container = null;
+ member_cache = null;
}
public string MakeName (string n)
return true;
}
- public static void Error_ExplicitInterfaceNotMemberInterface (Location loc, string name)
- {
- Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
- }
-
//
// IMemberContainer
//
MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
{
- return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+ BindingFlags new_bf = bf | BindingFlags.DeclaredOnly;
+
+ if (GenericType != null)
+ return TypeManager.FindMembers (GenericType, mt, new_bf,
+ null, null);
+ else
+ return FindMembers (mt, new_bf, null, null);
}
//
Modifiers.UNSAFE;
public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (ns, parent, name, l)
+ : base (ns, parent, name, attrs, l)
{
int accmods;
accmods = Modifiers.PRIVATE;
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
- this.attributes = attrs;
}
//
Modifiers.PRIVATE;
public Struct (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (ns, parent, name, l)
+ : base (ns, parent, name, attrs, l)
{
int accmods;
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
this.ModFlags |= Modifiers.SEALED;
- this.attributes = attrs;
-
}
//
Modifiers.OVERRIDE |
Modifiers.ABSTRACT |
Modifiers.UNSAFE |
+ Modifiers.METHOD_YIELDS |
Modifiers.EXTERN;
//
public Method (DeclSpace ds, Expression return_type, int mod, string name,
Parameters parameters, Attributes attrs, Location l)
: base (ds, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
- { }
+ {
+ }
public Method (GenericMethod generic, Expression return_type, int mod, string name,
Parameters parameters, Attributes attrs, Location l)
//
public override bool Define (TypeContainer container)
{
- if (!DoDefine (container))
- return false;
-
+ DeclSpace decl;
MethodBuilder mb = null;
if (GenericMethod != null) {
mb = container.TypeBuilder.DefineGenericMethod (Name, flags);
if (!GenericMethod.Define (mb))
return false;
- }
+ decl = GenericMethod;
+ } else
+ decl = container;
+
+ if (!DoDefine (decl, container))
+ return false;
if (!CheckBase (container))
return false;
// This is used to track the Entry Point,
//
if (Name == "Main" &&
- ((ModFlags & Modifiers.STATIC) != 0) &&
+ ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint &&
(RootContext.MainClass == null ||
RootContext.MainClass == container.TypeBuilder.FullName)){
if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
{
MethodData.Emit (container, Block, this);
Block = null;
+ MethodData = null;
}
void IIteratorContainer.SetYields ()
Expression parent_constructor_group;
Type t;
- ec.CurrentBlock = new Block (null, Block.Flags.Implicit, parameters);
+ ec.CurrentBlock = new ToplevelBlock (Block.Flags.Implicit, parameters, loc);
if (argument_list != null){
foreach (Argument a in argument_list){
public class Constructor : MethodCore {
public ConstructorBuilder ConstructorBuilder;
public ConstructorInitializer Initializer;
- new public Attributes OptAttributes;
// <summary>
// Modifiers allowed for a constructor.
// The spec claims that static is not permitted, but
// my very own code has static constructors.
//
- public Constructor (DeclSpace ds, string name, Parameters args,
+ public Constructor (DeclSpace ds, string name, int mod, Parameters args,
ConstructorInitializer init, Location l)
- : base (ds, null, 0, AllowedModifiers, name, null, args, l)
+ : base (ds, null, mod, AllowedModifiers, name, null, args, l)
{
Initializer = init;
}
member.InterfaceType, name, ReturnType, ParameterTypes);
if (member.InterfaceType != null && implementing == null){
- TypeContainer.Error_ExplicitInterfaceNotMemberInterface (
- Location, name);
+ Report.Error (539, Location, "'{0}' in explicit interface declaration is not an interface", method_name);
return false;
}
}
method_name, flags, CallingConventions,
ReturnType, ParameterTypes);
else
- builder.SetGenericMethodSignature (ReturnType, ParameterTypes);
+ builder.SetGenericMethodSignature (
+ flags, CallingConventions,
+ ReturnType, ParameterTypes);
if (builder == null)
return false;
//
// FIXME: This code generates buggy code
//
- if (member.Name == "Finalize" && ReturnType == TypeManager.void_type)
+ if (member is Destructor)
EmitDestructor (ec, block);
else {
SymbolWriter sw = CodeGen.SymbolWriter;
ILGenerator ig = ec.ig;
Label finish = ig.DefineLabel ();
- bool old_in_try = ec.InTry;
+
+ block.SetDestructor ();
ig.BeginExceptionBlock ();
- ec.InTry = true;
ec.ReturnLabel = finish;
ec.HasReturnLabel = true;
ec.EmitTopBlock (block, null, Location);
- ec.InTry = old_in_try;
// ig.MarkLabel (finish);
- bool old_in_finally = ec.InFinally;
- ec.InFinally = true;
ig.BeginFinallyBlock ();
if (ec.ContainerType.BaseType != null) {
ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
}
}
- ec.InFinally = old_in_finally;
ig.EndExceptionBlock ();
//ig.MarkLabel (ec.ReturnLabel);
}
}
+ public class Destructor : Method {
+
+ public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
+ Parameters parameters, Attributes attrs, Location l)
+ : base (ds, return_type, mod, name, parameters, attrs, l)
+ { }
+
+ }
+
abstract public class MemberBase : MemberCore {
public Expression Type;
- public readonly Attributes OptAttributes;
protected MethodAttributes flags;
+ protected readonly int explicit_mod_flags;
+
//
// The "short" name of this property / indexer / event. This is the
// name without the explicit interface.
//
protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod, string name,
Attributes attrs, Location loc)
- : base (name, loc)
+ : base (name, attrs, loc)
{
+ explicit_mod_flags = mod;
Type = type;
ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
- OptAttributes = attrs;
}
protected virtual bool CheckBase (TypeContainer container)
return !error;
}
- protected virtual bool DoDefine (TypeContainer container)
+ protected virtual bool DoDefine (DeclSpace decl, TypeContainer container)
{
if (Name == null)
Name = "this";
flags = Modifiers.MethodAttr (ModFlags);
// Lookup Type, verify validity
- MemberType = container.ResolveType (Type, false, Location);
+ MemberType = decl.ResolveType (Type, false, Location);
if (MemberType == null)
return false;
//
// Check for explicit interface implementation
//
- if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)){
- int pos = Name.LastIndexOf (".");
+ if ((ExplicitInterfaceName == null) && (Name.IndexOf ('.') != -1)){
+ int pos = Name.LastIndexOf ('.');
ExplicitInterfaceName = Name.Substring (0, pos);
ShortName = Name.Substring (pos + 1);
if (InterfaceType == null)
return false;
+ if (InterfaceType.IsClass) {
+ Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
+ return false;
+ }
+
// Compute the full name that we need to export.
Name = InterfaceType.FullName + "." + ShortName;
if (!container.VerifyImplements (InterfaceType, ShortName, Name, Location))
return false;
+ Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
+
IsExplicitImpl = true;
} else
IsExplicitImpl = false;
}
}
- public bool IsAssigned;
-
protected readonly Object init;
// Private.
Expression init_expr;
return init_expr;
}
+
+ public void SetAssigned ()
+ {
+ status |= Status.ASSIGNED;
+ }
}
//
return false;
}
+ try {
FieldBuilder = container.TypeBuilder.DefineField (
Name, t, Modifiers.FieldAttr (ModFlags));
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.");
+ return false;
+ }
+
return true;
}
Set = set_block;
}
- protected override bool DoDefine (TypeContainer container)
+ protected override bool DoDefine (DeclSpace decl, TypeContainer container)
{
- if (!base.DoDefine (container))
+ if (!base.DoDefine (decl, container))
return false;
ec = new EmitContext (container, Location, null, MemberType, ModFlags);
}
}
- public class Property : PropertyBase {
+ public class Property : PropertyBase, IIteratorContainer {
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.ABSTRACT |
Modifiers.UNSAFE |
Modifiers.EXTERN |
+ Modifiers.METHOD_YIELDS |
Modifiers.VIRTUAL;
public Property (DeclSpace ds, Expression type, string name, int mod_flags,
public override bool Define (TypeContainer container)
{
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
if (!CheckBase (container))
parameters, ip, CallingConventions.Standard,
Get.OptAttributes, ModFlags, flags, false);
+ //
+ // Setup iterator if we are one
+ //
+ if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+ IteratorHandler ih = new IteratorHandler (
+ "get", container, MemberType,
+ parameters, ip, ModFlags, Location);
+
+ Block new_block = ih.Setup (block);
+ if (new_block == null)
+ return false;
+ block = new_block;
+ }
+
if (!GetData.Define (container))
return false;
}
return true;
}
+
+ public void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
}
/// </summary>
EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
MethodAttributes m_attr = MethodAttributes.HideBySig | MethodAttributes.SpecialName
;
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
//
// Are we implementing an interface ?
//
- bool IsImplementing = false;
-
public Indexer (DeclSpace ds, Expression type, string int_type, int flags,
Parameters parameters, Accessor get_block, Accessor set_block,
Attributes attrs, Location loc)
PropertyAttributes.RTSpecialName |
PropertyAttributes.SpecialName;
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
Name = ShortName;
}
+ if (!CheckNameCollision (container))
+ return false;
+
if (!CheckBase (container))
return false;
}
}
- if (GetData != null)
- IsImplementing = GetData.IsImplementing;
- else if (SetData != null)
- IsImplementing = SetData.IsImplementing;
-
//
// Define the PropertyBuilder if one of the following conditions are met:
// a) we're not implementing an interface indexer.
return true;
}
+
+ bool CheckNameCollision (TypeContainer container) {
+ switch (VerifyName (container)){
+ case DeclSpace.AdditionResult.NameExists:
+ Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
+ return false;
+
+ case DeclSpace.AdditionResult.Success:
+ return true;
+ }
+ throw new NotImplementedException ();
+ }
+
+ DeclSpace.AdditionResult VerifyName (TypeContainer container) {
+ if (!AddIndexer (container, container.Name + "." + Name))
+ return DeclSpace.AdditionResult.NameExists;
+
+ if (Get != null) {
+ if (!AddIndexer (container, container.Name + ".get_" + Name))
+ return DeclSpace.AdditionResult.NameExists;
+ }
+
+ if (Set != null) {
+ if (!AddIndexer (container, container.Name + ".set_" + Name))
+ return DeclSpace.AdditionResult.NameExists;
+ }
+ return DeclSpace.AdditionResult.Success;
+ }
+
+ bool AddIndexer (TypeContainer container, string fullname)
+ {
+ object value = container.GetDefinition (fullname);
+
+ if (value != null) {
+ return value.GetType () != GetType () ? false : true;
+ }
+
+ container.DefineName (fullname, this);
+ return true;
+ }
+
+ public override string GetSignatureForError () {
+ return TypeManager.CSharpSignature (PropertyBuilder, true);
+ }
}
- public class Operator : MemberBase {
+ public class Operator : MemberBase, IIteratorContainer {
const int AllowedModifiers =
Modifiers.PUBLIC |
: base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
{
OperatorType = type;
+ Name = "op_" + OperatorType;
ReturnType = ret_type;
FirstArgType = arg1type;
FirstArgName = arg1name;
new Parameters (param_list, null, Location),
OptAttributes, Location);
+ OperatorMethod.Block = Block;
OperatorMethod.IsOperator = true;
OperatorMethod.Define (container);
if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
return;
- OperatorMethod.Block = Block;
OperatorMethod.Emit (container);
Block = null;
}
GetName (OperatorType),
param_types [0], param_types [1]);
}
+
+ public void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
}
//
// If only accessible to the defining assembly or
if (prot == MethodAttributes.FamANDAssem ||
prot == MethodAttributes.Assembly){
- if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
- return true;
- else
- return false;
+ return m.DeclaringType.Assembly == CodeGen.Assembly.Builder;
}
// Anything else (FamOrAssembly and Public) is fine