From 4c946886200223d2fa467acfa7840979b34f8c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Pottier?= Date: Sun, 7 Jul 2024 20:52:55 +0200 Subject: [PATCH] Remove the distinction between [`Def] and [`Defun]. There was no strong reason for this distinction to exist. --- src/cppo_eval.ml | 11 ++--------- src/cppo_parser.mly | 7 ++++--- src/cppo_types.ml | 5 +++-- src/cppo_types.mli | 5 +++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/cppo_eval.ml b/src/cppo_eval.ml index 3ea7dc7..6891efe 100644 --- a/src/cppo_eval.ml +++ b/src/cppo_eval.ml @@ -556,19 +556,12 @@ and expand_node ?(top = false) g env0 (x : node) = env - | `Def (loc, name, body)-> + | `Def (loc, name, formals, body)-> g.require_location := true; if M.mem name env0 then error loc (sprintf "%S is already defined" name) else - M.add name (EDef (loc, [], body, env0)) env0 - - | `Defun (loc, name, arg_names, body) -> - g.require_location := true; - if M.mem name env0 then - error loc (sprintf "%S is already defined" name) - else - M.add name (EDef (loc, arg_names, body, env0)) env0 + M.add name (EDef (loc, formals, body, env0)) env0 | `Undef (loc, name) -> g.require_location := true; diff --git a/src/cppo_parser.mly b/src/cppo_parser.mly index d064322..f3c7286 100644 --- a/src/cppo_parser.mly +++ b/src/cppo_parser.mly @@ -102,11 +102,12 @@ node: let body = $2 @ [safe_space] in let _, pos2 = $3 in - `Def ((pos1, pos2), name, body) } + let formals = [] in + `Def ((pos1, pos2), name, formals, body) } | DEFUN def_args1 CL_PAREN unode_list0 ENDEF { let (pos1, _), name = $1 in - let args = $2 in + let formals = $2 in (* Additional spacing is needed for cases like 'foo()bar' where 'foo()' expands into 'abc', giving 'abcbar' @@ -117,7 +118,7 @@ node: let body = $4 @ [safe_space] in let _, pos2 = $5 in - `Defun ((pos1, pos2), name, args, body) } + `Def ((pos1, pos2), name, formals, body) } | DEFUN CL_PAREN { error (fst (fst $1), snd $2) diff --git a/src/cppo_types.ml b/src/cppo_types.ml index 5c0cec6..c221991 100644 --- a/src/cppo_types.ml +++ b/src/cppo_types.ml @@ -51,10 +51,11 @@ and arith_expr = (* signed int64 *) type node = [ `Ident of (loc * string * actuals) - | `Def of (loc * macro * body) - | `Defun of (loc * macro * formals * body) (* the list [actuals] is empty if and only if no parentheses are used at this macro invocation site. *) + | `Def of (loc * macro * formals * body) + (* the list [formals] is empty if and only if no parentheses + are used at this macro definition site. *) | `Undef of (loc * macro) | `Include of (loc * string) | `Ext of (loc * string * string) diff --git a/src/cppo_types.mli b/src/cppo_types.mli index a8b7b32..0a35533 100644 --- a/src/cppo_types.mli +++ b/src/cppo_types.mli @@ -49,8 +49,9 @@ type node = [ `Ident of (loc * string * actuals) (* the list [actuals] is empty if and only if no parentheses are used at this macro invocation site. *) - | `Def of (loc * macro * body) - | `Defun of (loc * macro * formals * body) + | `Def of (loc * macro * formals * body) + (* the list [formals] is empty if and only if no parentheses + are used at this macro definition site. *) | `Undef of (loc * macro) | `Include of (loc * string) | `Ext of (loc * string * string)