use typename
[prop.git] / prop-src / gcgen.cc
blobe30170ec5d1b3fd95a8068766b283c2b4cdf34ce
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
8 #include <propdefs.h>
9 ///////////////////////////////////////////////////////////////////////////////
10 // Quark literals
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");
14 #line 1 "gcgen.pcc"
15 ///////////////////////////////////////////////////////////////////////////////
17 // This file implements the garbage collection interface generation
19 ///////////////////////////////////////////////////////////////////////////////
21 #include "ir.h"
22 #include "datatype.h"
23 #include "type.h"
25 ///////////////////////////////////////////////////////////////////////////////
27 // This method generates the interface method declarations
28 // for the garbage collector.
30 ///////////////////////////////////////////////////////////////////////////////
31 void DatatypeClass::generate_gc_interface(CodeGen& C)
33 C.pr("%^%/"
34 "%^//"
35 "%^// Method for garbage collection tracing"
36 "%^//"
37 "%^%/"
38 "%-%^protected:%+"
39 "%^virtual void trace(GC *);"
40 "%-%^public:%+"
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);
56 return;
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.
66 if (cons != NOcons)
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(
70 #line 55 "gcgen.pcc"
71 #line 55 "gcgen.pcc"
72 _g_c_g_e_nco_c_c_Q1
73 #line 55 "gcgen.pcc"
74 #line 55 "gcgen.pcc"
75 )),
76 arg_ty,tys,k,true);
79 C.pr("%-%^}\n\n");
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
92 if (this != root)
94 if (root->use_gc_base)
95 C.pr("%^%s%P::trace(gc__);", root->class_name, tys);
96 else
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)
120 #line 99 "gcgen.pcc"
121 #line 134 "gcgen.pcc"
123 Ty _V1 = deref_all(ty);
124 if (_V1) {
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"
131 Ids ls; Tys ts;
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"
136 } break;
137 case a_TyCon::tag_ARRAYtycon: {
138 if (((Ty_TYCONty *)_V1)->_2) {
139 if (((Ty_TYCONty *)_V1)->_2->_2) {
140 L1:;
141 #line 125 "gcgen.pcc"
142 if (is_gc_ty(ty))
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);
146 else
147 C.pr("%^gc__->trace(%e);",exp);
148 C.pr(" // %T", ty);
149 } else
150 { C.pr("%^// omitted %T", ty); }
152 #line 134 "gcgen.pcc"
153 } else {
154 #line 116 "gcgen.pcc"
155 C.pr("%^{%+"
156 "%^for (int i__ = 0; i__ < %e; i__++)"
157 "%^{%+",
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"
162 _g_c_g_e_nco_c_c_Q2
163 #line 120 "gcgen.pcc"
164 #line 120 "gcgen.pcc"
165 )),((Ty_TYCONty *)_V1)->_2->_1,tys,k);
166 C.pr("%-%^}"
167 "%-%^}");
169 #line 123 "gcgen.pcc"
171 } else { goto L1; }
172 } break;
173 default: { goto L1; } break;
175 } else {
176 switch ((int)((Ty_TYCONty *)_V1)->_1) {
177 case ((int)TUPLEtycon): {
178 #line 101 "gcgen.pcc"
179 int i = 1;
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"
184 } break;
185 case ((int)EXTUPLEtycon): {
186 #line 106 "gcgen.pcc"
187 int i = 1;
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"
192 } break;
193 default: { goto L1; } break;
196 } break;
197 default: { goto L1; } break;
199 } else { goto L1; }
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
212 Number of labels = 1
213 Number of gotos = 5
214 Adaptive matching = enabled
215 Fast string matching = disabled
216 Inline downcasts = enabled
217 --------------------------------------------------------------------------