private static ILSpan GetReuseSpan(ArrayBuilder <ISymUnmanagedScope> scopes, int ilOffset, bool isEndInclusive)
 {
     return(MethodContextReuseConstraints.CalculateReuseSpan(
                ilOffset,
                ILSpan.MaxValue,
                scopes.Select(scope => new ILSpan((uint)scope.GetStartOffset(), (uint)(scope.GetEndOffset() + (isEndInclusive ? 1 : 0))))));
 }
        /// <summary>
        /// Generate a list containing the given field and all dependencies
        /// of that field that require evaluation. The list is ordered by
        /// dependencies, with fields with no dependencies first. Cycles are
        /// broken at the first field lexically in the cycle. If multiple threads
        /// call this method with the same field, the order of the fields
        /// returned should be the same, although some fields may be missing
        /// from the lists in some threads as other threads evaluate fields.
        /// </summary>
        internal static void OrderAllDependencies(
            this SourceFieldSymbol field,
            ArrayBuilder <FieldInfo> order,
            bool earlyDecodingWellKnownAttributes)
        {
            Debug.Assert(order.Count == 0);

            var graph = PooledDictionary <SourceFieldSymbol, Node <SourceFieldSymbol> > .GetInstance();

            CreateGraph(graph, field, earlyDecodingWellKnownAttributes);

            Debug.Assert(graph.Count >= 1);
            CheckGraph(graph);

#if DEBUG
            var fields = ArrayBuilder <SourceFieldSymbol> .GetInstance();

            fields.AddRange(graph.Keys);
#endif

            OrderGraph(graph, order);

#if DEBUG
            // Verify all entries in the graph are in the ordered list.
            var map = new HashSet <SourceFieldSymbol>(order.Select(o => o.Field).Distinct());
            Debug.Assert(fields.All(f => map.Contains(f)));
            fields.Free();
#endif

            graph.Free();
        }
        private static string[] GetLocalNames(EvaluationContext context)
        {
            string unused;
            var    locals = new ArrayBuilder <LocalAndMethod>();

            context.CompileGetLocals(locals, argumentsOnly: false, typeName: out unused, testData: null);
            return(locals.Select(l => l.LocalName).ToArray());
        }
Exemple #4
0
        internal void VerifyLineEdits(
            EditScript <SyntaxNode> editScript,
            IEnumerable <SequencePointUpdates> expectedLineEdits,
            IEnumerable <string> expectedNodeUpdates,
            RudeEditDiagnosticDescription[] expectedDiagnostics)
        {
            var newText = SourceText.From(editScript.Match.NewRoot.SyntaxTree.ToString());

            var diagnostics = new ArrayBuilder <RudeEditDiagnostic>();
            var editMap     = BuildEditMap(editScript);

            var triviaEdits     = new ArrayBuilder <(SyntaxNode OldNode, SyntaxNode NewNode)>();
            var actualLineEdits = new ArrayBuilder <SequencePointUpdates>();

            Analyzer.GetTestAccessor().AnalyzeTrivia(
                editScript.Match,
                editMap,
                triviaEdits,
                actualLineEdits,
                diagnostics,
                default);

            VerifyDiagnostics(expectedDiagnostics, diagnostics, newText);

            // check files are matching:
            AssertEx.Equal(
                expectedLineEdits.Select(e => e.FileName),
                actualLineEdits.Select(e => e.FileName),
                itemSeparator: ",\r\n");

            // check lines are matching:
            _ = expectedLineEdits.Zip(actualLineEdits, (expected, actual) =>
            {
                AssertEx.Equal(
                    expected.LineUpdates,
                    actual.LineUpdates,
                    itemSeparator: ",\r\n",
                    itemInspector: s => $"new({s.OldLine}, {s.NewLine})");

                return(true);
            }).ToArray();

            var actualNodeUpdates = triviaEdits.Select(e => e.NewNode.ToString().ToLines().First());

            AssertEx.Equal(expectedNodeUpdates, actualNodeUpdates, itemSeparator: ",\r\n");
        }
 private static string[] GetLocalNames(EvaluationContext context)
 {
     string unused;
     var locals = new ArrayBuilder<LocalAndMethod>();
     context.CompileGetLocals(locals, argumentsOnly: false, typeName: out unused);
     return locals.Select(l => l.LocalName).ToArray();
 }