当前位置: 首页>>代码示例>>C#>>正文


C# CSharp.BoundLambda类代码示例

本文整理汇总了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);
            }
开发者ID:nagyist,项目名称:roslyn,代码行数:32,代码来源:LambdaRewriter.Frame.cs

示例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);
        }
开发者ID:Rookieek,项目名称:roslyn,代码行数:12,代码来源:VariablesDeclaredWalker.cs

示例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;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:21,代码来源:AbstractRegionControlFlowPass.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:39,代码来源:SynthesizedLambdaMethod.cs

示例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);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:5,代码来源:AbstractRegionControlFlowPass.cs

示例6: VisitLambda

 public override BoundNode VisitLambda(BoundLambda node)
 {
     MethodsConvertedToDelegates.Add(node.Symbol.OriginalDefinition);
     return VisitLambdaOrFunction(node);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:5,代码来源:LambdaRewriter.Analysis.cs

示例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;
            }
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:15,代码来源:AsyncExceptionHandlerRewriter.cs

示例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);
        }
开发者ID:abock,项目名称:roslyn,代码行数:66,代码来源:DiagnosticsPass_ExpressionTrees.cs

示例9: VisitLambda

 private BoundExpression VisitLambda(BoundLambda node)
 {
     var result = VisitLambdaInternal(node);
     return node.Type.IsExpressionTree() ? ExprFactory("Quote", result) : result;
 }
开发者ID:MichalStrehovsky,项目名称:roslyn,代码行数:5,代码来源:ExpressionLambdaRewriter.cs

示例10: VisitLambda

 public override BoundNode VisitLambda(BoundLambda node)
 {
     // Do not recurse into nested lambdas; we don't want their returns.
     return null;
 }
开发者ID:GeertVL,项目名称:roslyn,代码行数:5,代码来源:UnboundLambda.cs

示例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;
            }
开发者ID:riversky,项目名称:roslyn,代码行数:34,代码来源:LambdaRewriter.Analysis.cs

示例12: VisitLambda

 public override BoundNode VisitLambda(BoundLambda node)
 {
     lambdaLevel++;
     base.VisitLambda(node);
     lambdaLevel--;
     return null;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:LocalRewriter_WhileStatement.cs

示例13: VisitLambda

 public override BoundNode VisitLambda(BoundLambda node)
 {
     MakeSlots(node.Symbol.Parameters);
     return base.VisitLambda(node);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:5,代码来源:AbstractRegionDataFlowPass.cs

示例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;
            }
开发者ID:GloryChou,项目名称:roslyn,代码行数:32,代码来源:LambdaRewriter.Analysis.cs

示例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&lt;T&gt;, 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;
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:76,代码来源:UnboundLambda.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.BoundLambda类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。