use of st.gravel.support.compiler.ast.ClassNode 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.ClassNode in project gravel by gravel-st.
the class DiskClassReader method readClass_packageName_file_namespace_.
public ClassNode readClass_packageName_file_namespace_(final String _aName, final st.gravel.core.Symbol _packageName, final java.io.File _aFilename, final String[] _anArray) {
final Parser _parser;
MessageNode _expr;
ClassNode _cn;
st.gravel.support.jvm.Block3<ClassNode, ClassNode, MessageNode, Parser> _directive;
final int _start;
_cn = ClassNode.factory.name_namespacePath_(st.gravel.core.Symbol.value(_aName), st.gravel.support.jvm.ArrayExtensions.collect_(_anArray, ((st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>) (new st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>() {
@Override
public st.gravel.core.Symbol value_(final String _each) {
return (st.gravel.core.Symbol) st.gravel.core.Symbol.value(_each);
}
}))));
_parser = Parser.factory.source_sourceFile_(st.gravel.support.jvm.FilenameExtensions.contentsOfEntireFile(_aFilename), SourceFile.factory.directory_name_packageName_(_aFilename.getParent(), _aFilename.getName(), _packageName));
_start = _parser.position();
boolean _temp1 = false;
while (!_temp1) {
_temp1 = _parser.atEnd();
if (!_temp1) {
_expr = ((MessageNode) _parser.parseExpression());
_directive = DiskClassReader.this.directiveAt_(_expr.selector());
_cn = _directive.value_value_value_(_cn, _expr, _parser);
if (!_parser.atEnd()) {
_parser.parseBang();
}
}
}
return ((ClassNode) _parser.setSourcePosition_node_(_start, _cn));
}
use of st.gravel.support.compiler.ast.ClassNode in project gravel by gravel-st.
the class DiskClassWriter method write_.
public DiskClassWriter write_(final PackageNode _aPackageNode) {
final java.io.File[] _pkgRoot;
_pkgRoot = new java.io.File[1];
_pkgRoot[0] = new java.io.File(_root, _aPackageNode.name().asString());
_pkgRoot[0].mkdirs();
for (final ClassNode _cl : _aPackageNode.classes()) {
DiskClassWriter.this.writeClass_in_(_cl, _pkgRoot[0]);
}
for (final NamespaceNode _ns : _aPackageNode.namespaces()) {
DiskClassWriter.this.writeNamespace_in_(_ns, _pkgRoot[0]);
}
return this;
}
use of st.gravel.support.compiler.ast.ClassNode in project gravel by gravel-st.
the class PackageNodeMerger method load.
public SystemNode load() {
final Map<Reference, ClassNode>[] _classNodes;
final Map<Reference, ClassDescriptionNode>[] _classDescriptionNodes;
final Map<Reference, NamespaceNode>[] _namespaceNodes;
_classDescriptionNodes = new Map[1];
_classNodes = new Map[1];
_namespaceNodes = new Map[1];
_classNodes[0] = new java.util.HashMap<Reference, ClassNode>();
_namespaceNodes[0] = new java.util.HashMap<Reference, NamespaceNode>();
this.packageClassNodesDo_(new st.gravel.support.jvm.Block1<Object, ClassNode>() {
@Override
public Object value_(final ClassNode _classNode) {
if (!_classNode.isExtension()) {
final Reference _reference;
_reference = _classNode.reference();
if (_classNodes[0].containsKey(_reference)) {
throw new RuntimeException("Class " + _reference.toString() + " defined twice");
}
return _classNodes[0].put(_reference, _classNode);
}
return PackageNodeMerger.this;
}
});
this.packageClassNodesDo_(new st.gravel.support.jvm.Block1<Object, ClassNode>() {
@Override
public Object value_(final ClassNode _classNode) {
if (_classNode.isExtension()) {
final Reference _reference;
_reference = _classNode.reference();
if (!_classNodes[0].containsKey(_reference)) {
throw new RuntimeException("Can\'t extend Class " + _reference.toString() + "; not defined yet");
}
return _classNodes[0].put(_reference, _classNodes[0].get(_reference).mergedWithExtension_(_classNode));
}
return PackageNodeMerger.this;
}
});
_classDescriptionNodes[0] = new java.util.HashMap<Reference, ClassDescriptionNode>();
for (final ClassNode _classNode : _classNodes[0].values()) {
_classDescriptionNodes[0].put(_classNode.reference(), _classNode);
_classDescriptionNodes[0].put(_classNode.metaclassNode().reference(), _classNode.metaclassNode());
}
this.packageNamespaceNodesDo_(new st.gravel.support.jvm.Block1<Object, NamespaceNode>() {
@Override
public Object value_(final NamespaceNode _namespaceNode) {
final Reference _reference;
_reference = _namespaceNode.reference();
if (_namespaceNodes[0].containsKey(_reference)) {
return _namespaceNodes[0].put(_reference, _namespaceNode.mergeWith_(_namespaceNodes[0].get(_reference)));
} else {
return _namespaceNodes[0].put(_reference, _namespaceNode);
}
}
});
for (final Reference _ref : _classNodes[0].keySet()) {
final AbsoluteReference _namespace;
_namespace = _ref.namespace();
NamespaceNode _temp1 = _namespaceNodes[0].get(_namespace);
if (_temp1 == null) {
NamespaceNode _temp2 = NamespaceNode.factory.for_(_namespace);
_namespaceNodes[0].put(_namespace, _temp2);
_temp1 = _temp2;
}
}
return SystemNode.factory.classDescriptionNodes_namespaceNodes_(_classDescriptionNodes[0], _namespaceNodes[0]).flattenTraits();
}
use of st.gravel.support.compiler.ast.ClassNode in project gravel by gravel-st.
the class SystemMapping method newClassMappingForJavaClass_.
public ClassMapping newClassMappingForJavaClass_(final Class _receiverClass) {
final Map<st.gravel.core.Symbol, AbstractMethodMapping>[] _methodMappings;
final ClassNode _classNode;
final ClassMapping _superMapping;
final java.util.Set<st.gravel.core.Symbol>[] _allSelectors;
_allSelectors = new java.util.Set[1];
_methodMappings = new Map[1];
_superMapping = this.bestClassMappingFor_(_receiverClass);
_allSelectors[0] = _superMapping.allSelectorsIn_(this);
_methodMappings[0] = new java.util.HashMap<st.gravel.core.Symbol, AbstractMethodMapping>();
_compilerTools.methodNamesIn_do_(_receiverClass, new st.gravel.support.jvm.Block2<Object, String, Integer>() {
@Override
public Object value_value_(final String _methodName, final Integer _numArgs) {
final st.gravel.core.Symbol _sel;
_sel = _selectorConverter.functionNameAsSelector_(_methodName);
if (st.gravel.support.jvm.IntegerExtensions.equals_(_sel.numArgs(), _numArgs) && _allSelectors[0].contains(_sel)) {
final java.lang.invoke.MethodHandle _methodHandle;
_methodHandle = _compilerTools.methodHandleAt_numArgs_in_identityClass_isStatic_(_methodName, _sel.numArgs(), _receiverClass, _receiverClass, false);
if (_methodHandle != null) {
return _methodMappings[0].put(_sel, AnonymousMethodMapping.factory.methodHandle_definingClass_(_methodHandle, _receiverClass));
}
}
return SystemMapping.this;
}
});
_classNode = ClassNode.factory.name_superclassPath_properties_instVars_classInstVars_sharedVariables_methods_classMethods_namespace_isExtension_isTrait_traitUsage_classTraitUsage_(_superMapping.classNode().name(), _superMapping.reference().toString(), new java.util.HashMap<String, String>(), new VariableDeclarationNode[] {}, new VariableDeclarationNode[] {}, new SharedDeclarationNode[] {}, new MethodNode[] {}, new MethodNode[] {}, _superMapping.classNode().namespace(), false, false, EmptyTraitUsageNode.factory.basicNew(), EmptyTraitUsageNode.factory.basicNew());
return ClassMapping.factory.identityMapping_extensions_instVarMappings_classNode_(IdentityClassPartMapping.factory.javaClass_isGenerated_(_receiverClass, false).withMethodMappings_(_methodMappings[0]), new ExtensionClassPartMapping[] {}, new java.util.HashMap<String, InstVarMapping>(), _classNode);
}
Aggregations