Beispiel #1
0
        public bool ProtectedObjCCtorIsInThis(TypeMapper typeMapper)
        {
            // this predicate determines if this type has a protected objc ctor in this.
            // it's used to determine if, when writing the C# binding, if we need to call base () or this ()
            var classDecl = this as ClassDeclaration;

            if (classDecl == null)
            {
                return(false);
            }
            if (!IsObjC)
            {
                return(false);
            }
            // no inheritance
            // this : (nothing) -> IsImportedBinding
            if (Inheritance == null || Inheritance.FirstOrDefault(inh => inh.InheritanceKind == InheritanceKind.Class) == null)
            {
                // if there's no inheritance, then the protected ctor is in this if it wasn't imported
                return(!classDecl.IsImportedBinding);
            }
            // this : import -> true
            // this : binding : binding : import -> false
            var classInherit = Inheritance.First(inh => inh.InheritanceKind == InheritanceKind.Class);
            var entity       = typeMapper.GetEntityForTypeSpec(classInherit.InheritedTypeSpec);

            if (entity == null)
            {
                throw ErrorHelper.CreateError(ReflectorError.kCompilerBase + 9, $"Unable to find entity for class inheritance on type {classInherit.InheritedTypeName}");
            }
            var inheritedClass = entity.Type as ClassDeclaration;

            if (inheritedClass == null)
            {
                throw ErrorHelper.CreateError(ReflectorError.kCompilerBase + 10, $"Expected a ClassDeclaration in inheritance chain but got {entity.Type.ToFullyQualifiedName (true)} of {entity.Type.GetType ().Name}");
            }
            return(inheritedClass.IsImportedBinding);
        }
Beispiel #2
0
        public bool VirtualMethodExistsInInheritedBoundType(FunctionDeclaration func, TypeMapper typeMapper)
        {
            // virtual methods are only in classes
            if (!(this is ClassDeclaration))
            {
                return(false);
            }
            var classInheritance = Inheritance.FirstOrDefault(inh => inh.InheritanceKind == InheritanceKind.Class);

            if (classInheritance == null)
            {
                return(false);
            }

            var inheritedEntity = typeMapper.GetEntityForTypeSpec(classInheritance.InheritedTypeSpec);

            if (inheritedEntity == null)
            {
                throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 18, $"Unable to find type database entry for class {classInheritance.InheritedTypeName} while searching inheritance.");
            }

            // if we get here, the Type has to be a ClassDeclaration
            var inheritedClass = inheritedEntity.Type as ClassDeclaration;

            var methods = inheritedClass.AllVirtualMethods().FindAll(fn => fn.Name == func.Name &&
                                                                     fn.ParameterLists.Last().Count == func.ParameterLists.Last().Count).ToList();

            foreach (var method in methods)
            {
                if (ParmsMatchWithNames(method.ParameterLists.Last(), func.ParameterLists.Last()) &&
                    method.ReturnTypeSpec.Equals(func.ReturnTypeSpec))
                {
                    return(true);
                }
            }
            return(inheritedClass.VirtualMethodExistsInInheritedBoundType(func, typeMapper));
        }