public static bool IsTypeInferred(this CommonForEachStatementSyntax forEachStatement, SemanticModel semanticModel) { switch (forEachStatement.Kind()) { case SyntaxKind.ForEachStatement: return(((ForEachStatementSyntax)forEachStatement).Type.IsTypeInferred(semanticModel)); case SyntaxKind.ForEachComponentStatement: return((((ForEachComponentStatementSyntax)forEachStatement).VariableComponent as TypedVariableComponentSyntax)?.Type.IsTypeInferred(semanticModel) == true); default: return(false); } }
private void VisitCommonForEachStatement(CommonForEachStatementSyntax node) { Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda); var patternBinder = new ExpressionVariableBinder(node.Expression, _enclosing); AddToMap(node.Expression, patternBinder); Visit(node.Expression, patternBinder); var binder = new ForEachLoopBinder(patternBinder, node); AddToMap(node, binder); VisitPossibleEmbeddedStatement(node.Statement, binder); }
internal static void GetLocalNames(CommonForEachStatementSyntax commonForEach, ref List <SyntaxToken> result) { switch (commonForEach.Kind()) { case SyntaxKind.ForEachStatement: GetLocalNames(((ForEachStatementSyntax)commonForEach).Identifier, ref result); return; case SyntaxKind.ForEachVariableStatement: var forEachVariable = (ForEachVariableStatementSyntax)commonForEach; GetLocalNames(forEachVariable.Variable, ref result); return; default: throw ExceptionUtilities.UnexpectedValue(commonForEach.Kind()); } }
private static double ComputeWeightedDistance( CommonForEachStatementSyntax leftCommonForEach, CommonForEachStatementSyntax rightCommonForEach) { var statementDistance = ComputeDistance(leftCommonForEach.Statement, rightCommonForEach.Statement); var expressionDistance = ComputeDistance(leftCommonForEach.Expression, rightCommonForEach.Expression); List <SyntaxToken>?leftLocals = null; List <SyntaxToken>?rightLocals = null; GetLocalNames(leftCommonForEach, ref leftLocals); GetLocalNames(rightCommonForEach, ref rightLocals); var localNamesDistance = ComputeDistance(leftLocals, rightLocals); var distance = localNamesDistance * 0.6 + expressionDistance * 0.2 + statementDistance * 0.2; return(AdjustForLocalsInBlock(distance, leftCommonForEach.Statement, rightCommonForEach.Statement, localsWeight: 0.6)); }
public static bool IsCloseParenInStatement(this SyntaxToken token) { if (!(token.Parent is StatementSyntax statement)) { return(false); } return(statement switch { IfStatementSyntax ifStatement => ifStatement.CloseParenToken.Equals(token), SwitchStatementSyntax switchStatement => switchStatement.CloseParenToken.Equals(token), WhileStatementSyntax whileStatement => whileStatement.CloseParenToken.Equals(token), DoStatementSyntax doStatement => doStatement.CloseParenToken.Equals(token), ForStatementSyntax forStatement => forStatement.CloseParenToken.Equals(token), CommonForEachStatementSyntax foreachStatement => foreachStatement.CloseParenToken.Equals(token), LockStatementSyntax lockStatement => lockStatement.CloseParenToken.Equals(token), UsingStatementSyntax usingStatement => usingStatement.CloseParenToken.Equals(token), FixedStatementSyntax fixedStatement => fixedStatement.CloseParenToken.Equals(token), _ => false, });
public override ForEachStatementInfo GetForEachStatementInfo(CommonForEachStatementSyntax node) { MemberSemanticModel memberModel = GetMemberModel(node); return memberModel == null ? default(ForEachStatementInfo) : memberModel.GetForEachStatementInfo(node); }
private bool AnalyzeForEachStatement(CommonForEachStatementSyntax forEachStatement) => !forEachStatement.Statement.IsKind(SyntaxKind.Block);
public override ForEachStatementInfo GetForEachStatementInfo(CommonForEachStatementSyntax node) { BoundForEachStatement boundForEach = (BoundForEachStatement)GetUpperBoundNode(node); if (boundForEach == null) { return default(ForEachStatementInfo); } ForEachEnumeratorInfo enumeratorInfoOpt = boundForEach.EnumeratorInfoOpt; Debug.Assert(enumeratorInfoOpt != null || boundForEach.HasAnyErrors); if (enumeratorInfoOpt == null) { return default(ForEachStatementInfo); } // Even though we usually pretend to be using System.Collection.IEnumerable // for arrays, that doesn't make sense for pointer arrays since object // (the type of System.Collections.IEnumerator.Current) isn't convertible // to pointer types. if (enumeratorInfoOpt.ElementType.IsPointerType()) { Debug.Assert(!enumeratorInfoOpt.CurrentConversion.IsValid); return default(ForEachStatementInfo); } // NOTE: we're going to list GetEnumerator, etc for array and string // collections, even though we know that's not how the implementation // actually enumerates them. return new ForEachStatementInfo( enumeratorInfoOpt.GetEnumeratorMethod, enumeratorInfoOpt.MoveNextMethod, (PropertySymbol)enumeratorInfoOpt.CurrentPropertyGetter.AssociatedSymbol, enumeratorInfoOpt.NeedsDisposeMethod ? (MethodSymbol)Compilation.GetSpecialTypeMember(SpecialMember.System_IDisposable__Dispose) : null, enumeratorInfoOpt.ElementType, boundForEach.ElementConversion, enumeratorInfoOpt.CurrentConversion); }
private BoundStatement BindForEach(CommonForEachStatementSyntax node, DiagnosticBag diagnostics) { Binder loopBinder = this.GetBinder(node); return this.GetBinder(node.Expression).WrapWithVariablesIfAny(node.Expression, loopBinder.BindForEachParts(diagnostics, loopBinder)); }
internal static void Analyze(SyntaxNodeAnalysisContext context, CommonForEachStatementSyntax node) { AnalyzeEmbeddedStatement(context, node.CloseParenToken, node.Statement); }
public ForEachLoopBinder(Binder enclosing, CommonForEachStatementSyntax syntax) : base(enclosing) { Debug.Assert(syntax != null); _syntax = syntax; }
private void HighlightForEachStatement(CommonForEachStatementSyntax statement, List <TextSpan> spans) { spans.Add(statement.ForEachKeyword.Span); }
internal static void Analyze(SyntaxNodeAnalysisContext context, CommonForEachStatementSyntax forEachStatement) { Analyze(context, forEachStatement.CloseParenToken, forEachStatement.Statement); }
private static BoundBlock CreateBlockDeclaringIterationVariables( ImmutableArray<LocalSymbol> iterationVariables, BoundStatement iteratorVariableInitialization, BoundStatement rewrittenBody, CommonForEachStatementSyntax forEachSyntax) { // The scope of the iteration variable is the embedded statement syntax. // However consider the following foreach statement: // // foreach (int x in ...) { int y = ...; F(() => x); F(() => y)); // // We currently generate 2 closures. One containing variable x, the other variable y. // The EnC source mapping infrastructure requires each closure within a method body // to have a unique syntax offset. Hence we associate the bound block declaring the // iteration variable with the foreach statement, not the embedded statement. return new BoundBlock( forEachSyntax, locals: iterationVariables, localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty, statements: ImmutableArray.Create(iteratorVariableInitialization, rewrittenBody)); }
public TameCommonForEachStatementSyntax(CommonForEachStatementSyntax node) { Node = node; AddChildren(); }
public static bool FormattingSupportsEmbeddedStatement(CommonForEachStatementSyntax forEachStatement) { return(forEachStatement.SyntaxTree.IsSingleLineSpan(forEachStatement.ParenthesesSpan())); }
/// <summary> /// Gets for each statement info. /// </summary> /// <param name="node">The node.</param> public abstract ForEachStatementInfo GetForEachStatementInfo(CommonForEachStatementSyntax node);
internal static void Analyze(SyntaxNodeAnalysisContext context, CommonForEachStatementSyntax forEachStatement) { AnalyzeExpression(context, forEachStatement.Expression); }