Exemplo n.º 1
0
        public ThinMember(ThinType declaringType, string memberName, string returnType, MemberTypes memberType,
                          IncludeStatus includeStatus, ITypeDefinitionMember memberNode, VisibilityOverride visibility)

            : this(declaringType, memberName, returnType, memberType,
                   includeStatus, memberNode, visibility, SecurityTransparencyStatus.Transparent)
        {
        }
Exemplo n.º 2
0
        public ThinMember(ThinType declaringType, ThinMember memberToCopy)
        {
            _declaringType = declaringType;

            _memberNode = memberToCopy._memberNode;
            _memberFullName = memberToCopy._memberFullName;
            _returnType = memberToCopy._returnType;
            _memberType = memberToCopy._memberType;
            _includeStatus = memberToCopy._includeStatus;
            _visibility = memberToCopy._visibility;
            _securityTransparencyStatus = memberToCopy._securityTransparencyStatus;

            CheckVisibility();
        }
Exemplo n.º 3
0
        public ThinMember(ThinType declaringType, string memberName, string returnType, MemberTypes memberType,
                          IncludeStatus includeStatus, ITypeDefinitionMember memberNode, VisibilityOverride visibility,
                          SecurityTransparencyStatus securityTransparencyStatus)
        {
            _memberNode = memberNode;
            _declaringType = declaringType;
            _returnType = returnType;
            _memberType = memberType;
            _includeStatus = includeStatus;
            _visibility = visibility;
            _securityTransparencyStatus = securityTransparencyStatus;

            _memberFullName = memberName;

            CheckVisibility();
        }
Exemplo n.º 4
0
        public ThinMember(ThinType declaringType, ITypeDefinitionMember member, IncludeStatus includeStatus, VisibilityOverride visibility)
        {
            _declaringType = declaringType;

            _memberNode = member;
            _memberType = Util.TypeMemberType(member);
            _returnType = Util.GetConversionOperatorReturnType(member);
            _memberFullName = Util.GetMemberSignature(member, false);

            // Remove the trailing return type for conversion operators
            if (_returnType != null)
            {
                string suffix = " : " + _returnType;
                if (_memberFullName.EndsWith(suffix))
                    _memberFullName = _memberFullName.Substring(0, _memberFullName.Length - suffix.Length);
            }

            _includeStatus = includeStatus;
            _visibility = visibility;
            _securityTransparencyStatus = SecurityTransparencyStatus.Transparent;

            CheckVisibility();
        }
Exemplo n.º 5
0
        // Special case: If closureStatus == ApiRoot this will automatically
        // convert it to ImplRoot for internal types
        // TODO: Visitor should set status instead of this.
        public ThinModel ExportModel(IncludeStatus closureStatus)
        {
            _closureStatus = closureStatus;

            int nApiTypes = 0;
            int nApiTypeForwarders = 0;
            int nApiMembers = 0;

            ThinModel thinModel = new ThinModel(_thinModel.Options);
            Dictionary<String, ThinAssembly> assemblies = new Dictionary<String, ThinAssembly>(_depot.AssembliesClosure.Count);
            Dictionary<INamedTypeDefinition, ThinType> types = new Dictionary<INamedTypeDefinition, ThinType>(_depot.TypesClosure.Count);

            foreach (IAssembly assembly in _depot.AssembliesClosure.Values)
            {
                ThinAssembly thinAsm = new ThinAssembly(_thinModel, assembly.Name.Value, GetIncludeStatus(assembly), assembly);
                thinModel.Assemblies.Add(thinAsm.Name, thinAsm);
                assemblies.Add(assembly.Name.Value, thinAsm);
            }

            foreach (INamedTypeDefinition type in _depot.TypesClosure.Values)
            {
                IAssembly asm = TypeHelper.GetDefiningUnit(type) as IAssembly;
                if (asm != null && assemblies.ContainsKey(asm.Name.Value))
                {
                    VisibilityOverride vis = VisibilityOverride.None;
                    if (ShouldHideType(type))
                        vis = VisibilityOverride.Internal;

                    if (closureStatus != IncludeStatus.ApiRoot)
                    {
                        if (TypeIsVisibleInApi(type))
                        {
                            INamedTypeDefinition curType = type;
                            while (curType != null && curType != Dummy.Type && // TODO: Remove dummy check?
                                CanInclude(curType))
                            {
                                if (WeHidThisType(curType))
                                    throw new Exception("API closure error!  Base type " + curType + " was hidden, but " + type + " is in the public API");
                                ITypeReference curTypeRef = TypeHelper.BaseClass(curType);
                                curType = curTypeRef != null ? Util.CanonicalizeType(curTypeRef) : null;
                            }
                        }
                    }

                    ThinAssembly declaringAssembly = assemblies[asm.Name.Value];
                    ThinType thinType = new ThinType(declaringAssembly, Util.FullyQualifiedTypeNameFromType(type), GetIncludeStatus(type), type, vis);
                    declaringAssembly.Types.Add(thinType.Name, thinType);
                    types.Add(type, thinType);

                    if (thinType.IncludeStatus == IncludeStatus.ApiClosure ||
                        thinType.IncludeStatus == IncludeStatus.ApiRoot ||
                        thinType.IncludeStatus == IncludeStatus.ApiFxInternal)
                    {
                        nApiTypes++;
                    }
                }
                else
                {
                    Console.Error.WriteLine("BclRewriter : warning BR5004 : couldn't find declaring module of type {0} in closure", type);
                }
            }

            foreach (IAliasForType typeForwarder in _depot.TypeForwardersClosure.Values)
            {
                // TODO: Why is this getting an immutable copy of the assembly?
                IAssembly asm = Util.GetDefiningAssembly(typeForwarder);
                if (asm != null && assemblies.ContainsKey(asm.Name.Value))
                {
                    ThinAssembly declaringAssembly = assemblies[asm.Name.Value];
                    ITypeReference aliasedType = typeForwarder.AliasedType;
                    ThinTypeForwarder thinTypeForwarder = new ThinTypeForwarder(declaringAssembly,
                                                                                Util.GetDefiningAssembly(aliasedType).Name.Value,
                                                                                Util.GetTypeName(aliasedType),
                                                                                GetIncludeStatus(typeForwarder),
                                                                                typeForwarder);

                    declaringAssembly.TypeForwarders.Add(thinTypeForwarder.Key, thinTypeForwarder);

                    if (thinTypeForwarder.IncludeStatus == IncludeStatus.ApiClosure ||
                        thinTypeForwarder.IncludeStatus == IncludeStatus.ApiRoot ||
                        thinTypeForwarder.IncludeStatus == IncludeStatus.ApiFxInternal)
                    {
                        nApiTypeForwarders++;
                    }
                }
                else
                {
                    Console.Error.WriteLine("BclRewriter : warning BR5001 : couldn't find declaring module of type forwarder {0} in closure", typeForwarder);
                }
            }

            foreach (ITypeDefinitionMember member in _depot.MembersClosure.Keys)
            {
                INamedTypeDefinition type = Util.ContainingTypeDefinition(member);
                if (types.ContainsKey(type))
                {
                    ThinType declaringType = types[type];
                    IncludeStatus status = GetIncludeStatus(member);

                    VisibilityOverride vis = VisibilityOverride.None;
                    if (ShouldHideMember(member))
                        vis = VisibilityOverride.Internal;

                    if ((type.IsInterface) &&
                        TypeIsVisibleInApi(type) &&
                        vis == VisibilityOverride.Internal)
                    {
                        throw new Exception(string.Format("Implementation required non-public member on public interface: {0} on {1}. This usually means you added a property to model.xml without adding the corresponding getter or setter.",
                            member.Name,
                            Util.FullyQualifiedTypeNameFromType(member.ContainingType)));
                    }

                    ThinMember thinMember = new ThinMember(declaringType, member, status, vis);
                    declaringType.Members.Add(thinMember.Key, thinMember);

                    if (thinMember.IncludeStatus == IncludeStatus.ApiClosure ||
                        thinMember.IncludeStatus == IncludeStatus.ApiRoot ||
                        thinMember.IncludeStatus == IncludeStatus.ApiFxInternal)
                    {
                        nApiMembers++;
                    }
                }
                else
                {
                    Console.Error.WriteLine("BclRewriter : warning BR5002 : couldn't find declaring type of member {0} in closure", member);
                }
            }

            foreach (IMethodDefinition method in _depot.MethodsClosure.Values)
            {
                INamedTypeDefinition type = Util.ContainingTypeDefinition(method);
                if (types.ContainsKey(type))
                {
                    ThinType declaringType = types[type];
                    IncludeStatus status = GetIncludeStatus(method);

                    VisibilityOverride vis = VisibilityOverride.None;
                    if (ShouldHideMember(method))
                        vis = VisibilityOverride.Internal;

                    if ((type.IsInterface) &&
                        TypeIsVisibleInApi(type) &&
                        vis == VisibilityOverride.Internal)
                    {
                        //throw new Exception(string.Format("WARNING: implementation required non-public member on public interface: {0} on {1}. This usually means you added a property to model.xml without adding the corresponding getter or setter.",
                        //    method.Name, 
                        //    Util.FullyQualifiedTypeNameFromType(method.ContainingType)));
                    }

                    ThinMember thinMember = new ThinMember(declaringType, method, status, vis);
                    if (declaringType.Members.ContainsKey(thinMember.Key))
                    {
                        throw new Exception(String.Format("Found two members with the same signature: {0}", thinMember.Key));
                    }
                    declaringType.Members.Add(thinMember.Key, thinMember);

                    if (thinMember.IncludeStatus == IncludeStatus.ApiClosure ||
                        thinMember.IncludeStatus == IncludeStatus.ApiRoot ||
                        thinMember.IncludeStatus == IncludeStatus.ApiFxInternal)
                    {
                        nApiMembers++;
                    }
                }
                else
                {
                    Console.Error.WriteLine("BclRewriter : warning BR5003 : couldn't find declaring type of method {0} in closure", method);
                }
            }

            foreach (ThinMember thinMember in _missingMembers)
            {
                ThinType typeToExtend = types[thinMember.DeclaringType.Metadata];
                ThinMember newThinMember = new ThinMember(typeToExtend, thinMember);
                if (!typeToExtend.Members.ContainsKey(newThinMember.Key))
                    typeToExtend.Members.Add(newThinMember.Key, newThinMember);
            }

            return thinModel;
        }
Exemplo n.º 6
0
 private void AddRootType(ThinType type)
 {
     if (!_rootTypes.ContainsKey(type.Metadata))
         _rootTypes.Add(type.Metadata, type);
 }
Exemplo n.º 7
0
        private void CombineIncludeStatusWithModel(IncludeStatus targetStatusToAdd, ThinModel otherModel)
        {
            // TODO: which one should we keep, the one in this model or the other model?
            foreach (ThinAssembly assembly in Assemblies.Values)
            {
                AssemblyElement newAssembly;
                if (!otherModel.Assemblies.TryGetValue(assembly.Name, out newAssembly) &&
                    (assembly.IncludeStatus == targetStatusToAdd))
                {
                    newAssembly = new ThinAssembly(otherModel, assembly);
                    otherModel.Assemblies.Add(newAssembly.Key, newAssembly);
                }

                foreach (ThinTypeForwarder typeForwarder in assembly.TypeForwarders.Values)
                {
                    TypeForwarderElement newTypeForwarder;
                    if (!newAssembly.TypeForwarders.TryGetValue(typeForwarder.Key, out newTypeForwarder) &&
                        (typeForwarder.IncludeStatus == targetStatusToAdd))
                    {
                        newTypeForwarder = new ThinTypeForwarder((ThinAssembly)newAssembly, typeForwarder);
                        newAssembly.TypeForwarders.Add(newTypeForwarder.Key, newTypeForwarder);
                    }
                }

                foreach (ThinType type in assembly.Types.Values)
                {
                    TypeElement newType;
                    if (!newAssembly.Types.TryGetValue(type.Name, out newType) &&
                        (type.IncludeStatus == targetStatusToAdd))
                    {
                        newType = new ThinType((ThinAssembly)newAssembly, type);
                        newAssembly.Types.Add(newType.Key, newType);
                    }
                    foreach (ThinMember member in type.Members.Values)
                    {
                        MemberElement newMember;
                        if (!newType.Members.TryGetValue(member.Key, out newMember) &&
                            (member.IncludeStatus == targetStatusToAdd))
                        {
                            newMember = new ThinMember((ThinType)newType, member);
                            newType.Members.Add(newMember.Key, newMember);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public override TypeElement CreateTypeElement(AssemblyElement assembly, string typeName,
                                                      IncludeStatus includeStatus, VisibilityOverride visibilityOverride,
                                                      SecurityTransparencyStatus securityTransparencyStatus)
        {
            ThinAssembly declaringAssembly = (ThinAssembly)assembly;
            includeStatus = AdjustIncludeStatus(includeStatus);
            ThinType type = new ThinType(declaringAssembly, typeName, includeStatus, null, visibilityOverride, securityTransparencyStatus);

            String key = type.Name;
            if (declaringAssembly.Types.ContainsKey(key))
            {
                String errMsg = String.Format("XML file error: duplicate Type element \"{0}\"", key);
                Console.Error.WriteLine(errMsg);
                throw new FormatException(errMsg);
            }

            declaringAssembly.Types.Add(key, type);

            return type;
        }
Exemplo n.º 9
0
        public ThinType(ThinAssembly declaringAssembly, ThinType typeToCopy)
        {
            _members = new Dictionary<string, MemberElement>();
            _declaringAssembly = declaringAssembly;

            _typeNode = typeToCopy._typeNode;
            _typeFullName = typeToCopy._typeFullName;
            _includeStatus = typeToCopy._includeStatus;
            _visibility = typeToCopy._visibility;
            _securityTransparencyStatus = typeToCopy._securityTransparencyStatus;
        }
Exemplo n.º 10
0
        //public ThinModel DumpApi()
        //{
        //    ThinModel model = new ThinModel();

        //    foreach (ThinAssembly assembly in Assemblies.Values)
        //    {
        //        ThinAssembly newAssembly = new ThinAssembly(assembly.Name, IncludeStatus.Unknown, assembly.Metadata);
        //        model.Assemblies.Add(newAssembly.Name, newAssembly);
        //        foreach (INamedTypeDefinition type in newAssembly.Metadata.Types)
        //        {
        //            if (type.IsPublic)
        //            {
        //                ThinType thinType = new ThinType(newAssembly, type.ToString(), IncludeStatus.Unknown, type, VisibilityOverride.None);
        //                newAssembly.Types.Add(thinType.Name, thinType);

        //                DumpMembers(type, newAssembly, thinType);
        //            }
        //        }
        //    }

        //    return model;
        //}

        public void AddElementsFrom(ModelElement otherModel, bool overwriteExisting)
        {
            foreach (KeyValuePair<String, AssemblyElement> assembly in otherModel.Assemblies)
            {
                if (!_assemblies.ContainsKey(assembly.Key) || overwriteExisting)
                {
                    ThinAssembly newAssembly = new ThinAssembly(this, assembly.Value.Key, assembly.Value.IncludeStatus, null);
                    _assemblies[newAssembly.Key] = newAssembly;
                }

                ThinAssembly currentAssembly = (ThinAssembly)_assemblies[assembly.Key];

                foreach (var typeForwarder in assembly.Value.TypeForwarders)
                {
                    if (!currentAssembly.TypeForwarders.ContainsKey(typeForwarder.Key) || overwriteExisting)
                    {
                        TypeForwarderElement forwarder = typeForwarder.Value;
                        ThinTypeForwarder newTypeForwarder = new ThinTypeForwarder(currentAssembly, forwarder.AssemblyName, forwarder.TypeName,
                                                                                   forwarder.IncludeStatus, null);
                    }
                }
                foreach (KeyValuePair<String, TypeElement> type in assembly.Value.Types)
                {
                    if (!currentAssembly.Types.ContainsKey(type.Key) || overwriteExisting)
                    {
                        ThinType newType = new ThinType(currentAssembly, type.Value.Key,
                                                        type.Value.IncludeStatus, null, type.Value.VisibilityOverride);
                        currentAssembly.Types[newType.Key] = newType;
                    }
                    ThinType currentType = (ThinType)currentAssembly.Types[type.Key];

                    foreach (KeyValuePair<String, MemberElement> member in type.Value.Members)
                    {
                        if (!currentType.Members.ContainsKey(member.Key) || overwriteExisting)
                        {
                            ThinMember newMember = new ThinMember(currentType, member.Value.Name, member.Value.ReturnType, member.Value.MemberType,
                                                                  member.Value.IncludeStatus, null, member.Value.VisibilityOverride);
                            currentType.Members[newMember.Key] = newMember;
                        }
                    }
                }
            }
        }