2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
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 *)
30 force_newline
(); print_string
" "; open_box
0
33 close_box
(); force_newline
()
35 let print_option = Common.do_option
36 let print_between = Common.print_between
38 (* --------------------------------------------------------------------- *)
41 let meta_pos = function
42 Ast0.MetaPos
(name
,_
,_
) ->
44 let (_
,name
) = Ast0.unwrap_mcode name
in
46 | Ast0.NoMetaPos
-> ()
48 (* --------------------------------------------------------------------- *)
51 let mcodekind brackets fn x info mc
=
52 List.iter
(function (s
,_
) -> print_string s
) info
.Ast0.strings_before
;
54 Ast0.MINUS
(plus_stream
) ->
60 Some x
-> ("[","]^"^
(string_of_int x
))
62 let (plus_stream
,_
) = !plus_stream
in
65 else (print_string
"-";
66 print_string lb
; fn x
; print_string rb
);
67 U.print_anything
">>> " plus_stream
68 | Ast0.CONTEXT
(plus_streams
) ->
74 Some x
-> ("[",("]^"^
(string_of_int x
))) | None
-> ("","") in
75 let (plus_streams
,t1
,t2
) = !plus_streams
in
78 print_string lb
; fn x
; print_string rb
)
81 | Ast0.MIXED
(plus_streams
) ->
87 match brackets
with Some x
-> "^"^
(string_of_int x
) | None
-> "" in
89 let (plus_streams
,_
,_
) = !plus_streams
in
90 U.print_around
(function x
-> print_string lb
; fn x
; print_string rb
)
92 List.iter
(function (s
,_
) -> print_string s
) info
.Ast0.strings_after
94 let mcode fn
(x
,_
,info
,mc
,pos
) =
95 let fn x
= fn x
; meta_pos !pos
in
96 mcodekind (Some info
.Ast0.pos_info
.Ast0.line_start
)(*None*) fn x info mc
98 let print_context x
fn =
99 mcodekind (Some
(Ast0.get_line x
)) fn () (Ast0.get_info x
)
100 (Ast0.get_mcodekind x
)
102 let print_meta (_
,name
) = print_string name
104 (* --------------------------------------------------------------------- *)
105 (* --------------------------------------------------------------------- *)
108 let dots between
fn d
=
111 match Ast0.unwrap d
with
112 Ast0.DOTS
(l
) -> print_between between
fn l
113 | Ast0.CIRCLES
(l
) -> print_between between
fn l
114 | Ast0.STARS
(l
) -> print_between between
fn l
)
116 (* --------------------------------------------------------------------- *)
118 let print_types = function
122 Format.print_flush
();
123 print_between (function _
-> print_string
", ") Type_cocci.typeC ty
;
124 Format.print_flush
();
127 (* --------------------------------------------------------------------- *)
133 match Ast0.unwrap i
with
134 Ast0.Id
(name
) -> mcode print_string name
135 | Ast0.MetaId
(name
,_
,_
) -> mcode print_meta name
136 | Ast0.MetaFunc
(name
,_
,_
) -> mcode print_meta name
137 | Ast0.MetaLocalFunc
(name
,_
,_
) -> mcode print_meta name
138 | Ast0.OptIdent
(id
) -> print_string
"?"; ident id
139 | Ast0.UniqueIdent
(id
) -> print_string
"!"; ident id
)
141 (* --------------------------------------------------------------------- *)
144 let print_string_box s
= print_string s
; open_box
0
146 let rec expression e
=
147 print_option Type_cocci.typeC
(Ast0.get_type e
);
150 match Ast0.unwrap e
with
151 Ast0.Ident
(id
) -> ident id
152 | Ast0.Constant
(const
) -> mcode U.constant const
153 | Ast0.FunCall
(fn,lp
,args
,rp
) ->
154 expression fn; mcode print_string_box lp
;
155 let _ = dots (function _ -> ()) expression args
in
156 close_box
(); mcode print_string rp
157 | Ast0.Assignment
(left
,op
,right
,_) ->
158 expression left
; print_string
" "; mcode U.assignOp op
;
159 print_string
" "; expression right
160 | Ast0.CondExpr
(exp1
,why
,exp2
,colon
,exp3
) ->
161 expression exp1
; print_string
" "; mcode print_string why
;
162 print_option (function e
-> print_string
" "; expression e
) exp2
;
163 print_string
" "; mcode print_string colon
; expression exp3
164 | Ast0.Postfix
(exp
,op
) -> expression exp
; mcode U.fixOp op
165 | Ast0.Infix
(exp
,op
) -> mcode U.fixOp op
; expression exp
166 | Ast0.Unary
(exp
,op
) -> mcode U.unaryOp op
; expression exp
167 | Ast0.Binary
(left
,op
,right
) ->
169 expression left
; print_string
" "; mcode U.binaryOp op
;
170 print_string
" "; expression right
;
172 | Ast0.Nested
(left
,op
,right
) ->
174 expression left
; print_string
" "; mcode U.binaryOp op
;
175 print_string
" "; expression right
;
177 | Ast0.Paren
(lp
,exp
,rp
) ->
178 mcode print_string_box lp
; expression exp
; close_box
();
179 mcode print_string rp
180 | Ast0.ArrayAccess
(exp1
,lb
,exp2
,rb
) ->
181 expression exp1
; mcode print_string_box lb
; expression exp2
;
182 close_box
(); mcode print_string rb
183 | Ast0.RecordAccess
(exp
,pt
,field
) ->
184 expression exp
; mcode print_string pt
; ident field
185 | Ast0.RecordPtAccess
(exp
,ar
,field
) ->
186 expression exp
; mcode print_string ar
; ident field
187 | Ast0.Cast
(lp
,ty
,rp
,exp
) ->
188 mcode print_string_box lp
; typeC ty
; close_box
();
189 mcode print_string rp
; expression exp
190 | Ast0.SizeOfExpr
(szf
,exp
) ->
191 mcode print_string szf
; expression exp
192 | Ast0.SizeOfType
(szf
,lp
,ty
,rp
) ->
193 mcode print_string szf
;
194 mcode print_string_box lp
; typeC ty
; close_box
();
195 mcode print_string rp
196 | Ast0.TypeExp
(ty
) -> typeC ty
197 | Ast0.MetaErr
(name
,_,_) -> mcode print_meta name
198 | Ast0.MetaExpr
(name
,_,ty
,_,pure
) ->
199 mcode print_meta name
; print_types ty
(*;
202 Ast0.Pure -> print_string "pure"
203 | Ast0.Impure -> print_string "impure"
204 | Ast0.Context -> print_string "context"
205 | Ast0.PureContext -> print_string "pure_context")*)
206 | Ast0.MetaExprList
(name
,_,_) -> mcode print_meta name
207 | Ast0.EComma
(cm
) -> mcode print_string cm
; print_space
()
208 | Ast0.DisjExpr
(_,exp_list
,_,_) ->
209 print_string
"\n("; force_newline
();
211 (function _ -> print_string
"\n|"; force_newline
())
214 | Ast0.NestExpr
(starter
,expr_dots
,ender
,None
,multi
) ->
215 mcode print_string starter
;
216 start_block(); dots force_newline
expression expr_dots
; end_block();
217 mcode print_string ender
218 | Ast0.NestExpr
(starter
,expr_dots
,ender
,Some whencode
,multi
) ->
219 mcode print_string starter
; print_string
" WHEN != ";
221 start_block(); dots force_newline
expression expr_dots
; end_block();
222 mcode print_string ender
223 | Ast0.Edots
(dots,Some whencode
)
224 | Ast0.Ecircles
(dots,Some whencode
)
225 | Ast0.Estars
(dots,Some whencode
) ->
226 mcode print_string
dots; print_string
" WHEN != ";
228 | Ast0.Edots
(dots,None
)
229 | Ast0.Ecircles
(dots,None
)
230 | Ast0.Estars
(dots,None
) -> mcode print_string
dots
231 | Ast0.OptExp
(exp
) -> print_string
"?"; expression exp
232 | Ast0.UniqueExp
(exp
) -> print_string
"!"; expression exp
)
234 and expression_dots x
= dots (function _ -> ()) expression x
236 (* --------------------------------------------------------------------- *)
239 and print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) fn =
240 typeC ty
; mcode print_string lp1
; mcode print_string star
; fn();
241 mcode print_string rp1
; mcode print_string lp2
;
242 parameter_list params
; mcode print_string rp2
244 and print_function_type
(ty
,lp1
,params
,rp1
) fn =
245 print_option typeC ty
; fn(); mcode print_string lp1
;
246 parameter_list params
; mcode print_string rp1
251 match Ast0.unwrap t
with
252 Ast0.ConstVol
(cv
,ty
) ->
253 mcode U.const_vol cv
; print_string
" "; typeC ty
254 | Ast0.BaseType
(ty
,strings
) ->
255 List.iter
(function s
-> mcode print_string s
; print_string
" ")
257 | Ast0.Signed
(sgn
,ty
) -> mcode U.sign sgn
; print_option typeC ty
258 | Ast0.Pointer
(ty
,star
) -> typeC ty
; mcode print_string star
259 | Ast0.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
260 print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
)
262 | Ast0.FunctionType
(ty
,lp1
,params
,rp1
) ->
263 print_function_type
(ty
,lp1
,params
,rp1
) (function _ -> ())
264 | Ast0.Array
(ty
,lb
,size
,rb
) ->
265 typeC ty
; mcode print_string lb
; print_option expression size
;
266 mcode print_string rb
267 | Ast0.EnumName
(kind
,name
) -> mcode print_string kind
; print_string
" ";
269 | Ast0.StructUnionName
(kind
,name
) ->
270 mcode U.structUnion kind
;
271 print_option (function x
-> ident x
; print_string
" ") name
272 | Ast0.StructUnionDef
(ty
,lb
,decls
,rb
) ->
273 typeC ty
; mcode print_string lb
;
274 dots force_newline declaration decls
;
275 mcode print_string rb
276 | Ast0.TypeName
(name
)-> mcode print_string name
; print_string
" "
277 | Ast0.MetaType
(name
,_)-> mcode print_meta name
; print_string
" "
278 | Ast0.DisjType
(lp
,types
,mids
,rp
) ->
279 print_string
"\n"; mcode print_string lp
; force_newline
();
281 (function _ -> print_string
"\n|"; force_newline
())
283 print_string
"\n"; mcode print_string rp
284 | Ast0.OptType
(ty
) -> print_string
"?"; typeC ty
285 | Ast0.UniqueType
(ty
) -> print_string
"!"; typeC ty
)
287 (* --------------------------------------------------------------------- *)
288 (* Variable declaration *)
289 (* Even if the Cocci program specifies a list of declarations, they are
290 split out into multiple declarations of a single variable each. *)
292 and print_named_type ty id
=
293 match Ast0.unwrap ty
with
294 Ast0.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
295 print_function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
)
296 (function _ -> print_string
" "; ident id
)
297 | Ast0.FunctionType
(ty
,lp1
,params
,rp1
) ->
298 print_function_type
(ty
,lp1
,params
,rp1
)
299 (function _ -> print_string
" "; ident id
)
300 | Ast0.Array
(ty
,lb
,size
,rb
) ->
302 match Ast0.unwrap ty
with
303 Ast0.Array
(ty
,lb
,size
,rb
) ->
307 mcode print_string lb
;
308 print_option expression size
;
309 mcode print_string rb
)
310 | _ -> typeC ty
; ident id
; k
() in
311 loop ty
(function _ -> ())
312 | _ -> typeC ty
; ident id
317 match Ast0.unwrap d
with
318 Ast0.Init
(stg
,ty
,id
,eq
,ini
,sem
) ->
319 print_option (mcode U.storage
) stg
;
320 print_named_type ty id
;
322 mcode print_string eq
; print_string
" "; initialiser ini
;
323 mcode print_string sem
324 | Ast0.UnInit
(stg
,ty
,id
,sem
) ->
325 print_option (mcode U.storage
) stg
; print_named_type ty id
;
326 mcode print_string sem
327 | Ast0.MacroDecl
(name
,lp
,args
,rp
,sem
) ->
328 ident name
; mcode print_string_box lp
;
329 let _ = dots (function _ -> ()) expression args
in
330 close_box
(); mcode print_string rp
; mcode print_string sem
331 | Ast0.TyDecl
(ty
,sem
) -> typeC ty
; mcode print_string sem
332 | Ast0.Typedef
(stg
,ty
,id
,sem
) ->
333 mcode print_string stg
; typeC ty
; typeC id
;
334 mcode print_string sem
335 | Ast0.DisjDecl
(_,decls
,_,_) ->
336 print_string
"\n("; force_newline
();
338 (function _ -> print_string
"\n|"; force_newline
())
341 | Ast0.Ddots
(dots,Some whencode
) ->
342 mcode print_string
dots; print_string
" when != ";
344 | Ast0.Ddots
(dots,None
) -> mcode print_string
dots
345 | Ast0.OptDecl
(decl
) -> print_string
"?"; declaration decl
346 | Ast0.UniqueDecl
(decl
) -> print_string
"!"; declaration decl
)
348 and declaration_dots l
= dots (function _ -> ()) declaration l
350 (* --------------------------------------------------------------------- *)
356 match Ast0.unwrap i
with
357 Ast0.MetaInit
(name
,_)-> mcode print_meta name
; print_string
" "
358 | Ast0.InitExpr
(exp
) -> expression exp
359 | Ast0.InitList
(lb
,initlist
,rb
) ->
360 mcode print_string lb
; open_box
0;
361 let _ = dots (function _ -> ()) initialiser initlist
in
362 close_box
(); mcode print_string rb
363 | Ast0.InitGccExt
(designators
,eq
,ini
) ->
364 List.iter designator designators
; print_string
" ";
365 mcode print_string eq
; print_string
" "; initialiser ini
366 | Ast0.InitGccName
(name
,eq
,ini
) ->
367 ident name
; mcode print_string eq
; initialiser ini
368 | Ast0.IComma
(cm
) -> mcode print_string cm
; force_newline
()
369 | Ast0.Idots
(d
,Some whencode
) ->
370 mcode print_string d
; print_string
" WHEN != ";
372 | Ast0.Idots
(d
,None
) -> mcode print_string d
373 | Ast0.OptIni
(ini
) -> print_string
"?"; initialiser ini
374 | Ast0.UniqueIni
(ini
) -> print_string
"!"; initialiser ini
)
376 and designator
= function
377 Ast0.DesignatorField
(dot
,id
) -> mcode print_string dot
; ident id
378 | Ast0.DesignatorIndex
(lb
,exp
,rb
) ->
379 mcode print_string lb
; expression exp
; mcode print_string rb
380 | Ast0.DesignatorRange
(lb
,min
,dots,max
,rb
) ->
381 mcode print_string lb
; expression min
; mcode print_string
dots;
382 expression max
; mcode print_string rb
384 and initialiser_list l
= dots (function _ -> ()) initialiser l
386 (* --------------------------------------------------------------------- *)
389 and parameterTypeDef p
=
392 match Ast0.unwrap p
with
393 Ast0.VoidParam
(ty
) -> typeC ty
394 | Ast0.Param
(ty
,Some id
) -> print_named_type ty id
395 | Ast0.Param
(ty
,None
) -> typeC ty
396 | Ast0.MetaParam
(name
,_) -> mcode print_meta name
397 | Ast0.MetaParamList
(name
,_,_) -> mcode print_meta name
398 | Ast0.PComma
(cm
) -> mcode print_string cm
; print_space
()
399 | Ast0.Pdots
(dots) -> mcode print_string
dots
400 | Ast0.Pcircles
(dots) -> mcode print_string
dots
401 | Ast0.OptParam
(param
) -> print_string
"?"; parameterTypeDef param
402 | Ast0.UniqueParam
(param
) -> print_string
"!"; parameterTypeDef param
)
404 and parameter_list l
= dots (function _ -> ()) parameterTypeDef l
406 (* --------------------------------------------------------------------- *)
409 and statement arity s
=
412 match Ast0.unwrap s
with
413 Ast0.FunDecl
(_,fninfo
,name
,lp
,params
,rp
,lbrace
,body
,rbrace
) ->
415 List.iter print_fninfo fninfo
;
416 ident name
; mcode print_string_box lp
;
417 parameter_list params
; close_box
(); mcode print_string rp
;
419 print_string arity
; mcode print_string lbrace
; start_block();
420 dots force_newline
(statement arity
) body
;
421 end_block(); print_string arity
; mcode print_string rbrace
422 | Ast0.Decl
(_,decl
) -> print_string arity
; declaration decl
423 | Ast0.Seq
(lbrace
,body
,rbrace
) ->
424 print_string arity
; mcode print_string lbrace
; start_block();
425 dots force_newline
(statement arity
) body
;
426 end_block(); print_string arity
; mcode print_string rbrace
427 | Ast0.ExprStatement
(exp
,sem
) ->
428 print_string arity
; expression exp
; mcode print_string sem
429 | Ast0.IfThen
(iff
,lp
,exp
,rp
,branch1
,(info
,aft
)) ->
431 mcode print_string iff
; print_string
" "; mcode print_string_box lp
;
432 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
433 statement arity branch1
;
434 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
)
435 | Ast0.IfThenElse
(iff
,lp
,exp
,rp
,branch1
,els
,branch2
,(info
,aft
)) ->
437 mcode print_string iff
; print_string
" "; mcode print_string_box lp
;
438 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
439 statement arity branch1
;
440 print_string arity
; mcode print_string els
; print_string
" ";
441 statement arity branch2
;
442 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
)
443 | Ast0.While
(whl
,lp
,exp
,rp
,body
,(info
,aft
)) ->
445 mcode print_string whl
; print_string
" "; mcode print_string_box lp
;
446 expression exp
; close_box
(); mcode print_string rp
; print_string
" ";
447 statement arity body
;
448 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
)
449 | Ast0.Do
(d
,body
,whl
,lp
,exp
,rp
,sem
) ->
450 print_string arity
; mcode print_string d
; print_string
" ";
451 statement arity body
;
453 mcode print_string whl
; print_string
" "; mcode print_string_box lp
;
454 expression exp
; close_box
(); mcode print_string rp
;
455 mcode print_string sem
456 | Ast0.For
(fr
,lp
,e1
,sem1
,e2
,sem2
,e3
,rp
,body
,(info
,aft
)) ->
458 mcode print_string fr
; mcode print_string_box lp
;
459 print_option expression e1
; mcode print_string sem1
;
460 print_option expression e2
; mcode print_string sem2
;
461 print_option expression e3
; close_box
();
462 mcode print_string rp
; print_string
" "; statement arity body
;
463 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
)
464 | Ast0.Iterator
(nm
,lp
,args
,rp
,body
,(info
,aft
)) ->
466 ident nm
; print_string
" "; mcode print_string_box lp
;
467 let _ = dots (function _ -> ()) expression args
in
468 close_box
(); mcode print_string rp
; print_string
" ";
469 statement arity body
;
470 mcode (function _ -> ()) ((),(),info
,aft
,ref Ast0.NoMetaPos
)
471 | Ast0.Switch
(switch
,lp
,exp
,rp
,lb
,cases
,rb
) ->
473 mcode print_string switch
; print_string
" ";
474 mcode print_string_box lp
; expression exp
; close_box
();
475 mcode print_string rp
; print_string
" "; mcode print_string lb
;
476 dots force_newline
(case_line arity
) cases
;
477 mcode print_string rb
478 | Ast0.Break
(br
,sem
) ->
479 print_string arity
; mcode print_string br
; mcode print_string sem
480 | Ast0.Continue
(cont
,sem
) ->
481 print_string arity
; mcode print_string cont
; mcode print_string sem
482 | Ast0.Label
(l
,dd
) -> ident l
; print_string
":"
483 | Ast0.Goto
(goto
,l
,sem
) ->
484 mcode print_string goto
; ident l
; mcode print_string sem
485 | Ast0.Return
(ret
,sem
) ->
486 print_string arity
; mcode print_string ret
; mcode print_string sem
487 | Ast0.ReturnExpr
(ret
,exp
,sem
) ->
488 print_string arity
; mcode print_string ret
; print_string
" ";
489 expression exp
; mcode print_string sem
490 | Ast0.MetaStmt
(name
,pure
) ->
491 print_string arity
; mcode print_meta name
;(*
494 Ast0.Pure -> print_string "pure"
495 | Ast0.Impure -> print_string "impure"
496 | Ast0.Context -> print_string "context"
497 | Ast0.PureContext -> print_string "pure_context")*)
498 | Ast0.MetaStmtList
(name
,_) ->
499 print_string arity
; mcode print_meta name
500 | Ast0.Disj
(_,statement_dots_list
,_,_) ->
502 print_string
"\n("; force_newline
();
504 (function _ -> print_string
"\n|"; force_newline
())
505 (dots force_newline
(statement arity
))
508 | Ast0.Nest
(starter
,stmt_dots
,ender
,whn
,multi
) ->
510 mcode print_string starter
;
513 (whencode
(dots force_newline
(statement
"")) (statement
""))
517 dots force_newline
(statement arity
) stmt_dots
;
519 mcode print_string ender
520 | Ast0.Exp
(exp
) -> print_string arity
; expression exp
521 | Ast0.TopExp
(exp
) -> print_string arity
; expression exp
522 | Ast0.Ty
(ty
) -> print_string arity
; typeC ty
523 | Ast0.TopInit
(init
) -> initialiser init
524 | Ast0.Dots
(d
,whn
) | Ast0.Circles
(d
,whn
) | Ast0.Stars
(d
,whn
) ->
525 print_string arity
; mcode print_string d
;
527 (whencode
(dots force_newline
(statement
"")) (statement
""))
529 | Ast0.Include
(inc
,s
) ->
530 mcode print_string inc
; print_string
" "; mcode U.inc_file s
531 | Ast0.Define
(def
,id
,params
,body
) ->
532 mcode print_string def
; print_string
" "; ident id
;
533 print_define_parameters params
;
535 dots force_newline
(statement arity
) body
536 | Ast0.OptStm
(re
) -> statement
"?" re
537 | Ast0.UniqueStm
(re
) -> statement
"!" re
)
539 and print_define_parameters params
=
540 match Ast0.unwrap params
with
542 | Ast0.DParams
(lp
,params
,rp
) ->
543 mcode print_string lp
;
544 dots (function _ -> ()) print_define_param params
; mcode print_string rp
546 and print_define_param param
=
547 match Ast0.unwrap param
with
548 Ast0.DParam
(id
) -> ident id
549 | Ast0.DPComma
(comma
) -> mcode print_string comma
550 | Ast0.DPdots
(dots) -> mcode print_string
dots
551 | Ast0.DPcircles
(circles
) -> mcode print_string circles
552 | Ast0.OptDParam
(dp
) -> print_string
"?"; print_define_param dp
553 | Ast0.UniqueDParam
(dp
) -> print_string
"!"; print_define_param dp
555 and print_fninfo
= function
556 Ast0.FStorage
(stg
) -> mcode U.storage stg
557 | Ast0.FType
(ty
) -> typeC ty
558 | Ast0.FInline
(inline
) -> mcode print_string inline
559 | Ast0.FAttr
(attr
) -> mcode print_string attr
561 and whencode notfn alwaysfn
= function
563 print_string
" WHEN != "; open_box
0; notfn a
; close_box
()
564 | Ast0.WhenAlways a
->
565 print_string
" WHEN = "; open_box
0; alwaysfn a
; close_box
()
566 | Ast0.WhenModifier x
-> print_string
" WHEN "; U.print_when_modif x
567 | Ast0.WhenNotTrue a
->
568 print_string
" WHEN != TRUE "; open_box
0; expression a
; close_box
()
569 | Ast0.WhenNotFalse a
->
570 print_string
" WHEN != FALSE "; open_box
0; expression a
; close_box
()
572 and case_line arity c
=
575 match Ast0.unwrap c
with
576 Ast0.Default
(def
,colon
,code
) ->
578 mcode print_string def
; mcode print_string colon
; print_string
" ";
579 dots force_newline
(statement arity
) code
580 | Ast0.Case
(case
,exp
,colon
,code
) ->
582 mcode print_string case
; print_string
" "; expression exp
;
583 mcode print_string colon
; print_string
" ";
584 dots force_newline
(statement arity
) code
585 | Ast0.OptCase
(case
) -> case_line
"?" case
)
587 and statement_dots l
= dots (function _ -> ()) (statement
"") l
588 and case_dots l
= dots (function _ -> ()) (case_line
"") l
590 (* --------------------------------------------------------------------- *)
596 match Ast0.unwrap t
with
597 Ast0.FILEINFO
(old_file
,new_file
) ->
598 print_string
"--- "; mcode print_string old_file
; force_newline
();
599 print_string
"+++ "; mcode print_string new_file
600 | Ast0.DECL
(stmt
) -> statement
"" stmt
601 | Ast0.CODE
(stmt_dots
) ->
602 dots force_newline
(statement
"") stmt_dots
603 | Ast0.ERRORWORDS
(exps
) ->
604 print_string
"error words = [";
605 print_between (function _ -> print_string
", ") expression exps
;
608 print_string
"OTHER("; statement
"" s
; print_string
")")
611 print_between (function _ -> force_newline
(); force_newline
()) top_level
613 let unparse_anything x
=
617 Ast0.DotsExprTag
(d
) ->
618 print_string
"ExpDots:"; force_newline
();
620 | Ast0.DotsParamTag
(d
) ->
622 | Ast0.DotsInitTag
(d
) ->
624 | Ast0.DotsStmtTag
(d
) ->
625 print_string
"StmDots:"; force_newline
();
627 | Ast0.DotsDeclTag
(d
) ->
629 | Ast0.DotsCaseTag
(d
) ->
631 | Ast0.IdentTag
(d
) ->
633 | Ast0.ExprTag
(d
) | Ast0.ArgExprTag
(d
) | Ast0.TestExprTag
(d
) ->
634 print_string
"Exp:"; force_newline
();
636 | Ast0.TypeCTag
(d
) ->
638 | Ast0.ParamTag
(d
) ->
645 print_string
"Stm:"; force_newline
();
647 | Ast0.CaseLineTag
(d
) ->
651 | Ast0.IsoWhenTag
(x
) -> U.print_when_modif x
652 | Ast0.IsoWhenTTag
(e
) -> expression e
653 | Ast0.IsoWhenFTag
(e
) -> expression e
654 | Ast0.MetaPosTag
(var
) -> meta_pos var
);
659 print_string
"\n@@\n@@";
665 let unparse_to_string x
= Common.format_to_string
(function _ -> unparse x
)