[master] dab8e4ac6 cocci: Make isomorphisms actually work

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Aug 26 17:23:08 UTC 2022


commit dab8e4ac6f594fc097148df0993136030d23983d
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Aug 26 16:47:36 2022 +0200

    cocci: Make isomorphisms actually work
    
    It turns out declaring typedefs in coccinelle works better with the
    typedef keyword. Reusing the same keyword for the same purposes seems
    so obvious in hindsight.
    
    What happened before was that a generic type would be created, making
    VCL_BOOL or VCL_VOID match virtually any type, completely defeating
    the isomorphism purpose. With this out of the way, we can actually
    resume the effort of adding more typedefs.
    
    To summarize:
    
    - we should declare a typedef as an isomorphism
    - we should define macros as such
    
    I'm considering renaming tools/coccinelle/vdef.h to varnish.h to match
    the varnish.iso file name and wrapping the README instructions in a new
    shell script.

diff --git a/tools/coccinelle/README.rst b/tools/coccinelle/README.rst
index 99831344a..7582a6c7a 100644
--- a/tools/coccinelle/README.rst
+++ b/tools/coccinelle/README.rst
@@ -15,6 +15,13 @@ Unless noted otherwise, all patches should work when invoked as::
 	       -I include/ -I bin/varnishd/ --dir . --in-place \
 	       --sp-file $COCCI
 
+To expand a patch and see the implicit rules that will be taken into account,
+it is possible to parse the file::
+
+	spatch --macro-file tools/coccinelle/vdef.h \
+	       -I include/ -I bin/varnishd/ --parse-cocci
+	       --sp-file $COCCI
+
 The ``archive/`` directory contains patches which we used once and
 should not need again, but want to retain for reference.
 
diff --git a/tools/coccinelle/varnish.iso b/tools/coccinelle/varnish.iso
index e7034b296..c47b97f69 100644
--- a/tools/coccinelle/varnish.iso
+++ b/tools/coccinelle/varnish.iso
@@ -5,24 +5,26 @@
  * It can be used directly by semantic patches from the same directory
  * with the following syntax:
  *
- *     using "varnish.iso"
+ *     @using "varnish.iso"@
+ *     <decl>
+ *     @@
+ *
+ *     <semantic-diff>
  *
  * XXX: way incomplete.
- * XXX: consider autogeneration.
+ * XXX: consider autogeneration?
  */
 
 /* This section contains VCL types used by VMODs */
 
 Type
 @ vcl_void @
-type VCL_VOID;
+typedef VCL_VOID;
 @@
-
 VCL_VOID <=> void
 
 Type
 @ vcl_bool @
-type VCL_BOOL;
+typedef VCL_BOOL;
 @@
-
 VCL_BOOL <=> unsigned


More information about the varnish-commit mailing list