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 "datagen.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
8 ///////////////////////////////////////////////////////////////////////////////
10 // This file implements the datatype compiler of Prop.
12 ///////////////////////////////////////////////////////////////////////////////
15 #include <AD/strings/quark.h>
24 ///////////////////////////////////////////////////////////////////////////////
26 // Constructor and destructors for datatype compiler
28 ///////////////////////////////////////////////////////////////////////////////
29 int DatatypeCompiler::max_embedded_tags
= 0;
30 int DatatypeCompiler::max_embedded_bits
= 0;
31 LabelGen
DatatypeCompiler::temp_vars("_T");
33 DatatypeCompiler:: DatatypeCompiler(TyOpt opt
, int embedded_tags
)
35 { max_embedded_tags
= embedded_tags
;
36 max_embedded_bits
= 0;
37 for (int i
= embedded_tags
- 1; i
> 0; i
>>= 1)
40 DatatypeCompiler::~DatatypeCompiler() {}
42 ///////////////////////////////////////////////////////////////////////////////
44 // Method to create a datatype hierarchy
46 ///////////////////////////////////////////////////////////////////////////////
47 static DatatypeHierarchy
* create_datatype_hierarchy
48 (Id name
, TyVars parameters
, Inherits inhs
, TyQual qual
,
49 TermDefs terms
, Decls body
)
52 #line 44 "datagen.pcc"
53 #line 47 "datagen.pcc"
55 Ty _V1
= lookup_ty(name
);
58 case a_Ty::tag_TYCONty
: {
59 if (boxed(((Ty_TYCONty
*)_V1
)->_1
)) {
60 switch (((Ty_TYCONty
*)_V1
)->_1
->tag__
) {
61 case a_TyCon::tag_DATATYPEtycon
: {
62 #line 45 "datagen.pcc"
63 return ((TyCon_DATATYPEtycon
*)((Ty_TYCONty
*)_V1
)->_1
)->hierarchy
;
64 #line 45 "datagen.pcc"
68 #line 47 "datagen.pcc"
69 return new DatatypeHierarchy(name
,parameters
,inhs
,qual
,terms
,body
);
70 #line 47 "datagen.pcc"
75 default: { goto L1
; } break;
79 #line 48 "datagen.pcc"
80 #line 48 "datagen.pcc"
84 ///////////////////////////////////////////////////////////////////////////////
86 // Top level method to map datatype and type definitions into
87 // a C++ class hierarchy.
89 ///////////////////////////////////////////////////////////////////////////////
90 void DatatypeCompiler::gen_datatype
91 ( DatatypeDefs data_defs
, // datatype definitions
92 ViewDefs view_defs
, // view definitions
93 LawDefs law_defs
, // law definitions
94 TyDefs ty_defs
// type definitions
97 // Build the classes hierarchies
98 int N
= length(data_defs
);
99 DatatypeHierarchy
** H
= new DatatypeHierarchy
* [N
];
101 for_each (DatatypeDef
, d
, data_defs
)
103 #line 69 "datagen.pcc"
104 #line 73 "datagen.pcc"
106 #line 71 "datagen.pcc"
107 H
[i
] = create_datatype_hierarchy(d
->_1
,d
->_2
,d
->_3
,d
->_4
,d
->_5
,d
->_6
);
110 #line 73 "datagen.pcc"
112 #line 74 "datagen.pcc"
113 #line 74 "datagen.pcc"
118 // Generate forward datatype definitions
119 { for (int i
= 0; i
< N
; i
++)
120 if (H
[i
]) H
[i
]->generate_forward_declarations(*this);
123 // Generate type definitions
124 { for_each (TyDef
, t
, ty_defs
) gen_type_def(t
); }
126 // Generate the class hierarchies
127 { for (int i
= 0; i
< N
; i
++)
128 if (H
[i
]) H
[i
]->generate_datatype_definitions(*this);
131 // Compile the pattern laws
132 gen_law_defs(law_defs
);
135 ///////////////////////////////////////////////////////////////////////////////
137 // Method to generate a type definition
139 ///////////////////////////////////////////////////////////////////////////////
140 void DatatypeCompiler::gen_type_def (TyDef ty_def
)
142 #line 101 "datagen.pcc"
143 #line 109 "datagen.pcc"
146 #line 102 "datagen.pcc"
148 #line 102 "datagen.pcc"
151 #line 103 "datagen.pcc"
152 pr ("%^%/%^// Definition of type %s%V%^%/"
154 "%^%^typedef %t;\n\n",
155 ty_def
->_1
, ty_def
->_2
, ty_def
->begin_line
, ty_def
->file_name
, ty_def
->_3
, ty_def
->_1
);
157 #line 107 "datagen.pcc"
161 #line 109 "datagen.pcc"
162 #line 109 "datagen.pcc"
166 ///////////////////////////////////////////////////////////////////////////////
168 // Method to preprocess a datatype (for constraints)
170 ///////////////////////////////////////////////////////////////////////////////
171 void DatatypeCompiler::preprocess_def (DatatypeDef def
)
173 #line 118 "datagen.pcc"
174 #line 129 "datagen.pcc"
177 #line 119 "datagen.pcc"
178 (def
->_4
& QUALunifiable
)
179 #line 119 "datagen.pcc"
182 #line 120 "datagen.pcc"
183 Id var_term_name
= Quark(def
->_1
,"_var");
185 #line 121 "datagen.pcc"
186 #line 121 "datagen.pcc"
187 TERMdef(var_term_name
, mkidvarty(def
->_1
,def
->_2
), nil_1_
, nil_1_
, NOpat
, nil_1_
, OPTnone
, QUALvariable
, NOexp
)
188 #line 124 "datagen.pcc"
189 #line 124 "datagen.pcc"
192 #line 125 "datagen.pcc"
193 #line 125 "datagen.pcc"
194 list_1_(var_term
,def
->_5
)
195 #line 125 "datagen.pcc"
196 #line 125 "datagen.pcc"
198 // msg("[Unifiable datatype %s]\n", id);
200 #line 127 "datagen.pcc"
204 #line 129 "datagen.pcc"
205 #line 129 "datagen.pcc"
208 #line 131 "datagen.pcc"
210 ------------------------------- Statistics -------------------------------
211 Merge matching rules = yes
212 Number of DFA nodes merged = 25
213 Number of ifs generated = 4
214 Number of switches generated = 2
217 Adaptive matching = enabled
218 Fast string matching = disabled
219 Inline downcasts = enabled
220 --------------------------------------------------------------------------