Ejemplo n.º 1
0
        public void CheckMemberVisibility(AstNode node, ScopeMember member)
        {
            // Ignore placeholder types.
            if(member.IsType())
            {
                IChelaType type = (IChelaType)member;
                if(type.IsPlaceHolderType())
                    return;
            }

            // Special treatment for scope member.
            if(member.IsScope())
            {
                CheckScopeVisibility(node, (Scope)member);
                return;
            }

            // Check the parent scope access.
            Scope parentScope = member.GetParentScope();
            if(parentScope != null)
                CheckScopeVisibility(node, parentScope);

            // Check the actual member visibility.
            if(member.IsPrivate())
            {
                // Walk the scope hierarchy.
                Scope scope = currentScope;
                while(scope != null)
                {
                    // Found the defining scope, stop checking.
                    if(scope == parentScope ||
                       parentScope.IsInstanceOf(scope))
                        return;

                    // Found the scope.
                    scope = scope.GetParentScope();
                }

                // Couldn't find scope, raise error.
                Error(node, "cannot access private member " + member.GetFullName());
            }
            else if(member.IsProtected())
            {
                // The parent scope must be a Structure derivative.
                Structure parentBuilding = (Structure)parentScope;

                // Walk the scope hierarchy.
                Scope scope = currentScope;
                while(scope != null)
                {
                    // Found the defining scope, stop checking.
                    if(scope is Structure)
                    {
                        Structure derived = (Structure)scope;
                        if(derived == parentBuilding ||
                           derived.IsDerivedFrom(parentBuilding))
                            return;
                    }

                    // Found the scope.
                    scope = scope.GetParentScope();
                }

                // Couldn't find scope, raise error.
                Error(node, "cannot access protected member " + member.GetFullName());
            }
            else if(member.IsInternal())
            {
                if(member.GetModule() != currentModule)
                    Error(node, "cannot access internal member " + member.GetFullName() + " of another module.");
            }
        }
Ejemplo n.º 2
0
 private bool CheckTypeHint(ScopeMember value, bool typeHint)
 {
     return value != null && (!typeHint || value.IsType() || value.IsNamespace() || value.IsTypeName());
 }