本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Binder.BindStatement方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.BindStatement方法的具体用法?C# Binder.BindStatement怎么用?C# Binder.BindStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Binder
的用法示例。
在下文中一共展示了Binder.BindStatement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindGlobalStatement
private static BoundInitializer BindGlobalStatement(Binder binder, StatementSyntax statementNode, DiagnosticBag diagnostics, bool isLast)
{
BoundStatement boundStatement = binder.BindStatement(statementNode, diagnostics);
// the result of the last global expression is assigned to the result storage for submission result:
if (binder.Compilation.IsSubmission && isLast && boundStatement.Kind == BoundKind.ExpressionStatement && !boundStatement.HasAnyErrors)
{
var submissionReturnType = binder.Compilation.GetSubmissionReturnType();
// insert an implicit conversion for the submission return type (if needed):
var expression = ((BoundExpressionStatement)boundStatement).Expression;
if ((object)expression.Type == null || expression.Type.SpecialType != SpecialType.System_Void)
{
expression = binder.GenerateConversionForAssignment(submissionReturnType, expression, diagnostics);
boundStatement = new BoundExpressionStatement(boundStatement.Syntax, expression, expression.HasErrors);
}
}
return new BoundGlobalStatementInitializer(statementNode, boundStatement);
}
示例2: BindBlock
internal static BoundBlock BindBlock(BlockSyntax node, DiagnosticBag diagnostics, Binder blockBinder)
{
Debug.Assert(blockBinder != null);
var syntaxStatements = node.Statements;
int nStatements = syntaxStatements.Count;
ArrayBuilder<BoundStatement> boundStatements = ArrayBuilder<BoundStatement>.GetInstance(nStatements);
for (int i = 0; i < nStatements; i++)
{
var boundStatement = blockBinder.BindStatement(syntaxStatements[i], diagnostics);
boundStatements.Add(boundStatement);
}
if (blockBinder.IsDirectlyInIterator)
{
var method = blockBinder.ContainingMemberOrLambda as SourceMethodSymbol;
if ((object)method != null)
{
method.IteratorElementType = blockBinder.GetIteratorElementType(null, diagnostics);
}
else
{
Debug.Assert(!diagnostics.IsEmptyWithoutResolution);
}
}
return new BoundBlock(node, blockBinder.GetDeclaredLocalsForScope(node), boundStatements.ToImmutableAndFree());
}
示例3: BindGlobalStatement
private static BoundInitializer BindGlobalStatement(
Binder binder,
SynthesizedInteractiveInitializerMethod scriptInitializer,
StatementSyntax statementNode,
DiagnosticBag diagnostics,
bool isLast)
{
var statement = binder.BindStatement(statementNode, diagnostics);
if (isLast && !statement.HasAnyErrors)
{
// the result of the last global expression is assigned to the result storage for submission result:
if (binder.Compilation.IsSubmission)
{
// insert an implicit conversion for the submission return type (if needed):
var expression = InitializerRewriter.GetTrailingScriptExpression(statement);
if (expression != null &&
((object)expression.Type == null || expression.Type.SpecialType != SpecialType.System_Void))
{
var submissionResultType = scriptInitializer.ResultType;
expression = binder.GenerateConversionForAssignment(submissionResultType, expression, diagnostics);
statement = new BoundExpressionStatement(statement.Syntax, expression, expression.HasErrors);
}
}
// don't allow trailing expressions after labels (as in regular C#, labels must be followed by a statement):
if (statement.Kind == BoundKind.LabeledStatement)
{
var labeledStatementBody = ((BoundLabeledStatement)statement).Body;
while (labeledStatementBody.Kind == BoundKind.LabeledStatement)
{
labeledStatementBody = ((BoundLabeledStatement)labeledStatementBody).Body;
}
if (InitializerRewriter.GetTrailingScriptExpression(labeledStatementBody) != null)
{
Error(diagnostics, ErrorCode.ERR_SemicolonExpected, ((ExpressionStatementSyntax)labeledStatementBody.Syntax).SemicolonToken);
}
}
}
return new BoundGlobalStatementInitializer(statementNode, statement);
}
示例4: Bind
// This is used by other binding APIs to invoke the right binder API
virtual internal BoundNode Bind(Binder binder, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
var expression = node as ExpressionSyntax;
if (expression != null)
{
var parent = expression.Parent;
return (parent != null && parent.Kind() == SyntaxKind.GotoStatement)
? binder.BindLabel(expression, diagnostics)
: binder.BindNamespaceOrTypeOrExpression(expression, diagnostics);
}
var statement = node as StatementSyntax;
if (statement != null)
{
return binder.BindStatement(statement, diagnostics);
}
var globalStatement = node as GlobalStatementSyntax;
if (globalStatement != null)
{
BoundStatement bound = binder.BindStatement(globalStatement.Statement, diagnostics);
return new BoundGlobalStatementInitializer(node, bound);
}
return null;
}
示例5: BindGlobalStatement
private static BoundInitializer BindGlobalStatement(
Binder binder,
SynthesizedInteractiveInitializerMethod scriptInitializer,
StatementSyntax statementNode,
DiagnosticBag diagnostics,
bool isLast)
{
BoundStatement boundStatement = binder.BindStatement(statementNode, diagnostics);
// the result of the last global expression is assigned to the result storage for submission result:
if (binder.Compilation.IsSubmission && isLast && !boundStatement.HasAnyErrors)
{
// insert an implicit conversion for the submission return type (if needed):
var expression = InitializerRewriter.GetTrailingScriptExpression(boundStatement);
if (expression != null &&
((object)expression.Type == null || expression.Type.SpecialType != SpecialType.System_Void))
{
var submissionResultType = scriptInitializer.ResultType;
expression = binder.GenerateConversionForAssignment(submissionResultType, expression, diagnostics);
boundStatement = new BoundExpressionStatement(boundStatement.Syntax, expression, expression.HasErrors);
}
}
return new BoundGlobalStatementInitializer(statementNode, boundStatement);
}
示例6: BindSwitchSection
private BoundSwitchSection BindSwitchSection(SwitchSectionSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
{
// Bind switch section labels
var boundLabelsBuilder = ArrayBuilder<BoundSwitchLabel>.GetInstance();
foreach (var labelSyntax in node.Labels)
{
BoundSwitchLabel boundLabel = BindSwitchSectionLabel(labelSyntax, diagnostics);
boundLabelsBuilder.Add(boundLabel);
}
// Bind switch section statements
var boundStatementsBuilder = ArrayBuilder<BoundStatement>.GetInstance();
foreach (var statement in node.Statements)
{
boundStatementsBuilder.Add(originalBinder.BindStatement(statement, diagnostics));
}
return new BoundSwitchSection(node, boundLabelsBuilder.ToImmutableAndFree(), boundStatementsBuilder.ToImmutableAndFree());
}