Exemplo n.º 1
0
        private StructureInspectionResult AnalyzeCompilation(CompilationResult compilationResult)
        {
            var traceList = new List <TraceResult>(compilationResult.CompiledConfiguration.Count);
            var stack     = new Stack <TraceResult>();

            // prepare stack with initial data
            foreach (var item in compilationResult.CompilationTrace)
            {
                stack.Push(item);
            }
            while (stack.TryPop(out var item))
            {
                traceList.Add(item);
                foreach (var child in item.Children)
                {
                    stack.Push(child);
                }
            }

            var warnings = new Dictionary <string, List <string> >();

            foreach (var traceResult in traceList.OfType <KeyTraceResult>())
            {
                foreach (var warning in traceResult.Warnings)
                {
                    if (!warnings.ContainsKey(traceResult.Key))
                    {
                        warnings.Add(traceResult.Key, new List <string>());
                    }
                    warnings[traceResult.Key].Add(warning);
                }
            }

            var errors = new Dictionary <string, List <string> >();

            foreach (var traceResult in traceList.OfType <KeyTraceResult>())
            {
                foreach (var error in traceResult.Errors)
                {
                    if (!errors.ContainsKey(traceResult.Key))
                    {
                        errors.Add(traceResult.Key, new List <string>());
                    }
                    errors[traceResult.Key].Add(error);
                }
            }

            var result = new StructureInspectionResult
            {
                CompiledConfiguration = compilationResult.CompiledConfiguration,
                CompilationSuccessful = true,
                Stats = new CompilationStats
                {
                    ReferencesUsed   = traceList.OfType <MultiTraceResult>().Count(),
                    StaticValuesUsed = traceList.OfType <ValueTraceResult>().Count()
                },
                Warnings = warnings,
                Errors   = errors,
                UsedKeys = compilationResult.GetUsedKeys().ToList()
            };

            return(result);
        }