Search in sources :

Example 6 with TypeNode

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

the class Parser method parseNestedExpression.

public Expression parseNestedExpression() {
    Expression _exp;
    final int _start;
    final TypeNode _typeCast;
    _start = st.gravel.support.jvm.ReadStreamExtensions.position(_stream);
    st.gravel.support.jvm.ReadStreamExtensions.next(_stream);
    this.eatWhitespace();
    _typeCast = st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '{') ? this.parseTypeExpressionAndClose() : null;
    _exp = this.parseAssignmentOrExpression();
    if (_typeCast != null) {
        _exp = TypeCast.factory.type_expression_(_typeCast, _exp);
    }
    this.eatWhitespace();
    st.gravel.support.jvm.ObjectExtensions.assert_(this, st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, ')'));
    return ((Expression) this.setSourcePosition_node_(_start, _exp));
}
Also used : Expression(st.gravel.support.compiler.ast.Expression) BlockTypeNode(st.gravel.support.compiler.ast.BlockTypeNode) SelfTypeNode(st.gravel.support.compiler.ast.SelfTypeNode) InstanceTypeNode(st.gravel.support.compiler.ast.InstanceTypeNode) TypeNode(st.gravel.support.compiler.ast.TypeNode)

Example 7 with TypeNode

use of st.gravel.support.compiler.ast.TypeNode 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 8 with TypeNode

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

the class Parser method parseTypeOperand.

public TypeNode parseTypeOperand() {
    final String _id;
    TypeNode _base;
    TypeNode[] _args;
    TypeNode _exp;
    this.eatWhitespace();
    _id = this.parseIdentifier();
    if (_id != null) {
        if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '.')) {
            String[] _arr;
            _arr = st.gravel.support.jvm.ArrayFactory.with_with_(_id, Parser.this.parseIdentifier());
            boolean _temp1 = true;
            while (_temp1) {
                _temp1 = st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '.');
                if (_temp1) {
                    _arr = st.gravel.support.jvm.ArrayExtensions.copyWith_(_arr, Parser.this.parseIdentifier());
                }
            }
            _base = NamespacedTypeVariableNode.factory.path_(_arr);
        } else {
            if (st.gravel.support.jvm.StringExtensions.equals_(_id, "Self")) {
                _base = SelfTypeNode.factory.basicNew();
            } else {
                if (st.gravel.support.jvm.StringExtensions.equals_(_id, "Instance")) {
                    _base = InstanceTypeNode.factory.basicNew();
                } else {
                    _base = TypeVariableNode.factory.name_(_id);
                }
            }
        }
        Parser.this.eatWhitespace();
        if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '[')) {
            _args = Parser.this.parseTypeExpressionListAndClose();
            _exp = GenericTypeVariableNode.factory.root_arguments_(_base, _args);
        } else {
            _exp = _base;
        }
        Parser.this.eatWhitespace();
        if (st.gravel.support.jvm.CharacterExtensions.equals_(st.gravel.support.jvm.ReadStreamExtensions.peek(_stream), 'd')) {
            final String _defString;
            _defString = st.gravel.support.jvm.ReadStreamExtensions.next_(_stream, 3);
            st.gravel.support.jvm.ObjectExtensions.assert_(Parser.this, st.gravel.support.jvm.StringExtensions.equals_(_defString, "def"));
            return _exp.asDefNode();
        } else {
            return _exp;
        }
    }
    if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '[')) {
        return Parser.this.parseTypeExpressionBlockAndClose();
    }
    throw ParseError.factory.basicNew();
}
Also used : BlockTypeNode(st.gravel.support.compiler.ast.BlockTypeNode) SelfTypeNode(st.gravel.support.compiler.ast.SelfTypeNode) InstanceTypeNode(st.gravel.support.compiler.ast.InstanceTypeNode) TypeNode(st.gravel.support.compiler.ast.TypeNode)

Example 9 with TypeNode

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

the class SourcePrinter method visitBlockTypeNode_.

@Override
public SourcePrinter visitBlockTypeNode_(final BlockTypeNode _aNode) {
    _stream.append('[');
    boolean _temp1 = true;
    for (final TypeNode _each : _aNode.arguments()) {
        if (_temp1) {
            _temp1 = false;
        } else {
            _stream.append(',');
            _stream.append(' ');
        }
        if (_each == null) {
            _stream.append("Unknown");
        } else {
            SourcePrinter.this.visit_(_each);
        }
    }
    if (_aNode.returnType() != null) {
        if (_aNode.arguments().length != 0) {
            _stream.append(',');
            _stream.append(' ');
        }
        SourcePrinter.this.visit_(_aNode.returnType());
    }
    _stream.append(']');
    return this;
}
Also used : BlockTypeNode(st.gravel.support.compiler.ast.BlockTypeNode) BottomTypeNode(st.gravel.support.compiler.ast.BottomTypeNode) ClassTypeNode(st.gravel.support.compiler.ast.ClassTypeNode) SelfTypeNode(st.gravel.support.compiler.ast.SelfTypeNode) InstanceTypeNode(st.gravel.support.compiler.ast.InstanceTypeNode) TypeNode(st.gravel.support.compiler.ast.TypeNode)

Example 10 with TypeNode

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

the class SourcePrinter method visitGenericTypeVariableNode_.

@Override
public SourcePrinter visitGenericTypeVariableNode_(final GenericTypeVariableNode _aNode) {
    this.visit_(_aNode.root());
    _stream.append('[');
    boolean _temp1 = true;
    for (final TypeNode _each : _aNode.arguments()) {
        if (_temp1) {
            _temp1 = false;
        } else {
            _stream.append(',');
            _stream.append(' ');
        }
        SourcePrinter.this.visit_(_each);
    }
    _stream.append(']');
    return this;
}
Also used : BlockTypeNode(st.gravel.support.compiler.ast.BlockTypeNode) BottomTypeNode(st.gravel.support.compiler.ast.BottomTypeNode) ClassTypeNode(st.gravel.support.compiler.ast.ClassTypeNode) SelfTypeNode(st.gravel.support.compiler.ast.SelfTypeNode) InstanceTypeNode(st.gravel.support.compiler.ast.InstanceTypeNode) TypeNode(st.gravel.support.compiler.ast.TypeNode)

Aggregations

TypeNode (st.gravel.support.compiler.ast.TypeNode)15 BlockTypeNode (st.gravel.support.compiler.ast.BlockTypeNode)12 InstanceTypeNode (st.gravel.support.compiler.ast.InstanceTypeNode)12 SelfTypeNode (st.gravel.support.compiler.ast.SelfTypeNode)12 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PragmaNode (st.gravel.support.compiler.ast.PragmaNode)4 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)4 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)3 TypeCast (st.gravel.support.compiler.ast.TypeCast)3 BottomTypeNode (st.gravel.support.compiler.ast.BottomTypeNode)2 ClassTypeNode (st.gravel.support.compiler.ast.ClassTypeNode)2 BlockNode (st.gravel.support.compiler.ast.BlockNode)1 Expression (st.gravel.support.compiler.ast.Expression)1 Statement (st.gravel.support.compiler.ast.Statement)1