~ubuntu-branches/ubuntu/trusty/coccinelle/trusty-proposed

« back to all changes in this revision

Viewing changes to parsing_cocci/unify_ast.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 15:05:03 UTC
  • mfrom: (7.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110421150503-2pde6r9lgsn31t33
Tags: 0.2.5.deb-3
* Team upload
* Compile in bytecode only on non-natdynlink architectures (fixes FTBFS)

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
    Ast.Dots(_,_,_,_) | Ast.Circles(_,_,_,_) | Ast.Stars(_,_,_,_) -> true
113
113
  | _ -> false
114
114
 
 
115
let idots e =
 
116
  match Ast.unwrap e with
 
117
    Ast.Idots(_,_) -> true
 
118
  | _ -> false
 
119
 
115
120
(* --------------------------------------------------------------------- *)
116
121
(* Identifier *)
117
122
 
118
 
and unify_ident i1 i2 =
 
123
let rec unify_ident i1 i2 =
119
124
  match (Ast.unwrap i1,Ast.unwrap i2) with
120
125
    (Ast.Id(i1),Ast.Id(i2)) -> return (unify_mcode i1 i2)
121
126
 
126
131
  | (_,Ast.MetaFunc(_,_,_,_))
127
132
  | (_,Ast.MetaLocalFunc(_,_,_,_)) -> return true
128
133
 
 
134
  | (Ast.DisjId(i1),_) ->
 
135
      disjunct_all_bindings (List.map (function x -> unify_ident x i2) i1)
 
136
  | (_,Ast.DisjId(i2)) ->
 
137
      disjunct_all_bindings (List.map (function x -> unify_ident i1 x) i2)
 
138
 
129
139
  | (Ast.OptIdent(_),_)
130
140
  | (Ast.UniqueIdent(_),_)
131
141
  | (_,Ast.OptIdent(_))
134
144
(* --------------------------------------------------------------------- *)
135
145
(* Expression *)
136
146
 
137
 
let rec unify_expression e1 e2 =
 
147
and unify_expression e1 e2 =
138
148
  match (Ast.unwrap e1,Ast.unwrap e2) with
139
149
    (Ast.Ident(i1),Ast.Ident(i2)) -> unify_ident i1 i2
140
150
  | (Ast.Constant(c1),Ast.Constant(c2))-> return (unify_mcode c1 c2)
254
264
  | (Ast.Array(ty1,lb1,e1,rb1),Ast.Array(ty2,lb2,e2,rb2)) ->
255
265
      conjunct_bindings
256
266
        (unify_fullType ty1 ty2) (unify_option unify_expression e1 e2)
257
 
  | (Ast.EnumName(s1,ts1),Ast.EnumName(s2,ts2)) ->
 
267
  | (Ast.EnumName(s1,Some ts1),Ast.EnumName(s2,Some ts2)) ->
258
268
      if unify_mcode s1 s2 then unify_ident ts1 ts2 else return false
 
269
  | (Ast.EnumName(s1,None),Ast.EnumName(s2,None)) ->
 
270
      return true
 
271
  | (Ast.EnumDef(ty1,lb1,ids1,rb1),Ast.EnumDef(ty2,lb2,ids2,rb2)) ->
 
272
       conjunct_bindings (unify_fullType ty1 ty2)
 
273
         (unify_dots unify_expression edots ids1 ids2)
259
274
  | (Ast.StructUnionName(s1,Some ts1),Ast.StructUnionName(s2,Some ts2)) ->
260
275
      if unify_mcode s1 s2 then unify_ident ts1 ts2 else return false
261
276
  | (Ast.StructUnionName(s1,None),Ast.StructUnionName(s2,None)) ->
262
 
      return true
 
277
      return (unify_mcode s1 s2)
263
278
  | (Ast.StructUnionDef(ty1,lb1,decls1,rb1),
264
279
     Ast.StructUnionDef(ty2,lb2,decls2,rb2)) ->
265
280
       conjunct_bindings (unify_fullType ty1 ty2)
277
292
 
278
293
and unify_declaration d1 d2 =
279
294
  match (Ast.unwrap d1,Ast.unwrap d2) with
280
 
    (Ast.Init(stg1,ft1,id1,eq1,i1,s1),Ast.Init(stg2,ft2,id2,eq2,i2,s2)) ->
 
295
    (Ast.MetaDecl(_,_,_),_) | (_,Ast.MetaDecl(_,_,_)) -> return true
 
296
  | (Ast.MetaField(_,_,_),_) | (_,Ast.MetaField(_,_,_)) -> return true
 
297
  | (Ast.MetaFieldList(_,_,_,_),_) | (_,Ast.MetaFieldList(_,_,_,_)) ->
 
298
      return true
 
299
  | (Ast.Init(stg1,ft1,id1,eq1,i1,s1),Ast.Init(stg2,ft2,id2,eq2,i2,s2)) ->
281
300
      if bool_unify_option unify_mcode stg1 stg2
282
301
      then
283
302
        conjunct_bindings (unify_fullType ft1 ft2)
317
336
    (Ast.MetaInit(_,_,_),_) | (_,Ast.MetaInit(_,_,_)) -> return true
318
337
  | (Ast.InitExpr(expa),Ast.InitExpr(expb)) ->
319
338
      unify_expression expa expb
320
 
  | (Ast.InitList(_,_,initlista,_,whena),
321
 
     Ast.InitList(_,_,initlistb,_,whenb)) ->
 
339
  | (Ast.ArInitList(_,initlista,_),
 
340
     Ast.ArInitList(_,initlistb,_)) ->
 
341
      (* ignore whencode - returns true safely *)
 
342
      unify_dots unify_initialiser idots initlista initlistb
 
343
  | (Ast.StrInitList(_,_,initlista,_,whena),
 
344
     Ast.StrInitList(_,_,initlistb,_,whenb)) ->
322
345
      (* ignore whencode - returns true safely *)
323
346
      unify_lists unify_initialiser (function _ -> false) initlista initlistb
324
347
  | (Ast.InitGccExt(designatorsa,_,inia),
437
460
     Ast.IteratorHeader(nm2,lp2,args2,rp2)) ->
438
461
      conjunct_bindings (unify_ident nm1 nm2)
439
462
         (unify_dots unify_expression edots args1 args2)
 
463
  | (Ast.Undef(_,n1),Ast.Undef(_,n2)) -> unify_ident n1 n2
440
464
  | (Ast.DefineHeader(_,n1,p1),Ast.DefineHeader(_,n2,p2)) ->
441
465
      conjunct_bindings (unify_ident n1 n2)
442
466
        (unify_define_parameters p1 p2)
504
528
  let donothing r k e = k e in
505
529
  let recursor = V.combiner bind option_default
506
530
      mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
507
 
      donothing donothing donothing donothing
 
531
      donothing donothing donothing donothing donothing
508
532
      donothing expr donothing donothing donothing donothing donothing
509
533
      donothing donothing donothing donothing donothing in
510
534
  recursor.V.combiner_rule_elem
517
541
  let donothing r k e = k e in
518
542
  let recursor = V.combiner bind option_default
519
543
      mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
520
 
      donothing donothing donothing donothing
 
544
      donothing donothing donothing donothing donothing
521
545
      donothing donothing fullType donothing donothing donothing donothing
522
546
      donothing donothing donothing donothing donothing in
523
547
  recursor.V.combiner_rule_elem