use of st.gravel.support.compiler.ast.Reference 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.Reference 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.Reference in project gravel by gravel-st.
the class SystemNode method classNodes.
public Map<Reference, ClassNode> classNodes() {
final Map<Reference, ClassNode>[] _dict;
_dict = new Map[1];
_dict[0] = new java.util.HashMap<Reference, ClassNode>();
for (final ClassDescriptionNode _each : _classDescriptionNodes.values()) {
if (_each.isClassNode()) {
final ClassNode _cn;
_cn = ((ClassNode) _each);
_dict[0].put(_each.reference(), _cn);
}
}
return _dict[0];
}
use of st.gravel.support.compiler.ast.Reference in project gravel by gravel-st.
the class SystemNode method diffTo_.
public SystemDiff diffTo_(final SystemNode _aSystemNode) {
final List<ClassDiff>[] _unordered;
final SystemNode[] _start;
final List<ClassDiff>[] _classDiffs;
_unordered = new List[1];
_start = new SystemNode[1];
_classDiffs = new List[1];
_unordered[0] = new java.util.ArrayList();
st.gravel.support.jvm.DictionaryExtensions.syncWith(this.classNodes(), _aSystemNode.classNodes(), new st.gravel.support.jvm.Block2<Object, ClassNode, ClassNode>() {
@Override
public Object value_value_(final ClassNode _old, final ClassNode _new) {
final UpdateClassDiff _diff;
_diff = _old.diffTo_(_new);
if (!_diff.isEmpty()) {
return _unordered[0].add(_diff);
}
return SystemNode.this;
}
}, new st.gravel.support.jvm.Block1<Object, ClassNode>() {
@Override
public Object value_(final ClassNode _classNode) {
return _unordered[0].add(_classNode.javaClassPath() == null ? AddClassDiff.factory.classNode_(_classNode) : WrapJavaclassDiff.factory.classNode_(_classNode));
}
}, new st.gravel.support.jvm.Block1<Object, ClassNode>() {
@Override
public Object value_(final ClassNode _classNode) {
return _unordered[0].add(RemoveClassDiff.factory.classNode_(_classNode));
}
});
_start[0] = this;
_classDiffs[0] = new java.util.ArrayList();
boolean _temp1 = false;
while (!_temp1) {
_temp1 = _unordered[0].size() == 0;
if (!_temp1) {
final List<ClassDiff> _todo;
_todo = st.gravel.support.jvm.OrderedCollectionExtensions.select_(_unordered[0], new st.gravel.support.jvm.Predicate1<ClassDiff>() {
@Override
public boolean value_(final ClassDiff _elem) {
final Reference _superclassReference;
_superclassReference = _elem.superclassReference();
return (_superclassReference == null) || _start[0].includesReference_(_superclassReference);
}
});
if (_todo.size() == 0) {
throw new RuntimeException("Prerequisite error; trying to load classes with unknown superclass");
}
_unordered[0].removeAll(_todo);
for (final ClassDiff _each : _todo) {
if (_each.isNewClassDiff()) {
_start[0] = _start[0].withClassDescriptionNode_(((NewClassDiff) _each).classNode());
if (_each.isStatic()) {
Reference _nextRef;
_nextRef = _each.superclassReference();
boolean _temp2 = false;
while (!_temp2) {
_temp2 = _nextRef == null;
if (!_temp2) {
final ClassDiff _superNode;
final Reference _ref;
_ref = _nextRef;
_superNode = ((ClassDiff) st.gravel.support.jvm.OrderedCollectionExtensions.detect_ifNone_(_classDiffs[0], new st.gravel.support.jvm.Predicate1<ClassDiff>() {
@Override
public boolean value_(final ClassDiff _cd) {
return st.gravel.support.jvm.ObjectExtensions.equals_(_cd.reference(), _ref);
}
}, ((st.gravel.support.jvm.Block0<ClassDiff>) (new st.gravel.support.jvm.Block0<ClassDiff>() {
@Override
public ClassDiff value() {
throw new RuntimeException("Prereq not found");
}
}))));
_nextRef = _superNode.isStatic() ? null : _superNode.superclassReference();
_superNode.beStatic();
}
}
}
}
_classDiffs[0].add(_each);
}
}
}
return SystemDiff.factory.classDiffs_namespaces_(_classDiffs[0].toArray(new ClassDiff[_classDiffs[0].size()]), _aSystemNode.namespaceNodes());
}
use of st.gravel.support.compiler.ast.Reference in project gravel by gravel-st.
the class MetaclassNode method superclassReference.
@Override
public Reference superclassReference() {
final Reference _csr;
_csr = _classNode.superclassReference();
if (_csr == null) {
return null;
}
return ClassReference.factory.reference_(((AbsoluteReference) _csr));
}
Aggregations