public bool IsAccessible(IAccessibleMember member)
        {
            if (member.IsPublic)
            {
                return(true);
            }

            IInternalEntity internalEntity = GetInternalEntity(member);

            if (null != internalEntity)
            {
                internalEntity.Node.RemoveAnnotation("PrivateMemberNeverUsed");
                if (member.IsInternal)
                {
                    return(true);
                }
            }

            IType declaringType = member.DeclaringType;

            if (declaringType == CurrentType())
            {
                return(true);
            }

            if (member.IsProtected && CurrentType().IsSubclassOf(declaringType))
            {
                return(true);
            }

            return(IsDeclaredInside(declaringType));
        }
        override public void LeaveMemberReferenceExpression(MemberReferenceExpression node)
        {
            if (AstUtil.IsLhsOfAssignment(node))
            {
                return;
            }
            IAccessibleMember member = GetAccessibleMemberToReplace(node);

            if (null == member)
            {
                return;
            }

            IMethod accessor = GetMemberAccessor(member);

            if (member.EntityType == EntityType.Field)
            {
                ReplaceCurrentNode(
                    _context.CodeBuilder.CreateMethodInvocation(
                        node.Target,
                        accessor));
            }
            else
            {
                node.Entity = accessor;
            }
        }
        override public void LeaveBinaryExpression(BinaryExpression node)
        {
            if (node.Operator != BinaryOperatorType.Assign)
            {
                return;
            }

            MemberReferenceExpression mre = node.Left as MemberReferenceExpression;

            if (null == mre)
            {
                return;
            }

            IAccessibleMember member = GetAccessibleMemberToReplace(mre);

            if (null == member)
            {
                return;
            }

            ReplaceCurrentNode(
                _context.CodeBuilder.CreateMethodInvocation(
                    mre.Target,
                    GetFieldSetter((IField)member),
                    node.Right));
        }
        IMethod NewAccessor(IDictionary cache, IAccessibleMember member, Method accessor)
        {
            _externalType.Members.Add(accessor);
            IMethod entity = (IMethod)accessor.Entity;

            cache.Add(member, entity);
            return(entity);
        }
 public bool IsAccessible(IAccessibleMember member)
 {
     if (member.IsPublic)
     {
         return(true);
     }
     return(member.IsInternal && member is IInternalEntity);
 }
Beispiel #6
0
		static IInternalEntity GetInternalEntity(IAccessibleMember member)
		{
			if (member is IInternalEntity)
				return (IInternalEntity) member;

			IGenericMappedMember gmp = member as IGenericMappedMember;
			if (null != gmp && gmp.SourceMember is IInternalEntity)
				return (IInternalEntity) gmp.SourceMember;

			return null;
		}
        public bool IsAccessible(IAccessibleMember member)
        {
            if (member.IsPublic) return true;

            IType declaringType = member.DeclaringType;
            if (declaringType == CurrentType()) return true;
            if (member.IsInternal && member is IInternalEntity) return true;
            if (member.IsProtected && CurrentType().IsSubclassOf(declaringType)) return true;

            return IsDeclaredInside(declaringType);
        }
        Method CreateAccessorFor(IAccessibleMember member)
        {
            switch (member.EntityType)
            {
            case EntityType.Field:
                return(CreateFieldAccessor((IField)member));

            case EntityType.Method:
                return(CreateMethodAccessor((IMethod)member));
            }
            throw new System.ArgumentException("Unsupported member:" + member);
        }
Beispiel #9
0
 public static TypeMemberModifiers GetAccess(IAccessibleMember member)
 {
     if (member.IsPublic)
     {
         return(TypeMemberModifiers.Public);
     }
     else if (member.IsProtected)
     {
         return(TypeMemberModifiers.Protected);
     }
     return(TypeMemberModifiers.Private);
 }
        IMethod GetMemberAccessor(IAccessibleMember member)
        {
            IDictionary accessors = GetDictionary(AccessorsKey);
            IMethod     accessor  = (IMethod)accessors[member];

            if (null != accessor)
            {
                return(accessor);
            }

            return(NewAccessor(accessors, member, CreateAccessorFor(member)));
        }
Beispiel #11
0
        override public void OnReferenceExpression(ReferenceExpression node)
        {
            IAccessibleMember member = node.Entity as IAccessibleMember;

            if (null == member)
            {
                return;
            }

            if (_checker.IsAccessible(member))
            {
                return;
            }
            Error(CompilerErrorFactory.UnaccessibleMember(node, member.FullName));
        }
        static IInternalEntity GetInternalEntity(IAccessibleMember member)
        {
            if (member is IInternalEntity)
            {
                return((IInternalEntity)member);
            }

            IGenericMappedMember gmp = member as IGenericMappedMember;

            if (null != gmp && gmp.SourceMember is IInternalEntity)
            {
                return((IInternalEntity)gmp.SourceMember);
            }

            return(null);
        }
        IAccessibleMember GetAccessibleMemberToReplace(MemberReferenceExpression node)
        {
            IAccessibleMember member = node.Entity as IAccessibleMember;

            if (member == null)
            {
                return(null);
            }
            if (member.IsPublic || member.IsInternal)
            {
                return(null);
            }
            if (IsCurrentType(member.DeclaringType))
            {
                return(null);
            }
            return(member);
        }
Beispiel #14
0
		public bool IsAccessible(IAccessibleMember member)
		{
			if (member.IsPublic)
				return true;

			IInternalEntity internalEntity = GetInternalEntity(member);
			if (null != internalEntity)
			{
				internalEntity.Node.RemoveAnnotation("PrivateMemberNeverUsed");
				if (member.IsInternal)
					return true;
			}

			IType declaringType = member.DeclaringType;
			if (declaringType == CurrentType())
				return true;

			if (member.IsProtected && CurrentType().IsSubclassOf(declaringType))
				return true;

			return IsDeclaredInside(declaringType);
		}
Beispiel #15
0
        override public void LeaveMemberReferenceExpression(MemberReferenceExpression node)
        {
            IAccessibleMember member = node.Entity as IAccessibleMember;

            if (null == member)
            {
                return;
            }
            if (member.IsPublic)
            {
                return;
            }

            IType declaringType = member.DeclaringType;

            if (declaringType == _currentType)
            {
                return;
            }
            if (member.IsInternal && member is IInternalEntity)
            {
                return;
            }
            if (member.IsProtected)
            {
                if (_currentType.IsSubclassOf(declaringType))
                {
                    return;
                }
            }

            if (IsDeclaredInside(declaringType))
            {
                return;
            }
            Error(CompilerErrorFactory.UnaccessibleMember(node, member.FullName));
        }
Beispiel #16
0
        public bool IsAccessible(IAccessibleMember member)
        {
            if (member.IsPublic)
            {
                return(true);
            }

            IType declaringType = member.DeclaringType;

            if (declaringType == CurrentType())
            {
                return(true);
            }
            if (member.IsInternal && member is IInternalEntity)
            {
                return(true);
            }
            if (member.IsProtected && CurrentType().IsSubclassOf(declaringType))
            {
                return(true);
            }

            return(IsDeclaredInside(declaringType));
        }
Beispiel #17
0
 private bool IsAccessible(IAccessibleMember accessible)
 {
     return GetAccessibilityChecker().IsAccessible(accessible);
 }
Beispiel #18
0
 private static bool IsVisible(IAccessibleMember member)
 {
     // TODO: should it just be IsAccessible(member) here?
     return member.IsPublic || member.IsInternal;
 }
Beispiel #19
0
 public static CompilerError UnaccessibleMember(Node node, IAccessibleMember name)
 {
     return(Instantiate("BCE0120", node, name));
 }
 public bool IsAccessible(IAccessibleMember member)
 {
     if (member.IsPublic) return true;
     return member.IsInternal && member is IInternalEntity;
 }
Beispiel #21
0
		public static TypeMemberModifiers GetAccess(IAccessibleMember member)
		{
			if (member.IsPublic)
				return TypeMemberModifiers.Public;
			if (member.IsProtected)
			{
				if (member.IsInternal)
					return TypeMemberModifiers.Protected | TypeMemberModifiers.Internal;
				return TypeMemberModifiers.Protected;
			}
			if (member.IsInternal)
				return TypeMemberModifiers.Internal;
			return TypeMemberModifiers.Private;
		}
Beispiel #22
0
 public static CompilerError UnaccessibleMember(Node node, IAccessibleMember name)
 {
     return Instantiate("BCE0120", node, name);
 }
	    private bool IsAccessible(IAccessibleMember member)
	    {
	        return _checker.IsAccessible(member);
	    }
 private bool IsAccessible(IAccessibleMember method)
 {
     return GetAccessibilityChecker().IsAccessible(method);
 }
Beispiel #25
0
 public static TypeMemberModifiers GetAccess(IAccessibleMember member)
 {
     if (member.IsPublic)
     {
         return TypeMemberModifiers.Public;
     }
     else if (member.IsProtected)
     {
         return TypeMemberModifiers.Protected;
     }
     return TypeMemberModifiers.Private;
 }
Beispiel #26
0
 private bool IsAccessible(IAccessibleMember member)
 {
     return(_checker.IsAccessible(member));
 }