// Author: Miguel de Icaza (miguel@gnu.org)
// Marek Safar (marek.safar@seznam.cz)
//
-// Licensed under the terms of the GNU GPL
+// Dual licensed under the terms of the MIT X11 or GNU GPL
//
-// (C) 2001 Ximian, Inc (http://www.ximian.com)
-// (C) 2004 Novell, Inc
+// Copyright 2001 Ximian, Inc (http://www.ximian.com)
+// Copyright 2004-2008 Novell, Inc
//
// TODO: Move the method verification stuff from the class.cs and interface.cs here
//
return MakeName (Name, TypeArguments);
}
- public Expression GetTypeExpression ()
+ public ATypeNameExpression GetTypeExpression ()
{
if (Left == null) {
if (TypeArguments != null)
if (is_double_colon) {
if (Left.Left != null)
throw new InternalErrorException ("The left side of a :: should be an identifier");
- return new QualifiedAliasMember (Left.Name, Basename, Location);
+ return new QualifiedAliasMember (Left.Name, Name, TypeArguments, Location);
}
Expression lexpr = Left.GetTypeExpression ();
}
}
- public string FullName {
- get {
- if (TypeArguments != null)
- return Name + "<" + TypeArguments + ">";
- else
- return Name;
- }
- }
-
public string MethodName {
get {
string connect = is_double_colon ? "::" : ".";
if (Left != null)
- return Left.FullName + connect + Name;
+ return Left.FullyQualifiedName + connect + Name;
else
return Name;
}
}
-
+
+ // Please use this only for error reporting. For normal uses, just use the Equals and GetHashCode methods that make
+ // MemberName a proper hash key, and avoid tons of memory allocations
+ string FullyQualifiedName {
+ get { return TypeArguments == null ? MethodName : MethodName + "<" + TypeArguments.GetSignatureForError () + ">"; }
+ }
+
public string GetSignatureForError ()
{
- if (TypeArguments != null)
- return MethodName + "<" + TypeArguments.GetSignatureForError () + ">";
-
- return MethodName;
+ string append = TypeArguments == null ? "" : "<" + TypeArguments.GetSignatureForError () + ">";
+ if (Left == null)
+ return Name + append;
+ string connect = is_double_colon ? "::" : ".";
+ return Left.GetSignatureForError () + connect + Name + append;
}
public override bool Equals (object other)
}
return true;
- }
+ }
+
+ public void CheckProtectedModifier ()
+ {
+ if ((ModFlags & Modifiers.PROTECTED) == 0)
+ return;
+
+ if (Parent.PartialContainer.Kind == Kind.Struct) {
+ Report.Error (666, Location, "`{0}': Structs cannot contain protected members",
+ GetSignatureForError ());
+ return;
+ }
+
+ if ((Parent.ModFlags & Modifiers.STATIC) != 0) {
+ Report.Error (1057, Location, "`{0}': Static classes cannot contain protected members",
+ GetSignatureForError ());
+ return;
+ }
+
+ if (((Parent.ModFlags & Modifiers.SEALED) != 0) &&
+ ((ModFlags & Modifiers.OVERRIDE) == 0) && (Name != "Finalize")) {
+ Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class",
+ GetSignatureForError ());
+ return;
+ }
+ }
public abstract bool Define ();
switch (pAccess) {
case AccessLevel.Internal:
if (al == AccessLevel.Private || al == AccessLevel.Internal)
- same_access_restrictions = CodeGen.Assembly.Builder == p.Assembly || TypeManager.IsFriendAssembly (p.Assembly);
+ same_access_restrictions = TypeManager.IsThisOrFriendAssembly (p.Assembly);
break;
if (al == AccessLevel.Protected)
same_access_restrictions = mc.Parent.IsBaseType (p_parent);
else if (al == AccessLevel.Internal)
- same_access_restrictions = CodeGen.Assembly.Builder == p.Assembly || TypeManager.IsFriendAssembly (p.Assembly);
+ same_access_restrictions = TypeManager.IsThisOrFriendAssembly (p.Assembly);
else if (al == AccessLevel.ProtectedOrInternal)
same_access_restrictions = mc.Parent.IsBaseType (p_parent) &&
- (CodeGen.Assembly.Builder == p.Assembly || TypeManager.IsFriendAssembly (p.Assembly));
+ TypeManager.IsThisOrFriendAssembly (p.Assembly);
break;
public TypeContainer PartialContainer;
- readonly bool is_generic;
+ protected readonly bool is_generic;
readonly int count_type_params;
- readonly int count_current_type_params;
//
// Whether we are Generic
PartialContainer = null;
if (name.TypeArguments != null) {
is_generic = true;
- count_type_params = count_current_type_params = name.TypeArguments.Count;
+ count_type_params = name.TypeArguments.Count;
}
if (parent != null)
count_type_params += parent.count_type_params;
type.GetSignatureForError ());
}
+ public override void Emit ()
+ {
+#if GMCS_SOURCE
+ if (type_params != null) {
+ int offset = count_type_params - type_params.Length;
+ for (int i = offset; i < type_params.Length; i++)
+ CurrentTypeParameters [i - offset].Emit ();
+ }
+#endif
+
+ base.Emit ();
+ }
+
public override string GetSignatureForError ()
{
if (IsGeneric) {
- return SimpleName.RemoveGenericArity (Name) + TypeParameter.GetSignatureForError (CurrentTypeParameters);
+ return SimpleName.RemoveGenericArity (Name) + TypeParameter.GetSignatureForError (type_params);
}
// Parent.GetSignatureForError
return Name;
// However, this is invoked again later -- so safe to return true.
// May also be null when resolving top-level attributes.
return true;
- //
- // This test should probably use the declaringtype.
- //
- return check_type.Assembly == TypeBuilder.Assembly ||
- TypeManager.IsFriendAssembly (check_type.Assembly);
+
+ return TypeManager.IsThisOrFriendAssembly (check_type.Assembly);
case TypeAttributes.NestedPublic:
return true;
return FamilyAccessible (tb, check_type);
case TypeAttributes.NestedFamANDAssem:
- return ((check_type.Assembly == tb.Assembly) ||
- TypeManager.IsFriendAssembly (check_type.Assembly)) &&
+ return TypeManager.IsThisOrFriendAssembly (check_type.Assembly) &&
FamilyAccessible (tb, check_type);
case TypeAttributes.NestedFamORAssem:
- return (check_type.Assembly == tb.Assembly) ||
- FamilyAccessible (tb, check_type) ||
- TypeManager.IsFriendAssembly (check_type.Assembly);
+ return FamilyAccessible (tb, check_type) ||
+ TypeManager.IsThisOrFriendAssembly (check_type.Assembly);
case TypeAttributes.NestedAssembly:
- return check_type.Assembly == tb.Assembly ||
- TypeManager.IsFriendAssembly (check_type.Assembly);
+ return TypeManager.IsThisOrFriendAssembly (check_type.Assembly);
}
Console.WriteLine ("HERE: " + check_attr);
return null;
}
- public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name)
+ public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
return null;
}
//
// Extensions for generics
//
- TypeParameter[] type_params;
+ protected TypeParameter[] type_params;
TypeParameter[] type_param_list;
- protected string GetInstantiationName ()
- {
- StringBuilder sb = new StringBuilder (Name);
- sb.Append ("<");
- for (int i = 0; i < type_param_list.Length; i++) {
- if (i > 0)
- sb.Append (",");
- sb.Append (type_param_list [i].Name);
- }
- sb.Append (">");
- return sb.ToString ();
- }
-
bool check_type_parameter (ArrayList list, int start, string name)
{
for (int i = 0; i < start; i++) {
get {
if (!IsGeneric)
throw new InvalidOperationException ();
- if ((PartialContainer != null) && (PartialContainer != this))
- return PartialContainer.CurrentTypeParameters;
- if (type_params != null)
- return type_params;
- else
+
+ // TODO: Something is seriously broken here
+ if (type_params == null)
return new TypeParameter [0];
+
+ return type_params;
}
}
}
}
- public int CountCurrentTypeParameters {
- get {
- return count_current_type_params;
- }
- }
-
public TypeParameterExpr LookupGeneric (string name, Location loc)
{
if (!IsGeneric)
//
// Check for assembly methods
//
- if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder && !TypeManager.IsFriendAssembly (mi.DeclaringType.Assembly))
+ if (!TypeManager.IsThisOrFriendAssembly (mi.DeclaringType.Assembly))
continue;
break;
}