cocci.opp.exp 100 KB
Newer Older
1 2
File "cocci.mly", line 137, characters 0-6:
Warning: symbol reinit is unreachable from any of the start symbol(s).
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
Warning: you are using the standard library and/or the %inline keyword. We
recommend switching on --infer in order to avoid obscure type error messages.
%{

(* Not clear how to allow function declarations to specify a return type
and how to allow both to be specified as static, because they are in
different rules.  The rules seem to have to be combined, which would allow
functions to be declared as local variables *)

(* Not clear how to let a function have a parameter of type void.  At the
moment, void is allowed to be the type of a variable, which is wrong, and a
parameter needs both a type and an identifier *)
module Ast0 = Ast0_cocci
module Ast = Ast_cocci
module P = Parse_aux

%}
%start iso_main
%start iso_meta_main
%start meta_main
%start minus_main
%start never_used
%start plus_main
%start rule_name
%token <Data.clt> Tvolatile
%token <Data.clt> Tvoid
%token <Data.clt> Tunsigned
%token <Data.clt> Tunion
%token <Data.clt> Tstruct
%token <Data.clt> Tstatic
%token <Data.clt> Tsigned
%token <Data.clt> Tshort
%token <Data.clt> Tregister
%token <Data.clt> Tlong
%token Tlist
%token <Data.clt> Tint
%token <Data.clt> Tinline
%token <Data.clt> Tfloat
%token <Data.clt> Textern
%token <Data.clt> Tdouble
%token <Data.clt> Tconst
%token <Data.clt> Tchar
%token <Data.clt> Tauto
%token <string * Data.clt> Tattr
%token TWords
%token TWhy0
%token <Data.clt> TWhy
%token <Data.clt> TWhile
%token <Data.clt> TWhen
%token TUsing
%token TTypedef
%token <string * Data.clt> TTypeId
%token TType
%token <Data.clt> TTilde
%token <Data.clt> TSwitch
%token <string * Data.clt> TString
%token TStatement
%token <Data.clt> TSizeof
%token <string> TRuleName
%token TRightIso
%token <Data.clt> TReturn
%token TPure
%token <Data.clt> TPtrOp
%token <Data.clt> TPtVirg
%token <string> TPragma
%token <string * Data.clt> TPlusFile
%token TPlus0
%token TParameter
%token TOn
%token <Data.clt> TOPar0
%token <Data.clt> TOPar
%token <Data.clt> TOEllipsis
%token <Data.clt> TOCro
%token <Data.clt> TOBrace
%token TNothing
%token <string * Data.clt> TMinusFile
%token <Data.clt> TMid0
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaType
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaStmList
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaStm
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaParamList
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaParam
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaLocalFunc
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaId
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaFunc
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaExpList
%token <(string * string) * Ast0_cocci.pure * Type_cocci.typeC list option *
          Data.clt> TMetaExp
%token <(string * string) * Ast0_cocci.pure * Data.clt> TMetaErr
%token <(string * string) * Ast0_cocci.pure * Type_cocci.typeC list option *
          Data.clt> TMetaConst
%token TMPtVirg
%token TLocal
%token <Data.clt> TLineEnd
%token TIsoType
%token TIsoTopLevel
%token TIsoStatement
%token TIsoExpression
%token TIsoDeclaration
%token TIso
%token TInvalid
%token <string * Data.clt> TInt
%token <string * Data.clt> TIncludeNL
%token <string * Data.clt> TIncludeL
%token <Data.clt> TInc
%token TIdentifier
%token <string * Data.clt> TIdent
%token TFunction
%token <Data.clt> TFunDecl
%token TFresh
%token <Data.clt> TFor
%token <string * Data.clt> TFloat
%token TExtends
%token TExpression
%token TError
%token <Data.clt> TEq
%token <Data.clt> TEllipsis
%token <Data.clt> TDotDot
%token <Data.clt> TDot
%token <Data.clt> TDo
%token TDepends
%token <Data.clt * token * int> TDefineParam
%token <Data.clt * token> TDefine
%token <Data.clt> TDefault
%token <string * Data.clt> TDeclarerId
%token TDeclarer
%token <Data.clt> TDec
%token <Data.clt> TContinue
%token TContext
%token TConstant
%token <Data.clt> TComma
%token <string * Data.clt> TChar
%token <Data.clt> TCase
%token <Data.clt> TCPar0
%token <Data.clt> TCPar
%token <Data.clt> TCEllipsis
%token <Data.clt> TCCro
%token <Data.clt> TCBrace
%token <Data.clt> TBreak
%token TBang0
%token <Data.clt> TBang
%token <Ast_cocci.assignOp * Data.clt> TAssign
%token TArobArob
%token TArob
%token EOF
%token <Data.clt> TIf
%token <Data.clt> TElse
%token <Data.clt> TOrLog
%token <Data.clt> TAndLog
%token <Data.clt> TOr
%token <Data.clt> TXor
%token <Data.clt> TAnd
%token <Data.clt> TNotEq
%token <Data.clt> TEqEq
%token <Data.clt> TSupEq
%token <Data.clt> TSup
%token <Data.clt> TInfEq
%token <Data.clt> TInf
%token <Data.clt> TShr
%token <Data.clt> TShl
%token <Data.clt> TPlus
%token <Data.clt> TMinus
%token <Data.clt> TMul
%token <Data.clt> TMod
%token <Data.clt> TDiv
%nonassoc TIf 
%nonassoc TElse 
%left TOrLog 
%left TAndLog 
%left TOr 
%left TXor 
%left TAnd 
%left TNotEq TEqEq 
%left TSupEq TSup TInfEq TInf 
%left TShr TShl 
%left TPlus TMinus 
%left TMul TMod TDiv 
%type <Ast0_cocci.anything list list> iso_main
%type <(Ast_cocci.metavar,Ast_cocci.metavar) Common.either list> iso_meta_main
%type <(Ast_cocci.metavar,Ast_cocci.metavar) Common.either list> meta_main
%type <Ast0_cocci.rule> minus_main
%type <unit> never_used
%type <Ast0_cocci.rule> plus_main
%type <unit> reinit
%type <string * Ast_cocci.dependency list * string option> rule_name
%%

meta_main:
| m = metadec
192
    {                       ( m (!Ast0.rule_name) )}
193 194 195

struct_or_union:
| s = Tstruct
196
    {                 ( P.clt2mcode Ast.Struct s )}
197
| u = Tunion
198
    {                 ( P.clt2mcode Ast.Union u )}
199

200
loption_pure_decl_statement_list_:
201
| 
202
    {    ( [] )}
203
| x = pure_decl_statement_list
204
    {    ( x )}
205 206 207

loption_plus_function_decl_statement_or_expression_:
| 
208
    {    ( [] )}
209
| x = plus_function_decl_statement_or_expression
210
    {    ( x )}
211 212 213

loption_minus_function_decl_statement_or_expression_:
| 
214
    {    ( [] )}
215
| x = minus_function_decl_statement_or_expression
216
    {    ( x )}
217 218 219

loption_fun_exp_decl_statement_list_:
| 
220
    {    ( [] )}
221
| x = fun_exp_decl_statement_list
222
    {    ( x )}
223 224 225

loption_filespec_:
| 
226
    {    ( [] )}
227
| x = filespec
228
    {    ( x )}
229 230 231

loption_error_words_:
| 
232
    {    ( [] )}
233
| x = error_words
234
    {    ( x )}
235 236 237

list_whens_pre_post_decl_statement_or_expression_rule_elem_statement__:
| 
238
    {    ( [] )}
239
| x = whens_pre_post_decl_statement_or_expression_rule_elem_statement_ xs = list_whens_pre_post_decl_statement_or_expression_rule_elem_statement__
240
    {    ( x :: xs )}
241 242 243

list_pair_edots_when_TEllipsis_eexpr__dexpr__:
| 
244
    {    ( [] )}
245 246 247 248
| x0 = edots_when_TEllipsis_eexpr_ y0 = dexpr xs = list_pair_edots_when_TEllipsis_eexpr__dexpr__
    {let x =
  let y = y0 in
  let x = x0 in
249
      ( (x, y) )
250
in
251
    ( x :: xs )}
252 253 254

list_pair_dots_when_TEllipsis_pre_post_decl_statement_or_expression_rule_elem_statement__exp_decl_statement_list__:
| 
255
    {    ( [] )}
256 257 258 259
| x0 = dots_when_TEllipsis_pre_post_decl_statement_or_expression_rule_elem_statement_ y0 = exp_decl_statement_list xs = list_pair_dots_when_TEllipsis_pre_post_decl_statement_or_expression_rule_elem_statement__exp_decl_statement_list__
    {let x =
  let y = y0 in
  let x = x0 in
260
      ( (x, y) )
261
in
262
    ( x :: xs )}
263 264 265

list_mzl_statement__:
| 
266
    {    ( [] )}
267
| x = mzl_statement_ xs = list_mzl_statement__
268
    {    ( x :: xs )}
269 270 271

list_mzl_rule_elem_statement__:
| 
272
    {    ( [] )}
273
| x = mzl_rule_elem_statement_ xs = list_mzl_rule_elem_statement__
274
    {    ( x :: xs )}
275 276 277

list_mzl_expr__:
| 
278
    {    ( [] )}
279
| x = mzl_expr_ xs = list_mzl_expr__
280
    {    ( x :: xs )}
281 282 283

list_mzl_eexpr__:
| 
284
    {    ( [] )}
285
| x = mzl_eexpr_ xs = list_mzl_eexpr__
286
    {    ( x :: xs )}
287 288 289

list_mzl_ctype__:
| 
290
    {    ( [] )}
291
| x = mzl_ctype_ xs = list_mzl_ctype__
292
    {    ( x :: xs )}
293 294 295

list_iso_xstatement_dots_TEllipsis___:
| 
296
    {    ( [] )}
297
| x = iso_xstatement_dots_TEllipsis__ xs = list_iso_xstatement_dots_TEllipsis___
298
    {    ( x :: xs )}
299

300 301
list_iso_single_statement__:
| 
302
    {    ( [] )}
303
| x = iso_single_statement_ xs = list_iso_single_statement__
304
    {    ( x :: xs )}
305

306
minus_main:
307 308 309 310 311 312
| _1 = minus_body _2 = EOF
    {                           ( _1 )}
| m = minus_body _2 = TArobArob
    {                                                           ( m )}
| m = minus_body _2 = TArob
    {                     ( m )}
313 314

metadec:
315
| ar = arity ispure = pure _10 = TIdentifier ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
316
    {let kindfn =
317
  let _1 = _10 in
318
      ( (fun arity name pure check_meta ->
319
      let tok = check_meta(Ast.MetaIdDecl(arity,name)) in
320
      !Data.add_id_meta name pure; tok) )
321
in
322
    ( function current_rule ->
323 324 325 326 327 328 329 330 331 332
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
333 334
	   ids) )}
| ar = arity ispure = pure _10 = TFresh _20 = TIdentifier ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
335
    {let kindfn =
336 337
  let _2 = _20 in
  let _1 = _10 in
338
      ( (fun arity name pure check_meta ->
339
      let tok = check_meta(Ast.MetaFreshIdDecl(arity,name)) in
340
      !Data.add_id_meta name pure; tok) )
341
in
342
    ( function current_rule ->
343 344 345 346 347 348 349 350 351 352
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
353 354
	   ids) )}
| ar = arity ispure = pure _10 = TType ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
355
    {let kindfn =
356
  let _1 = _10 in
357
      ( (fun arity name pure check_meta ->
358
      let tok = check_meta(Ast.MetaTypeDecl(arity,name)) in
359
      !Data.add_type_meta name pure; tok) )
360
in
361
    ( function current_rule ->
362 363 364 365 366 367 368 369 370 371
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
372 373
	   ids) )}
| ar = arity ispure = pure _10 = TParameter ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
374
    {let kindfn =
375
  let _1 = _10 in
376
      ( (fun arity name pure check_meta ->
377
      let tok = check_meta(Ast.MetaParamDecl(arity,name)) in
378
      !Data.add_param_meta name pure; tok) )
379
in
380
    ( function current_rule ->
381 382 383 384 385 386 387 388 389 390
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
391 392
	   ids) )}
| ar = arity ispure = pure _10 = TParameter _20 = Tlist ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
393
    {let kindfn =
394 395
  let _2 = _20 in
  let _1 = _10 in
396
      ( (fun arity name pure check_meta ->
397
      let tok = check_meta(Ast.MetaParamListDecl(arity,name)) in
398
      !Data.add_paramlist_meta name pure; tok))
399
in
400
    ( function current_rule ->
401 402 403 404 405 406 407 408 409 410
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
411 412
	   ids) )}
| ar = arity ispure = pure _10 = TError ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
413
    {let kindfn =
414
  let _1 = _10 in
415
      ( (fun arity name pure check_meta ->
416
      let tok = check_meta(Ast.MetaErrDecl(arity,name)) in
417
      !Data.add_err_meta name pure; tok) )
418
in
419
    ( function current_rule ->
420 421 422 423 424 425 426 427 428 429
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
430 431
	   ids) )}
| ar = arity ispure = pure _10 = TExpression ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
432
    {let kindfn =
433
  let _1 = _10 in
434
      ( (fun arity name pure check_meta ->
435
      let tok = check_meta(Ast.MetaExpDecl(arity,name,None)) in
436
      !Data.add_exp_meta None name pure; tok) )
437
in
438
    ( function current_rule ->
439 440 441 442 443 444 445 446 447 448
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
449 450
	   ids) )}
| ar = arity ispure = pure _10 = TExpression _20 = Tlist ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
451
    {let kindfn =
452 453
  let _2 = _20 in
  let _1 = _10 in
454
      ( (fun arity name pure check_meta ->
455
      let tok = check_meta(Ast.MetaExpListDecl(arity,name)) in
456
      !Data.add_explist_meta name pure; tok) )
457
in
458
    ( function current_rule ->
459 460 461 462 463 464 465 466 467 468
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
469 470
	   ids) )}
| ar = arity ispure = pure _10 = TExpression m0 = nonempty_list_TMul_ ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
471 472
    {let kindfn =
  let m = m0 in
473
  let _1 = _10 in
474
      ( (fun arity name pure check_meta ->
475 476
      let ty = Some [P.ty_pointerify Type_cocci.Unknown m] in
      let tok = check_meta(Ast.MetaExpDecl(arity,name,ty)) in
477
      !Data.add_exp_meta ty name pure; tok) )
478
in
479
    ( function current_rule ->
480 481 482 483 484 485 486 487 488 489
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
490 491
	   ids) )}
| ar = arity ispure = pure _10 = TStatement ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
492
    {let kindfn =
493
  let _1 = _10 in
494
      ( (fun arity name pure check_meta ->
495
      let tok = check_meta(Ast.MetaStmDecl(arity,name)) in
496
      !Data.add_stm_meta name pure; tok) )
497
in
498
    ( function current_rule ->
499 500 501 502 503 504 505 506 507 508
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
509 510
	   ids) )}
| ar = arity ispure = pure _10 = TStatement _20 = Tlist ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
511
    {let kindfn =
512 513
  let _2 = _20 in
  let _1 = _10 in
514
      ( (fun arity name pure check_meta ->
515
      let tok = check_meta(Ast.MetaStmListDecl(arity,name)) in
516
      !Data.add_stmlist_meta name pure; tok) )
517
in
518
    ( function current_rule ->
519 520 521 522 523 524 525 526 527 528
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
529 530
	   ids) )}
| ar = arity ispure = pure _10 = TFunction ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
531
    {let kindfn =
532
  let _1 = _10 in
533
      ( (fun arity name pure check_meta ->
534
      let tok = check_meta(Ast.MetaFuncDecl(arity,name)) in
535
      !Data.add_func_meta name pure; tok) )
536
in
537
    ( function current_rule ->
538 539 540 541 542 543 544 545 546 547
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
548 549
	   ids) )}
| ar = arity ispure = pure _10 = TLocal _20 = TFunction ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
550
    {let kindfn =
551 552
  let _2 = _20 in
  let _1 = _10 in
553
      ( (fun arity name pure check_meta ->
554 555
      let tok = check_meta(Ast.MetaLocalFuncDecl(arity,name)) in
      !Data.add_local_func_meta name pure;
556
      tok) )
557
in
558
    ( function current_rule ->
559 560 561 562 563 564 565 566 567 568
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
569 570
	   ids) )}
| ar = arity ispure = pure vl0 = meta_exp_type ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
571 572
    {let kindfn =
  let vl = vl0 in
573
      ( (fun arity name pure check_meta ->
574 575
      let ty = Some vl in
      let tok = check_meta(Ast.MetaExpDecl(arity,name,ty)) in
576
      !Data.add_exp_meta ty name pure; tok) )
577
in
578
    ( function current_rule ->
579 580 581 582 583 584 585 586 587 588
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
589 590
	   ids) )}
| ar = arity ispure = pure vl0 = meta_exp_type _20 = TOCro _30 = TCCro ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
591
    {let kindfn =
592 593
  let _3 = _30 in
  let _2 = _20 in
594
  let vl = vl0 in
595
      ( (fun arity name pure check_meta ->
596 597
      let ty = Some (List.map (function x -> Type_cocci.Array x) vl) in
      let tok = check_meta(Ast.MetaExpDecl(arity,name,ty)) in
598
      !Data.add_exp_meta ty name pure; tok) )
599
in
600
    ( function current_rule ->
601 602 603 604 605 606 607 608 609 610
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
611 612
	   ids) )}
| ar = arity ispure = pure _10 = TConstant ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
613
    {let kindfn =
614
  let _1 = _10 in
615
  let ty =
616
        ( None )
617
  in
618
      ( (fun arity name pure check_meta ->
619
      let tok = check_meta(Ast.MetaConstDecl(arity,name,ty)) in
620
      !Data.add_const_meta ty name pure; tok) )
621
in
622
    ( function current_rule ->
623 624 625 626 627 628 629 630 631 632
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
633 634
	   ids) )}
| ar = arity ispure = pure _10 = TConstant x00 = meta_exp_type ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
635 636
    {let kindfn =
  let x0 = x00 in
637
  let _1 = _10 in
638 639
  let ty =
    let x = x0 in
640
        ( Some x )
641
  in
642
      ( (fun arity name pure check_meta ->
643
      let tok = check_meta(Ast.MetaConstDecl(arity,name,ty)) in
644
      !Data.add_const_meta ty name pure; tok) )
645
in
646
    ( function current_rule ->
647 648 649 650 651 652 653 654 655 656
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
657 658
	   ids) )}
| ar = arity ispure = pure _10 = TTypedef ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
659
    {let kindfn =
660
  let _1 = _10 in
661
      ( (fun arity (_,name) pure check_meta ->
662 663
      if arity = Ast.NONE && pure = Ast0.Impure
      then (!Data.add_type_name name; [])
664
      else raise (Semantic_cocci.Semantic "bad typedef")) )
665
in
666
    ( function current_rule ->
667 668 669 670 671 672 673 674 675 676
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
677 678
	   ids) )}
| ar = arity ispure = pure _10 = TDeclarer ids = comma_list_pure_ident_or_meta_ident_ _5 = TMPtVirg
679
    {let kindfn =
680
  let _1 = _10 in
681
      ( (fun arity (_,name) pure check_meta ->
682 683
      if arity = Ast.NONE && pure = Ast0.Impure
      then (!Data.add_declarer_name name; [])
684
      else raise (Semantic_cocci.Semantic "bad declarer")) )
685
in
686
    ( function current_rule ->
687 688 689 690 691 692 693 694 695 696
      List.concat
	(List.map
	   (function (rule,nm) ->
	     let (rule,checker) =
	       match rule with
		 None -> ((current_rule,nm),function x -> [Common.Left x])
	       | Some rule ->
		   ((rule,nm),
		    function x -> P.check_meta x; [Common.Right x]) in
	     kindfn ar rule ispure checker)
697
	   ids) )}
698 699 700

meta_exp_type:
| t = ctype
701 702 703
    {    ( [Ast0_cocci.ast0_type_to_type t] )}
| _1 = TOBrace t = comma_list_ctype_ _3 = TCBrace m = list_TMul_
    {    ( List.map
704
	(function x -> P.ty_pointerify (Ast0_cocci.ast0_type_to_type x) m)
705
	t )}
706 707 708

struct_decl:
| t = ctype d = d_ident pv = TPtVirg
709 710
    {  ( let (id,fn) = d in
	 Ast0.wrap(Ast0.UnInit(None,fn t,id,P.clt2mcode ";" pv)) )}
711
| t = fn_ctype lp1 = TOPar st = TMul d = d_ident rp1 = TCPar lp2 = TOPar p = decl_list_name_opt_decl_ rp2 = TCPar pv = TPtVirg
712
    {        ( let (id,fn) = d in
713 714 715 716 717
        let t =
	  Ast0.wrap
	    (Ast0.FunctionPointer
	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
718
        Ast0.wrap(Ast0.UnInit(None,fn t,id,P.clt2mcode ";" pv)) )}
719 720
| i = pure_ident d = d_ident pv = TPtVirg
    {let cv =
721
      ( None )
722
in
723
  ( let (id,fn) = d in
724
	 let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
725
	 Ast0.wrap(Ast0.UnInit(None,fn idtype,id,P.clt2mcode ";" pv)) )}
726 727 728
| x0 = const_vol i = pure_ident d = d_ident pv = TPtVirg
    {let cv =
  let x = x0 in
729
      ( Some x )
730
in
731
  ( let (id,fn) = d in
732
	 let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
733
	 Ast0.wrap(Ast0.UnInit(None,fn idtype,id,P.clt2mcode ";" pv)) )}
734 735

struct_decl_list:
736 737
| _1 = struct_decl_list_start
    {                          ( Ast0.wrap(Ast0.DOTS(_1)) )}
738 739

struct_decl_list_start:
740 741 742 743
| _1 = struct_decl
    {                                     ( [_1] )}
| _1 = struct_decl _2 = struct_decl_list_start
    {                                     ( _1::_2 )}
744
| d = edots_when_TEllipsis_struct_decl_ r = continue_struct_decl_list
745
    {    ( (P.mkddots "..." d)::r )}
746 747 748

minus_body:
| f = loption_filespec_ i = list_includes_ b = loption_minus_function_decl_statement_or_expression_ ew = loption_error_words_
749
    {    ( match f@i@b@ew with
750
      [] -> raise (Semantic_cocci.Semantic "minus slice can't be empty")
751
    | code -> Top_level.top_level code )}
752 753 754

storage:
| s = Tstatic
755
    {                        ( P.clt2mcode Ast.Static s )}
756
| s = Tauto
757
    {                        ( P.clt2mcode Ast.Auto s )}
758
| s = Tregister
759
    {                        ( P.clt2mcode Ast.Register s )}
760
| s = Textern
761
    {                        ( P.clt2mcode Ast.Extern s )}
762 763

name_opt_decl:
764 765
| _1 = decl
    {            ( _1 )}
766
| t = ctype
767
    {              ( Ast0.wrap(Ast0.Param(t, None)) )}
768
| t = fn_ctype lp = TOPar s = TMul rp = TCPar lp1 = TOPar d = decl_list_name_opt_decl_ rp1 = TCPar
769
    {        ( let fnptr =
770 771 772 773
	  Ast0.wrap
	    (Ast0.FunctionPointer
	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp,
		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
774
	Ast0.wrap(Ast0.Param(fnptr, None)) )}
775 776

statement:
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
| _1 = TMetaStm
    {    ( P.meta_stm _1 )}
| _1 = expr _2 = TPtVirg
    {    ( P.exp_stm _1 _2 )}
| _1 = TIf _2 = TOPar _3 = eexpr _4 = TCPar _5 = single_statement %prec TIf
    {    ( P.ifthen _1 _2 _3 _4 _5 )}
| _1 = TIf _2 = TOPar _3 = eexpr _4 = TCPar _5 = single_statement _6 = TElse _7 = single_statement
    {    ( P.ifthenelse _1 _2 _3 _4 _5 _6 _7 )}
| _1 = TFor _2 = TOPar _3 = option_eexpr_ _4 = TPtVirg _5 = option_eexpr_ _6 = TPtVirg _7 = option_eexpr_ _8 = TCPar _9 = single_statement
    {    ( P.forloop _1 _2 _3 _4 _5 _6 _7 _8 _9 )}
| _1 = TWhile _2 = TOPar _3 = eexpr _4 = TCPar _5 = single_statement
    {    ( P.whileloop _1 _2 _3 _4 _5 )}
| _1 = TDo _2 = single_statement _3 = TWhile _4 = TOPar _5 = eexpr _6 = TCPar _7 = TPtVirg
    {    ( P.doloop _1 _2 _3 _4 _5 _6 _7 )}
| _1 = TSwitch _2 = TOPar _3 = eexpr _4 = TCPar _5 = TOBrace _6 = list_case_line_ _7 = TCBrace
    {    ( P.switch _1 _2 _3 _4 _5 _6 _7 )}
| _1 = TReturn _2 = eexpr _3 = TPtVirg
    {                        ( P.ret_exp _1 _2 _3 )}
| _1 = TReturn _2 = TPtVirg
    {                  ( P.ret _1 _2 )}
| _1 = TBreak _2 = TPtVirg
    {                 ( P.break _1 _2 )}
| _1 = TContinue _2 = TPtVirg
    {                    ( P.cont _1 _2 )}
| _1 = TOBrace _2 = pre_post_decl_statement_and_expression_opt _3 = TCBrace
    {    ( P.seq _1 _2 _3 )}
| _1 = TOEllipsis w = option_whenppdecs_ b = statement_dots_TEllipsis_ c = TCEllipsis
    {    ( Ast0.wrap(Ast0.Nest(P.clt2mcode "<..." _1,
805
			  Ast0.wrap(Ast0.DOTS(b (P.mkdots "..."))),
806
			  P.clt2mcode "...>" c, w)) )}
807 808

whenppdecs:
809 810
| _1 = TWhen _2 = TNotEq w = pre_post_decl_statement_or_expression _4 = TLineEnd
    {    ( w )}
811 812 813

statement_dots_TEllipsis_:
| r = no_dot_start_end_exp_decl_statement_list_dots_when_TEllipsis_pre_post_decl_statement_or_expression_rule_elem_statement__
814 815
    {  ( function dot_builder ->
    List.concat (r (function x -> [dot_builder x])) )}
816 817

single_statement:
818 819 820 821
| _1 = statement
    {                                      ( _1 )}
| _1 = TOPar0 _2 = midzero_list_statement_ _3 = TCPar0
    {      ( let (mids,code) = _2 in
822
        Ast0.wrap
823
	  (Ast0.Disj(P.clt2mcode "(" _1,
824
		     List.map (function x -> Ast0.wrap(Ast0.DOTS([x]))) code,
825
		     mids, P.clt2mcode ")" _3)) )}
826 827

nest_expressions:
828 829
| _1 = TOEllipsis w = option_whenexp_ e = expr_dots_TEllipsis_ c = TCEllipsis
    {    ( Ast0.wrap(Ast0.NestExpr(P.clt2mcode "<..." _1,
830
			      Ast0.wrap(Ast0.DOTS(e (P.mkedots "..."))),
831
			      P.clt2mcode "...>" c, w)) )}
832 833

whenexp:
834 835
| _1 = TWhen _2 = TNotEq w = eexpr _4 = TLineEnd
    {                                       ( w )}
836 837 838

separated_nonempty_list_TComma_pure_ident_or_meta_ident_:
| x = pure_ident_or_meta_ident
839 840 841
    {    ( [ x ] )}
| x = pure_ident_or_meta_ident _2 = TComma xs = separated_nonempty_list_TComma_pure_ident_or_meta_ident_
    {    ( x :: xs )}
842 843 844

separated_nonempty_list_TComma_dexpr_:
| x = dexpr
845 846 847
    {    ( [ x ] )}
| x = dexpr _2 = TComma xs = separated_nonempty_list_TComma_dexpr_
    {    ( x :: xs )}
848 849 850

separated_nonempty_list_TComma_d_ident_:
| x = d_ident
851 852 853
    {    ( [ x ] )}
| x = d_ident _2 = TComma xs = separated_nonempty_list_TComma_d_ident_
    {    ( x :: xs )}
854 855 856

separated_nonempty_list_TComma_ctype_:
| x = ctype
857 858 859
    {    ( [ x ] )}
| x = ctype _2 = TComma xs = separated_nonempty_list_TComma_ctype_
    {    ( x :: xs )}
860 861 862

separated_nonempty_list_TAndLog_pnrule_:
| x = pnrule
863 864 865
    {    ( [ x ] )}
| x = pnrule _2 = TAndLog xs = separated_nonempty_list_TAndLog_pnrule_
    {    ( x :: xs )}
866 867

plus_main:
868 869 870 871 872 873
| _1 = plus_body _2 = EOF
    {                         ( _1 )}
| p = plus_body _2 = TArobArob
    {                                                        ( p )}
| p = plus_body _2 = TArob
    {                    ( p )}
874 875 876

iso_meta_main:
| m = metadec
877
    {                         ( m "" )}
878 879

pure:
880 881 882 883
| _1 = TPure
    {              ( Ast0.Pure )}
| _1 = TContext
    {              ( Ast0.Context )}
884
| 
885
    {              ( Ast0.Impure )}
886 887

rule_name:
888
| nm = pure_ident _2 = extends d = depends _5 = TArob
889
    {let i =
890
      ( None )
891
in
892
    ( let n = P.id2name nm in
893 894 895
    (try let _ =  Hashtbl.find Data.all_metadecls n in
    raise (Semantic_cocci.Semantic ("repeated rule name"))
    with Not_found -> ());
896 897
    (n,d,i) )}
| nm = pure_ident _2 = extends d = depends x0 = choose_iso _5 = TArob
898 899
    {let i =
  let x = x0 in
900
      ( Some x )
901
in
902
    ( let n = P.id2name nm in
903 904 905
    (try let _ =  Hashtbl.find Data.all_metadecls n in
    raise (Semantic_cocci.Semantic ("repeated rule name"))
    with Not_found -> ());
906
    (n,d,i) )}
907 908 909

extends:
| 
910 911 912
    {                                                  ( () )}
| _1 = TExtends parent = TRuleName
    {    ( !Data.install_bindings (parent) )}
913 914 915

depends:
| 
916 917 918
    {                                                  ( [] )}
| _1 = TDepends _2 = TOn parents = separated_nonempty_list_TAndLog_pnrule_
    {                                                               ( parents )}
919 920

pnrule:
921 922 923 924
| _1 = TRuleName
    {                  ( Ast.Dep _1 )}
| _1 = TBang _2 = TRuleName
    {                  ( Ast.AntiDep _2 )}
925 926

choose_iso:
927 928
| _1 = TUsing _2 = TString
    {                     ( P.id2name _2 )}
929 930

arity:
931 932 933 934 935 936
| _1 = TBang0
    {              ( Ast.UNIQUE )}
| _1 = TWhy0
    {              ( Ast.OPT )}
| _1 = TPlus0
    {              ( Ast.MULTI )}
937
| 
938
    {                   ( Ast.NONE )}
939 940 941

generic_ctype:
| q = ctype_qualif
942
    {         ( Ast0.wrap(Ast0.ImplicitInt(q)) )}
943 944
| ty = Tchar
    {let q =
945
      ( None )
946
in
947
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.CharType ty, q)) )}
948 949 950
| x0 = ctype_qualif ty = Tchar
    {let q =
  let x = x0 in
951
      ( Some x )
952
in
953
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.CharType ty, q)) )}
954 955
| ty = Tshort
    {let q =
956
      ( None )
957
in
958
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.ShortType ty, q)) )}
959 960 961
| x0 = ctype_qualif ty = Tshort
    {let q =
  let x = x0 in
962
      ( Some x )
963
in
964
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.ShortType ty, q)) )}
965 966
| ty = Tint
    {let q =
967
      ( None )
968
in
969
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.IntType ty, q)) )}
970 971 972
| x0 = ctype_qualif ty = Tint
    {let q =
  let x = x0 in
973
      ( Some x )
974
in
975
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.IntType ty, q)) )}
976
| t = Tdouble
977
    {         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.DoubleType t, None)) )}
978
| t = Tfloat
979
    {         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.FloatType t, None)) )}
980 981
| ty = Tlong
    {let q =
982
      ( None )
983
in
984
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.LongType ty, q)) )}
985 986 987
| x0 = ctype_qualif ty = Tlong
    {let q =
  let x = x0 in
988
      ( Some x )
989
in
990
         ( Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.LongType ty, q)) )}
991
| s = struct_or_union i = ident
992
    {  ( Ast0.wrap(Ast0.StructUnionName(s, i)) )}
993
| s = struct_or_union i = ident l = TOBrace d = struct_decl_list r = TCBrace
994
    {  ( Ast0.wrap(Ast0.StructUnionDef(Ast0.wrap(Ast0.StructUnionName(s, i)),
995
					 P.clt2mcode "{" l,
996
					 d, P.clt2mcode "}" r)) )}
997
| s = TMetaType l = TOBrace d = struct_decl_list r = TCBrace
998
    {  ( let (nm,pure,clt) = s in
999 1000
	 let ty = Ast0.wrap(Ast0.MetaType(P.clt2mcode nm clt,pure)) in
	 Ast0.wrap
1001 1002 1003
	   (Ast0.StructUnionDef(ty,P.clt2mcode "{" l,d,P.clt2mcode "}" r)) )}
| r = TRuleName _2 = TDot p = TIdent
    {  ( let nm = (r,P.id2name p) in
1004 1005 1006 1007
	 (* this is only possible when we are in a metavar decl.  Otherwise,
	    it will be represented already as a MetaType *)
	 let _ = P.check_meta(Ast.MetaTypeDecl(Ast.NONE,nm)) in
	 Ast0.wrap(Ast0.MetaType(P.clt2mcode nm (P.id2clt p),
1008
				 Ast0.Impure (*will be ignored*))) )}
1009
| p = TTypeId
1010
    {  ( Ast0.wrap(Ast0.TypeName(P.id2mcode p)) )}
1011
| p = TMetaType
1012 1013
    {  ( let (nm,pure,clt) = p in
	 Ast0.wrap(Ast0.MetaType(P.clt2mcode nm clt,pure)) )}
1014 1015 1016

continue_struct_decl_list:
| 
1017 1018 1019 1020 1021
    {                                     ( [] )}
| _1 = struct_decl _2 = struct_decl_list_start
    {                                     ( _1::_2 )}
| _1 = struct_decl
    {                                     ( [_1] )}
1022 1023 1024 1025

ctype:
| ty = generic_ctype m = list_TMul_
    {let cv =
1026
      ( None )
1027
in
1028
  ( P.pointerify (P.make_cv cv ty) m )}
1029 1030 1031
| x0 = const_vol ty = generic_ctype m = list_TMul_
    {let cv =
  let x = x0 in
1032
      ( Some x )
1033
in
1034
  ( P.pointerify (P.make_cv cv ty) m )}
1035 1036
| t = Tvoid m = nonempty_list_TMul_
    {let cv =
1037
      ( None )
1038
in
1039
         ( let ty =
1040
	     Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.VoidType t, None)) in
1041
	   P.pointerify (P.make_cv cv ty) m )}
1042 1043 1044
| x0 = const_vol t = Tvoid m = nonempty_list_TMul_
    {let cv =
  let x = x0 in
1045
      ( Some x )
1046
in
1047
         ( let ty =
1048
	     Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.VoidType t, None)) in
1049
	   P.pointerify (P.make_cv cv ty) m )}
1050 1051 1052

fn_ctype:
| ty = generic_ctype m = list_TMul_
1053
    {                                     ( P.pointerify ty m )}
1054
| t = Tvoid m = list_TMul_
1055
    {         ( P.pointerify
1056
	     (Ast0.wrap(Ast0.BaseType(P.clt2mcode Ast.VoidType t, None)))
1057
	     m )}
1058 1059

ctype_qualif:
1060 1061 1062 1063
| _1 = Tunsigned
    {                   ( P.clt2mcode Ast.Unsigned _1 )}
| _1 = Tsigned
    {                   ( P.clt2mcode Ast.Signed _1 )}
1064 1065 1066

plus_body:
| f = loption_filespec_ i = list_includes_ b = loption_plus_function_decl_statement_or_expression_ ew = loption_error_words_
1067
    {    ( Top_level.top_level (f@i@b@ew) )}
1068 1069

filespec:
1070 1071 1072 1073
| _1 = TMinusFile _2 = TPlusFile
    {    ( [Ast0.wrap
	  (Ast0.FILEINFO(P.id2mcode _1,
			 P.id2mcode _2))] )}
1074 1075 1076

list_iso_dexpr__:
| 
1077
    {    ( [] )}
1078
| x = iso_dexpr_ xs = list_iso_dexpr__
1079
    {    ( x :: xs )}
1080 1081 1082

list_iso_decl_var__:
| 
1083
    {    ( [] )}
1084
| x = iso_decl_var_ xs = list_iso_decl_var__
1085
    {    ( x :: xs )}
1086 1087 1088

list_iso_ctype__:
| 
1089
    {    ( [] )}
1090
| x = iso_ctype_ xs = list_iso_ctype__
1091
    {    ( x :: xs )}
1092 1093 1094

list_includes_:
| 
1095
    {    ( [] )}
1096
| x = includes xs = list_includes_
1097
    {    ( x :: xs )}
1098 1099 1100

list_dp_comma_args_TEllipsis__:
| 
1101
    {    ( [] )}
1102
| x = dp_comma_args_TEllipsis_ xs = list_dp_comma_args_TEllipsis__
1103
    {    ( x :: xs )}
1104 1105 1106

list_comma_decls_TEllipsis_name_opt_decl__:
| 
1107
    {    ( [] )}
1108
| x = comma_decls_TEllipsis_name_opt_decl_ xs = list_comma_decls_TEllipsis_name_opt_decl__
1109
    {    ( x :: xs )}
1110 1111 1112

list_comma_decls_TEllipsis_decl__:
| 
1113
    {    ( [] )}
1114
| x = comma_decls_TEllipsis_decl_ xs = list_comma_decls_TEllipsis_decl__
1115
    {    ( x :: xs )}
1116 1117 1118

list_comma_args_edots_when_TEllipsis_eexpr___:
| 
1119
    {    ( [] )}
1120
| x = comma_args_edots_when_TEllipsis_eexpr__ xs = list_comma_args_edots_when_TEllipsis_eexpr___
1121
    {    ( x :: xs )}
1122 1123 1124

list_case_line_:
| 
1125
    {    ( [] )}
1126
| x = case_line xs = list_case_line_
1127
    {    ( x :: xs )}
1128 1129 1130

list_array_dec_:
| 
1131
    {    ( [] )}
1132
| x = array_dec xs = list_array_dec_
1133
    {    ( x :: xs )}