}
public MemberName (MemberName left, MemberName right)
- : this (left, right, left != null ? left.Location : right != null ? right.Location : Location.Null)
+ : this (left, right, right.Location)
{
}
/// Base representation for members. This is used to keep track
/// of Name, Location and Modifier flags, and handling Attributes.
/// </summary>
- public abstract class MemberCore : Attributable {
+ public abstract class MemberCore : Attributable, IResolveContext {
/// <summary>
/// Public name
/// </summary>
/// </summary>
public int ModFlags;
- public /*readonly*/ TypeContainer Parent;
+ public /*readonly*/ DeclSpace Parent;
/// <summary>
/// Location where this declaration happens
IsUsed = 1 << 11,
IsAssigned = 1 << 12 // Field is assigned
}
-
+
/// <summary>
/// MemberCore flags at first detected then cached
- /// </summary>
+ /// </summary>
internal Flags caching_flags;
- public MemberCore (TypeContainer parent, MemberName name, Attributes attrs)
+ public MemberCore (DeclSpace parent, MemberName name, Attributes attrs)
: base (attrs)
{
if (parent is PartialContainer && !(this is PartialContainer))
VerifyClsCompliance (Parent);
}
- public virtual EmitContext EmitContext
- {
- get {
- return Parent.EmitContext;
- }
- }
-
- public bool InUnsafe {
- get {
- return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
- }
+ public virtual EmitContext EmitContext {
+ get { return Parent.EmitContext; }
}
public virtual bool IsUsed {
- get {
- return (caching_flags & Flags.IsUsed) != 0;
- }
+ get { return (caching_flags & Flags.IsUsed) != 0; }
}
public void SetMemberIsUsed ()
caching_flags |= Flags.IsUsed;
}
- //
- // Whehter is it ok to use an unsafe pointer in this type container
- //
- public bool UnsafeOK (DeclSpace parent)
- {
- //
- // First check if this MemberCore modifier flags has unsafe set
- //
- if ((ModFlags & Modifiers.UNSAFE) != 0)
- return true;
-
- if (parent.UnsafeContext)
- return true;
-
- Expression.UnsafeError (Location);
- return false;
- }
-
/// <summary>
/// Returns instance of ObsoleteAttribute for this MemberCore
/// </summary>
return null;
Attribute obsolete_attr = OptAttributes.Search (
- TypeManager.obsolete_attribute_type, EmitContext);
+ TypeManager.obsolete_attribute_type);
if (obsolete_attr == null)
return null;
- ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (EmitContext);
+ ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute ();
if (obsolete == null)
return null;
/// <summary>
/// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
/// </summary>
- public override bool IsClsComplianceRequired (DeclSpace container)
+ public override bool IsClsComplianceRequired ()
{
if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
return (caching_flags & Flags.ClsCompliant) != 0;
- if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
+ if (GetClsCompliantAttributeValue (Parent) && IsExposedFromAssembly (Parent)) {
caching_flags &= ~Flags.ClsCompliance_Undetected;
caching_flags |= Flags.ClsCompliant;
return true;
{
if (OptAttributes != null) {
Attribute cls_attribute = OptAttributes.Search (
- TypeManager.cls_compliant_attribute_type, ds.EmitContext);
+ TypeManager.cls_compliant_attribute_type);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- return cls_attribute.GetClsCompliantAttributeValue (ds.EmitContext);
+ return cls_attribute.GetClsCompliantAttributeValue ();
}
}
return ds.GetClsCompliantAttributeValue ();
/// </summary>
protected virtual bool VerifyClsCompliance (DeclSpace ds)
{
- if (!IsClsComplianceRequired (ds)) {
+ if (!IsClsComplianceRequired ()) {
if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
if (!IsExposedFromAssembly (ds))
- Report.Warning (3019, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
+ Report.Warning (3019, 2, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
if (!CodeGen.Assembly.IsClsCompliant)
- Report.Warning (3021, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
+ Report.Warning (3021, 2, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
}
return false;
}
{
DocUtil.GenerateDocComment (this, ds);
}
+
+ public override IResolveContext ResolveContext {
+ get {
+ return this;
+ }
+ }
+
+ #region IResolveContext Members
+
+ public virtual DeclSpace DeclContainer {
+ get {
+ return Parent;
+ }
+ }
+
+ public bool IsInObsoleteScope {
+ get {
+ if (GetObsoleteAttribute () != null)
+ return true;
+
+ return Parent == null ? false : Parent.IsInObsoleteScope;
+ }
+ }
+
+ public bool IsInUnsafeScope {
+ get {
+ if ((ModFlags & Modifiers.UNSAFE) != 0)
+ return true;
+
+ return Parent == null ? false : Parent.IsInUnsafeScope;
+ }
+ }
+
+ #endregion
}
/// <summary>
protected EmitContext ec;
public override EmitContext EmitContext {
- get {
- return ec;
- }
+ get { return ec; }
}
//
static string[] attribute_targets = new string [] { "type" };
- public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
Attributes attrs)
: base (parent, name, attrs)
{
count_type_params += parent.count_type_params;
}
+ public override DeclSpace DeclContainer {
+ get {
+ return this;
+ }
+ }
+
/// <summary>
/// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
/// </summary>
if (symbol is TypeParameter)
Report.Error (694, symbol.Location,
"Type parameter `{0}' has same name as " +
- "containing type or method", name);
+ "containing type, or method", name);
else {
Report.SymbolRelatedToPreviousError (this);
Report.Error (542, symbol.Location,
/// Define all members, but don't apply any attributes or do anything which may
/// access not-yet-defined classes. This method also creates the MemberCache.
/// </summary>
- public virtual bool DefineMembers (TypeContainer parent)
+ public virtual bool DefineMembers ()
{
if (((ModFlags & Modifiers.NEW) != 0) && IsTopLevel) {
Report.Error (1530, Location, "Keyword `new' is not allowed on namespace elements");
}
public override string GetSignatureForError ()
- {
+ {
+ if (IsGeneric) {
+ return SimpleName.RemoveGenericArity (Name) + TypeParameter.GetSignatureForError (CurrentTypeParameters);
+ }
// Parent.GetSignatureForError
return Name;
}
- //
- // Whether this is an `unsafe context'
- //
- public bool UnsafeContext {
- get {
- if ((ModFlags & Modifiers.UNSAFE) != 0)
- return true;
- if (Parent != null)
- return Parent.UnsafeContext;
- return false;
- }
- }
-
EmitContext type_resolve_ec;
protected EmitContext TypeResolveEmitContext {
get {
//
// However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
//
- type_resolve_ec = new EmitContext (Parent, this, Location.Null, null, null, ModFlags, false);
+ type_resolve_ec = new EmitContext (this, Parent, this, Location.Null, null, null, ModFlags, false);
}
return type_resolve_ec;
}
// Resolves the expression `e' for a type, and will recursively define
// types. This should only be used for resolving base types.
// </summary>
- protected TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, Location loc)
+ protected TypeExpr ResolveBaseTypeExpr (Expression e)
{
- TypeResolveEmitContext.loc = loc;
- TypeResolveEmitContext.ResolvingTypeTree = true;
if (this is GenericMethod)
TypeResolveEmitContext.ContainerType = Parent.TypeBuilder;
- return e.ResolveAsTypeTerminal (TypeResolveEmitContext);
+ return e.ResolveAsTypeTerminal (TypeResolveEmitContext, false);
}
public bool CheckAccessLevel (Type check_type)
else
tb = TypeBuilder;
- if (check_type.IsGenericInstance)
- check_type = check_type.GetGenericTypeDefinition ();
-
+ check_type = TypeManager.DropGenericTypeArguments (check_type);
if (check_type == tb)
return true;
for (Type current_type = TypeBuilder;
current_type != null && current_type != TypeManager.object_type;
current_type = current_type.BaseType) {
- if (current_type.IsGenericInstance)
- current_type = current_type.GetGenericTypeDefinition ();
+ current_type = TypeManager.DropGenericTypeArguments (current_type);
if (current_type is TypeBuilder) {
DeclSpace decl = this;
if (current_type != TypeBuilder)
caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
if (OptAttributes != null) {
- Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, ec);
+ Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- if (cls_attribute.GetClsCompliantAttributeValue (ec)) {
+ if (cls_attribute.GetClsCompliantAttributeValue ()) {
caching_flags |= Flags.ClsCompliantAttributeTrue;
return true;
}
if (param.Name != name)
continue;
- if (RootContext.WarningLevel >= 3)
- Report.Warning (
- 693, Location,
- "Type parameter `{0}' has same name " +
- "as type parameter from outer type `{1}'",
- name, Parent.GetInstantiationName ());
+ Report.Warning (693, 3, Location,
+ "Type parameter `{0}' has same name as type parameter from outer type `{1}'",
+ name, Parent.GetInstantiationName ());
return false;
}
if (!is_generic) {
if (constraints_list != null) {
Report.Error (
- 80, Location, "Contraints are not allowed " +
+ 80, Location, "Constraints are not allowed " +
"on non-generic declarations");
}
return;
}
- string[] names = MemberName.TypeArguments.GetDeclarations ();
+ TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
type_params = new TypeParameter [names.Length];
//
// Register all the names
//
for (int i = 0; i < type_params.Length; i++) {
- string name = names [i];
+ TypeParameterName name = names [i];
Constraints constraints = null;
if (constraints_list != null) {
foreach (Constraints constraint in constraints_list) {
if (constraint == null)
continue;
- if (constraint.TypeParameter == name) {
+ if (constraint.TypeParameter == name.Name) {
constraints = constraint;
break;
}
}
type_params [i] = new TypeParameter (
- Parent, this, name, constraints, Location);
+ Parent, this, name.Name, constraints, name.OptAttributes,
+ Location);
- AddToContainer (type_params [i], name);
+ AddToContainer (type_params [i], name.Name);
}
}
}
}
- protected TypeParameter[] CurrentTypeParameters {
+ public TypeParameter[] CurrentTypeParameters {
get {
if (!IsGeneric)
throw new InvalidOperationException ();
Report.SymbolRelatedToPreviousError ((DeclSpace)val);
}
- Report.Warning (3005, Location, "Identifier `{0}' differing only in case is not CLS-compliant", GetSignatureForError ());
+ Report.Warning (3005, 1, Location, "Identifier `{0}' differing only in case is not CLS-compliant", GetSignatureForError ());
return true;
}
}
// method cache with all declared and inherited methods.
Type type = container.Type;
if (!(type is TypeBuilder) && !type.IsInterface &&
- // !(type.IsGenericInstance && (type.GetGenericTypeDefinition () is TypeBuilder)) &&
- !type.IsGenericInstance &&
+ // !(type.IsGenericType && (type.GetGenericTypeDefinition () is TypeBuilder)) &&
+ !type.IsGenericType &&
(Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
method_hash = new Hashtable ();
AddMethods (type);
// We need to call AddMembers() with a single member type at a time
// to get the member type part of CacheEntry.EntryType right.
if (!container.IsInterface) {
- AddMembers (MemberTypes.Constructor, container);
- AddMembers (MemberTypes.Field, container);
+ AddMembers (MemberTypes.Constructor, container);
+ AddMembers (MemberTypes.Field, container);
}
AddMembers (MemberTypes.Method, container);
AddMembers (MemberTypes.Property, container);
protected class CacheEntry {
public readonly IMemberContainer Container;
- public EntryType EntryType;
- public MemberInfo Member;
+ public readonly EntryType EntryType;
+ public readonly MemberInfo Member;
public CacheEntry (IMemberContainer container, MemberInfo member,
MemberTypes mt, BindingFlags bf)
static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
- MemberFilter filter, object criteria)
+ MemberFilter filter, object criteria)
{
if (using_global)
throw new Exception ();
}
} else {
mi = (MethodInfo) entry.Member;
- cmpAttrs = TypeManager.GetArgumentTypes (mi);
+ cmpAttrs = TypeManager.GetParameterData (mi).Types;
}
if (fi != null) {
MethodBase method_to_compare = (MethodBase)entry.Member;
AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
- method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare));
+ method.ParameterTypes, TypeManager.GetParameterData (method_to_compare).Types);
if (result == AttributeTester.Result.Ok)
continue;
// TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
// However it is exactly what csc does.
- if (md != null && !md.IsClsComplianceRequired (method.Parent))
+ if (md != null && !md.IsClsComplianceRequired ())
continue;
Report.SymbolRelatedToPreviousError (entry.Member);