本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundReturnStatement类的典型用法代码示例。如果您正苦于以下问题:C# BoundReturnStatement类的具体用法?C# BoundReturnStatement怎么用?C# BoundReturnStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundReturnStatement类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了BoundReturnStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitReturnStatement
public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
BoundExpression expression = (BoundExpression)this.Visit(node.ExpressionOpt);
if (expression == null || expression.Kind != BoundKind.SpillSequence)
{
return node.Update(expression);
}
var spillSeq = (BoundSpillSequence)expression;
return RewriteSpillSequenceAsBlock(spillSeq, node.Update(spillSeq.Value));
}
示例2: VisitReturnStatement
public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
BoundStatement rewritten = (BoundStatement)base.VisitReturnStatement(node);
// NOTE: we will apply sequence points to synthesized return statements if they are contained in lambdas and have expressions.
// We do this to ensure that expression lambdas have sequence points, as in Dev10.
if (this.generateDebugInfo &&
(!rewritten.WasCompilerGenerated || (node.ExpressionOpt != null && this.factory.CurrentMethod is LambdaSymbol)))
{
// We're not calling AddSequencePoint since it ignores compiler-generated nodes.
return new BoundSequencePoint(rewritten.Syntax, rewritten);
}
return rewritten;
}
示例3: VisitReturnStatement
public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
BoundStatement rewritten = (BoundStatement)base.VisitReturnStatement(node);
// NOTE: we will apply sequence points to synthesized return
// statements if they are contained in lambdas and have expressions
// or if they are expression-bodied properties.
// We do this to ensure that expression lambdas and expression-bodied
// properties have sequence points.
if (this.GenerateDebugInfo &&
(!rewritten.WasCompilerGenerated ||
(node.ExpressionOpt != null && IsLambdaOrExpressionBodiedMember)))
{
// We're not calling AddSequencePoint since it ignores compiler-generated nodes.
return new BoundSequencePoint(rewritten.Syntax, rewritten);
}
return rewritten;
}
示例4: VisitReturnStatement
public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
BoundStatement rewritten = (BoundStatement)base.VisitReturnStatement(node);
// NOTE: we will apply sequence points to synthesized return
// statements if they are contained in lambdas and have expressions
// or if they are expression-bodied properties.
// We do this to ensure that expression lambdas and expression-bodied
// properties have sequence points.
// We also add sequence points for the implicit "return" statement at the end of the method body
// (added by FlowAnalysisPass.AppendImplicitReturn). Implicitly added return for async method
// does not need sequence points added here since it would be done later (presumably during Async rewrite).
if (this.Instrument &&
(!node.WasCompilerGenerated ||
(node.ExpressionOpt != null ?
IsLambdaOrExpressionBodiedMember :
(node.Syntax.Kind() == SyntaxKind.Block && _factory.CurrentMethod?.IsAsync == false))))
{
rewritten = _instrumenter.InstrumentReturnStatement(node, rewritten);
}
return rewritten;
}
示例5: UnpendBranches
private BoundStatement UnpendBranches(
AwaitFinallyFrame frame,
SynthesizedLocal pendingBranchVar,
SynthesizedLocal pendingException)
{
var parent = frame.ParentOpt;
// handle proxy labels if have any
var proxiedLabels = frame.proxiedLabels;
var proxyLabels = frame.proxyLabels;
// skip 0 - it means we took no explicit branches
int i = 1;
var cases = ArrayBuilder<BoundSwitchSection>.GetInstance();
if (proxiedLabels != null)
{
for (int cnt = proxiedLabels.Count; i <= cnt; i++)
{
var target = proxiedLabels[i - 1];
var parentProxy = parent.ProxyLabelIfNeeded(target);
var caseStatement = _F.SwitchSection(i, _F.Goto(parentProxy));
cases.Add(caseStatement);
}
}
if (frame.returnProxyLabel != null)
{
BoundLocal pendingValue = null;
if (frame.returnValue != null)
{
pendingValue = _F.Local(frame.returnValue);
}
SynthesizedLocal returnValue;
BoundStatement unpendReturn;
var returnLabel = parent.ProxyReturnIfNeeded(_F.CurrentMethod, pendingValue, out returnValue);
if (returnLabel == null)
{
unpendReturn = new BoundReturnStatement(_F.Syntax, pendingValue);
}
else
{
if (pendingValue == null)
{
unpendReturn = _F.Goto(returnLabel);
}
else
{
unpendReturn = _F.Block(
_F.Assignment(
_F.Local(returnValue),
pendingValue),
_F.Goto(returnLabel));
}
}
var caseStatement = _F.SwitchSection(i, unpendReturn);
cases.Add(caseStatement);
}
return _F.Switch(_F.Local(pendingBranchVar), cases.ToImmutableAndFree());
}
示例6: CreateBlockFromExpression
/// <summary>
/// Wrap a given expression e into a block as either { e; } or { return e; }
/// Shared between lambda and expression-bodied method binding.
/// </summary>
internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableArray<LocalSymbol> locals, RefKind refKind, BoundExpression expression, ExpressionSyntax expressionSyntax, DiagnosticBag diagnostics)
{
RefKind returnRefKind;
var returnType = GetCurrentReturnType(out returnRefKind);
var syntax = expressionSyntax ?? expression.Syntax;
BoundStatement statement;
if (IsInAsyncMethod() && refKind != RefKind.None)
{
// This can happen if we are binding an async anonymous method to a delegate type.
Error(diagnostics, ErrorCode.ERR_MustNotHaveRefReturn, syntax);
statement = new BoundReturnStatement(syntax, refKind, expression) { WasCompilerGenerated = true };
}
else if ((object)returnType != null)
{
if ((refKind != RefKind.None) != (returnRefKind != RefKind.None))
{
var errorCode = refKind != RefKind.None
? ErrorCode.ERR_MustNotHaveRefReturn
: ErrorCode.ERR_MustHaveRefReturn;
Error(diagnostics, errorCode, syntax);
statement = new BoundReturnStatement(syntax, RefKind.None, expression) { WasCompilerGenerated = true };
}
else if (returnType.SpecialType == SpecialType.System_Void || IsTaskReturningAsyncMethod())
{
// If the return type is void then the expression is required to be a legal
// statement expression.
Debug.Assert(expressionSyntax != null || !IsValidStatementExpression(expression.Syntax, expression));
bool errors = false;
if (expressionSyntax == null || !IsValidStatementExpression(expressionSyntax, expression))
{
Error(diagnostics, ErrorCode.ERR_IllegalStatement, syntax);
errors = true;
}
// Don't mark compiler generated so that the rewriter generates sequence points
var expressionStatement = new BoundExpressionStatement(syntax, expression, errors);
CheckForUnobservedAwaitable(expression, diagnostics);
statement = expressionStatement;
}
else
{
expression = CreateReturnConversion(syntax, diagnostics, expression, refKind, returnType);
statement = new BoundReturnStatement(syntax, returnRefKind, expression) { WasCompilerGenerated = true };
}
}
else if (expression.Type?.SpecialType == SpecialType.System_Void)
{
statement = new BoundExpressionStatement(syntax, expression) { WasCompilerGenerated = true };
}
else
{
statement = new BoundReturnStatement(syntax, refKind, expression) { WasCompilerGenerated = true };
}
// Need to attach the tree for when we generate sequence points.
return new BoundBlock(node, locals, ImmutableArray<LocalFunctionSymbol>.Empty, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind() != SyntaxKind.ArrowExpressionClause };
}
示例7: InstrumentReturnStatement
public override BoundStatement InstrumentReturnStatement(BoundReturnStatement original, BoundStatement rewritten)
{
return Previous.InstrumentReturnStatement(original, rewritten);
}
示例8: InstrumentReturnStatement
public override BoundStatement InstrumentReturnStatement(BoundReturnStatement original, BoundStatement rewritten)
{
rewritten = base.InstrumentReturnStatement(original, rewritten);
// A synthesized return statement that does not return a value never requires instrumentation.
// A property set defined without a block has such a synthesized return statement.
// A synthesized return statement that does return a value does require instrumentation.
// A method, property get, or lambda defined without a block has such a synthesized return statement.
if (ReturnsValueWithinExpressionBodiedConstruct(original))
{
// The return statement for value-returning methods defined without a block is compiler generated, but requires instrumentation.
return CollectDynamicAnalysis(original, rewritten);
}
return AddDynamicAnalysis(original, rewritten);
}
示例9: CreateBlockFromExpression
/// <summary>
/// Wrap a given expression e into a block as either { e; } or { return e; }
/// Shared between lambda and expression-bodied method binding.
/// </summary>
internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableArray<LocalSymbol> locals, ExpressionSyntax expressionSyntax, BoundExpression expression, DiagnosticBag diagnostics)
{
var returnType = GetCurrentReturnType();
var syntax = expressionSyntax ?? expression.Syntax;
BoundStatement statement;
if ((object)returnType != null)
{
if (returnType.SpecialType == SpecialType.System_Void || IsTaskReturningAsyncMethod())
{
// If the return type is void then the expression is required to be a legal
// statement expression.
Debug.Assert(expressionSyntax != null || !IsValidStatementExpression(expression.Syntax, expression));
bool errors = false;
if (expressionSyntax == null || !IsValidStatementExpression(expressionSyntax, expression))
{
Error(diagnostics, ErrorCode.ERR_IllegalStatement, syntax);
errors = true;
}
// Don't mark compiler generated so that the rewriter generates sequence points
var expressionStatement = new BoundExpressionStatement(syntax, expression, errors);
CheckForUnobservedAwaitable(expressionStatement, diagnostics);
statement = expressionStatement;
}
else
{
expression = CreateReturnConversion(syntax, diagnostics, expression, returnType);
statement = new BoundReturnStatement(syntax, expression) { WasCompilerGenerated = true };
}
}
else if (expression.Type?.SpecialType == SpecialType.System_Void)
{
statement = new BoundExpressionStatement(syntax, expression) { WasCompilerGenerated = true };
}
else
{
statement = new BoundReturnStatement(syntax, expression) { WasCompilerGenerated = true };
}
// Need to attach the tree for when we generate sequence points.
return new BoundBlock(node, locals, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind() != SyntaxKind.ArrowExpressionClause };
}
示例10: VisitReturnStatement
public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
var expression = node.ExpressionOpt;
if (expression != null)
{
var returnType = expression.Type;
// This is potentially inefficient if there are a large number of returns each with
// a different type. This seems unlikely.
if (!_types.Contains(returnType))
{
_types.Add(returnType);
}
}
else
{
_hasReturnWithoutArgument = true;
}
return null;
}
示例11: InstrumentReturnStatement
public virtual BoundStatement InstrumentReturnStatement(BoundReturnStatement original, BoundStatement rewritten)
{
return rewritten;
}
示例12: InstrumentReturnStatement
public override BoundStatement InstrumentReturnStatement(BoundReturnStatement original, BoundStatement rewritten)
{
rewritten = base.InstrumentReturnStatement(original, rewritten);
// A synthesized return statement that does not return a value never requires instrumentation.
// A property set method defined without a block has such a synthesized return statement.
if (!_methodHasExplicitBlock && ((BoundReturnStatement)original).ExpressionOpt != null)
{
// The return statement for value-returning methods defined without a block is compiler generated, but requires instrumentation.
return CollectDynamicAnalysis(original, rewritten);
}
return AddDynamicAnalysis(original, rewritten);
}
示例13: WrapExpressionLambdaBody
internal BoundBlock WrapExpressionLambdaBody(BoundExpression expression, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
var returnType = this.GetCurrentReturnType();
BoundStatement statement;
if ((object)returnType != null)
{
if (returnType.SpecialType == SpecialType.System_Void || IsTaskReturningAsyncMethod())
{
// If the return type is void then the expression is required to be a legal
// statement expression.
bool errors = false;
if (!IsValidStatementExpression(node, expression))
{
Error(diagnostics, ErrorCode.ERR_IllegalStatement, node);
errors = true;
}
var expressionStatement = new BoundExpressionStatement(expression.Syntax, expression, errors);
CheckForUnobservedAwaitable(expressionStatement, diagnostics);
statement = expressionStatement;
}
else
{
expression = CreateReturnConversion(node, diagnostics, expression, returnType);
statement = new BoundReturnStatement(expression.Syntax, expression) { WasCompilerGenerated = true };
}
}
else if ((object)expression.Type != null && expression.Type.SpecialType == SpecialType.System_Void)
{
statement = new BoundExpressionStatement(expression.Syntax, expression) { WasCompilerGenerated = true };
}
else
{
statement = new BoundReturnStatement(expression.Syntax, expression) { WasCompilerGenerated = true };
}
// Need to attach the tree for when we generate sequence points.
var block = new BoundBlock(node, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create<BoundStatement>(statement)) { WasCompilerGenerated = true };
return block;
}
示例14: ReturnsValueWithinExpressionBodiedConstruct
private static bool ReturnsValueWithinExpressionBodiedConstruct(BoundReturnStatement returnStatement)
{
if (returnStatement.WasCompilerGenerated &&
returnStatement.ExpressionOpt != null &&
returnStatement.ExpressionOpt.Syntax != null)
{
SyntaxKind parentKind = returnStatement.ExpressionOpt.Syntax.Parent.Kind();
switch (parentKind)
{
case SyntaxKind.ParenthesizedLambdaExpression:
case SyntaxKind.SimpleLambdaExpression:
case SyntaxKind.ArrowExpressionClause:
return true;
}
}
return false;
}
示例15: VisitReturnStatement
public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
SynthesizedLocal returnValue;
var returnLabel = _currentAwaitFinallyFrame.ProxyReturnIfNeeded(
_F.CurrentMethod,
node.ExpressionOpt,
out returnValue);
if (returnLabel == null)
{
return base.VisitReturnStatement(node);
}
var returnExpr = (BoundExpression)(this.Visit(node.ExpressionOpt));
if (returnExpr != null)
{
return _F.Block(
_F.Assignment(
_F.Local(returnValue),
returnExpr),
_F.Goto(
returnLabel));
}
else
{
return _F.Goto(returnLabel);
}
}