1 //
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 29 Aug 06 Brian Frank Creation
7 //
8
9 **
10 ** ReflectSlot is the implementation of CSlot for a slot imported
11 ** from a precompiled pod (as opposed to a SlotDef within the
12 ** compilation units being compiled).
13 **
14 abstract class ReflectSlot : CSlot
15 {
16 new make(Slot slot)
17 {
18 this.flags = (Int)slot->flags // undocumented trap
19 }
20
21 override abstract ReflectNamespace ns() // covariant redefinition
22 override abstract ReflectType parent() // covariant redefinition
23 override Str name() { return slot.name }
24 override Str qname() { return slot.qname }
25 override Str signature() { return slot.signature }
26 override readonly Int flags
27 override Str toStr() { return signature }
28 abstract Slot slot()
29 }
30
31 **************************************************************************
32 ** ReflectField
33 **************************************************************************
34
35 class ReflectField : ReflectSlot, CField
36 {
37 new make(ReflectType parent, Field f)
38 : super(f)
39 {
40 this.parent = parent
41 this.f = f
42 this.fieldType = ns.importType(f.of)
43 get := (Method)f->getter; if (get != null) this.getter = ns.importMethod(get)
44 set := (Method)f->setter; if (set != null) this.setter = ns.importMethod(set)
45 }
46
47 override ReflectNamespace ns() { return parent.ns }
48 override ReflectType parent
49
50 override Slot slot() { return f }
51
52 override CType inheritedReturnType()
53 {
54 if (!isOverride || getter == null) return fieldType
55 else return getter.inheritedReturnType
56 }
57
58 override readonly CType fieldType
59 override readonly CMethod getter
60 override readonly CMethod setter
61 readonly Field f
62 }
63
64 **************************************************************************
65 ** ReflectMethod
66 **************************************************************************
67
68 class ReflectMethod : ReflectSlot, CMethod
69 {
70 new make(ReflectType parent, Method m)
71 : super(m)
72 {
73 this.parent = parent
74 this.m = m
75 this.returnType = ns.importType(m.returns)
76 m.params.map(this.params = CParam[,]) |Param p->Obj| { return ReflectParam.make(ns, p) }
77 this.isGeneric = calcGeneric(this)
78 }
79
80 override ReflectNamespace ns() { return parent.ns }
81 override ReflectType parent
82
83 override Slot slot() { return m }
84
85 override CType inheritedReturnType()
86 {
87 // use trap to access undocumented hook
88 if (isOverride)
89 return ns.importType((Type)m->inheritedReturnType)
90 else
91 return returnType
92 }
93
94 override readonly CType returnType
95 override readonly CParam[] params
96 override readonly Bool isGeneric
97 readonly Method m
98 }
99
100 **************************************************************************
101 ** ReflectParam
102 **************************************************************************
103
104 class ReflectParam : CParam
105 {
106 new make(ReflectNamespace ns, Param p)
107 {
108 this.p = p
109 this.paramType = ns.importType(p.of)
110 }
111
112 override Str name() { return p.name }
113 override Bool hasDefault() { return p.hasDefault }
114
115 override readonly CType paramType
116 readonly Param p
117 }