Search in sources :

Example 1 with Reference

use of st.gravel.support.compiler.ast.Reference in project gravel by gravel-st.

the class ClassDescriptionNode method superclassNodeIn_.

public ClassDescriptionNode superclassNodeIn_(final SystemNode _aSystemNode) {
    final Reference _scr;
    _scr = this.superclassReference();
    if (_scr == null) {
        return null;
    }
    return _aSystemNode.classNodeAt_(_scr);
}
Also used : Reference(st.gravel.support.compiler.ast.Reference)

Example 2 with Reference

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();
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Reference

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;
}
Also used : Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Reference

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];
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) HashMap(java.util.HashMap) Map(java.util.Map) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 5 with Reference

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());
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) ArrayList(java.util.ArrayList) List(java.util.List) UpdateClassDiff(st.gravel.support.compiler.ast.UpdateClassDiff) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) NewClassDiff(st.gravel.support.compiler.ast.NewClassDiff) RemoveClassDiff(st.gravel.support.compiler.ast.RemoveClassDiff) UpdateClassDiff(st.gravel.support.compiler.ast.UpdateClassDiff) ClassDiff(st.gravel.support.compiler.ast.ClassDiff) AddClassDiff(st.gravel.support.compiler.ast.AddClassDiff) NewClassDiff(st.gravel.support.compiler.ast.NewClassDiff) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Reference (st.gravel.support.compiler.ast.Reference)17 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)11 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)3 ClassNode (st.gravel.support.compiler.ast.ClassNode)3 MethodHandle (java.lang.invoke.MethodHandle)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 AbstractMethodMapping (st.gravel.support.compiler.ast.AbstractMethodMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 ClassReference (st.gravel.support.compiler.ast.ClassReference)2 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)2 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)2 JVMDefinedObjectType (st.gravel.support.compiler.jvm.JVMDefinedObjectType)2 ConstantCallSite (java.lang.invoke.ConstantCallSite)1 Constructor (java.lang.reflect.Constructor)1 HashSet (java.util.HashSet)1