本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundLambda类的典型用法代码示例。如果您正苦于以下问题:C# BoundLambda类的具体用法?C# BoundLambda怎么用?C# BoundLambda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundLambda类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了BoundLambda类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SynthesizedLambdaMethod
internal SynthesizedLambdaMethod(NamedTypeSymbol containingType, MethodSymbol topLevelMethod, BoundLambda node, bool isStatic, TypeCompilationState compilationState)
: base(containingType,
node.Symbol,
null,
node.SyntaxTree.GetReference(node.Body.Syntax),
node.Syntax.GetLocation(),
GeneratedNames.MakeLambdaMethodName(topLevelMethod.Name, compilationState.GenerateTempNumber()),
(containingType is LambdaFrame ? DeclarationModifiers.Internal : DeclarationModifiers.Private)
| (isStatic ? DeclarationModifiers.Static : 0)
| (node.Symbol.IsAsync ? DeclarationModifiers.Async : 0))
{
TypeMap typeMap;
ImmutableArray<TypeParameterSymbol> typeParameters;
LambdaFrame lambdaFrame;
if (!topLevelMethod.IsGenericMethod)
{
typeMap = TypeMap.Empty;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else if ((object)(lambdaFrame = this.ContainingType as LambdaFrame) != null)
{
typeMap = lambdaFrame.TypeMap;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
typeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out typeParameters);
}
AssignTypeMapAndTypeParameters(typeMap, typeParameters);
}
示例2: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
if (IsInside && !node.WasCompilerGenerated)
{
foreach (var parameter in node.Symbol.Parameters)
{
_variablesDeclared.Add(parameter);
}
}
return base.VisitLambda(node);
}
示例3: VisitLambda
// Control flow analysis does not normally scan the body of a lambda, but region analysis does.
public override BoundNode VisitLambda(BoundLambda node)
{
var oldPending = SavePending(); // We do not support branches *into* a lambda.
LocalState finalState = this.State;
this.State = ReachableState();
var oldPending2 = SavePending();
VisitAlways(node.Body);
RestorePending(oldPending2); // process any forward branches within the lambda body
ImmutableArray<PendingBranch> pendingReturns = RemoveReturns();
RestorePending(oldPending);
IntersectWith(ref finalState, ref this.State);
foreach (PendingBranch returnBranch in pendingReturns)
{
this.State = returnBranch.State;
IntersectWith(ref finalState, ref this.State);
}
this.State = finalState;
return null;
}
示例4: SynthesizedLambdaMethod
internal SynthesizedLambdaMethod(
NamedTypeSymbol containingType,
ClosureKind closureKind,
MethodSymbol topLevelMethod,
DebugId topLevelMethodId,
BoundLambda lambdaNode,
DebugId lambdaId)
: base(containingType,
lambdaNode.Symbol,
null,
lambdaNode.SyntaxTree.GetReference(lambdaNode.Body.Syntax),
lambdaNode.Syntax.GetLocation(),
MakeName(topLevelMethod.Name, topLevelMethodId, closureKind, lambdaId),
(closureKind == ClosureKind.ThisOnly ? DeclarationModifiers.Private : DeclarationModifiers.Internal)
| (lambdaNode.Symbol.IsAsync ? DeclarationModifiers.Async : 0))
{
_topLevelMethod = topLevelMethod;
TypeMap typeMap;
ImmutableArray<TypeParameterSymbol> typeParameters;
LambdaFrame lambdaFrame;
if (!topLevelMethod.IsGenericMethod)
{
typeMap = TypeMap.Empty;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else if ((object)(lambdaFrame = this.ContainingType as LambdaFrame) != null)
{
typeMap = lambdaFrame.TypeMap;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
typeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out typeParameters);
}
AssignTypeMapAndTypeParameters(typeMap, typeParameters);
}
示例5: VisitLambda
// Control flow analysis does not normally scan the body of a lambda, but region analysis does.
public override BoundNode VisitLambda(BoundLambda node)
{
return VisitLocalFunctionOrLambda(node.Body);
}
示例6: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
MethodsConvertedToDelegates.Add(node.Symbol.OriginalDefinition);
return VisitLambdaOrFunction(node);
}
示例7: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
var origLabels = this.currentLabels;
var origSeenAwait = _seenAwait;
this.currentLabels = null;
_seenAwait = false;
base.VisitLambda(node);
this.currentLabels = origLabels;
_seenAwait = origSeenAwait;
return null;
}
示例8: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
if (_inExpressionLambda)
{
switch (node.Syntax.Kind())
{
case SyntaxKind.ParenthesizedLambdaExpression:
{
var lambdaSyntax = (ParenthesizedLambdaExpressionSyntax)node.Syntax;
if (lambdaSyntax.AsyncKeyword.Kind() == SyntaxKind.AsyncKeyword)
{
Error(ErrorCode.ERR_BadAsyncExpressionTree, node);
}
else if (lambdaSyntax.Body.Kind() == SyntaxKind.Block)
{
Error(ErrorCode.ERR_StatementLambdaToExpressionTree, node);
}
else if (lambdaSyntax.Body.Kind() == SyntaxKind.RefExpression)
{
Error(ErrorCode.ERR_BadRefReturnExpressionTree, node);
}
var lambda = node.ExpressionSymbol as MethodSymbol;
if ((object)lambda != null)
{
foreach (var p in lambda.Parameters)
{
if (p.RefKind != RefKind.None && p.Locations.Length != 0)
{
_diagnostics.Add(ErrorCode.ERR_ByRefParameterInExpressionTree, p.Locations[0]);
}
}
}
}
break;
case SyntaxKind.SimpleLambdaExpression:
{
var lambdaSyntax = (SimpleLambdaExpressionSyntax)node.Syntax;
if (lambdaSyntax.AsyncKeyword.Kind() == SyntaxKind.AsyncKeyword)
{
Error(ErrorCode.ERR_BadAsyncExpressionTree, node);
}
else if (lambdaSyntax.Body.Kind() == SyntaxKind.Block)
{
Error(ErrorCode.ERR_StatementLambdaToExpressionTree, node);
}
else if (lambdaSyntax.Body.Kind() == SyntaxKind.RefExpression)
{
Error(ErrorCode.ERR_BadRefReturnExpressionTree, node);
}
}
break;
case SyntaxKind.AnonymousMethodExpression:
Error(ErrorCode.ERR_ExpressionTreeContainsAnonymousMethod, node);
break;
default:
// other syntax forms arise from query expressions, and always result from implied expression-lambda-like forms
break;
}
}
return base.VisitLambda(node);
}
示例9: VisitLambda
private BoundExpression VisitLambda(BoundLambda node)
{
var result = VisitLambdaInternal(node);
return node.Type.IsExpressionTree() ? ExprFactory("Quote", result) : result;
}
示例10: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
// Do not recurse into nested lambdas; we don't want their returns.
return null;
}
示例11: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
Debug.Assert((object)node.Symbol != null);
seenLambda = true;
var oldParent = currentParent;
var oldBlock = currentBlock;
currentParent = node.Symbol;
currentBlock = node.Body;
blockParent[currentBlock] = oldBlock;
var wasInExpressionLambda = inExpressionLambda;
inExpressionLambda = inExpressionLambda || node.Type.IsExpressionTree();
// for the purpose of constructing frames parameters are scoped as if they are inside the lambda block
foreach (var parameter in node.Symbol.Parameters)
{
variableBlock[parameter] = currentBlock;
if (inExpressionLambda) declaredInsideExpressionLambda.Add(parameter);
}
if (!node.Body.LocalsOpt.IsDefaultOrEmpty)
{
foreach (var local in node.Body.LocalsOpt)
{
variableBlock[local] = currentBlock;
if (inExpressionLambda) declaredInsideExpressionLambda.Add(local);
}
}
var result = base.VisitBlock(node.Body);
inExpressionLambda = wasInExpressionLambda;
currentParent = oldParent;
currentBlock = oldBlock;
return result;
}
示例12: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
lambdaLevel++;
base.VisitLambda(node);
lambdaLevel--;
return null;
}
示例13: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
MakeSlots(node.Symbol.Parameters);
return base.VisitLambda(node);
}
示例14: VisitLambda
public override BoundNode VisitLambda(BoundLambda node)
{
Debug.Assert((object)node.Symbol != null);
SeenLambda = true;
var oldParent = _currentParent;
var oldBlock = _currentScope;
_currentParent = node.Symbol;
_currentScope = node.Body;
scopeParent[_currentScope] = oldBlock;
var wasInExpressionLambda = _inExpressionLambda;
_inExpressionLambda = _inExpressionLambda || node.Type.IsExpressionTree();
if (!_inExpressionLambda)
{
// for the purpose of constructing frames parameters are scoped as if they are inside the lambda block
foreach (var parameter in node.Symbol.Parameters)
{
variableScope[parameter] = _currentScope;
}
foreach (var local in node.Body.Locals)
{
variableScope[local] = _currentScope;
}
}
var result = base.VisitBlock(node.Body);
_inExpressionLambda = wasInExpressionLambda;
_currentParent = oldParent;
_currentScope = oldBlock;
return result;
}
示例15: ReallyBind
private BoundLambda ReallyBind(NamedTypeSymbol delegateType)
{
var returnType = DelegateReturnType(delegateType);
LambdaSymbol lambdaSymbol;
Binder lambdaBodyBinder;
BoundBlock block;
var diagnostics = DiagnosticBag.GetInstance();
// when binding for real (not for return inference), there is still
// a good chance that we could reuse a body of a lambda previously bound for
// return type inference.
MethodSymbol cacheKey = GetCacheKey(delegateType);
BoundLambda returnInferenceLambda;
if (_returnInferenceCache.TryGetValue(cacheKey, out returnInferenceLambda) && returnInferenceLambda.InferredFromSingleType)
{
var lambdaSym = returnInferenceLambda.Symbol;
var lambdaRetType = lambdaSym.ReturnType;
if (lambdaRetType == returnType)
{
lambdaSymbol = lambdaSym;
lambdaBodyBinder = returnInferenceLambda.Binder;
block = returnInferenceLambda.Body;
diagnostics.AddRange(returnInferenceLambda.Diagnostics);
goto haveLambdaBodyAndBinders;
}
}
var parameters = DelegateParameters(delegateType);
lambdaSymbol = new LambdaSymbol(binder.Compilation, binder.ContainingMemberOrLambda, _unboundLambda, parameters, returnType);
lambdaBodyBinder = new ExecutableCodeBinder(_unboundLambda.Syntax, lambdaSymbol, ParameterBinder(lambdaSymbol, binder));
block = BindLambdaBody(lambdaSymbol, ref lambdaBodyBinder, diagnostics);
ValidateUnsafeParameters(diagnostics, parameters);
haveLambdaBodyAndBinders:
bool reachableEndpoint = ControlFlowPass.Analyze(binder.Compilation, lambdaSymbol, block, diagnostics);
if (reachableEndpoint)
{
if (DelegateNeedsReturn(delegateType))
{
// Not all code paths return a value in {0} of type '{1}'
diagnostics.Add(ErrorCode.ERR_AnonymousReturnExpected, lambdaSymbol.Locations[0], this.MessageID.Localize(), delegateType);
}
else
{
block = FlowAnalysisPass.AppendImplicitReturn(block, lambdaSymbol, _unboundLambda.Syntax);
}
}
if (IsAsync && !ErrorFacts.PreventsSuccessfulDelegateConversion(diagnostics))
{
if ((object)returnType != null && // Can be null if "delegateType" is not actually a delegate type.
returnType.SpecialType != SpecialType.System_Void &&
returnType != binder.Compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task) &&
returnType.OriginalDefinition != binder.Compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task_T))
{
// Cannot convert async {0} to delegate type '{1}'. An async {0} may return void, Task or Task<T>, none of which are convertible to '{1}'.
diagnostics.Add(ErrorCode.ERR_CantConvAsyncAnonFuncReturns, lambdaSymbol.Locations[0], lambdaSymbol.MessageID.Localize(), delegateType);
}
}
if (IsAsync)
{
Debug.Assert(lambdaSymbol.IsAsync);
SourceMemberMethodSymbol.ReportAsyncParameterErrors(lambdaSymbol, diagnostics, lambdaSymbol.Locations[0]);
}
var result = new BoundLambda(_unboundLambda.Syntax, block, diagnostics.ToReadOnlyAndFree(), lambdaBodyBinder, delegateType, inferReturnType: false)
{ WasCompilerGenerated = _unboundLambda.WasCompilerGenerated };
return result;
}