Re: [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
On Mon, 2020-03-16 at 20:20 +0100, Markus Elfring wrote: > > ParenType and FunctionType are added to the SmPL ASTs. > > Add cases for these types in ….ml. > > A change description template was used several times. > I wonder if there is really a need to modify only a single OCaml > source file > in these update steps. > How do you think about to combine such changes in a bigger update > step? > These are separated this way so that it's easier for Julia to review. She will probably just squash all 26 of these together and apply them later. Cheers, Jaskaran. > Regards, > Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
On Mon, 2020-03-16 at 20:10 +0100, Markus Elfring wrote: > > The order of the terms in ParenType require implementing a special > > case for ParenType. This case handles only the following: > … > > It seems that this change description was repeated in other update > steps. Whoops, dumb mistake. 04 is for AST0 visitor and 05 for AST visitor. Will send a v2 for this. Cheers, Jaskaran. > Does this detail indicate a need to reconsider the patch granularity? > > Regards, > Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
> ParenType and FunctionType are added to the SmPL ASTs. > Add cases for these types in ….ml. A change description template was used several times. I wonder if there is really a need to modify only a single OCaml source file in these update steps. How do you think about to combine such changes in a bigger update step? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
> The order of the terms in ParenType require implementing a special > case for ParenType. This case handles only the following: … It seems that this change description was repeated in other update steps. Does this detail indicate a need to reconsider the patch granularity? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs
> ParenType and FunctionType are types present in the C AST that > are not present in the SmPL AST. Will a bit more background information become helpful for these data types? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
> Thus, a slightly hacky approach is taken to determine a function > prototype with not the best certainty but what works for most cases > in SmPL. If the identifier is preceded by any token that does not > seem to be part of a type, then it is not identified as a function > prototype. Else, it is. Would you like to extend this explanation? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs
> The aim of this patch series is to add the types ParenType Can it be that this kind of data processing will need a bit more explanation? > The FunctionPointer type is removed from the SmPL AST, since > all the productions that produce FunctionPointers in the SmPL > parser are replaced by those that produce ParenType. I imagine that dedicated data types can occasionally be helpful. Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 26/26] tests: Add test case for array of function pointers
Add a test case to match against an array of function pointers. This would previously not work due to differences in the C and SmPL ASTs. Signed-off-by: Jaskaran Singh --- tests/funptr_array.c | 1 + tests/funptr_array.cocci | 9 + tests/funptr_array.res | 1 + 3 files changed, 11 insertions(+) create mode 100644 tests/funptr_array.c create mode 100644 tests/funptr_array.cocci create mode 100644 tests/funptr_array.res diff --git a/tests/funptr_array.c b/tests/funptr_array.c new file mode 100644 index ..dac29ac6 --- /dev/null +++ b/tests/funptr_array.c @@ -0,0 +1 @@ +int (*x[2])(int x); diff --git a/tests/funptr_array.cocci b/tests/funptr_array.cocci new file mode 100644 index ..8027bcf4 --- /dev/null +++ b/tests/funptr_array.cocci @@ -0,0 +1,9 @@ +@@ +type T; +identifier x; +@@ + +T (*x[2])( +- int ++ char + x); diff --git a/tests/funptr_array.res b/tests/funptr_array.res new file mode 100644 index ..72e1a14a --- /dev/null +++ b/tests/funptr_array.res @@ -0,0 +1 @@ +int (*x[2])(char x); -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 23/26] engine: Match A.ParenType and A.FunctionType
ParenType and FunctionType are added to the SmPL AST as types. Match these types correctly. Signed-off-by: Jaskaran Singh --- engine/check_exhaustive_pattern.ml | 2 ++ engine/cocci_vs_c.ml | 27 +++ 2 files changed, 29 insertions(+) diff --git a/engine/check_exhaustive_pattern.ml b/engine/check_exhaustive_pattern.ml index 5a047f73..872c060c 100644 --- a/engine/check_exhaustive_pattern.ml +++ b/engine/check_exhaustive_pattern.ml @@ -149,6 +149,8 @@ let dumb_astcocci_type = function | A.SignedT (signa,tya) -> () | A.Pointer (typa, _) -> () | A.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> () + | A.ParenType(lp,ty,rp) -> () + | A.FunctionType(ty,lp,params,rp) -> () | A.Array (typa, _, eaopt, _) -> () | A.Decimal(_, _, _, _, _, _) -> () | A.EnumName(en, ena) -> () diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index a4a0e53b..3e0eb50e 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -3785,6 +3785,29 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = | _ -> fail ) +| A.ParenType (lpa, typa, rpa), (B.ParenType typb, ii) -> +let (lpb, rpb) = tuple_of_list2 ii in +fullType typa typb >>= (fun typa typb -> +tokenf lpa lpb >>= (fun lpa lpb -> +tokenf rpa rpb >>= (fun rpa rpb -> + return ( +(A.ParenType (lpa, typa, rpa)) +> A.rewrap ta, +(B.ParenType (typb), [lpb;rpb]) + + +| A.FunctionType (typa, lpa, paramsa, rpa), +(B.FunctionType (typb, (paramsb, (isvaargs, iidotsb))), ii) -> +let (lpb, rpb) = tuple_of_list2 ii in +fullType typa typb >>= (fun typa typb -> +tokenf lpa lpb >>= (fun lpa lpb -> +tokenf rpa rpb >>= (fun rpa rpb -> +parameters (seqstyle paramsa) (A.unwrap paramsa) paramsb >>= +(fun paramsaunwrap paramsb -> + let paramsa = A.rewrap paramsa paramsaunwrap in + return ( +(A.FunctionType (typa, lpa, paramsa, rpa)) +> A.rewrap ta, +(B.FunctionType (typb, (paramsb, (isvaargs, iidotsb))), [lpb;rpb]) + ) (* todo: handle the iso on optional size specification ? *) @@ -4361,6 +4384,10 @@ and compatible_typeC a (b,local) = | A.FunctionPointer (a, _, _, _, _, _, _), _ -> failwith "TODO: function pointer type doesn't store enough information to determine compatibility" +| A.ParenType (_, a, _), (qub, (B.ParenType b, ii)) -> + compatible_type a (b, local) +| A.FunctionType (a, _, _, _), (qub, (B.FunctionType (b,_), ii)) -> + compatible_type a (b, local) | A.Array (a, _, _, _), (qub, (B.Array (eopt, b),ii)) -> (* no size info for cocci *) compatible_type a (b, local) -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in position_generator.ml. Signed-off-by: Jaskaran Singh --- tools/spgen/source/position_generator.ml | 6 ++ 1 file changed, 6 insertions(+) diff --git a/tools/spgen/source/position_generator.ml b/tools/spgen/source/position_generator.ml index 31d6cb5e..2fa630fb 100644 --- a/tools/spgen/source/position_generator.ml +++ b/tools/spgen/source/position_generator.ml @@ -195,6 +195,12 @@ let rec type_pos t snp | Ast0.FunctionPointer(t,lp,star,rp,lp2,params,rp2) -> let constructor ~mc = Ast0.FunctionPointer(t,lp,star,rp,lp2,params,mc) in mcode_wrap ~mc:rp2 ~constructor snp + | Ast0.ParenType(lp,t,rp) -> + let constructor ~mc = Ast0.ParenType(lp,t,rp) in + mcode_wrap ~mc:rp ~constructor snp + | Ast0.FunctionType(t,lp,params,rp) -> + let constructor ~mc = Ast0.FunctionType(t,lp,params,rp) in + mcode_wrap ~mc:rp ~constructor snp | Ast0.Array(t,lb,expr,rb) -> let constructor ~mc = Ast0.Array(t,lb,expr,mc) in mcode_wrap ~mc:rb ~constructor snp -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer
ParenType and FunctionType are now in the SmPL AST, and these types have replaced all productions related to the FunctionPointer type in the SmPL parser. Remove FunctionPointer from the SmPL ASTs, its cases and any functions or constructs related to it from the codebase. Signed-off-by: Jaskaran Singh --- engine/check_exhaustive_pattern.ml | 1 - engine/cocci_vs_c.ml | 55 ocaml/coccilib.mli | 4 -- parsing_c/unparse_cocci.ml | 14 +- parsing_cocci/adjust_pragmas.ml | 3 -- parsing_cocci/arity.ml | 8 parsing_cocci/ast0_cocci.ml | 4 -- parsing_cocci/ast0_cocci.mli | 3 -- parsing_cocci/ast0toast.ml | 5 --- parsing_cocci/ast_cocci.ml | 8 parsing_cocci/ast_cocci.mli | 3 -- parsing_cocci/check_meta.ml | 3 -- parsing_cocci/compute_lines.ml | 10 - parsing_cocci/disjdistr.ml | 6 --- parsing_cocci/function_prototypes.ml | 3 -- parsing_cocci/get_constants.ml | 2 +- parsing_cocci/index.ml | 1 - parsing_cocci/iso_pattern.ml | 12 -- parsing_cocci/pretty_print_cocci.ml | 14 +- parsing_cocci/single_statement.ml| 1 - parsing_cocci/type_cocci.mli | 1 - parsing_cocci/type_infer.ml | 25 +-- parsing_cocci/unify_ast.ml | 8 parsing_cocci/unparse_ast0.ml| 13 +- parsing_cocci/visitor_ast.ml | 26 --- parsing_cocci/visitor_ast0.ml| 51 +- tools/spgen/source/meta_variable.ml | 1 - tools/spgen/source/position_generator.ml | 3 -- 28 files changed, 19 insertions(+), 269 deletions(-) diff --git a/engine/check_exhaustive_pattern.ml b/engine/check_exhaustive_pattern.ml index 872c060c..fe0b2c78 100644 --- a/engine/check_exhaustive_pattern.ml +++ b/engine/check_exhaustive_pattern.ml @@ -148,7 +148,6 @@ let dumb_astcocci_type = function | A.BaseType (basea,strings) -> () | A.SignedT (signa,tya) -> () | A.Pointer (typa, _) -> () - | A.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> () | A.ParenType(lp,ty,rp) -> () | A.FunctionType(ty,lp,params,rp) -> () | A.Array (typa, _, eaopt, _) -> () diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 3e0eb50e..87b0ce70 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -3733,58 +3733,6 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = (B.Pointer typb, [ibmult]) ))) -| A.FunctionPointer(tya,lp1a,stara,rp1a,lp2a,paramsa,rp2a), -(B.ParenType t1, ii) -> -let (lp1b, rp1b) = tuple_of_list2 ii in -let (qu1b, t1b) = t1 in -(match t1b with -| B.Pointer t2, ii -> -let (starb) = tuple_of_list1 ii in -let (qu2b, t2b) = t2 in -(match t2b with -| B.FunctionType (tyb, (paramsb, (isvaargs, iidotsb))), ii -> -let (lp2b, rp2b) = tuple_of_list2 ii in - -if isvaargs -then - pr2_once - ("Not handling well variable length arguments func. "^ -"You have been warned"); - -fullType tya tyb >>= (fun tya tyb -> -tokenf lp1a lp1b >>= (fun lp1a lp1b -> -tokenf rp1a rp1b >>= (fun rp1a rp1b -> -tokenf lp2a lp2b >>= (fun lp2a lp2b -> -tokenf rp2a rp2b >>= (fun rp2a rp2b -> -tokenf stara starb >>= (fun stara starb -> -parameters (seqstyle paramsa) (A.unwrap paramsa) paramsb >>= -(fun paramsaunwrap paramsb -> - let paramsa = A.rewrap paramsa paramsaunwrap in - - let t2 = -(qu2b, -(B.FunctionType (tyb, (paramsb, (isvaargs, iidotsb))), -[lp2b;rp2b])) - in - let t1 = -(qu1b, -(B.Pointer t2, [starb])) - in - - return ( -(A.FunctionPointer(tya,lp1a,stara,rp1a,lp2a,paramsa,rp2a)) -+> A.rewrap ta, -(B.ParenType t1, [lp1b;rp1b]) - ) -))) - - - -| _ -> fail -) -| _ -> fail -) - | A.ParenType (lpa, typa, rpa), (B.ParenType typb, ii) -> let (lpb, rpb) = tuple_of_list2 ii in fullType typa typb >>= (fun typa typb -> @@ -4381,9 +4329,6 @@ and compatible_typeC a (b,local) = | A.Pointer (a, _), (qub, (B.Pointer b, ii)) -> compatible_type a (b, local) -| A.FunctionPointer (a, _, _, _, _, _, _), _ -> - failwith - "TODO: function pointer type doesn't store enough information to determine compatibility" | A.ParenType (_,
[Cocci] [PATCH 20/26] parsing_cocci: ast_cocci: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in ast_cocci.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/ast_cocci.ml | 10 ++ 1 file changed, 10 insertions(+) diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index f8e6dee6..4fea9794 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -1110,6 +1110,10 @@ let rec string_of_typeC ty = string_of_fullType ty' ^ "*" | FunctionPointer (ty', _, _, _, _, _, _) -> string_of_fullType ty' ^ "(*)()" + | ParenType (_ , ty', _) -> + "(" ^ string_of_fullType ty' ^ ")" + | FunctionType (ty' , _, _, _) -> + string_of_fullType ty' ^ "()" | Array (ty', _, _, _) -> string_of_fullType ty' ^ "[]" | Decimal(_, _, e0, _, e1, _) -> @@ -1191,6 +1195,10 @@ and typeC_map tr ty = | Pointer (ty', s) -> rewrap ty (Pointer (fullType_map tr ty', s)) | FunctionPointer (ty, s0, s1, s2, s3, s4, s5) -> rewrap ty (FunctionPointer (fullType_map tr ty, s0, s1, s2, s3, s4, s5)) + | ParenType (s0, ty', s1) -> + rewrap ty (ParenType (s0, fullType_map tr ty', s1)) + | FunctionType (ty', s0, s1, s2) -> + rewrap ty (FunctionType (fullType_map tr ty', s0, s1, s2)) | Array (ty', s0, s1, s2) -> rewrap ty (Array (fullType_map tr ty', s0, s1, s2)) | EnumName (s0, ident) -> @@ -1250,6 +1258,8 @@ and typeC_fold tr ty v = | SignedT (_, Some ty') -> typeC_fold tr ty' v | Pointer (ty', _) | FunctionPointer (ty', _, _, _, _, _, _) + | ParenType (_, ty', _) + | FunctionType (ty', _, _, _) | Array (ty', _, _, _) | EnumDef (ty', _, _, _) | StructUnionDef (ty', _, _, _) -> fullType_fold tr ty' v -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in adjust_pragmas.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/adjust_pragmas.ml | 4 1 file changed, 4 insertions(+) diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml index 73b5ff5f..537150e7 100644 --- a/parsing_cocci/adjust_pragmas.ml +++ b/parsing_cocci/adjust_pragmas.ml @@ -171,6 +171,10 @@ let rec left_ty t = | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> call_right left_ty ty t (function ty -> Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)) + | Ast0.ParenType(lp,ty,rp) -> + call_right left_ty ty t (function ty -> Ast0.ParenType(lp,ty,rp)) + | Ast0.FunctionType(ty,lp,params,rp) -> + call_right left_ty ty t (function ty -> Ast0.FunctionType(ty,lp,params,rp)) | Ast0.Array(ty,lb,size,rb) -> call_right left_ty ty t (function ty -> Ast0.Array(ty,lb,size,rb)) | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 13/26] parsing_cocci: iso_pattern: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in iso_pattern.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/iso_pattern.ml | 5 + 1 file changed, 5 insertions(+) diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 5ceb2bdb..6d51b072 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -1818,6 +1818,11 @@ let instantiate bindings mv_bindings model = Ast0.rewrap ty ( Ast0.FunctionPointer( renamer ty', s0, s1, s2, s3, p, s4)) + | Ast0.ParenType(s0, ty', s1) -> + Ast0.rewrap ty (Ast0.ParenType(s0, renamer ty', s1)) + | Ast0.FunctionType(ty', s0, s1, s2) -> + Ast0.rewrap ty ( +Ast0.FunctionType(renamer ty', s0, s1, s2)) | Ast0.Array(ty', s0, e, s1) -> Ast0.rewrap ty (Ast0.Array(renamer ty', s0, e, s1)) | Ast0.Signed(s, ty') -> -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 12/26] parsing_cocci: check_meta: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in check_meta.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/check_meta.ml | 5 + 1 file changed, 5 insertions(+) diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 02b0fd9c..7b10bd53 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -224,6 +224,11 @@ and typeC old_metas table minus t = | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> typeC old_metas table minus ty; parameter_list old_metas table minus params + | Ast0.ParenType(lp,ty,rp) -> + typeC old_metas table minus ty + | Ast0.FunctionType(ty,lp,params,rp) -> + typeC old_metas table minus ty; + parameter_list old_metas table minus params | Ast0.Array(ty,lb,size,rb) -> typeC old_metas table minus ty; get_opt (expression ID old_metas table minus) size -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType
The order of the terms in ParenType require implementing a special case for ParenType. This case handles only the following: ( * id [ .* ] ) ( params ) i.e., a function pointer or an array of function pointers, and will fail for any other cases. This is similar to the function used to print ParenType in Pretty_print_c. Signed-off-by: Jaskaran Singh --- parsing_c/unparse_cocci.ml | 60 ++ 1 file changed, 60 insertions(+) diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 30e755e9..9dd84821 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -722,6 +722,13 @@ and typeC ty = | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) (function _ -> ()) + | Ast.ParenType(lp,ty,rp) -> + print_parentype (lp,ty,rp) (function _ -> ()) + | Ast.FunctionType(ty,lp,params,rp) -> + fullType ty; + mcode print_string lp; + parameter_list params; + mcode print_string rp | Ast.Array(ty,lb,size,rb) -> fullType ty; mcode print_string lb; print_option expression size; mcode print_string rb @@ -786,6 +793,57 @@ and storage = function | Ast.Register -> print_string "register" | Ast.Extern -> print_string "extern" +(* - *) +(* ParenType *) + +and print_parentype (lp,ty,rp) fn = + match Ast.unwrap ty with + Ast.Type(_,_,fty1) -> +(match Ast.unwrap fty1 with + Ast.Pointer(ty1,star) -> + (match Ast.unwrap ty1 with + Ast.Type(_,_,fty2) -> + (match Ast.unwrap fty2 with +Ast.FunctionType(ty2,lp2,params,rp2) -> + fullType ty2; + pr_space(); + mcode print_string lp; + mcode print_string star; + fn(); + mcode print_string rp; + mcode print_string lp2; + parameter_list params; + mcode print_string rp2 + | _ -> failwith "ParenType Unparse_cocci") + | _ -> failwith "ParenType Unparse_cocci") +| Ast.Array(ty1,lb1,size1,rb1) -> + (match Ast.unwrap ty1 with + Ast.Type(_,_,fty2) -> + (match Ast.unwrap fty2 with +Ast.Pointer(ty2,star) -> + (match Ast.unwrap ty2 with + Ast.Type(_,_,fty3) -> +(match Ast.unwrap fty3 with + Ast.FunctionType(ty3,lp3,params,rp3) -> + fullType ty3; + pr_space(); + mcode print_string lp; + mcode print_string star; + fn(); + mcode print_string lb1; + print_option expression size1; + mcode print_string rb1; + mcode print_string rp; + mcode print_string lp3; + parameter_list params; + mcode print_string rp3 +| _ -> failwith "ParenType Unparse_cocci") + | _ -> failwith "ParenType Unparse_cocci") + | _ -> failwith "ParenType Unparse_cocci") + | _ -> failwith "ParenType Unparse_cocci") +| _ -> failwith "ParenType Unparse_cocci") + | _ -> failwith "ParenType Unparse_cocci" + (* - *) (* Variable declaration *) @@ -818,6 +876,8 @@ and print_named_type ty id = pretty_print_c.Pretty_print_c.type_with_ident ty (function _ -> id()) | _ -> error name ty "type value expected") + | Ast.ParenType(lp,ty,rp) -> + print_parentype (lp,ty,rp) (function _ -> id()) (*| should have a case here for pointer to array or function type that would put ( * ) around the variable. This makes one wonder why we really need a special case for function pointer *) -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
ParenType and FunctionType are added to the SmPL ASTs. Add cases for these types in arity.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/arity.ml | 17 + 1 file changed, 17 insertions(+) diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index f29b86eb..3b408554 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -419,6 +419,23 @@ and top_typeC tgt opt_allowed typ = let params = parameter_list tgt params in make_typeC typ tgt arity (Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)) + | Ast0.ParenType(lp,ty,rp) -> + let arity = +all_same opt_allowed tgt (mcode2line lp) +[mcode2arity lp; mcode2arity rp] in + let lp = mcode lp in + let ty = typeC arity ty in + let rp = mcode rp in + make_typeC typ tgt arity (Ast0.ParenType(lp,ty,rp)) + | Ast0.FunctionType(ty,lp,params,rp) -> + let arity = +all_same opt_allowed tgt (mcode2line lp) +[mcode2arity lp; mcode2arity rp] in + let ty = typeC arity ty in + let lp = mcode lp in + let params = parameter_list tgt params in + let rp = mcode rp in + make_typeC typ tgt arity (Ast0.FunctionType(ty,lp,params,rp)) | Ast0.Array(ty,lb,size,rb) -> let arity = all_same opt_allowed tgt (mcode2line lb) -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 08/26] parsing_cocci: context_neg: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in context_neg.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/context_neg.ml | 4 1 file changed, 4 insertions(+) diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index 7bbf743d..b3a52daf 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -663,6 +663,10 @@ let equal_typeC t1 t2 = equal_mcode sign1 sign2 | (Ast0.Pointer(_,star1),Ast0.Pointer(_,star2)) -> equal_mcode star1 star2 + | (Ast0.ParenType(lp1,_,rp1),Ast0.ParenType(lp2,_,rp2)) -> + equal_mcode lp1 lp2 && equal_mcode rp1 rp2 + | (Ast0.FunctionType(_,lp1,_,rp1),Ast0.FunctionType(_,lp2,_,rp2)) -> + equal_mcode lp1 lp2 && equal_mcode rp1 rp2 | (Ast0.Array(_,lb1,_,rb1),Ast0.Array(_,lb2,_,rb2)) -> equal_mcode lb1 lb2 && equal_mcode rb1 rb2 | (Ast0.Decimal(dec1,lp1,_,comma1,_,rp1), -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in unify_ast.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/unify_ast.ml | 8 1 file changed, 8 insertions(+) diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index d4ad3030..de86b1d3 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -336,6 +336,14 @@ and unify_typeC t1 t2 = unify_fullType tya tyb && unify_dots unify_parameterTypeDef pdots paramsa paramsb else false + | (Ast.ParenType(lpa,tya,rpa),Ast.ParenType(lpb,tyb,rpb)) -> + unify_fullType tya tyb && unify_mcode lpa lpb && unify_mcode rpa rpb + | (Ast.FunctionType(tya,lpa,paramsa,rpa), + Ast.FunctionType(tyb,lpb,paramsb,rpb)) -> + unify_fullType tya tyb && + unify_mcode lpa lpb && + unify_dots unify_parameterTypeDef pdots paramsa paramsb && + unify_mcode rpa rpb | (Ast.Array(ty1,lb1,e1,rb1),Ast.Array(ty2,lb2,e2,rb2)) -> unify_fullType ty1 ty2 && unify_option unify_expression e1 e2 | (Ast.Decimal(dec1,lp1,len1,comma1,prec_opt1,rp1), -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 10/26] parsing_cocci: single_statement: Add cases for ParenType/FunctionType
ParenType/FunctionType are now types in the SmPL ASTs. Add cases for these types in single_statement.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/single_statement.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 46408b73..48d77b5a 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -166,6 +166,8 @@ and left_typeC t = | Ast0.Signed(sgn,ty) -> modif_before_mcode sgn | Ast0.Pointer(ty,star) -> left_typeC ty | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> left_typeC ty + | Ast0.ParenType(lp,ty,rp) -> left_typeC ty + | Ast0.FunctionType(ty,lp,params,rp) -> left_typeC ty | Ast0.Array(ty,lb,size,rb) -> left_typeC ty | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> modif_before_mcode dec -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 15/26] parsing_cocci: compute_lines: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in compute_lines.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/compute_lines.ml | 11 +++ 1 file changed, 11 insertions(+) diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index f4b6f4d8..8231a0e7 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -574,6 +574,17 @@ and typeC t = let rp2 = normal_mcode rp2 in mkres t (Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)) ty (promote_mcode rp2) + | Ast0.ParenType(lp,ty,rp) -> + let lp = normal_mcode lp in + let rp = normal_mcode rp in + let ty = typeC ty in + mkres t (Ast0.ParenType(lp,ty,rp)) ty (promote_mcode rp) + | Ast0.FunctionType(ty,lp,params,rp) -> + let ty = typeC ty in + let lp = normal_mcode lp in + let params = parameter_list (Some(promote_mcode lp)) params in + let rp = normal_mcode rp in + mkres t (Ast0.FunctionType(ty,lp,params,rp)) ty (promote_mcode rp) | Ast0.Array(ty,lb,size,rb) -> let ty = typeC ty in let lb = normal_mcode lb in -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 11/26] parsing_cocci: function_prototypes: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in function_prototypes.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/function_prototypes.ml | 4 1 file changed, 4 insertions(+) diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml index 2e6eea43..fd36f31b 100644 --- a/parsing_cocci/function_prototypes.ml +++ b/parsing_cocci/function_prototypes.ml @@ -229,6 +229,10 @@ let rec attach_right strings ty = | Ast0.FunctionPointer(ty,lp,star,rp,lp1,ps,rp1) -> Ast0.FunctionPointer(ty,lp,star,rp,lp1,ps, right_attach_mcode strings rp1) +| Ast0.ParenType(lp,ty,rp) -> + Ast0.ParenType(lp,ty,right_attach_mcode strings rp) +| Ast0.FunctionType(ty,lp,ps,rp) -> + Ast0.FunctionType(ty,lp,ps,right_attach_mcode strings rp) | Ast0.Array(ty,lb,e,rb) -> Ast0.Array(ty,lb,e,right_attach_mcode strings rb) | Ast0.Decimal(dec,lp,e1,comma,e2,rp) -> -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in type_cocci.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/type_cocci.mli | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parsing_cocci/type_cocci.mli b/parsing_cocci/type_cocci.mli index c1ccb58f..6f24adf7 100644 --- a/parsing_cocci/type_cocci.mli +++ b/parsing_cocci/type_cocci.mli @@ -16,6 +16,8 @@ type typeC = | SignedT of sign * typeC option | Pointer of typeC | FunctionPointer of typeC (* only return type *) + | ParenType of typeC (* only return type *) + | FunctionTypeof typeC (* only return type *) | Array of typeC (* drop size info *) | Decimal of name * name | EnumNameof name -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType
The order of the terms in ParenType require implementing a special case for ParenType. This case handles only the following: ( * id [ .* ] ) ( params ) i.e., a function pointer or an array of function pointers, and will fail for any other cases. This is similar to the function used to print ParenType in Pretty_print_c. Signed-off-by: Jaskaran Singh --- parsing_cocci/pretty_print_cocci.ml | 57 + 1 file changed, 57 insertions(+) diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index 6338e464..ef60106c 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -403,6 +403,54 @@ and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn = mcode print_string rp1; mcode print_string lp1; parameter_list params; mcode print_string rp2 +and print_parentype (lp,ty,rp) fn = + match Ast.unwrap ty with + Ast.Type(_,_,fty1) -> +(match Ast.unwrap fty1 with + Ast.Pointer(ty1,star) -> + (match Ast.unwrap ty1 with + Ast.Type(_,_,fty2) -> + (match Ast.unwrap fty2 with +Ast.FunctionType(ty2,lp2,params,rp2) -> + fullType ty2; + print_space(); + mcode print_string lp; + mcode print_string star; + fn(); + mcode print_string rp; + mcode print_string lp2; + parameter_list params; + mcode print_string rp2 + | _ -> failwith "ParenType Pretty_print_cocci") + | _ -> failwith "ParenType Pretty_print_cocci") +| Ast.Array(ty1,lb1,size1,rb1) -> + (match Ast.unwrap ty1 with + Ast.Type(_,_,fty2) -> + (match Ast.unwrap fty2 with +Ast.Pointer(ty2,star) -> + (match Ast.unwrap ty2 with + Ast.Type(_,_,fty3) -> +(match Ast.unwrap fty3 with + Ast.FunctionType(ty3,lp3,params,rp3) -> + fullType ty3; + print_space(); + mcode print_string lp; + mcode print_string star; + fn(); + mcode print_string lb1; + print_option expression size1; + mcode print_string rb1; + mcode print_string rp; + mcode print_string lp3; + parameter_list params; + mcode print_string rp3 +| _ -> failwith "ParenType Pretty_print_cocci") + | _ -> failwith "ParenType Pretty_print_cocci") + | _ -> failwith "ParenType Pretty_print_cocci") + | _ -> failwith "ParenType Pretty_print_cocci") +| _ -> failwith "ParenType Pretty_print_cocci") + | _ -> failwith "ParenType Pretty_print_cocci" + and varargs = function | None -> () | Some (comma, ellipsis) -> @@ -424,6 +472,13 @@ and typeC ty = | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) (function _ -> ()) + | Ast.ParenType(lp,ty,rp) -> + print_parentype (lp,ty,rp) (function _ -> ()) + | Ast.FunctionType(ty,lp,params,rp) -> + fullType ty; + mcode print_string lp; + parameter_list params; + mcode print_string rp | Ast.Array(ty,lb,size,rb) -> fullType ty; mcode print_string lb; print_option expression size; mcode print_string rb @@ -498,6 +553,8 @@ and print_named_type ty id = | _ -> failwith "complex array types not supported") | _ -> typeC ty; id(); k () in loop ty1 (function _ -> ()) + | Ast.ParenType(lp,ty,rp) -> + print_parentype (lp,ty,rp) (function _ -> id()) | _ -> fullType ty; id()) | _ -> fullType ty; id() -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: Add cases for ParenType/FunctionType
ParenType/FunctionType are now types in the SmPL ASTs. Add cases for these types in unparse_ast0.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/unparse_ast0.ml | 43 +++ 1 file changed, 43 insertions(+) diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index 5d450e0e..f8684dd2 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -292,6 +292,40 @@ and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn = mcode print_string rp1; mcode print_string lp2; parameter_list params; mcode print_string rp2 +and print_parentype (lp,ty,rp) fn = + match Ast0.unwrap ty with + Ast0.Pointer(ty1,star) -> + (match Ast0.unwrap ty1 with + Ast0.FunctionType(ty2,lp2,params,rp2) -> + typeC ty2; + mcode print_string lp; + mcode print_string star; + fn(); + mcode print_string rp; + mcode print_string lp2; + parameter_list params; + mcode print_string rp2; + | _ -> failwith "ParenType Unparse_ast0") + | Ast0.Array(ty1,lb1,size1,rb1) -> + (match Ast0.unwrap ty1 with + Ast0.Pointer(ty2,star) -> + (match Ast0.unwrap ty2 with + Ast0.FunctionType(ty3,lp3,params,rp3) -> + typeC ty3; + mcode print_string lp; + mcode print_string star; + fn(); + mcode print_string lb1; + print_option expression size1; + mcode print_string rb1; + mcode print_string rp; + mcode print_string lp3; + parameter_list params; + mcode print_string rp3; + | _ -> failwith "ParenType Unparse_ast0") + | _ -> failwith "ParenType Unparse_ast0") + | _ -> failwith "ParenType Unparse_ast0" + and typeC t = print_context t (function _ -> @@ -306,6 +340,13 @@ and typeC t = | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) (function _ -> ()) + | Ast0.ParenType(lp,ty,rp) -> + print_parentype (lp,ty,rp) (function _ -> ()) + | Ast0.FunctionType(ty,lp,params,rp) -> + typeC ty; + mcode print_string lp; + parameter_list params; + mcode print_string rp | Ast0.Array(ty,lb,size,rb) -> typeC ty; mcode print_string lb; print_option expression size; mcode print_string rb @@ -367,6 +408,8 @@ and print_named_type ty id = mcode print_string rb) | _ -> typeC ty; ident id; k () in loop ty (function _ -> ()) + | Ast0.ParenType(lp,ty,rp) -> + print_parentype (lp,ty,rp) (function _ -> ident id) | _ -> typeC ty; ident id and declaration d = -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 19/26] parsing_cocci: disjdistr: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in disjdistr.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/disjdistr.ml | 10 ++ 1 file changed, 10 insertions(+) diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index 668a8810..91d7f1b8 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -73,6 +73,16 @@ and disjtypeC bty = (function ty -> Ast.rewrap bty (Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))) ty + | Ast.ParenType(lp,ty,rp) -> + let ty = disjty ty in + List.map +(function ty -> + Ast.rewrap bty (Ast.ParenType(lp,ty,rp))) ty + | Ast.FunctionType(ty,lp,params,rp) -> + let ty = disjty ty in + List.map +(function ty -> + Ast.rewrap bty (Ast.FunctionType(ty,lp,params,rp))) ty | Ast.Array(ty,lb,size,rb) -> disjmult2 (disjty ty) (disjoption disjexp size) (function ty -> function size -> -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules
The direct_declarator rule and the direct_abstract_d rule are present in the C parser. Add similar rules to the SmPL parser so that declarators are parsed as they are in the C parser. For the type ParenType, direct_declarator and direct_abstract_d only allow the following productions: ( * id [ .* ] ) ( params ) i.e. a function pointer or an array of function pointers. The compromise is flexibility in the range of productions, mainly because collateral evolutions needed by having a flexible rule are very large and distasteful. Replace usage of the older d_ident rule in the SmPL parser with the above mentioned rules. All usages of d_ident, however, have not been removed due to reduce/reduce conflicts. Remove rules/productions that parse function pointers with usage of direct_declarator and direct_abstract_d. Signed-off-by: Jaskaran Singh --- parsing_cocci/parser_cocci_menhir.mly | 239 +- 1 file changed, 116 insertions(+), 123 deletions(-) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 26958f63..fade830f 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -1116,33 +1116,17 @@ struct_decl_one: { let (mids,code) = t in Ast0.wrap (Ast0.ConjField(P.id2mcode lp,code,mids, P.id2mcode rp)) } -| t=ctype d=d_ident_option bf=struct_bitfield? pv=TPtVirg +| t=ctype d=direct_decl_option(disj_ident) bf=struct_bitfield? pv=TPtVirg { let (id,fn) = d in Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) } -| t=ctype lp1=TOPar st=TMul d=d_ident_option rp1=TCPar - lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar - bf=struct_bitfield? pv=TPtVirg -{ let (id,fn) = d in -let t = - Ast0.wrap - (Ast0.FunctionPointer - (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1, - P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in -Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) } - | cv=ioption(const_vol) i=pure_ident_or_symbol d=d_ident_option +| cv=ioption(const_vol) i=pure_ident_or_symbol + d=direct_decl_option(disj_ident) bf=struct_bitfield? pv=TPtVirg { let (id,fn) = d in let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in Ast0.wrap(Ast0.Field(fn idtype,id,bf,P.clt2mcode ";" pv)) } -d_ident_option: -{ None, (fun x -> x) } - | d=d_ident { - let (id, fn) = d in - (Some id, fn) -} - struct_bitfield: c=TDotDot e=expr { (P.clt2mcode ":" c, e) } @@ -1529,17 +1513,9 @@ storage: | s=Tregister{ P.clt2mcode Ast.Register s } | s=Textern { P.clt2mcode Ast.Extern s } -decl: t=ctype i=disj_ident a=list(array_dec) - { let t = P.arrayify t a in Ast0.wrap(Ast0.Param(t, Some i)) } +decl: t=ctype d=direct_declarator(disj_ident) + { let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i)) } | t=ctype { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t, None)) } -| t=ctype lp=TOPar s=TMul i=disj_ident rp=TCPar - lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar -{ let fnptr = - Ast0.wrap - (Ast0.FunctionPointer - (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp, - P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in - Ast0.wrap(Ast0.Param(fnptr, Some i)) } | TMetaParam { let (nm,cstr,pure,clt) = $1 in Ast0.wrap(Ast0.MetaParam(P.clt2mcode nm clt,cstr,pure)) } @@ -1547,14 +1523,6 @@ decl: t=ctype i=disj_ident a=list(array_dec) name_opt_decl: decl { $1 } -| t=ctype lp=TOPar s=TMul rp=TCPar - lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar -{ let fnptr = - Ast0.wrap - (Ast0.FunctionPointer - (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp, - P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in - Ast0.wrap(Ast0.Param(fnptr, None)) } const_vol: Tconst { P.clt2mcode Ast.Const $1 } @@ -1684,13 +1652,15 @@ decl_var: t=ctype pv=TPtVirg { [Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv))] } | TMetaDecl { [P.meta_decl $1] } - | s=ioption(storage) t=ctype d=comma_list(d_ident) pv=TPtVirg + | s=ioption(storage) t=ctype + d=comma_list(direct_declarator(disj_ident)) pv=TPtVirg { List.map (function (id,fn) -> Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv))) d } | f=funproto { [f] } - | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq e=initialize + | s=ioption(storage) t=ctype d=direct_declarator(disj_ident) +a=attr_list q=TEq e=initialize pv=TPtVirg {let (id,fn) = d in [Ast0.wrap @@ -1711,18 +1681,6 @@ decl_var: let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in [Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
[Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs
ParenType and FunctionType are types present in the C AST that are not present in the SmPL AST. In the pursuit of aligning both the C and SmPL ASTs, add these types to the SmPL ASTs. Signed-off-by: Jaskaran Singh --- ocaml/coccilib.mli | 6 ++ parsing_cocci/ast0_cocci.ml | 3 +++ parsing_cocci/ast0_cocci.mli | 3 +++ parsing_cocci/ast_cocci.ml | 3 +++ parsing_cocci/ast_cocci.mli | 3 +++ 5 files changed, 18 insertions(+) diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 5a913099..e5409a97 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -2709,6 +2709,9 @@ module Ast_cocci : | Pointer of fullType * string mcode | FunctionPointer of fullType * string mcode * string mcode * string mcode * string mcode * parameter_list * string mcode + | ParenType of string mcode (* ( *) * fullType * string mcode (* ) *) + | FunctionType of fullType * + string mcode (* ( *) * parameter_list * string mcode (* ) *) | Array of fullType * string mcode * expression option * string mcode | Decimal of string mcode * string mcode * expression * string mcode option * expression option * string mcode @@ -3353,6 +3356,9 @@ module Ast0_cocci : | Pointer of typeC * string mcode | FunctionPointer of typeC * string mcode * string mcode * string mcode * string mcode * parameter_list * string mcode + | ParenType of string mcode * typeC * string mcode + | FunctionType of typeC * + string mcode * parameter_list * string mcode | Array of typeC * string mcode * expression option * string mcode | Decimal of string mcode * string mcode * expression * string mcode option * expression option * string mcode diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 77dc46f0..0acbeaa4 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -203,6 +203,9 @@ and base_typeC = | FunctionPointer of typeC * string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)* string mcode (* ( *)*parameter_list*string mcode(* ) *) + | ParenType of string mcode (* ( *) * typeC * string mcode (* ) *) + | FunctionTypeof typeC * + string mcode (* ( *) * parameter_list * string mcode (* ) *) | Array of typeC * string mcode (* [ *) * expression option * string mcode (* ] *) | Decimal of string mcode (* decimal *) * string mcode (* ( *) * diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index 274c6bc2..33bd12b2 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -194,6 +194,9 @@ and base_typeC = | FunctionPointer of typeC * string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)* string mcode (* ( *)*parameter_list*string mcode(* ) *) + | ParenType of string mcode (* ( *) * typeC * string mcode (* ) *) + | FunctionTypeof typeC * + string mcode (* ( *) * parameter_list * string mcode (* ) *) | Array of typeC * string mcode (* [ *) * expression option * string mcode (* ] *) | Decimal of string mcode (* decimal *) * string mcode (* ( *) * diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index ba6ec29e..f8e6dee6 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -343,6 +343,9 @@ and base_typeC = | FunctionPointer of fullType * string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)* string mcode (* ( *)*parameter_list*string mcode(* ) *) + | ParenType of string mcode (* ( *) * fullType * string mcode (* ) *) + | FunctionTypeof fullType * + string mcode (* ( *) * parameter_list * string mcode (* ) *) | Array of fullType * string mcode (* [ *) * expression option * string mcode (* ] *) | Decimal of string mcode (* decimal *) * string mcode (* ( *) * diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 5f21664b..7fb54e4d 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -325,6 +325,9 @@ and base_typeC = | FunctionPointer of fullType * string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)* string mcode (* ( *)*parameter_list*string mcode(* ) *) + | ParenType of string mcode (* ( *) * fullType * string mcode (* ) *) + | FunctionTypeof fullType * + string mcode (* ( *) * parameter_list * string mcode (* ) *) | Array of fullType * string mcode (* [ *) * expression option * string mcode (* ] *) | Decimal of string mcode (* decimal *) * string mcode (* ( *) * -- 2.21.1 ___ Cocci mailing list
[Cocci] [PATCH 05/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
The order of the terms in ParenType require implementing a special case for ParenType. This case handles only the following: ( * id [ .* ] ) ( params ) i.e., a function pointer or an array of function pointers, and will fail for any other cases. This is similar to the function used to print ParenType in Pretty_print_c. Signed-off-by: Jaskaran Singh --- parsing_cocci/visitor_ast.ml | 75 1 file changed, 75 insertions(+) diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 3d5de794..99af7652 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -318,6 +318,61 @@ let combiner bind option_default let lrb = string_mcode rb in multibind ([lty] @ lid @ [lb; lsize; lrb]) + and parentype_type (lp, ty, (id : Ast.ident option), rp) = +match Ast.unwrap ty with + Ast.Type(_,_,fty1) -> + (match Ast.unwrap fty1 with + Ast.Pointer(ty1,star) -> + (match Ast.unwrap ty1 with + Ast.Type(_,_,fty2) -> + (match Ast.unwrap fty2 with +Ast.FunctionType(ty2,lp2,params,rp2) -> + let typ = fullType ty2 in + let lp = string_mcode lp in + let star = string_mcode star in + let idl = match id with +| Some idd -> [ident idd] +| None -> [] in + let rp = string_mcode rp in + let lp2 = string_mcode lp2 in + let params = parameter_dots params in + let rp2 = string_mcode rp2 in + multibind +([typ;lp;star] @ idl @ [rp;lp2;params;rp2]) +| _ -> failwith "ParenType Visitor_ast") + | _ -> failwith "ParenType Visitor_ast") + | Ast.Array(ty1,lb1,size1,rb1) -> + (match Ast.unwrap ty1 with +Ast.Type(_,_,fty2) -> + (match Ast.unwrap fty2 with + Ast.Pointer(ty2,star) -> +(match Ast.unwrap ty2 with + Ast.Type(_,_,fty3) -> + (match Ast.unwrap fty3 with + Ast.FunctionType(ty3,lp3,params,rp3) -> + let typ = fullType ty3 in + let lp = string_mcode lp in + let star = string_mcode star in + let idl = match id with + | Some idd -> [ident idd] + | None -> [] in + let lb1 = string_mcode lb1 in + let size1 = get_option expression size1 in + let rb1 = string_mcode rb1 in + let rp = string_mcode rp in + let lp3 = string_mcode lp3 in + let params = parameter_dots params in + let rp3 = string_mcode rp3 in + multibind + ([typ;lp;star] @ idl @ +[lb1;size1;rb1;rp;lp3;params;rp3]) + | _ -> failwith "ParenType Visitor_ast") +| _ -> failwith "ParenType Visitor_ast") + | _ -> failwith "ParenType Visitor_ast") + | _ -> failwith "ParenType Visitor_ast") + | _ -> failwith "ParenType Visitor_ast") +| _ -> failwith "ParenType Visitor_ast" + and typeC ty = let k ty = match Ast.unwrap ty with @@ -332,6 +387,14 @@ let combiner bind option_default bind lty lstar | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2) + | Ast.ParenType(lp,ty,rp) -> + parentype_type (lp,ty,None,rp) + | Ast.FunctionType(ty,lp,params,rp) -> + let lty = fullType ty in + let llp = string_mcode lp in + let lparams = parameter_dots params in + let lrp = string_mcode rp in + multibind [lty; llp; lparams; lrp] | Ast.Array(ty,lb,size,rb) -> array_type (ty,None,lb,size,rb) | Ast.Decimal(dec,lp,length,comma,precision_opt,rp) -> let ldec = string_mcode dec in @@ -384,6 +447,7 @@ let combiner bind option_default Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2) | Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb) +| Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp) | _ -> let lty = fullType ty in let lid = ident id in bind lty lid) @@ -1253,6 +1317,17 @@ let rebuilder let lparams = parameter_dots params in let lrp2 = string_mcode rp2 in Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2) +| Ast.ParenType(lp,ty,rp) -> +let llp = string_mcode lp in +let lty = fullType ty in +let lrp = string_mcode rp in +Ast.ParenType(llp,lty,lrp) +
[Cocci] [PATCH 07/26] parsing_cocci: index: Add cases for ParenType/FunctionType
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in index.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/index.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index a1103503..5c91f620 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -93,6 +93,8 @@ let typeC t = | Ast0.Signed(sign,ty) -> [129] | Ast0.Pointer(ty,star) -> [49] | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> [131] + | Ast0.ParenType(lp,ty,rp) -> [138] + | Ast0.FunctionType(ty,lp,params,rp) -> [139] | Ast0.Array(ty,lb,size,rb) -> [50] | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> [160] | Ast0.EnumName(kind,name) -> [146] -- 2.21.1 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
To add the types ParenType and FunctionType to the SmPL AST, a reduce/reduce conflict with the funproto rule of the SmPL parser must be resolved. This requires explicitly identifying a function prototype by use of a token (TFunProto). While the correct method of identifying a function prototype would be to check if an identifier is preceded by a return type, it is challenging to implement. This is because implementing an OCaml function, to correctly determine a C type in SmPL, without the aid of Yacc, would have to handle a number of cases (disjunctions, typeof expressions, etc.). Thus, a slightly hacky approach is taken to determine a function prototype with not the best certainty but what works for most cases in SmPL. If the identifier is preceded by any token that does not seem to be part of a type, then it is not identified as a function prototype. Else, it is. Signed-off-by: Jaskaran Singh --- parsing_cocci/parse_cocci.ml | 72 +++ parsing_cocci/parser_cocci_menhir.mly | 9 ++-- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml index 679d213a..4b2cb7e4 100644 --- a/parsing_cocci/parse_cocci.ml +++ b/parsing_cocci/parse_cocci.ml @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt = | PC.TLineEnd(clt) -> "line end" | PC.TInvalid -> "invalid" | PC.TFunDecl(clt) -> "fundecl" + | PC.TFunProto(clt) -> "funproto" | PC.TIso -> "<=>" | PC.TRightIso -> "=>" @@ -480,7 +481,7 @@ let get_clt (tok,_) = | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) | PC.TCPar0(_,clt) | PC.TOEllipsis(clt) | PC.TCEllipsis(clt) - | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) + | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) | PC.TFunProto(clt) | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt) | PC.TLineEnd(clt) -> clt | PC.TVAEllipsis(clt) -> clt @@ -718,6 +719,7 @@ let update_clt (tok,x) clt = | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x) | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x) + | PC.TFunProto(_) -> (PC.TFunProto(clt),x) | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x) | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x) | PC.TAttr_(_) -> (PC.TAttr_(clt),x) @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) = | PC.TInitialize | PC.TFinalize -> ([t],[t]) | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt) -> split t clt - | PC.TFunDecl(clt) + | PC.TFunDecl(clt) | PC.TFunProto(clt) | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt) | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt) | PC.TEllipsis(clt) @@ -1006,7 +1008,8 @@ let find_function_names l = | _ -> false in let rec split acc = function [] | [_] -> raise Irrelevant -| ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest -> +| ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest +| ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) :: rest -> (List.rev (t1::acc),(t2::rest)) | x::xs -> split (x::acc) xs in let rec balanced_name level = function @@ -1037,7 +1040,48 @@ let find_function_names l = | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ -> raise Irrelevant | t::rest -> balanced_args level rest in - let rec loop = function + let rec is_permissible_proto = function + [] -> false +| (PC.TCPar0(_),_):: + ((PC.TMid0(_),_) | (PC.TAnd0(_),_)):: + (PC.TOPar0(_),_)::_ -> false +| (PC.TOPar0(_),_)::rest +| (PC.TCPar0(_),_)::rest -> is_permissible_proto rest +| x::rest when is_mid x -> +let rec loop = function + [] -> false +| (PC.TOPar0(_),_)::xs -> is_permissible_proto xs +| x::xs -> loop xs in +loop rest +| _::((PC.TEq(_),_) | (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_ +| _::(PC.TWhen(_),_)::_ +| (PC.TComma(_),_)::_ +| (PC.TDirective(_),_)::_ +| (PC.TElse(_),_)::_ +| (PC.TReturn(_),_)::_ +| (PC.TMetaStm(_),_)::_ +| (PC.TMetaExp(_),_)::_ +| (PC.TMetaId(_),_)::_ +| (PC.TMetaLocalIdExp(_),_)::_ +| (PC.TEq(_),_)::_ +| (PC.TEllipsis(_),_)::_ +| (PC.TOEllipsis(_),_)::_ +| (PC.TCEllipsis(_),_)::_ +| (PC.TPOEllipsis(_),_)::_ +| (PC.TPCEllipsis(_),_)::_ +| (PC.TPtVirg(_),_)::_ +| (PC.TOBrace(_),_)::_ +| (PC.TCBrace(_),_)::_ +| (PC.TOPar(_),_)::_ +| (PC.TCPar(_),_)::_ +| (PC.TIdent(_),_)::_ -> false +| _ -> true in + let decl_or_proto clt info bef aft = +match aft with + (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) :: bef), aft) +| (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) :: bef), aft) +| _ -> raise Irrelevant in + let rec loop acc = function [] -> [] | t :: rest -> if is_par t || is_mid t || is_ident t @@ -1046,26 +1090,30 @@ let find_function_names l = try let (bef,aft) = split [] (t::rest) in let rest = balanced_name 0 bef in + (match
[Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs
The aim of this patch series is to add the types ParenType and FunctionType to the SmPL AST. These types are present in the C AST but not in the SmPL AST. Preliminarily, a hack to resolve a reduce/reduce conflict with the funproto rule in the SmPL parser is implemented. Upon this, rules similar to that of the C parser's direct declarator and abstract direct declarator rules are implemented, and used wherever suitable. These rules produce ParenType and FunctionType, similar to the C parser. Cases for these types are added to various places in the codebase. The FunctionPointer type is removed from the SmPL AST, since all the productions that produce FunctionPointers in the SmPL parser are replaced by those that produce ParenType. Any functions, constructs or cases of FunctionPointer are also removed from the codebase. A test case to match an array of function pointers is included to demonstrate matching improvements. [PATCH 01/26] parsing_cocci: Add Function Prototype token [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to [PATCH 03/26] parsing_cocci: parser: Add [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for [PATCH 05/26] parsing_cocci: visitor_ast0: Add cases for [PATCH 06/26] parsing_cocci: arity: Add cases for [PATCH 07/26] parsing_cocci: index: Add cases for [PATCH 08/26] parsing_cocci: context_neg: Add cases for [PATCH 09/26] parsing_cocci: unparse_ast0: Add cases for [PATCH 10/26] parsing_cocci: single_statement: Add cases for [PATCH 11/26] parsing_cocci: function_prototypes: Add cases for [PATCH 12/26] parsing_cocci: check_meta: Add cases for [PATCH 13/26] parsing_cocci: iso_pattern: Add cases for [PATCH 14/26] parsing_cocci: adjust_pragmas: Add cases for [PATCH 15/26] parsing_cocci: compute_lines: Add cases for [PATCH 16/26] parsing_cocci: ast0toast: Add cases for [PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType [PATCH 18/26] parsing_cocci: unify_ast: Add cases for [PATCH 19/26] parsing_cocci: disjdistr: Add cases for [PATCH 20/26] parsing_cocci: ast_cocci: Add cases for [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print [PATCH 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType [PATCH 23/26] engine: Match A.ParenType and A.FunctionType [PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType [PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer [PATCH 26/26] tests: Add test case for array of function pointers engine/check_exhaustive_pattern.ml |3 engine/cocci_vs_c.ml | 82 +++--- ocaml/coccilib.mli | 10 - parsing_c/unparse_cocci.ml | 74 +++-- parsing_cocci/adjust_pragmas.ml |7 parsing_cocci/arity.ml | 25 ++- parsing_cocci/ast0_cocci.ml |7 parsing_cocci/ast0_cocci.mli |6 parsing_cocci/ast0toast.ml | 11 - parsing_cocci/ast_cocci.ml | 21 +- parsing_cocci/ast_cocci.mli |6 parsing_cocci/check_meta.ml |8 - parsing_cocci/compute_lines.ml | 21 +- parsing_cocci/context_neg.ml |4 parsing_cocci/disjdistr.ml | 16 +- parsing_cocci/function_prototypes.ml |7 parsing_cocci/get_constants.ml |2 parsing_cocci/index.ml |3 parsing_cocci/iso_pattern.ml | 17 -- parsing_cocci/parse_cocci.ml | 72 +++-- parsing_cocci/parser_cocci_menhir.mly| 248 +++ parsing_cocci/pretty_print_cocci.ml | 71 +++- parsing_cocci/single_statement.ml|3 parsing_cocci/type_cocci.mli |3 parsing_cocci/type_infer.ml | 25 +-- parsing_cocci/unify_ast.ml | 16 +- parsing_cocci/unparse_ast0.ml| 56 +-- parsing_cocci/visitor_ast.ml | 101 +--- parsing_cocci/visitor_ast0.ml| 214 -- tests/funptr_array.c |1 tests/funptr_array.cocci |9 + tests/funptr_array.res |1 tools/spgen/source/meta_variable.ml |1 tools/spgen/source/position_generator.ml |9 - 34 files changed, 754 insertions(+), 406 deletions(-) ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
The order of the terms in ParenType require implementing a special case for ParenType. This case handles only the following: ( * id [ .* ] ) ( params ) i.e., a function pointer or an array of function pointers, and will fail for any other cases. This is similar to the function used to print ParenType in Pretty_print_c. Signed-off-by: Jaskaran Singh --- parsing_cocci/visitor_ast0.ml | 163 ++ 1 file changed, 163 insertions(+) diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index c282e1f8..c56cd7a7 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -339,6 +339,12 @@ let visitor mode bind option_default | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> let (t,id) = function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2) in t +| Ast0.ParenType(lp,ty,rp) -> + let (t,id) = + parentype_type (lp,ty,None,rp) in t +| Ast0.FunctionType(ty,lp,params,rp) -> + let (t,id) = + functiontype_type (ty,None,lp,params,rp) in t | Ast0.Array(ty,lb,size,rb) -> let (t,id) = array_type (ty,None,lb,size,rb) in t | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> @@ -435,6 +441,76 @@ let visitor mode bind option_default ((multibind ([ty_n] @ idl @ [lb_n;size_n;rb_n]), Ast0.Array(ty,lb,size,rb)), idu) + and parentype_type (lp,ty,(id : Ast0.ident option),rp) = +match Ast0.unwrap ty with + Ast0.Pointer(ty1,star) -> +(match Ast0.unwrap ty1 with + Ast0.FunctionType(ty2,lp2,params,rp2) -> +let (ty_n,typ) = typeC ty2 in +let (lp_n,lp) = string_mcode lp in +let (star_n,star) = string_mcode star in +let (idl,idu) = (match id with + | Some a -> let (b,c) = ident a in ([b],Some c) + | None -> ([],None)) in +let (rp_n,rp) = string_mcode rp in +let (lp2_n,lp2) = string_mcode lp2 in +let (params_n,params) = parameter_dots params in +let (rp2_n,rp2) = string_mcode rp2 in +((multibind ([ty_n;lp_n;star_n] @ idl @ + [rp_n;lp2_n;params_n;rp2_n]), + Ast0.ParenType + (lp, + Ast0.rewrap ty1 (Ast0.Pointer + (Ast0.rewrap ty2 (Ast0.FunctionType + (typ,lp2,params,rp2)),star)),rp)), idu) + | _ -> failwith "ParenType Visitor_ast0") +| Ast0.Array(ty1,lb1,size1,rb1) -> +(match Ast0.unwrap ty1 with + Ast0.Pointer(ty2,star) -> +(match Ast0.unwrap ty2 with + Ast0.FunctionType(ty3,lp3,params,rp3) -> +let (ty_n,typ) = typeC ty3 in +let (lp_n,lp) = string_mcode lp in +let (star_n,star) = string_mcode star in +let (idl,idu) = (match id with + | Some a -> let (b,c) = ident a in ([b],Some c) + | None -> ([],None)) in +let (lb1_n,lb1) = string_mcode lb1 in +let (size_n,size1) = get_option expression size1 in +let (rb1_n,rb1) = string_mcode rb1 in +let (rp_n,rp) = string_mcode rp in +let (lp3_n,lp3) = string_mcode lp3 in +let (params_n,params) = parameter_dots params in +let (rp3_n,rp3) = string_mcode rp3 in +((multibind ([ty_n;lp_n;star_n] @ idl @ + [lb1_n;size_n;rb1_n;rp_n;lp3_n;params_n;rp3_n]), + Ast0.ParenType + (lp, + Ast0.rewrap ty1 + (Ast0.Array + (Ast0.rewrap ty2 + (Ast0.Pointer + (Ast0.rewrap ty3 + (Ast0.FunctionType(typ,lp3,params,rp3)), + star)), +lb1,size1,rb1)), + rp)), + idu) + | _ -> failwith "ParenType Visitor_ast0") +| _ -> failwith "ParenType Visitor_ast0") +| _ -> failwith "ParenType Visitor_ast0" + + and functiontype_type (ty,(id : Ast0.ident option),lp,params,rp) = +let (ty_n,ty) = typeC ty in +let (idl,idu) = (match id with + | Some a -> let (b,c) = ident a in ([b],Some c) + | None -> ([],None)) in +let (lp_n,lp) = string_mcode lp in +let (params_n,params) = parameter_dots params in +let (rp_n,rp) = string_mcode rp in +((multibind ([ty_n] @ idl @ [lp_n; params_n; rp_n]), + Ast0.FunctionType(ty,lp,params,rp)), idu) + and named_type ty id = match Ast0.unwrap ty with Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) -> @@ -446,6 +522,14 @@ let visitor mode bind option_default let (tyres, idn) = array_type (rty,Some id,lb,size,rb) in let idn = match idn with Some i -> i | None -> failwith