2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 module Ast0
= Ast0_cocci
25 module U
= Pretty_print_cocci
27 let quiet = ref true (* true = no decoration on - context, etc *)
29 let full_ids = ref false (* true = print rule name as well *)
32 force_newline
(); print_string
" "; open_box
0
35 close_box
(); force_newline
()
37 let print_option = Common.do_option
38 let print_between = Common.print_between
40 (* --------------------------------------------------------------------- *)
43 let meta_pos = function
44 Ast0.MetaPos
(name
,_
,_
) ->
46 let (_
,name
) = Ast0.unwrap_mcode name
in
48 | Ast0.NoMetaPos
-> ()
50 (* --------------------------------------------------------------------- *)
53 let mcodekind brackets fn x info mc
=
54 List.iter
(function (s
,_
) -> print_string s
) info
.Ast0.strings_before
;
56 Ast0.MINUS
(plus_stream
) ->
62 Some x
-> ("[","]^"^
(string_of_int x
))
64 let (plus_stream
,_
) = !plus_stream
in
67 else (print_string
"-";
68 print_string lb
; fn x
; print_string rb
);
69 U.print_anything
">>> " plus_stream
70 | Ast0.CONTEXT
(plus_streams
) ->
76 Some x
-> ("[",("]^"^
(string_of_int x
))) | None
-> ("","") in
77 let (plus_streams
,t1
,t2
) = !plus_streams
in
80 print_string lb
; fn x
; print_string rb
)
82 | Ast0.PLUS _
-> print_int
(info
.Ast0.pos_info
.Ast0.column
); fn x
83 | Ast0.MIXED
(plus_streams
) ->
89 match brackets
with Some x
-> "^"^
(string_of_int x
) | None
-> "" in
91 let (plus_streams
,_
,_
) = !plus_streams
in
92 U.print_around
(function x
-> print_string lb
; fn x
; print_string rb
)
94 List.iter
(function (s
,_
) -> print_string s
) info
.Ast0.strings_after
96 let mcode fn
(x
,_
,info
,mc
,pos
,adj
) =
97 let fn x
= fn x
; meta_pos !pos
in
98 mcodekind (Some info
.Ast0.pos_info
.Ast0.line_start
)(*None*) fn x info mc
100 let print_context x
fn =
101 mcodekind (Some
(Ast0.get_line x
)) fn () (Ast0.get_info x
)
102 (Ast0.get_mcodekind x
)
104 let print_meta (ctx
,name
) =
105 if !full_ids then (print_string ctx
; print_string
":");
108 (* --------------------------------------------------------------------- *)
109 (* --------------------------------------------------------------------- *)
112 let dots between
fn d
=
115 match Ast0.unwrap d
with
116 Ast0.DOTS
(l
) -> print_between between
fn l
117 | Ast0.CIRCLES
(l
) -> print_between between
fn l
118 | Ast0.STARS
(l
) -> print_between between
fn l
)
120 (* --------------------------------------------------------------------- *)
122 let print_types = function
126 Format.print_flush
();
127 print_between (function _
-> print_string
", ") Type_cocci.typeC ty
;
128 Format.print_flush
();
131 (* --------------------------------------------------------------------- *)
137 match Ast0.unwrap i
with
138 Ast0.Id
(name
) -> mcode print_string name
139 | Ast0.MetaId
(name
,_
,_
) -> mcode print_meta name
140 | Ast0.MetaFunc
(name
,_
,_
) -> mcode print_meta name
141 | Ast0.MetaLocalFunc
(name
,_
,_
) -> mcode print_meta name
142 | Ast0.OptIdent
(id
) -> print_string
"?"; ident id
143 | Ast0.UniqueIdent
(id
) -> print_string
"!"; ident id
)
145 (* --------------------------------------------------------------------- *)
148 let print_string_box s
= print_string s
; open_box
0
150 let rec expression e
=
151 print_option Type_cocci.typeC
(Ast0.get_type e
);
154 match Ast0.unwrap e
with
155 Ast0.Ident
(id
) -> ident id
156 | Ast0.Constant
(const
) -> mcode U.constant const
157 | Ast0.FunCall
(fn,lp
,args
,rp
) ->
158 expression fn; mcode print_string_box lp
;
159 let _ = dots (function _ -> ()) expression args
in
160 close_box
(); mcode print_string rp
161 | Ast0.Assignment
(left
,op
,right
,_) ->
162 expression left
; print_string
" "; mcode U.assignOp op
;
163 print_string
" "; expression right
164 | Ast0.CondExpr
(exp1
,why
,exp2
,colon
,exp3
) ->
165 expression exp1
; print_string
" "; mcode print_string why
;
166 print_option (function e
-> print_string
" "; expression e
) exp2
;
167 print_string
" "; mcode print_string colon
; expression exp3
168 | Ast0.Postfix
(exp
,op
) -> expression exp
; mcode U.fixOp op
169 | Ast0.Infix
(exp
,op
) -> mcode U.fixOp op
; expression exp
170 | Ast0.Unary
(exp
,op
) -> mcode U.unaryOp op
; expression exp
171 | Ast0.Binary
(left
,op
,right
) ->
173 expression left
; print_string
" "; mcode U.binaryOp op
;
174 print_string
" "; expression right
;
176 | Ast0.Nested
(left
,op
,right
) ->
178 expression left
; print_string
" "; mcode U.binaryOp op
;
179 print_string
" "; expression right
;
181 | Ast0.Paren
(lp
,exp
,rp
) ->
182 mcode print_string_box lp
; expression exp
; close_box
();
183 mcode print_string rp
184 | Ast0.ArrayAccess
(exp1
,lb
,exp2
,rb
) ->
185 expression exp1
; mcode print_string_box lb
; expression exp2
;
186 close_box
(); mcode print_string rb
187 | Ast0.RecordAccess
(exp
,pt
,field
) ->
188 expression exp
; mcode print_string pt
; ident field
189 | Ast0.RecordPtAccess
(exp
,ar
,field
) ->
190 expression exp
; mcode print_string ar
; ident field
191 | Ast0.Cast
(lp
,ty
,rp
,exp
) ->
192 mcode print_string_box lp
; typeC ty
; close_box
();
193 mcode print_string rp
; expression exp
194 | Ast0.SizeOfExpr
(szf
,exp
) ->
195 mcode print_string szf
; expression exp
196 | Ast0.SizeOfType
(szf
,lp
,ty
,rp
) ->
197 mcode print_string szf
;
198 mcode print_string_box lp
; typeC ty
; close_box
();
199 mcode print_string rp
200 | Ast0.TypeExp
(ty
) -> typeC ty
201 | Ast0.MetaErr
(name
,_,_) -> mcode print_meta name
202 | Ast0.MetaExpr
(name
,_,ty
,_,pure
) ->
203 mcode print_meta name
; print_types ty
(*;
206 Ast0.Pure -> print_string "pure"
207 | Ast0.Impure -> print_string "impure"
208 | Ast0.Context -> print_string "context"
209 | Ast0.PureContext -> print_string "pure_context")*)
210 | Ast0.MetaExprList
(name
,_,_) -> mcode print_meta name
211 | Ast0.EComma
(cm
) -> mcode print_string cm
; print_space
()
212 | Ast0.DisjExpr
(_,exp_list
,_,_) ->
213 print_string
"\n("; force_newline
();
215 (function _ -> print_string
"\n|"; force_newline
())
218 | Ast0.NestExpr
(starter
,expr_dots
,ender
,None
,multi
) ->
219 mcode print_string starter
;
220 start_block(); dots force_newline
expression expr_dots
; end_block();
221 mcode print_string ender
222 | Ast0.NestExpr
(starter
,expr_dots
,ender
,Some whencode
,multi
) ->
223 mcode print_string starter
; print_string
" WHEN != ";
225 start_block(); dots force_newline
expression expr_dots
; end_block();
226 mcode print_string ender
227 | Ast0.Edots
(dots,Some whencode
)
228 | Ast0.Ecircles
(dots,Some whencode
)
229 | Ast0.Estars
(dots,Some whencode
) ->
230 mcode print_string
dots; print_string
" WHEN != ";
232 | Ast0.Edots
(dots,None
)
233 | Ast0.Ecircles
(dots,None
)
234 | Ast0.Estars
(dots,None
) -> mcode print_string
dots
235 | Ast0.OptExp
(exp
) -> print_string
"?"; expression exp
236 | Ast0.UniqueExp
(exp
) -> print_string
"!"; expression exp
)
238 and expression_dots x
= dots (function _ -> ()) expression x
240 (* --------------------------------------------------------------------- *)
243 and print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) fn =
244 typeC ty
; mcode print_string lp1
; mcode print_string star
; fn();
245 mcode print_string rp1
; mcode print_string lp2
;
246 parameter_list params
; mcode print_string rp2
248 and print_function_type
(ty
,lp1
,params
,rp1
) fn =
249 print_option typeC ty
; fn(); mcode print_string lp1
;
250 parameter_list params
; mcode print_string rp1
255 match Ast0.unwrap t
with
256 Ast0.ConstVol
(cv
,ty
) ->
257 mcode U.const_vol cv
; print_string
" "; typeC ty
258 | Ast0.BaseType
(ty
,strings
) ->
259 List.iter
(function s
-> mcode print_string s
; print_string
" ")
261 | Ast0.Signed
(sgn
,ty
) -> mcode U.sign sgn
; print_option typeC ty
262 | Ast0.Pointer
(ty
,star
) -> typeC ty
; mcode print_string star
263 | Ast0.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
264 print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
)
266 | Ast0.FunctionType
(ty
,lp1
,params
,rp1
) ->
267 print_function_type
(ty
,lp1
,params
,rp1
) (function _ -> ())
268 | Ast0.Array
(ty
,lb
,size
,rb
) ->
269 typeC ty
; mcode print_string lb
; print_option expression size
;
270 mcode print_string rb
271 | Ast0.EnumName
(kind
,name
) -> mcode print_string kind
; print_string
" ";
273 | Ast0.StructUnionName
(kind
,name
) ->
274 mcode U.structUnion kind
;
275 print_option (function x
-> ident x
; print_string
" ") name
276 | Ast0.StructUnionDef
(ty
,lb
,decls
,rb
) ->
277 typeC ty
; mcode print_string lb
;
278 dots force_newline declaration decls
;
279 mcode print_string rb
280 | Ast0.TypeName
(name
)-> mcode print_string name
; print_string
" "
281 | Ast0.MetaType
(name
,_)-> mcode print_meta name
; print_string
" "
282 | Ast0.DisjType
(lp
,types
,mids
,rp
) ->
283 print_string
"\n"; mcode print_string lp
; force_newline
();
285 (function _ -> print_string
"\n|"; force_newline
())
287 print_string
"\n"; mcode print_string rp
288 | Ast0.OptType
(ty
) -> print_string
"?"; typeC ty
289 | Ast0.UniqueType
(ty
) -> print_string
"!"; typeC ty
)
291 (* --------------------------------------------------------------------- *)
292 (* Variable declaration *)
293 (* Even if the Cocci program specifies a list of declarations, they are
294 split out into multiple declarations of a single variable each. *)
296 and print_named_type ty id
=
297 match Ast0.unwrap ty
with
298 Ast0.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
299 print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
)
300 (function _ -> print_string
" "; ident id
)
301 | Ast0.FunctionType
(ty
,lp1
,params
,rp1
) ->
302 print_function_type
(ty
,lp1
,params
,rp1
)
303 (function _ -> print_string
" "; ident id
)
304 | Ast0.Array
(ty
,lb
,size
,rb
) ->
306 match Ast0.unwrap ty
with
307 Ast0.Array
(ty
,lb
,size
,rb
) ->
311 mcode print_string lb
;
312 print_option expression size
;
313 mcode print_string rb
)
314 | _ -> typeC ty
; ident id
; k
() in
315 loop ty
(function _ -> ())
316 | _ -> typeC ty
; ident id
321 match Ast0.unwrap d
with
322 Ast0.Init
(stg
,ty
,id
,eq
,ini
,sem
) ->
323 print_option (mcode U.storage
) stg
;
324 print_named_type ty id
;
326 mcode print_string eq
; print_string
" "; initialiser ini
;
327 mcode print_string sem
328 | Ast0.UnInit
(stg
,ty
,id
,sem
) ->
329 print_option (mcode U.storage
) stg
; print_named_type ty id
;
330 mcode print_string sem
331 | Ast0.MacroDecl
(name
,lp
,args
,rp
,sem
) ->
332 ident name
; mcode print_string_box lp
;
333 let _ = dots (function _ -> ()) expression args
in
334 close_box
(); mcode print_string rp
; mcode print_string sem
335 | Ast0.TyDecl
(ty
,sem
) -> typeC ty
; mcode print_string sem
336 | Ast0.Typedef
(stg
,ty
,id
,sem
) ->
337 mcode print_string stg
; typeC ty
; typeC id
;
338 mcode print_string sem
339 | Ast0.DisjDecl
(_,decls
,_,_) ->
340 print_string
"\n("; force_newline
();
342 (function _ -> print_string
"\n|"; force_newline
())
345 | Ast0.Ddots
(dots,Some whencode
) ->
346 mcode print_string
dots; print_string
" when != ";
348 | Ast0.Ddots
(dots,None
) -> mcode print_string
dots
349 | Ast0.OptDecl
(decl
) -> print_string
"?"; declaration decl
350 | Ast0.UniqueDecl
(decl
) -> print_string
"!"; declaration decl
)
352 and declaration_dots l
= dots (function _ -> ()) declaration l
354 (* --------------------------------------------------------------------- *)
360 match Ast0.unwrap i
with
361 Ast0.MetaInit
(name
,_)-> mcode print_meta name
; print_string
" "
362 | Ast0.InitExpr
(exp
) -> expression exp
363 | Ast0.InitList
(lb
,initlist
,rb
) ->
364 mcode print_string lb
; open_box
0;
365 let _ = dots (function _ -> ()) initialiser initlist
in
366 close_box
(); mcode print_string rb
367 | Ast0.InitGccExt
(designators
,eq
,ini
) ->
368 List.iter designator designators
; print_string
" ";
369 mcode print_string eq
; print_string
" "; initialiser ini
370 | Ast0.InitGccName
(name
,eq
,ini
) ->
371 ident name
; mcode print_string eq
; initialiser ini
372 | Ast0.IComma
(cm
) -> mcode print_string cm
; force_newline
()
373 | Ast0.Idots
(d
,Some whencode
) ->
374 mcode print_string d
; print_string
" WHEN != ";
376 | Ast0.Idots
(d
,None
) -> mcode print_string d
377 | Ast0.OptIni
(ini
) -> print_string
"?"; initialiser ini
378 | Ast0.UniqueIni
(ini
) -> print_string
"!"; initialiser ini
)
380 and designator
= function
381 Ast0.DesignatorField
(dot
,id
) -> mcode print_string dot
; ident id
382 | Ast0.DesignatorIndex
(lb
,exp
,rb
) ->
383 mcode print_string lb
; expression exp
; mcode print_string rb
384 | Ast0.DesignatorRange
(lb
,min
,dots,max
,rb
) ->
385 mcode print_string lb
; expression min
; mcode print_string
dots;
386 expression max
; mcode print_string rb
388 and initialiser_list l
= dots (function _ -> ()) initialiser l
390 (* --------------------------------------------------------------------- *)
393 and parameterTypeDef p
=
396 match Ast0.unwrap p
with
397 Ast0.VoidParam
(ty
) -> typeC ty
398 | Ast0.Param
(ty
,Some id
) -> print_named_type ty id
399 | Ast0.Param
(ty
,None
) -> typeC ty
400 | Ast0.MetaParam
(name
,_) -> mcode print_meta name
401 | Ast0.MetaParamList
(name
,_,_) -> mcode print_meta name
402 | Ast0.PComma
(cm
) -> mcode print_string cm
; print_space
()
403 | Ast0.Pdots
(dots) -> mcode print_string
dots
404 | Ast0.Pcircles
(dots) -> mcode print_string
dots
405 | Ast0.OptParam
(param
) -> print_string
"?"; parameterTypeDef param
406 | Ast0.UniqueParam
(param
) -> print_string
"!"; parameterTypeDef param
)
408 and parameter_list l
= dots (function _ -> ()) parameterTypeDef l
410 (* --------------------------------------------------------------------- *)
413 and statement arity s
=
416 match Ast0.unwrap s
with
417 Ast0.FunDecl
(_,fninfo
,name
,lp
,params
,rp
,lbrace
,body
,rbrace
) ->
419 List.iter print_fninfo fninfo
;
420 ident name
; mcode print_string_box lp
;
421 parameter_list params
; close_box
(); mcode print_string rp
;
423 print_string arity
; mcode print_string lbrace
; start_block();
424 dots force_newline
(statement arity
) body
;
425 end_block(); print_string arity
; mcode print_string rbrace
426 | Ast0.Decl
(_,decl
) -> print_string arity
; declaration decl
427 | Ast0.Seq
(lbrace
,body
,rbrace
) ->
428 print_string arity
; mcode print_string lbrace
; start_block();
429 dots force_newline
(statement arity
) body
;
430 end_block(); print_string arity
; mcode print_string rbrace
431 | Ast0.ExprStatement
(exp
,sem
) ->
432 print_string arity
; expression exp
; mcode print_string sem
433 | Ast0.IfThen
(iff
,lp
,exp
,rp
,branch1
,(info
,aft
)) ->
435 mcode print_string iff
; print_string
" "; mcode print_string_box lp
;
436 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
437 statement arity branch1
;
438 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
439 | Ast0.IfThenElse
(iff
,lp
,exp
,rp
,branch1
,els
,branch2
,(info
,aft
)) ->
441 mcode print_string iff
; print_string
" "; mcode print_string_box lp
;
442 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
443 statement arity branch1
;
444 print_string arity
; mcode print_string els
; print_string
" ";
445 statement arity branch2
;
446 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
447 | Ast0.While
(whl
,lp
,exp
,rp
,body
,(info
,aft
)) ->
449 mcode print_string whl
; print_string
" "; mcode print_string_box lp
;
450 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
451 statement arity body
;
452 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
453 | Ast0.Do
(d
,body
,whl
,lp
,exp
,rp
,sem
) ->
454 print_string arity
; mcode print_string d
; print_string
" ";
455 statement arity body
;
457 mcode print_string whl
; print_string
" "; mcode print_string_box lp
;
458 expression exp
; close_box
(); mcode print_string rp
;
459 mcode print_string sem
460 | Ast0.For
(fr
,lp
,e1
,sem1
,e2
,sem2
,e3
,rp
,body
,(info
,aft
)) ->
462 mcode print_string fr
; mcode print_string_box lp
;
463 print_option expression e1
; mcode print_string sem1
;
464 print_option expression e2
; mcode print_string sem2
;
465 print_option expression e3
; close_box
();
466 mcode print_string rp
; print_string
" "; statement arity body
;
467 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
468 | Ast0.Iterator
(nm
,lp
,args
,rp
,body
,(info
,aft
)) ->
470 ident nm
; print_string
" "; mcode print_string_box lp
;
471 let _ = dots (function _ -> ()) expression args
in
472 close_box
(); mcode print_string rp
; print_string
" ";
473 statement arity body
;
474 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
475 | Ast0.Switch
(switch
,lp
,exp
,rp
,lb
,decls
,cases
,rb
) ->
477 mcode print_string switch
; print_string
" ";
478 mcode print_string_box lp
; expression exp
; close_box
();
479 mcode print_string rp
; print_string
" "; mcode print_string lb
;
480 dots force_newline
(statement arity
) decls
;
481 dots force_newline
(case_line arity
) cases
;
482 mcode print_string rb
483 | Ast0.Break
(br
,sem
) ->
484 print_string arity
; mcode print_string br
; mcode print_string sem
485 | Ast0.Continue
(cont
,sem
) ->
486 print_string arity
; mcode print_string cont
; mcode print_string sem
487 | Ast0.Label
(l
,dd
) -> ident l
; print_string
":"
488 | Ast0.Goto
(goto
,l
,sem
) ->
489 mcode print_string goto
; ident l
; mcode print_string sem
490 | Ast0.Return
(ret
,sem
) ->
491 print_string arity
; mcode print_string ret
; mcode print_string sem
492 | Ast0.ReturnExpr
(ret
,exp
,sem
) ->
493 print_string arity
; mcode print_string ret
; print_string
" ";
494 expression exp
; mcode print_string sem
495 | Ast0.MetaStmt
(name
,pure
) ->
496 print_string arity
; mcode print_meta name
;(*
499 Ast0.Pure -> print_string "pure"
500 | Ast0.Impure -> print_string "impure"
501 | Ast0.Context -> print_string "context"
502 | Ast0.PureContext -> print_string "pure_context")*)
503 | Ast0.MetaStmtList
(name
,_) ->
504 print_string arity
; mcode print_meta name
505 | Ast0.Disj
(starter
,statement_dots_list
,_,ender
) ->
507 print_string
"\n"; mcode print_string starter
; force_newline
();
509 (function _ -> print_string
"\n|"; force_newline
())
510 (dots force_newline
(statement arity
))
512 print_string
"\n"; mcode print_string ender
513 | Ast0.Nest
(starter
,stmt_dots
,ender
,whn
,multi
) ->
515 mcode print_string starter
;
518 (whencode
(dots force_newline
(statement
"")) (statement
""))
522 dots force_newline
(statement arity
) stmt_dots
;
524 mcode print_string ender
525 | Ast0.Exp
(exp
) -> print_string arity
; expression exp
526 | Ast0.TopExp
(exp
) -> print_string arity
; expression exp
527 | Ast0.Ty
(ty
) -> print_string arity
; typeC ty
528 | Ast0.TopInit
(init
) -> initialiser init
529 | Ast0.Dots
(d
,whn
) | Ast0.Circles
(d
,whn
) | Ast0.Stars
(d
,whn
) ->
530 print_string arity
; mcode print_string d
;
532 (whencode
(dots force_newline
(statement
"")) (statement
""))
534 | Ast0.Include
(inc
,s
) ->
535 mcode print_string inc
; print_string
" "; mcode U.inc_file s
536 | Ast0.Define
(def
,id
,params
,body
) ->
537 mcode print_string def
; print_string
" "; ident id
;
538 print_define_parameters params
;
540 dots force_newline
(statement arity
) body
541 | Ast0.OptStm
(re
) -> statement
"?" re
542 | Ast0.UniqueStm
(re
) -> statement
"!" re
)
544 and print_define_parameters params
=
545 match Ast0.unwrap params
with
547 | Ast0.DParams
(lp
,params
,rp
) ->
548 mcode print_string lp
;
549 dots (function _ -> ()) print_define_param params
; mcode print_string rp
551 and print_define_param param
=
552 match Ast0.unwrap param
with
553 Ast0.DParam
(id
) -> ident id
554 | Ast0.DPComma
(comma
) -> mcode print_string comma
555 | Ast0.DPdots
(dots) -> mcode print_string
dots
556 | Ast0.DPcircles
(circles
) -> mcode print_string circles
557 | Ast0.OptDParam
(dp
) -> print_string
"?"; print_define_param dp
558 | Ast0.UniqueDParam
(dp
) -> print_string
"!"; print_define_param dp
560 and print_fninfo
= function
561 Ast0.FStorage
(stg
) -> mcode U.storage stg
562 | Ast0.FType
(ty
) -> typeC ty
563 | Ast0.FInline
(inline
) -> mcode print_string inline
564 | Ast0.FAttr
(attr
) -> mcode print_string attr
566 and whencode notfn alwaysfn
= function
568 print_string
" WHEN != "; open_box
0; notfn a
; close_box
()
569 | Ast0.WhenAlways a
->
570 print_string
" WHEN = "; open_box
0; alwaysfn a
; close_box
()
571 | Ast0.WhenModifier x
-> print_string
" WHEN "; U.print_when_modif x
572 | Ast0.WhenNotTrue a
->
573 print_string
" WHEN != TRUE "; open_box
0; expression a
; close_box
()
574 | Ast0.WhenNotFalse a
->
575 print_string
" WHEN != FALSE "; open_box
0; expression a
; close_box
()
577 and case_line arity c
=
580 match Ast0.unwrap c
with
581 Ast0.Default
(def
,colon
,code
) ->
583 mcode print_string def
; mcode print_string colon
; print_string
" ";
584 dots force_newline
(statement arity
) code
585 | Ast0.Case
(case
,exp
,colon
,code
) ->
587 mcode print_string case
; print_string
" "; expression exp
;
588 mcode print_string colon
; print_string
" ";
589 dots force_newline
(statement arity
) code
590 | Ast0.DisjCase
(starter
,case_lines
,mids
,ender
) ->
591 print_string
"\n("; force_newline
();
593 (function _ -> print_string
"\n|"; force_newline
())
594 (case_line arity
) case_lines
;
596 | Ast0.OptCase
(case
) -> case_line
"?" case
)
598 and statement_dots l
= dots (function _ -> ()) (statement
"") l
599 and case_dots l
= dots (function _ -> ()) (case_line
"") l
601 (* --------------------------------------------------------------------- *)
607 match Ast0.unwrap t
with
608 Ast0.FILEINFO
(old_file
,new_file
) ->
609 print_string
"--- "; mcode print_string old_file
; force_newline
();
610 print_string
"+++ "; mcode print_string new_file
611 | Ast0.DECL
(stmt
) -> statement
"" stmt
612 | Ast0.CODE
(stmt_dots
) ->
613 dots force_newline
(statement
"") stmt_dots
614 | Ast0.ERRORWORDS
(exps
) ->
615 print_string
"error words = [";
616 print_between (function _ -> print_string
", ") expression exps
;
619 print_string
"OTHER("; statement
"" s
; print_string
")")
622 print_between (function _ -> force_newline
(); force_newline
()) top_level
624 let unparse_anything x
=
628 Ast0.DotsExprTag
(d
) ->
629 print_string
"ExpDots:"; force_newline
();
631 | Ast0.DotsParamTag
(d
) ->
633 | Ast0.DotsInitTag
(d
) ->
635 | Ast0.DotsStmtTag
(d
) ->
636 print_string
"StmDots:"; force_newline
();
638 | Ast0.DotsDeclTag
(d
) ->
640 | Ast0.DotsCaseTag
(d
) ->
642 | Ast0.IdentTag
(d
) ->
644 | Ast0.ExprTag
(d
) | Ast0.ArgExprTag
(d
) | Ast0.TestExprTag
(d
) ->
645 print_string
"Exp:"; force_newline
();
647 | Ast0.TypeCTag
(d
) ->
649 | Ast0.ParamTag
(d
) ->
656 print_string
"Stm:"; force_newline
();
658 | Ast0.CaseLineTag
(d
) ->
662 | Ast0.IsoWhenTag
(x
) -> U.print_when_modif x
663 | Ast0.IsoWhenTTag
(e
) -> expression e
664 | Ast0.IsoWhenFTag
(e
) -> expression e
665 | Ast0.MetaPosTag
(var
) -> meta_pos var
);
670 print_string
"\n@@\n@@";
676 let unparse_to_string x
= Common.format_to_string
(function _ -> unparse x
)