private static Result IsCreationCore(RecursiveValues values, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            values.Reset();
            var result = Result.No;

            while (values.MoveNext())
            {
                switch (IsCreationCore(values.Current, semanticModel, cancellationToken))
                {
                case Result.Unknown:
                    if (result == Result.No)
                    {
                        result = Result.Unknown;
                    }

                    break;

                case Result.Yes:
                    return(Result.Yes);

                case Result.No:
                    break;

                case Result.Maybe:
                    result = Result.Maybe;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(result);
        }
Пример #2
0
        internal static Result IsAnyCreation(RecursiveValues values, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (values.IsEmpty)
            {
                return(Result.No);
            }

            values.Reset();
            var result = Result.No;

            while (values.MoveNext())
            {
                switch (IsCreationCore(values.Current, semanticModel, cancellationToken))
                {
                case Result.Unknown:
                    if (result == Result.No)
                    {
                        result = Result.Unknown;
                    }

                    break;

                case Result.Yes:
                    return(Result.Yes);

                case Result.AssumeYes:
                    result = Result.AssumeYes;
                    break;

                case Result.No:
                    break;

                case Result.AssumeNo:
                    if (result == Result.No)
                    {
                        result = Result.AssumeNo;
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(result);
        }
Пример #3
0
        internal static Result IsAnyCachedOrInjected(RecursiveValues values, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (values.IsEmpty)
            {
                return(Result.No);
            }

            var result = Result.No;

            values.Reset();
            while (values.MoveNext())
            {
                if (values.Current is ElementAccessExpressionSyntax elementAccess &&
                    semanticModel.TryGetSymbol(elementAccess.Expression, cancellationToken, out var symbol))
                {
                    var isInjected = IsInjectedCore(symbol);
                    if (isInjected == Result.Yes)
                    {
                        return(Result.Yes);
                    }

                    if (isInjected == Result.AssumeYes)
                    {
                        result = Result.AssumeYes;
                    }

                    using var assignedValues = AssignedValueWalker.Borrow(values.Current, semanticModel, cancellationToken);
                    using var recursive      = RecursiveValues.Borrow(assignedValues, semanticModel, cancellationToken);
                    isInjected = IsAnyCachedOrInjected(recursive, semanticModel, cancellationToken);
                    if (isInjected == Result.Yes)
                    {
                        return(Result.Yes);
                    }

                    if (isInjected == Result.AssumeYes)
                    {
                        result = Result.AssumeYes;
                    }
                }
        private static Result IsInjectedCore(RecursiveValues values, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (values.Count == 0)
            {
                return(Result.No);
            }

            var result = Result.No;

            values.Reset();
            while (values.MoveNext())
            {
                if (values.Current is ElementAccessExpressionSyntax elementAccess)
                {
                    var symbol     = semanticModel.GetSymbolSafe(elementAccess.Expression, cancellationToken);
                    var isInjected = IsInjectedCore(symbol);
                    if (isInjected == Result.Yes)
                    {
                        return(Result.Yes);
                    }

                    if (isInjected == Result.Maybe)
                    {
                        result = Result.Maybe;
                    }

                    using (var assignedValues = AssignedValueWalker.Borrow(values.Current, semanticModel, cancellationToken))
                    {
                        using (var recursive = RecursiveValues.Create(assignedValues, semanticModel, cancellationToken))
                        {
                            isInjected = IsInjectedCore(recursive, semanticModel, cancellationToken);
                            if (isInjected == Result.Yes)
                            {
                                return(Result.Yes);
                            }

                            if (isInjected == Result.Maybe)
                            {
                                result = Result.Maybe;
                            }
                        }
                    }
                }
                else
                {
                    var symbol     = semanticModel.GetSymbolSafe(values.Current, cancellationToken);
                    var isInjected = IsInjectedCore(symbol);
                    if (isInjected == Result.Yes)
                    {
                        return(Result.Yes);
                    }

                    if (isInjected == Result.Maybe)
                    {
                        result = Result.Maybe;
                    }
                }
            }

            return(result);
        }