Search in sources :

Example 11 with Statement

use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.

the class ParserTest method testAssignmentExpressionInBlock.

@Test
public void testAssignmentExpressionInBlock() {
    final Statement _node;
    _node = Parser.factory.source_("[ foo := 7 ]").parseStatement();
    assertTrue(st.gravel.support.jvm.ObjectExtensions.equals_(_node.factory(), BlockNode.factory));
    assertEquals((String) "[foo := 7]", (String) _node.prettySourceString());
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) Test(org.junit.Test)

Example 12 with Statement

use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.

the class LiteralSendInliner method produceBlock_arguments_.

public Statement produceBlock_arguments_(final BlockNode _block, final Expression[] _arguments) {
    final SequenceNode[] _body;
    final Statement[] _stmts;
    final Expression[] _argTemps;
    final VariableNode _result;
    final Statement _lastStatement;
    _body = new SequenceNode[1];
    _body[0] = _block.body();
    if (_body[0].statements().length == 0) {
        return NilLiteralNode.factory.basicNew();
    }
    for (final VariableDeclarationNode _temp : _block.body().temporaries()) {
        _body[0] = ((SequenceNode) VariableRenamer.factory.in_rename_to_(_body[0], _temp.name(), LiteralSendInliner.this.newTempSuggestion_(_temp.name()).name()));
    }
    _argTemps = st.gravel.support.jvm.ArrayExtensions.collect_(_arguments, ((st.gravel.support.jvm.Block1<Expression, Expression>) (new st.gravel.support.jvm.Block1<Expression, Expression>() {

        @Override
        public Expression value_(final Expression _each) {
            if (_each.isVariableNode()) {
                return _each;
            } else {
                final VariableNode _t;
                _t = LiteralSendInliner.this.newTempSuggestion_("extract");
                LiteralSendInliner.this.extraEmit_(LocalWriteNode.factory.name_value_(_t.name(), _each));
                return _t;
            }
        }
    })));
    _stmts = _body[0].statements();
    int _temp1 = (_stmts.length - 1);
    for (int _i = 1; _i <= _temp1; _i++) {
        final Statement _stmt;
        _stmt = _stmts[_i - 1];
        LiteralSendInliner.this.extraEmit_(LiteralSendInliner.this.in_replaceAll_with_(_stmt, _block.arguments(), _argTemps));
    }
    _lastStatement = this.in_replaceAll_with_(_stmts[_stmts.length - 1], _block.arguments(), _argTemps);
    if (_lastStatement.isReturnNode()) {
        return _lastStatement;
    }
    _result = this.newTempSuggestion_("result");
    this.extraEmit_(_result.assign_(((Expression) _lastStatement)));
    return _result;
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) SequenceNode(st.gravel.support.compiler.ast.SequenceNode) VariableNode(st.gravel.support.compiler.ast.VariableNode) Expression(st.gravel.support.compiler.ast.Expression) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode)

Example 13 with Statement

use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.

the class LiteralSendInliner method visitSequenceNode_.

@Override
public SequenceNode visitSequenceNode_(final SequenceNode _anObject) {
    final List<VariableDeclarationNode>[] _temporaries;
    final List<Statement>[] _statements;
    final List<VariableDeclarationNode>[] _oldExtraTemps;
    _statements = new List[1];
    _temporaries = new List[1];
    _oldExtraTemps = new List[1];
    _temporaries[0] = new java.util.ArrayList();
    _statements[0] = new java.util.ArrayList();
    for (final VariableDeclarationNode _each : _anObject.temporaries()) {
        final VariableDeclarationNode _newTemp;
        _newTemp = ((VariableDeclarationNode) LiteralSendInliner.this.visit_(_each));
        _temporaries[0].add(_newTemp);
    }
    for (final Statement _each : _anObject.statements()) {
        final Statement _res;
        final List<Statement> _oldExtraEmits;
        _oldExtraEmits = _extraEmits;
        _oldExtraTemps[0] = _extraTemps;
        _extraEmits = new java.util.ArrayList();
        _extraTemps = new java.util.ArrayList();
        _res = ((Statement) LiteralSendInliner.this.visit_(_each));
        _statements[0].addAll(_extraEmits);
        _temporaries[0] = st.gravel.support.jvm.OrderedCollectionExtensions.copyWithAll_(_temporaries[0], _extraTemps);
        _extraEmits = _oldExtraEmits;
        _extraTemps = _oldExtraTemps[0];
        _statements[0].add(_res);
    }
    return SequenceNode.factory.temporaries_statements_(_temporaries[0].toArray(new VariableDeclarationNode[_temporaries[0].size()]), _statements[0].toArray(new Statement[_statements[0].size()]));
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Statement(st.gravel.support.compiler.ast.Statement) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 14 with Statement

use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.

the class LiteralSendInliner method visitReturnNode_.

@Override
public Statement visitReturnNode_(final ReturnNode _anObject) {
    final Statement _value;
    _value = ((Statement) this.visit_(_anObject.value()));
    if (_value.isReturnNode()) {
        return _value;
    }
    return ReturnNode.factory.value_(((Expression) _value));
}
Also used : Expression(st.gravel.support.compiler.ast.Expression) Statement(st.gravel.support.compiler.ast.Statement)

Example 15 with Statement

use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.

the class NonLocalTempAccessToHolderConverter method visitSequenceNode_.

@Override
public SequenceNode visitSequenceNode_(final SequenceNode _anObject) {
    final SequenceNode[] _node;
    _node = new SequenceNode[1];
    _node[0] = SequenceNode.factory.temporaries_statements_(st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.temporaries(), ((st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>) (new st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>() {

        @Override
        public VariableDeclarationNode value_(final VariableDeclarationNode _each) {
            _temps.put(_each.name(), VariableScopeAnalyzerStateDefined.factory.basicNew());
            return (VariableDeclarationNode) NonLocalTempAccessToHolderConverter.this.visit_(_each);
        }
    }))), st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.statements(), ((st.gravel.support.jvm.Block1<Statement, Statement>) (new st.gravel.support.jvm.Block1<Statement, Statement>() {

        @Override
        public Statement value_(final Statement _each) {
            return (Statement) NonLocalTempAccessToHolderConverter.this.visit_(_each);
        }
    }))));
    for (final Map.Entry<String, VariableScopeAnalyzerState> _temp1 : _temps.entrySet()) {
        String _varName = _temp1.getKey();
        VariableScopeAnalyzerState _state = _temp1.getValue();
        if (NonLocalTempAccessToHolderConverter.this.needsRewrite_(_state)) {
            _node[0] = ((SequenceNode) VariableToHolderRewriter.factory.varName_(_varName).visit_(_node[0]));
        }
    }
    return _node[0];
}
Also used : VariableScopeAnalyzerState(st.gravel.support.compiler.ast.VariableScopeAnalyzerState) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Statement(st.gravel.support.compiler.ast.Statement) HashMap(java.util.HashMap) Map(java.util.Map) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Aggregations

Statement (st.gravel.support.compiler.ast.Statement)34 Test (org.junit.Test)21 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)5 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)3 Expression (st.gravel.support.compiler.ast.Expression)3 KeywordMessageNode (st.gravel.support.compiler.ast.KeywordMessageNode)3 MessageNode (st.gravel.support.compiler.ast.MessageNode)3 UnaryMessageNode (st.gravel.support.compiler.ast.UnaryMessageNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IntermediateStatement (st.gravel.support.compiler.ast.IntermediateStatement)1 PragmaNode (st.gravel.support.compiler.ast.PragmaNode)1 TypeNode (st.gravel.support.compiler.ast.TypeNode)1 VariableNode (st.gravel.support.compiler.ast.VariableNode)1 VariableScopeAnalyzerState (st.gravel.support.compiler.ast.VariableScopeAnalyzerState)1