Exemplo n.º 1
0
        private static ReachabilityAnnotation?BuildReachabilityAnnotation(IInvocableDeclarationSyntax invocable)
        {
            var parameters = invocable.Parameters.Select((p, i) => new { Param = p, Index = i })
                             .Where(x => x.Param is INamedParameterSyntax)
                             .ToDictionary(x => ((INamedParameterSyntax)x.Param).Name, x => ParameterReference.Create(x.Index));

            ReachabilityAnnotation?annotation = null;

            var canReach = ToReferences(invocable.ReachabilityAnnotations.CanReachAnnotation, parameters);

            if (canReach.Count != 0)
            {
                var refs = new ReachableReferences(canReach);
                annotation = new ReachabilityAnnotation(ReturnReference.Instance, refs);
            }

            var reachableFrom = ToReferences(invocable.ReachabilityAnnotations.ReachableFromAnnotation, parameters);

            if (reachableFrom.Count != 0)
            {
                var chain = (ReachabilityChain?)annotation ?? new ReachableReferences(ReturnReference.Instance);
                annotation = new ReachabilityAnnotation(reachableFrom, chain);
            }

            return(annotation);
        }
Exemplo n.º 2
0
        private void ResolveReachabilityAnnotations(IInvocableDeclarationSyntax invocable)
        {
            var canReach = invocable.ReachabilityAnnotations.CanReachAnnotation?.Parameters
                           ?? Enumerable.Empty <IParameterNameSyntax>();
            var reachableFrom = invocable.ReachabilityAnnotations.ReachableFromAnnotation?.Parameters
                                ?? Enumerable.Empty <IParameterNameSyntax>();
            var symbols = symbolTree.Children(invocable.Symbol.Result).OfType <BindingSymbol>().ToFixedSet();

            foreach (var syn in canReach.Concat(reachableFrom))
            {
                ResolveReachabilityAnnotation(invocable.File, syn, symbols);
            }
        }
Exemplo n.º 3
0
        private static FixedSet <ReachabilityAnnotation>?BuildReachabilityAnnotations(IInvocableDeclarationSyntax invocable)
        {
            var annotation = BuildReachabilityAnnotation(invocable);

            return(annotation is null ? null : new FixedSet <ReachabilityAnnotation>(annotation.Yield()));
        }