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 "codegen.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
8 ///////////////////////////////////////////////////////////////////////////////
10 // This file implements the low level routine for generating C++ output->
12 ///////////////////////////////////////////////////////////////////////////////
15 #include <AD/strings/charesc.h>
23 ///////////////////////////////////////////////////////////////////////////////
25 // Code generator constructor and destructor
27 ///////////////////////////////////////////////////////////////////////////////
29 : output(&std::cerr
), anchored(true), tabbing(0), tab_unit(3) {}
30 CodeGen::~CodeGen() {}
31 void CodeGen::set_stream(std::ostream
& s
) { output
= &s
; }
33 ///////////////////////////////////////////////////////////////////////////////
35 // Convert literals to a type string.
37 ///////////////////////////////////////////////////////////////////////////////
38 #line 31 "codegen.pcc"
39 #line 38 "codegen.pcc"
40 Id
literal_type_of (Literal x_1
);
41 Id
literal_type_of (Literal x_1
)
44 case a_Literal::tag_INTlit
: {
45 #line 31 "codegen.pcc"
47 #line 31 "codegen.pcc"
49 case a_Literal::tag_BOOLlit
: {
50 #line 34 "codegen.pcc"
52 #line 34 "codegen.pcc"
54 case a_Literal::tag_CHARlit
: {
55 #line 33 "codegen.pcc"
57 #line 33 "codegen.pcc"
59 case a_Literal::tag_REALlit
: {
60 #line 32 "codegen.pcc"
62 #line 32 "codegen.pcc"
64 case a_Literal::tag_QUARKlit
: {
65 #line 36 "codegen.pcc"
67 #line 36 "codegen.pcc"
69 case a_Literal::tag_BIGINTlit
: {
70 #line 37 "codegen.pcc"
72 #line 37 "codegen.pcc"
75 #line 35 "codegen.pcc"
77 #line 35 "codegen.pcc"
81 #line 38 "codegen.pcc"
82 #line 38 "codegen.pcc"
85 ///////////////////////////////////////////////////////////////////////////////
87 // Emit a string with indenting.
89 ///////////////////////////////////////////////////////////////////////////////
90 void CodeGen::gen_code(const char * code
)
91 { const char * p
, * q
;
94 for (p
= code
; *p
; ) {
98 if (tabbing
== 0) my_tab
= 0;
99 else for (my_tab
= 0, q
= p
; *q
== ' '; q
++) my_tab
++;
102 for (t
= my_tab
; *p
== ' ' && t
> 0; p
++) t
--;
103 for (t
= tabbing
; t
> 0; t
--) output
->put(' ');
105 for (t
= tabbing
; *p
== ' ' && t
> 0; p
++) t
--;
106 for ( ; t
> 0; t
--) output
->put(' ');
109 for ( ; *p
== ' '; p
++); output
->put(' ');
113 if (*p
== '\0') break;
115 if (*p
== '\n') { line_no
++; anchored
= true; p
++; break; }
121 ///////////////////////////////////////////////////////////////////////////////
123 // Decode a format string and dispatch to various printing routines.
125 ///////////////////////////////////////////////////////////////////////////////
126 std::ostream
& CodeGen::outv(const char * fmt
, va_list arg
)
128 while ((c
= *fmt
++) != 0)
131 case 'i': (*output
)<< va_arg(arg
,int); anchored
= false; break;
132 case 'c': c
= (unsigned char)va_arg(arg
,int);
133 output
->put(c
); anchored
= (c
== '\n'); break;
134 case 'C': gen_code(va_arg(arg
,const char *)); break;
135 case 's': { const char * s
= va_arg(arg
,const char *);
138 anchored
= (s
[len
-1] == '\n');
140 case 'S': (*output
)<< mangle(va_arg(arg
,const char *));
143 case 'q': (*output
)<< va_arg(arg
,QualId
); anchored
= false; break;
144 case 'e': (*output
)<< va_arg(arg
,Exp
); anchored
= false; break;
145 case 'f': { Bool save
= pretty_print_exp
;
146 pretty_print_exp
= true;
147 (*output
)<< va_arg(arg
,Exp
); anchored
= false;
148 pretty_print_exp
= save
;
150 case 'E': { Exp e
= va_arg(arg
,Exp
);
152 #line 106 "codegen.pcc"
153 #line 109 "codegen.pcc"
157 case a_Exp::tag_MARKEDexp
: {
158 #line 108 "codegen.pcc"
159 pr ("%D", MARKEDdecl(((Exp_MARKEDexp
*)e
)->_1
, EXPdecl(((Exp_MARKEDexp
*)e
)->_2
)));
160 #line 108 "codegen.pcc"
164 #line 109 "codegen.pcc"
166 #line 109 "codegen.pcc"
171 #line 110 "codegen.pcc"
172 #line 110 "codegen.pcc"
176 case 'l': (*output
)<< va_arg(arg
,Literal
); anchored
= false; break;
177 case 'p': (*output
)<< va_arg(arg
,Pat
); anchored
= false; break;
178 case 'r': (*output
)<< va_arg(arg
,MatchRule
); anchored
= false; break;
179 case 'b': { Ty ty
= va_arg (arg
,Ty
);
180 Id name
= va_arg (arg
,Id
);
181 Id id
= mangle(name
);
182 Parameter p
= (Parameter
)va_arg (arg
,int);
183 Bool is_array
= is_array_constructor(name
);
187 { pr ("%^const int len_;%^");
188 body_ty
= mkarrayty(ty
,LITERALexp(INTlit(0)));
193 #line 129 "codegen.pcc"
194 #line 129 "codegen.pcc"
195 list_1_(Id("_len_"),list_1_(id
))
196 #line 129 "codegen.pcc"
197 #line 129 "codegen.pcc"
200 #line 130 "codegen.pcc"
201 #line 130 "codegen.pcc"
202 list_1_(integer_ty
,list_1_(mkptrty(QUALty(QUALconst
,ty
))))
203 #line 130 "codegen.pcc"
204 #line 130 "codegen.pcc"
208 print_parameter(*output
, body_ty
, id
, p
);
211 "%^inline int len() const { return len_; }"
212 "%^inline %t const& at(int i) const { return %S[i]; }"
213 "%^inline %t& at(int i) { return %S[i]; }"
214 "%^inline %t const * array() const { return %S; }"
215 "%^inline %t * array() { return %S; }",
216 ty
, "", name
, ty
, "", name
,
217 ty
, "", name
, ty
, "", name
);
220 print_parameter(*output
, ty
, id
, p
);
224 case 'T': (*output
)<< va_arg(arg
,Ty
); anchored
= false; break;
225 case 't': { Bool save
= pretty_print_ty
;
226 pretty_print_ty
= false;
227 Ty ty
= va_arg(arg
,Ty
);
228 ty_id
= va_arg(arg
,Id
);
231 pretty_print_ty
= save
;
233 case 'V': print_tyvars(*output
,va_arg(arg
,TyVars
), '<', '>', false);
234 anchored
= false; break;
235 case 'P': { Tys tys
= va_arg(arg
,Tys
);
236 Bool save
= pretty_print_ty
;
237 pretty_print_ty
= false;
238 if (tys
)(*output
)<< '<' << tys
<< '>';
239 pretty_print_ty
= save
;
242 case 'Q': (*output
)<< va_arg(arg
,Pid
); anchored
= false; break;
243 case 'H': print_tyvars(*output
,va_arg(arg
,TyVars
), '<', '>', true);
244 anchored
= false; break;
245 case 'v': print_tyvars(*output
,va_arg(arg
,TyVars
), '(', ')', false);
246 anchored
= false; break;
247 case '#': { int l
= va_arg(arg
,int);
248 const char * f
= va_arg(arg
,const char *);
249 if (options
.line_directives
)
250 { if (! anchored
)(*output
)<< '\n';
251 (*output
)<< "#line " << l
<< " \"" << f
<< "\"\n";
255 case '!': { const Loc
* l
= va_arg(arg
, const Loc
*);
256 if (! anchored
)(*output
)<< '\n';
257 if (options
.GNU_style_message
)
258 (*output
)<< l
->file_name
<< ':'
259 << l
->begin_line
<< ": ";
261 (*output
)<< '"' << l
->file_name
<< "\", line "
262 << l
->begin_line
<< ": ";
265 case 'L': if (options
.GNU_style_message
)
266 (*output
)<< file
<< ':' << line
<< ": ";
268 (*output
)<< '"' << file
<< "\", line " << line
<< ": ";
271 case 'w': if (options
.strict_checking
) errors
++;
272 else(*output
)<< "warning: ";
275 case 'M': (*output
)<< va_arg(arg
,Match
); anchored
= false; break;
276 case 'n': if (! anchored
)(*output
)<< '\n'; anchored
= true; break;
277 case 'I': { Inherits i
= va_arg(arg
,Inherits
);
281 case 'U': { Exp exp
= va_arg(arg
,Exp
);
282 Ty ty
= va_arg(arg
,Ty
);
283 (*output
) << MatchCompiler::untag(exp
,ty
);
285 case '*': { Cons cons
= va_arg(arg
,Cons
);
286 Bool normalized
= va_arg(arg
,int);
287 (*output
) << MatchCompiler::tag_name_of(cons
,
290 case '%': (*output
)<< '%'; anchored
= false; break;
291 case '?': if (! anchored
) break;
292 case '^': { if (! anchored
)(*output
)<< '\n';
293 if (tabbing
< 0) error ("Tab = %i\n", tabbing
);
294 for (int i
= tabbing
; i
> 0; i
--)(*output
)<< ' ';
295 anchored
= (tabbing
== 0);
297 case '+': tabbing
+= tab_unit
; break;
298 case '-': tabbing
-= tab_unit
; break;
299 case '/': { for (int i
= 79 - tabbing
; i
> 0; i
--)(*output
)<< '/';
300 (*output
)<< '\n'; anchored
= true;
302 case '=': (*output
)<< "_equal_" << literal_type_of(va_arg(arg
,Literal
)); break;
303 case '<': (*output
)<< "_less_" << literal_type_of(va_arg(arg
,Literal
)); break;
304 default: arg
= printer(fmt
[-1],arg
); break;
307 else { output
->put(c
); anchored
= (c
== '\n'); }
312 ///////////////////////////////////////////////////////////////////////////////
316 ///////////////////////////////////////////////////////////////////////////////
317 std::ostream
& CodeGen::pr(const char * fmt
, ...)
324 #line 249 "codegen.pcc"
326 ------------------------------- Statistics -------------------------------
327 Merge matching rules = yes
328 Number of DFA nodes merged = 37
329 Number of ifs generated = 1
330 Number of switches generated = 2
333 Adaptive matching = enabled
334 Fast string matching = disabled
335 Inline downcasts = enabled
336 --------------------------------------------------------------------------