Re: [Cocci] Inserting code after specific set of declarations?

2020-03-20 Thread Ville Syrjälä
On Wed, Feb 19, 2020 at 11:37:03PM +0100, Julia Lawall wrote: > > > --- Please note the new email address --- > > > On Wed, 19 Feb 2020, Ville Syrjälä wrote: > > > Hi all, > > > > I was trying to do the following transformation: > > @@ > > identifier M; > > expression E; > > @@ > > - struct

Re: [Cocci] [PATCH v3 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType

2020-03-20 Thread Markus Elfring
> The order of the terms in ParenType require implementing a special > case for ParenType. This case handles only the following: * Would it be nice to mention a key word like “parentheses”? * How do you distinguish “visitors” for the affected software? * I would prefer less repeated change

Re: [Cocci] [PATCH v3 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs

2020-03-20 Thread Markus Elfring
> ParenType and FunctionType are types present in the C AST that > are not present in the SmPL AST. Can the understanding of mentioned details be improved by reconsidering the usage of abbreviations? > In the pursuit of aligning both the C and SmPL ASTs, I find this approach also helpful. >

[Cocci] [PATCH v3 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 25/26] cocci: Remove Ast_cocci.FunctionPointer

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 15/26] parsing_cocci: compute_lines: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 13/26] parsing_cocci: iso_pattern: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 19/26] parsing_cocci: disjdistr: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 23/26] engine: Match A.ParenType and A.FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 24/26] tools: spgen: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 07/26] parsing_cocci: index: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index

[Cocci] [PATCH v3 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 16/26] parsing_cocci: ast0toast: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
ParenType and FunctionType are now added to the SmPL ASTs. Add cases for these types in ast0toast.ml. Signed-off-by: Jaskaran Singh --- parsing_cocci/ast0toast.ml | 6 ++ 1 file changed, 6 insertions(+) diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index

[Cocci] [PATCH v3 26/26] tests: Add test case for array of function pointers

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 12/26] parsing_cocci: check_meta: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 20/26] parsing_cocci: ast_cocci: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 14/26] parsing_cocci: adjust_pragmas: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 08/26] parsing_cocci: context_neg: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs

2020-03-20 Thread Jaskaran Singh
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, a rule similar

[Cocci] [PATCH v3 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules

2020-03-20 Thread Jaskaran Singh
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: (

[Cocci] [PATCH v3 11/26] parsing_cocci: function_prototypes: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 01/26] parsing_cocci: Add Function Prototype token

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 09/26] parsing_cocci: unparse_ast0: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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 | 38 +++ 1 file changed, 38 insertions(+) diff --git a/parsing_cocci/unparse_ast0.ml

[Cocci] [PATCH v3 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs

2020-03-20 Thread Jaskaran Singh
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. For a function pointer as follows: int (*x)(params) The SmPL AST would be as follows: ParenType -> Pointer ->

[Cocci] [PATCH v3 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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

[Cocci] [PATCH v3 10/26] parsing_cocci: single_statement: Add cases for ParenType/FunctionType

2020-03-20 Thread Jaskaran Singh
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