Inheritance: CMember
        private void TryItemTypeFixup()
        {
            CClass  type;
            CMethod items = (CMethod)base.LookupMember("items");

            type = ((CArrayType)items.Declared[CProperty.ixGet].Type).ItemType.ActualType;

            if (type == null)
            {
                CMethod add = (CMethod)base.LookupMember("add");
                type = add.Function.Arguments[1].Type.ActualType;
            }

            if (type == null)
            {
                CProperty item = (CProperty)base.LookupMember("item");
                type = item.Type.ActualType;
                if (type == null && item.GetAccessor != null)
                {
                    type = item.GetAccessor.Type.ActualType;
                }
                if (type == null && item.SetAccessor != null)
                {
                    type = item.SetAccessor.Arguments[1].Type.ActualType;
                }
            }

            if (type != null)
            {
                ItemType = new CTypeRef(null, type);
            }
        }
        public CFunctionType(CToken token, CFunction function, bool declarationOnly)
            : base(token, function.TypeSignature)
        {
            target = function;
            this.declarationOnly = declarationOnly;

            CMethod method = new CMethod(function);
            DefaultMember = method;

            function.TypeChanged += new EventHandler(function_TypeChanged);
            foreach (CArgument arg in function.Arguments)
                arg.TypeChanged += new EventHandler(function_TypeChanged);

            this.IsSealed = true;

            // we don't actually want people accessing the default method directly
            // we also don't want it to get visited through the type.
            // so we don't do this: Members.Add(function.Name, method);
            Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
        }
        private void GenerateMembers()
        {
            generatingMembers = true;

            // <snip>

            CMethod items = (CMethod)LookupMember("items");
            CClass  type  = new CArrayType(1);

            items.LoadType(type);
            items.Function.LoadType(type);

            base.Scope.Clear();
            foreach (CMember member in InheritedMemberIterator)
            {
                base.Scope.add(member);
            }

            generatingMembers = false;
            generatedMembers  = true;
        }
        private void UpdateMembers()
        {
            CMethod items = (CMethod)base.LookupMember("items");

            ((CArrayType)items.Function.Type.ActualType).ItemType = ItemType;

            CMethod add = (CMethod)base.LookupMember("add");

            add.Function.Arguments[1].LoadType(ItemType);

            CProperty item = (CProperty)base.LookupMember("item");

            item.LoadType(ItemType);
            if (item.GetAccessor != null)
            {
                item.GetAccessor.LoadType(ItemType);
            }
            if (item.SetAccessor != null)
            {
                item.SetAccessor.Arguments[1].LoadType(ItemType);
            }
        }
Esempio n. 5
0
        public CFunctionType(CToken token, CFunction function, bool declarationOnly)
            : base(token, function.TypeSignature)
        {
            target = function;
            this.declarationOnly = declarationOnly;

            CMethod method = new CMethod(function);

            DefaultMember = method;

            function.TypeChanged += new EventHandler(function_TypeChanged);
            foreach (CArgument arg in function.Arguments)
            {
                arg.TypeChanged += new EventHandler(function_TypeChanged);
            }

            this.IsSealed = true;

            // we don't actually want people accessing the default method directly
            // we also don't want it to get visited through the type.
            // so we don't do this: Members.Add(function.Name, method);
            Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
        }
Esempio n. 6
0
 public CMethod(CMethod method, bool isUnionMember)
     : base(method.Token, method.Name, "method", 1, isUnionMember)
 {
     Declared[0] = function = method.function;
 }
Esempio n. 7
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);
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
 public CMethod(CMethod method, bool isUnionMember)
     : base(method.Token, method.Name, "method", 1, isUnionMember)
 {
     Declared[0] = function = method.function;
 }