Search in sources :

Example 6 with ClassNode

use of st.gravel.support.compiler.ast.ClassNode 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 7 with ClassNode

use of st.gravel.support.compiler.ast.ClassNode 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)

Example 8 with ClassNode

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

the class SystemDefinitionNode method classNodeAt_ifAbsent_.

public ClassNode classNodeAt_ifAbsent_(final Reference _reference, final st.gravel.support.jvm.Block0<ClassNode> _aBlock) {
    final ClassNode[] _cn;
    _cn = new ClassNode[1];
    for (final PackageNode _each : _packageNodes) {
        _cn[0] = _each.classNodeAt_ifAbsent_(_reference, ((st.gravel.support.jvm.Block0<ClassNode>) (new st.gravel.support.jvm.Block0<ClassNode>() {

            @Override
            public ClassNode value() {
                return (ClassNode) null;
            }
        })));
        if (_cn[0] != null) {
            return _cn[0];
        }
    }
    return _aBlock.value();
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) PackageNode(st.gravel.support.compiler.ast.PackageNode)

Example 9 with ClassNode

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

the class ClassDescriptionMirror method compile_classified_.

public Object compile_classified_(String source, String protocol) {
    final MethodNode method = Parser.factory.parseMethod_(source).withProtocol_(protocol);
    ClassDescriptionNode currentClassNode = definitionClassNode();
    final MethodNode current = currentClassNode.methodOrNilAt_(method.selector());
    Symbol targetPackageName = current == null ? definitionClassNode().packageName() : current.packageName();
    if (targetPackageName == null) {
        targetPackageName = definitionClassNode().packageName();
        if (targetPackageName == null) {
            targetPackageName = current.packageName();
        }
    }
    SystemDefinitionNode newSystem = ImageBootstrapper.systemMapping.systemDefinitionNode().copyUpdatePackage_do_(targetPackageName, new Block1<PackageNode, PackageNode>() {

        @Override
        public PackageNode value_(PackageNode packageNode) {
            return packageNode.copyUpdateClassNode_do_(definitionClassNode().reference(), new Block1<ClassNode, ClassNode>() {

                @Override
                public ClassNode value_(ClassNode classNode) {
                    return current == null ? classNode.withMethodNode_(method) : classNode.copyReplaceMethodNode_(method);
                }
            });
        }
    });
    ImageBootstrapper.systemMapping.updateTo_(newSystem);
    return getMethodMirror(Symbol.value(method.selector()));
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) Symbol(st.gravel.core.Symbol) SystemDefinitionNode(st.gravel.support.compiler.ast.SystemDefinitionNode) PackageNode(st.gravel.support.compiler.ast.PackageNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 10 with ClassNode

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

the class DiskClassWriter method writeClass_in_.

public DiskClassWriter writeClass_in_(final ClassNode _aClassNode, final java.io.File _aFilename) {
    final java.io.File _nsFn;
    final java.io.File _clFn;
    final StringBuilder[] _str;
    final VariableNode[] _reader;
    _reader = new VariableNode[1];
    _str = new StringBuilder[1];
    _nsFn = ((java.io.File) st.gravel.support.jvm.ArrayExtensions.inject_into_(_aClassNode.reference().namespace().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();
    _clFn = new java.io.File(_nsFn, _aClassNode.reference().name().asString() + ".st");
    _str[0] = st.gravel.support.jvm.WriteStreamFactory.on_(new String());
    _reader[0] = VariableNode.factory.name_("reader");
    if (_aClassNode.isExtension()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_(_aClassNode.isTrait() ? "extendTrait:" : "extendClass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString())), _str[0]);
    } else {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_(_aClassNode.isTrait() ? "defineTrait:superclass:" : "defineClass:superclass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString()), DiskClassWriter.this.referenceAsLiteralNode_(_aClassNode.superclassReference())), _str[0]);
        for (final SharedDeclarationNode _sv : _aClassNode.metaclassNode().sharedVariables()) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("defineSharedVariable:init:", DiskClassWriter.this.asLiteralNode_(_sv.name()), DiskClassWriter.this.initializerSource_(_sv.initializer())), _str[0]);
        }
    }
    for (final Node _each : TraitUsageToDirectiveConverter.factory.visit_(_aClassNode.traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final Node _each : ClassTraitUsageToDirectiveConverter.factory.visit_(_aClassNode.metaclassNode().traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final VariableDeclarationNode _each : _aClassNode.instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final VariableDeclarationNode _each : _aClassNode.metaclassNode().instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addClassInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final Map.Entry<String, String> _temp1 : _aClassNode.properties().entrySet()) {
        String _k = _temp1.getKey();
        String _v = _temp1.getValue();
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("propertyAt:put:", DiskClassWriter.this.asLiteralNode_(_k), DiskClassWriter.this.asLiteralNode_(_v)), _str[0]);
    }
    for (final MethodNode _each : _aClassNode.methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    for (final MethodNode _each : _aClassNode.metaclassNode().methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    st.gravel.support.jvm.StringExtensions.writeToFile_(_str[0].toString(), _clFn);
    return this;
}
Also used : VariableNode(st.gravel.support.compiler.ast.VariableNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Node(st.gravel.support.compiler.ast.Node) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) ClassNode(st.gravel.support.compiler.ast.ClassNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) PackageNode(st.gravel.support.compiler.ast.PackageNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) VariableNode(st.gravel.support.compiler.ast.VariableNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClassNode (st.gravel.support.compiler.ast.ClassNode)10 HashMap (java.util.HashMap)5 Map (java.util.Map)4 MethodNode (st.gravel.support.compiler.ast.MethodNode)4 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)3 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)3 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)3 PackageNode (st.gravel.support.compiler.ast.PackageNode)3 Reference (st.gravel.support.compiler.ast.Reference)3 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Symbol (st.gravel.core.Symbol)2 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)2 SystemDefinitionNode (st.gravel.support.compiler.ast.SystemDefinitionNode)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)1 AbstractMethodMapping (st.gravel.support.compiler.ast.AbstractMethodMapping)1