use of st.gravel.support.compiler.ast.AbstractClassMapping in project gravel by gravel-st.
the class ObjectExtensions method inheritsFrom_.
public static boolean inheritsFrom_(ObjectClass receiver, Object arg) {
ClassMapping cm = ImageBootstrapper.systemMapping.classMappingForJavaClass_(receiver.getClass());
ClassMapping other = ImageBootstrapper.systemMapping.classMappingForJavaClass_(arg.getClass());
AbstractClassMapping sm = cm;
while (sm != null) {
sm = sm.superclassMappingIn_(ImageBootstrapper.systemMapping);
if (sm == other)
return true;
}
return false;
}
use of st.gravel.support.compiler.ast.AbstractClassMapping in project gravel by gravel-st.
the class ImageBootstrapperTest method testLookupClass.
@Test
public void testLookupClass() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
ImageBootstrapper.bootstrap();
systemMapping = ImageBootstrapper.systemMapping;
Reference ref = Reference.factory.value_("st.gravel.lang.Message class");
AbstractClassMapping meta = systemMapping.classMappingAtReference_(ref);
Object cl = systemMapping.singletonAtReference_(ref.nonmeta());
Method basicNew = cl.getClass().getMethod("basicNew");
Object instance = basicNew.invoke(cl);
Method r_class = instance.getClass().getMethod("r_class");
Object instanceClass = r_class.invoke(instance);
assertEquals(meta.identityClass(), instanceClass.getClass());
}
use of st.gravel.support.compiler.ast.AbstractClassMapping in project gravel by gravel-st.
the class SystemMapping method subclassMappingsFor_do_.
public SystemMapping subclassMappingsFor_do_(final Reference _aReference, final st.gravel.support.jvm.Block1<Object, AbstractClassMapping> _aBlock) {
final java.util.Set<AbstractClassMapping> _c;
if (_subclassMappingsCache == null) {
SystemMapping.this.buildSubclassMappingsCache();
}
java.util.Set<AbstractClassMapping> _temp1 = _subclassMappingsCache.get(_aReference);
_c = ((java.util.Set<AbstractClassMapping>) _temp1);
if (_c == null) {
return null;
}
for (final AbstractClassMapping _temp2 : _c) {
_aBlock.value_(_temp2);
}
return this;
}
use of st.gravel.support.compiler.ast.AbstractClassMapping in project gravel by gravel-st.
the class SystemMappingUpdater method link.
public SystemMappingUpdater link() {
_systemMapping.classMappingsDo_(new st.gravel.support.jvm.Block1<Object, AbstractClassMapping>() {
@Override
public Object value_(final AbstractClassMapping _acm) {
if (_acm.classNode().isMeta()) {
SystemMappingUpdater.this.initializeClassShareds_(((MetaclassNode) _acm.classNode()));
return _systemMapping.singletonAtReference_ifAbsentPut_(_acm.reference().nonmeta(), new st.gravel.support.jvm.Block0<Object>() {
@Override
public Object value() {
return _compilerTools.createSingletonForClass_(_acm.identityClass());
}
});
}
return SystemMappingUpdater.this;
}
});
_compilerTools.resetCallsites();
_systemMapping.namespaceGlobalsAndInitializersDo_(new st.gravel.support.jvm.Block2<Object, AbsoluteReference, SharedDeclarationNode>() {
@Override
public Object value_value_(final AbsoluteReference _reference, final SharedDeclarationNode _sharedVariable) {
return _systemMapping.singletonAtReference_initialize_(_reference, _sharedVariable);
}
});
for (final Reference _ref : _toInitialize) {
_compilerTools.initializeClass_systemMapping_(((ClassMapping) _systemMapping.classMappingAtReference_(_ref)), _systemMapping);
}
_toInitialize = new java.util.ArrayList();
return this;
}
use of st.gravel.support.compiler.ast.AbstractClassMapping in project gravel by gravel-st.
the class SystemMapping method buildSubclassMappingsCache.
public SystemMapping buildSubclassMappingsCache() {
_subclassMappingsCache = new java.util.HashMap<Reference, java.util.Set<AbstractClassMapping>>();
for (final AbstractClassMapping _each : _classMappingsByReference.values()) {
final Reference _scr;
_scr = _each.superclassReference();
if (_scr != null) {
java.util.Set<AbstractClassMapping> _temp1 = _subclassMappingsCache.get(_scr);
if (_temp1 == null) {
java.util.Set<AbstractClassMapping> _temp2 = new java.util.HashSet();
_subclassMappingsCache.put(_scr, _temp2);
_temp1 = _temp2;
}
_temp1.add(_each);
}
}
return this;
}
Aggregations