本文整理汇总了C#中StatementSyntax.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# StatementSyntax.Kind方法的具体用法?C# StatementSyntax.Kind怎么用?C# StatementSyntax.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StatementSyntax
的用法示例。
在下文中一共展示了StatementSyntax.Kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetExpression
private static ExpressionSyntax TryGetExpression(StatementSyntax firstStatement)
{
if (firstStatement.Kind() == SyntaxKind.ExpressionStatement)
{
return ((ExpressionStatementSyntax)firstStatement).Expression;
}
else if (firstStatement.Kind() == SyntaxKind.ReturnStatement)
{
var returnStatement = (ReturnStatementSyntax)firstStatement;
if (returnStatement.Expression != null)
{
// If there are any comments on the return keyword, move them to
// the expression.
return firstStatement.GetLeadingTrivia().Any(t => t.IsSingleOrMultiLineComment())
? returnStatement.Expression.WithLeadingTrivia(returnStatement.GetLeadingTrivia())
: returnStatement.Expression;
}
}
else if (firstStatement.Kind() == SyntaxKind.ThrowStatement)
{
var throwStatement = (ThrowStatementSyntax)firstStatement;
if (throwStatement.Expression != null)
{
return SyntaxFactory.ThrowExpression(throwStatement.ThrowKeyword, throwStatement.Expression);
}
}
return null;
}
示例2: GenerateStatement
private void GenerateStatement(StatementSyntax statement)
{
var success = false;
int mark = GetMark();
switch (statement.Kind())
{
case SyntaxKind.LocalDeclarationStatement:
success = TryGenerateLocal((LocalDeclarationStatementSyntax)statement);
break;
case SyntaxKind.Block:
success = true;
GenerateBlock((BlockSyntax)statement);
break;
case SyntaxKind.ExpressionStatement:
success = TryGenerateExpressionStatement((ExpressionStatementSyntax)statement);
break;
}
if (!success)
{
Rewind(mark);
GenerateUnknown(statement);
}
// Just for readability
LineBreak();
}
示例3: GetBinderForPossibleEmbeddedStatement
/// <summary>
/// Some statements by default do not introduce its own scope for locals.
/// For example: Expression Statement, Return Statement, etc. However,
/// when a statement like that is an embedded statement (like IfStatementSyntax.Statement),
/// then it should introduce a scope for locals declared within it.
/// Here we are detecting such statements and creating a binder that should own the scope.
/// </summary>
private Binder GetBinderForPossibleEmbeddedStatement(StatementSyntax statement, Binder enclosing, out CSharpSyntaxNode embeddedScopeDesignator)
{
switch (statement.Kind())
{
case SyntaxKind.LocalDeclarationStatement:
case SyntaxKind.LabeledStatement:
case SyntaxKind.LocalFunctionStatement:
// It is an error to have a declaration or a label in an embedded statement,
// but we still want to bind it.
case SyntaxKind.ExpressionStatement:
case SyntaxKind.LockStatement:
case SyntaxKind.IfStatement:
case SyntaxKind.YieldReturnStatement:
case SyntaxKind.ReturnStatement:
case SyntaxKind.ThrowStatement:
Debug.Assert((object)_containingMemberOrLambda == enclosing.ContainingMemberOrLambda);
embeddedScopeDesignator = statement;
return new EmbeddedStatementBinder(enclosing, statement);
case SyntaxKind.SwitchStatement:
Debug.Assert((object)_containingMemberOrLambda == enclosing.ContainingMemberOrLambda);
var switchStatement = (SwitchStatementSyntax)statement;
embeddedScopeDesignator = switchStatement.Expression;
return new ExpressionVariableBinder(switchStatement.Expression, enclosing);
default:
embeddedScopeDesignator = null;
return enclosing;
}
}
示例4: AdjustBinderForPositionWithinStatement
private static Binder AdjustBinderForPositionWithinStatement(int position, Binder binder, StatementSyntax stmt)
{
switch (stmt.Kind())
{
case SyntaxKind.SwitchStatement:
var switchStmt = (SwitchStatementSyntax)stmt;
if (LookupPosition.IsBetweenTokens(position, switchStmt.OpenParenToken, switchStmt.OpenBraceToken))
{
binder = binder.GetBinder(switchStmt.Expression);
Debug.Assert(binder != null);
}
break;
case SyntaxKind.ForEachStatement:
case SyntaxKind.ForEachComponentStatement:
var foreachStmt = (CommonForEachStatementSyntax)stmt;
if (LookupPosition.IsBetweenTokens(position, foreachStmt.OpenParenToken, foreachStmt.Statement.GetFirstToken()))
{
binder = binder.GetBinder(foreachStmt.Expression);
Debug.Assert(binder != null);
}
break;
}
return binder;
}
示例5: AdjustForLocalsInBlock
private static double AdjustForLocalsInBlock(
double distance,
StatementSyntax leftStatement,
StatementSyntax rightStatement,
double localsWeight)
{
// If the statement is a block that declares local variables,
// weight them more than the rest of the statement.
if (leftStatement.Kind() == SyntaxKind.Block && rightStatement.Kind() == SyntaxKind.Block)
{
double localsDistance;
if (TryComputeLocalsDistance((BlockSyntax)leftStatement, (BlockSyntax)rightStatement, out localsDistance))
{
return localsDistance * localsWeight + distance * (1 - localsWeight);
}
}
return distance;
}
示例6: BindPossibleEmbeddedStatement
internal BoundStatement BindPossibleEmbeddedStatement(StatementSyntax node, DiagnosticBag diagnostics)
{
switch (node.Kind())
{
case SyntaxKind.ExpressionStatement:
Binder binder = this.GetBinder(node);
Debug.Assert(binder != null);
return binder.WrapWithVariablesIfAny(node, binder.BindStatement(node, diagnostics));
default:
return BindStatement(node, diagnostics);
}
}
示例7: VisitPossibleEmbeddedStatement
private void VisitPossibleEmbeddedStatement(StatementSyntax statement, Binder enclosing)
{
if (statement != null)
{
switch (statement.Kind())
{
case SyntaxKind.LocalDeclarationStatement:
case SyntaxKind.LabeledStatement:
// It is an error to have a declaration or a label in an embedded statement,
// but we still want to bind it. We'll pretend that the statement was
// inside a block.
Debug.Assert((object)_method == enclosing.ContainingMemberOrLambda);
var blockBinder = new BlockBinder(enclosing, new SyntaxList<StatementSyntax>(statement));
AddToMap(statement, blockBinder);
Visit(statement, blockBinder);
return;
case SyntaxKind.Block:
case SyntaxKind.UsingStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.DoStatement:
case SyntaxKind.ForStatement:
case SyntaxKind.ForEachStatement:
case SyntaxKind.FixedStatement:
case SyntaxKind.LockStatement:
case SyntaxKind.SwitchStatement:
case SyntaxKind.IfStatement:
// These statements always have dedicated binders.
break;
default:
break;
}
}
Visit(statement, enclosing);
}
示例8: BindPossibleEmbeddedStatement
internal BoundStatement BindPossibleEmbeddedStatement(StatementSyntax node, DiagnosticBag diagnostics)
{
Binder binder;
switch (node.Kind())
{
case SyntaxKind.ExpressionStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.DoStatement:
case SyntaxKind.LockStatement:
case SyntaxKind.IfStatement:
case SyntaxKind.YieldReturnStatement:
case SyntaxKind.LocalDeclarationStatement:
case SyntaxKind.DeconstructionDeclarationStatement:
case SyntaxKind.ReturnStatement:
case SyntaxKind.ThrowStatement:
binder = this.GetBinder(node);
Debug.Assert(binder != null);
return binder.WrapWithVariablesIfAny(node, binder.BindStatement(node, diagnostics));
case SyntaxKind.LabeledStatement:
case SyntaxKind.LocalFunctionStatement:
binder = this.GetBinder(node);
Debug.Assert(binder != null);
return binder.WrapWithVariablesAndLocalFunctionsIfAny(node, binder.BindStatement(node, diagnostics));
case SyntaxKind.SwitchStatement:
var switchStatement = (SwitchStatementSyntax)node;
binder = this.GetBinder(switchStatement.Expression);
Debug.Assert(binder != null);
return binder.WrapWithVariablesIfAny(switchStatement.Expression, binder.BindStatement(node, diagnostics));
default:
return BindStatement(node, diagnostics);
}
}
示例9: VisitPossibleEmbeddedStatement
private void VisitPossibleEmbeddedStatement(StatementSyntax statement, Binder enclosing)
{
if (statement != null)
{
switch (statement.Kind())
{
case SyntaxKind.LocalDeclarationStatement:
case SyntaxKind.LabeledStatement:
case SyntaxKind.LocalFunctionStatement:
// It is an error to have a declaration or a label in an embedded statement,
// but we still want to bind it. We'll pretend that the statement was
// inside a block.
Debug.Assert((object)_containingMemberOrLambda == enclosing.ContainingMemberOrLambda);
var blockBinder = new BlockBinder(enclosing, new SyntaxList<StatementSyntax>(statement));
AddToMap(statement, blockBinder);
Visit(statement, blockBinder);
return;
default:
break;
}
Visit(statement, enclosing);
}
}
示例10: GetFirstIncludedToken
private static SyntaxToken GetFirstIncludedToken(StatementSyntax statement)
{
Debug.Assert(statement != null);
switch (statement.Kind())
{
case SyntaxKind.Block:
return ((BlockSyntax)statement).OpenBraceToken;
case SyntaxKind.BreakStatement:
return ((BreakStatementSyntax)statement).BreakKeyword;
case SyntaxKind.CheckedStatement:
case SyntaxKind.UncheckedStatement:
return ((CheckedStatementSyntax)statement).Keyword;
case SyntaxKind.ContinueStatement:
return ((ContinueStatementSyntax)statement).ContinueKeyword;
case SyntaxKind.ExpressionStatement:
case SyntaxKind.LocalDeclarationStatement:
case SyntaxKind.DeconstructionDeclarationStatement:
return statement.GetFirstToken();
case SyntaxKind.DoStatement:
return ((DoStatementSyntax)statement).DoKeyword;
case SyntaxKind.EmptyStatement:
return default(SyntaxToken); //The caller will have to check for this.
case SyntaxKind.FixedStatement:
return ((FixedStatementSyntax)statement).FixedKeyword;
case SyntaxKind.ForEachStatement:
case SyntaxKind.ForEachComponentStatement:
return ((CommonForEachStatementSyntax)statement).OpenParenToken.GetNextToken();
case SyntaxKind.ForStatement:
return ((ForStatementSyntax)statement).OpenParenToken.GetNextToken();
case SyntaxKind.GotoDefaultStatement:
case SyntaxKind.GotoCaseStatement:
case SyntaxKind.GotoStatement:
return ((GotoStatementSyntax)statement).GotoKeyword;
case SyntaxKind.IfStatement:
return ((IfStatementSyntax)statement).IfKeyword;
case SyntaxKind.LabeledStatement:
return ((LabeledStatementSyntax)statement).Identifier;
case SyntaxKind.LockStatement:
return ((LockStatementSyntax)statement).LockKeyword;
case SyntaxKind.ReturnStatement:
return ((ReturnStatementSyntax)statement).ReturnKeyword;
case SyntaxKind.SwitchStatement:
return ((SwitchStatementSyntax)statement).Expression.GetFirstToken();
case SyntaxKind.ThrowStatement:
return ((ThrowStatementSyntax)statement).ThrowKeyword;
case SyntaxKind.TryStatement:
return ((TryStatementSyntax)statement).TryKeyword;
case SyntaxKind.UnsafeStatement:
return ((UnsafeStatementSyntax)statement).UnsafeKeyword;
case SyntaxKind.UsingStatement:
return ((UsingStatementSyntax)statement).UsingKeyword;
case SyntaxKind.WhileStatement:
return ((WhileStatementSyntax)statement).WhileKeyword;
case SyntaxKind.YieldReturnStatement:
case SyntaxKind.YieldBreakStatement:
return ((YieldStatementSyntax)statement).YieldKeyword;
case SyntaxKind.LocalFunctionStatement:
return statement.GetFirstToken();
default:
throw ExceptionUtilities.UnexpectedValue(statement.Kind());
}
}
示例11: GetFirstExcludedToken
private static SyntaxToken GetFirstExcludedToken(StatementSyntax statement)
{
Debug.Assert(statement != null);
switch (statement.Kind())
{
case SyntaxKind.Block:
return ((BlockSyntax)statement).CloseBraceToken;
case SyntaxKind.BreakStatement:
return ((BreakStatementSyntax)statement).SemicolonToken;
case SyntaxKind.CheckedStatement:
case SyntaxKind.UncheckedStatement:
return ((CheckedStatementSyntax)statement).Block.CloseBraceToken;
case SyntaxKind.ContinueStatement:
return ((ContinueStatementSyntax)statement).SemicolonToken;
case SyntaxKind.LocalDeclarationStatement:
return ((LocalDeclarationStatementSyntax)statement).SemicolonToken;
case SyntaxKind.DeconstructionDeclarationStatement:
return ((DeconstructionDeclarationStatementSyntax)statement).SemicolonToken;
case SyntaxKind.DoStatement:
return ((DoStatementSyntax)statement).SemicolonToken;
case SyntaxKind.EmptyStatement:
return ((EmptyStatementSyntax)statement).SemicolonToken;
case SyntaxKind.ExpressionStatement:
return ((ExpressionStatementSyntax)statement).SemicolonToken;
case SyntaxKind.FixedStatement:
return GetFirstExcludedToken(((FixedStatementSyntax)statement).Statement);
case SyntaxKind.ForEachStatement:
case SyntaxKind.ForEachComponentStatement:
return GetFirstExcludedToken(((CommonForEachStatementSyntax)statement).Statement);
case SyntaxKind.ForStatement:
return GetFirstExcludedToken(((ForStatementSyntax)statement).Statement);
case SyntaxKind.GotoDefaultStatement:
case SyntaxKind.GotoCaseStatement:
case SyntaxKind.GotoStatement:
return ((GotoStatementSyntax)statement).SemicolonToken;
case SyntaxKind.IfStatement:
IfStatementSyntax ifStmt = (IfStatementSyntax)statement;
ElseClauseSyntax elseOpt = ifStmt.Else;
return GetFirstExcludedToken(elseOpt == null ? ifStmt.Statement : elseOpt.Statement);
case SyntaxKind.LabeledStatement:
return GetFirstExcludedToken(((LabeledStatementSyntax)statement).Statement);
case SyntaxKind.LockStatement:
return GetFirstExcludedToken(((LockStatementSyntax)statement).Statement);
case SyntaxKind.ReturnStatement:
return ((ReturnStatementSyntax)statement).SemicolonToken;
case SyntaxKind.SwitchStatement:
return ((SwitchStatementSyntax)statement).CloseBraceToken;
case SyntaxKind.ThrowStatement:
return ((ThrowStatementSyntax)statement).SemicolonToken;
case SyntaxKind.TryStatement:
TryStatementSyntax tryStmt = (TryStatementSyntax)statement;
FinallyClauseSyntax finallyClause = tryStmt.Finally;
if (finallyClause != null)
{
return finallyClause.Block.CloseBraceToken;
}
CatchClauseSyntax lastCatch = tryStmt.Catches.LastOrDefault();
if (lastCatch != null)
{
return lastCatch.Block.CloseBraceToken;
}
return tryStmt.Block.CloseBraceToken;
case SyntaxKind.UnsafeStatement:
return ((UnsafeStatementSyntax)statement).Block.CloseBraceToken;
case SyntaxKind.UsingStatement:
return GetFirstExcludedToken(((UsingStatementSyntax)statement).Statement);
case SyntaxKind.WhileStatement:
return GetFirstExcludedToken(((WhileStatementSyntax)statement).Statement);
case SyntaxKind.YieldReturnStatement:
case SyntaxKind.YieldBreakStatement:
return ((YieldStatementSyntax)statement).SemicolonToken;
case SyntaxKind.LocalFunctionStatement:
LocalFunctionStatementSyntax localFunctionStmt = (LocalFunctionStatementSyntax)statement;
if (localFunctionStmt.Body != null)
return GetFirstExcludedToken(localFunctionStmt.Body);
if (localFunctionStmt.SemicolonToken != null)
return localFunctionStmt.SemicolonToken;
return localFunctionStmt.ParameterList.GetLastToken();
default:
throw ExceptionUtilities.UnexpectedValue(statement.Kind());
}
}
示例12: IsInStatementScope
/// <remarks>
/// Used to determine whether it would be appropriate to use the binder for the statement (if any).
/// Not used to determine whether the position is syntactically within the statement.
/// </remarks>
internal static bool IsInStatementScope(int position, StatementSyntax statement)
{
Debug.Assert(statement != null);
if (statement.Kind() == SyntaxKind.EmptyStatement)
{
return false;
}
// CONSIDER: the check for default(SyntaxToken) could go in IsBetweenTokens,
// but this is where it has special meaning.
SyntaxToken firstIncludedToken = GetFirstIncludedToken(statement);
return firstIncludedToken != default(SyntaxToken) &&
IsBetweenTokens(position, firstIncludedToken, GetFirstExcludedToken(statement));
}
示例13: GetFirstIncludedToken
private static SyntaxToken GetFirstIncludedToken(StatementSyntax statement, bool inRecursiveCall = false)
{
Debug.Assert(statement != null);
switch (statement.Kind())
{
case SyntaxKind.Block:
return ((BlockSyntax)statement).OpenBraceToken;
case SyntaxKind.BreakStatement:
return ((BreakStatementSyntax)statement).BreakKeyword;
case SyntaxKind.CheckedStatement:
case SyntaxKind.UncheckedStatement:
return ((CheckedStatementSyntax)statement).Keyword;
case SyntaxKind.ContinueStatement:
return ((ContinueStatementSyntax)statement).ContinueKeyword;
case SyntaxKind.ExpressionStatement:
case SyntaxKind.LocalDeclarationStatement:
return statement.GetFirstToken();
case SyntaxKind.DoStatement:
return ((DoStatementSyntax)statement).DoKeyword;
case SyntaxKind.EmptyStatement:
return default(SyntaxToken); //The caller will have to check for this.
case SyntaxKind.FixedStatement:
return ((FixedStatementSyntax)statement).FixedKeyword;
case SyntaxKind.ForEachStatement:
// NB: iteration variable is only in scope in body.
ForEachStatementSyntax forEachSyntax = (ForEachStatementSyntax)statement;
if (inRecursiveCall)
{
return forEachSyntax.ForEachKeyword;
}
return GetFirstIncludedToken(forEachSyntax.Statement, inRecursiveCall: true);
case SyntaxKind.ForStatement:
// Section 8.8.3 of the spec says that the scope of the loop variable starts at
// its declaration. If it's not there, then the scope we are interested in is
// the loop body.
ForStatementSyntax forSyntax = (ForStatementSyntax)statement;
if (inRecursiveCall)
{
return forSyntax.ForKeyword;
}
VariableDeclarationSyntax declOpt = forSyntax.Declaration;
return declOpt == null ? GetFirstIncludedToken(forSyntax.Statement, inRecursiveCall: true) : declOpt.GetFirstToken();
case SyntaxKind.GotoDefaultStatement:
case SyntaxKind.GotoCaseStatement:
case SyntaxKind.GotoStatement:
return ((GotoStatementSyntax)statement).GotoKeyword;
case SyntaxKind.IfStatement:
return ((IfStatementSyntax)statement).IfKeyword;
case SyntaxKind.LabeledStatement:
return ((LabeledStatementSyntax)statement).Identifier;
case SyntaxKind.LockStatement:
return ((LockStatementSyntax)statement).LockKeyword;
case SyntaxKind.ReturnStatement:
return ((ReturnStatementSyntax)statement).ReturnKeyword;
case SyntaxKind.SwitchStatement:
return ((SwitchStatementSyntax)statement).OpenBraceToken;
case SyntaxKind.ThrowStatement:
return ((ThrowStatementSyntax)statement).ThrowKeyword;
case SyntaxKind.TryStatement:
return ((TryStatementSyntax)statement).TryKeyword;
case SyntaxKind.UnsafeStatement:
return ((UnsafeStatementSyntax)statement).UnsafeKeyword;
case SyntaxKind.UsingStatement:
return ((UsingStatementSyntax)statement).UsingKeyword;
case SyntaxKind.WhileStatement:
return ((WhileStatementSyntax)statement).WhileKeyword;
case SyntaxKind.YieldReturnStatement:
case SyntaxKind.YieldBreakStatement:
return ((YieldStatementSyntax)statement).YieldKeyword;
case SyntaxKind.LocalFunctionStatement:
return statement.GetFirstToken();
default:
throw ExceptionUtilities.UnexpectedValue(statement.Kind());
}
}
示例14: AdjustBinderForPositionWithinStatement
private static Binder AdjustBinderForPositionWithinStatement(int position, Binder binder, StatementSyntax stmt)
{
switch (stmt.Kind())
{
case SyntaxKind.SwitchStatement:
var switchStmt = (SwitchStatementSyntax)stmt;
if (LookupPosition.IsBetweenTokens(position, switchStmt.OpenParenToken, switchStmt.OpenBraceToken))
{
binder = binder.GetBinder(switchStmt.Expression);
Debug.Assert(binder != null);
}
break;
case SyntaxKind.ForStatement:
var forStmt = (ForStatementSyntax)stmt;
if (LookupPosition.IsBetweenTokens(position, forStmt.SecondSemicolonToken, forStmt.CloseParenToken) &&
forStmt.Incrementors.Count > 0)
{
binder = binder.GetBinder(forStmt.Incrementors.First());
Debug.Assert(binder != null);
}
else if (LookupPosition.IsBetweenTokens(position, forStmt.FirstSemicolonToken, LookupPosition.GetFirstExcludedToken(forStmt)) &&
forStmt.Condition != null)
{
binder = binder.GetBinder(forStmt.Condition);
Debug.Assert(binder != null);
}
break;
case SyntaxKind.ForEachStatement:
case SyntaxKind.ForEachVariableStatement:
var foreachStmt = (CommonForEachStatementSyntax)stmt;
var start = stmt.Kind() == SyntaxKind.ForEachVariableStatement ? foreachStmt.InKeyword : foreachStmt.OpenParenToken;
if (LookupPosition.IsBetweenTokens(position, start, foreachStmt.Statement.GetFirstToken()))
{
binder = binder.GetBinder(foreachStmt.Expression);
Debug.Assert(binder != null);
}
break;
}
return binder;
}
示例15: BindPossibleEmbeddedStatement
internal BoundStatement BindPossibleEmbeddedStatement(StatementSyntax node, DiagnosticBag diagnostics)
{
switch (node.Kind())
{
case SyntaxKind.Block:
case SyntaxKind.UsingStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.DoStatement:
case SyntaxKind.ForStatement:
case SyntaxKind.ForEachStatement:
case SyntaxKind.FixedStatement:
case SyntaxKind.LockStatement:
case SyntaxKind.SwitchStatement:
case SyntaxKind.IfStatement:
// These statements always have dedicated binders and binding code for them handles lookup of the binders.
break;
default:
BoundStatement result = BindStatement(node, diagnostics);
return result;
}
return BindStatement(node, diagnostics);
}