Exemple #1
0
        private static bool CanBeMarkedAsConst(
            SeparatedSyntaxList <VariableDeclaratorSyntax> variables,
            SyntaxList <StatementSyntax> statements,
            int startIndex)
        {
            MarkLocalVariableAsConstWalker walker = MarkLocalVariableAsConstWalkerCache.GetInstance();

            foreach (VariableDeclaratorSyntax variable in variables)
            {
                walker.Identifiers.Add(variable.Identifier.ValueText);
            }

            for (int i = startIndex; i < statements.Count; i++)
            {
                walker.Visit(statements[i]);

                if (walker.IsMatch)
                {
                    MarkLocalVariableAsConstWalkerCache.Free(walker);
                    return(false);
                }
            }

            MarkLocalVariableAsConstWalkerCache.Free(walker);
            return(true);
        }
Exemple #2
0
        private static bool IsAnyVariableAssigned(SeparatedSyntaxList <VariableDeclaratorSyntax> variables, SyntaxList <StatementSyntax> statements, int startIndex)
        {
            for (int i = startIndex; i < statements.Count; i++)
            {
                MarkLocalVariableAsConstWalker walker = MarkLocalVariableAsConstWalkerCache.Acquire();

                walker.Visit(statements[i]);

                HashSet <string> assigned = MarkLocalVariableAsConstWalkerCache.GetAssignedAndRelease(walker);

                if (assigned != null)
                {
                    foreach (VariableDeclaratorSyntax variable in variables)
                    {
                        if (assigned.Contains(variable.Identifier.ValueText))
                        {
                            return(true);
                        }
                    }

                    walker.Clear();
                }
            }

            return(false);
        }