internal IEnumerable <IMethodDefinition> getReachableMethodsFromMethod(IMethodReference method, IEnumerable <IModule> modules) { IEnumerable <IAssembly> assemblies = getAssembliesFromModules(modules); Microsoft.Cci.MetadataReaderHost readerHost = host as Microsoft.Cci.MetadataReaderHost; if (readerHost == null) { return(new List <IMethodDefinition>()); //? } ILGarbageCollect.Mark.WholeProgram program = new ILGarbageCollect.Mark.WholeProgram(assemblies, readerHost); RapidTypeAnalysis analyzer = new RapidTypeAnalysis(program, TargetProfile.Phone); analyzer.Run(new IMethodReference[] { method }); return(analyzer.ReachableMethods()); }
public PhoneNavigationCodeTraverser(MetadataReaderHost host, IEnumerable<IAssemblyReference> assemblies) : base() { this.host = host; List<IAssembly> assembliesTraversed = new List<IAssembly>(); foreach (IAssemblyReference asmRef in assemblies) { assembliesTraversed.Add(asmRef.ResolvedAssembly); } Microsoft.Cci.Immutable.PlatformType platform = host.PlatformType as Microsoft.Cci.Immutable.PlatformType; // TODO obtain version, culture and signature data dynamically IAssemblyReference assembly= PhoneTypeHelper.getPhoneAssemblyReference(host); // TODO determine the needed types dynamically navigationSvcType = platform.CreateReference(assembly, "System", "Windows", "Navigation", "NavigationService"); assembly = PhoneTypeHelper.getSystemAssemblyReference(host); cancelEventArgsType = platform.CreateReference(assembly, "System", "ComponentModel", "CancelEventArgs"); navigationCallers = new HashSet<IMethodReference>(); }
public static AssemblyIdentity GetAssemblyIdentity(EnvDTE.Project project, MetadataReaderHost host) { Contract.Requires(project != null); Contract.Requires(host != null); if (!ProjectIsAvailable(project)) return null; VSServiceProvider.Current.Logger.WriteToLog("Getting the assembly identity for project: " + project.Name); string location_RootDir = null; string location_RelativeAssemblyDir = null; string location_FileName = null; string location = null; IName iName = null; string culture = "";//TODO: Find out where to get culture information. Version version = new Version(); AssemblyIdentity result = null; try { var activePropCount = project.ConfigurationManager != null && project.ConfigurationManager.ActiveConfiguration != null && project.ConfigurationManager.ActiveConfiguration.Properties != null ? project.ConfigurationManager.ActiveConfiguration.Properties.Count : 0; for (int i = activePropCount; 1 <= i; i--) { var prop = project.ConfigurationManager.ActiveConfiguration.Properties.Item(i); if (prop == null) continue; if (prop.Name == "OutputPath") { location_RelativeAssemblyDir = prop.Value as string; break; } } var propCount = project.Properties != null ? project.Properties.Count : 0; for (int i = propCount; 1 <= i; i--) { var prop = project.Properties.Item(i); if (prop == null) continue; switch (prop.Name) { case "AssemblyName": iName = host.NameTable.GetNameFor(prop.Value as string); break; case "AssemblyVersion": var stringVersion = prop.Value as string; if (!Version.TryParse(stringVersion, out version)) { version = new Version(); } Contract.Assume(version != null); break; case "FullPath": location_RootDir = prop.Value as string; break; case "OutputFileName": location_FileName = prop.Value as string; break; default: break; } } } catch (COMException comEx) { VSServiceProvider.Current.Logger.WriteToLog("COM Exception while trying to access project's properties."); VSServiceProvider.Current.Logger.WriteToLog("Message: " + comEx.Message); if (comEx.Message.Contains(COMExceptionMessage_ProjectUnavailable)) { VSServiceProvider.Current.Logger.WriteToLog("Returning null."); return null; } else if (((uint)comEx.ErrorCode) == 0x80020009) { VSServiceProvider.Current.Logger.WriteToLog("Returning null."); return null; } else { throw comEx; } } //Check if we got enough information from VS to build the location if (location_FileName == null || location_RelativeAssemblyDir == null || location_RootDir == null) { VSServiceProvider.Current.Logger.WriteToLog("Couldn't find path to the project's output assembly."); return null; } //Set the location of the output assembly location = Path.Combine(location_RootDir, location_RelativeAssemblyDir, location_FileName); //Check that the output assembly exists if (!File.Exists(location)) { VSServiceProvider.Current.Logger.WriteToLog("Project output assembly could not be found at the location given by Visual Studio: " + location); } //Check our other information from VS if (iName == null || string.IsNullOrEmpty(location)) { VSServiceProvider.Current.Logger.WriteToLog("Couldn't gather sufficient information from the project to construct an assembly identity."); return null; } //Success Contract.Assert(version != null); Contract.Assert(culture != null); result = new AssemblyIdentity(iName, culture, version, Enumerable<byte>.Empty, location); host.AddLibPath(Path.Combine(location_RootDir, location_RelativeAssemblyDir, "CodeContracts")); host.AddLibPath(Path.Combine(location_RootDir, location_RelativeAssemblyDir, @"..\Debug\CodeContracts")); return result; }
public static void AddProjectReferencesPathsIntoHost(References references, MetadataReaderHost host) { Contract.Requires(host != null); if (references == null) return; for (int i = 1; i <= references.Count; i++) { var tempRef = references.Item(i); if (tempRef == null) continue; var refPath = tempRef.Path; if (!String.IsNullOrEmpty(refPath)) { var refDir = Path.GetDirectoryName(refPath); if (refDir != null) { host.AddLibPath(refDir); var referenceAssemblyPath = Path.Combine(refDir, "CodeContracts"); if (System.IO.Directory.Exists(referenceAssemblyPath)) host.AddLibPath(referenceAssemblyPath); } } } }
private CciModuleSource(MetadataReaderHost host, IAssembly module) : this(host) { _moduleInfoList.Add(new ModuleInfo(module)); }
public CciModuleSource(MetadataReaderHost host, List<ModuleInfo> moduleInfoList) : this(host) { _moduleInfoList = moduleInfoList; }
public CciModuleSource(MetadataReaderHost host = null) { pdbReaders = new Dictionary<string, PdbReader>(StringComparer.OrdinalIgnoreCase); _host = host ?? new PeReader.DefaultHost(); _moduleInfoList = new List<ModuleInfo>(); }
public PhoneNavigationMetadataTraverser(MetadataReaderHost host) : base() { this.host = host; }
private static void RewriteBinary( Assembly copy, AssemblyReport assemblyReport, MetadataReaderHost host, string outputPath, MethodRemoval methodRemoval, StubMethodBodyEmitter stubEmitter) { /* This is an attempt to decouple the MethodRemoval commandline options * from the tree shaker, but it doesn't really seem to be working. * Might be better to just pass the method removal directly to * the rewriter. */ bool removeMethods = (methodRemoval == MethodRemoval.Remove); bool fullDebugStubs = (methodRemoval == MethodRemoval.Debug); bool dryRun = (methodRemoval == MethodRemoval.None); PdbReader/*?*/ pdbReader = null; string pdbFile = Path.ChangeExtension(copy.Location, "pdb"); if (File.Exists(pdbFile)) { using (var pdbStream = File.OpenRead(pdbFile)) { pdbReader = new PdbReader(pdbStream, host); } } else { Console.WriteLine("Could not load the PDB file for '" + copy.Name.Value + "' . Proceeding anyway."); } using (pdbReader) { var localScopeProvider = pdbReader == null ? null : new ILGenerator.LocalScopeProvider(pdbReader); var outputFileName = Path.GetFileNameWithoutExtension(outputPath); using (var peStream = File.Create(outputPath)) { using (var pdbWriter = new PdbWriter(outputFileName + ".pdb", pdbReader)) { var rewriter = new TreeShakingRewriter(host, assemblyReport, dryRun, removeMethods, fullDebugStubs, stubEmitter); IAssembly rewrittenCopy = rewriter.Rewrite(copy); PeWriter.WritePeToStream(rewrittenCopy, host, peStream, pdbReader, localScopeProvider, pdbWriter); } } } }
public void Dispose() { _mutableAssembly = null; _host.Dispose(); _host = null; }
public PhoneInitializationCodeTraverser(MetadataReaderHost host, IMethodDefinition traversedMethod) : base() { this.methodBeingTraversed = traversedMethod; this.host = host; InitializeTraverser(); }
public PhoneInitializationMetadataTraverser(MetadataReaderHost host) : base() { this.host = host; }