Example #1
0
 private static (IXor2ComputationNodeReference, AlreadyProcessedSyntaxNodes) _DispatchXor7ExpressionSyntax(IXor7ExpressionSyntax expressionSyntax, MethodBlockAnalysis methodAnalysis, AlreadyProcessedSyntaxNodes processedNodes, TextSpan span)
 => expressionSyntax.Dispatch
Example #2
0
        static public Maybe <FuncResult <IXor4IdentifierOriginSyntax, SimpleControlFlowAnalysisError> > GetIdentifierDeclarationSyntax(IdentifierNameSyntax syntax, MethodBlockAnalysis methodAnalysis)
        {
            Maybe <FuncResult <IXor4IdentifierOriginSyntax, SimpleControlFlowAnalysisError> > __Ok(IXor4IdentifierOriginSyntax ok) => new FuncResult <IXor4IdentifierOriginSyntax, SimpleControlFlowAnalysisError>(ok);
            Maybe <FuncResult <IXor4IdentifierOriginSyntax, SimpleControlFlowAnalysisError> > __Error(SimpleControlFlowAnalysisError error) => new FuncResult <IXor4IdentifierOriginSyntax, SimpleControlFlowAnalysisError>(error);


            var loopLikeSyntax = syntax.Ancestors().FirstOrDefault(x => SyntaxOperations.IsLoopLike(x));

            if (loopLikeSyntax != null)
            {
                return(__Error(SimpleControlFlowAnalysisError.NotALinearControlFlow(loopLikeSyntax)));
            }
            else
            {
                var symbolInfo = methodAnalysis.SemanticModel.GetSymbolInfo(syntax);


                switch (symbolInfo.Symbol.Kind)
                {
                case SymbolKind.NamedType:
                case SymbolKind.Namespace:
                {
                    return(Maybe.NoValue);
                }

                case SymbolKind.Local:
                {
                    var declaratorSyntax = (VariableDeclaratorSyntax)symbolInfo.Symbol.DeclaringSyntaxReferences.Single().GetSyntax();
                    var delarationSyntax = declaratorSyntax.Ancestors().OfType <LocalDeclarationStatementSyntax>().First();
                    return(__Ok(new Xor4IdentifierOriginSyntax(delarationSyntax)));
                }

                case SymbolKind.Field:
                {
                    var declaringSyntax = (FieldDeclarationSyntax)symbolInfo.Symbol.DeclaringSyntaxReferences.Single().GetSyntax();
                    return(__Ok(new Xor4IdentifierOriginSyntax(declaringSyntax)));
                }

                case SymbolKind.Property:
                {
                    var declaringSyntax = (PropertyDeclarationSyntax)symbolInfo.Symbol.DeclaringSyntaxReferences.Single().GetSyntax();
                    return(__Ok(new Xor4IdentifierOriginSyntax(declaringSyntax)));
                }

                case SymbolKind.Parameter:
                {
                    var declaringSyntax = (ParameterSyntax)symbolInfo.Symbol.DeclaringSyntaxReferences.Single().GetSyntax();
                    return(__Ok(new Xor4IdentifierOriginSyntax(declaringSyntax)));
                }

                default:
                    throw NotPreparedForThatCase.UnexpectedEnumException(symbolInfo.Symbol.Kind);
                }
            }
        }
Example #3
0
        static public (IXor2ComputationNodeReference, AlreadyProcessedSyntaxNodes) FromReturnStatement(ReturnStatementSyntax returnSyntax, MethodBlockAnalysis methodAnalysis, TextSpan span, AlreadyProcessedSyntaxNodes processedNodesOrNull = null)
        {
            Throw.IfNot(methodAnalysis.DataFlowAnalysis.Succeeded);


            var processedNodes = (processedNodesOrNull ?? new AlreadyProcessedSyntaxNodes());

            if (!span.Contains(returnSyntax.Span))
            {
                return(_CreatePair(Xor2ComputationNodeReference.OutOfScope(returnSyntax), processedNodes));
            }

            var rhsSyntax = SyntaxOperations.GetRightHandSideExpression(returnSyntax);

            var previous = _DispatchXor7ExpressionSyntax(rhsSyntax, methodAnalysis, processedNodes ?? new AlreadyProcessedSyntaxNodes(), span);

            var node = ComputationGraphNode.FromReturnStatement(returnSyntax, previous.Item1);


            if (!previous.Item1.IsA)
            {
                return(_CreatePair(node, previous.Item2));
            }


            return(_CreatePair(node, previous.Item2));
        }