1 module d.object; 2 3 import d.ir.symbol; 4 5 import source.location; 6 import source.name; 7 8 final class ObjectReference { 9 private Module object; 10 11 this(Module object) { 12 this.object = object; 13 } 14 15 auto getSizeT() { 16 return cast(TypeAlias) object.resolve( 17 Location.init, 18 BuiltinName!"size_t", 19 ); 20 } 21 22 private auto getClass(Name name) { 23 return cast(Class) object.resolve(Location.init, name); 24 } 25 26 auto getObject() { 27 return getClass(BuiltinName!"Object"); 28 } 29 30 auto getTypeInfo() { 31 return getClass(BuiltinName!"TypeInfo"); 32 } 33 34 auto getClassInfo() { 35 return getClass(BuiltinName!"ClassInfo"); 36 } 37 38 auto getThrowable() { 39 return getClass(BuiltinName!"Throwable"); 40 } 41 42 auto getException() { 43 return getClass(BuiltinName!"Exception"); 44 } 45 46 auto getError() { 47 return getClass(BuiltinName!"Error"); 48 } 49 50 private auto getFunction(Name name) { 51 auto s = object.resolve(Location.init, name); 52 if (auto f = cast(Function) s) { 53 return f; 54 } 55 56 auto os = cast(OverloadSet) s; 57 assert(os.set.length == 1); 58 return cast(Function) os.set[0]; 59 } 60 61 auto getClassDowncast() { 62 return getFunction(BuiltinName!"__sd_class_downcast"); 63 } 64 65 auto getThrow() { 66 return getFunction(BuiltinName!"__sd_eh_throw"); 67 } 68 69 auto getPersonality() { 70 return getFunction(BuiltinName!"__sd_eh_personality"); 71 } 72 73 auto getArrayOutOfBounds() { 74 return getFunction(BuiltinName!"__sd_array_outofbounds"); 75 } 76 77 auto getAssertFail() { 78 return getFunction(BuiltinName!"__sd_assert_fail"); 79 } 80 81 auto getAssertFailMsg() { 82 return getFunction(BuiltinName!"__sd_assert_fail_msg"); 83 } 84 85 auto getArrayConcat() { 86 return cast(OverloadSet) object.resolve( 87 Location.init, 88 BuiltinName!"__sd_array_concat", 89 ); 90 } 91 92 auto getGCThreadLocalAllow() { 93 return getFunction(BuiltinName!"__sd_gc_tl_malloc"); 94 } 95 } 96