Beispiel #1
0
        /// <summary>
        /// Should invoke_super be used to call this method from the given method?
        /// </summary>
        public bool UseInvokeSuper(XMethodDefinition currentlyCompiledMethod)
        {
            if (IsConstructor)
            {
                return(false);
            }
            if (this == currentlyCompiledMethod)
            {
                return(false);
            }

            if (!DeclaringType.IsBaseOf(currentlyCompiledMethod.DeclaringType))
            {
                return(false);
            }

            // Check if this method is a direct base method of the currently compiled method
            var iterator = currentlyCompiledMethod;

            while (true)
            {
                var baseMethod = iterator.GetBaseMethod(true);
                if ((baseMethod == null) || (baseMethod == iterator))
                {
                    break;
                }
                if ((baseMethod.IsSame(this)) && (baseMethod != currentlyCompiledMethod))
                {
                    return(true);
                }
                // Keep the order or baseMethod.IsSame(..)
                iterator = baseMethod;
            }

            // Check if this method is a direct base method of any of the methods in the declaring type of the currently compiled method.
            var sameInCurrentType = currentlyCompiledMethod.DeclaringType.Methods.FirstOrDefault(x => x.IsSameExceptDeclaringType(this));

            if (sameInCurrentType != null)
            {
                iterator = sameInCurrentType;
                while (true)
                {
                    var baseMethod = iterator.GetBaseMethod(true);
                    if ((baseMethod == null) || (baseMethod == iterator))
                    {
                        break;
                    }
                    if ((baseMethod.IsSame(this)) && (baseMethod != currentlyCompiledMethod))
                    {
                        return(true);
                    }
                    // Keep the order or baseMethod.IsSame(..)
                    iterator = baseMethod;
                }
            }

            return(false);
        }
Beispiel #2
0
 protected void CheckInstanceType(object instance, SourceInfo current)
 {
     FARLogger.AssertFormat(StaticParser && instance == null ||
                            instance != null && (DeclaringType?.IsBaseOf(instance.GetType()) ?? true),
                            "Invalid instance type {0}, expected {1}",
                            current,
                            instance?.GetType(),
                            DeclaringType);
 }