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 "rwgen5.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_QUARK_USED
9 ///////////////////////////////////////////////////////////////////////////////
11 ///////////////////////////////////////////////////////////////////////////////
12 static const Quark
_r_w_g_e_n_5co_c_c_Q1("none");
14 ///////////////////////////////////////////////////////////////////////////////
16 // This file implements indexing for rewriters
18 ///////////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
31 RewriteIndexing::RewriteIndexing(Ty t
, Id i
, Bool e
)
32 : ty(t
), name(i
), external(e
) {}
33 RewriteIndexing::~RewriteIndexing() {}
35 ///////////////////////////////////////////////////////////////////////////////
37 // Mapping from id to RewriteClass
39 ///////////////////////////////////////////////////////////////////////////////
40 HashTable
RewritingCompiler::rewrite_classes(string_hash
, string_equal
);
42 ///////////////////////////////////////////////////////////////////////////////
44 // Enter a rewrite class
46 ///////////////////////////////////////////////////////////////////////////////
47 void RewritingCompiler::add_rewrite_class(RewriteClass
* C
)
48 { if (rewrite_classes
.contains(C
->class_name
)) {
49 error ("%Lrewrite class %s has already been defined\n", C
->class_name
);
51 rewrite_classes
.insert(C
->class_name
, C
);
52 debug_msg ("[Rewriting class %s declared]\n", C
->class_name
);
56 ///////////////////////////////////////////////////////////////////////////////
58 // Lookup a rewrite class
60 ///////////////////////////////////////////////////////////////////////////////
61 RewriteClass
* RewritingCompiler::lookup_rewrite_class(Id id
)
62 { HashTable::Entry
* e
= rewrite_classes
.lookup(id
);
64 error ("%Lrewrite class %s is undefined\n", id
);
67 return (RewriteClass
*)rewrite_classes
.value(e
);
71 Protocols
RewritingCompiler::lookup_protocols(Id id
)
72 { RewriteClass
* C
= lookup_rewrite_class(id
);
73 return C
? C
->protocols
:
82 TyQual
RewritingCompiler::lookup_qual(Id id
)
83 { RewriteClass
* C
= lookup_rewrite_class(id
);
84 return C
? C
->qualifiers
: QUALnone
;
87 ///////////////////////////////////////////////////////////////////////////////
89 // Method to retrieve the indexing information for a type
91 ///////////////////////////////////////////////////////////////////////////////
92 const RewriteIndexing
* RewritingCompiler::get_index(Ty ty
) const
93 { for_each (RewriteIndexing
*, i
, indices
)
94 { if (ty_equal(i
->ty
, ty
)) return i
;
99 ///////////////////////////////////////////////////////////////////////////////
101 // Method to compute the index
103 ///////////////////////////////////////////////////////////////////////////////
104 Bool
RewritingCompiler::compute_index (Ty ty
, Id
& name
, Bool
& external
) const
105 { Ty datatype_ty
= deref_all(ty
);
106 Bool is_boxed
= boxed_variants(datatype_ty
) > 0;
107 Bool rewritable
= has_qual(QUALrewritable
, datatype_ty
);
108 const RewriteIndexing
* I
= get_index(ty
);
109 Bool need_cache
= Fmap
->has_replacement
|| Fmap
->gen_reducers
;
111 Bool ok
= is_boxed
&& (rewritable
|| I
!= 0) && need_cache
;
113 if (I
!= 0 && I
->name
==
114 #line 94 "rwgen5.pcc"
115 #line 94 "rwgen5.pcc"
116 _r_w_g_e_n_5co_c_c_Q1
117 #line 94 "rwgen5.pcc"
118 #line 94 "rwgen5.pcc"
122 { if (I
) { name
= I
->name
; external
= I
->external
; }
123 else { name
= "rewrite"; external
= false; }
129 ///////////////////////////////////////////////////////////////////////////////
131 // Method to check whether a type has an index
133 ///////////////////////////////////////////////////////////////////////////////
134 Bool
RewritingCompiler::has_index (Ty ty
) const
135 { Id name
; Bool external
;
136 return compute_index(ty
,name
,external
);
139 ///////////////////////////////////////////////////////////////////////////////
141 // Method to emit code for retrieving the state from an expression
143 ///////////////////////////////////////////////////////////////////////////////
144 Id
RewritingCompiler::gen_get_rewrite_state(Ty ty
, Exp pat_exp
)
145 { Id name
; Bool external
;
146 if (! compute_index(ty
,name
,external
))
147 { bug("%Lexpression %e : %T has no index", pat_exp
, ty
); }
148 int units
= unboxed_variants(ty
);
149 int args
= boxed_variants(ty
);
150 Functor f
= Fmap
->type_map
[ty
];
151 Id state_var
= vars
.new_label();
154 { pr("%^int %s = ", state_var
);
155 if (external
) pr("get_%s_state(%e);", name
, pat_exp
);
156 else pr("%e->get_%s_state();", pat_exp
, name
);
157 } else if (args
== 0)
158 { pr("%^int %s = %e + %i;", state_var
, pat_exp
, f
);
160 { Id pat_var
= vars
.new_label();
162 "%^int %s = boxed(%s) ? ",
163 ty
, "", pat_var
, pat_exp
, state_var
, pat_var
);
164 if (external
) pr("get_%s_state(%s)", name
, pat_var
);
165 else pr("%s->get_%s_state()", pat_var
, name
);
166 pr(" : ((int)%s + %i);", pat_var
, f
);
171 ///////////////////////////////////////////////////////////////////////////////
173 // Method to emit code for retrieving the state from index
175 ///////////////////////////////////////////////////////////////////////////////
176 void RewritingCompiler::gen_get_rewrite_state(Ty ty
, Id redex
)
177 { Id name
; Bool external
;
178 if (! compute_index(ty
,name
,external
)) return;
180 { pr("%^int cached__;"
181 "%^if (r__ && boxed(redex) && (cached__ = get_%s_state(%s)) != BURS::undefined_state)"
182 "%^{ s__ = cached__; return%s; }",
183 name
, redex
, (Fmap
->is_applicative
? " redex" : ""));
185 { pr("%^int cached__;"
186 "%^if (r__ && boxed(redex) && (cached__ = %s->get_%s_state()) != BURS::undefined_state)"
187 "%^{ s__ = cached__; return%s; }",
188 redex
, name
, (Fmap
->is_applicative
? " redex" : ""));
192 ///////////////////////////////////////////////////////////////////////////////
194 // Method to emit code for setting the index state
196 ///////////////////////////////////////////////////////////////////////////////
197 void RewritingCompiler::gen_set_rewrite_state_and_rule(Ty ty
, Id redex
)
198 { Id name
; Bool external
;
199 if (! compute_index(ty
,name
,external
)) return;
201 { pr("%^if (boxed(redex)) {%+"
202 "%^set_%s_state(%s,s__);",name
,redex
);
203 if (Fmap
->gen_reducers
)
204 pr("%^set_%s_rule(%s,rule__);",name
,redex
);
207 { pr("%^if (boxed(redex)) {%+"
208 "%^%s->set_%s_state(s__);",redex
,name
);
209 if (Fmap
->gen_reducers
)
210 pr("%^%s->set_%s_rule(rule__);",redex
,name
);
215 ///////////////////////////////////////////////////////////////////////////////
217 // Method to emit code for retrieving the cached rule
219 ///////////////////////////////////////////////////////////////////////////////
220 void RewritingCompiler::gen_get_rewrite_rule(Ty ty
, Id redex
)
221 { Id name
; Bool external
;
222 if (! compute_index(ty
,name
,external
))
223 { error("%Ltype %T is no index defined in treeparser mode rewrite class %s\n",
224 ty
, Fmap
->class_name
);
228 { pr("get_%s_rule(%s)", name
, redex
);
230 { pr("%s->get_%s_rule()", redex
, name
);
233 #line 208 "rwgen5.pcc"
235 ------------------------------- Statistics -------------------------------
236 Merge matching rules = yes
237 Number of DFA nodes merged = 0
238 Number of ifs generated = 0
239 Number of switches generated = 0
242 Adaptive matching = enabled
243 Fast string matching = disabled
244 Inline downcasts = enabled
245 --------------------------------------------------------------------------