~npalix/coccinelle/upstream

4161.1.5 by Sébastien Hinderer
Add GPL header to all the files in Coccinelle.
1
(*
4493 by julia
typo
2
 * This file is part of Coccinelle, licensed under the terms of the GPL v2.
4161.1.5 by Sébastien Hinderer
Add GPL header to all the files in Coccinelle.
3
 * See copyright.txt in the Coccinelle source code for more information.
4
 * The Coccinelle source code can be obtained at http://coccinelle.lip6.fr
5
 *)
6
1342 by Julia Lawall
*** empty log message ***
7
module Ast = Ast_cocci
8
module Past = Ast_popl
9
10
(* --------------------------------------------------------------------- *)
11
12
let rec stm s =
13
  match Ast.unwrap s with
14
    Ast.Atomic(ast) ->
15
      (match Ast.unwrap ast with
16
	Ast.ExprStatement(_,_) -> Past.Term ast
1352 by Julia Lawall
*** empty log message ***
17
      |	Ast.Exp(_) -> Past.Term ast
18
      |	Ast.Decl(_,_,_) -> Past.Term ast
1342 by Julia Lawall
*** empty log message ***
19
      |	_ -> failwith "complex statements not supported")
1403 by Julia Lawall
*** empty log message ***
20
  | Ast.Disj(stm1::stm2::stmts) ->
21
      List.fold_left
22
	(function prev ->
23
	  function cur ->
24
	    Past.Or(Past.Seq(prev,Past.Empty),stm_list cur))
25
	(Past.Or(stm_list stm1,stm_list stm2)) stmts
1537 by Julia Lawall
major changes in the handling of dots, some changes in get_bef_aft for ? case, changes in get_constants and asttomember for the ? case
26
  | Ast.Dots(dots,whencodes,_,_) ->
1342 by Julia Lawall
*** empty log message ***
27
      (match whencodes with
1416 by Julia Lawall
*** empty log message ***
28
	[Ast.WhenNot(a)] -> Past.DInfo(Past.When(Past.Dots,stm_list a),[],[])
29
      |	_ -> failwith "only one when != supported")
1713 by Julia Lawall
<+... ...+>
30
  | Ast.Nest(stmt_dots,whencodes,false,_,_) ->
1342 by Julia Lawall
*** empty log message ***
31
      let nest = Past.Nest(stm_list stmt_dots) in
32
      (match whencodes with
1416 by Julia Lawall
*** empty log message ***
33
	[Ast.WhenNot(a)] -> Past.DInfo(Past.When(nest,stm_list a),[],[])
1342 by Julia Lawall
*** empty log message ***
34
      |	_ -> failwith "only when != supported")
1403 by Julia Lawall
*** empty log message ***
35
  | Ast.While(header,body,(_,_,_,aft)) | Ast.For(header,body,(_,_,_,aft)) ->
36
      (* only allowed if only the header is significant *)
37
      (match (Ast.unwrap body,aft) with
38
	(Ast.Atomic(re),Ast.CONTEXT(_,Ast.NOTHING)) ->
39
	  (match Ast.unwrap re with
40
	    Ast.MetaStmt(_,Type_cocci.Unitary,_,false) -> Past.Term header
41
	  | _ -> failwith "unsupported statement1")
42
      | _ -> failwith "unsupported statement2")
43
  | _ ->
44
      Pretty_print_cocci.statement "" s;
45
      failwith "unsupported statement3"
1342 by Julia Lawall
*** empty log message ***
46
47
and stm_list s =
4130 by julia
Drop circles, stars
48
  List.fold_right
49
    (function cur -> function rest -> Past.Seq(stm cur, rest))
50
    (Ast.unwrap s) Past.Empty
1342 by Julia Lawall
*** empty log message ***
51
52
let top s =
53
  match Ast.unwrap s with
54
    Ast.CODE(stmt_dots) -> stm_list stmt_dots
55
  | _ -> failwith "only CODE handled"