Пример #1
0
 /// <summary>
 ///   FEATURE #45
 ///   make this an inlined return statement
 /// </summary>
 /// <param name="returnValueStorer">the variable used to store the return value</param>
 public void Unify([NotNull] VariableExpression returnValueStorer)
 {
     if (null != ConvertedStatementList)
     {
         ConvertedStatementList = new StatementList(MetaData,
                                                    ConvertedVariableDeclaration,
                                                    new ExpressionStatement(MetaData,
                                                                            new AssignmentExpression(MetaData, returnValueStorer,
                                                                                                     ConvertedReturnStatement.Expression)),
                                                    new GotoStatement(MetaData, ReturnLabel.GetLabel().Name));
     }
     else
     {
         ConvertedStatementList = new StatementList(MetaData,
                                                    new ExpressionStatement(MetaData,
                                                                            new AssignmentExpression(MetaData, returnValueStorer, Expression)),
                                                    new GotoStatement(MetaData, ReturnLabel.GetLabel().Name));
     }
 }
Пример #2
0
        public override void SurroundWith(Environment environment)
        {
            // base.SurroundWith(environment);
            Env = environment;
            Expression.SurroundWith(Env);
            if (null != ReturnLabel)
            {
                return;
            }
            var returnLabel = Env.FindReturnLabelByName(_labelName ?? "");

            if (null == returnLabel)
            {
                Errors.AddAndThrow($"{MetaData.GetErrorHeader()}cannot return outside a lambda");
            }
            else
            {
                ReturnLabel = returnLabel;
                ReturnLabel.StatementsUsingThis.Add(this);
            }
            if (Expression is AtomicExpression)
            {
                return;
            }
            var variableName = $"genRet{(ulong) GetHashCode()}";

            ConvertedVariableDeclaration =
                new VariableDeclaration(MetaData, variableName, Expression, type: Expression.GetExpressionType());
            ConvertedReturnStatement = new ReturnStatement(MetaData,
                                                           new VariableExpression(MetaData, variableName), _labelName)
            {
                ReturnLabel = ReturnLabel
            };
            ConvertedStatementList = new StatementList(MetaData,
                                                       ConvertedVariableDeclaration,
                                                       ConvertedReturnStatement);
        }
Пример #3
0
 public IfStatement(
     MetaData metaData,
     [NotNull] Expression condition,
     [NotNull] StatementList ifStatementList,
     [CanBeNull] StatementList elseStatementList = null) : base(metaData, condition, ifStatementList) =>