Beispiel #1
0
        internal bool IsAConstructor(CFunction function)
        {
            if (function == null)
            {
                return(false);
            }
            CMember ctor = this.Constructor;

            if (null == ctor)
            {
                return(false);
            }
            switch (ctor.MemberType)
            {
            case "method":
                return(((CMethod)ctor).Function == function);

            case "override":
                CMemberOverload cmo = (CMemberOverload)ctor;
                foreach (CMember ctor_overload in cmo.Overloads)
                {
                    if (((CMethod)ctor_overload).Function == function)
                    {
                        return(true);
                    }
                }

                return(false);

            default:
                throw new InvalidOperationException(ctor.MemberType);
            }
        }
Beispiel #2
0
        public virtual String UpdateMembers(IVisitor checker)
        {
            if (types.Count == 0)
            {
                return("Empty enum type used");
            }

            bool isObject = true;

            for (int i = 0; i < types.Count; i++)
            {
                CTypeRef otype = types[i];
                if (!otype.Resolved)
                {
                    CClass ntype = CProgram.Global.FindClass(otype.TypeName);
                    if (ntype == null)
                    {
                        return("Cannot find type " + otype.TypeName.RawValue);
                    }
                    otype.InternalLoad(ntype);
                }
                types[i] = otype;
                types[i].ActualType.Accept(checker);
                isObject = isObject && otype.ActualType.IsObject;
            }
            IsObject = isObject;

            base.ClearMembers();
            Scope.Clear();

            foreach (CMember member in types[0].ActualType.InheritedMemberIterator)
            {
                bool found;
                if (member is CMemberOverload)
                {
                    found = false;
                }
                else// Unions can only access public members
                {
                    found = member.Visibility == TokenTypes.visPublic;
                }


                IEnumerator <CTypeRef> it = types.GetEnumerator();
                it.MoveNext();
                while (found && it.MoveNext())
                {
                    CClass  type     = it.Current.ActualType;
                    CMember luMember = type.LookupMember(member.Name);
                    if (luMember == null)
                    {
                        found = false;
                    }
                    else if (luMember.MemberType != member.MemberType)
                    {
                        // one's a method, the other's a field, or etc...
                        found = false;
                    }
                    else if (luMember.Visibility != TokenTypes.visPublic)
                    {
                        found = false;
                    }
                    else
                    {
                        switch (luMember.MemberType)
                        {
                        case "method":
                            CMethod metho   = (CMethod)member;
                            CMethod luMetho = (CMethod)luMember;
                            // already checked return type, let's try the parameters
                            if (metho.Function.Arguments.Count != luMetho.Function.Arguments.Count)
                            {
                                found = false;
                            }
                            break;

                        case "property":
                            found = UnionProperty((CProperty)member, (CProperty)luMember);
                            // dur
                            break;

                        case "field":
                            // already checked return type, nothing left to check
                            break;

                        case "override":
                            found = false;    // dur
                            break;
                        }
                    }
                }
                if (found)
                {
                    CMember fmember;
                    switch (member.MemberType)
                    {
                    case "method":
                        fmember = new CMethod((CMethod)member, true);
                        break;

                    case "property":
                        fmember = new CProperty((CProperty)member, true);
                        break;

                    case "field":
                        fmember = new CField((CField)member, true);
                        break;

                    case "override":
                        fmember = new CMemberOverload((CMemberOverload)member, true);
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                    SetMember(member.Name, fmember);
                    Scope.add(fmember);
                }
            }

            bool hasDefault = true;

            DefaultMember = null;
            foreach (CTypeRef _class in types)
            {
                var memberBase = ((CClass)types[0]).DefaultMember;
                var member     = _class.ActualType.DefaultMember;
                if (memberBase == null ||
                    member == null ||
                    !UnionProperty((CProperty)memberBase, (CProperty)member))
                {
                    hasDefault = false;
                    break;
                }
            }
            if (hasDefault)
            {
                DefaultMember = ((CClass)types[0]).DefaultMember;
            }

            return(null);
        }
 public CMemberOverload(CMemberOverload field, bool isUnionMember)
     : base(field.Token, field.Name, "override", 0, isUnionMember)
 {
     this.owner = field.DeclaringClass;
 }
 public CMemberOverload(CMemberOverload field, bool isUnionMember)
     : base(field.Token, field.Name, "override", 0, isUnionMember)
 {
     this.owner = field.DeclaringClass;
 }
        public virtual String UpdateMembers(IVisitor checker)
        {
            if (types.Count == 0)
                return "Empty enum type used";

            bool isObject = true;
            for (int i = 0; i < types.Count; i++)
            {
                CTypeRef otype = types[i];
                if (!otype.Resolved)
                {
                    CClass ntype = CProgram.Global.FindClass(otype.TypeName);
                    if (ntype == null)
                        return "Cannot find type " + otype.TypeName.RawValue;
                    otype.InternalLoad(ntype);
                }
                types[i] = otype;
                types[i].ActualType.Accept(checker);
                isObject = isObject && otype.ActualType.IsObject;
            }
            IsObject = isObject;

            base.ClearMembers();
            Scope.Clear();

            foreach (CMember member in types[0].ActualType.InheritedMemberIterator)
            {
                bool found;
                if (member is CMemberOverload)
                    found = false;
                else// Unions can only access public members
                    found = member.Visibility == TokenTypes.visPublic;

                IEnumerator<CTypeRef> it = types.GetEnumerator();
                it.MoveNext();
                while (found && it.MoveNext())
                {
                    CClass type = it.Current.ActualType;
                    CMember luMember = type.LookupMember(member.Name);
                    if (luMember == null)
                        found = false;
                    else if (luMember.MemberType != member.MemberType)
                        // one's a method, the other's a field, or etc...
                        found = false;
                    else if (luMember.Visibility != TokenTypes.visPublic)
                        found = false;
                    else
                    {
                        switch (luMember.MemberType)
                        {
                            case "method":
                                CMethod metho = (CMethod)member;
                                CMethod luMetho = (CMethod)luMember;
                                // already checked return type, let's try the parameters
                                if (metho.Function.Arguments.Count != luMetho.Function.Arguments.Count)
                                    found = false;
                                break;
                            case "property":
                                found = UnionProperty((CProperty)member, (CProperty)luMember);
                                // dur
                                break;
                            case "field":
                                // already checked return type, nothing left to check
                                break;
                            case "override":
                                found = false;// dur
                                break;
                        }
                    }
                }
                if (found)
                {
                    CMember fmember;
                    switch (member.MemberType)
                    {
                        case "method":
                            fmember = new CMethod((CMethod)member, true);
                            break;
                        case "property":
                            fmember = new CProperty((CProperty)member, true);
                            break;
                        case "field":
                            fmember = new CField((CField)member, true);
                            break;
                        case "override":
                            fmember = new CMemberOverload((CMemberOverload)member, true);
                            break;
                        default:
                            throw new InvalidOperationException();
                    }
                    SetMember(member.Name, fmember);
                    Scope.add(fmember);
                }
            }

            bool hasDefault = true;
            DefaultMember = null;
            foreach (CTypeRef _class in types)
            {
                var memberBase = ((CClass)types[0]).DefaultMember;
                var member = _class.ActualType.DefaultMember;
                if ( memberBase == null ||
                     member == null ||
                     !UnionProperty((CProperty)memberBase, (CProperty) member))
                {
                    hasDefault = false;
                    break;
                }
            }
            if (hasDefault)
                DefaultMember = ((CClass)types[0]).DefaultMember;

            return null;
        }