~npalix/coccinelle/upstream

« back to all changes in this revision

Viewing changes to parsing_cocci/get_constants2.ml

  • Committer: Julia Lawall
  • Date: 2008-06-10 19:49:56 UTC
  • Revision ID: git-v1:bfce445bc28d65de46ab3c6c86424a6d98a24ce5
*** empty log message ***

svn path=/coccinelle/; revision=4494

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
      | 1  -> y::(merge l1 ys)
65
65
      | _ -> failwith "not possible")
66
66
 
 
67
let intersect l1 l2 = List.filter (function l1e -> List.mem l1e l2) l1
 
68
 
 
69
let minus_set l1 l2 = List.filter (function l1e -> not (List.mem l1e l2)) l1
 
70
 
67
71
let rec insert x l = merge [x] l
68
72
 
69
 
let build_and x y =
 
73
let rec build_and x y =
70
74
  if x = y
71
75
  then x
72
76
  else
76
80
    | (And l1,And l2) -> And (merge l1 l2)
77
81
    | (x,Or l) when List.mem x l -> x
78
82
    | (Or l,x) when List.mem x l -> x
 
83
    | (Or l1,Or l2) when not ((intersect l1 l2) = []) ->
 
84
        let inner =
 
85
          build_and
 
86
            (List.fold_left build_or False (minus_set l1 l2))
 
87
            (List.fold_left build_or False (minus_set l2 l1)) in
 
88
        List.fold_left build_or inner (intersect l1 l2)
79
89
    | (x,And l) | (And l,x) ->
80
 
        if List.mem x l then And l else And (insert x l)
 
90
        if List.mem x l
 
91
        then And l
 
92
        else
 
93
          let others =
 
94
            List.filter
 
95
              (function
 
96
                  Or l -> not(List.mem x l)
 
97
                | _ -> true)
 
98
              l in
 
99
          And (insert x others)
81
100
    | (x,y) -> norm(And [x;y])
82
101
 
83
 
let build_or x y =
 
102
and build_or x y =
84
103
  if x = y
85
104
  then x
86
105
  else
90
109
    | (Or l1,Or l2) -> Or (merge l1 l2)
91
110
    | (x,And l) when List.mem x l -> x
92
111
    | (And l,x) when List.mem x l -> x
 
112
    | (And l1,And l2) when not ((intersect l1 l2) = []) ->
 
113
        let inner =
 
114
          build_or
 
115
            (List.fold_left build_and True (minus_set l1 l2))
 
116
            (List.fold_left build_and True (minus_set l2 l1)) in
 
117
        List.fold_left build_and inner (intersect l1 l2)
93
118
    | (x,Or l) | (Or l,x) ->
94
 
        if List.mem x l then Or l else Or (insert x l)
 
119
        if List.mem x l
 
120
        then Or l
 
121
        else
 
122
          let others =
 
123
            List.filter
 
124
              (function
 
125
                  And l -> not(List.mem x l)
 
126
                | _ -> true)
 
127
              l in
 
128
          Or (insert x others)
95
129
    | (x,y) -> norm(Or [x;y])
96
130
 
97
131
let keep x = Elem x
244
278
                List.fold_left
245
279
                  (function prev ->
246
280
                    function
247
 
                        Ast.IncPath s -> (Elem s)::prev
 
281
                        (* just take the last thing, probably the most
 
282
                           specific.  everything is necessary anyway. *)
 
283
                        Ast.IncPath s -> [Elem s]
248
284
                      | Ast.IncDots -> prev)
249
285
                  [] l in
250
286
              (match strings with