use of st.gravel.support.compiler.ast.SequenceNode in project gravel by gravel-st.
the class IntermediateNodeRewriter method produce_ifTrue_ifFalse_.
public IfTrueIfFalseNode produce_ifTrue_ifFalse_(final Node _receiver, final Expression _trueExpr, final Expression _falseExpr) {
final BlockNode _trueBlockNode;
final BlockNode _falseBlockNode;
if (!_trueExpr.isBlockNode()) {
return null;
}
if (!_falseExpr.isBlockNode()) {
return null;
}
_trueBlockNode = ((BlockNode) _trueExpr);
_falseBlockNode = ((BlockNode) _falseExpr);
return IfTrueIfFalseNode.factory.test_trueSequence_falseSequence_returnType_(((Expression) this.visit_(_receiver)), ((SequenceNode) this.visit_(_trueBlockNode.body())), ((SequenceNode) this.visit_(_falseBlockNode.body())), TypeOrNode.factory.left_right_(_trueBlockNode.returnType(), _falseBlockNode.returnType()));
}
use of st.gravel.support.compiler.ast.SequenceNode 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;
}
use of st.gravel.support.compiler.ast.SequenceNode 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];
}
use of st.gravel.support.compiler.ast.SequenceNode in project gravel by gravel-st.
the class Parser method parseBinaryMethod_.
public BinaryMethodNode parseBinaryMethod_(final String _aString) {
final VariableDeclarationNode _argument;
final SequenceNode _body;
final TypeNode _returnType;
final PragmaNode[][] _pragmas;
_pragmas = new PragmaNode[1][];
this.eatWhitespace();
_argument = this.parseVariableDeclaration();
_returnType = this.parseReturnType();
_pragmas[0] = this.readPragmas();
_body = this.parseSequenceNode_(new st.gravel.support.jvm.Block1<Object, PragmaNode[]>() {
@Override
public Object value_(final PragmaNode[] _extraPragmas) {
return _pragmas[0] = st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_pragmas[0], _extraPragmas);
}
});
return BinaryMethodNode.factory.selector_argument_body_returnType_pragmas_protocol_(_aString, _argument, _body, _returnType, _pragmas[0], null);
}
use of st.gravel.support.compiler.ast.SequenceNode in project gravel by gravel-st.
the class Parser method parseUnaryMethod_.
public MethodNode parseUnaryMethod_(final String _aString) {
final SequenceNode _body;
final TypeNode _returnType;
final PragmaNode[][] _pragmas;
_pragmas = new PragmaNode[1][];
_returnType = this.parseReturnType();
_pragmas[0] = this.readPragmas();
_body = this.parseSequenceNode_(new st.gravel.support.jvm.Block1<Object, PragmaNode[]>() {
@Override
public Object value_(final PragmaNode[] _extraPragmas) {
return _pragmas[0] = st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_pragmas[0], _extraPragmas);
}
});
return UnaryMethodNode.factory.selector_body_returnType_pragmas_protocol_(_aString, _body, _returnType, _pragmas[0], null);
}
Aggregations