//
// Authors: Miguel de Icaza (miguel@gnu.org)
// Martin Baulig (martin@gnome.org)
+// Anirban Bhattacharjee (banirban@novell.com)
//
// Licensed under the terms of the GNU GPL
//
if (error)
return null;
+ if (this is Interface)
+ parent = null;
+
if (is_class && parent != null){
if (parent == TypeManager.enum_type ||
(parent == TypeManager.value_type && RootContext.StdLib) ||
if (!is_class && TypeManager.value_type == null)
throw new Exception ();
- if (is_class && Parent.Parent == null) \r
+ if (is_class && Parent.Parent == null && (!(this is Interface))) \r
{
if ((ModFlags & Modifiers.PRIVATE) != 0)
Report.Error (31089, Location,
if (fields != null)
DefineMembers (fields, defined_names);
- if (this is Class){
+ if (this is Class && (!(this is Interface))){
if (instance_constructors == null){
if (default_constructor == null) \r
DefineDefaultConstructor (false);
foreach (Indexer ix in indexers)
ix.Emit (this);
- CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
+ /*CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
this, IndexerName, ModFlags, Location);
- TypeBuilder.SetCustomAttribute (cb);
+ TypeBuilder.SetCustomAttribute (cb);*/
}
if (fields != null)
bool IMemberContainer.IsInterface {
get {
- return false;
+ return this is Interface;
}
}
//
protected InternalParameters parameter_info;
protected Type [] parameter_types;
+
+ // Whether this is an operator
+ public bool IsOperator;
public MethodCore (Expression type, int mod, int allowed_mod, string name,
Attributes attrs, Parameters parameters, Location loc)
return MemberType;
}
- // Whether this is an operator method.
- public bool IsOperator;
+ void DuplicateEntryPoint (MethodInfo b, Location location)
+ {
+ Report.Error (
+ 30738, location,
+ "Program `" + CodeGen.FileName +
+ "' has more than one entry point defined: `" +
+ TypeManager.MonoBASIC_Signature(b) + "'");
+ }
- void DuplicateEntryPoint (MethodInfo b, Location location)
- {
- Report.Error (
- 30738, location,
- "Program `" + CodeGen.FileName +
- "' has more than one entry point defined: `" +
- TypeManager.MonoBASIC_Signature(b) + "'");
- }
-
- void Report28 (MethodInfo b)
- {
+ void Report28 (MethodInfo b)
+ {
if (RootContext.WarningLevel < 4)
return;
- Report.Warning (
- 28, Location,
- "`" + TypeManager.MonoBASIC_Signature(b) +
- "' has the wrong signature to be an entry point");
- }
-
- public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
- {
- if (b.ReturnType != TypeManager.void_type &&
- b.ReturnType != TypeManager.int32_type)
- return false;
-
- if (pinfo.Count == 0)
- return true;
-
- if (pinfo.Count > 1)
- return false;
-
- Type t = pinfo.ParameterType(0);
- if (t.IsArray &&
- (t.GetArrayRank() == 1) &&
- (t.GetElementType() == TypeManager.string_type) &&
- (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
- return true;
- else
- return false;
- }
+ Report.Warning (
+ 28, Location,
+ "`" + TypeManager.MonoBASIC_Signature(b) +
+ "' has the wrong signature to be an entry point");
+ }
+
+ public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
+ {
+ if (b.ReturnType != TypeManager.void_type &&
+ b.ReturnType != TypeManager.int32_type)
+ return false;
+
+ if (pinfo.Count == 0)
+ return true;
+
+ if (pinfo.Count > 1)
+ return false;
+
+ Type t = pinfo.ParameterType(0);
+ if (t.IsArray &&
+ (t.GetArrayRank() == 1) &&
+ (t.GetElementType() == TypeManager.string_type) &&
+ (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
+ return true;
+ else
+ return false;
+ }
//
// Checks our base implementation if any
//
// Check for explicit interface implementation
//
- if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)){
+ if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)) {
int pos = Name.LastIndexOf (".");
ExplicitInterfaceName = Name.Substring (0, pos);
//
// Checks our base implementation if any
//
- protected override bool CheckBase (TypeContainer parent)
+ protected override bool CheckBase (TypeContainer container)
{
+ base.CheckBase (container);
+
// Check whether arguments were correct.
- if (!DoDefineParameters (parent))
+ if (!DoDefineParameters (container))
return false;
if (IsExplicitImpl)
return true;
+ MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
+ if (!IsOperator) \r
+ {
+ MemberList mi_this;
+
+ mi_this = TypeContainer.FindMembers (
+ container.TypeBuilder, MemberTypes.Property,
+ BindingFlags.NonPublic | BindingFlags.Public |
+ BindingFlags.Static | BindingFlags.Instance |
+ BindingFlags.DeclaredOnly,
+ MethodSignature.method_signature_filter, ms);
+
+ if (mi_this.Count > 0) {
+ Report.Error (111, Location, "Class `" + container.Name + "' " +
+ "already defines a member called `" + Name + "' " +
+ "with the same parameter types");
+ return false;
+ }
+ }
+
+ if (container is Interface)
+ return true;
+
string report_name;
- MethodSignature ms, base_ms;
+ MethodSignature base_ms;
if (this is Indexer) {
string name, base_name;
report_name = "this";
- name = TypeManager.IndexerPropertyName (parent.TypeBuilder);
+ name = TypeManager.IndexerPropertyName (container.TypeBuilder);
ms = new MethodSignature (name, null, ParameterTypes);
- base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType);
+ base_name = TypeManager.IndexerPropertyName (container.TypeBuilder.BaseType);
base_ms = new MethodSignature (base_name, null, ParameterTypes);
} else {
report_name = Name;
ms = base_ms = new MethodSignature (Name, null, ParameterTypes);
}
- MemberList props_this;
-
- props_this = TypeContainer.FindMembers (
- parent.TypeBuilder, MemberTypes.Property,
- BindingFlags.NonPublic | BindingFlags.Public |
- BindingFlags.Static | BindingFlags.Instance |
- BindingFlags.DeclaredOnly,
- MethodSignature.method_signature_filter, ms);
-
- if (props_this.Count > 0) {
- Report.Error (111, Location, "Class `" + parent.Name + "' " +
- "already defines a member called `" + report_name + "' " +
- "with the same parameter types");
- return false;
- }
-
//
- // Find properties with the same name on the base class
+ // 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.
//
- MemberList props;
- MemberList props_static = TypeContainer.FindMembers (
- parent.TypeBuilder.BaseType, MemberTypes.Property,
+ Type ptype = container.TypeBuilder.BaseType;
+
+ MemberInfo parent_member = null;
+ MemberList mi, mi_static, mi_instance;
+
+ mi_static = TypeContainer.FindMembers (
+ ptype, MemberTypes.Property,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
- MethodSignature.inheritable_property_signature_filter, base_ms);
+ MethodSignature.inheritable_method_signature_filter, ms);
- MemberList props_instance = TypeContainer.FindMembers (
- parent.TypeBuilder.BaseType, MemberTypes.Property,
+ mi_instance = TypeContainer.FindMembers (
+ ptype, MemberTypes.Property,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
- MethodSignature.inheritable_property_signature_filter,
- base_ms);
+ MethodSignature.inheritable_method_signature_filter,
+ ms);
- //
- // Find if we have anything
- //
- if (props_static.Count > 0)
- props = props_static;
- else if (props_instance.Count > 0)
- props = props_instance;
+ if (mi_instance.Count > 0) {
+ mi = mi_instance;
+ } else if (mi_static.Count > 0)
+ mi = mi_static;
else
- props = null;
-
+ mi = null;
- //
- // If we have something on the base.
- if (props != null && props.Count > 0){
- PropertyInfo pi = (PropertyInfo) props [0];
+ if (mi != null && mi.Count > 0)\r
+ parent_member = (MethodInfo) mi [0];
+\r
+ if (parent_member is PropertyInfo) {
+ PropertyInfo parent_property = (PropertyInfo)parent_member;
- MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);
- MethodInfo inherited_set = TypeManager.GetPropertySetter (pi);
+ string name = parent_property.DeclaringType.Name + "." +
+ parent_property.Name;
- MethodInfo reference = inherited_get == null ?
- inherited_set : inherited_get;
-
- if (reference != null) {
- string name = reference.DeclaringType.Name + "." + report_name;
+ MethodInfo get, set, parent_method;
+ get = parent_property.GetGetMethod (true);
+ set = parent_property.GetSetMethod (true);
- if (!CheckMethodAgainstBase (parent, flags, reference, name))
- return false;
- }
+ if (get != null)
+ parent_method = get;
+ else if (set != null)
+ parent_method = set;
+ else
+ throw new Exception ("Internal error!");
- if (((ModFlags & Modifiers.NEW) == 0) && (pi.PropertyType != MemberType)) {
- Report.Error (508, parent.MakeName (Name) + ": cannot " +
- "change return type when overriding inherited " +
- "member `" + pi.DeclaringType + "." + pi.Name + "'");
+ if (!CheckMethodAgainstBase (container, flags, parent_method, name))
return false;
+
+ if ((ModFlags & Modifiers.NEW) == 0) {
+ Type parent_type = TypeManager.TypeToCoreType (
+ parent_property.PropertyType);
+
+ if (parent_type != MemberType) {
+ Report.Error (
+ 508, Location, container.MakeName (Name) + ": cannot " +
+ "change return type when overriding " +
+ "inherited member " + name);
+ return false;
+ }
}
- } else {
+ } else if (parent_member == null) {
/*if ((ModFlags & Modifiers.NEW) != 0)
- WarningNotHiding (parent);*/
-
- if ((ModFlags & Modifiers.OVERRIDE) != 0){
+ WarningNotHiding (container);
+ */
+ if ((ModFlags & Modifiers.OVERRIDE) != 0) {
if (this is Indexer)
Report.Error (115, Location,
- parent.MakeName (Name) +
- " no suitable indexers found to override");
+ container.MakeName (Name) +
+ " no suitable indexers found to override");
else
- Report.Error (30284, Location,
- parent.MakeName (Name) +
- " no suitable properties found to override");
+ Report.Error (115, Location,
+ container.MakeName (Name) +
+ " no suitable properties found to override");
return false;
}
if ((ModFlags & ( Modifiers.NEW | Modifiers.SHADOWS | Modifiers.OVERRIDE )) == 0) {
- if ((ModFlags & Modifiers.NONVIRTUAL) != 0) {
- Report.Error (31088, Location,
- parent.MakeName (Name) + " : Cannot " +
- "be declared NotOverridable since this 'Property' does " +
- "not 'Overrides' any other 'Property'");
- }
+ if ((ModFlags & Modifiers.NONVIRTUAL) != 0) {
+ Report.Error (31088, Location,
+ container.MakeName (Name) + " : Cannot " +
+ "be declared NotOverridable since this method is " +
+ "not maked as Overrides");
}
- // if a member of module is not inherited from Object class
- // can not be declared protected
- if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
- Report.Error (30503, Location,
- "'Property' inside a 'Module' can not be declared as " +
- "'Protected' or 'Protected Friend'");
+ }
+ // if a member of module is not inherited from Object class
+ // can not be declared protected
+ if ((container is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+ Report.Error (31066, Location,
+ "'Property' inside a 'Module' can not be declared as " +
+ "'Protected' or 'Protected Friend'");
}
return true;
}
"Property without 'Get' accessor must have a 'WriteOnly' modifier");
}
else {
- if (get_params == Parameters.EmptyReadOnlyParameters)
- {
+ if (get_params == Parameters.EmptyReadOnlyParameters) {
g_parameters = TypeManager.NoTypes;
g_ip = new InternalParameters (
parent, Parameters.EmptyReadOnlyParameters);
- }
- else
- {
+ } else {
g_parameters = new Type [get_params.FixedParameters.Length];
- for (int i = 0; i < get_params.FixedParameters.Length; i ++)
- {
+ for (int i = 0; i < get_params.FixedParameters.Length; i ++) {
g_parameters[i] = get_params.FixedParameters[i].ParameterType;
}
g_parms = new Parameter [get_params.FixedParameters.Length];
- for (int i = 0; i < get_params.FixedParameters.Length; i ++)
- {
+ for (int i = 0; i < get_params.FixedParameters.Length; i ++) {
Parameter tp = get_params.FixedParameters[i];
g_parms[i] = new Parameter (tp.TypeName, tp.Name,
Parameter.Modifier.NONE, null);
s_parms = new Parameter [1];
s_parms [0] = new Parameter (Type, set_parameter_name,
Parameter.Modifier.NONE, null);
- }
- else
- {
+ } else {
s_parameters = new Type [set_params.FixedParameters.Length];
- for (int i = 0; i < set_params.FixedParameters.Length; i ++)
- {
+ for (int i = 0; i < set_params.FixedParameters.Length; i ++) {
s_parameters[i] = set_params.FixedParameters[i].ParameterType;
}
s_parms = new Parameter [set_params.FixedParameters.Length];
- for (int i = 0; i < set_params.FixedParameters.Length; i ++)
- {
+ for (int i = 0; i < set_params.FixedParameters.Length; i ++) {
Parameter tp = set_params.FixedParameters[i];
s_parms[i] = new Parameter (tp.TypeName, tp.Name,
Parameter.Modifier.NONE, null);
// interface.cs: Interface handler
//
// Author: Miguel de Icaza (miguel@gnu.org)
+// Anirban Bhattacharjee (banirban@novell.com)
//
// Licensed under the terms of the GNU GPL
//
// (C) 2001 Ximian, Inc (http://www.ximian.com)
//
+
+/*This file will go off shortly
+ * after copying the interface class
+ * in class.cs file
+ */
+
#define CACHE
using System.Collections;
using System;
/// <summary>
/// Interfaces
/// </summary>
- public class Interface : DeclSpace, IMemberContainer {
- const MethodAttributes interface_method_attributes =
- MethodAttributes.Public |
- MethodAttributes.Abstract |
- MethodAttributes.HideBySig |
- MethodAttributes.NewSlot |
- MethodAttributes.Virtual;
-
- const MethodAttributes property_attributes =
- MethodAttributes.Public |
- MethodAttributes.Abstract |
- MethodAttributes.HideBySig |
- MethodAttributes.NewSlot |
- MethodAttributes.SpecialName |
- MethodAttributes.Virtual;
-
- ArrayList bases;
-
- ArrayList defined_method;
- ArrayList defined_indexer;
- ArrayList defined_events;
- ArrayList defined_properties;
-
- ArrayList method_builders;
- ArrayList property_builders;
- ArrayList event_builders;
-
- Attributes OptAttributes;
-
- public string IndexerName;
-
- IMemberContainer parent_container;
- MemberCache member_cache;
- bool members_defined;
- // These will happen after the semantic analysis
-
- // Hashtable defined_indexers;
- // Hashtable defined_methods;
-
+ /// <summary>
+ /// Interfaces
+ /// </summary>
+ public class Interface : Mono.MonoBASIC.Class /*TypeContainer , IMemberContainer */\r
+ {
/// <summary>
/// Modifiers allowed in a class declaration
/// </summary>
- public const int AllowedModifiers =
+ public new const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.INTERNAL |
- Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Interface (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (parent, name, l)
- {
- ModFlags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PUBLIC, l);
- OptAttributes = attrs;
-
- method_builders = new ArrayList ();
- property_builders = new ArrayList ();
- event_builders = new ArrayList ();
- }
-
- public AdditionResult AddMethod (InterfaceMethod imethod)
- {
- string name = imethod.Name;
- Object value = defined_names [name];
-
- if (value != null){
- if (!(value is InterfaceMethod))
- return AdditionResult.NameExists;
- }
-
- if (defined_method == null)
- defined_method = new ArrayList ();
-
- defined_method.Add (imethod);
- if (value == null)
- DefineName (name, imethod);
-
- return AdditionResult.Success;
- }
-
- public AdditionResult AddProperty (InterfaceProperty iprop)
- {
- AdditionResult res;
- string name = iprop.Name;
-
- if ((res = IsValid (name)) != AdditionResult.Success)
- return res;
-
- DefineName (name, iprop);
-
- if (defined_properties == null)
- defined_properties = new ArrayList ();
-
- defined_properties.Add (iprop);
- return AdditionResult.Success;
- }
-
- public AdditionResult AddEvent (InterfaceEvent ievent)
- {
- string name = ievent.Name;
- AdditionResult res;
-
- if ((res = IsValid (name)) != AdditionResult.Success)
- return res;
-
- DefineName (name, ievent);
-
- if (defined_events == null)
- defined_events = new ArrayList ();
-
- defined_events.Add (ievent);
- return AdditionResult.Success;
- }
-
- public bool AddIndexer (InterfaceIndexer iindexer)
+ public Interface (TypeContainer parent, string name, int mod,
+ Attributes attrs, Location l)
+ : base (parent, name, 0, null, l)
{
- if (defined_indexer == null)
- defined_indexer = new ArrayList ();
-
- defined_indexer.Add (iindexer);
- return true;
- }
-
- public ArrayList InterfaceMethods {
- get {
- return defined_method;
- }
- }
-
- public ArrayList InterfaceProperties {
- get {
- return defined_properties;
- }
- }
-
- public ArrayList InterfaceEvents {
- get {
- return defined_events;
- }
- }
-
- public ArrayList InterfaceIndexers {
- get {
- return defined_indexer;
- }
- }
-
- public ArrayList Bases {
- get {
- return bases;
- }
-
- set {
- bases = value;
- }
- }
-
- public virtual TypeAttributes InterfaceAttr {
- get {
- TypeAttributes x = TypeAttributes.Interface | TypeAttributes.Abstract;
-
- if (IsTopLevel == false) {
-
- if ((ModFlags & Modifiers.PROTECTED) != 0
- && (ModFlags & Modifiers.INTERNAL) != 0)
- x |= TypeAttributes.NestedFamORAssem;
- else if ((ModFlags & Modifiers.PROTECTED) != 0)
- x |= TypeAttributes.NestedFamily;
- else if ((ModFlags & Modifiers.INTERNAL) != 0)
- x |= TypeAttributes.NestedAssembly;
- else if ((ModFlags & Modifiers.PUBLIC) != 0)
- x |= TypeAttributes.NestedPublic;
- else
- x |= TypeAttributes.NestedPrivate;
- } else {
- if ((ModFlags & Modifiers.PUBLIC) != 0)
- x |= TypeAttributes.Public;
- else if ((ModFlags & Modifiers.PRIVATE) != 0)
- x |= TypeAttributes.NotPublic;
- }
-
- if ((ModFlags & Modifiers.ABSTRACT) != 0)
- x |= TypeAttributes.Abstract;
-
- if ((ModFlags & Modifiers.SEALED) != 0)
- x |= TypeAttributes.Sealed;
-
- return x;
- }
- }
-
- void Error111 (InterfaceMemberBase ib)
- {
- Report.Error (
- 111,
- "Interface `" + Name + "' already contains a definition with the " +
- "same return value and parameter types for member `" + ib.Name + "'");
- }
-
- bool RegisterMethod (MethodBase mb, InternalParameters ip, Type [] types)
- {
- if (!TypeManager.RegisterMethod (mb, ip, types))
- return false;
-
- method_builders.Add (mb);
- return true;
- }
-
- //
- // This might trigger a definition of the methods. This happens only
- // with Attributes, as Attribute classes are processed before interfaces.
- // Ideally, we should make everything just define recursively in terms
- // of its dependencies.
- //
- public MethodInfo [] GetMethods (TypeContainer container)
- {
- int n = 0;
-
- if (!members_defined){
- if (DefineMembers (container))
- n = method_builders.Count;
- } else
- n = method_builders.Count;
-
- MethodInfo [] mi = new MethodInfo [n];
-
- method_builders.CopyTo (mi, 0);
-
- return mi;
- }
-
- // Hack around System.Reflection as found everywhere else
- public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
- MemberFilter filter, object criteria)
- {
- ArrayList members = new ArrayList ();
-
- if ((mt & MemberTypes.Method) != 0) {
- foreach (MethodBuilder mb in method_builders)
- if (filter (mb, criteria))
- members.Add (mb);
- }
-
- if ((mt & MemberTypes.Property) != 0) {
- foreach (PropertyBuilder pb in property_builders)
- if (filter (pb, criteria))
- members.Add (pb);
- }
-
- if ((mt & MemberTypes.Event) != 0) {
- foreach (MyEventBuilder eb in event_builders)
- if (filter (eb, criteria))
- members.Add (eb);
- }
-
- if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
- MemberList parent_mi;
-
- parent_mi = TypeContainer.FindMembers (
- TypeBuilder.BaseType, mt, bf, filter, criteria);
-
- members.AddRange (parent_mi);
- }
-
- return new MemberList (members);
- }
-
- public override MemberCache MemberCache {
- get {
- return member_cache;
- }
- }
-
- //
- // Populates the methods in the interface
- //
- void PopulateMethod (TypeContainer parent, DeclSpace decl_space, InterfaceMethod im)
- {
- Type return_type = this.ResolveType (im.ReturnType, false, im.Location);
- Type [] arg_types = im.ParameterTypes (this);
- MethodBuilder mb;
- Parameter [] p;
- int i;
-
- if (return_type == null)
- return;
-
- if (return_type.IsPointer && !UnsafeOK (this))
- return;
-
- if (arg_types == null)
- return;
-
- foreach (Type t in arg_types){
-
- if (t == null)
- return;
-
- if (t.IsPointer && !UnsafeOK (this))
- return;
- }
-
- //
- // Create the method
- //
- mb = TypeBuilder.DefineMethod (
- im.Name, interface_method_attributes,
- return_type, arg_types);
-
- InternalParameters ip = new InternalParameters (arg_types, im.Parameters);
-
- if (!RegisterMethod (mb, ip, arg_types)) {
- Error111 (im);
- return;
- }
-
- //
- // Define each type attribute (in/out/ref) and
- // the argument names.
- //
- p = im.Parameters.FixedParameters;
- if (p != null){
- for (i = 0; i < p.Length; i++)
- mb.DefineParameter (i + 1, p [i].Attributes, p [i].Name);
-
- if (i != arg_types.Length)
- Console.WriteLine ("Implement the type definition for params");
- }
-
- EmitContext ec = new EmitContext (parent, decl_space, Location, null,
- return_type, ModFlags, false);
-
- if (im.OptAttributes != null)
- Attribute.ApplyAttributes (ec, mb, im, im.OptAttributes, Location);
- }
-
- //
- // Populates the properties in the interface
- //
- void PopulateProperty (TypeContainer parent, DeclSpace decl_space, InterfaceProperty ip)
- {
- PropertyBuilder pb;
- MethodBuilder get = null, set = null;
- ip.Type = this.ResolveTypeExpr (ip.Type, false, ip.Location);
- Type prop_type = ip.Type.Type;
- Type [] setter_args = new Type [1];
-
- if (prop_type == null)
- return;
-
- if (prop_type.IsPointer && !UnsafeOK (this))
- return;
-
- setter_args [0] = prop_type;
-
- //
- // FIXME: properties are missing the following
- // flags: hidebysig newslot specialname
- //
- pb = TypeBuilder.DefineProperty (
- ip.Name, PropertyAttributes.None,
- prop_type, null);
-
- if (ip.HasGet){
- get = TypeBuilder.DefineMethod (
- "get_" + ip.Name, property_attributes ,
- prop_type, null);
-
- //
- // HACK because System.Reflection.Emit is lame
- //
- Type [] null_types = null;
- InternalParameters inp = new InternalParameters
- (null_types, Parameters.EmptyReadOnlyParameters);
-
- if (!RegisterMethod (get, inp, null)) {
- Error111 (ip);
- return;
- }
-
- pb.SetGetMethod (get);
- }
-
- if (ip.HasSet){
- setter_args [0] = prop_type;
-
- set = TypeBuilder.DefineMethod (
- "set_" + ip.Name, property_attributes,
- TypeManager.void_type, setter_args);
-
- set.DefineParameter (1, ParameterAttributes.None, "value");
- pb.SetSetMethod (set);
-
- //
- // HACK because System.Reflection.Emit is lame
- //
- Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (ip.Type, "value", Parameter.Modifier.NONE, null);
- InternalParameters ipp = new InternalParameters (
- this, new Parameters (parms, null, Location.Null));
-
- if (!RegisterMethod (set, ipp, setter_args)) {
- Error111 (ip);
- return;
- }
- }
-
- EmitContext ec = new EmitContext (parent, decl_space, Location, null,
- null, ModFlags, false);
-
- if (ip.OptAttributes != null)
- Attribute.ApplyAttributes (ec, pb, ip, ip.OptAttributes, Location);
-
- TypeManager.RegisterProperty (pb, get, set);
- property_builders.Add (pb);
- }
-
- //
- // Populates the events in the interface
- //
- void PopulateEvent (TypeContainer parent, DeclSpace decl_space, InterfaceEvent ie)
- {
- //
- // FIXME: We need to do this after delegates have been
- // declared or we declare them recursively.
- //
- MyEventBuilder eb;
- MethodBuilder add = null, remove = null;
- ie.Type = this.ResolveTypeExpr (ie.Type, false, ie.Location);
- Type event_type = ie.Type.Type;
-
- if (event_type == null)
- return;
-
- if (event_type.IsPointer && !UnsafeOK (this))
- return;
-
- Type [] parameters = new Type [1];
- parameters [0] = event_type;
-
- eb = new MyEventBuilder (TypeBuilder, ie.Name,
- EventAttributes.None, event_type);
-
- //
- // Now define the accessors
- //
- string add_name = "add_" + ie.Name;
-
- add = TypeBuilder.DefineMethod (
- add_name, property_attributes, null, parameters);
- add.DefineParameter (1, ParameterAttributes.None, "value");
- eb.SetAddOnMethod (add);
-
- string remove_name = "remove_" + ie.Name;
- remove = TypeBuilder.DefineMethod (
- remove_name, property_attributes, null, parameters);
- remove.DefineParameter (1, ParameterAttributes.None, "value");
- eb.SetRemoveOnMethod (remove);
+ int accmods;
- Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (ie.Type, "value", Parameter.Modifier.NONE, null);
- InternalParameters ip = new InternalParameters (
- this, new Parameters (parms, null, Location.Null));
-
- if (!RegisterMethod (add, ip, parameters)) {
- Error111 (ie);
- return;
- }
-
- if (!RegisterMethod (remove, ip, parameters)) {
- Error111 (ie);
- return;
- }
-
- EmitContext ec = new EmitContext (parent, decl_space, Location, null,
- null, ModFlags, false);
-
-
- if (ie.OptAttributes != null)
- Attribute.ApplyAttributes (ec, eb, ie, ie.OptAttributes, Location);
-
- TypeManager.RegisterEvent (eb, add, remove);
- event_builders.Add (eb);
- }
-
- //
- // Populates the indexers in the interface
- //
- void PopulateIndexer (TypeContainer parent, DeclSpace decl_space, InterfaceIndexer ii)
- {
- PropertyBuilder pb;
- ii.Type = this.ResolveTypeExpr (ii.Type, false, ii.Location);
- Type prop_type = ii.Type.Type;
- Type [] arg_types = ii.ParameterTypes (this);
- Type [] value_arg_types;
-
- if (prop_type == null)
- return;
-
- if (prop_type.IsPointer && !UnsafeOK (this))
- return;
-
- //
- // Sets up the extra invisible `value' argument for setters.
- //
- if (arg_types != null){
- int count = arg_types.Length;
- value_arg_types = new Type [count + 1];
-
- arg_types.CopyTo (value_arg_types, 0);
- value_arg_types [count] = prop_type;
-
- foreach (Type t in arg_types){
- if (t.IsPointer && !UnsafeOK (this))
- return;
- }
- } else {
- value_arg_types = new Type [1];
-
- value_arg_types [1] = prop_type;
- }
-
- EmitContext ec = new EmitContext (parent, decl_space, Location, null,
- null, ModFlags, false);
-
- IndexerName = Attribute.ScanForIndexerName (ec, ii.OptAttributes);
- if (IndexerName == null)
- IndexerName = "Item";
-
- pb = TypeBuilder.DefineProperty (
- IndexerName, PropertyAttributes.None,
- prop_type, arg_types);
-
- MethodBuilder set_item = null, get_item = null;
- if (ii.HasGet){
- Parameter [] p = ii.Parameters.FixedParameters;
-
- get_item = TypeBuilder.DefineMethod (
- "get_" + IndexerName, property_attributes,
- prop_type, arg_types);
- pb.SetGetMethod (get_item);
- //
- // HACK because System.Reflection.Emit is lame
- //
- InternalParameters ip = new InternalParameters (
- arg_types, ii.Parameters);
-
- if (!RegisterMethod (get_item, ip, arg_types)) {
- Error111 (ii);
- return;
- }
-
- if (p != null){
- for (int i = 0; i < p.Length; i++)
- get_item.DefineParameter (
- i + 1,
- p [i].Attributes, p [i].Name);
- }
- }
-
- if (ii.HasSet){
- Parameter [] p = ii.Parameters.FixedParameters;
- Parameter [] pv;
- int i = 0;
-
- pv = new Parameter [p.Length + 1];
- p.CopyTo (pv, 0);
- pv [p.Length] = new Parameter (ii.Type, "value", Parameter.Modifier.NONE, null);
- Parameters value_params = new Parameters (pv, null, Location.Null);
- value_params.GetParameterInfo (decl_space);
-
- set_item = TypeBuilder.DefineMethod (
- "set_" + IndexerName, property_attributes,
- TypeManager.void_type, value_arg_types);
- pb.SetSetMethod (set_item);
- //
- // HACK because System.Reflection.Emit is lame
- //
- InternalParameters ip = new InternalParameters (
- value_arg_types, value_params);
- if (!RegisterMethod (set_item, ip, value_arg_types)) {
- Error111 (ii);
- return;
- }
-
- if (p != null){
- for (; i < p.Length; i++)
- set_item.DefineParameter (
- i + 1,
- p [i].Attributes, p [i].Name);
- }
-
- set_item.DefineParameter (i + 1, ParameterAttributes.None, "value");
- }
-
- if (ii.OptAttributes != null)
- Attribute.ApplyAttributes (ec, pb, ii, ii.OptAttributes, Location);
-
- property_builders.Add (pb);
- }
-
- /// <summary>
- /// Performs the semantic analysis for all the interface members
- /// that were declared
- /// </summary>
- bool SemanticAnalysis ()
- {
- Hashtable methods = new Hashtable ();
-
-
- if (defined_method != null){
- foreach (InterfaceMethod im in defined_method){
- string sig = im.GetSignature (this);
-
- //
- // If there was an undefined Type on the signatures
- //
- if (sig == null)
- continue;
-
- if (methods [sig] != null){
- Error111 (im);
- return false;
- }
- }
- }
-
- //
- // FIXME: Here I should check i
- //
- return true;
- }
-
- Type GetInterfaceTypeByName (string name)
- {
- Type t = FindType (Location, name);
-
- if (t == null) {
- Report.Error (246, Location, "The type or namespace `" + name +
- "' could not be found");
- return null;
- }
-
- if (t.IsInterface)
- return t;
-
- string cause;
-
- if (t.IsValueType)
- cause = "is a struct";
- else if (t.IsClass)
- cause = "is a class";
+ if (parent.Parent == null)
+ accmods = Modifiers.INTERNAL;
else
- cause = "Should not happen.";
-
- Report.Error (527, Location, "`"+name+"' " + cause +
- ", need an interface instead");
-
- return null;
- }
-
- //
- // Returns the list of interfaces that this interface implements
- // Or null if it does not implement any interface.
- //
- // Sets the error boolean accoringly.
- //
- Type [] GetInterfaceBases (out bool error)
- {
- Type [] tbases;
- int i;
-
- error = false;
- if (Bases == null)
- return null;
-
- tbases = new Type [Bases.Count];
- i = 0;
-
- foreach (string name in Bases){
- Type t;
-
- t = GetInterfaceTypeByName (name);
- if (t == null){
- error = true;
- return null;
- }
-
- if (!Parent.AsAccessible (t, ModFlags))
- Report.Error (61, Location,
- "Inconsistent accessibility: base interface `" +
- TypeManager.MonoBASIC_Name (t) + "' is less " +
- "accessible than interface `" +
- Name + "'");
-
- tbases [i++] = t;
- }
-
- return TypeManager.ExpandInterfaces (tbases);
- }
-
- //
- // <summary>
- // Defines the Interface in the appropriate ModuleBuilder or TypeBuilder
- // </summary>
- //
- // TODO:
- // Rework the way we recurse, because for recursive
- // definitions of interfaces (A:B and B:A) we report the
- // error twice, rather than once.
-
- public override TypeBuilder DefineType ()
- {
- Type [] ifaces;
- bool error;
-
- if (TypeBuilder != null)
- return TypeBuilder;
-
- if (InTransit)
- return null;
-
- InTransit = true;
-
- ifaces = GetInterfaceBases (out error);
+ accmods = Modifiers.PUBLIC;
- if (error)
- return null;
-
- if (IsTopLevel) {
- ModuleBuilder builder = CodeGen.ModuleBuilder;
-
- TypeBuilder = builder.DefineType (
- Name,
- InterfaceAttr,
- (Type)null, // Parent Type
- ifaces);
- RootContext.RegisterOrder (this);
- } else {
- TypeBuilder builder = Parent.TypeBuilder;
-
- TypeBuilder = builder.DefineNestedType (
- Basename,
- InterfaceAttr,
- (Type) null, //parent type
- ifaces);
-
- TypeContainer tc = TypeManager.LookupTypeContainer (builder);
- tc.RegisterOrder (this);
- }
-
- TypeManager.AddUserInterface (Name, TypeBuilder, this, ifaces);
- InTransit = false;
-
- return TypeBuilder;
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ this.ModFlags |= Modifiers.ABSTRACT;
+ this.attributes = attrs;
}
- //
- // Defines the indexers, and also verifies that the IndexerNameAttribute in the
- // interface is consistent. Either it is `Item' or it is the name defined by all the
- // indexers with the `IndexerName' attribute.
- //
- // Turns out that the IndexerNameAttribute is applied to each indexer,
- // but it is never emitted, instead a DefaultName attribute is attached
- // to the interface
- //
- void DefineIndexers (TypeContainer parent)
- {
- string interface_indexer_name = null;
-
- foreach (InterfaceIndexer ii in defined_indexer){
-
- PopulateIndexer (parent, this, ii);
-
- if (interface_indexer_name == null){
- interface_indexer_name = IndexerName;
- continue;
- }
-
- if (IndexerName == interface_indexer_name)
- continue;
-
- Report.Error (
- 668, "Two indexers have different names, " +
- " you should use the same name for all your indexers");
- }
- if (interface_indexer_name == null)
- interface_indexer_name = "Item";
- IndexerName = interface_indexer_name;
- }
-
- /// <summary>
- /// Performs semantic analysis, and then generates the IL interfaces
- /// </summary>
- public override bool DefineMembers (TypeContainer parent)
+ /*public override AttributeTargets AttributeTargets \r
{
- if (!SemanticAnalysis ())
- return false;
-
- if (defined_method != null){
- foreach (InterfaceMethod im in defined_method)
- PopulateMethod (parent, this, im);
+ get \r
+ {
+ return AttributeTargets.Interface;
}
+ }*/
- if (defined_properties != null){
- foreach (InterfaceProperty ip in defined_properties)
- PopulateProperty (parent, this, ip);
- }
-
- if (defined_events != null)
- foreach (InterfaceEvent ie in defined_events)
- PopulateEvent (parent, this, ie);
-
- if (defined_indexer != null) {
- DefineIndexers (parent);
-
- CustomAttributeBuilder cb = EmitDefaultMemberAttr (
- parent, IndexerName, ModFlags, Location);
- if (cb != null)
- TypeBuilder.SetCustomAttribute (cb);
- }
-
-#if CACHE
- if (TypeBuilder.BaseType != null)
- parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
-
- member_cache = new MemberCache (this);
-#endif
- members_defined = true;
- return true;
- }
-
- /// <summary>
- /// Applies all the attributes.
- /// </summary>
- public override bool Define (TypeContainer parent)
+ public override TypeAttributes TypeAttr \r
{
- if (OptAttributes != null) {
- EmitContext ec = new EmitContext (parent, this, Location, null, null,
- ModFlags, false);
- Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes, Location);
+ get \r
+ {
+ return base.TypeAttr |
+ TypeAttributes.AutoLayout |
+ TypeAttributes.Abstract |
+ TypeAttributes.Interface;
}
-
- return true;
- }
-
- public static CustomAttributeBuilder EmitDefaultMemberAttr (TypeContainer parent,
- string name,
- int flags,
- Location loc)
- {
- EmitContext ec = new EmitContext (parent, loc, null, null, flags);
-
- Expression ml = Expression.MemberLookup (ec, TypeManager.default_member_type,
- ".ctor", MemberTypes.Constructor,
- BindingFlags.Public | BindingFlags.Instance,
- Location.Null);
-
- if (!(ml is MethodGroupExpr)) {
- Console.WriteLine ("Internal error !!!!");
- return null;
- }
-
- MethodGroupExpr mg = (MethodGroupExpr) ml;
-
- MethodBase constructor = mg.Methods [0];
-
- string [] vals = { name };
-
- CustomAttributeBuilder cb = null;
- try {
- cb = new CustomAttributeBuilder ((ConstructorInfo) constructor, vals);
- } catch {
- Report.Warning (-100, "Can not set the indexer default member attribute");
- }
-
- return cb;
- }
-
- //
- // IMemberContainer
- //
-
- string IMemberContainer.Name {
- get {
- return Name;
- }
- }
-
- Type IMemberContainer.Type {
- get {
- return TypeBuilder;
- }
- }
-
- IMemberContainer IMemberContainer.Parent {
- get {
- return parent_container;
- }
- }
-
- MemberCache IMemberContainer.MemberCache {
- get {
- return member_cache;
- }
- }
-
- bool IMemberContainer.IsInterface {
- get {
- return true;
- }
- }
-
- MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
- {
- // Interfaces only contain instance members.
- if ((bf & BindingFlags.Instance) == 0)
- return MemberList.Empty;
- if ((bf & BindingFlags.Public) == 0)
- return MemberList.Empty;
-
- ArrayList members = new ArrayList ();
-
- if ((mt & MemberTypes.Method) != 0)
- members.AddRange (method_builders);
-
- if ((mt & MemberTypes.Property) != 0)
- members.AddRange (property_builders);
-
- if ((mt & MemberTypes.Event) != 0)
- members.AddRange (event_builders);
-
- return new MemberList (members);
}
}
+/*
public class InterfaceMemberBase {
public readonly string Name;
public readonly bool IsNew;
Location = loc;
}
}
-
- public class InterfaceEvent : InterfaceMemberBase {
+*/
+/* public class InterfaceEvent : InterfaceMemberBase {
public readonly Location Location;
public Expression Type;
Location = loc;
}
}
-
+/*
public class InterfaceMethod : InterfaceMemberBase {
public readonly Expression ReturnType;
public readonly Parameters Parameters;
{
return Parameters.GetParameterInfo (ds);
}
- }
+ }*/
}
// Mono.MonoBASIC.Parser.cs (from .jay): The Parser for the MonoBASIC compiler
//
// Author: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
+// Anirban Bhattacharjee (banirban@novell.com)
//
// Licensed under the terms of the GNU GPL
//
// Copyright (C) 2001 A Rafael D Teixeira
//
-// TODO:
-// Nearly everything
//
namespace Mono.MonoBASIC
END CLASS logical_end_of_line
{
Class new_class = (Class) current_container;
- new_class.Bases = (ArrayList) $4;
+
+ ArrayList bases = (ArrayList) $4;
+
+ ArrayList ifaces = (ArrayList) $5;
+ if (ifaces != null){
+ if (bases != null)
+ bases.AddRange(ifaces);
+ else
+ bases = ifaces;
+ }
+ new_class.Bases = bases;
current_container = current_container.Parent;
CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
interface_member_declaration
: interface_method_declaration
{
- InterfaceMethod m = (InterfaceMethod) $1;
-
+ Method m = (Method) $1;
CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
}
| interface_property_declaration
- {
- InterfaceProperty p = (InterfaceProperty) $1;
-
- CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
- }
- | interface_event_declaration
- {
- InterfaceEvent e = (InterfaceEvent) $1;
+ /*| interface_event_declaration
+ {
+ Event e = (Event) $1;
CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
- }
+ }*/
;
opt_new
;
interface_method_declaration
- : SUB identifier
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS logical_end_of_line
- {
- $$ = new InterfaceMethod (TypeManager.system_void_expr, (string) $2, false,
- (Parameters) $4, current_attributes, lexer.Location);
- }
- | FUNCTION identifier opt_type_character
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS AS type
+ : SUB identifier opt_params logical_end_of_line
{
- if ($3 != null && $3 != $8)
- Report.Error (-1, lexer.Location, "Type character conflicts with declared type."); // TODO: Correct error number and message text
+ current_modifiers |= Modifiers.ABSTRACT;
+
+ Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
+ (Parameters) $3, null, null, lexer.Location);
- $$ = new InterfaceMethod (
- (Expression) $8, (string) $2, false, (Parameters) $5,
- current_attributes, lexer.Location);
+ $$ = method;
}
- | FUNCTION identifier type_character
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ | FUNCTION identifier opt_type_character opt_params opt_type_with_ranks logical_end_of_line
{
- $$ = new InterfaceMethod (
- (Expression) $3, (string) $2, false, (Parameters) $5,
- current_attributes, lexer.Location);
+ Expression ftype = ($5 == null) ? (($3 == null) ? TypeManager.
+ system_object_expr : (Expression) $3 ) : (Expression) $5;
+
+ current_modifiers |= Modifiers.ABSTRACT;
+
+ Method method = new Method ((Expression) ftype, (int) current_modifiers,
+ (string) $2,(Parameters) $4, null, null,
+ lexer.Location);
+
+ $$ = method;
}
;
interface_property_declaration
- : opt_modifiers PROPERTY identifier
- OPEN_PARENS
- opt_formal_parameter_list
- CLOSE_PARENS opt_type_spec logical_end_of_line
+ : PROPERTY identifier opt_type_character opt_property_parameters AS type logical_end_of_line
{
- // FIXME we MUST pass property parameters
- $$ = new InterfaceProperty ((Expression) $6, (string) $2, false,
- true, true, current_attributes,
- lexer.Location);
+ Expression ftype = ($6 == null) ? (($3 == null) ?
+ TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
+
+ current_modifiers |= Modifiers.ABSTRACT;
+
+ current_local_parameters = (Parameters) $4;
+ if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
+ get_parameters = current_local_parameters.Copy (lexer.Location);
+ set_parameters = current_local_parameters.Copy (lexer.Location);
+
+ Parameter implicit_value_parameter = new Parameter (
+ ftype, "Value", Parameter.Modifier.NONE, null);
+
+ set_parameters.AppendParameter (implicit_value_parameter);
+ }
+ else
+ {
+ get_parameters = Parameters.EmptyReadOnlyParameters;
+ set_parameters = new Parameters (null, null ,lexer.Location);
+
+ Parameter implicit_value_parameter = new Parameter (
+ ftype, "Value", Parameter.Modifier.NONE, null);
+
+ set_parameters.AppendParameter (implicit_value_parameter);
+ }
+ lexer.PropertyParsing = true;
+
+ Accessor get_block = new Accessor (null, null);
+ Accessor set_block = new Accessor (null, null);
+
+ Property prop = new Property ((Expression) ftype, (string) $2, current_modifiers,
+ get_block, set_block, current_attributes, lexer.Location,
+ null, get_parameters, set_parameters, null);
+
+ CheckDef (current_interface.AddProperty (prop), prop.Name, lexer.Location);
+
+ get_implicit_value_parameter_type = null;
+ set_implicit_value_parameter_type = null;
+ get_parameters = null;
+ set_parameters = null;
+ current_local_parameters = null;
}
;
-interface_event_declaration
- : opt_attributes opt_new EVENT type identifier logical_end_of_line
+/*interface_event_declaration
+ : EVENT identifier AS type logical_end_of_line
{
$$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
- lexer.Location);
+ lexer.Location);
}
;
-
+*/
property_declaration
: abstruct_propery_declaration
| non_abstruct_propery_declaration
if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
get_parameters = current_local_parameters.Copy (lexer.Location);
set_parameters = current_local_parameters.Copy (lexer.Location);
+
+ Parameter implicit_value_parameter = new Parameter (
+ ftype, "Value", Parameter.Modifier.NONE, null);
+
+ set_parameters.AppendParameter (implicit_value_parameter);
}
else
{
variable_declarators logical_end_of_line
{
int mod = (int) current_modifiers;
-
VariableDeclaration.FixupTypes ((ArrayList) $2);
VariableDeclaration.FixupArrayTypes ((ArrayList) $2);