~ubuntu-branches/ubuntu/karmic/coccinelle/karmic

« back to all changes in this revision

Viewing changes to engine/cocci_vs_c.ml

  • Committer: Bazaar Package Importer
  • Author(s): Євгеній Мещеряков
  • Date: 2009-05-11 15:32:24 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090511153224-1odv41d4dkr3y80v
Tags: 0.1.8.deb-2
Use common install Makefile target for both native and bytecode
build. This hopefully fixes FTBFS on bytecode archs 

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
(*****************************************************************************)
31
31
(* Wrappers *)
32
32
(*****************************************************************************)
 
33
let pr2, pr2_once = Common.mk_pr2_wrappers Flag_matcher.verbose_matcher
33
34
 
34
35
(*****************************************************************************)
35
36
(* Helpers *)
91
92
let mcode_contain_plus = function
92
93
  | A.CONTEXT (_,A.NOTHING) -> false
93
94
  | A.CONTEXT _ -> true
94
 
  | A.MINUS (_,[]) -> false
95
 
  | A.MINUS (_,x::xs) -> true
 
95
  | A.MINUS (_,_,_,[]) -> false
 
96
  | A.MINUS (_,_,_,x::xs) -> true
96
97
  | A.PLUS -> raise Impossible
97
98
 
98
99
let mcode_simple_minus = function
99
 
  | A.MINUS (_,[]) -> true
 
100
  | A.MINUS (_,_,_,[]) -> true
100
101
  | _ -> false
101
102
 
102
103
 
110
111
 
111
112
let minusizer = 
112
113
  ("fake","fake"), 
113
 
  {A.line = 0; column =0; A.strbef=[]; A.straft=[];},
114
 
  (A.MINUS(A.DontCarePos, [])),
 
114
  {A.line = 0; A.column =0; A.strbef=[]; A.straft=[];},
 
115
  (A.MINUS(A.DontCarePos,[],-1,[])),
115
116
  A.NoMetaPos
116
117
 
117
118
let generalize_mcode ia = 
121
122
    | A.PLUS -> raise Impossible
122
123
    | A.CONTEXT (A.NoPos,x) -> 
123
124
        A.CONTEXT (A.DontCarePos,x)
124
 
    | A.MINUS   (A.NoPos,x) -> 
125
 
        A.MINUS   (A.DontCarePos,x)
 
125
    | A.MINUS   (A.NoPos,inst,adj,x) -> 
 
126
        A.MINUS   (A.DontCarePos,inst,adj,x)
126
127
 
127
128
    | A.CONTEXT ((A.FixPos _|A.DontCarePos), _) 
128
 
    | A.MINUS ((A.FixPos _|A.DontCarePos), _)
 
129
    | A.MINUS ((A.FixPos _|A.DontCarePos), _, _, _)
129
130
        ->
130
131
        raise Impossible
131
132
  in
448
449
                    ref (Some ((Lib_parsing_c.al_type returnType),local),
449
450
                               Ast_c.NotTest) in
450
451
                  let ident = name in
451
 
                  let idexpr = (B.Ident (ident), typ),Ast_c.noii in
452
 
                  F.DefineExpr
453
 
                    ((B.Assignment (idexpr, B.SimpleAssign, e), 
454
 
                     Ast_c.noType()), [iini])
 
452
                  let idexpr = 
 
453
                    Ast_c.mk_e_bis (B.Ident (ident)) typ Ast_c.noii
 
454
                  in
 
455
                  let assign = 
 
456
                    Ast_c.mk_e 
 
457
                      (B.Assignment (idexpr,B.SimpleAssign, e)) [iini] in
 
458
                  F.DefineExpr assign
 
459
                    
455
460
              | _ -> F.Decl decl
456
461
              )
457
462
          | _ -> F.Decl decl
762
767
          ))
763
768
      in
764
769
      (match term ia1, ib with 
765
 
      | A.Int x, B.Int y -> 
 
770
      | A.Int x, B.Int (y,_) -> 
766
771
          X.value_format_flag (fun use_value_equivalence -> 
767
772
            if use_value_equivalence 
768
773
            then 
1082
1087
 
1083
1088
 
1084
1089
 
1085
 
 
1086
1090
(* ------------------------------------------------------------------------- *)
1087
1091
and (ident_cpp: info_ident -> (A.ident, B.name) matcher) = 
1088
 
 fun infoidb ida idb -> 
 
1092
 fun infoidb ida idb ->
1089
1093
   match idb with
1090
1094
   | B.RegularName (s, iis) -> 
1091
1095
       let iis = tuple_of_list1 iis in
1095
1099
           (B.RegularName (s, [iis]))
1096
1100
         ))
1097
1101
   | B.CppConcatenatedName _ | B.CppVariadicName _ |B.CppIdentBuilder _
1098
 
       -> raise Todo
 
1102
       ->
 
1103
         (* This should be moved to the Id case of ident.  Metavariables
 
1104
         should be allowed to be bound to such variables.  But doing so
 
1105
         would require implementing an appropriate distr function *)
 
1106
         fail
1099
1107
 
1100
1108
and (ident: info_ident -> (A.ident, string * Ast_c.info) matcher) = 
1101
1109
 fun infoidb ida ((idb, iib) as ib) -> 
1663
1671
                         [iisb;lpb;rpb;iiendb;iifakestart] ++ iistob))
1664
1672
          ))))))))
1665
1673
 
1666
 
  | _, (B.MacroDecl _ |B.DeclList _) -> fail
 
1674
  | _, (B.MacroDecl _ |B.DeclList _) ->       fail
1667
1675
 
1668
1676
 
1669
1677
 
2229
2237
      )
2230
2238
 
2231
2239
and (struct_field: (A.declaration, B.field) matcher) = fun fa fb -> 
2232
 
  let (xfield, iifield) = fb in
2233
2240
 
2234
 
  match xfield with 
 
2241
  match fb with 
2235
2242
  | B.DeclarationField (B.FieldDeclList (onefield_multivars,iiptvirg)) -> 
2236
2243
 
2237
2244
    let iiptvirgb = tuple_of_list1 iiptvirg in
2276
2283
                  return (
2277
2284
                    (fa),
2278
2285
                    ((B.DeclarationField 
2279
 
                        (B.FieldDeclList ([onevar, iivirg], [iiptvirgb]))),
2280
 
                    iifield)
 
2286
                        (B.FieldDeclList ([onevar, iivirg], [iiptvirgb])))
 
2287
                    )
2281
2288
                  )
2282
2289
              | _ -> raise Impossible
2283
2290
            )
2287
2294
      pr2_once "PB: More that one variable in decl. Have to split";
2288
2295
      fail
2289
2296
    )
2290
 
  | B.EmptyField -> 
2291
 
      let _iiptvirgb = tuple_of_list1 iifield in
 
2297
  | B.EmptyField _iifield -> 
2292
2298
      fail
2293
2299
 
2294
 
  | B.MacroStructDeclTodo -> fail
 
2300
  | B.MacroDeclField _ -> 
 
2301
      raise Todo
 
2302
 
2295
2303
  | B.CppDirectiveStruct directive -> fail
2296
2304
  | B.IfdefStruct directive -> fail
2297
2305
 
3748
3756
 
3749
3757
  | _, F.ExprStatement (_, (None, ii)) -> fail (* happen ? *)
3750
3758
 
3751
 
  | A.Label(id,dd), F.Label (st,(s,ii)) ->
3752
 
      let (ib1,ib2) = tuple_of_list2 ii in
3753
 
      let (string_of_id,rebuild) =
3754
 
        match A.unwrap id with
3755
 
          A.Id(s) -> (s,function s -> A.rewrap id (A.Id(s)))
3756
 
        | _ -> failwith "labels with metavariables not supported" in
3757
 
      if (term string_of_id) =$= s
3758
 
      then
3759
 
        tokenf string_of_id ib1 >>= (fun string_of_id ib1 ->
 
3759
  | A.Label(id,dd), F.Label (st, nameb, ((),ii)) ->
 
3760
      let (ib2) = tuple_of_list1 ii in
 
3761
      (match A.unwrap id with
 
3762
      | A.Id(_s) ->
 
3763
        ident_cpp DontKnow id nameb >>= (fun ida nameb ->
3760
3764
        tokenf dd ib2 >>= (fun dd ib2 ->
3761
3765
          return (
3762
 
            A.Label(rebuild string_of_id,dd),
3763
 
            F.Label (st,(s,[ib1;ib2]))
 
3766
            A.Label (ida,dd),
 
3767
            F.Label (st,nameb, ((),[ib2]))
3764
3768
          )))
3765
 
      else fail
 
3769
      | _ -> failwith "labels with metavariables not supported"
 
3770
      )
3766
3771
 
3767
 
  | A.Goto(goto,id,sem),          F.Goto (st,(s,ii))       ->
3768
 
      let (ib1,ib2,ib3) = tuple_of_list3 ii in
 
3772
  | A.Goto(goto,id,sem),          F.Goto (st,nameb, ((),ii))       ->
 
3773
      let (ib1,ib3) = tuple_of_list2 ii in
3769
3774
      tokenf goto ib1 >>= (fun goto ib1 ->
3770
 
      ident DontKnow id (s, ib2) >>= (fun id (s, ib2) ->
 
3775
      ident_cpp DontKnow id nameb >>= (fun id nameb ->
3771
3776
      tokenf sem ib3 >>= (fun sem ib3 ->
3772
3777
        return(
3773
3778
            A.Goto(goto,id,sem),
3774
 
            F.Goto (st,(s,[ib1;ib2;ib3]))
 
3779
            F.Goto (st,nameb, ((),[ib1;ib3]))
3775
3780
          ))))
3776
3781
 
3777
3782
  (* have not a counter part in coccinelle, for the moment *)
3788
3793
    (F.MacroStmt (_, _)| F.DefineDoWhileZeroHeader _| F.EndNode|F.TopNode)
3789
3794
      -> fail
3790
3795
  | _, 
3791
 
    (F.Label (_, _)|F.Break (_, _)|F.Continue (_, _)|F.Default (_, _)|
 
3796
    (F.Label (_, _, _)|F.Break (_, _)|F.Continue (_, _)|F.Default (_, _)|
3792
3797
    F.Case (_, _)|F.Include _|F.Goto _|F.ExprStatement _|
3793
3798
    F.DefineType _|F.DefineExpr _|F.DefineTodo|
3794
3799
    F.DefineHeader (_, _)|F.ReturnExpr (_, _)|F.Return (_, _)|F.MacroIterHeader (_, _)|