use of st.gravel.support.compiler.ast.SharedDeclarationNode in project gravel by gravel-st.
the class DiskClassWriter method writeNamespace_in_.
public DiskClassWriter writeNamespace_in_(final NamespaceNode _aNamespaceNode, final java.io.File _aFilename) {
final java.io.File _nsFn;
final String _json;
final Map<String, Object> _dict;
final String[] _privateImports;
final String[] _publicImports;
final Map<String, String>[] _sharedVariables;
_sharedVariables = new Map[1];
_nsFn = ((java.io.File) st.gravel.support.jvm.ArrayExtensions.inject_into_(_aNamespaceNode.reference().path(), _aFilename, ((st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>) (new st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>() {
@Override
public java.io.File value_value_(final java.io.File _fn, final st.gravel.core.Symbol _each) {
return (java.io.File) new java.io.File(_fn, _each.asString());
}
}))));
_nsFn.mkdirs();
_dict = new java.util.HashMap<String, Object>();
_privateImports = st.gravel.support.jvm.ArrayExtensions.collect_(_aNamespaceNode.privateImports(), ((st.gravel.support.jvm.Block1<String, AbsoluteReference>) (new st.gravel.support.jvm.Block1<String, AbsoluteReference>() {
@Override
public String value_(final AbsoluteReference _each) {
return (String) _each.toString();
}
})));
_dict.put("privateImports", _privateImports);
_publicImports = st.gravel.support.jvm.ArrayExtensions.collect_(_aNamespaceNode.publicImports(), ((st.gravel.support.jvm.Block1<String, AbsoluteReference>) (new st.gravel.support.jvm.Block1<String, AbsoluteReference>() {
@Override
public String value_(final AbsoluteReference _each) {
return (String) _each.toString();
}
})));
_dict.put("publicImports", _publicImports);
_sharedVariables[0] = new java.util.HashMap<String, String>();
for (final SharedDeclarationNode _each : _aNamespaceNode.sharedVariables()) {
_sharedVariables[0].put(_each.name(), _each.initializer() == null ? null : _each.initializer().sourceString());
}
_dict.put("sharedVariables", _sharedVariables[0]);
_json = st.gravel.support.jvm.DictionaryExtensions.asJSON(_dict);
st.gravel.support.jvm.StringExtensions.writeToFile_(_json, new java.io.File(_nsFn, "properties.json"));
return this;
}
use of st.gravel.support.compiler.ast.SharedDeclarationNode in project gravel by gravel-st.
the class DiskClassReader method readNamespace_namespace_.
public NamespaceNode readNamespace_namespace_(final java.io.File _aFilename, final String[] _namespaceStrings) {
final Map<String, Object> _dict;
final AbsoluteReference[] _publicImports;
final AbsoluteReference[] _privateImports;
final Object[] _publicImportStrings;
final Object[] _privateImportStrings;
final Map<String, String> _sharedVariableStrings;
final List<SharedDeclarationNode>[] _sharedVariables;
_sharedVariables = new List[1];
_dict = this.readPropertiesFile_(_aFilename);
Object _temp1 = _dict.get("publicImports");
if (_temp1 == null) {
_temp1 = new Object[] {};
}
_publicImportStrings = ((Object[]) _temp1);
Object _temp2 = _dict.get("privateImports");
if (_temp2 == null) {
_temp2 = new Object[] {};
}
_privateImportStrings = ((Object[]) _temp2);
Object _temp3 = _dict.get("sharedVariables");
if (_temp3 == null) {
_temp3 = new java.util.HashMap<String, String>();
}
_sharedVariableStrings = ((Map<String, String>) _temp3);
_publicImports = st.gravel.support.jvm.ArrayExtensions.collect_(_publicImportStrings, ((st.gravel.support.jvm.Block1<AbsoluteReference, Object>) (new st.gravel.support.jvm.Block1<AbsoluteReference, Object>() {
@Override
public AbsoluteReference value_(final Object _obj) {
final String _str;
_str = ((String) _obj);
return (AbsoluteReference) Reference.factory.value_(_str);
}
})));
_privateImports = st.gravel.support.jvm.ArrayExtensions.collect_(_privateImportStrings, ((st.gravel.support.jvm.Block1<AbsoluteReference, Object>) (new st.gravel.support.jvm.Block1<AbsoluteReference, Object>() {
@Override
public AbsoluteReference value_(final Object _obj) {
final String _str;
_str = ((String) _obj);
return (AbsoluteReference) Reference.factory.value_(_str);
}
})));
_sharedVariables[0] = new java.util.ArrayList();
for (final Map.Entry<String, String> _temp4 : _sharedVariableStrings.entrySet()) {
String _name = _temp4.getKey();
String _initializerString = _temp4.getValue();
_sharedVariables[0].add(SharedDeclarationNode.factory.name_initializer_(_name, DiskClassReader.this.parseInitializerSource_(_initializerString)));
}
return NamespaceNode.factory.reference_publicImports_privateImports_sharedVariables_(AbsoluteReference.factory.path_(st.gravel.support.jvm.ArrayExtensions.collect_(_namespaceStrings, ((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);
}
})))), _publicImports, _privateImports, _sharedVariables[0].toArray(new SharedDeclarationNode[_sharedVariables[0].size()]));
}
use of st.gravel.support.compiler.ast.SharedDeclarationNode 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);
}
use of st.gravel.support.compiler.ast.SharedDeclarationNode in project gravel by gravel-st.
the class SystemMapping method namespaceGlobalsAndInitializersDo_.
public SystemMapping namespaceGlobalsAndInitializersDo_(final st.gravel.support.jvm.Block2<Object, AbsoluteReference, SharedDeclarationNode> _aBlock) {
for (final Map.Entry<Reference, NamespaceNode> _temp1 : _systemNode.namespaceNodes().entrySet()) {
Reference _reference = _temp1.getKey();
NamespaceNode _namespaceNode = _temp1.getValue();
for (final SharedDeclarationNode _sharedVariable : _namespaceNode.sharedVariables()) {
_aBlock.value_value_(((AbsoluteReference) _reference).$slash$(st.gravel.core.Symbol.value(_sharedVariable.name())), _sharedVariable);
}
}
return this;
}
use of st.gravel.support.compiler.ast.SharedDeclarationNode in project gravel by gravel-st.
the class SystemMappingUpdater method initializeClassShareds_.
public SystemMappingUpdater initializeClassShareds_(final MetaclassNode _aMetaclassNode) {
for (final SharedDeclarationNode _sharedVariable : _aMetaclassNode.sharedVariables()) {
final AbsoluteReference _reference;
_reference = _aMetaclassNode.reference().nonmeta().$slash$(st.gravel.core.Symbol.value(_sharedVariable.name()));
_systemMapping.singletonAtReference_initialize_(_reference, _sharedVariable);
}
return this;
}
Aggregations