From 1c82453e89e0b569630e48ddde015e201df0e5f9 Mon Sep 17 00:00:00 2001 From: Brandon Wu <49291449+brandonspark@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:05:10 -0800 Subject: [PATCH] chore(ast-generic): Add `Cls` variant (#329) - [X] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [X] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to *consume* data generated by Semgrep 1.50.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades Note that the types related to the semgrep-core JSON output or the semgrep-core RPC do not need to be backward compatible! --- ast_generic_v1.atd | 1 + ast_generic_v1_j.ml | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ast_generic_v1.atd b/ast_generic_v1.atd index 70477e8..1884a88 100644 --- a/ast_generic_v1.atd +++ b/ast_generic_v1.atd @@ -287,6 +287,7 @@ type field_name = [ type special = [ (* special vars *) | This | Super (* called 'base' in C# *) + | Cls (* similar to `self`, but indicating the type of the class, not the instance *) | Self | Parent (* different from This/Super? *) (* special calls *) diff --git a/ast_generic_v1_j.ml b/ast_generic_v1_j.ml index 68488cd..682c5d8 100644 --- a/ast_generic_v1_j.ml +++ b/ast_generic_v1_j.ml @@ -1361,6 +1361,7 @@ let write_special = ( match x with | `This -> Buffer.add_string ob "\"This\"" | `Super -> Buffer.add_string ob "\"Super\"" + | `Cls -> Buffer.add_string ob "\"Cls\"" | `Self -> Buffer.add_string ob "\"Self\"" | `Parent -> Buffer.add_string ob "\"Parent\"" | `Eval -> Buffer.add_string ob "\"Eval\"" @@ -1435,6 +1436,10 @@ let read_special = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; `Super + | "Cls" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `Cls | "Self" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; @@ -1578,6 +1583,8 @@ let read_special = ( `This | "Super" -> `Super + | "Cls" -> + `Cls | "Self" -> `Self | "Parent" ->