Search in sources :

Example 11 with VariableDeclarationNode

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

the class SourcePrinter method printArguments_.

public boolean printArguments_(final VariableDeclarationNode[] _args) {
    if (_args.length == 0) {
        return false;
    }
    boolean _temp1 = true;
    for (final VariableDeclarationNode _arg : _args) {
        if (_temp1) {
            _temp1 = false;
        } else {
            _stream.append(' ');
        }
        _stream.append(':');
        SourcePrinter.this.visit_(_arg);
    }
    return true;
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode)

Example 12 with VariableDeclarationNode

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

the class SequenceNode method sourceTemporariesOn_.

public SequenceNode sourceTemporariesOn_(final StringBuilder _aStream) {
    if (_temporaries.length != 0) {
        _aStream.append('|');
        _aStream.append(' ');
        for (final VariableDeclarationNode _arg : _temporaries) {
            _arg.sourceOn_(_aStream);
            _aStream.append(' ');
        }
        _aStream.append('|');
    }
    return this;
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode)

Example 13 with VariableDeclarationNode

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

the class Parser method parseSequenceNode_.

public SequenceNode parseSequenceNode_(final st.gravel.support.jvm.Block1<Object, PragmaNode[]> _extraPragmaBlock) {
    VariableDeclarationNode[] _temporaries;
    Statement[] _statements;
    Statement _statement;
    final int _start;
    final PragmaNode[] _pragmas;
    _start = st.gravel.support.jvm.ReadStreamExtensions.position(_stream);
    this.eatWhitespace();
    _temporaries = new VariableDeclarationNode[] {};
    if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '|')) {
        Parser.this.eatWhitespace();
        boolean _temp1 = false;
        while (!_temp1) {
            _temp1 = st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '|');
            if (!_temp1) {
                Parser.this.eatWhitespace();
                _temporaries = st.gravel.support.jvm.ArrayExtensions.copyWith_(_temporaries, Parser.this.parseVariableDeclaration());
                Parser.this.eatWhitespace();
            }
        }
    }
    _pragmas = this.readPragmas();
    if (_pragmas.length != 0) {
        _extraPragmaBlock.value_(_pragmas);
    }
    _statements = new Statement[] {};
    _statement = this.parseStatement();
    this.eatWhitespace();
    boolean _temp2 = false;
    while (!_temp2) {
        _temp2 = _statement == null;
        if (!_temp2) {
            _statements = st.gravel.support.jvm.ArrayExtensions.copyWith_(_statements, _statement);
            st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '.');
            _statement = Parser.this.parseStatement();
            Parser.this.eatWhitespace();
        }
    }
    return ((SequenceNode) this.setSourcePosition_node_(_start, SequenceNode.factory.temporaries_statements_(_temporaries, _statements)));
}
Also used : PragmaNode(st.gravel.support.compiler.ast.PragmaNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Statement(st.gravel.support.compiler.ast.Statement)

Example 14 with VariableDeclarationNode

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

the class VariableToHolderRewriter method visitSequenceNode_.

@Override
public SequenceNode visitSequenceNode_(final SequenceNode _anObject) {
    final List<VariableDeclarationNode>[] _found;
    Statement[] _stmts;
    final VariableDeclarationNode[] _temporaries;
    _found = new List[1];
    _found[0] = new java.util.ArrayList();
    _stmts = 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) VariableToHolderRewriter.this.visit_(_each);
        }
    })));
    _temporaries = 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) {
            VariableDeclarationNode _newDecl;
            if (st.gravel.support.jvm.StringExtensions.equals_(_each.name(), _varName)) {
                _found[0].add(_each);
                _newDecl = HolderDeclarationNode.factory.name_type_(_each.name(), ((TypeNode) VariableToHolderRewriter.this.visit_(_each.type())));
            } else {
                _newDecl = ((VariableDeclarationNode) VariableToHolderRewriter.this.visit_(_each));
            }
            return (VariableDeclarationNode) _newDecl;
        }
    })));
    if (_found[0].size() != 0) {
        _stmts = st.gravel.support.jvm.ArrayExtensions.copyWithFirst_(_stmts, AssignmentNode.factory.variable_value_(VariableNode.factory.name_(_varName), CreateHolderNode.factory.basicNew()));
    }
    return SequenceNode.factory.temporaries_statements_(_temporaries, _stmts);
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) ArrayList(java.util.ArrayList) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) ArrayList(java.util.ArrayList) List(java.util.List) TypeNode(st.gravel.support.compiler.ast.TypeNode)

Example 15 with VariableDeclarationNode

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

the class VariableAccessToFieldAccessConverter method visitVariableNode_.

@Override
public Expression visitVariableNode_(final VariableNode _anObject) {
    final VariableDeclarationNode _instVar;
    if (st.gravel.support.jvm.StringExtensions.equals_(_anObject.name(), "self")) {
        return SelfNode.factory.basicNew();
    }
    if (st.gravel.support.jvm.StringExtensions.equals_(_anObject.name(), "super")) {
        return SuperNode.factory.reference_(_ownerReference);
    }
    if (this.includesLocalName_(_anObject.name())) {
        return LocalReadNode.factory.name_(_anObject.name());
    }
    _instVar = this.instVarAt_(_anObject.name());
    if (_instVar != null) {
        return FieldReadNode.factory.owner_field_type_(_owner, _instVar.name(), _instVar.type());
    }
    return GlobalReadNode.factory.namespace_name_(_namespace, _anObject.name());
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode)

Aggregations

VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)24 ArrayList (java.util.ArrayList)6 List (java.util.List)6 MethodNode (st.gravel.support.compiler.ast.MethodNode)6 Statement (st.gravel.support.compiler.ast.Statement)5 HashMap (java.util.HashMap)4 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)4 PragmaNode (st.gravel.support.compiler.ast.PragmaNode)4 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)4 TypeNode (st.gravel.support.compiler.ast.TypeNode)4 Map (java.util.Map)3 BlockTypeNode (st.gravel.support.compiler.ast.BlockTypeNode)3 ClassNode (st.gravel.support.compiler.ast.ClassNode)3 InstanceTypeNode (st.gravel.support.compiler.ast.InstanceTypeNode)3 SelfTypeNode (st.gravel.support.compiler.ast.SelfTypeNode)3 BlockSendArgument (st.gravel.support.compiler.jvm.BlockSendArgument)3 Expression (st.gravel.support.compiler.ast.Expression)2 KeywordMethodNode (st.gravel.support.compiler.ast.KeywordMethodNode)2 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)2 TypeCast (st.gravel.support.compiler.ast.TypeCast)2