// basenames in the defined_names array.
//
//
-#define CACHE
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Text;
-#if BOOTSTRAP_WITH_OLDLIB
+#if BOOTSTRAP_WITH_OLDLIB || NET_2_1
using XmlElement = System.Object;
#else
using System.Xml;
protected ArrayList initialized_static_fields;
// Holds the list of constants
- MemberCoreArrayList constants;
+ protected MemberCoreArrayList constants;
// Holds the methods.
MemberCoreArrayList methods;
// The base member cache and our member cache
MemberCache base_cache;
- MemberCache member_cache;
+ protected MemberCache member_cache;
public const string DefaultIndexerName = "Item";
public void AddMethod (Method method)
{
- if (!AddMember (method))
+ MemberName mn = method.MemberName;
+ if (!AddToContainer (method, mn.IsGeneric ? mn.Basename : mn.MethodName))
return;
-
+
if (methods == null)
methods = new MemberCoreArrayList ();
}
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
+ if (!AddToContainer (c, is_static ?
+ ConstructorBuilder.ConstructorName : ConstructorBuilder.TypeConstructorName))
+ return;
if (is_static){
if (default_static_constructor != null) {
- Report.SymbolRelatedToPreviousError (default_static_constructor);
- Report.Error (111, c.Location, Error111, c.GetSignatureForError ());
- return;
+ Report.SymbolRelatedToPreviousError (default_static_constructor);
+ Report.Error (111, c.Location,
+ "A member `{0}' is already defined. Rename this member or use different parameter types",
+ c.GetSignatureForError ());
+ return;
}
default_static_constructor = c;
} else {
- if (c.Parameters.Empty){
- if (default_constructor != null) {
- Report.SymbolRelatedToPreviousError (default_constructor);
- Report.Error (111, c.Location, Error111, c.GetSignatureForError ());
- return;
- }
+ if (c.Parameters.Empty)
default_constructor = c;
- }
if (instance_constructors == null)
instance_constructors = new MemberCoreArrayList ();
}
}
- internal static string Error111 {
- get {
- return "`{0}' is already defined. Rename this member or use different parameter types";
- }
- }
-
public bool AddField (FieldBase field)
{
if (!AddMember (field))
ConstructedType ct = base_type as ConstructedType;
if ((ct != null) && !ct.CheckConstraints (this))
return false;
+
+ member_cache = new MemberCache (base_type.Type, this);
+ } else if (Kind == Kind.Interface) {
+ member_cache = new MemberCache (null, this);
+ Type [] ifaces = TypeManager.GetInterfaces (TypeBuilder);
+ for (int i = 0; i < ifaces.Length; ++i)
+ member_cache.AddInterface (TypeManager.LookupMemberCache (ifaces [i]));
+ } else {
+ member_cache = new MemberCache (null, this);
+ }
+
+ if (types != null)
+ foreach (TypeContainer tc in types)
+ member_cache.AddNestedType (tc);
+
+ if (delegates != null)
+ foreach (Delegate d in delegates)
+ member_cache.AddNestedType (d);
+
+ if (partial_parts != null) {
+ foreach (TypeContainer part in partial_parts)
+ part.member_cache = member_cache;
}
if (!IsTopLevel) {
GenericType = CurrentType;
}
-#if CACHE
- member_cache = new MemberCache (this);
- if (partial_parts != null) {
- foreach (TypeContainer part in partial_parts)
- part.member_cache = member_cache;
- }
-#endif
+#if GMCS_SOURCE
+ //
+ // FIXME: This hack is needed because member cache does not work
+ // with generic types, we rely on runtime to inflate dynamic types.
+ // TODO: This hack requires member cache refactoring to be removed
+ //
+ if (TypeBuilder.IsGenericType)
+ member_cache = new MemberCache (this);
+#endif
return true;
}
//
// Since the whole process is a no-op, it is fine to check for null here.
//
+ // TODO: This approach will be one day completely removed, it's already
+ // used at few places only
+ //
+ //
public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
MemberFilter filter, object criteria)
{
if ((mc.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
continue;
- if (!mc.IsUsed) {
+ if (!mc.IsUsed && (mc.caching_flags & Flags.Excluded) == 0) {
Report.Warning (169, 3, mc.Location, "The private {0} `{1}' is never used", member_type, mc.GetSignatureForError ());
}
}
}
}
- MemberCache IMemberContainer.MemberCache {
- get {
- return member_cache;
- }
- }
-
bool IMemberContainer.IsInterface {
get {
return Kind == Kind.Interface;
get { return "T:"; }
}
- public virtual MemberCache BaseCache {
+ public MemberCache BaseCache {
get {
if (base_cache != null)
return base_cache;
if ((events != null) && Report.WarningLevel >= 3) {
foreach (Event e in events){
- if ((e.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
- continue;
-
+ // Note: The event can be assigned from same class only, so we can report
+ // this warning for all accessibility modes
if ((e.caching_flags & Flags.IsUsed) == 0)
Report.Warning (67, 3, e.Location, "The event `{0}' is never used", e.GetSignatureForError ());
}
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotISO1 (Location, "static classes");
+ Report.FeatureIsNotAvailable (Location, "static classes");
}
}
}
}
- if (IsStatic) {
+ if (PartialContainer.IsStaticClass) {
if (base_class.Type != TypeManager.object_type) {
Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object",
GetSignatureForError (), base_class.GetSignatureForError ());
if (ifaces != null) {
foreach (TypeExpr t in ifaces)
Report.SymbolRelatedToPreviousError (t.Type);
- Report.Error (714, Location, "`{0}': static classes cannot implement interfaces", GetSignatureForError ());
+ Report.Error (714, Location, "Static class `{0}' cannot implement interfaces", GetSignatureForError ());
}
}
{
}
- protected override bool CheckForDuplications ()
- {
- throw new NotSupportedException ();
- }
-
protected override bool VerifyClsCompliance ()
{
if (!base.VerifyClsCompliance ())
if (!DefineParameters (Parameters))
return false;
- if (!base.CheckBase ())
- return false;
-
- return true;
- }
-
- // TODO: create a special method for operators only to make code better
- protected bool IsDuplicateImplementation (MethodCore method)
- {
- if (method == this)
- return false;
-
- Operator op2 = null;
- Operator op1 = null;
-
- if (!(method.MemberName.Equals (MemberName)))
- {
- op1 = this as Operator;
- if (op1 == null || !(op1.OperatorType == Operator.OpType.Explicit || op1.OperatorType == Operator.OpType.Implicit))
- return false;
-
- op2 = method as Operator;
- if (op2 == null || !(op2.OperatorType == Operator.OpType.Explicit || op2.OperatorType == Operator.OpType.Implicit))
+ if ((caching_flags & Flags.MethodOverloadsExist) != 0) {
+ if (!Parent.MemberCache.CheckExistingMembersOverloads (this,
+ MemberName.IsGeneric ? MemberName.Basename : MemberName.MethodName, Parameters))
return false;
- } else {
- op1 = this as Operator;
- op2 = method as Operator;
- }
- Type[] param_types = method.ParameterTypes;
- // This never happen. Rewrite this as Equal
- if (param_types == null && ParameterTypes == null)
- return true;
- if (param_types == null || ParameterTypes == null)
- return false;
-
- if (param_types.Length != ParameterTypes.Length)
- return false;
-
- if (method.Parameters.HasArglist != Parameters.HasArglist)
- return false;
-
- bool equal = true;
-
- for (int i = 0; i < param_types.Length; i++) {
- if (param_types [i] != ParameterTypes [i])
- equal = false;
- }
-
- if (IsExplicitImpl && (method.InterfaceType != InterfaceType))
- equal = false;
-
- // TODO: make operator compatible with MethodCore to avoid this
- if (op1 != null && op2 != null) {
- if (MemberType != method.MemberType)
- equal = false;
- }
-
- if (!equal)
- return false;
-
- //
- // Try to report 663: method only differs on out/ref
- //
- Parameters info = ParameterInfo;
- Parameters other_info = method.ParameterInfo;
- for (int i = 0; i < info.Count; i++) {
- if (info.ParameterModifier (i) != other_info.ParameterModifier (i)) {
- Report.SymbolRelatedToPreviousError (method);
- Report.Error (663, Location, "`{0}': Methods cannot differ only on their use of ref and out on a parameters",
- GetSignatureForError ());
- return false;
+ // TODO: Find a better way how to check reserved accessors collision
+ Method m = this as Method;
+ if (m != null) {
+ if (!m.CheckForDuplications ())
+ return false;
}
}
- Report.SymbolRelatedToPreviousError (method);
- if (this is Operator && method is Operator)
- Report.Error (557, Location, "Duplicate user-defined conversion in type `{0}'", Parent.Name);
- else
- Report.Error (111, Location, TypeContainer.Error111, GetSignatureForError ());
+ if (!base.CheckBase ())
+ return false;
return true;
}
get { return "M:"; }
}
+ public override bool EnableOverloadChecks (MemberCore overload)
+ {
+ if (overload is MethodCore || overload is AbstractPropertyEventMethod) {
+ caching_flags |= Flags.MethodOverloadsExist;
+ return true;
+ }
+
+ return false;
+ }
+
public virtual void SetYields ()
{
ModFlags |= Modifiers.METHOD_YIELDS;
if (!base.CheckBase ())
return false;
- if ((caching_flags & Flags.TestMethodDuplication) != 0 && !CheckForDuplications ())
- return false;
-
if (IsExplicitImpl)
return true;
if ((base_classp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
//
// when overriding protected internal, the method can be declared
- // protected internal only within the same assembly
+ // protected internal only within the same assembly or assembly
+ // which has InternalsVisibleTo
//
-
if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
- if (Parent.TypeBuilder.Assembly != base_method.DeclaringType.Assembly){
- //
- // assemblies differ - report an error
- //
-
- return false;
- } else if (thisp != base_classp) {
+ if (Parent.TypeBuilder.Assembly != base_method.DeclaringType.Assembly)
+ return TypeManager.IsFriendAssembly (base_method.DeclaringType.Assembly);
+
+ if (thisp != base_classp) {
//
// same assembly, but other attributes differ - report an error
//
return false;
- };
+ }
} else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
//
// if it's not "protected internal", it must be "protected"
if (iface_texpr == null)
return false;
+ if ((ModFlags & Modifiers.PARTIAL) != 0) {
+ Report.Error (754, Location, "A partial method `{0}' cannot explicitly implement an interface",
+ GetSignatureForError ());
+ return false;
+ }
+
InterfaceType = iface_texpr.Type;
if (!InterfaceType.IsInterface) {
}
}
- /// <summary>
- /// For custom member duplication search in a container
- /// </summary>
- protected abstract bool CheckForDuplications ();
-
/// <summary>
/// Gets base method and its return type
/// </summary>
return;
}
- MethodBuilder.SetCustomAttribute (cb);
+ if (MethodBuilder != null)
+ MethodBuilder.SetCustomAttribute (cb);
}
public override AttributeTargets AttributeTargets {
if (!CheckAbstractAndExtern (block != null))
return false;
+ if ((ModFlags & Modifiers.PARTIAL) != 0) {
+ for (int i = 0; i < Parameters.Count; ++i ) {
+ if (Parameters.ParameterModifier (i) == Parameter.Modifier.OUT) {
+ Report.Error (752, Location, "`{0}': A partial method parameters cannot use `out' modifier",
+ GetSignatureForError ());
+ return false;
+ }
+ }
+ }
+
if (!CheckBase ())
return false;
+
+ if (IsPartialDefinition) {
+ caching_flags &= ~Flags.Excluded_Undetected;
+ caching_flags |= Flags.Excluded;
+ // Add to member cache only when a partial method implementation is not there
+ if ((caching_flags & Flags.MethodOverloadsExist) == 0) {
+ MethodBase mb = new PartialMethodDefinitionInfo (this);
+ Parent.MemberCache.AddMember (mb, this);
+ TypeManager.AddMethod (mb, this);
+ }
+
+ return true;
+ }
MethodData = new MethodData (
this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method);
if (!MethodData.Define (Parent.PartialContainer))
return false;
-
+
MethodBuilder = MethodData.MethodBuilder;
+#if GMCS_SOURCE
+ if (MethodBuilder.IsGenericMethod)
+ Parent.MemberCache.AddGenericMember (MethodBuilder, this);
+#endif
+
+ Parent.MemberCache.AddMember (MethodBuilder, this);
+
if (!TypeManager.IsGenericParameter (MemberType)) {
if (MemberType.IsAbstract && MemberType.IsSealed) {
Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
GetSignatureForError ());
}
- public override bool IsOverloadable {
+ public bool IsPartialDefinition {
get {
- return true;
+ return (ModFlags & Modifiers.PARTIAL) != 0 && Block == null;
+ }
+ }
+
+ public bool IsPartialImplementation {
+ get {
+ return (ModFlags & Modifiers.PARTIAL) != 0 && Block != null;
}
}
return true;
}
- IMethodData md = TypeManager.GetMethod (base_method);
+ IMethodData md = TypeManager.GetMethod (TypeManager.DropGenericMethodArguments (base_method));
if (md == null) {
if (AttributeTester.IsConditionalMethodExcluded (base_method)) {
caching_flags |= Flags.Excluded;
base.ApplyAttributeBuilder (a, cb);
}
- protected override bool CheckForDuplications ()
+ public bool CheckForDuplications ()
{
- ArrayList ar = Parent.PartialContainer.Methods;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Method m = (Method) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
-
- ar = Parent.PartialContainer.Properties;
+ ArrayList ar = Parent.PartialContainer.Properties;
if (ar != null) {
for (int i = 0; i < ar.Count; ++i) {
PropertyBase pb = (PropertyBase) ar [i];
}
}
- ar = Parent.PartialContainer.Events;
- if (ar != null) {
- for (int i = 0; i < ar.Count; ++i) {
- Event ev = (Event) ar [i];
- if (ev.AreAccessorsDuplicateImplementation (this))
- return false;
- }
- }
-
return true;
}
{
try {
Report.Debug (64, "METHOD EMIT", this, MethodBuilder, Location, Block, MethodData);
+ if (IsPartialDefinition) {
+ //
+ // Do attribute checks only when partial implementation does not exist
+ //
+ if (MethodBuilder == null)
+ base.Emit ();
+
+ return;
+ }
+
+ if ((ModFlags & Modifiers.PARTIAL) != 0 && (caching_flags & Flags.PartialDefinitionExists) == 0)
+ Report.Error (759, Location, "A partial method `{0}' implementation is missing a partial method declaration",
+ GetSignatureForError ());
+
MethodData.Emit (Parent);
base.Emit ();
}
}
+ public override bool EnableOverloadChecks (MemberCore overload)
+ {
+ // TODO: It can be deleted when members will be defined in correct order
+ if (overload is Operator)
+ return overload.EnableOverloadChecks (this);
+
+ if (overload is Indexer)
+ return false;
+
+ return base.EnableOverloadChecks (overload);
+ }
+
public static void Error1599 (Location loc, Type t)
{
Report.Error (1599, loc, "Method or delegate cannot return type `{0}'", TypeManager.CSharpName (t));
return mi;
}
+ public void SetPartialDefinition (Method methodDefinition)
+ {
+ caching_flags |= Flags.PartialDefinitionExists;
+ methodDefinition.MethodBuilder = MethodBuilder;
+ if (methodDefinition.attributes == null)
+ return;
+
+ if (attributes == null) {
+ attributes = methodDefinition.attributes;
+ } else {
+ attributes.Attrs.AddRange (methodDefinition.attributes.Attrs);
+ }
+ }
+
protected override bool VerifyClsCompliance ()
{
if (!base.VerifyClsCompliance ())
if (base_constructor_group == null)
return false;
-
+
base_constructor_group = base_constructor_group.OverloadResolve (
ec, argument_list, false, loc);
if (base_constructor_group == null)
return false;
-
+
ConstructorInfo base_ctor = (ConstructorInfo)base_constructor_group;
if (base_ctor == caller_builder){
return true;
}
- protected override bool CheckForDuplications ()
- {
- ArrayList ar = Parent.PartialContainer.InstanceConstructors;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Constructor m = (Constructor) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
- return true;
- }
-
protected override bool CheckBase ()
{
if ((ModFlags & Modifiers.STATIC) != 0) {
if (!DefineParameters (Parameters))
return false;
- if (!CheckForDuplications ())
- return false;
+ if ((caching_flags & Flags.MethodOverloadsExist) != 0)
+ Parent.MemberCache.CheckExistingMembersOverloads (this, ConstructorBuilder.ConstructorName,
+ Parameters);
if (Parent.PartialContainer.Kind == Kind.Struct) {
if (ParameterTypes.Length == 0) {
ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
}
+ Parent.MemberCache.AddMember (ConstructorBuilder, this);
TypeManager.AddMethod (ConstructorBuilder, this);
+
+ // It's here only to report an error
+ if ((ModFlags & Modifiers.METHOD_YIELDS) != 0) {
+ member_type = TypeManager.void_type;
+ Iterator.CreateIterator (this, Parent, null, ModFlags);
+ }
return true;
}
if (ParameterInfo.Count > 0) {
ArrayList al = (ArrayList)Parent.MemberCache.Members [".ctor"];
- if (al.Count > 3)
+ if (al.Count > 2)
MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
if (Parent.TypeBuilder.IsSubclassOf (TypeManager.attribute_type)) {
base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
{
if (RootContext.Version == LanguageVersion.ISO_1)
- Report.FeatureIsNotISO1 (loc, "fixed size buffers");
-
- if ((mod & Modifiers.VOLATILE) != 0)
- Modifiers.Error_InvalidModifier (loc, Modifiers.Name (Modifiers.VOLATILE));
+ Report.FeatureIsNotAvailable (loc, "fixed size buffers");
this.size_expr = size_expr;
}
RootContext.RegisterCompilerGeneratedType (fixed_buffer_type);
FieldBuilder = Parent.TypeBuilder.DefineField (Name, fixed_buffer_type, Modifiers.FieldAttr (ModFlags));
+
+ Parent.MemberCache.AddMember (FieldBuilder, this);
TypeManager.RegisterFieldBase (FieldBuilder, this);
return true;
{
}
+ bool CanBeVolatile ()
+ {
+#if GMCS_SOURCE
+ if (TypeManager.IsGenericParameter (MemberType)) {
+ GenericConstraints constraints = TypeManager.GetTypeParameterConstraints (MemberType);
+ if (constraints == null)
+ return false;
+
+ return constraints.IsReferenceType;
+ }
+#endif
+
+ if (!MemberType.IsValueType)
+ return true;
+
+ if (MemberType.IsEnum)
+ return true;
+
+ if (MemberType == TypeManager.bool_type || MemberType == TypeManager.char_type ||
+ MemberType == TypeManager.sbyte_type || MemberType == TypeManager.byte_type ||
+ MemberType == TypeManager.short_type || MemberType == TypeManager.ushort_type ||
+ MemberType == TypeManager.int32_type || MemberType == TypeManager.uint32_type ||
+ MemberType == TypeManager.float_type)
+ return true;
+
+ return false;
+ }
+
public override bool Define ()
{
if (!base.Define ())
return false;
if ((ModFlags & Modifiers.VOLATILE) != 0){
- if (!MemberType.IsClass){
- Type vt = MemberType;
-
- if (TypeManager.IsEnumType (vt))
- vt = TypeManager.EnumToUnderlying (MemberType);
-
- if (!((vt == TypeManager.bool_type) ||
- (vt == TypeManager.sbyte_type) ||
- (vt == TypeManager.byte_type) ||
- (vt == TypeManager.short_type) ||
- (vt == TypeManager.ushort_type) ||
- (vt == TypeManager.int32_type) ||
- (vt == TypeManager.uint32_type) ||
- (vt == TypeManager.char_type) ||
- (vt == TypeManager.float_type) ||
- (!vt.IsValueType))){
- Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'",
- GetSignatureForError (), TypeManager.CSharpName (vt));
- return false;
- }
+ if (!CanBeVolatile ()) {
+ Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'",
+ GetSignatureForError (), TypeManager.CSharpName (MemberType));
}
if ((ModFlags & Modifiers.READONLY) != 0){
Report.Error (678, Location, "`{0}': A field cannot be both volatile and readonly",
GetSignatureForError ());
- return false;
}
}
FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
- if (Parent.PartialContainer.Kind == Kind.Struct &&
- ((fa & FieldAttributes.Static) == 0) &&
- MemberType == Parent.TypeBuilder &&
- !TypeManager.IsBuiltinType (MemberType)){
- Report.Error (523, Location, "Struct member `" + Parent.Name + "." + Name +
- "' causes a cycle in the structure layout");
- return false;
- }
-
try {
FieldBuilder = Parent.TypeBuilder.DefineField (
Name, MemberType, Modifiers.FieldAttr (ModFlags));
+ Parent.MemberCache.AddMember (FieldBuilder, this);
TypeManager.RegisterFieldBase (FieldBuilder, this);
}
catch (ArgumentException) {
if (initializer != null)
((TypeContainer) Parent).RegisterFieldForInitialization (this,
new FieldInitializer (FieldBuilder, initializer));
+
+ if (Parent.PartialContainer.Kind == Kind.Struct && (fa & FieldAttributes.Static) == 0 &&
+ MemberType == Parent.TypeBuilder && !TypeManager.IsBuiltinType (MemberType) && initializer == null) {
+ Report.Error (523, Location, "Struct member `{0}' causes a cycle in the structure layout",
+ GetSignatureForError ());
+ return false;
+ }
+
return true;
}
method_data.Emit (parent);
}
+ public override bool EnableOverloadChecks (MemberCore overload)
+ {
+ // This can only happen with indexers and it will
+ // be catched as indexer difference
+ if (overload is AbstractPropertyEventMethod)
+ return true;
+
+ if (overload is MethodCore) {
+ caching_flags |= Flags.MethodOverloadsExist;
+ return true;
+ }
+ return false;
+ }
+
public override bool IsClsComplianceRequired()
{
return false;
anonymous_methods = accessor.AnonymousMethods;
if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotISO1 (Location, "access modifiers on properties");
+ Report.FeatureIsNotAvailable (Location, "access modifiers on properties");
}
}
}
}
- public override bool IsOverloadable {
- get {
- return true;
- }
- }
-
protected bool CheckForDuplications ()
{
- if ((caching_flags & Flags.TestMethodDuplication) == 0)
+ if ((caching_flags & Flags.MethodOverloadsExist) == 0)
return true;
-
- ArrayList ar = Parent.PartialContainer.Methods;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Method m = (Method) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
- return true;
+ return Parent.MemberCache.CheckExistingMembersOverloads (this, Name, ParameterInfo);
}
}
Modifiers.SEALED |
Modifiers.OVERRIDE |
Modifiers.ABSTRACT |
- Modifiers.UNSAFE |
+ Modifiers.UNSAFE |
Modifiers.EXTERN |
Modifiers.METHOD_YIELDS |
Modifiers.VIRTUAL;
Field field = new Field (
Parent, Type,
Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & Modifiers.STATIC),
- CompilerGeneratedClass.MakeName (null, "CompilerGeneratedField"),
- null, Location);
+ "<" + Name + ">k__BackingField", null, Location);
((TypeContainer)Parent).AddField (field);
// Make get block
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, attrs, define_set_first)
{
- if (RootContext.Version >= LanguageVersion.LINQ &&
- !is_iface &&
- (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
+ if (!is_iface && (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
get_block != null && get_block.Block == null &&
- set_block != null && set_block.Block == null)
+ set_block != null && set_block.Block == null) {
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (Location, "automatically implemented properties");
+
CreateAutomaticProperty (current_block, get_block, set_block);
+ }
if (get_block == null)
Get = new GetMethod (this);
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
MemberName.ToString (), PropertyAttributes.None, MemberType, null);
- if (!Get.IsDummy)
+ if (!Get.IsDummy) {
PropertyBuilder.SetGetMethod (GetBuilder);
-
- if (!Set.IsDummy)
+ Parent.MemberCache.AddMember (GetBuilder, Get);
+ }
+
+ if (!Set.IsDummy) {
PropertyBuilder.SetSetMethod (SetBuilder);
+ Parent.MemberCache.AddMember (SetBuilder, Set);
+ }
TypeManager.RegisterProperty (PropertyBuilder, this);
+ Parent.MemberCache.AddMember (PropertyBuilder, this);
return true;
}
if (!base.Define ())
return false;
- if (IsExplicitImpl)
- SetMemberIsUsed ();
-
+ SetMemberIsUsed ();
return true;
}
if (TypeManager.IsGenericType (MemberType))
SetMemberIsUsed();
+ if (Add.IsInterfaceImplementation)
+ SetMemberIsUsed ();
+
FieldBuilder = Parent.TypeBuilder.DefineField (
Name, MemberType,
FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
get { return null; }
}
+ public bool IsInterfaceImplementation {
+ get { return method_data.implementing != null; }
+ }
+
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
if (a.IsInternalMethodImplAttribute) {
EventBuilder = new MyEventBuilder (this, Parent.TypeBuilder, Name, EventAttributes.None, MemberType);
EventBuilder.SetAddOnMethod (AddBuilder);
EventBuilder.SetRemoveOnMethod (RemoveBuilder);
+
+ Parent.MemberCache.AddMember (EventBuilder, this);
+ Parent.MemberCache.AddMember (AddBuilder, Add);
+ Parent.MemberCache.AddMember (RemoveBuilder, Remove);
+
return true;
}
public class Indexer : PropertyBase
{
- public class GetIndexerMethod : GetMethod
+ class GetIndexerMethod : GetMethod
{
public GetIndexerMethod (PropertyBase method):
base (method)
base (method, accessor)
{
}
+
+ public override bool EnableOverloadChecks (MemberCore overload)
+ {
+ if (base.EnableOverloadChecks (overload)) {
+ overload.caching_flags |= Flags.MethodOverloadsExist;
+ return true;
+ }
+
+ return false;
+ }
public override Parameters ParameterInfo {
get {
}
}
- public class SetIndexerMethod: SetMethod
+ class SetIndexerMethod: SetMethod
{
public SetIndexerMethod (PropertyBase method):
base (method)
parameters = Parameters.MergeGenerated (((Indexer)method).parameters,
new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location));
}
+
+ public override bool EnableOverloadChecks (MemberCore overload)
+ {
+ if (base.EnableOverloadChecks (overload)) {
+ overload.caching_flags |= Flags.MethodOverloadsExist;
+ return true;
+ }
+
+ return false;
+ }
}
const int AllowedModifiers =
Set = new SetIndexerMethod (this, set_block);
}
- protected override bool CheckForDuplications ()
- {
- ArrayList ar = Parent.PartialContainer.Indexers;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Indexer m = (Indexer) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
-
- return true;
- }
-
- bool IsDuplicateImplementation (Indexer indexer)
- {
- if (this == indexer)
- return false;
-
- if (!MemberName.Equals (indexer.MemberName))
- return false;
-
- Type[] param_types = indexer.parameters.Types;
-
- // When it is not yet defined
- if (param_types == null)
- return false;
-
- if (param_types.Length != parameters.Count)
- return false;
-
- for (int i = 0; i < param_types.Length; i++)
- if (param_types [i] != parameters.Types [i])
- return false;
-
- Report.SymbolRelatedToPreviousError (indexer);
- Report.Error (111, Location, TypeContainer.Error111, indexer.GetSignatureForError ());
- return true;
- }
-
-
public override bool Define ()
{
if (!DoDefineBase ())
if (!CheckBase ())
return false;
+
+ if ((caching_flags & Flags.MethodOverloadsExist) != 0) {
+ if (!Parent.MemberCache.CheckExistingMembersOverloads (this, Name, parameters))
+ return false;
+ }
+
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
if (!DefineAccessors ())
//
// Now name the parameters
//
- Parameter [] p = parameters.FixedParameters;
- if (p != null) {
- // TODO: should be done in parser and it needs to do cycle
- if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
- CSharpParser.Error_ParameterModifierNotValid (Location);
- return false;
- }
- }
-
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
Name, PropertyAttributes.None, MemberType, parameters.Types);
-
- if (!Get.IsDummy)
+
+ if (!Get.IsDummy) {
PropertyBuilder.SetGetMethod (GetBuilder);
+ Parent.MemberCache.AddMember (GetBuilder, Get);
+ }
- if (!Set.IsDummy)
+ if (!Set.IsDummy) {
PropertyBuilder.SetSetMethod (SetBuilder);
+ Parent.MemberCache.AddMember (SetBuilder, Set);
+ }
TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder, parameters.Types);
-
+ Parent.MemberCache.AddMember (PropertyBuilder, this);
return true;
}
+ public override bool EnableOverloadChecks (MemberCore overload)
+ {
+ if (overload is Indexer) {
+ caching_flags |= Flags.MethodOverloadsExist;
+ return true;
+ }
+
+ return false;
+ }
+
public override string GetDocCommentName (DeclSpace ds)
{
return DocUtil.GetMethodDocCommentName (this, parameters, ds);
return sb.ToString ();
}
- public override bool IsOverloadable {
- get {
- return true;
- }
- }
-
protected override PropertyInfo ResolveBaseProperty ()
{
return Parent.PartialContainer.BaseCache.FindMemberToOverride (
base.ApplyAttributeBuilder (a, cb);
}
- protected override bool CheckForDuplications ()
- {
- ArrayList ar = Parent.PartialContainer.Operators;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Operator o = (Operator) ar [i];
- if (IsDuplicateImplementation (o))
- return false;
- }
- }
-
- ar = Parent.PartialContainer.Methods;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Method m = (Method) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
-
- return true;
- }
-
public override bool Define ()
{
const int RequiredModifiers = Modifiers.PUBLIC | Modifiers.STATIC;
return false;
}
- // imlicit and explicit operator of same types are not allowed
- if (OperatorType == OpType.Explicit || OperatorType == OpType.Implicit)
- EnableOverloadChecks ();
-
if (!base.Define ())
return false;
+ // imlicit and explicit operator of same types are not allowed
+ if (OperatorType == OpType.Explicit)
+ Parent.MemberCache.CheckExistingMembersOverloads (this, "op_Implicit", Parameters);
+ else if (OperatorType == OpType.Implicit)
+ Parent.MemberCache.CheckExistingMembersOverloads (this, "op_Explicit", Parameters);
+
if (MemberType == TypeManager.void_type) {
Report.Error (590, Location, "User-defined operators cannot return void");
return false;
Type declaring_type = MethodData.DeclaringType;
Type return_type = MemberType;
Type first_arg_type = ParameterTypes [0];
+
+ Type first_arg_type_unwrap = first_arg_type;
+ if (TypeManager.IsNullableType (first_arg_type))
+ first_arg_type_unwrap = TypeManager.GetTypeArguments (first_arg_type) [0];
+
+ Type return_type_unwrap = return_type;
+ if (TypeManager.IsNullableType (return_type))
+ return_type_unwrap = TypeManager.GetTypeArguments (return_type) [0];
+ //
// Rules for conversion operators
-
+ //
if (OperatorType == OpType.Implicit || OperatorType == OpType.Explicit) {
- if (first_arg_type == return_type && first_arg_type == declaring_type){
+ if (first_arg_type_unwrap == return_type_unwrap && first_arg_type_unwrap == declaring_type){
Report.Error (555, Location,
"User-defined operator cannot take an object of the enclosing type and convert to an object of the enclosing type");
return false;
}
Type conv_type;
- if (TypeManager.IsEqual (declaring_type, return_type)) {
- conv_type = first_arg_type;
- } else if (TypeManager.IsEqual (declaring_type, first_arg_type)) {
- conv_type = return_type;
- } else if (TypeManager.IsNullableTypeOf (return_type, declaring_type)) {
+ if (TypeManager.IsEqual (declaring_type, return_type) || declaring_type == return_type_unwrap) {
conv_type = first_arg_type;
- } else if (TypeManager.IsNullableTypeOf (first_arg_type, declaring_type)) {
+ } else if (TypeManager.IsEqual (declaring_type, first_arg_type) || declaring_type == first_arg_type_unwrap) {
conv_type = return_type;
} else {
Report.Error (556, Location,