use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.
the class CompositeTraitUsageNode method flattenClassDescriptionNode_in_.
@Override
public ClassDescriptionNode flattenClassDescriptionNode_in_(final ClassDescriptionNode _aClassDescriptionNode, final SystemNode _aSystemNode) {
final ClassDescriptionNode[] _n;
final Map<String, MethodNode>[] _definitionInOtherTraits;
final List<MethodNode>[] _requirements;
_n = new ClassDescriptionNode[1];
_definitionInOtherTraits = new Map[1];
_requirements = new List[1];
_n[0] = _aClassDescriptionNode;
_definitionInOtherTraits[0] = new java.util.HashMap<String, MethodNode>();
_requirements[0] = new java.util.ArrayList();
for (final SimpleTraitUsageNode _component : _components) {
_component.allMethodsIn_do_(_aSystemNode, new st.gravel.support.jvm.Block1<Object, MethodNode>() {
@Override
public Object value_(final MethodNode _method) {
final boolean _canUnderstand;
final String _selector;
_selector = _method.selector();
_canUnderstand = _aClassDescriptionNode.canUnderstand_in_(_selector, _aSystemNode);
if (_method.isTraitRequirement()) {
if (!_canUnderstand) {
return _requirements[0].add(_method.ofTrait_(_component.reference()));
}
} else {
if (!_aClassDescriptionNode.includesSelector_(_selector)) {
final MethodNode _other;
MethodNode _temp1 = _definitionInOtherTraits[0].get(_selector);
_other = ((MethodNode) _temp1);
if (_other != null) {
if (CompositeTraitUsageNode.this.conflicts_with_(_other, _method)) {
_n[0] = _n[0].copyReplaceMethodNode_(_method.withBody_(SequenceNode.factory.statement_(GlobalReadNode.factory.namespace_name_(AbsoluteReference.factory.object(), "TraitConflict").send_with_("raiseSignal:", StringLiteralNode.factory.value_(CompositeTraitUsageNode.this.traitConflictStringFor_in_(_selector, _aSystemNode))))));
}
} else {
_n[0] = _n[0].withMethodNode_ofTrait_(_method, _component.reference());
}
}
return _definitionInOtherTraits[0].put(_method.selector(), _method);
}
return CompositeTraitUsageNode.this;
}
});
}
for (final MethodNode _method : _requirements[0]) {
if (!(_definitionInOtherTraits[0].containsKey(_method.selector()) || _n[0].includesSelector_(_method.selector()))) {
_n[0] = _n[0].withMethodNode_(CompositeTraitUsageNode.this.newTraitRequirementNotDefinedFor_(_method));
}
}
return _n[0];
}
use of st.gravel.support.compiler.ast.MethodNode 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();
}
use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.
the class LiteralBlockSendCallSite method findMethod.
@Override
protected MethodHandle findMethod(Class receiverClass) {
MethodMapping methodMapping = ImageBootstrapper.systemMapping.methodMappingFor_methodName_(receiverClass, selector);
if (methodMapping == null) {
return createDNUHandle(receiverClass).asType(type);
}
MethodNode methodNode = methodMapping.methodNode();
return inlineBlocks(methodNode, ImageBootstrapper.systemMapping.classMappingForJavaClass_(receiverClass).reference(), (JVMNonPrimitiveType) ImageBootstrapper.systemMapping.compilerTools().jvmTypeForClass_(receiverClass));
}
use of st.gravel.support.compiler.ast.MethodNode 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.MethodNode in project gravel by gravel-st.
the class SystemMappingUpdater method linkMethods_in_identityClass_to_isStatic_.
public ClassPartMapping linkMethods_in_identityClass_to_isStatic_(final MethodNode[] _methods, final Class _javaClass, final Class _identityClass, final ClassPartMapping _cpm, final boolean _isStatic) {
final ClassPartMapping[] _ecm;
_ecm = new ClassPartMapping[1];
_ecm[0] = _cpm;
for (final MethodNode _m : _methods) {
final String _fn;
final java.lang.invoke.MethodHandle _methodHandle;
final st.gravel.core.Symbol _selector;
_selector = st.gravel.core.Symbol.value(_m.selector());
_fn = _selectorConverter.selectorAsFunctionName_(_selector);
_methodHandle = _compilerTools.methodHandleAt_numArgs_in_identityClass_isStatic_(_fn, _selector.numArgs(), _javaClass, _identityClass, _isStatic);
_ecm[0] = _ecm[0].withMethodMapping_(((MethodMapping) MethodMapping.factory.methodNode_methodHandle_definingClass_(_m, _methodHandle, _javaClass)));
}
return _ecm[0];
}
Aggregations