summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2021-12-18 15:30:38 +1300
committerOlly Betts <olly@survex.com>2021-12-18 15:30:38 +1300
commit7d75e3eb7e760846f8569ecea0e6a379029c9db6 (patch)
tree2348a7e056494bec2a8ccb25556c03d234936eb3
parent6f016f3a3864093d68c981b48260589418ec6565 (diff)
downloadswig-7d75e3eb7e760846f8569ecea0e6a379029c9db6.tar.gz
[PHP] Add new PHP 8.1 keyword
Add PHP keyword 'readonly' (added in 8.1) to the list SWIG knows to automatically rename. This keyword is special in that PHP allows it to be used as a function (or method) name.
-rw-r--r--CHANGES.current5
-rw-r--r--Examples/test-suite/php_namewarn_rename.i14
-rw-r--r--Lib/php/phpkw.swg9
3 files changed, 28 insertions, 0 deletions
diff --git a/CHANGES.current b/CHANGES.current
index cadbbadfb..fc56246c6 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
+2021-12-18: olly
+ [PHP] Add PHP keyword 'readonly' (added in 8.1) to the list SWIG
+ knows to automatically rename. This keyword is special in that PHP
+ allows it to be used as a function (or method) name.
+
2021-12-05: rwf1
[Octave] #2020 #1893 Add support for Octave 6 up to and including 6.4.
Also add support for compiling with -Bsymbolic which is used by default
diff --git a/Examples/test-suite/php_namewarn_rename.i b/Examples/test-suite/php_namewarn_rename.i
index bb54dba5e..d70cad770 100644
--- a/Examples/test-suite/php_namewarn_rename.i
+++ b/Examples/test-suite/php_namewarn_rename.i
@@ -8,6 +8,7 @@
%warnfilter(SWIGWARN_PARSE_KEYWORD) null;
%warnfilter(SWIGWARN_PARSE_KEYWORD) True;
%warnfilter(SWIGWARN_PARSE_KEYWORD) FALSE;
+%warnfilter(SWIGWARN_PARSE_KEYWORD) ns::readonly;
#endif
%ignore prev::operator++;
@@ -50,4 +51,17 @@
class FALSE
{
};
+
+ // PHP 8.1 made `readonly` a keyword, but (unlike any other keyword it seems)
+ // it may still be used as a function name.
+ namespace ns {
+ class readonly { };
+ }
+
+ class readonly_should_be_ok_as_method {
+ public:
+ bool readonly() const { return true; }
+ };
+
+ bool readonly() { return false; }
%}
diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg
index e431fc2e4..b6855ce9a 100644
--- a/Lib/php/phpkw.swg
+++ b/Lib/php/phpkw.swg
@@ -5,6 +5,9 @@
/* Keyword (case insensitive) */
#define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renaming to 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x`
+/* Keyword, except ok as a function */
+#define PHPKW_ok_as_function(x) %keywordwarn("'" `x` "' is a PHP keyword, renaming to 'c_" `x` "'",%$not %$isfunction,sourcefmt="%(lower)s",rename="c_%s") `x`
+
/* Class (case insensitive) */
#define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, renaming to 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x`
@@ -84,6 +87,11 @@ PHPKW(while);
PHPKW(xor);
PHPKW(yield);
+/* PHP 8.1 made `readonly` a keyword, but (unlike any other keyword it seems)
+ * it may still be used as a function name.
+ */
+PHPKW_ok_as_function(readonly);
+
// Compile-time "magic" constants
// From: http://php.net/manual/en/reserved.keywords.php
// also at: http://php.net/manual/en/language.constants.predefined.php
@@ -869,6 +877,7 @@ PHPFN(unset); // "Language construct"
PHPFN(usort);
#undef PHPKW
+#undef PHPKW_ok_as_function
#undef PHPBN1a
#undef PHPBN1b
#undef PHPBN1