Scoop API

scoop:scoop.core:0.1.0

src/type_info.scoop

Selected production source · src/type_info.scoop

1/**
2 * Obtains compiler-provided metadata for the concrete type T. It describes types and declarations;
3 * it does not enable arbitrary dynamic invocation.
4 */
5public fun <T> typeInfo(): TypeInfo<T> = TypeInfo<T>(__scoopTypeReference<T>())
7internal fun <T> __scoopTypeReference(): TypeRef {
8 val data = coreTypeReference<T>()
9 return TypeRef(data.identity, data.displayName, data.nominal, data.arguments, {
10 coreTypeDescription<T>()
11 })
14internal struct TypeReferenceData(
15 val identity: String,
16 val displayName: String,
17 val nominal: Option<NominalRef>,
18 val arguments: Array<TypeRef>
21@Intrinsic("type_reference")
22internal fun <T> coreTypeReference(): TypeReferenceData
24@Intrinsic("type_description")
25internal fun <T> coreTypeDescription(): TypeDescription
27/**
28 * A typed entry point into concrete type metadata.
29 */
30public struct TypeInfo<T>(val type: TypeRef) {
31 /**
32 * Returns the declaration and shape metadata of the represented type.
33 */
34 public fun describe(): TypeDescription = type.describe()
37/**
38 * A concrete type identity with a display name and lazily available description. Identity
39 * comparison is independent of display spelling.
40 */
41public class TypeRef public constructor(
42 private val identity: String,
43 /**
44 * Human-readable type spelling; do not use it as an identity key.
45 */
46 public val displayName: String,
47 /**
48 * The declaring nominal identity when the type has one.
49 */
50 public val nominal: Option<NominalRef>,
51 /**
52 * The concrete generic argument types, in declaration order.
53 */
54 public val arguments: Array<TypeRef>,
55 private val describeBody: () -> TypeDescription
56) : Equals<TypeRef> {
57 /**
58 * Compares concrete type identities, including generic arguments.
59 */
60 public override operator fun equals(other: TypeRef): Boolean = identity == other.identity
62 /**
63 * Evaluates the type's description provider.
64 */
65 public fun describe(): TypeDescription = describeBody()
68/**
69 * Combines a concrete type identity, its declaration annotations, and its structural shape.
70 */
71public struct TypeDescription(
72 val type: TypeRef,
73 val annotations: Array<AnnotationInfo>,
74 val shape: TypeShape