private void AddRootAssembly(ThinAssembly assembly) { if (!_rootAssemblies.ContainsKey(assembly.Metadata)) _rootAssemblies.Add(assembly.Metadata, assembly); }
// 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; }
public override AssemblyElement CreateAssemblyElement(ModelElement model, string assemblyName, IncludeStatus includeStatus) { includeStatus = AdjustIncludeStatus(includeStatus); ThinAssembly assembly = new ThinAssembly(_thinModel, assemblyName, includeStatus, null); _thinModel.Assemblies.Add(assembly.Name, assembly); return assembly; }
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); } } } } }
public ThinTypeForwarder(ThinAssembly declaringAssembly, ThinTypeForwarder typeToCopy) { _declaringAssembly = declaringAssembly; _assemblyName = typeToCopy._assemblyName; _typeName = typeToCopy._typeName; _alias = typeToCopy._alias; _includeStatus = typeToCopy._includeStatus; }
public ThinAssembly(ThinModel declaringModel, ThinAssembly assyToCopy) { _types = new Dictionary<string, TypeElement>(); _typeForwaders = new Dictionary<string, TypeForwarderElement>(); _assemblyNode = assyToCopy._assemblyNode; _assemblyName = assyToCopy._assemblyName; _includeStatus = assyToCopy._includeStatus; _thinModel = declaringModel; }
public ThinTypeForwarder(ThinAssembly declaringAssembly, string assemblyName, string typeName, IncludeStatus includeStatus, IAliasForType alias) { _declaringAssembly = declaringAssembly; _assemblyName = assemblyName; _typeName = typeName; _alias = alias; _includeStatus = includeStatus; }
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; }
public ThinType(ThinAssembly declaringAssembly, string typeName, IncludeStatus includeStatus, INamedTypeDefinition typeNode, VisibilityOverride visibility, SecurityTransparencyStatus securityTransparencyStatus) { _members = new Dictionary<string, MemberElement>(); _typeNode = typeNode; _declaringAssembly = declaringAssembly; _includeStatus = includeStatus; _visibility = visibility; _securityTransparencyStatus = securityTransparencyStatus; //_typeFullName = Util.CCI2StyleTypeName(typeName); _typeFullName = typeName; }
public ThinType(ThinAssembly declaringAssembly, string typeName, IncludeStatus includeStatus, INamedTypeDefinition typeNode, VisibilityOverride visibility) : this(declaringAssembly, typeName, includeStatus, typeNode, visibility, SecurityTransparencyStatus.Transparent) { }
//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; } } } } }