public bool ProcessAssembly(AssemblyDefinition assembly, bool optimize) { var aspects = _aspectExtractor.ReadAll(assembly); _log.Log(GeneralRules.Info, $"Found {aspects.Count} aspects"); var injections = _injectionCollector.ReadAll(assembly).ToList(); _log.Log(GeneralRules.Info, $"Found {injections.Count} injections"); if (_log.IsErrorThrown) { return(false); } var hasAspects = aspects.Count != 0; var hasInjections = injections.Count != 0; if (hasAspects) { _log.Log(GeneralRules.Info, "Processing aspects..."); foreach (var aspect in aspects) { _aspectWeaver.WeaveGlobalAssests(aspect); } } if (hasInjections) { _log.Log(GeneralRules.Info, "Processing injections..."); foreach (var injector in _effectWeavers.OrderByDescending(i => i.Priority)) { _log.Log(GeneralRules.Info, $"Executing {injector.GetType().Name}..."); foreach (var prioritizedInjections in injections.GroupBy(i => i.Priority).OrderByDescending(a => a.Key).ToList()) { foreach (var injection in prioritizedInjections.OrderByDescending(i => i.Effect.Priority)) { if (injector.CanWeave(injection)) { injector.Weave(injection); injections.Remove(injection); } } } } foreach (var injection in injections) { _log.Log(GeneralRules.UnexpectedCompilerBehaviour, injection.Target, $"Couldn't find weaver for => {injection.ToString()}"); } } if (hasAspects || hasInjections) { if (optimize) { _log.Log(GeneralRules.Info, "Cleanup and optimize..."); } else { _log.Log(GeneralRules.Info, "Cleanup..."); } foreach (var module in assembly.Modules) { if (optimize) { EditorFactory.Optimize(module); } EditorFactory.CleanUp(module); } return(true); } return(false); }
protected override bool PatchAssembly(AssemblyDefinition assembly, bool optimize) { var aspects = _aspectExtractor.ReadAll(assembly); _log.Log(GeneralRules.Info, $"Found {aspects.Count} aspects"); var injections = _injectionCollector.ReadAll(assembly).ToList(); _log.Log(GeneralRules.Info, $"Found {injections.Count} injections"); if (_log.IsErrorThrown) { return(false); } var hasAspects = aspects.Count != 0; var hasInjections = injections.Count != 0; if (hasAspects) { _log.Log(GeneralRules.Info, "Processing aspects..."); foreach (var aspect in aspects) { _aspectWeaver.WeaveGlobalAssests(aspect); } } var modifiedBodies = new List <MethodBody>(); CutEvents.OnModify = mb => { if (!modifiedBodies.Contains(mb)) { mb.SimplifyMacros(); modifiedBodies.Add(mb); } }; if (hasInjections) { _log.Log(GeneralRules.Info, "Processing injections..."); foreach (var injector in _effectWeavers.OrderByDescending(i => i.Priority)) { _log.Log(GeneralRules.Info, $"Executing {injector.GetType().Name}..."); foreach (var prioritizedInjections in injections.GroupBy(i => i.Priority).OrderByDescending(a => a.Key).ToList()) { foreach (var injection in prioritizedInjections.OrderByDescending(i => i.Effect.Priority)) { if (injector.CanWeave(injection)) { injector.Weave(injection); injections.Remove(injection); } } } } foreach (var injection in injections) { _log.Log(GeneralRules.UnexpectedCompilerBehaviour, injection.Target, $"Couldn't find weaver for => {injection.ToString()}"); } } if (hasAspects || hasInjections) { if (optimize) { _log.Log(GeneralRules.Info, "Optimizing..."); foreach (var mb in modifiedBodies) { mb.OptimizeMacros(); } } _log.Log(GeneralRules.Info, "Processing is done."); return(true); } return(false); }
public void ProcessModule(ModuleDefinition module, bool optimize) { var aspects = _aspectExtractor.ReadAll(module); _weaver.LogInfo($"Found {aspects.Count} aspects"); var injections = _injectionCollector.ReadAll(module).ToList(); _weaver.LogInfo($"Found {injections.Count} injections"); if (aspects.Count != 0) { _weaver.LogInfo($"Processing aspects..."); foreach (var aspect in aspects) { _aspectWeaver.WeaveGlobalAssests(aspect); } } if (injections.Count != 0) { _weaver.LogInfo($"Processing injections..."); foreach (var injector in _effectWeavers.OrderByDescending(i => i.Priority)) { _weaver.LogInfo($"Executing {injector.GetType().Name}..."); foreach (var prioritizedInjections in injections.GroupBy(i => i.Priority).OrderByDescending(a => a.Key).ToList()) { foreach (var injection in prioritizedInjections.OrderByDescending(i => i.Effect.Priority)) { if (injector.CanWeave(injection)) { injector.Weave(injection); injections.Remove(injection); } } } } foreach (var injection in injections) { _weaver.LogError($"Couldn't find weaver for {injection}"); } } if (optimize) { _weaver.LogInfo($"Cleanup and optimize..."); } else { _weaver.LogInfo($"Cleanup..."); } if (optimize) { EditorFactory.Optimize(module); } EditorFactory.CleanUp(module); }