void CollectIssues(AstNode variableDecl, AstNode rootNode, LocalResolveResult resolveResult) { if (resolveResult == null) { return; } var type = resolveResult.Type; var typeDef = type.GetDefinition(); if (typeDef == null || (typeDef.KnownTypeCode != KnownTypeCode.IEnumerable && typeDef.KnownTypeCode != KnownTypeCode.IEnumerableOfT)) { return; } FindReferences(variableDecl, rootNode, resolveResult.Variable); var statements = AnalysisStatementCollector.Collect(variableDecl); var builder = new VariableReferenceGraphBuilder(ctx); foreach (var statement in statements) { var vrNode = builder.Build(statement, references, refStatements, ctx); FindMultipleEnumeration(vrNode); } foreach (var lambda in lambdaExpressions) { var vrNode = builder.Build(references, ctx.Resolver, (Expression)lambda.Body); FindMultipleEnumeration(vrNode); } }
void CollectIssues(AstNode variableDecl, AstNode rootNode, LocalResolveResult resolveResult) { if (resolveResult == null) return; var type = resolveResult.Type; var typeDef = type.GetDefinition (); if (typeDef == null || (typeDef.KnownTypeCode != KnownTypeCode.IEnumerable && typeDef.KnownTypeCode != KnownTypeCode.IEnumerableOfT)) return; FindReferences (variableDecl, rootNode, resolveResult.Variable); var statements = AnalysisStatementCollector.Collect (variableDecl); var builder = new VariableReferenceGraphBuilder (ctx); foreach (var statement in statements) { var vrNode = builder.Build (statement, references, refStatements, ctx); FindMultipleEnumeration (vrNode); } foreach (var lambda in lambdaExpressions) { var vrNode = builder.Build (references, ctx.Resolver, (Expression)lambda.Body); FindMultipleEnumeration (vrNode); } }
void CollectIssues(AstNode variableDecl, BlockStatement rootStatement, LocalResolveResult resolveResult) { if (rootStatement == null || resolveResult == null) return; var references = new HashSet<AstNode> (); var refStatements = new HashSet<Statement> (); var usedInLambda = false; var results = ctx.FindReferences (rootStatement, resolveResult.Variable); foreach (var result in results) { var node = result.Node; if (node == variableDecl) continue; var parent = node.Parent; while (!(parent == null || parent is Statement || parent is LambdaExpression)) parent = parent.Parent; if (parent == null) continue; var statement = parent as Statement; if (statement != null) { references.Add (node); refStatements.Add (statement); } while (parent != null && parent != rootStatement) { if (parent is LambdaExpression || parent is AnonymousMethodExpression) { usedInLambda = true; break; } parent = parent.Parent; } if (usedInLambda) { break; } } // stop analyzing if the variable is used in any lambda expression or anonymous method if (usedInLambda) return; var startNode = new VariableReferenceGraphBuilder (ctx).Build (rootStatement, references, refStatements, ctx); var variableInitializer = variableDecl as VariableInitializer; if (variableInitializer != null && !variableInitializer.Initializer.IsNull) startNode.References.Insert (0, variableInitializer); ProcessNodes (startNode); }
void CollectIssues(AstNode variableDecl, BlockStatement rootStatement, LocalResolveResult resolveResult) { if (rootStatement == null || resolveResult == null) { return; } var references = new HashSet <AstNode>(); var refStatements = new HashSet <Statement>(); var usedInLambda = false; var results = ctx.FindReferences(rootStatement, resolveResult.Variable); foreach (var result in results) { var node = result.Node; if (node == variableDecl) { continue; } var parent = node.Parent; while (!(parent == null || parent is Statement || parent is LambdaExpression || parent is QueryExpression)) { parent = parent.Parent; } if (parent == null) { continue; } var statement = parent as Statement; if (statement != null) { references.Add(node); refStatements.Add(statement); } while (parent != null && parent != rootStatement) { if (parent is LambdaExpression || parent is AnonymousMethodExpression || parent is QueryExpression) { usedInLambda = true; break; } parent = parent.Parent; } if (usedInLambda) { break; } } // stop analyzing if the variable is used in any lambda expression or anonymous method if (usedInLambda) { return; } var startNode = new VariableReferenceGraphBuilder(ctx).Build(rootStatement, references, refStatements, ctx); var variableInitializer = variableDecl as VariableInitializer; if (variableInitializer != null && !variableInitializer.Initializer.IsNull) { startNode.References.Insert(0, variableInitializer); } ProcessNodes(startNode); }