use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class ClassBuilder method build.
public Class build() {
Map<String, String> _properties = new HashMap<>();
VariableDeclarationNode[] _instVars = instVars.toArray(new VariableDeclarationNode[instVars.size()]);
VariableDeclarationNode[] _classInstVars = new VariableDeclarationNode[0];
MethodNode[] _methods = methods.toArray(new MethodNode[methods.size()]);
MethodNode[] _classMethods = classMethods.toArray(new MethodNode[classMethods.size()]);
Symbol[] _namespace = new Symbol[] { Symbol.value("ClassBuilder") };
ClassNode classNode = ClassNode.factory.name_superclassPath_properties_instVars_classInstVars_sharedVariables_methods_classMethods_namespace_isExtension_isTrait_traitUsage_classTraitUsage_(Symbol.value(name), superclassName, _properties, _instVars, _classInstVars, new SharedDeclarationNode[0], _methods, _classMethods, _namespace, false, false, EmptyTraitUsageNode.factory.basicNew(), EmptyTraitUsageNode.factory.basicNew());
SystemDefinitionNode systemDefinitionNode = ImageBootstrapper.systemMapping.systemDefinitionNode();
ImageBootstrapper.systemMapping.updateTo_(systemDefinitionNode.withPackageNamed_classNode_(Symbol.value(name), classNode));
return ImageBootstrapper.systemMapping.classMappingAtReference_(classNode.reference()).identityClass();
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class KeywordMethodNode method sourceOn_.
@Override
public KeywordMethodNode sourceOn_(final StringBuilder _aStream) {
final String[] _keywords;
_keywords = st.gravel.support.jvm.StringExtensions.tokensBasedOn_(_selector, ':');
for (int _i = 1; _i <= _arguments.length; _i++) {
final String _keyword;
final VariableDeclarationNode _argument;
_keyword = _keywords[_i - 1];
_argument = _arguments[_i - 1];
if (!st.gravel.support.jvm.IntegerExtensions.equals_(_i, 1)) {
_aStream.append(' ');
}
_aStream.append(_keyword);
_aStream.append(':');
_aStream.append(' ');
_argument.sourceOn_(_aStream);
}
this.returnTypeAndBodySourceOn_(_aStream);
return this;
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode 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.VariableDeclarationNode 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()]));
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class BlockInliner method buildMethodNodeArguments_.
public VariableDeclarationNode[] buildMethodNodeArguments_(final MethodNode _node) {
final List<VariableDeclarationNode>[] _arguments;
_arguments = new List[1];
_arguments[0] = new java.util.ArrayList();
st.gravel.support.jvm.ArrayExtensions.with_do_(_astConstants, _node.arguments(), new st.gravel.support.jvm.Block2<Object, BlockSendArgument, VariableDeclarationNode>() {
@Override
public Object value_value_(final BlockSendArgument _astConstant, final VariableDeclarationNode _arg) {
if (_astConstant == null) {
return _arguments[0].add(_arg);
}
return BlockInliner.this;
}
});
for (final String _each : _copiedArgumentNames) {
_arguments[0].add(BlockInliner.this.variableDeclarationNodeFor_(_each));
}
return _arguments[0].toArray(new VariableDeclarationNode[_arguments[0].size()]);
}
Aggregations