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); } }
private static bool UnionProperty(CProperty propo, CProperty luPropo) { for (int i = 0; i < 3; i++) { if ((propo.Declared[i] == null) != (luPropo.Declared[i] == null)) { return(false); } else if (propo.Declared[i] != null && ((CFunction)propo.Declared[i]).Arguments.Count != ((CFunction)luPropo.Declared[i]).Arguments.Count) { return(false); } } return(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); } }
public CProperty(CProperty property, bool isUnionMember) : base(property.Token, property.Name, "property", 3, isUnionMember) { Declared[ixGet] = m_get = property.m_get; Declared[ixSet] = m_set = property.m_set; }
public CProperty(CProperty property, bool isUnionMember) : base(property.Token, property.Name, "property", 3, isUnionMember) { Declared[ixGet] = m_get = property.m_get; Declared[ixSet] = m_set = property.m_set; }
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); }
private static bool UnionProperty(CProperty propo, CProperty luPropo) { for (int i = 0; i < 3; i++) { if ((propo.Declared[i] == null) != (luPropo.Declared[i] == null)) return false; else if (propo.Declared[i] != null && ((CFunction)propo.Declared[i]).Arguments.Count != ((CFunction)luPropo.Declared[i]).Arguments.Count) return false; } return true; }
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; }