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));
}
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);
}
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();
}
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;
}
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;
}
Aggregations