45
45
let (option: 'a matcher -> ('a option matcher)) = fun f t1 t2 ->
47
| (Some t1, Some t2) ->
47
| (Some t1, Some t2) ->
51
51
| (None, None) -> return None
55
let same_s saopt sbopt =
55
let same_s saopt sbopt =
56
56
match saopt, sbopt with
57
57
| None, None -> true
58
| Some namea, Some nameb ->
58
| Some namea, Some nameb ->
59
59
let sa = Ast_c.str_of_name namea in
60
60
let sb = Ast_c.str_of_name nameb in
65
let rec fullType a b =
65
let rec fullType a b =
66
66
let ((qua,iiqa), tya) = a in
67
67
let ((qub,iiqb), tyb) = b in
68
68
(qua.const =:= qub.const && qua.volatile =:= qub.volatile) >&&>
70
let (qu,iiq) = (qua, iiqa) in
71
typeC tya tyb >>= (fun ty ->
70
let (qu,iiq) = (qua, iiqa) in
71
typeC tya tyb >>= (fun ty ->
72
72
return ((qu,iiq), ty)
76
76
let (a, iia) = tya in
77
77
let (b, iib) = tyb in
82
| BaseType a, BaseType b ->
82
| BaseType a, BaseType b ->
83
83
a =*= b >&&> return (BaseType a, iix)
84
| Pointer a, Pointer b ->
84
| Pointer a, Pointer b ->
85
85
fullType a b >>= (fun x -> return (Pointer x, iix))
87
| StructUnionName (sua, sa), StructUnionName (sub, sb) ->
88
(sua =*= sub && sa =$= sb) >&&>
87
| StructUnionName (sua, sa), StructUnionName (sub, sb) ->
88
(sua =*= sub && sa =$= sb) >&&>
89
89
return (StructUnionName (sua, sa), iix)
91
| TypeName (namea, opta), TypeName (nameb, optb) ->
91
| TypeName (namea, opta), TypeName (nameb, optb) ->
92
92
let sa = Ast_c.str_of_name namea in
93
93
let sb = Ast_c.str_of_name nameb in
95
95
(* assert compatible opta optb ? *)
96
96
(*option fullType opta optb*)
99
99
(match opta, optb with
100
100
| None, None -> None
108
108
return (TypeName (namea, opt), iix)
111
| Array (ea, a), Array (eb,b) ->
111
| Array (ea, a), Array (eb,b) ->
112
112
let get_option f = function Some x -> Some (f x) | None -> None in
113
113
let ea = get_option Lib_parsing_c.al_expr ea in
114
114
let eb = get_option Lib_parsing_c.al_expr eb in
115
115
ea =*= eb >&&> fullType a b >>= (fun x -> return (Array (ea, x), iix))
117
| FunctionType (returna, paramsa), FunctionType (returnb, paramsb) ->
117
| FunctionType (returna, paramsa), FunctionType (returnb, paramsb) ->
118
118
let (tsa, (ba,iihas3dotsa)) = paramsa in
119
119
let (tsb, (bb,iihas3dotsb)) = paramsb in
154
154
let paramsx = (List.rev tsx, (bx, iihas3dotsx)) in
155
155
return (FunctionType (returnx, paramsx), iix)
158
| Enum (saopt, enuma), Enum (sbopt, enumb) ->
158
| Enum (saopt, enuma), Enum (sbopt, enumb) ->
159
159
(saopt =*= sbopt &&
160
List.length enuma =|= List.length enumb &&
161
Common.zip enuma enumb +> List.for_all (fun
160
List.length enuma =|= List.length enumb &&
161
Common.zip enuma enumb +> List.for_all (fun
162
162
(((namesa,eopta), iicommaa), ((namesb,eoptb),iicommab))
164
164
let sa = str_of_name namesa in
165
165
let sb = str_of_name namesb in
167
167
(* todo ? eopta and b can have some info so ok to use =*= ? *)
171
171
return (Enum (saopt, enuma), iix)
173
173
| EnumName sa, EnumName sb -> sa =$= sb >&&> return (EnumName sa, iix)
175
| ParenType a, ParenType b ->
175
| ParenType a, ParenType b ->
177
fullType a b >>= (fun x ->
177
fullType a b >>= (fun x ->
178
178
return (ParenType x, iix)
181
| TypeOfExpr ea, TypeOfExpr eb ->
181
| TypeOfExpr ea, TypeOfExpr eb ->
182
182
let ea = Lib_parsing_c.al_expr ea in
183
183
let eb = Lib_parsing_c.al_expr eb in
184
184
ea =*= eb >&&> return (TypeOfExpr ea, iix)
186
| TypeOfType a, TypeOfType b ->
186
| TypeOfType a, TypeOfType b ->
187
187
fullType a b >>= (fun x -> return (TypeOfType x, iix))
189
(* | TypeOfType a, b ->
189
(* | TypeOfType a, b ->
194
| StructUnion (sua, saopt, sta), StructUnion (sub, sbopt, stb) ->
195
(sua =*= sub && saopt =*= sbopt && List.length sta =|= List.length stb)
197
Common.zip sta stb +> List.fold_left
198
(fun acc ((fielda), (fieldb)) ->
200
match fielda, fieldb with
201
| EmptyField iia, EmptyField iib ->
194
| StructUnion (sua, saopt, sta), StructUnion (sub, sbopt, stb) ->
195
(sua =*= sub && saopt =*= sbopt && List.length sta =|= List.length stb)
197
Common.zip sta stb +> List.fold_left
198
(fun acc ((fielda), (fieldb)) ->
200
match fielda, fieldb with
201
| EmptyField iia, EmptyField iib ->
203
203
return ((EmptyField iix)::xs)
205
| DeclarationField (FieldDeclList (fa, iipta)),
206
DeclarationField (FieldDeclList (fb, iiptb)) ->
205
| DeclarationField (FieldDeclList (fa, iipta)),
206
DeclarationField (FieldDeclList (fb, iiptb)) ->
207
207
let iipt = iipta in (* TODO ?*)
208
(List.length fa =|= List.length fb) >&&>
208
(List.length fa =|= List.length fb) >&&>
210
Common.zip fa fb +> List.fold_left
211
(fun acc2 ((fielda,iia),(fieldb,iib))->
210
Common.zip fa fb +> List.fold_left
211
(fun acc2 ((fielda,iia),(fieldb,iib))->
214
214
match fielda, fieldb with
215
| Simple (nameaopt, ta), Simple (namebopt, tb) ->
218
same_s nameaopt namebopt >&&>
219
fullType ta tb >>= (fun tx ->
215
| Simple (nameaopt, ta), Simple (namebopt, tb) ->
218
same_s nameaopt namebopt >&&>
219
fullType ta tb >>= (fun tx ->
220
220
return (((Simple (nameaopt, tx)), iix)::xs)
223
| BitField (nameopta, ta, infoa, ea),
224
BitField (nameoptb, tb, infob, eb) ->
223
| BitField (nameopta, ta, infoa, ea),
224
BitField (nameoptb, tb, infob, eb) ->
225
225
let infox = infoa in
226
(same_s nameopta nameoptb && ea =*= eb) >&&>
227
fullType ta tb >>= (fun tx ->
226
(same_s nameopta nameoptb && ea =*= eb) >&&>
227
fullType ta tb >>= (fun tx ->
228
228
return (((BitField (nameopta,tx,infox,ea)), iix)::xs)
234
return (((DeclarationField
234
return (((DeclarationField
235
235
(FieldDeclList (List.rev fx,iipt))))::xs)
250
250
* must put iib and not iix, because we want the token corresponding
251
251
* to the typedef.
253
| TypeName (name, Some a), _ ->
254
fullType a (Ast_c.nQ, tyb) >>= (fun x ->
255
return (TypeName (name, Some x), iia)
253
| TypeName (name, Some a), _ ->
254
fullType a (Ast_c.nQ, tyb) >>= (fun x ->
255
return (TypeName (name, Some x), iia)
258
| _, TypeName (name, Some b) ->
259
fullType b (Ast_c.nQ, tya) >>= (fun x ->
258
| _, TypeName (name, Some b) ->
259
fullType b (Ast_c.nQ, tya) >>= (fun x ->
260
260
return (TypeName (name, Some x), iib) (* subtil: *)