Skip to content

Commit daf5cb2

Browse files
committed
typeinfo - access and such
1 parent 0ef792f commit daf5cb2

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/builtin/module_builtin_rtti.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ namespace das {
645645
TypeInfoAnnotation(ModuleLibrary & ml) : ManagedTypeInfoAnnotation ("TypeInfo", ml) {
646646
addField<DAS_BIND_MANAGED_FIELD(type)>("_type","type");
647647
addField<DAS_BIND_MANAGED_FIELD(dim)>("dim");
648-
addField<DAS_BIND_MANAGED_FIELD(annotation_or_name)>("annotation_or_name");
648+
// addField<DAS_BIND_MANAGED_FIELD(annotation_or_name)>("annotation_or_name");
649+
addProperty<DAS_BIND_MANAGED_PROP(getAnnotation)>("annotation_or_name", "getAnnotation");
649650
}
650651
};
651652

src/builtin/rtti.das

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ def public class_info(cl) : StructInfo const? {
145145
}
146146
}
147147

148+
def public type_info(cl) : TypeInfo const? {
149+
static_if (typeinfo is_pointer(cl)) {
150+
if (cl == null) {
151+
return null
152+
}
153+
static_if (typeinfo is_class(*cl)) {
154+
unsafe {
155+
return (reinterpret<TypeInfo const?>((*cl).__rtti))
156+
}
157+
} else {
158+
concept_assert(false, "not a pointer to a class")
159+
return null
160+
}
161+
} static_elif (typeinfo is_class(cl)) {
162+
unsafe {
163+
return reinterpret<TypeInfo const?>(cl.__rtti)
164+
}
165+
} static_elif (typeinfo is_lambda(cl)) {
166+
unsafe {
167+
var l = reinterpret<int8 ??> addr(cl)
168+
if (l == null) {
169+
return null
170+
}
171+
return reinterpret<TypeInfo const ??>(l[0] - 16)
172+
}
173+
} else {
174+
concept_assert(false, "this type does not have class info. its not a class or a lambda with options rtti")
175+
return null
176+
}
177+
}
178+
148179
[generic]
149180
def type_info(vinfo : LocalVariableInfo) : TypeInfo const? {
150181
unsafe {

0 commit comments

Comments
 (0)