コード例 #1
0
        private static void CheckForNoExitProperty(SyntaxNodeAnalysisContext c)
        {
            var property       = (PropertyDeclarationSyntax)c.Node;
            var propertySymbol = c.SemanticModel.GetDeclaredSymbol(property);

            if (propertySymbol == null)
            {
                return;
            }

            IControlFlowGraph cfg;

            if (property.ExpressionBody?.Expression != null)
            {
                if (CSharpControlFlowGraph.TryGet(property.ExpressionBody.Expression, c.SemanticModel, out cfg))
                {
                    var walker = new CfgWalkerForProperty(
                        new RecursionAnalysisContext(cfg, propertySymbol, property.Identifier.GetLocation(), c),
                        "property's recursion",
                        isSetAccessor: false);
                    walker.CheckPaths();
                }
                return;
            }

            var accessors = property.AccessorList?.Accessors.Where(a => a.HasBodyOrExpressionBody());

            if (accessors != null)
            {
                foreach (var accessor in accessors)
                {
                    var bodyNode = (CSharpSyntaxNode)accessor.Body ?? accessor.ExpressionBody();
                    if (CSharpControlFlowGraph.TryGet(bodyNode, c.SemanticModel, out cfg))
                    {
                        var walker = new CfgWalkerForProperty(
                            new RecursionAnalysisContext(cfg, propertySymbol, accessor.Keyword.GetLocation(), c),
                            "property accessor's recursion",
                            isSetAccessor: accessor.Keyword.IsKind(SyntaxKind.SetKeyword));
                        walker.CheckPaths();

                        CheckInfiniteJumpLoop(bodyNode, cfg, "property accessor", c);
                    }
                }
            }
        }
コード例 #2
0
        private static void CheckForNoExitProperty(SyntaxNodeAnalysisContext c)
        {
            var property = (PropertyDeclarationSyntax)c.Node;
            var propertySymbol = c.SemanticModel.GetDeclaredSymbol(property);
            if (propertySymbol == null)
            {
                return;
            }

            IControlFlowGraph cfg;
            if (property.ExpressionBody?.Expression != null)
            {
                if (ControlFlowGraph.TryGet(property.ExpressionBody.Expression, c.SemanticModel, out cfg))
                {
                    var walker = new CfgWalkerForProperty(
                         new RecursionAnalysisContext(cfg, propertySymbol, property.Identifier.GetLocation(), c),
                        "property's recursion",
                        isSetAccessor: false);
                    walker.CheckPaths();
                }
                return;
            }

            var accessors = property.AccessorList?.Accessors.Where(a => a.Body != null);
            if (accessors != null)
            {
                foreach (var accessor in accessors)
                {
                    if (ControlFlowGraph.TryGet(accessor.Body, c.SemanticModel, out cfg))
                    {
                        var walker = new CfgWalkerForProperty(
                            new RecursionAnalysisContext(cfg, propertySymbol, accessor.Keyword.GetLocation(), c),
                            "property accessor's recursion",
                            isSetAccessor: accessor.Keyword.IsKind(SyntaxKind.SetKeyword));
                        walker.CheckPaths();

                        CheckInfiniteJumpLoop(accessor.Body, cfg, "property accessor", c);
                    }
                }
            }
        }