GetSuperType() private method

private GetSuperType ( ) : IReflect
return IReflect
        internal override IReflect InferType(JSField inference_target)
        {
            if (this.method != null)
            {
                ParameterInfo[] parameters = this.method.GetParameters();
                if ((parameters != null) && (parameters.Length != 0))
                {
                    return(parameters[0].ParameterType);
                }
                return(this.method.ReturnType);
            }
            ScriptObject parent = base.Globals.ScopeStack.Peek();

            while (parent is WithObject)
            {
                parent = parent.GetParent();
            }
            if (parent is GlobalScope)
            {
                return(parent);
            }
            if (!(parent is FunctionScope) || !((FunctionScope)parent).isMethod)
            {
                return(Typeob.Object);
            }
            ClassScope scope = (ClassScope)((FunctionScope)parent).owner.enclosing_scope;

            if (this.isSuper)
            {
                return(scope.GetSuperType());
            }
            return(scope);
        }
Exemplo n.º 2
0
 internal void AddOverloadedMembers(MemberInfoList mems, ClassScope scope, BindingFlags attrs){
   JSMemberField field = this;
   while (field != null){
     MethodInfo meth = ((JSMemberField)field).GetAsMethod(scope);
     if (meth.IsStatic){
       if ((attrs & BindingFlags.Static) == 0) goto next;
     }else{
       if ((attrs & BindingFlags.Instance) == 0) goto next;
     }
     if (meth.IsPublic){
       if ((attrs & BindingFlags.Public) == 0) goto next;
     }else{
       if ((attrs & BindingFlags.NonPublic) == 0) goto next;
     }
     mems.Add(meth);
   next:
     field = field.nextOverload;
   }
   if ((attrs & BindingFlags.DeclaredOnly) != 0 && (attrs&BindingFlags.FlattenHierarchy) == 0) return;
   IReflect superClass = scope.GetSuperType();
   MemberInfo[] supMembers = superClass.GetMember(this.Name, attrs&~BindingFlags.DeclaredOnly);
   foreach (MemberInfo supMember in supMembers)
     if (supMember.MemberType == MemberTypes.Method)
       mems.Add(supMember);
 }
Exemplo n.º 3
0
        internal void AddOverloadedMembers(MemberInfoList mems, ClassScope scope, BindingFlags attrs)
        {
            JSMemberField field = this;

            while (field != null)
            {
                MethodInfo meth = ((JSMemberField)field).GetAsMethod(scope);
                if (meth.IsStatic)
                {
                    if ((attrs & BindingFlags.Static) == 0)
                    {
                        goto next;
                    }
                }
                else
                {
                    if ((attrs & BindingFlags.Instance) == 0)
                    {
                        goto next;
                    }
                }
                if (meth.IsPublic)
                {
                    if ((attrs & BindingFlags.Public) == 0)
                    {
                        goto next;
                    }
                }
                else
                {
                    if ((attrs & BindingFlags.NonPublic) == 0)
                    {
                        goto next;
                    }
                }
                mems.Add(meth);
next:
                field = field.nextOverload;
            }
            if ((attrs & BindingFlags.DeclaredOnly) != 0 && (attrs & BindingFlags.FlattenHierarchy) == 0)
            {
                return;
            }
            IReflect superClass = scope.GetSuperType();

            MemberInfo[] supMembers = superClass.GetMember(this.Name, attrs & ~BindingFlags.DeclaredOnly);
            foreach (MemberInfo supMember in supMembers)
            {
                if (supMember.MemberType == MemberTypes.Method)
                {
                    mems.Add(supMember);
                }
            }
        }
 internal void AddOverloadedMembers(MemberInfoList mems, ClassScope scope, BindingFlags attrs)
 {
     for (JSMemberField field = this; field != null; field = field.nextOverload)
     {
         MethodInfo asMethod = field.GetAsMethod(scope);
         if (asMethod.IsStatic)
         {
             if ((attrs & BindingFlags.Static) != BindingFlags.Default)
             {
                 goto Label_0020;
             }
             continue;
         }
         if ((attrs & BindingFlags.Instance) == BindingFlags.Default)
         {
             continue;
         }
     Label_0020:
         if (asMethod.IsPublic)
         {
             if ((attrs & BindingFlags.Public) != BindingFlags.Default)
             {
                 goto Label_0036;
             }
             continue;
         }
         if ((attrs & BindingFlags.NonPublic) == BindingFlags.Default)
         {
             continue;
         }
     Label_0036:
         mems.Add(asMethod);
     }
     if (((attrs & BindingFlags.DeclaredOnly) == BindingFlags.Default) || ((attrs & BindingFlags.FlattenHierarchy) != BindingFlags.Default))
     {
         foreach (MemberInfo info2 in scope.GetSuperType().GetMember(this.Name, attrs & ~BindingFlags.DeclaredOnly))
         {
             if (info2.MemberType == MemberTypes.Method)
             {
                 mems.Add(info2);
             }
         }
     }
 }
Exemplo n.º 5
0
        internal void AddOverloadedMembers(MemberInfoList mems, ClassScope scope, BindingFlags attrs)
        {
            for (JSMemberField field = this; field != null; field = field.nextOverload)
            {
                MethodInfo asMethod = field.GetAsMethod(scope);
                if (asMethod.IsStatic)
                {
                    if ((attrs & BindingFlags.Static) != BindingFlags.Default)
                    {
                        goto Label_0020;
                    }
                    continue;
                }
                if ((attrs & BindingFlags.Instance) == BindingFlags.Default)
                {
                    continue;
                }
Label_0020:
                if (asMethod.IsPublic)
                {
                    if ((attrs & BindingFlags.Public) != BindingFlags.Default)
                    {
                        goto Label_0036;
                    }
                    continue;
                }
                if ((attrs & BindingFlags.NonPublic) == BindingFlags.Default)
                {
                    continue;
                }
Label_0036:
                mems.Add(asMethod);
            }
            if (((attrs & BindingFlags.DeclaredOnly) == BindingFlags.Default) || ((attrs & BindingFlags.FlattenHierarchy) != BindingFlags.Default))
            {
                foreach (MemberInfo info2 in scope.GetSuperType().GetMember(this.Name, attrs & ~BindingFlags.DeclaredOnly))
                {
                    if (info2.MemberType == MemberTypes.Method)
                    {
                        mems.Add(info2);
                    }
                }
            }
        }
Exemplo n.º 6
0
        internal override IReflect InferType(JSField inference_target)
        {
            Debug.Assert(Globals.TypeRefs.InReferenceContext(this.method));
            if (this.method != null)
            {
                ParameterInfo[] pars = this.method.GetParameters();
                if (pars == null || pars.Length == 0)
                {
                    return(this.method.ReturnType);
                }
                else
                {
                    return(pars[0].ParameterType);
                }
            }
            ScriptObject top = Globals.ScopeStack.Peek();

            while (top is WithObject)
            {
                top = top.GetParent();
            }
            if (top is GlobalScope)
            {
                return(top);
            }
            else if (top is FunctionScope && ((FunctionScope)top).isMethod)
            {
                ClassScope csc = (ClassScope)((FunctionScope)top).owner.enclosing_scope;
                if (this.isSuper)
                {
                    return(csc.GetSuperType());
                }
                else
                {
                    return(csc);
                }
            }
            return(Typeob.Object);
        }
Exemplo n.º 7
0
        private void BindName(JSField inferenceTarget)
        {
            MemberInfo[] members = null;
            this.rootObject = this.rootObject.PartiallyEvaluate();
            IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget);

            if (this.rootObject is ConstantWrapper)
            {
                Object ob = Convert.ToObject2(this.rootObject.Evaluate(), this.Engine);
                if (ob == null)
                {
                    this.rootObject.context.HandleError(JSError.ObjectExpected);
                    return;
                }
                ClassScope csc = ob as ClassScope;
                Type       t   = ob as Type;
                if (csc != null || t != null)
                {
                    //object is a type. Look for static members on the type only. If none are found, look for instance members on type Type.
                    if (csc != null)
                    {
                        this.members = members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    else
                    {
                        this.members = members = t.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    if (members.Length > 0)
                    {
                        return;             //found a binding
                    }
                    //Look for instance members on type Type
                    this.members = members = Typeob.Type.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance);
                    return;
                }
                Namespace ns = ob as Namespace;
                if (ns != null)
                {
                    String fullname = ns.Name + "." + this.name;
                    csc = this.Engine.GetClass(fullname);
                    if (csc != null)
                    {
                        FieldAttributes attrs = FieldAttributes.Literal;
                        if ((csc.owner.attributes & TypeAttributes.Public) == 0)
                        {
                            attrs |= FieldAttributes.Private;
                        }
                        this.members = new MemberInfo[] { new JSGlobalField(null, this.name, csc, attrs) };
                        return;
                    }
                    else
                    {
                        t = this.Engine.GetType(fullname);
                        if (t != null)
                        {
                            this.members = new MemberInfo[] { t };
                            return;
                        }
                    }
                }
                else if (ob is MathObject || ob is ScriptFunction && !(ob is FunctionObject)) //It is a built in constructor function
                {
                    obType = (IReflect)ob;
                }
            }
            obType = this.ProvideWrapperForPrototypeProperties(obType);

            //Give up and go late bound if not enough is known about the object at compile time.
            if (obType == Typeob.Object && !this.isNonVirtual) //The latter provides for super in classes that extend System.Object
            {
                this.members = new MemberInfo[0];
                return;
            }

            Type ty = obType as Type;

            //Interfaces are weird, call a helper
            if (ty != null && ty.IsInterface)
            {
                this.members = JSBinder.GetInterfaceMembers(this.name, ty);
                return;
            }
            ClassScope cs = obType as ClassScope;

            if (cs != null && cs.owner.isInterface)
            {
                this.members = cs.owner.GetInterfaceMember(this.name);
                return;
            }

            //Now run up the inheritance chain until a member is found
            while (obType != null)
            {
                cs = obType as ClassScope;
                if (cs != null)
                {
                    //The FlattenHierachy flag here tells ClassScope to add in any overloads found on base classes
                    members = this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy);
                    if (members.Length > 0)
                    {
                        return;
                    }
                    obType = cs.GetSuperType();
                    continue;
                }
                ty = obType as Type;
                if (ty == null) //Dealing with the global scope via the this literal or with a built in object in fast mode
                {
                    this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance);
                    return;
                }
                members = this.members = ty.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (members.Length > 0)
                {
                    MemberInfo mem = LateBinding.SelectMember(members);
                    if (mem == null)
                    {
                        //Found a method or methods. Need to add any overloads found in base classes.
                        //Do another lookup, this time with the DeclaredOnly flag cleared and asking only for methods
                        members = this.members = ty.GetMember(this.name, MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        if (members.Length == 0) //Dealing with an indexed property, ask again
                        {
                            this.members = ty.GetMember(this.name, MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        }
                    }
                    return;
                }
                obType = ty.BaseType;
            }
        }
Exemplo n.º 8
0
        private void BindName(JSField inferenceTarget)
        {
            MemberInfo[] mems = null;
            this.rootObject = this.rootObject.PartiallyEvaluate();
            IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget);

            if (this.rootObject is ConstantWrapper)
            {
                object obj2 = Microsoft.JScript.Convert.ToObject2(this.rootObject.Evaluate(), base.Engine);
                if (obj2 == null)
                {
                    this.rootObject.context.HandleError(JSError.ObjectExpected);
                    return;
                }
                ClassScope scope = obj2 as ClassScope;
                Type       type  = obj2 as Type;
                if ((scope != null) || (type != null))
                {
                    if (scope != null)
                    {
                        base.members = mems = scope.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    else
                    {
                        base.members = mems = type.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    if (mems.Length <= 0)
                    {
                        base.members = mems = Typeob.Type.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance);
                    }
                    return;
                }
                Namespace namespace2 = obj2 as Namespace;
                if (namespace2 != null)
                {
                    string className = namespace2.Name + "." + base.name;
                    scope = base.Engine.GetClass(className);
                    if (scope != null)
                    {
                        FieldAttributes literal = FieldAttributes.Literal;
                        if ((scope.owner.attributes & TypeAttributes.Public) == TypeAttributes.AnsiClass)
                        {
                            literal |= FieldAttributes.Private;
                        }
                        base.members = new MemberInfo[] { new JSGlobalField(null, base.name, scope, literal) };
                        return;
                    }
                    type = base.Engine.GetType(className);
                    if (type != null)
                    {
                        base.members = new MemberInfo[] { type };
                        return;
                    }
                }
                else if ((obj2 is MathObject) || ((obj2 is ScriptFunction) && !(obj2 is FunctionObject)))
                {
                    obType = (IReflect)obj2;
                }
            }
            obType = this.ProvideWrapperForPrototypeProperties(obType);
            if ((obType == Typeob.Object) && !base.isNonVirtual)
            {
                base.members = new MemberInfo[0];
            }
            else
            {
                Type t = obType as Type;
                if ((t != null) && t.IsInterface)
                {
                    base.members = JSBinder.GetInterfaceMembers(base.name, t);
                }
                else
                {
                    ClassScope scope2 = obType as ClassScope;
                    if ((scope2 != null) && scope2.owner.isInterface)
                    {
                        base.members = scope2.owner.GetInterfaceMember(base.name);
                    }
                    else
                    {
                        while (obType != null)
                        {
                            scope2 = obType as ClassScope;
                            if (scope2 != null)
                            {
                                mems = base.members = obType.GetMember(base.name, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                                if (mems.Length > 0)
                                {
                                    return;
                                }
                                obType = scope2.GetSuperType();
                            }
                            else
                            {
                                t = obType as Type;
                                if (t == null)
                                {
                                    base.members = obType.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance);
                                    return;
                                }
                                mems = base.members = t.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                                if (mems.Length > 0)
                                {
                                    if (LateBinding.SelectMember(mems) == null)
                                    {
                                        mems = base.members = t.GetMember(base.name, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                        if (mems.Length == 0)
                                        {
                                            base.members = t.GetMember(base.name, MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                        }
                                    }
                                    return;
                                }
                                obType = t.BaseType;
                            }
                        }
                    }
                }
            }
        }