1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "gcgen.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_QUARK_USED
9 ///////////////////////////////////////////////////////////////////////////////
11 ///////////////////////////////////////////////////////////////////////////////
12 static const Quark
_g_c_g_e_nco_c_c_Q2("i__");
13 static const Quark
_g_c_g_e_nco_c_c_Q1("this");
15 ///////////////////////////////////////////////////////////////////////////////
17 // This file implements the garbage collection interface generation
19 ///////////////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////////////
27 // This method generates the interface method declarations
28 // for the garbage collector.
30 ///////////////////////////////////////////////////////////////////////////////
31 void DatatypeClass::generate_gc_interface(CodeGen
& C
)
35 "%^// Method for garbage collection tracing"
39 "%^virtual void trace(GC *);"
44 ///////////////////////////////////////////////////////////////////////////////
46 // This method generates an implementation for the trace method
48 ///////////////////////////////////////////////////////////////////////////////
49 void DatatypeClass::generate_gc_implementation(CodeGen
& C
, Tys tys
, DefKind k
)
51 // Unit constructors do not need gc methods
52 if (root
->arg_constructors
== 0) return;
54 if (k
== INTERFACE_DEFINITION
)
55 { C
.pr("%^extern void %s%P::trace(GC *);", class_name
, tys
);
59 C
.pr("%^void %s%P::trace(GC * gc__)"
60 "%^{%+", class_name
, tys
);
62 // Invoke base class tracing methods
63 gen_super_class_tracing_methods(C
,tys
,k
);
65 // Invoke tracing functions for each collectable fields.
67 { Ty arg_ty
= cons_arg_ty
;
68 if (is_array
) arg_ty
= mkarrayty(arg_ty
,IDexp("len_"));
69 gen_field_tracing_methods(C
,DEREFexp(IDexp(
82 ///////////////////////////////////////////////////////////////////////////////
84 // This method generates a tracing method for each base class
85 // that is collectable.
87 ///////////////////////////////////////////////////////////////////////////////
88 void DatatypeClass::gen_super_class_tracing_methods
89 (CodeGen
& C
, Tys tys
, DefKind k
)
91 // Generate a call to the superclass
94 if (root
->use_gc_base
)
95 C
.pr("%^%s%P::trace(gc__);", root
->class_name
, tys
);
97 C
.pr("%^// call to method %s%P::trace() has been optimized out",
98 root
->class_name
, tys
);
101 for_each(Inherit
, inh
, inherited_classes
)
102 { if((inh
->qualifiers
& QUALcollectable
) || is_gc_ty(inh
->super_class
))
103 { C
.pr("%^%t::trace(gc__);",
104 apply_ty(mkpolyty(inh
->super_class
,parameters
),tys
), "");
105 if (this == root
) root
->use_gc_base
= true;
110 ///////////////////////////////////////////////////////////////////////////////
112 // This method generates a tracing method for each field
113 // that is collectable.
115 ///////////////////////////////////////////////////////////////////////////////
116 void DatatypeClass::gen_field_tracing_methods
117 (CodeGen
& C
, Exp exp
, Ty ty
, Tys tys
, DefKind k
, Bool toplevel
)
121 #line 134 "gcgen.pcc"
123 Ty _V1
= deref_all(ty
);
125 switch (_V1
->tag__
) {
126 case a_Ty::tag_TYCONty
: {
127 if (boxed(((Ty_TYCONty
*)_V1
)->_1
)) {
128 switch (((Ty_TYCONty
*)_V1
)->_1
->tag__
) {
129 case a_TyCon::tag_RECORDtycon
: {
130 #line 111 "gcgen.pcc"
132 for(ls
= ((TyCon_RECORDtycon
*)((Ty_TYCONty
*)_V1
)->_1
)->_1
, ts
= ((Ty_TYCONty
*)_V1
)->_2
; ls
&& ts
; ls
= ls
->_2
, ts
= ts
->_2
)
133 gen_field_tracing_methods(C
,DOTexp(exp
,ls
->_1
),ts
->_1
,tys
,k
);
135 #line 114 "gcgen.pcc"
137 case a_TyCon::tag_ARRAYtycon
: {
138 if (((Ty_TYCONty
*)_V1
)->_2
) {
139 if (((Ty_TYCONty
*)_V1
)->_2
->_2
) {
141 #line 125 "gcgen.pcc"
143 { if (toplevel
) exp
= DOTexp(exp
,mangle(cons
->name
));
144 if (is_pointer_ty(ty
))
145 C
.pr("%^%e = (%t)gc__->trace(%e);",exp
,ty
,"",exp
);
147 C
.pr("%^gc__->trace(%e);",exp
);
150 { C
.pr("%^// omitted %T", ty
); }
152 #line 134 "gcgen.pcc"
154 #line 116 "gcgen.pcc"
156 "%^for (int i__ = 0; i__ < %e; i__++)"
158 ((TyCon_ARRAYtycon
*)((Ty_TYCONty
*)_V1
)->_1
)->ARRAYtycon
);
159 gen_field_tracing_methods(C
,INDEXexp(exp
,IDexp(
160 #line 120 "gcgen.pcc"
161 #line 120 "gcgen.pcc"
163 #line 120 "gcgen.pcc"
164 #line 120 "gcgen.pcc"
165 )),((Ty_TYCONty
*)_V1
)->_2
->_1
,tys
,k
);
169 #line 123 "gcgen.pcc"
173 default: { goto L1
; } break;
176 switch ((int)((Ty_TYCONty
*)_V1
)->_1
) {
177 case ((int)TUPLEtycon
): {
178 #line 101 "gcgen.pcc"
180 for_each(Ty
, ty
, ((Ty_TYCONty
*)_V1
)->_2
)
181 gen_field_tracing_methods(C
,DOTexp(exp
,index_of(i
++)),ty
,tys
,k
);
183 #line 104 "gcgen.pcc"
185 case ((int)EXTUPLEtycon
): {
186 #line 106 "gcgen.pcc"
188 for_each(Ty
, ty
, ((Ty_TYCONty
*)_V1
)->_2
)
189 gen_field_tracing_methods(C
,DOTexp(exp
,index_of(i
++)),ty
,tys
,k
);
191 #line 109 "gcgen.pcc"
193 default: { goto L1
; } break;
197 default: { goto L1
; } break;
201 #line 135 "gcgen.pcc"
202 #line 135 "gcgen.pcc"
205 #line 137 "gcgen.pcc"
207 ------------------------------- Statistics -------------------------------
208 Merge matching rules = yes
209 Number of DFA nodes merged = 23
210 Number of ifs generated = 4
211 Number of switches generated = 3
214 Adaptive matching = enabled
215 Fast string matching = disabled
216 Inline downcasts = enabled
217 --------------------------------------------------------------------------