[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.
This commit is contained in:
Olly Betts 2021-12-18 15:30:38 +13:00
parent 6f016f3a38
commit 7d75e3eb7e
3 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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; }
%}

View File

@ -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