IsSameOrDerivedFrom() private method

private IsSameOrDerivedFrom ( ClassScope other ) : bool
other ClassScope
return bool
Example #1
0
        //Adds a list of classes to result. Superclasses always follow derived classes.

        internal void AddClassesExcluding(ClassScope excludedClass, String name, ArrayList result)
        {
            ArrayList eligibleClasses = new ArrayList();

            foreach (MemberInfo member in this.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (member is JSVariableField && ((JSVariableField)member).IsLiteral)
                {
                    Object val = ((JSVariableField)member).value;
                    if (val is ClassScope)
                    {
                        ClassScope csc = (ClassScope)val;
                        if (csc.name != member.Name)
                        {
                            continue;
                        }
                        if (excludedClass == null || !excludedClass.IsSameOrDerivedFrom(csc))
                        {
                            if (csc.GetMember(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).Length > 0)
                            {
                                eligibleClasses.Add(csc);
                            }
                        }
                    }
                }
            }
            if (eligibleClasses.Count == 0)
            {
                return;
            }
            ClassScope[] classes = new ClassScope[eligibleClasses.Count]; eligibleClasses.CopyTo(classes);
            Array.Sort(classes);
            result.AddRange(classes);
        }
 internal void AddClassesExcluding(ClassScope excludedClass, string name, ArrayList result)
 {
     ArrayList list = new ArrayList();
     foreach (MemberInfo info in this.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
     {
         if ((info is JSVariableField) && ((JSVariableField) info).IsLiteral)
         {
             object obj2 = ((JSVariableField) info).value;
             if (obj2 is ClassScope)
             {
                 ClassScope other = (ClassScope) obj2;
                 if (((other.name == info.Name) && ((excludedClass == null) || !excludedClass.IsSameOrDerivedFrom(other))) && (other.GetMember(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Length > 0))
                 {
                     list.Add(other);
                 }
             }
         }
     }
     if (list.Count != 0)
     {
         ClassScope[] array = new ClassScope[list.Count];
         list.CopyTo(array);
         Array.Sort<ClassScope>(array);
         result.AddRange(array);
     }
 }
Example #3
0
      //Adds a list of classes to result. Superclasses always follow derived classes.

      internal void AddClassesExcluding(ClassScope excludedClass, String name, ArrayList result){
        ArrayList eligibleClasses = new ArrayList();
        foreach (MemberInfo member in this.GetMembers(BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)){
          if (member is JSVariableField && ((JSVariableField)member).IsLiteral){
            Object val = ((JSVariableField)member).value;
            if (val is ClassScope){
              ClassScope csc = (ClassScope)val;
              if (csc.name != member.Name) continue;
              if (excludedClass == null || !excludedClass.IsSameOrDerivedFrom(csc))
                if (csc.GetMember(name, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly).Length > 0)
                  eligibleClasses.Add(csc);
            }
          }
        }
        if (eligibleClasses.Count == 0) return;
        ClassScope[] classes = new ClassScope[eligibleClasses.Count]; eligibleClasses.CopyTo(classes);
        Array.Sort(classes);
        result.AddRange(classes);
      }
Example #4
0
        private void TranslateToILObjectForMember(ILGenerator il, Type obType, bool noValue, MemberInfo mem)
        {
            this.thereIsAnObjectOnTheStack = true;
            if (mem is IWrappedMember)
            {
                Object obj = ((IWrappedMember)mem).GetWrappedObject();
                if (obj is LenientGlobalObject)
                {
                    this.EmitILToLoadEngine(il);
                    il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
                }
                else if (obj is Type || obj is ClassScope)
                {
                    if (obType.IsAssignableFrom(Typeob.Type))
                    {
                        (new ConstantWrapper(obj, null)).TranslateToIL(il, Typeob.Type);
                        return;
                    }
                    //this.name is the name of an instance member of the superclass of the class (or an outer class) in which this expression appears
                    //get class instance on stack
                    ScriptObject scope = Globals.ScopeStack.Peek();
                    while (scope is WithObject || scope is BlockScope)
                    {
                        scope = scope.GetParent();
                    }
                    if (scope is FunctionScope)
                    {
                        FunctionObject func = ((FunctionScope)scope).owner;
                        if (func.isMethod)
                        {
                            il.Emit(OpCodes.Ldarg_0);
                        }
                        else //Need to get the StackFrame.closureInstance on the stack
                        {
                            this.EmitILToLoadEngine(il);
                            il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                            scope = this.Globals.ScopeStack.Peek();
                            while (scope is WithObject || scope is BlockScope)
                            {
                                il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                                scope = scope.GetParent();
                            }
                            il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                            il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                        }
                    }
                    else if (scope is ClassScope)
                    {
                        il.Emit(OpCodes.Ldarg_0); //Inside instance initializer
                    }

                    //If dealing with a member of an outer class, get the outer class instance on the stack
                    scope = Globals.ScopeStack.Peek();
                    while (scope != null)
                    {
                        ClassScope csc = scope as ClassScope;
                        if (csc != null) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                        {
                            if (csc.IsSameOrDerivedFrom(obType))
                            {
                                break;
                            }
                            il.Emit(OpCodes.Ldfld, csc.outerClassField);
                        }
                        scope = scope.GetParent();
                    }
                }
                else
                {
                    this.TranslateToILDefaultThisObject(il, this.lexLevel);
                    Convert.Emit(this, il, Typeob.Object, obType);
                }
            }
            else
            {
                ScriptObject scope = Globals.ScopeStack.Peek();
                while (scope is WithObject || scope is BlockScope)
                {
                    scope = scope.GetParent();
                }
                if (scope is FunctionScope)
                {
                    FunctionObject func = ((FunctionScope)scope).owner;
                    if (!func.isMethod) //Need to get the StackFrame.closureInstance on the stack
                    {
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                        scope = this.Globals.ScopeStack.Peek();
                        while (scope is WithObject || scope is BlockScope)
                        {
                            il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                            scope = scope.GetParent();
                        }
                        il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                        il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                        while (scope != null)
                        {
                            if (scope is ClassScope) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                            {
                                ClassScope csc = (ClassScope)scope;
                                if (csc.IsSameOrDerivedFrom(obType))
                                {
                                    break;
                                }
                                il.Emit(OpCodes.Castclass, csc.GetTypeBuilder());
                                il.Emit(OpCodes.Ldfld, csc.outerClassField);
                            }
                            scope = scope.GetParent();
                        }
                        il.Emit(OpCodes.Castclass, obType);
                        return;
                    }
                }
                il.Emit(OpCodes.Ldarg_0);
                while (scope != null)
                {
                    if (scope is ClassScope) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                    {
                        ClassScope csc = (ClassScope)scope;
                        if (csc.IsSameOrDerivedFrom(obType))
                        {
                            break;
                        }
                        il.Emit(OpCodes.Ldfld, csc.outerClassField);
                    }
                    scope = scope.GetParent();
                }
            }
        }
        internal void AddClassesExcluding(ClassScope excludedClass, string name, ArrayList result)
        {
            ArrayList list = new ArrayList();

            foreach (MemberInfo info in this.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
            {
                if ((info is JSVariableField) && ((JSVariableField)info).IsLiteral)
                {
                    object obj2 = ((JSVariableField)info).value;
                    if (obj2 is ClassScope)
                    {
                        ClassScope other = (ClassScope)obj2;
                        if (((other.name == info.Name) && ((excludedClass == null) || !excludedClass.IsSameOrDerivedFrom(other))) && (other.GetMember(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Length > 0))
                        {
                            list.Add(other);
                        }
                    }
                }
            }
            if (list.Count != 0)
            {
                ClassScope[] array = new ClassScope[list.Count];
                list.CopyTo(array);
                Array.Sort <ClassScope>(array);
                result.AddRange(array);
            }
        }
 private void TranslateToILObjectForMember(ILGenerator il, Type obType, bool noValue, MemberInfo mem)
 {
     this.thereIsAnObjectOnTheStack = true;
     if (mem is IWrappedMember)
     {
         object wrappedObject = ((IWrappedMember)mem).GetWrappedObject();
         if (wrappedObject is LenientGlobalObject)
         {
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
         }
         else if ((wrappedObject is Type) || (wrappedObject is ClassScope))
         {
             if (obType.IsAssignableFrom(Typeob.Type))
             {
                 new ConstantWrapper(wrappedObject, null).TranslateToIL(il, Typeob.Type);
             }
             else
             {
                 ScriptObject parent = base.Globals.ScopeStack.Peek();
                 while ((parent is WithObject) || (parent is BlockScope))
                 {
                     parent = parent.GetParent();
                 }
                 if (parent is FunctionScope)
                 {
                     if (((FunctionScope)parent).owner.isMethod)
                     {
                         il.Emit(OpCodes.Ldarg_0);
                     }
                     else
                     {
                         base.EmitILToLoadEngine(il);
                         il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                         parent = base.Globals.ScopeStack.Peek();
                         while ((parent is WithObject) || (parent is BlockScope))
                         {
                             il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                             parent = parent.GetParent();
                         }
                         il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                         il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                     }
                 }
                 else if (parent is ClassScope)
                 {
                     il.Emit(OpCodes.Ldarg_0);
                 }
                 for (parent = base.Globals.ScopeStack.Peek(); parent != null; parent = parent.GetParent())
                 {
                     ClassScope scope = parent as ClassScope;
                     if (scope != null)
                     {
                         if (scope.IsSameOrDerivedFrom(obType))
                         {
                             return;
                         }
                         il.Emit(OpCodes.Ldfld, scope.outerClassField);
                     }
                 }
             }
         }
         else
         {
             this.TranslateToILDefaultThisObject(il, this.lexLevel);
             Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, obType);
         }
     }
     else
     {
         ScriptObject obj5 = base.Globals.ScopeStack.Peek();
         while ((obj5 is WithObject) || (obj5 is BlockScope))
         {
             obj5 = obj5.GetParent();
         }
         if (!(obj5 is FunctionScope) || ((FunctionScope)obj5).owner.isMethod)
         {
             il.Emit(OpCodes.Ldarg_0);
             while (obj5 != null)
             {
                 if (obj5 is ClassScope)
                 {
                     ClassScope scope3 = (ClassScope)obj5;
                     if (scope3.IsSameOrDerivedFrom(obType))
                     {
                         return;
                     }
                     il.Emit(OpCodes.Ldfld, scope3.outerClassField);
                 }
                 obj5 = obj5.GetParent();
             }
         }
         else
         {
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
             obj5 = base.Globals.ScopeStack.Peek();
             while ((obj5 is WithObject) || (obj5 is BlockScope))
             {
                 il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                 obj5 = obj5.GetParent();
             }
             il.Emit(OpCodes.Castclass, Typeob.StackFrame);
             il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
             while (obj5 != null)
             {
                 if (obj5 is ClassScope)
                 {
                     ClassScope scope2 = (ClassScope)obj5;
                     if (scope2.IsSameOrDerivedFrom(obType))
                     {
                         break;
                     }
                     il.Emit(OpCodes.Castclass, scope2.GetTypeBuilder());
                     il.Emit(OpCodes.Ldfld, scope2.outerClassField);
                 }
                 obj5 = obj5.GetParent();
             }
             il.Emit(OpCodes.Castclass, obType);
         }
     }
 }