public AssemblyProperty(IAliasForType alias) { this.Key = alias.AliasedType.RefDocId(); this.Name = "Forwarder: " + this.Key; this.Value = alias.AliasedType.GetAssemblyReference().ToString(); this.Delimiter = " => "; }
public override void Visit(IAliasForType aliasForType) { this.Visit(aliasForType.GetAttributes(Context)); // do not visit the reference to aliased type, it does not get into the type ref table based only on its membership of the exported types collection. // but DO visit the reference to assembly (if any) that defines the aliased type. That assembly might not already be in the assembly reference list. var definingUnit = TypeHelper.GetDefiningUnitReference(aliasForType.AliasedType, Context); var definingAssembly = definingUnit as IAssemblyReference; if (definingAssembly != null) { this.Visit(definingAssembly); } var definingModule = definingUnit as IModuleReference; if (definingModule != null) { definingAssembly = definingModule.GetContainingAssembly(Context); if (definingAssembly != null && !ReferenceEquals(definingAssembly, this.module.GetContainingAssembly(Context))) { this.Visit(definingAssembly); } } }
/// <summary> /// Helper to step through one indirection of IAliasForType. /// The method gets the type reference on the target of the alias /// and if that target is another alias it also returns its IAliasForType. /// This can be used to step over aliases one by one, as opposed to IAliasForType.AliasedType /// which sometimes resolves all the way through to the type def. /// It also provides a way to get to the target's IAliasForType which is otherwise /// really hard to get to (a simple type ref pointing to it is not enough, it will still report itself as non-alias). /// </summary> /// <param name="aliasForType">The alias to step through.</param> /// <param name="referencedAliasForType">If the target points to another alias this will contain IAliasForType for it.</param> /// <returns>The type ref for the target of the source alias. The type ref can be resolved, but its IsAlias property can't be trusted /// as it will always return false.</returns> public static INamedTypeReference GetUnresolvedAliasedTypeReference(this IAliasForType aliasForType, out IAliasForType referencedAliasForType) { referencedAliasForType = null; var exportedAliasForType = aliasForType as ExportedTypeAliasBase; if (exportedAliasForType == null) { throw new NotSupportedException("An IAliasForType created using PEReader is required."); } IMetadataReaderNamedTypeReference typeReference = exportedAliasForType.UnresolvedAliasedTypeReference as IMetadataReaderNamedTypeReference; if (typeReference == null) { throw new NotSupportedException("A type reference created using PEReader is required."); } var internalAssembly = typeReference.ModuleReference.ResolvedUnit as Assembly; if (internalAssembly != null) { // Try if the other assembly has this as yet another type alias, since there's no good way of getting from a normal type reference // to the alias. This is basically the only way to do that. referencedAliasForType = internalAssembly.PEFileToObjectModel.TryToResolveAsNamespaceTypeAlias(typeReference.NamespaceFullName, typeReference.MangledTypeName); } return(typeReference); }
public override void Visit(IAliasForType aliasForType) { // Do nothing. AssemblyIdentity id = aliasForType.AliasedType.GetAssemblyReference().AssemblyIdentity; if (!AliasedAssemblyReferences.Contains(id)) AliasedAssemblyReferences.Add(id); }
public override void Visit(IAliasForType aliasForType) { if (Process(aliasForType)) { visitor.Visit(aliasForType); } base.Visit(aliasForType); }
public override void Visit(IAliasForType aliasForType) { // Do nothing. AssemblyIdentity id = aliasForType.AliasedType.GetAssemblyReference().AssemblyIdentity; if (!AliasedAssemblyReferences.Contains(id)) { AliasedAssemblyReferences.Add(id); } }
//^ ensures this.path.Count == old(this.path.Count); /// <summary> /// Visits the specified alias for type. /// </summary> /// <param name="aliasForType">Type of the alias for.</param> public virtual void Visit(IAliasForType aliasForType) { if (this.stopTraversal) return; //^ int oldCount = this.path.Count; this.path.Push(aliasForType); this.Visit(aliasForType.AliasedType); this.Visit(aliasForType.Attributes); //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count. this.path.Pop(); aliasForType.Dispatch(this); }
private static INamespaceAliasForType GetAliasForType(IAliasForType aliasForType) { INestedAliasForType nestedAliasForType = aliasForType as INestedAliasForType; while (nestedAliasForType != null) { aliasForType = nestedAliasForType.ContainingAlias; nestedAliasForType = aliasForType as INestedAliasForType; } INamespaceAliasForType namespaceAliasForType = aliasForType as INamespaceAliasForType; return(namespaceAliasForType); }
public override void Visit(IAliasForType aliasForType) { base.Visit(aliasForType); if (aliasForType.AliasedType is Dummy) { Contract.Assert(!(aliasForType.AliasedType is Dummy), "The aliased type should not be a dummy"); } if (aliasForType.AliasedType.ResolvedType is Dummy) { AddUnresolvedReference(aliasForType.AliasedType); } }
public bool AddTypeForwarder(IAliasForType alias) { String signature = Util.GetTypeForwarderSignature(alias); if (!TypeForwardersClosure.ContainsKey(signature)) { TypeForwardersClosure.Add(signature, alias); _workList.Enqueue(alias); return(true); } return(false); }
public IncludeStatus GetIncludeStatus(IAliasForType typeForwarder) { ThinTypeForwarder modelTypeForwarder; if (!_rootTypeForwarders.TryGetValue(typeForwarder, out modelTypeForwarder)) { if (_depot.TypeForwardersClosure.ContainsKey(Util.GetTypeForwarderSignature(typeForwarder))) { return(_closureStatus); } return(IncludeStatus.Exclude); } return(modelTypeForwarder.IncludeStatus); }
/// <summary> /// Returns the data in model file that corresponds to passed CCI2 type /// </summary> /// <param name="typeForwarderDef">The CCI2 type tforwarder o look up</param> public TypeForwarderElement this[IAliasForType typeForwarderDef] { get { IAssembly assemblyDef = Util.GetDefiningAssembly(typeForwarderDef); if (assemblyDef != null) { AssemblyElement assembly; string assemblyName = assemblyDef.Name.Value; if (_reader.Model.Assemblies.TryGetValue(assemblyName, out assembly)) { TypeForwarderElement typeForwarder; string typeForwarderSig = Util.GetTypeForwarderSignature(typeForwarderDef); if (assembly.TypeForwarders.TryGetValue(typeForwarderSig, out typeForwarder)) { return(typeForwarder); } } } return(null); } }
public virtual void VisitNode(IReference node) { IAssembly assembly = node as IAssembly; INamedTypeDefinition type = node as INamedTypeDefinition; ITypeDefinitionMember member = node as ITypeDefinitionMember; IAliasForType alias = node as IAliasForType; if (assembly != null) { if (m_implModel.CanIncludeAssembly(assembly.AssemblyIdentity)) { Visit(assembly); } } else if (type != null) { INamedTypeReference typeRef = Util.CanonicalizeTypeReference(type); if (m_implModel.CanInclude(typeRef)) { Visit(type); } } else if (member != null) { INamedTypeReference typeRef = Util.CanonicalizeTypeReference(member.ContainingType); if (m_implModel.CanInclude(typeRef)) { Visit(member); } } else if (alias != null) { Visit(alias); } else { throw new Exception("Illegal node: " + node.GetType().Name); } }
// Walk up the path of defining namespaces and units until we get to the assembly public static IAssembly GetDefiningAssembly(IAliasForType aliasForType) { INamespaceAliasForType namespaceAliasForType = GetAliasForType(aliasForType); if (namespaceAliasForType == null) { return(null); } INamespaceDefinition containingNamespace = namespaceAliasForType.ContainingNamespace; IUnitNamespace unitNamespace = GetUnitNamespace(containingNamespace); if (unitNamespace == null) { return(null); } IUnit unit = unitNamespace.Unit; IAssembly assembly = GetAssembly(unit); return(assembly); }
public static String GetTypeForwarderSignature(IAliasForType alias) { ITypeReference type = alias.AliasedType; return GetTypeForwarderSignature(Util.GetDefiningAssembly(type).Name.Value, Util.GetTypeName(type)); }
public void ExportedType(IAliasForType exportedType) { INamespaceAliasForType nsAlias = exportedType as INamespaceAliasForType; INestedAliasForType nestedAlias = exportedType as INestedAliasForType; this.ILDasmPaper.Directive(".class extern"); if (nsAlias != null) { if (nsAlias.IsPublic) { this.ILDasmPaper.Keyword("public"); } this.QualifiedAliasForType(exportedType); this.ILDasmPaper.NewLine(); } else if (nestedAlias != null) { this.ILDasmPaper.Keyword("nested"); this.TypeMemberAccess(nestedAlias.Visibility); this.ILDasmPaper.Identifier(nestedAlias.Name.Value); this.ILDasmPaper.NewLine(); } else { this.ILDasmPaper.NewLine(); return; } this.ILDasmPaper.OpenBlock(); if (nsAlias != null) { this.ILDasmPaper.Directive(".file"); this.ILDasmPaper.Identifier(Helper.GetModuleForType(nsAlias.AliasedType.ResolvedType).Name.Value); } else { this.ILDasmPaper.Directive(".class extern"); this.QualifiedAliasForType(nestedAlias.ContainingAlias); } this.ILDasmPaper.NewLine(); this.ILDasmPaper.CloseBlock(); }
/// <summary> /// Traverses the children of the alias for type. /// </summary> public virtual void TraverseChildren(IAliasForType aliasForType) { if (this.stopTraversal) return; this.Traverse(aliasForType.AliasedType); if (this.stopTraversal) return; this.Traverse(aliasForType.Attributes); if (this.stopTraversal) return; this.Traverse(aliasForType.Members); }
/// <summary> /// Visits the specified alias for type. /// </summary> /// <param name="aliasForType">Type of the alias for.</param> public virtual void Visit(IAliasForType aliasForType) { // IAliasForType is a base interface that should never be implemented directly. // Get aliasForType to call the most type specific visitor. aliasForType.Dispatch(this); }
/// <summary> /// Rewrites the alias for type /// </summary> public virtual IAliasForType Rewrite(IAliasForType aliasForType) { return aliasForType; }
public override void TraverseChildren(IAliasForType aliasForType) { MethodEnter(aliasForType); base.TraverseChildren(aliasForType); MethodExit(); }
public override void Visit(IAliasForType aliasForType) { allElements.Add(new InvokInfo(Traverser, "IAliasForType", aliasForType)); }
/// <summary> /// Visits the specified alias for type. /// </summary> /// <param name="aliasForType">Type of the alias for.</param> public virtual void Visit(IAliasForType aliasForType) { this.Visit(aliasForType.AliasedType); this.Visit(aliasForType.GetAttributes(Context)); aliasForType.Dispatch(this); }
/// <summary> /// Visits the specified alias for type. /// </summary> public virtual void Visit(IAliasForType aliasForType) { }
/// <summary> /// Returns the data in model file that corresponds to passed CCI2 type /// </summary> /// <param name="typeForwarderDef">The CCI2 type tforwarder o look up</param> public TypeForwarderElement this[IAliasForType typeForwarderDef] { get { IAssembly assemblyDef = Util.GetDefiningAssembly(typeForwarderDef); if (assemblyDef != null) { AssemblyElement assembly; string assemblyName = assemblyDef.Name.Value; if (_reader.Model.Assemblies.TryGetValue(assemblyName, out assembly)) { TypeForwarderElement typeForwarder; string typeForwarderSig = Util.GetTypeForwarderSignature(typeForwarderDef); if (assembly.TypeForwarders.TryGetValue(typeForwarderSig, out typeForwarder)) return typeForwarder; } } return null; } }
public static String GetTypeForwarderSignature(IAliasForType alias) { ITypeReference type = alias.AliasedType; return(GetTypeForwarderSignature(Util.GetDefiningAssembly(type).Name.Value, Util.GetTypeName(type))); }
// Walk up the path of defining namespaces and units until we get to the assembly public static IAssembly GetDefiningAssembly(IAliasForType aliasForType) { INamespaceAliasForType namespaceAliasForType = GetAliasForType(aliasForType); if (namespaceAliasForType == null) return null; INamespaceDefinition containingNamespace = namespaceAliasForType.ContainingNamespace; IUnitNamespace unitNamespace = GetUnitNamespace(containingNamespace); if (unitNamespace == null) return null; IUnit unit = unitNamespace.Unit; IAssembly assembly = GetAssembly(unit); return assembly; }
/// <summary> /// Visits the specified alias for type. /// </summary> public virtual void VisitReference(IAliasForType aliasForType) { //IAliasForType is a base interface that should never be implemented directly. //Get aliasForType to call the most type specific visitor. aliasForType.DispatchAsReference(this); }
private static INamespaceAliasForType GetAliasForType(IAliasForType aliasForType) { INestedAliasForType nestedAliasForType = aliasForType as INestedAliasForType; while (nestedAliasForType != null) { aliasForType = nestedAliasForType.ContainingAlias; nestedAliasForType = aliasForType as INestedAliasForType; } INamespaceAliasForType namespaceAliasForType = aliasForType as INamespaceAliasForType; return namespaceAliasForType; }
/// <summary> /// The nested type this reference resolves to. /// </summary> private INestedTypeDefinition GetResolvedType() { this.aliasForType = Dummy.AliasForType; foreach (ITypeDefinitionMember member in this.ContainingType.ResolvedType.GetMembersNamed(this.name, false)) { INestedTypeDefinition/*?*/ neType = member as INestedTypeDefinition; if (neType != null && neType.GenericParameterCount == this.genericParameterCount) { if (this.ContainingType.IsAlias) { //Then there must be an entry for this nested type in the exported types collection. var assembly = TypeHelper.GetDefiningUnitReference(this).ResolvedUnit as IAssembly; if (assembly != null) { foreach (var alias in assembly.ExportedTypes) { var neAlias = alias as INestedAliasForType; if (neAlias == null) continue; if (neAlias.Name.UniqueKey != this.Name.UniqueKey) continue; if (neAlias.GenericParameterCount != this.GenericParameterCount) continue; if (neAlias.ContainingAlias != this.ContainingType.AliasForType) continue; this.aliasForType = neAlias; break; } } } return neType; } } return Dummy.NestedTypeDefinition; }
public virtual void AddTypeForwarder(IAliasForType alias) { m_implModel.AddTypeForwarderReference(alias); }
public override void TraverseChildren(IAliasForType aliasForType) { // Already outputted these at the top for IAssembly }
/// <summary> /// Traverses the children of the alias for type. /// </summary> public virtual void TraverseChildren(IAliasForType aliasForType) { Contract.Requires(aliasForType != null); if (this.stopTraversal) return; this.Traverse(aliasForType.AliasedType); if (this.stopTraversal) return; this.Traverse(aliasForType.Attributes); if (this.stopTraversal) return; this.Traverse(aliasForType.Members); }
public virtual void AddTypeForwarderReference(IAliasForType alias) { _depot.AddTypeForwarder(alias); }
/// <summary> /// Performs some computation with the alias for type, as a reference. /// </summary> /// <param name="aliasForType"></param> public virtual void VisitReference(IAliasForType aliasForType) { aliasForType.DispatchAsReference(this); }
/// <summary> /// Visits the specified alias for type. /// </summary> public void Visit(IAliasForType aliasForType) { //We should only get here by traversing the ExportedTypes collection of an assembly. Contract.Assume(this.validator.currentAssembly != null); if (aliasForType.AliasedType is Dummy) { this.ReportError(MetadataError.IncompleteNode, aliasForType, "AliasedType"); return; } var definingModule = TypeHelper.GetDefiningUnitReference(aliasForType.AliasedType) as IModuleReference; if (definingModule == null) { this.ReportError(MetadataError.IncompleteNode, aliasForType, "AliasedType"); return; } if (definingModule.ContainingAssembly == null) { //an alias whose module reference is not an assembly, should use a module reference //to a member module of the current assembly. That reference is incomplete if it does //not have a containing assembly. this.ReportError(MetadataError.IncompleteNode, definingModule, "ContainingAssembly"); return; } if (definingModule.ModuleIdentity.Equals(this.validator.currentModule.ModuleIdentity)) { this.ReportError(MetadataError.ExportedTypeBelongsToManifestModule, aliasForType, definingModule); return; } if (!(definingModule is IAssemblyReference) && //this is an alias for an exported type, not a forwarded type. !(definingModule.ContainingAssembly.AssemblyIdentity.Equals(this.validator.currentAssembly.AssemblyIdentity))) { this.ReportError(MetadataError.AliasedTypeDoesNotBelongToAModule, aliasForType, definingModule); return; } foreach (var aliasMember in aliasForType.Members) { //TODO: make the members element type be INestedAliasForType var nestedAlias = aliasMember as INestedAliasForType; if (nestedAlias == null) this.ReportError(MetadataError.UnexpectedAliasMember, aliasMember, aliasForType); } }
/// <summary> /// Traverses the alias for type. /// </summary> public void Traverse(IAliasForType aliasForType) { aliasForType.Dispatch(this.dispatchingVisitor); }
public override void Visit(IAliasForType aliasForType) { if(Process(aliasForType)){visitor.Visit(aliasForType);} base.Visit(aliasForType); }
public ThinTypeForwarder(ThinAssembly declaringAssembly, string assemblyName, string typeName, IncludeStatus includeStatus, IAliasForType alias) { _declaringAssembly = declaringAssembly; _assemblyName = assemblyName; _typeName = typeName; _alias = alias; _includeStatus = includeStatus; }
/// <summary> /// The namespace type this reference resolves to. /// </summary> private INamespaceTypeDefinition GetResolvedType() { this.aliasForType = Dummy.AliasForType; foreach (INamespaceMember member in this.ContainingUnitNamespace.ResolvedUnitNamespace.GetMembersNamed(this.name, false)) { var nsTypeDef = member as INamespaceTypeDefinition; if (nsTypeDef != null) { if (nsTypeDef.GenericParameterCount == this.GenericParameterCount) return nsTypeDef; } else { var nsAlias = member as INamespaceAliasForType; if (nsAlias != null && nsAlias.AliasedType.GenericParameterCount == this.GenericParameterCount) this.aliasForType = nsAlias; } } if (this.aliasForType != null) { var resolvedType = this.aliasForType.AliasedType.ResolvedType as INamespaceTypeDefinition; if (resolvedType != null && resolvedType.GenericParameterCount == this.GenericParameterCount) return resolvedType; } return Dummy.NamespaceTypeDefinition; }
public ThinTypeForwarder(ThinAssembly declaringAssembly, ThinTypeForwarder typeToCopy) { _declaringAssembly = declaringAssembly; _assemblyName = typeToCopy._assemblyName; _typeName = typeToCopy._typeName; _alias = typeToCopy._alias; _includeStatus = typeToCopy._includeStatus; }
public IncludeStatus GetIncludeStatus(IAliasForType typeForwarder) { ThinTypeForwarder modelTypeForwarder; if (!_rootTypeForwarders.TryGetValue(typeForwarder, out modelTypeForwarder)) { if (_depot.TypeForwardersClosure.ContainsKey(Util.GetTypeForwarderSignature(typeForwarder))) { return _closureStatus; } return IncludeStatus.Exclude; } return modelTypeForwarder.IncludeStatus; }
public bool AddTypeForwarder(IAliasForType alias) { String signature = Util.GetTypeForwarderSignature(alias); if (!TypeForwardersClosure.ContainsKey(signature)) { TypeForwardersClosure.Add(signature, alias); _workList.Enqueue(alias); return true; } return false; }
public void LoadMetadata() { foreach (var alias in _declaringAssembly.Metadata.ExportedTypes) { if (Util.GetDefiningAssembly(alias.AliasedType).Name.Value == _assemblyName && Util.GetTypeName(alias.AliasedType) == _typeName) { _alias = alias; break; } } if (_alias == null) { throw new Exception("API type forwarder to '" + Key + "' could not be loaded!"); } }
void QualifiedAliasForType(IAliasForType aliasForType) { INamespaceAliasForType nsAliasForType = aliasForType as INamespaceAliasForType; if (nsAliasForType != null) { bool wasRoot; this.QualifiedUnitNamespace((IUnitNamespace)nsAliasForType.ContainingNamespace, out wasRoot); if (!wasRoot) { this.ILDasmPaper.Symbol("."); } this.ILDasmPaper.Identifier(nsAliasForType.Name.Value); return; } INestedAliasForType nestedAliasForType = aliasForType as INestedAliasForType; if (nestedAliasForType != null) { this.SimpleAliasForType(nestedAliasForType.ContainingAlias); this.ILDasmPaper.Symbol("."); this.ILDasmPaper.Identifier(nestedAliasForType.Name.Value); return; } return; }
void SimpleAliasForType(IAliasForType aliasForType) { INamespaceAliasForType nsAliasForType = aliasForType as INamespaceAliasForType; if (nsAliasForType != null) { this.ILDasmPaper.Identifier(nsAliasForType.Name.Value); return; } INestedAliasForType nstAliasForType = aliasForType as INestedAliasForType; if (nstAliasForType != null) { this.ILDasmPaper.Identifier(nstAliasForType.Name.Value); return; } }