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


C# Ast.ScopeBuilder类代码示例

本文整理汇总了C#中IronRuby.Compiler.Ast.ScopeBuilder的典型用法代码示例。如果您正苦于以下问题:C# ScopeBuilder类的具体用法?C# ScopeBuilder怎么用?C# ScopeBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScopeBuilder类属于IronRuby.Compiler.Ast命名空间,在下文中一共展示了ScopeBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TransformRead

        internal sealed override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
            string debugString = (IsSingletonDeclaration) ? "SINGLETON" : ((this is ClassDeclaration) ? "CLASS" : "MODULE") + " " + QualifiedName.Name;

            ScopeBuilder outerLocals = gen.CurrentScope;
                
            // definition needs to take place outside the defined lexical scope:
            MSA.Expression definition = MakeDefinitionExpression(gen);
            MSA.Expression selfVariable = outerLocals.DefineHiddenVariable("#module", typeof(RubyModule));
            MSA.Expression rfcVariable = gen.CurrentRfcVariable;
            MSA.Expression parentScope = gen.CurrentScopeVariable;

            // inner locals:
            ScopeBuilder scope = new ScopeBuilder();
            MSA.Expression scopeVariable = scope.DefineHiddenVariable("#scope", typeof(RubyScope));
            
            gen.EnterModuleDefinition(
                scope,
                selfVariable, 
                scopeVariable, 
                IsSingletonDeclaration
            );

            // first, transform locals defined within the module body:
            DefinedScope.TransformLocals(scope);

            // second, transform body:
            MSA.Expression transformedBody = Body.TransformRead(gen);

            // outer local:
            MSA.Expression resultVariable = outerLocals.DefineHiddenVariable("#result", transformedBody.Type);
            
            // begin with new scope
            //   self = DefineModule/Class(... parent scope here ...)
            //   <body>
            // end
            MSA.Expression result = AstFactory.Block(
                gen.DebugMarker(debugString),
                Ast.Assign(selfVariable, definition),
                scope.CreateScope(
                    Ast.Block(
                        Ast.Assign(scopeVariable, 
                            Methods.CreateModuleScope.OpCall(scope.VisibleVariables(), parentScope, rfcVariable, selfVariable)),
                        Ast.Assign(resultVariable, transformedBody),
                        AstUtils.Empty()
                    )
                ),
                gen.DebugMarker("END OF " + debugString),
                resultVariable
            );

            gen.LeaveModuleDefinition();

            return result;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:54,代码来源:ModuleDeclaration.cs

示例2: ScopeBuilder

        public ScopeBuilder(AstParameters parameters, int firstClosureParam, int localCount, 
            ScopeBuilder parent, LexicalScope/*!*/ lexicalScope) {
            Debug.Assert(parent == null || parent.LexicalScope == lexicalScope.OuterScope);
#if DEBUG
            _id = Interlocked.Increment(ref _Id);
#endif
            _parent = parent;
            _parameters = parameters;
            _localCount = localCount;
            _firstClosureParam = firstClosureParam;
            _lexicalScope = lexicalScope;
            _hiddenVariables = new AstParameters();
            _localsTuple = DefineHiddenVariable("#locals", MakeLocalsTupleType());
            _outermostClosureReferredTo = this;
        }
开发者ID:atczyc,项目名称:ironruby,代码行数:15,代码来源:ScopeBuilder.cs

示例3: DefineParameters

        private MSA.ParameterExpression[]/*!*/ DefineParameters(AstGenerator/*!*/ gen, ScopeBuilder/*!*/ scope) {
            
            // user defined locals/args:
            MSA.ParameterExpression[] parameters = DefinedScope.TransformParameters(_parameters, HiddenParameterCount);
            scope.AddVisibleParameters(parameters, HiddenParameterCount);

            parameters[0] = Ast.Parameter(typeof(object), "#self");

            if (_parameters.Block != null) {
                // map user defined proc parameter to the special param #1:
                parameters[1] = _parameters.Block.TransformBlockParameterDefinition();
            } else {
                parameters[1] = Ast.Parameter(typeof(Proc), "#block");
            }

            return parameters;
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:17,代码来源:MethodDeclaration.cs

示例4: EnterBlockDefinition

        public void EnterBlockDefinition(
            ScopeBuilder/*!*/ locals,
            MSA.Expression/*!*/ bfcVariable,
            MSA.Expression/*!*/ selfVariable,
            MSA.ParameterExpression/*!*/ runtimeScopeVariable, 
            MSA.LabelTarget/*!*/ redoLabel) {
            Assert.NotNull(locals, bfcVariable, selfVariable);
            Assert.NotNull(redoLabel);

            BlockScope block = new BlockScope(locals, selfVariable, runtimeScopeVariable, bfcVariable, redoLabel);
            block.Parent = _currentElement;
            block.ParentRescue = _currentRescue;
            block.ParentLoop = _currentLoop;
            block.ParentBlock = _currentBlock;
            block.ParentVariableScope = _currentVariableScope;
            
            _currentElement = block;
            _currentRescue = null;
            _currentLoop = null;
            _currentBlock = block;
            _currentVariableScope = block;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:22,代码来源:AstGenerator.cs

示例5: ModuleScope

 public ModuleScope(ScopeBuilder/*!*/ builder, MSA.Expression/*!*/ selfVariable, MSA.ParameterExpression/*!*/ runtimeScopeVariable, bool isSingleton)
     : base(builder, selfVariable, runtimeScopeVariable) {
     _isSingleton = isSingleton;
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:4,代码来源:AstGenerator.cs

示例6: MethodScope

            public MethodScope(
                ScopeBuilder/*!*/ builder,
                MSA.Expression/*!*/ selfVariable,
                MSA.ParameterExpression/*!*/ runtimeScopeVariable,
                MSA.Expression blockVariable, 
                string methodName, 
                Parameters parameters)
                : base(builder, selfVariable, runtimeScopeVariable) {

                _blockVariable = blockVariable;
                _methodName = methodName;
                _parameters = parameters;
            }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:13,代码来源:AstGenerator.cs

示例7: BlockScope

 public BlockScope(ScopeBuilder/*!*/ builder, MSA.Expression/*!*/ selfVariable, MSA.ParameterExpression/*!*/ runtimeScopeVariable,
     MSA.Expression/*!*/ bfcVariable, MSA.LabelTarget/*!*/ redoLabel)
     : base(builder, selfVariable, runtimeScopeVariable) {
     Assert.NotNull(bfcVariable, redoLabel);
     _bfcVariable = bfcVariable;
     _redoLabel = redoLabel;
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:7,代码来源:AstGenerator.cs

示例8: FrameScope

 public FrameScope(ScopeBuilder/*!*/ builder, MSA.Expression/*!*/ selfVariable, MSA.ParameterExpression/*!*/ runtimeScopeVariable)
     : base(builder, selfVariable, runtimeScopeVariable) {
     _uniqueId = Interlocked.Increment(ref _UniqueId);
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:4,代码来源:AstGenerator.cs

示例9: VariableScope

 public VariableScope(ScopeBuilder/*!*/ locals, MSA.Expression/*!*/ selfVariable, MSA.ParameterExpression/*!*/ runtimeScopeVariable) {
     Assert.NotNull(selfVariable, runtimeScopeVariable);
     _builder = locals;
     _runtimeScopeVariable = runtimeScopeVariable;
     _selfVariable = selfVariable;
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:6,代码来源:AstGenerator.cs

示例10: TransformBody

        private MSA.Expression/*!*/ TransformBody(AstGenerator/*!*/ gen, MSA.Expression/*!*/ methodDefinitionVariable) {
            string encodedName = RubyExceptionData.EncodeMethodName(gen.SourceUnit, _name, Location);
            
            ScopeBuilder scope = new ScopeBuilder();
            MSA.Expression parentScope = gen.CurrentScopeVariable;

            MSA.ParameterExpression[] parameters = DefineParameters(gen, scope);
            MSA.Expression currentMethodVariable = scope.DefineHiddenVariable("#method", typeof(RubyMethodInfo));
            MSA.Expression rfcVariable = scope.DefineHiddenVariable("#rfc", typeof(RuntimeFlowControl));
            MSA.Expression scopeVariable = scope.DefineHiddenVariable("#scope", typeof(RubyMethodScope));
            MSA.Expression selfParameter = parameters[0];
            MSA.Expression blockParameter = parameters[1];

            gen.EnterMethodDefinition(
                scope,
                selfParameter,
                scopeVariable,
                blockParameter,
                rfcVariable,
                currentMethodVariable,
                _name,
                _parameters
            );

            DefinedScope.TransformLocals(scope);

            MSA.ParameterExpression unwinder = scope.DefineHiddenVariable("#unwinder", typeof(MethodUnwinder));

            MSA.Expression body = AstFactory.MakeUserMethodBody(
                gen, Location.End.Line,
                blockParameter,
                rfcVariable,
                unwinder,
                Ast.Block(
                    Ast.Assign(currentMethodVariable, methodDefinitionVariable),

                    Ast.Assign(scopeVariable, Methods.CreateMethodScope.OpCall(
                        scope.VisibleVariables(), parentScope, currentMethodVariable, rfcVariable, selfParameter, blockParameter)
                    ),
                
                    _parameters.TransformOptionalsInitialization(gen),
                    gen.TraceEnabled ? Methods.TraceMethodCall.OpCall(scopeVariable, Ast.Convert(AstUtils.Constant(gen.SourceUnit.Path), typeof(string)), AstUtils.Constant(Location.Start.Line)) : AstUtils.Empty(),
                    Body.TransformResult(gen, ResultOperation.Return),
                    AstUtils.Empty()
                ),
                ResultOperation.Return,
                (gen.Profiler != null) ? gen.Profiler.GetTickIndex(encodedName) : -1,
                (gen.Profiler != null) ? scope.DefineHiddenVariable("#stamp", typeof(long)) : null,
                gen.ReturnLabel
            );

            body = gen.AddReturnTarget(scope.CreateScope(body));
            gen.LeaveMethodDefinition();

            return CreateLambda(
                encodedName, 
                parameters, 
                body
            );
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:60,代码来源:MethodDeclaration.cs

示例11: EnterSourceUnit

        public void EnterSourceUnit(
            ScopeBuilder/*!*/ locals,
            MSA.Expression/*!*/ selfParameter,
            MSA.ParameterExpression/*!*/ runtimeScopeVariable,
            MSA.Expression blockParameter,
            string methodName,
            Parameters parameters) {
            Assert.NotNull(locals, selfParameter, runtimeScopeVariable);

            Debug.Assert(_currentElement == null && _currentLoop == null && _currentRescue == null &&
                _currentVariableScope == null && _currentModule == null && _currentBlock == null && _currentMethod == null);

            EnterMethodDefinition(
                locals,
                selfParameter,
                runtimeScopeVariable,
                blockParameter,
                methodName,
                parameters);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:20,代码来源:AstGenerator.cs

示例12: EnterMethodDefinition

        public void EnterMethodDefinition(
            ScopeBuilder/*!*/ locals, 
            MSA.Expression/*!*/ selfParameter,
            MSA.ParameterExpression/*!*/ runtimeScopeVariable,
            MSA.Expression blockParameter,
            string/*!*/ methodName,
            Parameters parameters) {
            Assert.NotNull(locals, selfParameter, runtimeScopeVariable);

            MethodScope method = new MethodScope(
                locals,
                selfParameter, 
                runtimeScopeVariable, 
                blockParameter, 
                methodName, 
                parameters
            );

            method.Parent = _currentElement;
            method.ParentRescue = _currentRescue;
            method.ParentLoop = _currentLoop;
            method.ParentBlock = _currentBlock;
            method.ParentVariableScope = _currentVariableScope;
            method.ParentMethod = _currentMethod;

            _currentElement = method;
            _currentRescue = null;
            _currentLoop = null;
            _currentBlock = null;
            _currentVariableScope = method;
            _currentMethod = method;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:32,代码来源:AstGenerator.cs

示例13: MethodScope

            public MethodScope(
                ScopeBuilder/*!*/ builder, 
                MSA.Expression/*!*/ selfVariable, 
                MSA.Expression/*!*/ runtimeScopeVariable,
                MSA.Expression blockVariable, 
                MSA.Expression/*!*/ rfcVariable,
                MSA.Expression currentMethodVariable, 
                string methodName, 
                Parameters parameters)
                : base(builder, selfVariable, runtimeScopeVariable) {

                Assert.NotNull(rfcVariable);
                _blockVariable = blockVariable;
                _rfcVariable = rfcVariable;
                _methodName = methodName;
                _parameters = parameters;
                _currentMethodVariable = currentMethodVariable;
            }
开发者ID:jcteague,项目名称:ironruby,代码行数:18,代码来源:AstGenerator.cs

示例14: TransformBody

        internal MSA.LambdaExpression/*!*/ TransformBody(AstGenerator/*!*/ gen, RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule) {
            string encodedName = RubyExceptionData.EncodeMethodName(_name, gen.SourcePath, Location);
            
            ScopeBuilder scope = new ScopeBuilder();
            
            MSA.ParameterExpression[] parameters = DefineParameters(gen, scope);
            var currentMethodVariable = scope.DefineHiddenVariable("#method", typeof(RubyMethodInfo));
            var rfcVariable = scope.DefineHiddenVariable("#rfc", typeof(RuntimeFlowControl));
            var scopeVariable = scope.DefineHiddenVariable("#scope", typeof(RubyMethodScope));
            var selfParameter = parameters[0];
            var blockParameter = parameters[1];

            gen.EnterMethodDefinition(
                scope,
                selfParameter,
                scopeVariable,
                blockParameter,
                rfcVariable,
                _name,
                _parameters
            );

            DefinedScope.TransformLocals(scope);

            // profiling:
            MSA.Expression profileStart, profileEnd;
            if (gen.Profiler != null) {
                int profileTickIndex = gen.Profiler.GetTickIndex(encodedName);
                var stampVariable = scope.DefineHiddenVariable("#stamp", typeof(long));
                profileStart = Ast.Assign(stampVariable, Methods.Stopwatch_GetTimestamp.OpCall());
                profileEnd = Methods.UpdateProfileTicks.OpCall(AstUtils.Constant(profileTickIndex), stampVariable);
            } else {
                profileStart = profileEnd = AstUtils.Empty();
            }

            // tracing:
            MSA.Expression traceCall, traceReturn;
            if (gen.TraceEnabled) {
                traceCall = Methods.TraceMethodCall.OpCall(
                    scopeVariable, 
                    gen.SourcePathConstant, 
                    AstUtils.Constant(Location.Start.Line)
                );

                traceReturn = Methods.TraceMethodReturn.OpCall(
                    gen.CurrentScopeVariable,
                    gen.SourcePathConstant,
                    AstUtils.Constant(Location.End.Line)
                );
            } else {
                traceCall = traceReturn = AstUtils.Empty();
            }

            MSA.ParameterExpression unwinder = scope.DefineHiddenVariable("#unwinder", typeof(Exception));
            
            MSA.Expression body = AstUtils.Try(
                profileStart,

                // scope initialization:
                Ast.Assign(rfcVariable, Methods.CreateRfcForMethod.OpCall(AstUtils.Convert(blockParameter, typeof(Proc)))),
                Ast.Assign(scopeVariable, Methods.CreateMethodScope.OpCall(
                    scope.VisibleVariables(), 
                    Ast.Constant(declaringScope, typeof(RubyScope)),
                    Ast.Constant(declaringModule, typeof(RubyModule)), 
                    Ast.Constant(_name),
                    rfcVariable, selfParameter, blockParameter,
                    EnterInterpretedFrameExpression.Instance
                )),
            
                _parameters.TransformOptionalsInitialization(gen),
                traceCall,
                Body.TransformResult(gen, ResultOperation.Return)
            ).Filter(unwinder, Methods.IsMethodUnwinderTargetFrame.OpCall(scopeVariable, unwinder),
                Ast.Return(gen.ReturnLabel, Methods.GetMethodUnwinderReturnValue.OpCall(unwinder))
            ).Finally(  
                // leave frame:
                Methods.LeaveMethodFrame.OpCall(rfcVariable),
                LeaveInterpretedFrameExpression.Instance,
                profileEnd,
                traceReturn
            );

            body = gen.AddReturnTarget(scope.CreateScope(body));
            gen.LeaveMethodDefinition();

            return CreateLambda(encodedName, parameters, body);
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:87,代码来源:MethodDeclaration.cs

示例15: Transform

        internal override MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) {
            MSA.Expression parentScope = gen.CurrentScopeVariable;
            ScopeBuilder scope = new ScopeBuilder();

            // define hidden parameters and RHS-placeholders (#1..#n will be used as RHS of a parallel assignment):
            MSA.Expression blockParameter, selfParameter;
            MSA.ParameterExpression[] parameters = DefineParameters(out selfParameter, out blockParameter);

            MSA.ParameterExpression scopeVariable = scope.DefineHiddenVariable("#scope", typeof(RubyBlockScope));
            MSA.LabelTarget redoLabel = Ast.Label();

            gen.EnterBlockDefinition(
                scope,
                blockParameter,
                selfParameter,
                scopeVariable,
                redoLabel
            );

            if (_definedScope != null) {
                _definedScope.TransformLocals(scope);
            }

            MSA.Expression paramInit = MakeParametersInitialization(gen, parameters);
            MSA.ParameterExpression blockUnwinder = scope.DefineHiddenVariable("#unwinder", typeof(BlockUnwinder));
            MSA.ParameterExpression filterVariable = scope.DefineHiddenVariable("#e", typeof(Exception));

            MSA.Expression traceCall, traceReturn;
			if (gen.TraceEnabled) {
                int firstStatementLine = _body.Count > 0 ? _body.First.Location.Start.Line : Location.End.Line;
                int lastStatementLine = _body.Count > 0 ? _body.Last.Location.End.Line : Location.End.Line;

                traceCall = Methods.TraceBlockCall.OpCall(scopeVariable, blockParameter, Ast.Convert(AstUtils.Constant(gen.SourceUnit.Path), typeof(string)), AstUtils.Constant(firstStatementLine));
                traceReturn = Methods.TraceBlockReturn.OpCall(scopeVariable, blockParameter, Ast.Convert(AstUtils.Constant(gen.SourceUnit.Path), typeof(string)), AstUtils.Constant(lastStatementLine));
            } else {
                traceCall = traceReturn = Ast.Empty();
            }

            MSA.Expression body = AstUtils.Try(
                Ast.Assign(scopeVariable,
                    Methods.CreateBlockScope.OpCall(
                        scope.VisibleVariables(), parentScope, blockParameter, selfParameter, EnterInterpretedFrameExpression.Instance
                    )
                ),

                paramInit,
                traceCall,
                Ast.Label(redoLabel),
                AstUtils.Try(
                    gen.TransformStatements(_body, ResultOperation.Return)
                ).Catch(blockUnwinder,
                    // redo:
                    AstUtils.IfThen(Ast.Field(blockUnwinder, BlockUnwinder.IsRedoField), Ast.Goto(redoLabel)),

                    // next:
                    gen.Return(Ast.Field(blockUnwinder, BlockUnwinder.ReturnValueField))
                )
            ).Filter(filterVariable,
                Methods.FilterBlockException.OpCall(scopeVariable, filterVariable)
            ).Finally(
                traceReturn,
                Methods.LeaveBlockFrame.OpCall(scopeVariable),
                LeaveInterpretedFrameExpression.Instance
            );

            body = gen.AddReturnTarget(scope.CreateScope(body));
            gen.LeaveBlockDefinition();

            int parameterCount = _parameters.LeftValues.Count;

            var attributes = _parameters.GetBlockSignatureAttributes();

            return Methods.DefineBlock.OpCall(
                gen.CurrentScopeVariable,
                gen.CurrentRfcVariable,
                gen.CurrentSelfVariable,
                BlockDispatcher.CreateLambda(
                    body,
                    RubyExceptionData.EncodeMethodName(gen.SourceUnit, gen.CurrentMethod.MethodName, Location), 
                    new ReadOnlyCollection<MSA.ParameterExpression>(parameters),
                    parameterCount,
                    attributes
                ),
                AstUtils.Constant(parameterCount),
                AstUtils.Constant(attributes)
            );
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:87,代码来源:BlockDefinition.cs


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