Search in sources :

Example 1 with ClassDescriptionNode

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

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

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

the class UpdateClassDescriptorDiff method applyOnClassNode_.

public ClassDescriptionNode applyOnClassNode_(final ClassDescriptionNode _startClassNode) {
    ClassDescriptionNode _classNode;
    _classNode = ((ClassDescriptionNode) st.gravel.support.jvm.ArrayExtensions.inject_into_(_methodNodes, _startClassNode, ((st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>) (new st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>() {

        @Override
        public ClassDescriptionNode value_value_(final ClassDescriptionNode _cn, final MethodNode _m) {
            return (ClassDescriptionNode) _cn.withMethodNode_(_m);
        }
    }))));
    _classNode = ((ClassDescriptionNode) st.gravel.support.jvm.ArrayExtensions.inject_into_(_updatedMethodNodes, _classNode, ((st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>) (new st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>() {

        @Override
        public ClassDescriptionNode value_value_(final ClassDescriptionNode _cn, final MethodNode _m) {
            return (ClassDescriptionNode) _cn.copyReplaceMethodNode_(_m);
        }
    }))));
    return ((ClassDescriptionNode) st.gravel.support.jvm.ArrayExtensions.inject_into_(_deletedSelectors, _classNode, ((st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, String>) (new st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, String>() {

        @Override
        public ClassDescriptionNode value_value_(final ClassDescriptionNode _cn, final String _sel) {
            return (ClassDescriptionNode) _cn.copyRemoveSelector_(_sel);
        }
    }))));
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 4 with ClassDescriptionNode

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

the class SimpleTraitUsageNode method allMethodsIn_do_.

@Override
public SimpleTraitUsageNode allMethodsIn_do_(final SystemNode _aSystemNode, final st.gravel.support.jvm.Block1<Object, MethodNode> _aBlock) {
    final ClassDescriptionNode _trait;
    _trait = _aSystemNode.classNodeAt_(_reference);
    _trait.allMethodsIn_do_(_aSystemNode, _aBlock);
    return this;
}
Also used : ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 5 with ClassDescriptionNode

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

the class JVMClassCompiler method compileClassNode.

public JVMClass compileClassNode() {
    final MethodNode[] _allMethods;
    Reference _superclassReference;
    BoundVariableDeclarationNode[] _allInstVars;
    final MethodNode[] _localLinkedMethods;
    ClassDescriptionNode _scn;
    if (_ownerType == null) {
        _ownerType = ((JVMDefinedObjectType) _selfType);
    }
    _allMethods = _classDescriptionNode.methods();
    _superclassReference = _classDescriptionNode.superclassReference();
    _allInstVars = _classDescriptionNode.boundInstVars();
    boolean _temp1 = false;
    while (!_temp1) {
        _temp1 = _superclassReference == null;
        if (!_temp1) {
            _scn = _systemNode.classNodeAt_(_superclassReference);
            _superclassReference = _scn.superclassReference();
            _allInstVars = st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_scn.boundInstVars(), _allInstVars);
        }
    }
    _localLinkedMethods = _systemMappingUpdater.localLinkMethods_instVars_ownerReference_(_allMethods, _allInstVars, _classDescriptionNode.reference());
    for (final MethodNode _each : _localLinkedMethods) {
        JVMClassCompiler.this.compileMethod_(_each);
    }
    for (final VariableDeclarationNode _each : _classDescriptionNode.instVars()) {
        _fields.add(JVMField.factory.ownerType_varName_type_isStatic_(_ownerType, _each.name(), TypeNodeToJVMTypeConverter.factory.namespace_(JVMClassCompiler.this.namespace()).visit_(_each.type()), false));
    }
    this.compileBlocks();
    return this.createContainerClass();
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) BoundVariableDeclarationNode(st.gravel.support.compiler.ast.BoundVariableDeclarationNode) Reference(st.gravel.support.compiler.ast.Reference) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) BoundVariableDeclarationNode(st.gravel.support.compiler.ast.BoundVariableDeclarationNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Aggregations

ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)14 MethodNode (st.gravel.support.compiler.ast.MethodNode)10 HashMap (java.util.HashMap)6 ExtensionClassPartMapping (st.gravel.support.compiler.ast.ExtensionClassPartMapping)4 UnaryMethodNode (st.gravel.support.compiler.ast.UnaryMethodNode)4 Map (java.util.Map)3 ClassNode (st.gravel.support.compiler.ast.ClassNode)3 IdentityClassPartMapping (st.gravel.support.compiler.ast.IdentityClassPartMapping)3 Reference (st.gravel.support.compiler.ast.Reference)3 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)2 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)2 JVMClass (st.gravel.support.compiler.jvm.JVMClass)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Symbol (st.gravel.core.Symbol)1 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)1 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)1 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)1 PackageNode (st.gravel.support.compiler.ast.PackageNode)1 SimpleTraitUsageNode (st.gravel.support.compiler.ast.SimpleTraitUsageNode)1