public List<AphidExpression> ExpandIfExpression(IfExpression expression)
        {
            var g = Guid.NewGuid();

            IdentifierExpression ifLabel = new IdentifierExpression("If_" + g),
                elseLabel = new IdentifierExpression("Else_" + g),
                endIfLabel = new IdentifierExpression("EndIf_" + g);

            var ast = new List<AphidExpression>
            {
                ifLabel,
                MutateCondition(expression.Condition),
                new CallExpression(gotoFalseId, elseLabel)
            };

            ast.AddRange(expression.Body);
            ast.Add(new CallExpression(gotoId, endIfLabel));
            ast.Add(elseLabel);

            if (expression.ElseBody != null)
            {
                ast.AddRange(expression.ElseBody);
            }

            ast.Add(endIfLabel);

            return ast;
        }
Exemple #2
0
        public static IfExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            AphidExpression condition_aphidExpression,
            List <AphidExpression> body_list,
            List <AphidExpression> elseBody_list1,
            int value_i,
            int value_i1
            )
        {
            IfExpression ifExpression =
                new IfExpression(context_aphidExpressionContext, condition_aphidExpression,
                                 body_list, elseBody_list1);

            ((AphidExpression)ifExpression).Index  = value_i;
            ((AphidExpression)ifExpression).Length = value_i1;
            return(ifExpression);

            // TODO: Edit factory method of IfExpression
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
 private AphidObject InterpretIfExpression(IfExpression expression)
 {
     if ((bool)ValueHelper.Unwrap(InterpretExpression(expression.Condition)))
     {
         InterpretChild(expression.Body);
     }
     else if (expression.ElseBody != null)
     {
         InterpretChild(expression.ElseBody);
     }
     return null;
 }
Exemple #4
0
        private CodeStatementCollection GenerateImperativeStatement(IfExpression node)
        {
            var condition = GenerateImperativeExpression(node.Condition, isCondition: true);
            var trueStmts = GenerateImperativeStatements(node.Body).OfType<CodeStatement>().ToArray();

            var falseStmts = node.ElseBody != null ?
                GenerateImperativeStatements(node.ElseBody).OfType<CodeStatement>().ToArray() :
                new CodeStatement[0];

            var stmt = new CodeConditionStatement(condition, trueStmts, falseStmts);

            return new CodeStatementCollection(new[] { stmt });
        }