public void VisitElse(WithBlock astNode)
        {
            //Leave Context
            state.ContextStack.Pop();
            var truthyContext = state.TruthyStack.Pop();

            truthyContext.Truthy = !truthyContext.Truthy;
            state.TruthyStack.Push(truthyContext);
            state.PushNewBlock();
        }
Exemple #2
0
        private GraceObject WithDo(EvaluationContext ctx, MethodRequest req)
        {
            var with      = req[0].Arguments[0];
            var block     = req[1].Arguments[0];
            var withBlock = new WithBlock(elements, block);
            var innerReq  = MethodRequest.Single("do", withBlock);

            with.Request(ctx, innerReq);
            return(GraceObject.Done);
        }
        public void VisitEnter(WithBlock astNode)
        {
            state.SetCursor(astNode);
            state.PushNewBlock();
            //Enter new Context and promise to check its truthyness
            Context context;

            if (astNode.Expr.TryEvaluate(state, out context))
            {
                state.PromiseTruthyCheck(context);
                state.ContextStack.Push(context);
            }
        }
        public void VisitLeave(WithBlock astNode)
        {
            //Leave Context
            state.ContextStack.Pop();
            var latestBlock = state.PopBlock();

            if (astNode.HasElseBlock)
            {
                state.DoTruthyCheck(state.PopBlock(), latestBlock, IfType.If);
            }
            else
            {
                state.DoTruthyCheck(latestBlock, ifType: IfType.If);
            }
        }
Exemple #5
0
        public TranslationResult Translate(WithBlock withBlock, ScopeAccessInformation scopeAccessInformation, int indentationDepth)
        {
            if (withBlock == null)
            {
                throw new ArgumentNullException("withBlock");
            }
            if (scopeAccessInformation == null)
            {
                throw new ArgumentNullException("scopeAccessInformation");
            }
            if (indentationDepth < 0)
            {
                throw new ArgumentOutOfRangeException("indentationDepth", "must be zero or greater");
            }

            var translatedTargetReference = _statementTranslator.Translate(withBlock.Target, scopeAccessInformation, ExpressionReturnTypeOptions.Reference, _logger.Warning);
            var undeclaredVariables       = translatedTargetReference.VariablesAccessed
                                            .Where(v => !scopeAccessInformation.IsDeclaredReference(v, _nameRewriter));

            foreach (var undeclaredVariable in undeclaredVariables)
            {
                _logger.Warning("Undeclared variable: \"" + undeclaredVariable.Content + "\" (line " + (undeclaredVariable.LineIndex + 1) + ")");
            }

            var targetName = base._tempNameGenerator(new CSharpName("with"), scopeAccessInformation);
            var withBlockContentTranslationResult = Translate(
                withBlock.Content.ToNonNullImmutableList(),
                new ScopeAccessInformation(
                    withBlock,
                    scopeAccessInformation.ScopeDefiningParent,
                    scopeAccessInformation.ParentReturnValueNameIfAny,
                    scopeAccessInformation.ErrorRegistrationTokenIfAny,
                    new ScopeAccessInformation.DirectedWithReferenceDetails(
                        targetName,
                        withBlock.Target.Tokens.First().LineIndex
                        ),
                    scopeAccessInformation.ExternalDependencies,
                    scopeAccessInformation.Classes,
                    scopeAccessInformation.Functions,
                    scopeAccessInformation.Properties,
                    scopeAccessInformation.Constants,
                    scopeAccessInformation.Variables,
                    scopeAccessInformation.StructureExitPoints
                    ),
                indentationDepth
                );

            return(new TranslationResult(
                       withBlockContentTranslationResult.TranslatedStatements
                       .Insert(
                           new TranslatedStatement(
                               string.Format(
                                   "var {0} = {1};",
                                   targetName.Name,
                                   translatedTargetReference.TranslatedContent
                                   ),
                               indentationDepth,
                               withBlock.Target.Tokens.First().LineIndex
                               ),
                           0
                           ),
                       withBlockContentTranslationResult.ExplicitVariableDeclarations,
                       withBlockContentTranslationResult.UndeclaredVariablesAccessed.AddRange(undeclaredVariables)
                       ));
        }
        public override bool Walk(WithStatement node)
        {
            WithBlock wb = new WithBlock(node);
            // With is essentially a Try-Catch-Finally, hence Push Try Block for With Statement
            tryBlocks.Push(wb);
            node.Body.Walk(this);

            ExceptionBlock eb = tryBlocks.Pop();
            Debug.Assert((object)wb == (object)eb);

            return false;
        }
 public void VisitLeave(WithBlock astNode)
 {
     //Leave Context
       state.ContextStack.Pop();
       var latestBlock = state.PopBlock();
       if (astNode.HasElseBlock)
     state.DoTruthyCheck(state.PopBlock(), latestBlock, IfType.If);
       else
     state.DoTruthyCheck(latestBlock, ifType: IfType.If);
 }
 public void VisitEnter(WithBlock astNode)
 {
     state.SetCursor(astNode);
       state.PushNewBlock();
       //Enter new Context and promise to check its truthyness
       Context context;
       if (astNode.Expr.TryEvaluate(state, out context))
       {
     state.PromiseTruthyCheck(context);
     state.ContextStack.Push(context);
       }
 }
 public void VisitElse(WithBlock astNode)
 {
     //Leave Context
       state.ContextStack.Pop();
       var truthyContext = state.TruthyStack.Pop();
       truthyContext.Truthy = !truthyContext.Truthy;
       state.TruthyStack.Push(truthyContext);
       state.PushNewBlock();
 }