package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file meta_ast_c.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

(* generated by ocamltarzan with: camlp4o -o /tmp/yyy.ml -I pa/ pa_type_conv.cmo pa_vof.cmo  pr_o.cmo /tmp/xxx.ml  *)
open Ast_c

let vof_info x = Meta_parse_info.vof_info_adjustable_precision x
let vof_tok x = vof_info x
let vof_wrap _of_a (v1, v2) =
  let v1 = _of_a v1
  and _v2TODO = vof_info v2
  in
  Ocaml.VTuple [ v1 (* ; v2 *) ]

and vof_unaryOp =
  function
  | Cst_cpp.GetRef -> Ocaml.VSum (("GetRef", []))
  | Cst_cpp.DeRef -> Ocaml.VSum (("DeRef", []))
  | Cst_cpp.UnPlus -> Ocaml.VSum (("UnPlus", []))
  | Cst_cpp.UnMinus -> Ocaml.VSum (("UnMinus", []))
  | Cst_cpp.Tilde -> Ocaml.VSum (("Tilde", []))
  | Cst_cpp.Not -> Ocaml.VSum (("Not", []))
  | Cst_cpp.GetRefLabel -> Ocaml.VSum (("GetRefLabel", []))

let rec vof_assignOp =
  function
  | Cst_cpp.SimpleAssign -> Ocaml.VSum (("SimpleAssign", []))
  | Cst_cpp.OpAssign v1 ->
      let v1 = vof_arithOp v1 in Ocaml.VSum (("OpAssign", [ v1 ]))
and vof_fixOp =
  function
  | Cst_cpp.Dec -> Ocaml.VSum (("Dec", []))
  | Cst_cpp.Inc -> Ocaml.VSum (("Inc", []))
and vof_binaryOp =
  function
  | Cst_cpp.Arith v1 -> let v1 = vof_arithOp v1 in Ocaml.VSum (("Arith", [ v1 ]))
  | Cst_cpp.Logical v1 ->
      let v1 = vof_logicalOp v1 in Ocaml.VSum (("Logical", [ v1 ]))
and vof_arithOp =
  function
  | Cst_cpp.Plus -> Ocaml.VSum (("Plus", []))
  | Cst_cpp.Minus -> Ocaml.VSum (("Minus", []))
  | Cst_cpp.Mul -> Ocaml.VSum (("Mul", []))
  | Cst_cpp.Div -> Ocaml.VSum (("Div", []))
  | Cst_cpp.Mod -> Ocaml.VSum (("Mod", []))
  | Cst_cpp.DecLeft -> Ocaml.VSum (("DecLeft", []))
  | Cst_cpp.DecRight -> Ocaml.VSum (("DecRight", []))
  | Cst_cpp.And -> Ocaml.VSum (("And", []))
  | Cst_cpp.Or -> Ocaml.VSum (("Or", []))
  | Cst_cpp.Xor -> Ocaml.VSum (("Xor", []))
and vof_logicalOp =
  function
  | Cst_cpp.Inf -> Ocaml.VSum (("Inf", []))
  | Cst_cpp.Sup -> Ocaml.VSum (("Sup", []))
  | Cst_cpp.InfEq -> Ocaml.VSum (("InfEq", []))
  | Cst_cpp.SupEq -> Ocaml.VSum (("SupEq", []))
  | Cst_cpp.Eq -> Ocaml.VSum (("Eq", []))
  | Cst_cpp.NotEq -> Ocaml.VSum (("NotEq", []))
  | Cst_cpp.AndLog -> Ocaml.VSum (("AndLog", []))
  | Cst_cpp.OrLog -> Ocaml.VSum (("OrLog", []))


let vof_name v = vof_wrap Ocaml.vof_string v
  
let rec vof_type_ =
  function
  | TBase v1 -> let v1 = vof_name v1 in Ocaml.VSum (("TBase", [ v1 ]))
  | TPointer v1 -> let v1 = vof_type_ v1 in Ocaml.VSum (("TPointer", [ v1 ]))
  | TArray ((v1, v2)) ->
      let v1 = Ocaml.vof_option vof_const_expr v1
      and v2 = vof_type_ v2
      in Ocaml.VSum (("TArray", [ v1; v2 ]))
  | TFunction v1 ->
      let v1 = vof_function_type v1 in Ocaml.VSum (("TFunction", [ v1 ]))
  | TStructName ((v1, v2)) ->
      let v1 = vof_struct_kind v1
      and v2 = vof_name v2
      in Ocaml.VSum (("TStructName", [ v1; v2 ]))
  | TEnumName v1 ->
      let v1 = vof_name v1 in Ocaml.VSum (("TEnumName", [ v1 ]))
  | TTypeName v1 ->
      let v1 = vof_name v1 in Ocaml.VSum (("TTypeName", [ v1 ]))
and vof_function_type (v1, v2) =
  let v1 = vof_type_ v1
  and v2 = Ocaml.vof_list vof_parameter v2
  in Ocaml.VTuple [ v1; v2 ]
and vof_parameter { p_type = v_p_type; p_name = v_p_name } =
  let bnds = [] in
  let arg = Ocaml.vof_option vof_name v_p_name in
  let bnd = ("p_name", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_type_ v_p_type in
  let bnd = ("p_type", arg) in let bnds = bnd :: bnds in Ocaml.VDict bnds
and vof_struct_kind =
  function
  | Struct -> Ocaml.VSum (("Struct", []))
  | Union -> Ocaml.VSum (("Union", []))
and vof_const_expr v = vof_expr v
  
and vof_expr =
  function
  | Int v1 ->
      let v1 = vof_wrap Ocaml.vof_string v1 in Ocaml.VSum (("Int", [ v1 ]))
  | Float v1 ->
      let v1 = vof_wrap Ocaml.vof_string v1 in Ocaml.VSum (("Float", [ v1 ]))
  | String v1 ->
      let v1 = vof_wrap Ocaml.vof_string v1
      in Ocaml.VSum (("String", [ v1 ]))
  | Char v1 ->
      let v1 = vof_wrap Ocaml.vof_string v1 in Ocaml.VSum (("Char", [ v1 ]))
  | Id v1 -> let v1 = vof_name v1 in Ocaml.VSum (("Id", [ v1 ]))
  | Ellipses v1 -> let v1 = vof_tok v1 in Ocaml.VSum (("Ellipses", [ v1 ]))
  | Call ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = Ocaml.vof_list vof_expr v2
      in Ocaml.VSum (("Call", [ v1; v2 ]))
  | Assign ((v1, v2, v3)) ->
      let v1 = vof_wrap vof_assignOp v1
      and v2 = vof_expr v2
      and v3 = vof_expr v3
      in Ocaml.VSum (("Assign", [ v1; v2; v3 ]))
  | ArrayAccess ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_expr v2
      in Ocaml.VSum (("ArrayAccess", [ v1; v2 ]))
  | RecordPtAccess ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_name v2
      in Ocaml.VSum (("RecordPtAccess", [ v1; v2 ]))
  | Cast ((v1, v2)) ->
      let v1 = vof_type_ v1
      and v2 = vof_expr v2
      in Ocaml.VSum (("Cast", [ v1; v2 ]))
  | Postfix ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_wrap vof_fixOp v2
      in Ocaml.VSum (("Postfix", [ v1; v2 ]))
  | Infix ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_wrap vof_fixOp v2
      in Ocaml.VSum (("Infix", [ v1; v2 ]))
  | Unary ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_wrap vof_unaryOp v2
      in Ocaml.VSum (("Unary", [ v1; v2 ]))
  | Binary ((v1, v2, v3)) ->
      let v1 = vof_expr v1
      and v2 = vof_wrap vof_binaryOp v2
      and v3 = vof_expr v3
      in Ocaml.VSum (("Binary", [ v1; v2; v3 ]))
  | CondExpr ((v1, v2, v3)) ->
      let v1 = vof_expr v1
      and v2 = vof_expr v2
      and v3 = vof_expr v3
      in Ocaml.VSum (("CondExpr", [ v1; v2; v3 ]))
  | Sequence ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_expr v2
      in Ocaml.VSum (("Sequence", [ v1; v2 ]))
  | SizeOf v1 ->
      let v1 = Ocaml.vof_either vof_expr vof_type_ v1
      in Ocaml.VSum (("SizeOf", [ v1 ]))
  | ArrayInit v1 ->
      let v1 =
        Ocaml.vof_list
          (fun (v1, v2) ->
             let v1 = Ocaml.vof_option vof_expr v1
             and v2 = vof_expr v2
             in Ocaml.VTuple [ v1; v2 ])
          v1
      in Ocaml.VSum (("ArrayInit", [ v1 ]))
  | RecordInit v1 ->
      let v1 =
        Ocaml.vof_list
          (fun (v1, v2) ->
             let v1 = vof_name v1
             and v2 = vof_expr v2
             in Ocaml.VTuple [ v1; v2 ])
          v1
      in Ocaml.VSum (("RecordInit", [ v1 ]))
  | GccConstructor ((v1, v2)) ->
      let v1 = vof_type_ v1
      and v2 = vof_expr v2
      in Ocaml.VSum (("GccConstructor", [ v1; v2 ]))
  
let rec vof_stmt =
  function
  | ExprSt v1 -> let v1 = vof_expr v1 in Ocaml.VSum (("ExprSt", [ v1 ]))
  | Block v1 ->
      let v1 = Ocaml.vof_list vof_stmt v1 in Ocaml.VSum (("Block", [ v1 ]))
  | If ((v1, v2, v3)) ->
      let v1 = vof_expr v1
      and v2 = vof_stmt v2
      and v3 = vof_stmt v3
      in Ocaml.VSum (("If", [ v1; v2; v3 ]))
  | Switch ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = Ocaml.vof_list vof_case v2
      in Ocaml.VSum (("Switch", [ v1; v2 ]))
  | While ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = vof_stmt v2
      in Ocaml.VSum (("While", [ v1; v2 ]))
  | DoWhile ((v1, v2)) ->
      let v1 = vof_stmt v1
      and v2 = vof_expr v2
      in Ocaml.VSum (("DoWhile", [ v1; v2 ]))
  | For ((v1, v2, v3, v4)) ->
      let v1 = Ocaml.vof_option vof_expr v1
      and v2 = Ocaml.vof_option vof_expr v2
      and v3 = Ocaml.vof_option vof_expr v3
      and v4 = vof_stmt v4
      in Ocaml.VSum (("For", [ v1; v2; v3; v4 ]))
  | Return v1 ->
      let v1 = Ocaml.vof_option vof_expr v1
      in Ocaml.VSum (("Return", [ v1 ]))
  | Continue -> Ocaml.VSum (("Continue", []))
  | Break -> Ocaml.VSum (("Break", []))
  | Label ((v1, v2)) ->
      let v1 = vof_name v1
      and v2 = vof_stmt v2
      in Ocaml.VSum (("Label", [ v1; v2 ]))
  | Goto v1 -> let v1 = vof_name v1 in Ocaml.VSum (("Goto", [ v1 ]))
  | Vars v1 ->
      let v1 = Ocaml.vof_list vof_var_decl v1
      in Ocaml.VSum (("Vars", [ v1 ]))
  | Asm v1 ->
      let v1 = Ocaml.vof_list vof_expr v1 in Ocaml.VSum (("Asm", [ v1 ]))
and vof_case =
  function
  | Case ((v1, v2)) ->
      let v1 = vof_expr v1
      and v2 = Ocaml.vof_list vof_stmt v2
      in Ocaml.VSum (("Case", [ v1; v2 ]))
  | Default v1 ->
      let v1 = Ocaml.vof_list vof_stmt v1 in Ocaml.VSum (("Default", [ v1 ]))
and
  vof_var_decl {
                 v_name = v_v_name;
                 v_type = v_v_type;
                 v_storage = v_v_storage;
                 v_init = v_v_init
               } =
  let bnds = [] in
  let arg = Ocaml.vof_option vof_initialiser v_v_init in
  let bnd = ("v_init", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_storage v_v_storage in
  let bnd = ("v_storage", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_type_ v_v_type in
  let bnd = ("v_type", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_name v_v_name in
  let bnd = ("v_name", arg) in let bnds = bnd :: bnds in Ocaml.VDict bnds
and vof_initialiser v = vof_expr v
and vof_storage =
  function
  | Extern -> Ocaml.VSum (("Extern", []))
  | Static -> Ocaml.VSum (("Static", []))
  | DefaultStorage -> Ocaml.VSum (("DefaultStorage", []))
  
let vof_func_def 
    { f_name = v_f_name; f_type = v_f_type; f_body = v_f_body; 
      f_static = v_f_static }
                 =
  let bnds = [] in
  let arg = Ocaml.vof_list vof_stmt v_f_body in
  let bnd = ("f_body", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_function_type v_f_type in
  let bnd = ("f_type", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_name v_f_name in
  let bnd = ("f_name", arg) in 
  let bnds = bnd :: bnds in 
  let arg = Ocaml.vof_bool v_f_static in
  let bnd = ("f_static", arg) in 
  let bnds = bnd :: bnds in 
  Ocaml.VDict bnds
  
and vof_field_def { fld_name = v_fld_name; fld_type = v_fld_type } =
  let bnds = [] in
  let arg = vof_type_ v_fld_type in
  let bnd = ("fld_type", arg) in
  let bnds = bnd :: bnds in
  let arg = Ocaml.vof_option vof_name v_fld_name in
  let bnd = ("fld_name", arg) in let bnds = bnd :: bnds in Ocaml.VDict bnds
  
let vof_enum_def (v1, v2) =
  let v1 = vof_name v1
  and v2 =
    Ocaml.vof_list
      (fun (v1, v2) ->
         let v1 = vof_name v1
         and v2 = Ocaml.vof_option vof_expr v2
         in Ocaml.VTuple [ v1; v2 ])
      v2
  in Ocaml.VTuple [ v1; v2 ]
  
let vof_type_def (v1, v2) =
  let v1 = vof_name v1 and v2 = vof_type_ v2 in Ocaml.VTuple [ v1; v2 ]
  
let vof_define_body =
  function
  | CppExpr v1 -> let v1 = vof_expr v1 in Ocaml.VSum (("CppExpr", [ v1 ]))
  | CppStmt v1 -> let v1 = vof_stmt v1 in Ocaml.VSum (("CppStmt", [ v1 ]))
(*  | CppEmpty -> Ocaml.VSum (("CppEmpty", [])) *)

let
  vof_struct_def { s_name = v_s_name; s_kind = v_s_kind; s_flds = v_s_flds }
                 =
  let bnds = [] in
  let arg = Ocaml.vof_list vof_field_def v_s_flds in
  let bnd = ("s_flds", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_struct_kind v_s_kind in
  let bnd = ("s_kind", arg) in
  let bnds = bnd :: bnds in
  let arg = vof_name v_s_name in
  let bnd = ("s_name", arg) in let bnds = bnd :: bnds in Ocaml.VDict bnds

 
let vof_toplevel =
  function
  | Define ((v1, v2)) ->
      let v1 = vof_name v1
      and v2 = vof_define_body v2
      in Ocaml.VSum (("Define", [ v1; v2 ]))
(*  | Undef v1 -> let v1 = vof_name v1 in Ocaml.VSum (("Undef", [ v1 ])) *)
  | Include v1 ->
      let v1 = vof_wrap Ocaml.vof_string v1
      in Ocaml.VSum (("Include", [ v1 ]))
  | Macro ((v1, v2, v3)) ->
      let v1 = vof_name v1
      and v2 = Ocaml.vof_list vof_name v2
      and v3 = vof_define_body v3
      in Ocaml.VSum (("Macro", [ v1; v2; v3 ]))
  | StructDef v1 ->
      let v1 = vof_struct_def v1 in Ocaml.VSum (("StructDef", [ v1 ]))
  | TypeDef v1 ->
      let v1 = vof_type_def v1 in Ocaml.VSum (("TypeDef", [ v1 ]))
  | EnumDef v1 ->
      let v1 = vof_enum_def v1 in Ocaml.VSum (("EnumDef", [ v1 ]))
  | FuncDef v1 ->
      let v1 = vof_func_def v1 in Ocaml.VSum (("FuncDef", [ v1 ]))
  | Global v1 -> let v1 = vof_var_decl v1 in Ocaml.VSum (("Global", [ v1 ]))
  | Prototype v1 ->
      let v1 = vof_func_def v1 in Ocaml.VSum (("Prototype", [ v1 ]))
  
let vof_program v = Ocaml.vof_list vof_toplevel v
  
let vof_any =
  function
  | Expr v1 -> let v1 = vof_expr v1 in Ocaml.VSum (("Expr", [ v1 ]))
  | Stmt v1 -> let v1 = vof_stmt v1 in Ocaml.VSum (("Stmt", [ v1 ]))
  | Type v1 -> let v1 = vof_type_ v1 in Ocaml.VSum (("Type", [ v1 ]))
  | Toplevel v1 ->
      let v1 = vof_toplevel v1 in Ocaml.VSum (("Toplevel", [ v1 ]))
  | Program v1 -> let v1 = vof_program v1 in Ocaml.VSum (("Program", [ v1 ]))
  
OCaml

Innovation. Community. Security.