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 "instance.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
8 //////////////////////////////////////////////////////////////////////////////
10 // This file implements datatype instantiations
12 //////////////////////////////////////////////////////////////////////////////
20 //////////////////////////////////////////////////////////////////////////////
22 // Method to instantiate a list of datatypes
24 //////////////////////////////////////////////////////////////////////////////
25 void DatatypeCompiler::instantiate_datatypes(Bool external
, Tys tys
)
28 { for_each (Ty
, ty
, tys
) instantiate_datatypes(true,ty
); }
29 { for_each (Ty
, ty
, tys
) instantiate_datatypes(external
,ty
); }
32 //////////////////////////////////////////////////////////////////////////////
34 // Method to instantiate one datatype
36 //////////////////////////////////////////////////////////////////////////////
37 void DatatypeCompiler::instantiate_datatypes(Bool e
, Ty ty
)
39 #line 31 "instance.pcc"
40 #line 42 "instance.pcc"
42 Ty _V1
= deref_all(ty
);
45 case a_Ty::tag_TYCONty
: {
46 if (boxed(((Ty_TYCONty
*)_V1
)->_1
)) {
47 switch (((Ty_TYCONty
*)_V1
)->_1
->tag__
) {
48 case a_TyCon::tag_DATATYPEtycon
: {
49 #line 33 "instance.pcc"
50 if (((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V1
)->_1
)->hierarchy
== 0)
51 { error ("%Ldefinition of datatype %T is unknown\n", ty
);
53 { if (! is_ground(_V1
))
54 error("%Lmissing parameters in instantiation of datatype %T\n",
56 ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V1
)->_1
)->hierarchy
->generate_datatype_instantiations(*this,((Ty_TYCONty
*)_V1
)->_2
,e
);
59 #line 41 "instance.pcc"
63 #line 42 "instance.pcc"
64 error ("%Ldefinition of %T is not found\n", _V1
);
65 #line 42 "instance.pcc"
70 default: { goto L1
; } break;
74 #line 43 "instance.pcc"
75 #line 43 "instance.pcc"
79 //////////////////////////////////////////////////////////////////////////////
81 // Method to instantiate a datatype
83 //////////////////////////////////////////////////////////////////////////////
84 void DatatypeHierarchy::generate_datatype_instantiations
85 (CodeGen
& C
, Tys argument_types
, Bool interface
)
87 if (is_view()) return;
90 Id msg
= interface
? "Interface specification" : "Instantiation";
93 "%^// %s of datatype %s%P"
97 msg
, datatype_name
, argument_types
, line
, file
99 DefKind k
= interface
? EXTERNAL_DEFINITION
: EXTERNAL_INSTANTIATION
;
101 gen_class_instantiation(C
, argument_types
, k
);
102 gen_class_implementation(C
, argument_types
, k
);
103 for (int i
= 0; i
< number_of_subclasses
; i
++)
104 subclasses
[i
]->gen_class_implementation(C
, argument_types
, k
);
108 //////////////////////////////////////////////////////////////////////////////
110 // Method to generate the implementation of a class
112 //////////////////////////////////////////////////////////////////////////////
113 void DatatypeClass::gen_class_implementation(CodeGen
& C
, Tys tys
, DefKind k
)
115 ///////////////////////////////////////////////////////////////////////////
117 // Compute the new argument types of the constructors
119 ///////////////////////////////////////////////////////////////////////////
121 #line 87 "instance.pcc"
122 #line 98 "instance.pcc"
125 #line 89 "instance.pcc"
127 { case EXTERNAL_INSTANTIATION
:
128 case EXTERNAL_DEFINITION
:
129 cons_arg_ty
= apply_ty(cons
->cons_ty
,tys
); break;
131 cons_arg_ty
= cons
->ty
; break;
134 #line 96 "instance.pcc"
136 #line 98 "instance.pcc"
138 #line 98 "instance.pcc"
141 #line 99 "instance.pcc"
142 #line 99 "instance.pcc"
144 ///////////////////////////////////////////////////////////////////////////
146 // Generate the constructors, destructors, and datatype constructor
147 // function if inline methods are not used.
149 ///////////////////////////////////////////////////////////////////////////
150 if (! root
->inline_methods
)
152 // Generate the constructor of the class
153 if (cons
!= NOcons
&& (k
!= EXTERNAL_DEFINITION
|| tys
!=
154 #line 109 "instance.pcc"
155 #line 109 "instance.pcc"
157 #line 109 "instance.pcc"
158 #line 109 "instance.pcc"
160 gen_class_constructor(C
, tys
, k
);
162 // Generate the destructor of the class
163 if ((k
!= EXTERNAL_DEFINITION
|| tys
!=
164 #line 113 "instance.pcc"
165 #line 113 "instance.pcc"
167 #line 113 "instance.pcc"
168 #line 113 "instance.pcc"
170 ((root
->qualifiers
& QUALvirtualdestr
) ||
171 (qualifiers
& QUALvirtualdestr
) ||
173 gen_class_destructor(C
, tys
, k
);
175 if (cons
!= NOcons
&& (k
!= EXTERNAL_DEFINITION
|| tys
!=
176 #line 119 "instance.pcc"
177 #line 119 "instance.pcc"
179 #line 119 "instance.pcc"
180 #line 119 "instance.pcc"
182 generate_datatype_constructor(C
, tys
, k
);
185 ///////////////////////////////////////////////////////////////////////////
187 // Generate the implementation methods for various features
189 ///////////////////////////////////////////////////////////////////////////
190 if (root
->qualifiers
& QUALpersistent
&& k
== EXTERNAL_INSTANTIATION
)
191 generate_persistence_implementation(C
,tys
,k
);
192 //if (root->qualifiers & QUALvariable && k == EXTERNAL_INSTANTIATION)
193 // generate_logic_implementation(C,tys,k);
194 if (root
->qualifiers
& QUALcollectable
&& k
== EXTERNAL_INSTANTIATION
)
195 generate_gc_implementation(C
,tys
,k
);
196 if (root
->qualifiers
& QUALrelation
&& k
== EXTERNAL_INSTANTIATION
)
197 generate_inference_implementation(C
,tys
,k
);
198 if (root
->qualifiers
& QUALprintable
)
199 generate_print_implementation(C
,tys
,k
);
202 void DatatypeHierarchy::gen_class_implementation(CodeGen
& C
, Tys tys
,DefKind k
)
204 DatatypeClass::gen_class_implementation(C
,tys
,k
);
207 //////////////////////////////////////////////////////////////////////////////
209 // Method to generate template instantiation of a class
211 //////////////////////////////////////////////////////////////////////////////
212 void DatatypeClass::gen_class_instantiation(CodeGen
& C
, Tys tys
, DefKind k
)
214 C
.pr("%^template class %S%P;", class_name
, tys
);
216 if (cons
!= NOcons
&& root
->inline_methods
)
217 { // Constructor function
218 C
.pr("%^template %S%P * %S%b;",
219 root
->class_name
, tys
,
220 constructor_name
, cons_arg_ty
, cons
->name
, TYsimpleformal
);
223 { C
.pr("%^template %S%P * %S%b;",
224 root
->class_name
, tys
, constructor_name
,
225 component_ty(cons_arg_ty
,1), cons
->name
, TYsimpleformal
);
231 //////////////////////////////////////////////////////////////////////////////
233 // Method to generate template instantiation of a class hierarchy
235 //////////////////////////////////////////////////////////////////////////////
236 void DatatypeHierarchy::gen_class_instantiation(CodeGen
& C
, Tys tys
, DefKind k
)
238 #line 175 "instance.pcc"
239 #line 175 "instance.pcc"
241 #line 175 "instance.pcc"
242 #line 175 "instance.pcc"
243 && k
== EXTERNAL_INSTANTIATION
&& arg_constructors
> 0)
244 { C
.pr("%n#ifdef PROP_EXPLICIT_TEMPLATE_INSTANTIATION");
245 DatatypeClass::gen_class_instantiation(C
,tys
,k
);
246 for (int i
= 0; i
< number_of_subclasses
; i
++)
247 { subclasses
[i
]->gen_class_instantiation(C
,tys
,k
);
249 gen_untagging_function_instantiation(C
,tys
,k
);
250 gen_downcasting_function_instantiation(C
,tys
,k
);
251 C
.pr("%n#endif /* PROP_EXPLICIT_TEMPLATE_INSTANTIATION */");
255 //////////////////////////////////////////////////////////////////////////////
257 // Method to generate template instantiation of untagging functions.
259 //////////////////////////////////////////////////////////////////////////////
260 void DatatypeHierarchy::gen_untagging_function_instantiation
261 (CodeGen
& C
, Tys tys
, DefKind k
)
263 C
.pr("%^template int boxed(const %S%P *);"
264 "%^template int untag(const %S%P *);",
265 class_name
, tys
, class_name
, tys
);
266 if (optimizations
& OPTtaggedpointer
)
267 { C
.pr("%^template int untagp(const %S%P *);"
268 "%^template %S%P * derefp(const %S%P *);",
269 class_name
, tys
, class_name
, tys
, class_name
, tys
);
273 //////////////////////////////////////////////////////////////////////////////
275 // Method to generate template instantiation of downcasting functions.
277 //////////////////////////////////////////////////////////////////////////////
278 void DatatypeHierarchy::gen_downcasting_function_instantiation
279 (CodeGen
& C
, Tys tys
, DefKind k
)
281 if (options
.inline_casts
== false || parameters
!=
282 #line 213 "instance.pcc"
283 #line 213 "instance.pcc"
285 #line 213 "instance.pcc"
286 #line 213 "instance.pcc"
288 { for (int i
= 0; i
< number_of_subclasses
; i
++)
289 { DatatypeClass
* D
= subclasses
[i
];
290 C
.pr("%^template %S%P * _%S(const %S%P *);",
291 root
->class_name
, tys
, D
->constructor_name
, class_name
, tys
);
295 #line 221 "instance.pcc"
297 ------------------------------- Statistics -------------------------------
298 Merge matching rules = yes
299 Number of DFA nodes merged = 23
300 Number of ifs generated = 3
301 Number of switches generated = 2
304 Adaptive matching = enabled
305 Fast string matching = disabled
306 Inline downcasts = enabled
307 --------------------------------------------------------------------------