예제 #1
0
    public static void ProcessLeftSideOfAssignment(ISymbol variable, BlockSyntax block, SemanticModel semanticModel, CancellationToken cancellationToken, RefCounterStatus status)
    {
        List <AssignmentExpressionSyntax> rc = new List <AssignmentExpressionSyntax>();

        using (var walker = AssignmentWalker.Borrow(block, Search.TopLevel, semanticModel, cancellationToken))
        {
            foreach (AssignmentExpressionSyntax assignment in walker.Assignments)
            {
                var sym = ModelExtensions.GetSymbolInfo(semanticModel, assignment.Left, cancellationToken);
                if (variable.Equals(sym.Symbol))
                {
                    AssignmentUtils.CalcAssignmentValue(assignment.Right, block, semanticModel, cancellationToken, status);
                }
            }
        }
    }
예제 #2
0
        private static void HandleLocalVariable(SyntaxNodeAnalysisContext context, VariableDeclaratorSyntax variable)
        {
            if (context.SemanticModel.GetDeclaredSymbolSafe(variable, context.CancellationToken) is
                ILocalSymbol local)
            {
                var block = variable.FirstAncestorOrSelf <BlockSyntax>();
                if (block == null)
                {
                    return;
                }
                RefCounterStatus status = new RefCounterStatus();

                AssignmentUtils.ProcessVariableInitialization(variable, block, context.SemanticModel, context.CancellationToken, status);

                ProcessLocalOrParamenterVar(context, local, block, status);
            }
        }
예제 #3
0
        private static void HandleInvocation(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation)
        {
            var semanticModle = context.SemanticModel;
            var canel         = context.CancellationToken;
            var symbolInfo    = semanticModle.GetSymbolInfo(invocation.Expression, canel);

            if (symbolInfo.Symbol is IMethodSymbol methodSymbol)
            {
                if (RefCounter.IsAssignableTo(methodSymbol.ReturnType))
                {
                    if (!AssignmentUtils.IsGetMethod(invocation, context.SemanticModel, context.CancellationToken))
                    {
                        ProcessCreation(invocation, context);
                    }
                }
            }
        }
예제 #4
0
        private static void ProcessLocalOrParamenterVar(SyntaxNodeAnalysisContext context, ISymbol local,
                                                        BlockSyntax block, RefCounterStatus status)
        {
            RightOfAssignmentUtils.ProcessRightSideOfAssignment(local, block, context.SemanticModel,
                                                                context.CancellationToken, status);

            SystemCollectionUtils.ProcessAddedToCollection(local, block, context.SemanticModel, context.CancellationToken,
                                                           status);
            LeftOfAssignmentUtils.ProcessLeftSideOfAssignment(local, block, context.SemanticModel,
                                                              context.CancellationToken, status);

            ChangeReferenceMethodUtils.ProcessIncDelRefInvocation(local, block, context.SemanticModel, context.CancellationToken,
                                                                  status);

            AssignmentUtils.ProcessOutRefInvocation(local, block, context.SemanticModel, context.CancellationToken, status);

            ReturnUtils.ProcessReturnStatement(local, block, context.SemanticModel, context.CancellationToken, status);

            ReportError(context, local, status);
        }