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 ** CSlot is a "compiler slot" which is represents a Slot in the
11 ** compiler. CSlots unifies slots being compiled as SlotDefs
12 ** with slots imported as ReflectSlot or FSlot.
13 **
14 mixin CSlot
15 {
16 virtual Namespace ns() { return parent.ns }
17 abstract CType parent()
18 abstract Str name()
19 abstract Str qname()
20 abstract Str signature()
21 abstract Int flags()
22
23 Bool isAbstract() { return flags & FConst.Abstract != 0 }
24 Bool isAccessor() { return flags & (FConst.Getter | FConst.Setter) != 0 }
25 Bool isConst() { return flags & FConst.Const != 0 }
26 Bool isCtor() { return flags & FConst.Ctor != 0 }
27 Bool isEnum() { return flags & FConst.Enum != 0 }
28 Bool isGetter() { return flags & FConst.Getter != 0 }
29 Bool isInternal() { return flags & FConst.Internal != 0 }
30 Bool isOverride() { return flags & FConst.Override != 0 }
31 Bool isPrivate() { return flags & FConst.Private != 0 }
32 Bool isProtected() { return flags & FConst.Protected != 0 }
33 Bool isPublic() { return flags & FConst.Public != 0 }
34 Bool isSetter() { return flags & FConst.Setter != 0 }
35 Bool isStatic() { return flags & FConst.Static != 0 }
36 Bool isStorage() { return flags & FConst.Storage != 0 }
37 Bool isSynthetic() { return flags & FConst.Synthetic != 0 }
38 Bool isVirtual() { return flags & FConst.Virtual != 0 }
39 }
40
41 **************************************************************************
42 ** CField
43 **************************************************************************
44
45 **
46 ** CField is a "compiler field" which is represents a Field in the
47 ** compiler. CFields unify methods being compiled as FieldDefs
48 ** with methods imported as ReflectField or FField.
49 **
50 mixin CField : CSlot
51 {
52 abstract CType fieldType()
53 abstract CMethod getter()
54 abstract CMethod setter()
55
56 **
57 ** Original return type from inherited method if a covariant override.
58 **
59 abstract CType inheritedReturnType()
60
61 **
62 ** Does this field covariantly override a method?
63 **
64 Bool isCovariant() { return isOverride && fieldType != inheritedReturnType }
65 }
66
67 **************************************************************************
68 ** CMethod
69 **************************************************************************
70
71 **
72 ** CMethod is a "compiler method" which is represents a Method in the
73 ** compiler. CMethods unify methods being compiled as MethodDefs
74 ** with methods imported as ReflectMethod or FMethod.
75 **
76 mixin CMethod : CSlot
77 {
78 **
79 ** Return type
80 **
81 abstract CType returnType()
82
83 **
84 ** Parameter signatures
85 **
86 abstract CParam[] params()
87
88 **
89 ** Original return type from inherited method if a covariant override.
90 **
91 abstract CType inheritedReturnType()
92
93 **
94 ** Does this method have a covariant return type
95 **
96 Bool isCovariant() { return isOverride && returnType != inheritedReturnType }
97
98 **
99 ** Does this method contains generic parameters in its signature.
100 **
101 virtual Bool isGeneric() { return false }
102
103 **
104 ** Is this method the parameterization of a generic method,
105 ** with all the generic parameters filled in with real types.
106 **
107 virtual Bool isParameterized() { return false }
108
109 **
110 ** If isParameterized is true, then return the generic
111 ** method which this method parameterizes, otherwise null
112 **
113 virtual CMethod generic() { return null }
114
115 static Bool calcGeneric(CMethod m)
116 {
117 if (!m.parent.isGeneric) return false
118 isGeneric := m.returnType.isGenericParameter
119 m.params.each |CParam p| { isGeneric = isGeneric || p.paramType.isGenericParameter }
120 return isGeneric
121 }
122
123 **
124 ** Return a string with the name and parameters.
125 **
126 Str nameAndParamTypesToStr()
127 {
128 return name + "(" +
129 params.join(", ", |CParam p->Str| { return p.paramType.signature }) +
130 ")"
131 }
132
133 **
134 ** Return if this method has the exact same parameters as
135 ** the specified method.
136 **
137 Bool hasSameParams(CMethod that)
138 {
139 a := params
140 b := that.params
141
142 if (a.size != b.size) return false
143 for (i:=0; i<a.size; ++i)
144 if (a[i].paramType != b[i].paramType) return false
145
146 return true
147 }
148
149 }
150
151 **************************************************************************
152 ** CParam
153 **************************************************************************
154
155 **
156 ** CParam models a MethodParam in the compiler. CParams unify the params
157 ** being compiled (ParamDef) and parameters imported (ReflectParam, FMethodVar)
158 **
159 mixin CParam
160 {
161 abstract Str name()
162 abstract CType paramType()
163 abstract Bool hasDefault()
164 }
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 ** CSlot is a "compiler slot" which is represents a Slot in the
11 ** compiler. CSlots unifies slots being compiled as SlotDefs
12 ** with slots imported as ReflectSlot or FSlot.
13 **
14 mixin CSlot
15 {
16 virtual Namespace ns() { return parent.ns }
17 abstract CType parent()
18 abstract Str name()
19 abstract Str qname()
20 abstract Str signature()
21 abstract Int flags()
22
23 Bool isAbstract() { return flags & FConst.Abstract != 0 }
24 Bool isAccessor() { return flags & (FConst.Getter | FConst.Setter) != 0 }
25 Bool isConst() { return flags & FConst.Const != 0 }
26 Bool isCtor() { return flags & FConst.Ctor != 0 }
27 Bool isEnum() { return flags & FConst.Enum != 0 }
28 Bool isGetter() { return flags & FConst.Getter != 0 }
29 Bool isInternal() { return flags & FConst.Internal != 0 }
30 Bool isOverride() { return flags & FConst.Override != 0 }
31 Bool isPrivate() { return flags & FConst.Private != 0 }
32 Bool isProtected() { return flags & FConst.Protected != 0 }
33 Bool isPublic() { return flags & FConst.Public != 0 }
34 Bool isSetter() { return flags & FConst.Setter != 0 }
35 Bool isStatic() { return flags & FConst.Static != 0 }
36 Bool isStorage() { return flags & FConst.Storage != 0 }
37 Bool isSynthetic() { return flags & FConst.Synthetic != 0 }
38 Bool isVirtual() { return flags & FConst.Virtual != 0 }
39 }
40
41 **************************************************************************
42 ** CField
43 **************************************************************************
44
45 **
46 ** CField is a "compiler field" which is represents a Field in the
47 ** compiler. CFields unify methods being compiled as FieldDefs
48 ** with methods imported as ReflectField or FField.
49 **
50 mixin CField : CSlot
51 {
52 abstract CType fieldType()
53 abstract CMethod getter()
54 abstract CMethod setter()
55
56 **
57 ** Original return type from inherited method if a covariant override.
58 **
59 abstract CType inheritedReturnType()
60
61 **
62 ** Does this field covariantly override a method?
63 **
64 Bool isCovariant() { return isOverride && fieldType != inheritedReturnType }
65 }
66
67 **************************************************************************
68 ** CMethod
69 **************************************************************************
70
71 **
72 ** CMethod is a "compiler method" which is represents a Method in the
73 ** compiler. CMethods unify methods being compiled as MethodDefs
74 ** with methods imported as ReflectMethod or FMethod.
75 **
76 mixin CMethod : CSlot
77 {
78 **
79 ** Return type
80 **
81 abstract CType returnType()
82
83 **
84 ** Parameter signatures
85 **
86 abstract CParam[] params()
87
88 **
89 ** Original return type from inherited method if a covariant override.
90 **
91 abstract CType inheritedReturnType()
92
93 **
94 ** Does this method have a covariant return type
95 **
96 Bool isCovariant() { return isOverride && returnType != inheritedReturnType }
97
98 **
99 ** Does this method contains generic parameters in its signature.
100 **
101 virtual Bool isGeneric() { return false }
102
103 **
104 ** Is this method the parameterization of a generic method,
105 ** with all the generic parameters filled in with real types.
106 **
107 virtual Bool isParameterized() { return false }
108
109 **
110 ** If isParameterized is true, then return the generic
111 ** method which this method parameterizes, otherwise null
112 **
113 virtual CMethod generic() { return null }
114
115 static Bool calcGeneric(CMethod m)
116 {
117 if (!m.parent.isGeneric) return false
118 isGeneric := m.returnType.isGenericParameter
119 m.params.each |CParam p| { isGeneric = isGeneric || p.paramType.isGenericParameter }
120 return isGeneric
121 }
122
123 **
124 ** Return a string with the name and parameters.
125 **
126 Str nameAndParamTypesToStr()
127 {
128 return name + "(" +
129 params.join(", ", |CParam p->Str| { return p.paramType.signature }) +
130 ")"
131 }
132
133 **
134 ** Return if this method has the exact same parameters as
135 ** the specified method.
136 **
137 Bool hasSameParams(CMethod that)
138 {
139 a := params
140 b := that.params
141
142 if (a.size != b.size) return false
143 for (i:=0; i<a.size; ++i)
144 if (a[i].paramType != b[i].paramType) return false
145
146 return true
147 }
148
149 }
150
151 **************************************************************************
152 ** CParam
153 **************************************************************************
154
155 **
156 ** CParam models a MethodParam in the compiler. CParams unify the params
157 ** being compiled (ParamDef) and parameters imported (ReflectParam, FMethodVar)
158 **
159 mixin CParam
160 {
161 abstract Str name()
162 abstract CType paramType()
163 abstract Bool hasDefault()
164 }