public AnalysisNet.Assembly ExtractAssembly() { // create empty assembly AnalysisNet.Assembly assembly = new AnalysisNet.Assembly(module.Assembly.Name.Name); // populate assembly references assembly.References.AddRange(ExtractAssemblyReferences()); // create root namespace // every other namespace is created while processing each cecil type definition assembly.RootNamespace = new AnalysisNet.Namespace(string.Empty) { ContainingAssembly = new AnalysisNet.AssemblyReference(assembly.Name) }; namespaces[string.Empty] = assembly.RootNamespace; // re use the same object because it contains a cache inside // but be sure typeExtractor is not referenced forever // otherwise we would not dipose cecil code model TypeExtractor typeExtractor = new TypeExtractor(host); // if cecilType is a nested type, we guarantee that we have already visited its declaring type foreach (Cecil.TypeDefinition cecilType in module.TraverseTypes()) { ExtractTypeDefinition(cecilType, assembly, typeExtractor); } return(assembly); }
public CodeProvider(TypeExtractor typeExtractor) { this.typeExtractor = typeExtractor; parameters = new Dictionary <int, AnalysisNetTac.Values.IVariable>(); locals = new Dictionary <int, AnalysisNetTac.Values.IVariable>(); }
// the extracted type is added to the expected namespace // if cecilType is a nested type, we guarantee that we have already visited its declaring type private void ExtractTypeDefinition(Cecil.TypeDefinition cecilType, AnalysisNet.Assembly assembly, TypeExtractor typeExtractor) { // afaik it is not necessary to generate this class // for instance cci does not even load it although cecil does if (cecilType.Name.Equals("<Module>") && cecilType.BaseType == null) { return; } AnalysisNet.Types.TypeDefinition extractedType = typeExtractor.ExtractTypeDefinition(cecilType); typeDefinitions[cecilType] = extractedType; extractedType.ContainingAssembly = assembly; // analysis-net does not follow ecma standard for nested types // analysis-net expects to have nested types in their ContainingType.Types and share the same namespace that its enclosing type. // However, nested types should not be added to the ContainingNamespace.Types // If the type is not nested then the processed type is added to its namespace directly if (cecilType.DeclaringType != null) { AnalysisNet.Types.TypeDefinition containingType = typeDefinitions[cecilType.DeclaringType]; extractedType.ContainingType = containingType; containingType.Types.Add(extractedType); extractedType.ContainingNamespace = containingType.ContainingNamespace; } else { AnalysisNet.Namespace ns = GetOrCreateNamespace(cecilType.Namespace); extractedType.ContainingNamespace = ns; ns.Types.Add(extractedType); } }
public GenericParameterExtractor(TypeExtractor typeExtractor) { this.typeExtractor = typeExtractor; genericParamsMap = new Dictionary <Cecil.IGenericParameterProvider, GenericParameterMap>(); }