Beispiel #1
0
    public static bool MethodOverrides(Smoke* smoke, Smoke.Method* method, out MemberAttributes access, out bool foundInInterface)
    {
        access = MemberAttributes.Public;
        foundInInterface = false;

        if (smoke->inheritanceList[smoke->classes[method->classId].parents] == 0)
        {
            return false;
        }

        long id = method - smoke->methods;
        Smoke.ModuleIndex methodModuleIndex = new Smoke.ModuleIndex(smoke, (short) id);

        Smoke.Method* firstMethod = (Smoke.Method*) IntPtr.Zero;
        short* firstParent = smoke->inheritanceList + smoke->classes[method->classId].parents;

        for (short* parent = firstParent; *parent > 0; parent++)
        {
            if (firstMethod != (Smoke.Method*) IntPtr.Zero && !foundInInterface)
            {
                // already found a method in the first parent class
                break;
            }

            // Do this with linq... there's probably room for optimization here.
            // Select virtual and pure virtual methods from superclasses.
            var inheritedVirtuals = from key in smoke->FindAllMethods(*parent, true).Keys
                                    where ((key.smoke->methods[key.index].flags & (ushort) Smoke.MethodFlags.mf_virtual) > 0
                                           ||
                                           (key.smoke->methods[key.index].flags & (ushort) Smoke.MethodFlags.mf_purevirtual) > 0)
                                    select key;

            foreach (Smoke.ModuleIndex mi in inheritedVirtuals)
            {
                Smoke.Method* meth = mi.smoke->methods + mi.index;

                if (SmokeMethodEqualityComparer.DefaultEqualityComparer.Equals(methodModuleIndex, mi))
                {
                    if ((meth->flags & (uint) Smoke.MethodFlags.mf_protected) > 0)
                    {
                        access = MemberAttributes.Family;
                    }
                    else
                    {
                        access = MemberAttributes.Public;
                    }

                    // don't return here - we need the access of the method in the topmost superclass
                    firstMethod = meth;
                    if (parent != firstParent)
                    {
                        foundInInterface = true;
                    }
                }
            }
        }

        // we need to have a method that's not in a interface to mark it as overriden
        bool ret = firstMethod != (Smoke.Method*) IntPtr.Zero && !foundInInterface;

        // we need to have a public method in one of the interfaces for this to be set
        foundInInterface = firstMethod != (Smoke.Method*) IntPtr.Zero && foundInInterface && access == MemberAttributes.Public;

        return ret;
    }
Beispiel #2
0
    private static bool MethodOverrides(Smoke *smoke, Smoke.Method *method, out MemberAttributes access, out bool foundInInterface)
    {
        access           = MemberAttributes.Public;
        foundInInterface = false;

        if (smoke->inheritanceList[smoke->classes[method->classId].parents] == 0)
        {
            return(false);
        }

        long id = method - smoke->methods;

        Smoke.ModuleIndex methodModuleIndex = new Smoke.ModuleIndex(smoke, (short)id);

        Smoke.Method *firstMethod = (Smoke.Method *)IntPtr.Zero;
        short *       firstParent = smoke->inheritanceList + smoke->classes[method->classId].parents;

        for (short *parent = firstParent; *parent > 0; parent++)
        {
            if (firstMethod != (Smoke.Method *)IntPtr.Zero && !foundInInterface)
            {
                // already found a method in the first parent class
                break;
            }

            // Do this with linq... there's probably room for optimization here.
            // Select virtual and pure virtual methods from superclasses.
            var inheritedVirtuals = from key in smoke->FindAllMethods(*parent, true).Keys
                                    where ((key.smoke->methods[key.index].flags & (ushort)Smoke.MethodFlags.mf_virtual) > 0
                                           ||
                                           (key.smoke->methods[key.index].flags & (ushort)Smoke.MethodFlags.mf_purevirtual) > 0)
                                    select key;

            foreach (Smoke.ModuleIndex mi in inheritedVirtuals)
            {
                Smoke.Method *meth = mi.smoke->methods + mi.index;

                if (SmokeMethodEqualityComparer.DefaultEqualityComparer.Equals(methodModuleIndex, mi))
                {
                    if ((meth->flags & (uint)Smoke.MethodFlags.mf_protected) > 0)
                    {
                        access = MemberAttributes.Family;
                    }
                    else
                    {
                        access = MemberAttributes.Public;
                    }

                    // don't return here - we need the access of the method in the topmost superclass
                    firstMethod = meth;
                    if (parent != firstParent)
                    {
                        foundInInterface = true;
                    }
                }
            }
        }

        // we need to have a method that's not in a interface to mark it as overriden
        bool ret = firstMethod != (Smoke.Method *)IntPtr.Zero && !foundInInterface;

        // we need to have a public method in one of the interfaces for this to be set
        foundInInterface = firstMethod != (Smoke.Method *)IntPtr.Zero && foundInInterface && access == MemberAttributes.Public;

        return(ret);
    }