本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ForStatementSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ForStatementSyntax类的具体用法?C# ForStatementSyntax怎么用?C# ForStatementSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForStatementSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ForStatementSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasAcceptableIncrementors
static bool HasAcceptableIncrementors(ForStatementSyntax @for)
{
if (@for.Incrementors.Count != 1) return false;
var unary = @for.Incrementors[0] as PostfixUnaryExpressionSyntax;
if (unary == null) return false;
return unary.IsKind(SyntaxKind.PostIncrementExpression) || unary.IsKind(SyntaxKind.PostDecrementExpression);
}
示例2: AreDeclarationConditionAndIncrementorUsingTheSameVariable
static bool AreDeclarationConditionAndIncrementorUsingTheSameVariable(ForStatementSyntax @for)
{
SyntaxToken reference;
if (@for.Declaration != null)
{
reference = @for.Declaration.Variables[0].Identifier;
}
else
{
var initializer = @for.Initializers[0] as AssignmentExpressionSyntax;
if (initializer == null) return false;
var name = initializer.Left as IdentifierNameSyntax;
if (name == null) return false;
reference = name.Identifier;
}
var condition = @for.Condition as BinaryExpressionSyntax;
var incrementor = @for.Incrementors[0] as PostfixUnaryExpressionSyntax;
if (!(condition.Left is IdentifierNameSyntax)) return false;
if (!(incrementor.Operand is IdentifierNameSyntax)) return false;
var conditionVariableIdentifier = (condition.Left as IdentifierNameSyntax).Identifier;
var incrementorVariableIdentifier = (incrementor.Operand as IdentifierNameSyntax).Identifier;
return reference.Text == conditionVariableIdentifier.Text
&& reference.Text == incrementorVariableIdentifier.Text;
}
示例3: BindForParts
private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
{
BoundStatement initializer;
if (node.Declaration != null)
{
Debug.Assert(node.Initializers.Count == 0);
if (node.Declaration.IsDeconstructionDeclaration)
{
initializer = originalBinder.BindDeconstructionDeclaration(node.Declaration, node.Declaration, diagnostics);
}
else
{
ImmutableArray<BoundLocalDeclaration> unused;
initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.ForInitializerVariable, diagnostics, out unused);
}
}
else
{
initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
}
var condition = (node.Condition != null) ? originalBinder.BindBooleanExpression(node.Condition, diagnostics) : null;
var increment = originalBinder.BindStatementExpressionList(node.Incrementors, diagnostics);
var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);
Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
return new BoundForStatement(node,
this.Locals,
initializer,
condition,
increment,
body,
this.BreakLabel,
this.ContinueLabel);
}
示例4: AddBraces
public static ForStatementSyntax AddBraces(ForStatementSyntax forStatement)
{
Debug.Assert(forStatement != null && NeedsBraces(forStatement));
return forStatement
.WithStatement(SyntaxFactory.Block(forStatement.Statement))
.WithAdditionalAnnotations(Formatter.Annotation);
}
示例5: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
if (node.Condition != null)
{
_builder.Add(node);
}
base.VisitForStatement(node);
}
示例6: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
if (!(node.Statement is BlockSyntax))
{
CreateAuditVariable(node.Statement);
}
base.VisitForStatement(node);
}
示例7: HasConditionCompatibleWithTheIncrementor
static bool HasConditionCompatibleWithTheIncrementor(ForStatementSyntax @for)
{
var condition = @for.Condition as BinaryExpressionSyntax;
var postIncrement = IsPostIncrement(@for.Incrementors[0]);
return condition != null &&
(
(postIncrement && condition.OperatorToken.IsKind(SyntaxKind.LessThanToken)) ||
(!postIncrement && condition.OperatorToken.IsKind(SyntaxKind.GreaterThanEqualsToken))
);
}
示例8: ForInitializerBlock
internal ForInitializerBlock(ForStatementSyntax forNode, Block successor)
: base(successor)
{
if (forNode == null)
{
throw new ArgumentNullException(nameof(forNode));
}
ForNode = forNode;
}
示例9: ForStatement
public static string ForStatement(ForStatementSyntax statement)
{
var output = "for ";
output += SyntaxNode(statement.Declaration) + "; " + SyntaxNode(statement.Condition) + "; " + //TODO: these semicolons should be handled in their syntaxParsers
SyntaxNode(statement.Incrementors.First()).TrimEnd(); //TODO: handle multiple incrementors
output += " " + SyntaxNode(statement.Statement);
return output;
}
示例10: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
if (node.Declaration != null)
{
AddVariableExpressions(node.Declaration.Variables, _expressions);
}
node.Initializers.Do(i => AddExpressionTerms(i, _expressions));
AddExpressionTerms(node.Condition, _expressions);
node.Incrementors.Do(i => AddExpressionTerms(i, _expressions));
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:CSharpProximityExpressionsService.RelevantExpressionsCollector.cs
示例11: VisitForStatement
public override void VisitForStatement(ForStatementSyntax forStatement)
{
var initializers = string.Join(" ", forStatement.Initializers.Select(o => o.ToString()));
var condition = forStatement.Condition?.ToString();
var interator = string.Join(" ", forStatement.Incrementors.Select(o => o.ToString()));
var expression = $"for ({initializers}; {condition}; {interator})";
var token = CreateBlock(expression, SDNodeRole.ForLoop);
_tokenList.Add(token);
VisitChildren(token.Statements, forStatement.Statement);
}
示例12: VisitForStatement
public override SyntaxNode VisitForStatement(ForStatementSyntax node)
{
node = (ForStatementSyntax)base.VisitForStatement(node);
if (!node.Statement.IsKind(SyntaxKind.Block))
{
this.addedAnnotations = true;
node = node.WithStatement(SyntaxFactory.Block(node.Statement));
}
return node;
}
示例13: ForStatementTranslation
public ForStatementTranslation(ForStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
//KeyValuePair<int, string>? a = null;
//var b = ((bool?)null)?.Equals(false) ?? true ? false ? true : false :true;
//string str = "\{ ("\{( "(\{ "{}" })" )}") }";
Condition = syntax.Condition.Get<ExpressionTranslation>(this);
Declaration = syntax.Declaration.Get<VariableDeclarationTranslation>(this);
Incrementors = syntax.Incrementors.Get<ExpressionSyntax, ExpressionTranslation>(this);
Initializers = syntax.Initializers.Get<ExpressionSyntax, ExpressionTranslation>(this);
Statement = syntax.Statement.Get<StatementTranslation>(this);
}
示例14: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
var tokens = new List<SyntaxToken>();
if (node.Declaration != null)
{
tokens.AddRange(node.Declaration.Variables.Select(v => v.Identifier));
}
tracker.AddIdentifiers(tokens);
Visit(node.Statement);
tracker.RemoveIdentifiers(tokens);
}
示例15: BindForParts
private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
{
BoundStatement initializer;
// Declaration and Initializers are mutually exclusive.
if (_syntax.Declaration != null)
{
ImmutableArray<BoundLocalDeclaration> unused;
initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.RegularVariable, diagnostics, out unused);
}
else
{
initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
}
BoundExpression condition = null;
var innerLocals = ImmutableArray<LocalSymbol>.Empty;
ExpressionSyntax conditionSyntax = node.Condition;
if (conditionSyntax != null)
{
originalBinder = originalBinder.GetBinder(conditionSyntax);
condition = originalBinder.BindBooleanExpression(conditionSyntax, diagnostics);
innerLocals = originalBinder.GetDeclaredLocalsForScope(conditionSyntax);
}
BoundStatement increment = null;
SeparatedSyntaxList<ExpressionSyntax> incrementors = node.Incrementors;
if (incrementors.Count > 0)
{
var scopeDesignator = incrementors.First();
var incrementBinder = originalBinder.GetBinder(scopeDesignator);
increment = incrementBinder.WrapWithVariablesIfAny(scopeDesignator, incrementBinder.BindStatementExpressionList(incrementors, diagnostics));
}
var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);
Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
return new BoundForStatement(node,
this.Locals,
initializer,
innerLocals,
condition,
increment,
body,
this.BreakLabel,
this.ContinueLabel);
}