Release coccinelle-0.2.0
[bpt/coccinelle.git] / parsing_cocci / data.ml
CommitLineData
9f8e26f4
C
1(*
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.
5 *
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.
9 *
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.
14 *
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/>.
17 *
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
20 *)
21
22
34e49164
C
23module Ast0 = Ast0_cocci
24module Ast = Ast_cocci
25
26(* types that clutter the .mly file *)
27(* for iso metavariables, true if they can only match nonmodified, unitary
28 metavariables *)
29type fresh = bool
30
951c7801
C
31type incl_iso =
32 Include of string | Iso of (string,string) Common.either
33 | Virt of string list (* virtual rules *)
978fd7e5 34
34e49164
C
35type clt =
36 line_type * int * int * int * int (* starting spaces *) *
0708f913
C
37 (string * Ast0.position_info) list (* code before *) *
38 (string * Ast0.position_info) list (* code after *) *
34e49164
C
39 Ast0.meta_pos (* position variable, minus only *)
40
41(* ---------------------------------------------------------------------- *)
42
43(* Things that need to be seen by the lexer and parser. *)
44
45and line_type =
46 MINUS | OPTMINUS | UNIQUEMINUS
951c7801 47 | PLUS | PLUSPLUS
34e49164
C
48 | CONTEXT | UNIQUE | OPT
49
951c7801
C
50type iconstraints = Ast.idconstraint
51type econstraints = Ast0.constraints
34e49164
C
52type pconstraints = Ast.meta_name list
53
54let in_rule_name = ref false
55let in_meta = ref false
56let in_iso = ref false
faf9a90c 57let in_generating = ref false
7f004419 58let ignore_patch_or_match = ref false
34e49164 59let in_prolog = ref false
978fd7e5
C
60(* state machine for lexer..., allows smpl keywords as type names *)
61let saw_struct = ref false
34e49164
C
62let inheritable_positions =
63 ref ([] : string list) (* rules from which posns can be inherited *)
64
978fd7e5
C
65let call_in_meta f =
66 in_meta := true; saw_struct := false;
67 let res = f() in
68 in_meta := false;
69 res
70
34e49164
C
71let all_metadecls =
72 (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t)
73
faf9a90c
C
74let clear_meta: (unit -> unit) ref =
75 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
76
77let add_id_meta:
faf9a90c
C
78 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
79 ref (fun _ -> failwith "uninitialized add_meta")
34e49164 80
b1b2de81
C
81let add_fresh_id_meta: (Ast.meta_name -> unit) ref =
82 ref (fun _ -> failwith "uninitialized add_meta")
83
faf9a90c
C
84let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
85 ref (fun _ -> failwith "uninitialized add_meta")
34e49164 86
113803cf
C
87let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
88 ref (fun _ -> failwith "uninitialized add_meta")
89
faf9a90c
C
90let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
91 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
92
93let add_paramlist_meta:
faf9a90c
C
94 (Ast.meta_name -> Ast.meta_name option -> Ast0.pure -> unit) ref =
95 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
96
97let add_const_meta:
98 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
99 Ast0.pure -> unit)
100 ref =
faf9a90c 101 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
102
103let add_err_meta:
104 (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref =
faf9a90c 105 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
106
107let add_exp_meta:
108 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
109 Ast0.pure -> unit)
110 ref =
faf9a90c 111 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
112
113let add_idexp_meta:
114 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
115 Ast0.pure -> unit)
116 ref =
faf9a90c 117 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
118
119let add_local_idexp_meta:
120 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
121 Ast0.pure -> unit)
122 ref =
faf9a90c 123 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
124
125let add_explist_meta:
faf9a90c
C
126 (Ast.meta_name -> Ast.meta_name option -> Ast0.pure -> unit) ref =
127 ref (fun _ -> failwith "uninitialized add_meta")
34e49164 128
faf9a90c
C
129let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
130 ref (fun _ -> failwith "uninitialized add_meta")
34e49164 131
faf9a90c
C
132let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
133 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
134
135let add_func_meta:
faf9a90c
C
136 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
137 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
138
139let add_local_func_meta:
faf9a90c
C
140 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
141 ref (fun _ -> failwith "uninitialized add_meta")
34e49164
C
142
143let add_declarer_meta:
144 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
faf9a90c 145 ref (fun _ -> failwith "uninitialized add_decl")
34e49164
C
146
147let add_iterator_meta:
148 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
faf9a90c 149 ref (fun _ -> failwith "uninitialized add_iter")
34e49164
C
150
151let add_pos_meta:
faf9a90c
C
152 (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref =
153 ref (fun _ -> failwith "uninitialized add_meta")
34e49164 154
faf9a90c
C
155let add_type_name: (string -> unit) ref =
156 ref (fun _ -> failwith "uninitialized add_type")
34e49164 157
faf9a90c
C
158let add_declarer_name: (string -> unit) ref =
159 ref (fun _ -> failwith "uninitialized add_decl")
34e49164 160
faf9a90c
C
161let add_iterator_name: (string -> unit) ref =
162 ref (fun _ -> failwith "uninitialized add_iter")
34e49164
C
163
164let init_rule: (unit -> unit) ref =
faf9a90c 165 ref (fun _ -> failwith "uninitialized install_bindings")
34e49164
C
166
167let install_bindings: (string -> unit) ref =
faf9a90c 168 ref (fun _ -> failwith "uninitialized install_bindings")