2 module Ast0
= Ast0_cocci
3 module U
= Pretty_print_cocci
5 let quiet = ref true (* true = no decoration on - context, etc *)
7 let full_ids = ref false (* true = print rule name as well *)
10 force_newline
(); print_string
" "; open_box
0
13 close_box
(); force_newline
()
15 let print_option = Common.do_option
16 let print_between = Common.print_between
18 (* --------------------------------------------------------------------- *)
21 let meta_pos = function
22 Ast0.MetaPos
(name
,_
,_
) ->
24 let (_
,name
) = Ast0.unwrap_mcode name
in
26 | Ast0.NoMetaPos
-> ()
28 (* --------------------------------------------------------------------- *)
31 let mcodekind brackets fn x info mc
=
32 List.iter
(function (s
,_
) -> print_string s
) info
.Ast0.strings_before
;
34 Ast0.MINUS
(plus_stream
) ->
40 Some x
-> ("[","]^"^
(string_of_int x
))
42 let (plus_stream
,_
) = !plus_stream
in
45 else (print_string
"-";
46 print_string lb
; fn x
; print_string rb
);
47 U.print_anything
">>> " plus_stream
48 | Ast0.CONTEXT
(plus_streams
) ->
54 Some x
-> ("[",("]^"^
(string_of_int x
))) | None
-> ("","") in
55 let (plus_streams
,t1
,t2
) = !plus_streams
in
58 print_string lb
; fn x
; print_string rb
)
60 | Ast0.PLUS _
-> print_int
(info
.Ast0.pos_info
.Ast0.column
); fn x
61 | Ast0.MIXED
(plus_streams
) ->
67 match brackets
with Some x
-> "^"^
(string_of_int x
) | None
-> "" in
69 let (plus_streams
,_
,_
) = !plus_streams
in
70 U.print_around
(function x
-> print_string lb
; fn x
; print_string rb
)
72 List.iter
(function (s
,_
) -> print_string s
) info
.Ast0.strings_after
74 let mcode fn
(x
,_
,info
,mc
,pos
,adj
) =
75 let fn x
= fn x
; meta_pos !pos
in
76 mcodekind (Some info
.Ast0.pos_info
.Ast0.line_start
)(*None*) fn x info mc
78 let print_context x
fn =
79 mcodekind (Some
(Ast0.get_line x
)) fn () (Ast0.get_info x
)
80 (Ast0.get_mcodekind x
)
82 let print_meta (ctx
,name
) =
83 if !full_ids then (print_string ctx
; print_string
":");
86 (* --------------------------------------------------------------------- *)
87 (* --------------------------------------------------------------------- *)
90 let dots between
fn d
=
93 match Ast0.unwrap d
with
94 Ast0.DOTS
(l
) -> print_between between
fn l
95 | Ast0.CIRCLES
(l
) -> print_between between
fn l
96 | Ast0.STARS
(l
) -> print_between between
fn l
)
98 (* --------------------------------------------------------------------- *)
100 let print_types = function
104 Format.print_flush
();
105 print_between (function _
-> print_string
", ") Type_cocci.typeC ty
;
106 Format.print_flush
();
109 (* --------------------------------------------------------------------- *)
115 match Ast0.unwrap i
with
116 Ast0.Id
(name
) -> mcode print_string name
117 | Ast0.MetaId
(name
,_
,_
) -> mcode print_meta name
118 | Ast0.MetaFunc
(name
,_
,_
) -> mcode print_meta name
119 | Ast0.MetaLocalFunc
(name
,_
,_
) -> mcode print_meta name
120 | Ast0.OptIdent
(id
) -> print_string
"?"; ident id
121 | Ast0.UniqueIdent
(id
) -> print_string
"!"; ident id
)
123 (* --------------------------------------------------------------------- *)
126 let print_string_box s
= print_string s
; open_box
0
128 let rec expression e
=
129 print_option Type_cocci.typeC
(Ast0.get_type e
);
132 match Ast0.unwrap e
with
133 Ast0.Ident
(id
) -> ident id
134 | Ast0.Constant
(const
) -> mcode U.constant const
135 | Ast0.FunCall
(fn,lp
,args
,rp
) ->
136 expression fn; mcode print_string_box lp
;
137 let _ = dots (function _ -> ()) expression args
in
138 close_box
(); mcode print_string rp
139 | Ast0.Assignment
(left
,op
,right
,_) ->
140 expression left
; print_string
" "; mcode U.assignOp op
;
141 print_string
" "; expression right
142 | Ast0.CondExpr
(exp1
,why
,exp2
,colon
,exp3
) ->
143 expression exp1
; print_string
" "; mcode print_string why
;
144 print_option (function e
-> print_string
" "; expression e
) exp2
;
145 print_string
" "; mcode print_string colon
; expression exp3
146 | Ast0.Postfix
(exp
,op
) -> expression exp
; mcode U.fixOp op
147 | Ast0.Infix
(exp
,op
) -> mcode U.fixOp op
; expression exp
148 | Ast0.Unary
(exp
,op
) -> mcode U.unaryOp op
; expression exp
149 | Ast0.Binary
(left
,op
,right
) ->
151 expression left
; print_string
" "; mcode U.binaryOp op
;
152 print_string
" "; expression right
;
154 | Ast0.Nested
(left
,op
,right
) ->
156 expression left
; print_string
" "; mcode U.binaryOp op
;
157 print_string
" "; expression right
;
159 | Ast0.Paren
(lp
,exp
,rp
) ->
160 mcode print_string_box lp
; expression exp
; close_box
();
161 mcode print_string rp
162 | Ast0.ArrayAccess
(exp1
,lb
,exp2
,rb
) ->
163 expression exp1
; mcode print_string_box lb
; expression exp2
;
164 close_box
(); mcode print_string rb
165 | Ast0.RecordAccess
(exp
,pt
,field
) ->
166 expression exp
; mcode print_string pt
; ident field
167 | Ast0.RecordPtAccess
(exp
,ar
,field
) ->
168 expression exp
; mcode print_string ar
; ident field
169 | Ast0.Cast
(lp
,ty
,rp
,exp
) ->
170 mcode print_string_box lp
; typeC ty
; close_box
();
171 mcode print_string rp
; expression exp
172 | Ast0.SizeOfExpr
(szf
,exp
) ->
173 mcode print_string szf
; expression exp
174 | Ast0.SizeOfType
(szf
,lp
,ty
,rp
) ->
175 mcode print_string szf
;
176 mcode print_string_box lp
; typeC ty
; close_box
();
177 mcode print_string rp
178 | Ast0.TypeExp
(ty
) -> typeC ty
179 | Ast0.MetaErr
(name
,_,_) -> mcode print_meta name
180 | Ast0.MetaExpr
(name
,_,ty
,_,pure
) ->
181 mcode print_meta name
; print_types ty
(*;
184 Ast0.Pure -> print_string "pure"
185 | Ast0.Impure -> print_string "impure"
186 | Ast0.Context -> print_string "context"
187 | Ast0.PureContext -> print_string "pure_context")*)
188 | Ast0.MetaExprList
(name
,_,_) -> mcode print_meta name
189 | Ast0.EComma
(cm
) -> mcode print_string cm
; print_space
()
190 | Ast0.DisjExpr
(_,exp_list
,_,_) ->
191 print_string
"\n("; force_newline
();
193 (function _ -> print_string
"\n|"; force_newline
())
196 | Ast0.NestExpr
(starter
,expr_dots
,ender
,None
,multi
) ->
197 mcode print_string starter
;
198 start_block(); dots force_newline
expression expr_dots
; end_block();
199 mcode print_string ender
200 | Ast0.NestExpr
(starter
,expr_dots
,ender
,Some whencode
,multi
) ->
201 mcode print_string starter
; print_string
" WHEN != ";
203 start_block(); dots force_newline
expression expr_dots
; end_block();
204 mcode print_string ender
205 | Ast0.Edots
(dots,Some whencode
)
206 | Ast0.Ecircles
(dots,Some whencode
)
207 | Ast0.Estars
(dots,Some whencode
) ->
208 mcode print_string
dots; print_string
" WHEN != ";
210 | Ast0.Edots
(dots,None
)
211 | Ast0.Ecircles
(dots,None
)
212 | Ast0.Estars
(dots,None
) -> mcode print_string
dots
213 | Ast0.OptExp
(exp
) -> print_string
"?"; expression exp
214 | Ast0.UniqueExp
(exp
) -> print_string
"!"; expression exp
)
216 and expression_dots x
= dots (function _ -> ()) expression x
218 (* --------------------------------------------------------------------- *)
221 and print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) fn =
222 typeC ty
; mcode print_string lp1
; mcode print_string star
; fn();
223 mcode print_string rp1
; mcode print_string lp2
;
224 parameter_list params
; mcode print_string rp2
226 and print_function_type
(ty
,lp1
,params
,rp1
) fn =
227 print_option typeC ty
; fn(); mcode print_string lp1
;
228 parameter_list params
; mcode print_string rp1
233 match Ast0.unwrap t
with
234 Ast0.ConstVol
(cv
,ty
) ->
235 mcode U.const_vol cv
; print_string
" "; typeC ty
236 | Ast0.BaseType
(ty
,strings
) ->
237 List.iter
(function s
-> mcode print_string s
; print_string
" ")
239 | Ast0.Signed
(sgn
,ty
) -> mcode U.sign sgn
; print_option typeC ty
240 | Ast0.Pointer
(ty
,star
) -> typeC ty
; mcode print_string star
241 | Ast0.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
242 print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
)
244 | Ast0.FunctionType
(ty
,lp1
,params
,rp1
) ->
245 print_function_type
(ty
,lp1
,params
,rp1
) (function _ -> ())
246 | Ast0.Array
(ty
,lb
,size
,rb
) ->
247 typeC ty
; mcode print_string lb
; print_option expression size
;
248 mcode print_string rb
249 | Ast0.EnumName
(kind
,name
) -> mcode print_string kind
; print_string
" ";
251 | Ast0.StructUnionName
(kind
,name
) ->
252 mcode U.structUnion kind
;
253 print_option (function x
-> ident x
; print_string
" ") name
254 | Ast0.StructUnionDef
(ty
,lb
,decls
,rb
) ->
255 typeC ty
; mcode print_string lb
;
256 dots force_newline declaration decls
;
257 mcode print_string rb
258 | Ast0.TypeName
(name
)-> mcode print_string name
; print_string
" "
259 | Ast0.MetaType
(name
,_)-> mcode print_meta name
; print_string
" "
260 | Ast0.DisjType
(lp
,types
,mids
,rp
) ->
261 print_string
"\n"; mcode print_string lp
; force_newline
();
263 (function _ -> print_string
"\n|"; force_newline
())
265 print_string
"\n"; mcode print_string rp
266 | Ast0.OptType
(ty
) -> print_string
"?"; typeC ty
267 | Ast0.UniqueType
(ty
) -> print_string
"!"; typeC ty
)
269 (* --------------------------------------------------------------------- *)
270 (* Variable declaration *)
271 (* Even if the Cocci program specifies a list of declarations, they are
272 split out into multiple declarations of a single variable each. *)
274 and print_named_type ty id
=
275 match Ast0.unwrap ty
with
276 Ast0.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
277 print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
)
278 (function _ -> print_string
" "; ident id
)
279 | Ast0.FunctionType
(ty
,lp1
,params
,rp1
) ->
280 print_function_type
(ty
,lp1
,params
,rp1
)
281 (function _ -> print_string
" "; ident id
)
282 | Ast0.Array
(ty
,lb
,size
,rb
) ->
284 match Ast0.unwrap ty
with
285 Ast0.Array
(ty
,lb
,size
,rb
) ->
289 mcode print_string lb
;
290 print_option expression size
;
291 mcode print_string rb
)
292 | _ -> typeC ty
; ident id
; k
() in
293 loop ty
(function _ -> ())
294 | _ -> typeC ty
; ident id
299 match Ast0.unwrap d
with
300 Ast0.Init
(stg
,ty
,id
,eq
,ini
,sem
) ->
301 print_option (mcode U.storage
) stg
;
302 print_named_type ty id
;
304 mcode print_string eq
; print_string
" "; initialiser ini
;
305 mcode print_string sem
306 | Ast0.UnInit
(stg
,ty
,id
,sem
) ->
307 print_option (mcode U.storage
) stg
; print_named_type ty id
;
308 mcode print_string sem
309 | Ast0.MacroDecl
(name
,lp
,args
,rp
,sem
) ->
310 ident name
; mcode print_string_box lp
;
311 let _ = dots (function _ -> ()) expression args
in
312 close_box
(); mcode print_string rp
; mcode print_string sem
313 | Ast0.TyDecl
(ty
,sem
) -> typeC ty
; mcode print_string sem
314 | Ast0.Typedef
(stg
,ty
,id
,sem
) ->
315 mcode print_string stg
; typeC ty
; typeC id
;
316 mcode print_string sem
317 | Ast0.DisjDecl
(_,decls
,_,_) ->
318 print_string
"\n("; force_newline
();
320 (function _ -> print_string
"\n|"; force_newline
())
323 | Ast0.Ddots
(dots,Some whencode
) ->
324 mcode print_string
dots; print_string
" when != ";
326 | Ast0.Ddots
(dots,None
) -> mcode print_string
dots
327 | Ast0.OptDecl
(decl
) -> print_string
"?"; declaration decl
328 | Ast0.UniqueDecl
(decl
) -> print_string
"!"; declaration decl
)
330 and declaration_dots l
= dots (function _ -> ()) declaration l
332 (* --------------------------------------------------------------------- *)
338 match Ast0.unwrap i
with
339 Ast0.MetaInit
(name
,_)-> mcode print_meta name
; print_string
" "
340 | Ast0.InitExpr
(exp
) -> expression exp
341 | Ast0.InitList
(lb
,initlist
,rb
) ->
342 mcode print_string lb
; open_box
0;
343 let _ = dots (function _ -> ()) initialiser initlist
in
344 close_box
(); mcode print_string rb
345 | Ast0.InitGccExt
(designators
,eq
,ini
) ->
346 List.iter designator designators
; print_string
" ";
347 mcode print_string eq
; print_string
" "; initialiser ini
348 | Ast0.InitGccName
(name
,eq
,ini
) ->
349 ident name
; mcode print_string eq
; initialiser ini
350 | Ast0.IComma
(cm
) -> mcode print_string cm
; force_newline
()
351 | Ast0.Idots
(d
,Some whencode
) ->
352 mcode print_string d
; print_string
" WHEN != ";
354 | Ast0.Idots
(d
,None
) -> mcode print_string d
355 | Ast0.OptIni
(ini
) -> print_string
"?"; initialiser ini
356 | Ast0.UniqueIni
(ini
) -> print_string
"!"; initialiser ini
)
358 and designator
= function
359 Ast0.DesignatorField
(dot
,id
) -> mcode print_string dot
; ident id
360 | Ast0.DesignatorIndex
(lb
,exp
,rb
) ->
361 mcode print_string lb
; expression exp
; mcode print_string rb
362 | Ast0.DesignatorRange
(lb
,min
,dots,max
,rb
) ->
363 mcode print_string lb
; expression min
; mcode print_string
dots;
364 expression max
; mcode print_string rb
366 and initialiser_list l
= dots (function _ -> ()) initialiser l
368 (* --------------------------------------------------------------------- *)
371 and parameterTypeDef p
=
374 match Ast0.unwrap p
with
375 Ast0.VoidParam
(ty
) -> typeC ty
376 | Ast0.Param
(ty
,Some id
) -> print_named_type ty id
377 | Ast0.Param
(ty
,None
) -> typeC ty
378 | Ast0.MetaParam
(name
,_) -> mcode print_meta name
379 | Ast0.MetaParamList
(name
,_,_) -> mcode print_meta name
380 | Ast0.PComma
(cm
) -> mcode print_string cm
; print_space
()
381 | Ast0.Pdots
(dots) -> mcode print_string
dots
382 | Ast0.Pcircles
(dots) -> mcode print_string
dots
383 | Ast0.OptParam
(param
) -> print_string
"?"; parameterTypeDef param
384 | Ast0.UniqueParam
(param
) -> print_string
"!"; parameterTypeDef param
)
386 and parameter_list l
= dots (function _ -> ()) parameterTypeDef l
388 (* --------------------------------------------------------------------- *)
391 and statement arity s
=
394 match Ast0.unwrap s
with
395 Ast0.FunDecl
(_,fninfo
,name
,lp
,params
,rp
,lbrace
,body
,rbrace
) ->
397 List.iter print_fninfo fninfo
;
398 ident name
; mcode print_string_box lp
;
399 parameter_list params
; close_box
(); mcode print_string rp
;
401 print_string arity
; mcode print_string lbrace
; start_block();
402 dots force_newline
(statement arity
) body
;
403 end_block(); print_string arity
; mcode print_string rbrace
404 | Ast0.Decl
(_,decl
) -> print_string arity
; declaration decl
405 | Ast0.Seq
(lbrace
,body
,rbrace
) ->
406 print_string arity
; mcode print_string lbrace
; start_block();
407 dots force_newline
(statement arity
) body
;
408 end_block(); print_string arity
; mcode print_string rbrace
409 | Ast0.ExprStatement
(exp
,sem
) ->
410 print_string arity
; expression exp
; mcode print_string sem
411 | Ast0.IfThen
(iff
,lp
,exp
,rp
,branch1
,(info
,aft
)) ->
413 mcode print_string iff
; print_string
" "; mcode print_string_box lp
;
414 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
415 statement arity branch1
;
416 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
417 | Ast0.IfThenElse
(iff
,lp
,exp
,rp
,branch1
,els
,branch2
,(info
,aft
)) ->
419 mcode print_string iff
; print_string
" "; mcode print_string_box lp
;
420 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
421 statement arity branch1
;
422 print_string arity
; mcode print_string els
; print_string
" ";
423 statement arity branch2
;
424 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
425 | Ast0.While
(whl
,lp
,exp
,rp
,body
,(info
,aft
)) ->
427 mcode print_string whl
; print_string
" "; mcode print_string_box lp
;
428 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
429 statement arity body
;
430 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
431 | Ast0.Do
(d
,body
,whl
,lp
,exp
,rp
,sem
) ->
432 print_string arity
; mcode print_string d
; print_string
" ";
433 statement arity body
;
435 mcode print_string whl
; print_string
" "; mcode print_string_box lp
;
436 expression exp
; close_box
(); mcode print_string rp
;
437 mcode print_string sem
438 | Ast0.For
(fr
,lp
,e1
,sem1
,e2
,sem2
,e3
,rp
,body
,(info
,aft
)) ->
440 mcode print_string fr
; mcode print_string_box lp
;
441 print_option expression e1
; mcode print_string sem1
;
442 print_option expression e2
; mcode print_string sem2
;
443 print_option expression e3
; close_box
();
444 mcode print_string rp
; print_string
" "; statement arity body
;
445 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
446 | Ast0.Iterator
(nm
,lp
,args
,rp
,body
,(info
,aft
)) ->
448 ident nm
; print_string
" "; mcode print_string_box lp
;
449 let _ = dots (function _ -> ()) expression args
in
450 close_box
(); mcode print_string rp
; print_string
" ";
451 statement arity body
;
452 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
,-1)
453 | Ast0.Switch
(switch
,lp
,exp
,rp
,lb
,decls
,cases
,rb
) ->
455 mcode print_string switch
; print_string
" ";
456 mcode print_string_box lp
; expression exp
; close_box
();
457 mcode print_string rp
; print_string
" "; mcode print_string lb
;
458 dots force_newline
(statement arity
) decls
;
459 dots force_newline
(case_line arity
) cases
;
460 mcode print_string rb
461 | Ast0.Break
(br
,sem
) ->
462 print_string arity
; mcode print_string br
; mcode print_string sem
463 | Ast0.Continue
(cont
,sem
) ->
464 print_string arity
; mcode print_string cont
; mcode print_string sem
465 | Ast0.Label
(l
,dd
) -> ident l
; print_string
":"
466 | Ast0.Goto
(goto
,l
,sem
) ->
467 mcode print_string goto
; ident l
; mcode print_string sem
468 | Ast0.Return
(ret
,sem
) ->
469 print_string arity
; mcode print_string ret
; mcode print_string sem
470 | Ast0.ReturnExpr
(ret
,exp
,sem
) ->
471 print_string arity
; mcode print_string ret
; print_string
" ";
472 expression exp
; mcode print_string sem
473 | Ast0.MetaStmt
(name
,pure
) ->
474 print_string arity
; mcode print_meta name
;(*
477 Ast0.Pure -> print_string "pure"
478 | Ast0.Impure -> print_string "impure"
479 | Ast0.Context -> print_string "context"
480 | Ast0.PureContext -> print_string "pure_context")*)
481 | Ast0.MetaStmtList
(name
,_) ->
482 print_string arity
; mcode print_meta name
483 | Ast0.Disj
(starter
,statement_dots_list
,_,ender
) ->
485 print_string
"\n"; mcode print_string starter
; force_newline
();
487 (function _ -> print_string
"\n|"; force_newline
())
488 (dots force_newline
(statement arity
))
490 print_string
"\n"; mcode print_string ender
491 | Ast0.Nest
(starter
,stmt_dots
,ender
,whn
,multi
) ->
493 mcode print_string starter
;
496 (whencode
(dots force_newline
(statement
"")) (statement
""))
500 dots force_newline
(statement arity
) stmt_dots
;
502 mcode print_string ender
503 | Ast0.Exp
(exp
) -> print_string arity
; expression exp
504 | Ast0.TopExp
(exp
) -> print_string arity
; expression exp
505 | Ast0.Ty
(ty
) -> print_string arity
; typeC ty
506 | Ast0.TopInit
(init
) -> initialiser init
507 | Ast0.Dots
(d
,whn
) | Ast0.Circles
(d
,whn
) | Ast0.Stars
(d
,whn
) ->
508 print_string arity
; mcode print_string d
;
510 (whencode
(dots force_newline
(statement
"")) (statement
""))
512 | Ast0.Include
(inc
,s
) ->
513 mcode print_string inc
; print_string
" "; mcode U.inc_file s
514 | Ast0.Define
(def
,id
,params
,body
) ->
515 mcode print_string def
; print_string
" "; ident id
;
516 print_define_parameters params
;
518 dots force_newline
(statement arity
) body
519 | Ast0.OptStm
(re
) -> statement
"?" re
520 | Ast0.UniqueStm
(re
) -> statement
"!" re
)
522 and print_define_parameters params
=
523 match Ast0.unwrap params
with
525 | Ast0.DParams
(lp
,params
,rp
) ->
526 mcode print_string lp
;
527 dots (function _ -> ()) print_define_param params
; mcode print_string rp
529 and print_define_param param
=
530 match Ast0.unwrap param
with
531 Ast0.DParam
(id
) -> ident id
532 | Ast0.DPComma
(comma
) -> mcode print_string comma
533 | Ast0.DPdots
(dots) -> mcode print_string
dots
534 | Ast0.DPcircles
(circles
) -> mcode print_string circles
535 | Ast0.OptDParam
(dp
) -> print_string
"?"; print_define_param dp
536 | Ast0.UniqueDParam
(dp
) -> print_string
"!"; print_define_param dp
538 and print_fninfo
= function
539 Ast0.FStorage
(stg
) -> mcode U.storage stg
540 | Ast0.FType
(ty
) -> typeC ty
541 | Ast0.FInline
(inline
) -> mcode print_string inline
542 | Ast0.FAttr
(attr
) -> mcode print_string attr
544 and whencode notfn alwaysfn
= function
546 print_string
" WHEN != "; open_box
0; notfn a
; close_box
()
547 | Ast0.WhenAlways a
->
548 print_string
" WHEN = "; open_box
0; alwaysfn a
; close_box
()
549 | Ast0.WhenModifier x
-> print_string
" WHEN "; U.print_when_modif x
550 | Ast0.WhenNotTrue a
->
551 print_string
" WHEN != TRUE "; open_box
0; expression a
; close_box
()
552 | Ast0.WhenNotFalse a
->
553 print_string
" WHEN != FALSE "; open_box
0; expression a
; close_box
()
555 and case_line arity c
=
558 match Ast0.unwrap c
with
559 Ast0.Default
(def
,colon
,code
) ->
561 mcode print_string def
; mcode print_string colon
; print_string
" ";
562 dots force_newline
(statement arity
) code
563 | Ast0.Case
(case
,exp
,colon
,code
) ->
565 mcode print_string case
; print_string
" "; expression exp
;
566 mcode print_string colon
; print_string
" ";
567 dots force_newline
(statement arity
) code
568 | Ast0.DisjCase
(starter
,case_lines
,mids
,ender
) ->
569 print_string
"\n("; force_newline
();
571 (function _ -> print_string
"\n|"; force_newline
())
572 (case_line arity
) case_lines
;
574 | Ast0.OptCase
(case
) -> case_line
"?" case
)
576 and statement_dots l
= dots (function _ -> ()) (statement
"") l
577 and case_dots l
= dots (function _ -> ()) (case_line
"") l
579 (* --------------------------------------------------------------------- *)
585 match Ast0.unwrap t
with
586 Ast0.FILEINFO
(old_file
,new_file
) ->
587 print_string
"--- "; mcode print_string old_file
; force_newline
();
588 print_string
"+++ "; mcode print_string new_file
589 | Ast0.DECL
(stmt
) -> statement
"" stmt
590 | Ast0.CODE
(stmt_dots
) ->
591 dots force_newline
(statement
"") stmt_dots
592 | Ast0.ERRORWORDS
(exps
) ->
593 print_string
"error words = [";
594 print_between (function _ -> print_string
", ") expression exps
;
597 print_string
"OTHER("; statement
"" s
; print_string
")")
600 print_between (function _ -> force_newline
(); force_newline
()) top_level
602 let unparse_anything x
=
606 Ast0.DotsExprTag
(d
) ->
607 print_string
"ExpDots:"; force_newline
();
609 | Ast0.DotsParamTag
(d
) ->
611 | Ast0.DotsInitTag
(d
) ->
613 | Ast0.DotsStmtTag
(d
) ->
614 print_string
"StmDots:"; force_newline
();
616 | Ast0.DotsDeclTag
(d
) ->
618 | Ast0.DotsCaseTag
(d
) ->
620 | Ast0.IdentTag
(d
) ->
622 | Ast0.ExprTag
(d
) | Ast0.ArgExprTag
(d
) | Ast0.TestExprTag
(d
) ->
623 print_string
"Exp:"; force_newline
();
625 | Ast0.TypeCTag
(d
) ->
627 | Ast0.ParamTag
(d
) ->
634 print_string
"Stm:"; force_newline
();
636 | Ast0.CaseLineTag
(d
) ->
640 | Ast0.IsoWhenTag
(x
) -> U.print_when_modif x
641 | Ast0.IsoWhenTTag
(e
) -> expression e
642 | Ast0.IsoWhenFTag
(e
) -> expression e
643 | Ast0.MetaPosTag
(var
) -> meta_pos var
);
648 print_string
"\n@@\n@@";
654 let unparse_to_string x
= Common.format_to_string
(function _ -> unparse x
)