update reserved names: add finally, fn, match, yield

pull/7268/head
Brent Shaffer 3 years ago
parent 336ed1820a
commit bade043986
  1. 31
      php/ext/google/protobuf/names.c
  2. 19
      php/src/Google/Protobuf/Internal/GPBUtil.php
  3. 24
      php/tests/GeneratedClassTest.php
  4. 4
      php/tests/proto/test_reserved_enum_lower.proto
  5. 90
      php/tests/proto/test_reserved_enum_upper.proto
  6. 90
      php/tests/proto/test_reserved_enum_value_lower.proto
  7. 4
      php/tests/proto/test_reserved_message_lower.proto
  8. 4
      php/tests/proto/test_reserved_message_upper.proto
  9. 33
      src/google/protobuf/compiler/php/php_generator.cc

@ -71,21 +71,22 @@ static void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
/* def name -> classname ******************************************************/
const char *const kReservedNames[] = {
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"for", "foreach", "function", "global", "goto",
"if", "implements", "include", "include_once", "instanceof",
"insteadof", "interface", "isset", "list", "namespace",
"new", "or", "print", "private", "protected",
"public", "require", "require_once", "return", "static",
"switch", "throw", "trait", "try", "unset",
"use", "var", "while", "xor", "int",
"float", "bool", "string", "true", "false",
"null", "void", "iterable", NULL};
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"finally", "fn" "for", "foreach", "function",
"if", "implements", "include", "include_once", "instanceof",
"global", "goto", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "or",
"print", "private", "protected", "public", "require",
"require_once", "return", "static", "switch", "throw",
"trait", "try", "unset", "use", "var",
"while", "xor", "yield", "int", "float",
"bool", "string", "true", "false", "null",
"void", "iterable", NULL};
bool is_reserved_name(const char* name) {
int i;

@ -279,15 +279,16 @@ class GPBUtil
"do"=>0, "echo"=>0, "else"=>0, "elseif"=>0, "empty"=>0,
"enddeclare"=>0, "endfor"=>0, "endforeach"=>0, "endif"=>0,
"endswitch"=>0, "endwhile"=>0, "eval"=>0, "exit"=>0, "extends"=>0,
"final"=>0, "for"=>0, "foreach"=>0, "function"=>0, "global"=>0,
"goto"=>0, "if"=>0, "implements"=>0, "include"=>0,
"include_once"=>0, "instanceof"=>0, "insteadof"=>0, "interface"=>0,
"isset"=>0, "list"=>0, "namespace"=>0, "new"=>0, "or"=>0,
"print"=>0, "private"=>0, "protected"=>0, "public"=>0, "require"=>0,
"require_once"=>0, "return"=>0, "static"=>0, "switch"=>0,
"throw"=>0, "trait"=>0, "try"=>0, "unset"=>0, "use"=>0, "var"=>0,
"while"=>0, "xor"=>0, "int"=>0, "float"=>0, "bool"=>0, "string"=>0,
"true"=>0, "false"=>0, "null"=>0, "void"=>0, "iterable"=>0
"final"=>0, "finally"=>0, "fn"=>0, "for"=>0, "foreach"=>0,
"function"=>0, "global"=>0, "goto"=>0, "if"=>0, "implements"=>0,
"include"=>0, "include_once"=>0, "instanceof"=>0, "insteadof"=>0,
"interface"=>0, "isset"=>0, "list"=>0, "match"=>0, "namespace"=>0,
"new"=>0, "or"=>0, "print"=>0, "private"=>0, "protected"=>0,
"public"=>0, "require"=>0, "require_once"=>0, "return"=>0,
"static"=>0, "switch"=>0, "throw"=>0, "trait"=>0, "try"=>0,
"unset"=>0, "use"=>0, "var"=>0, "while"=>0, "xor"=>0, "yield"=>0,
"int"=>0, "float"=>0, "bool"=>0, "string"=>0, "true"=>0, "false"=>0,
"null"=>0, "void"=>0, "iterable"=>0
);
if (array_key_exists(strtolower($classname), $reserved_words)) {

@ -913,6 +913,8 @@ class GeneratedClassTest extends TestBase
$m = new \Lower\PBexit();
$m = new \Lower\PBextends();
$m = new \Lower\PBfinal();
$m = new \Lower\PBfinally();
$m = new \Lower\PBfn();
$m = new \Lower\PBfor();
$m = new \Lower\PBforeach();
$m = new \Lower\PBfunction();
@ -927,6 +929,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower\PBinterface();
$m = new \Lower\PBisset();
$m = new \Lower\PBlist();
$m = new \Lower\PBmatch();
$m = new \Lower\PBnamespace();
$m = new \Lower\PBnew();
$m = new \Lower\PBor();
@ -947,6 +950,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower\PBvar();
$m = new \Lower\PBwhile();
$m = new \Lower\PBxor();
$m = new \Lower\PByield();
$m = new \Lower\PBint();
$m = new \Lower\PBfloat();
$m = new \Lower\PBbool();
@ -987,6 +991,8 @@ class GeneratedClassTest extends TestBase
$m = new \Upper\PBEXIT();
$m = new \Upper\PBEXTENDS();
$m = new \Upper\PBFINAL();
$m = new \Upper\PBFINALLY();
$m = new \Upper\PBFN();
$m = new \Upper\PBFOR();
$m = new \Upper\PBFOREACH();
$m = new \Upper\PBFUNCTION();
@ -1001,6 +1007,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper\PBINTERFACE();
$m = new \Upper\PBISSET();
$m = new \Upper\PBLIST();
$m = new \Upper\PBMATCH();
$m = new \Upper\PBNAMESPACE();
$m = new \Upper\PBNEW();
$m = new \Upper\PBOR();
@ -1021,6 +1028,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper\PBVAR();
$m = new \Upper\PBWHILE();
$m = new \Upper\PBXOR();
$m = new \Upper\PBYIELD();
$m = new \Upper\PBINT();
$m = new \Upper\PBFLOAT();
$m = new \Upper\PBBOOL();
@ -1061,6 +1069,8 @@ class GeneratedClassTest extends TestBase
$m = new \Lower_enum\PBexit();
$m = new \Lower_enum\PBextends();
$m = new \Lower_enum\PBfinal();
$m = new \Lower_enum\PBfinally();
$m = new \Lower_enum\PBfn();
$m = new \Lower_enum\PBfor();
$m = new \Lower_enum\PBforeach();
$m = new \Lower_enum\PBfunction();
@ -1075,6 +1085,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower_enum\PBinterface();
$m = new \Lower_enum\PBisset();
$m = new \Lower_enum\PBlist();
$m = new \Lower_enum\PBmatch();
$m = new \Lower_enum\PBnamespace();
$m = new \Lower_enum\PBnew();
$m = new \Lower_enum\PBor();
@ -1095,6 +1106,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower_enum\PBvar();
$m = new \Lower_enum\PBwhile();
$m = new \Lower_enum\PBxor();
$m = new \Lower_enum\PByield();
$m = new \Lower_enum\PBint();
$m = new \Lower_enum\PBfloat();
$m = new \Lower_enum\PBbool();
@ -1135,6 +1147,8 @@ class GeneratedClassTest extends TestBase
$m = new \Upper_enum\PBEXIT();
$m = new \Upper_enum\PBEXTENDS();
$m = new \Upper_enum\PBFINAL();
$m = new \Upper_enum\PBFINALLY();
$m = new \Upper_enum\PBFN();
$m = new \Upper_enum\PBFOR();
$m = new \Upper_enum\PBFOREACH();
$m = new \Upper_enum\PBFUNCTION();
@ -1149,6 +1163,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper_enum\PBINTERFACE();
$m = new \Upper_enum\PBISSET();
$m = new \Upper_enum\PBLIST();
$m = new \Upper_enum\PBMATCH();
$m = new \Upper_enum\PBNAMESPACE();
$m = new \Upper_enum\PBNEW();
$m = new \Upper_enum\PBOR();
@ -1169,6 +1184,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper_enum\PBVAR();
$m = new \Upper_enum\PBWHILE();
$m = new \Upper_enum\PBXOR();
$m = new \Upper_enum\PBYIELD();
$m = new \Upper_enum\PBINT();
$m = new \Upper_enum\PBFLOAT();
$m = new \Upper_enum\PBBOOL();
@ -1209,6 +1225,8 @@ class GeneratedClassTest extends TestBase
$m = \Lower_enum_value\NotAllowed::PBexit;
$m = \Lower_enum_value\NotAllowed::PBextends;
$m = \Lower_enum_value\NotAllowed::PBfinal;
$m = \Lower_enum_value\NotAllowed::PBfinally;
$m = \Lower_enum_value\NotAllowed::PBfn;
$m = \Lower_enum_value\NotAllowed::PBfor;
$m = \Lower_enum_value\NotAllowed::PBforeach;
$m = \Lower_enum_value\NotAllowed::PBfunction;
@ -1223,6 +1241,7 @@ class GeneratedClassTest extends TestBase
$m = \Lower_enum_value\NotAllowed::PBinterface;
$m = \Lower_enum_value\NotAllowed::PBisset;
$m = \Lower_enum_value\NotAllowed::PBlist;
$m = \Lower_enum_value\NotAllowed::PBmatch;
$m = \Lower_enum_value\NotAllowed::PBnamespace;
$m = \Lower_enum_value\NotAllowed::PBnew;
$m = \Lower_enum_value\NotAllowed::PBor;
@ -1243,6 +1262,7 @@ class GeneratedClassTest extends TestBase
$m = \Lower_enum_value\NotAllowed::PBvar;
$m = \Lower_enum_value\NotAllowed::PBwhile;
$m = \Lower_enum_value\NotAllowed::PBxor;
$m = \Lower_enum_value\NotAllowed::PByield;
$m = \Lower_enum_value\NotAllowed::int;
$m = \Lower_enum_value\NotAllowed::float;
$m = \Lower_enum_value\NotAllowed::bool;
@ -1283,6 +1303,8 @@ class GeneratedClassTest extends TestBase
$m = \Upper_enum_value\NotAllowed::PBEXIT;
$m = \Upper_enum_value\NotAllowed::PBEXTENDS;
$m = \Upper_enum_value\NotAllowed::PBFINAL;
$m = \Upper_enum_value\NotAllowed::PBFINALLY;
$m = \Upper_enum_value\NotAllowed::PBFN;
$m = \Upper_enum_value\NotAllowed::PBFOR;
$m = \Upper_enum_value\NotAllowed::PBFOREACH;
$m = \Upper_enum_value\NotAllowed::PBFUNCTION;
@ -1297,6 +1319,7 @@ class GeneratedClassTest extends TestBase
$m = \Upper_enum_value\NotAllowed::PBINTERFACE;
$m = \Upper_enum_value\NotAllowed::PBISSET;
$m = \Upper_enum_value\NotAllowed::PBLIST;
$m = \Upper_enum_value\NotAllowed::PBMATCH;
$m = \Upper_enum_value\NotAllowed::PBNAMESPACE;
$m = \Upper_enum_value\NotAllowed::PBNEW;
$m = \Upper_enum_value\NotAllowed::PBOR;
@ -1317,6 +1340,7 @@ class GeneratedClassTest extends TestBase
$m = \Upper_enum_value\NotAllowed::PBVAR;
$m = \Upper_enum_value\NotAllowed::PBWHILE;
$m = \Upper_enum_value\NotAllowed::PBXOR;
$m = \Upper_enum_value\NotAllowed::PBYIELD;
$m = \Upper_enum_value\NotAllowed::INT;
$m = \Upper_enum_value\NotAllowed::FLOAT;
$m = \Upper_enum_value\NotAllowed::BOOL;

@ -32,6 +32,8 @@ enum eval { ZERO27 = 0; }
enum exit { ZERO28 = 0; }
enum extends { ZERO29 = 0; }
enum final { ZERO30 = 0; }
enum finally { ZERO30 = 0; }
enum fn { ZERO30 = 0; }
enum for { ZERO31 = 0; }
enum foreach { ZERO32 = 0; }
enum function { ZERO33 = 0; }
@ -46,6 +48,7 @@ enum insteadof { ZERO41 = 0; }
enum interface { ZERO42 = 0; }
enum isset { ZERO43 = 0; }
enum list { ZERO44 = 0; }
enum match { ZERO30 = 0; }
enum namespace { ZERO45 = 0; }
enum new { ZERO46 = 0; }
enum or { ZERO47 = 0; }
@ -66,6 +69,7 @@ enum use { ZERO61 = 0; }
enum var { ZERO62 = 0; }
enum while { ZERO63 = 0; }
enum xor { ZERO64 = 0; }
enum yield { ZERO30 = 0; }
enum int { ZERO65 = 0; }
enum float { ZERO66 = 0; }
enum bool { ZERO67 = 0; }

@ -32,46 +32,50 @@ enum EVAL { ZERO27 = 0; }
enum EXIT { ZERO28 = 0; }
enum EXTENDS { ZERO29 = 0; }
enum FINAL { ZERO30 = 0; }
enum FOR { ZERO31 = 0; }
enum FOREACH { ZERO32 = 0; }
enum FUNCTION { ZERO33 = 0; }
enum GLOBAL { ZERO34 = 0; }
enum GOTO { ZERO35 = 0; }
enum IF { ZERO36 = 0; }
enum IMPLEMENTS { ZERO37 = 0; }
enum INCLUDE { ZERO38 = 0; }
enum INCLUDE_ONCE { ZERO39 = 0; }
enum INSTANCEOF { ZERO40 = 0; }
enum INSTEADOF { ZERO41 = 0; }
enum INTERFACE { ZERO42 = 0; }
enum ISSET { ZERO43 = 0; }
enum LIST { ZERO44 = 0; }
enum NAMESPACE { ZERO45 = 0; }
enum NEW { ZERO46 = 0; }
enum OR { ZERO47 = 0; }
enum PRINT { ZERO48 = 0; }
enum PRIVATE { ZERO49 = 0; }
enum PROTECTED { ZERO50 = 0; }
enum PUBLIC { ZERO51 = 0; }
enum REQUIRE { ZERO52 = 0; }
enum REQUIRE_ONCE { ZERO53 = 0; }
enum RETURN { ZERO54 = 0; }
enum STATIC { ZERO55 = 0; }
enum SWITCH { ZERO56 = 0; }
enum THROW { ZERO57 = 0; }
enum TRAIT { ZERO58 = 0; }
enum TRY { ZERO59 = 0; }
enum UNSET { ZERO60 = 0; }
enum USE { ZERO61 = 0; }
enum VAR { ZERO62 = 0; }
enum WHILE { ZERO63 = 0; }
enum XOR { ZERO64 = 0; }
enum INT { ZERO65 = 0; }
enum FLOAT { ZERO66 = 0; }
enum BOOL { ZERO67 = 0; }
enum STRING { ZERO68 = 0; }
enum TRUE { ZERO69 = 0; }
enum FALSE { ZERO70 = 0; }
enum NULL { ZERO71 = 0; }
enum VOID { ZERO72 = 0; }
enum ITERABLE { ZERO73 = 0; }
enum FINALLY { ZERO31 = 0; }
enum FN { ZERO32 = 0; }
enum FOR { ZERO33 = 0; }
enum FOREACH { ZERO34 = 0; }
enum FUNCTION { ZERO35 = 0; }
enum GLOBAL { ZERO36 = 0; }
enum GOTO { ZERO37 = 0; }
enum IF { ZERO38 = 0; }
enum IMPLEMENTS { ZERO39 = 0; }
enum INCLUDE { ZERO40 = 0; }
enum INCLUDE_ONCE { ZERO41 = 0; }
enum INSTANCEOF { ZERO42 = 0; }
enum INSTEADOF { ZERO43 = 0; }
enum INTERFACE { ZERO44 = 0; }
enum ISSET { ZERO45 = 0; }
enum LIST { ZERO46 = 0; }
enum MATCH { ZERO47 = 0; }
enum NAMESPACE { ZERO48 = 0; }
enum NEW { ZERO49 = 0; }
enum OR { ZERO50 = 0; }
enum PRINT { ZERO51 = 0; }
enum PRIVATE { ZERO52 = 0; }
enum PROTECTED { ZERO53 = 0; }
enum PUBLIC { ZERO54 = 0; }
enum REQUIRE { ZERO55 = 0; }
enum REQUIRE_ONCE { ZERO56 = 0; }
enum RETURN { ZERO57 = 0; }
enum STATIC { ZERO58 = 0; }
enum SWITCH { ZERO59 = 0; }
enum THROW { ZERO60 = 0; }
enum TRAIT { ZERO61 = 0; }
enum TRY { ZERO62 = 0; }
enum UNSET { ZERO63 = 0; }
enum USE { ZERO64 = 0; }
enum VAR { ZERO65 = 0; }
enum WHILE { ZERO66 = 0; }
enum XOR { ZERO67 = 0; }
enum YIELD { ZERO68 = 0; }
enum INT { ZERO69 = 0; }
enum FLOAT { ZERO70 = 0; }
enum BOOL { ZERO71 = 0; }
enum STRING { ZERO72 = 0; }
enum TRUE { ZERO73 = 0; }
enum FALSE { ZERO74 = 0; }
enum NULL { ZERO75 = 0; }
enum VOID { ZERO76 = 0; }
enum ITERABLE { ZERO77 = 0; }

@ -33,47 +33,51 @@ enum NotAllowed {
exit = 27;
extends = 28;
final = 29;
for = 30;
foreach = 31;
function = 32;
global = 33;
goto = 34;
if = 35;
implements = 36;
include = 37;
include_once = 38;
instanceof = 39;
insteadof = 40;
interface = 41;
isset = 42;
list = 43;
namespace = 44;
new = 45;
or = 46;
print = 47;
private = 48;
protected = 49;
public = 50;
require = 51;
require_once = 52;
return = 53;
static = 54;
switch = 55;
throw = 56;
trait = 57;
try = 58;
unset = 59;
use = 60;
var = 61;
while = 62;
xor = 63;
int = 64;
float = 65;
bool = 66;
string = 67;
true = 68;
false = 69;
null = 70;
void = 71;
iterable = 72;
finally = 30;
fn = 31;
for = 32;
foreach = 33;
function = 34;
global = 35;
goto = 36;
if = 37;
implements = 38;
include = 39;
include_once = 40;
instanceof = 41;
insteadof = 42;
interface = 43;
isset = 44;
list = 45;
match = 46;
namespace = 47;
new = 48;
or = 49;
print = 50;
private = 51;
protected = 52;
public = 53;
require = 54;
require_once = 55;
return = 56;
static = 57;
switch = 58;
throw = 59;
trait = 60;
try = 61;
unset = 62;
use = 63;
var = 64;
while = 65;
xor = 66;
yield = 67;
int = 68;
float = 69;
bool = 70;
string = 71;
true = 72;
false = 73;
null = 74;
void = 75;
iterable = 76;
}

@ -32,6 +32,8 @@ message eval {}
message exit {}
message extends {}
message final {}
message finally {}
message fn {}
message for {}
message foreach {}
message function {}
@ -46,6 +48,7 @@ message insteadof {}
message interface {}
message isset {}
message list {}
message match {}
message namespace {}
message new {}
message or {}
@ -66,6 +69,7 @@ message use {}
message var {}
message while {}
message xor {}
message yield {}
message int {}
message float {}
message bool {}

@ -32,6 +32,8 @@ message EVAL {}
message EXIT {}
message EXTENDS {}
message FINAL {}
message FINALLY {}
message FN {}
message FOR {}
message FOREACH {}
message FUNCTION {}
@ -46,6 +48,7 @@ message INSTEADOF {}
message INTERFACE {}
message ISSET {}
message LIST {}
message MATCH {}
message NAMESPACE {}
message NEW {}
message OR {}
@ -66,6 +69,7 @@ message USE {}
message VAR {}
message WHILE {}
message XOR {}
message YIELD {}
message INT {}
message FLOAT {}
message BOOL {}

@ -48,26 +48,27 @@ const std::string kDescriptorMetadataFile =
const std::string kDescriptorDirName = "Google/Protobuf/Internal";
const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
const char* const kReservedNames[] = {
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"for", "foreach", "function", "global", "goto",
"if", "implements", "include", "include_once", "instanceof",
"insteadof", "interface", "isset", "list", "namespace",
"new", "or", "print", "private", "protected",
"public", "require", "require_once", "return", "static",
"switch", "throw", "trait", "try", "unset",
"use", "var", "while", "xor", "int",
"float", "bool", "string", "true", "false",
"null", "void", "iterable"};
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"finally", "fn", "for", "foreach", "function",
"global", "goto", "if", "implements", "include",
"include_once", "instanceof", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "or",
"print", "private", "protected", "public", "require",
"require_once", "return", "static", "switch", "throw",
"trait", "try", "unset", "use", "var",
"while", "xor", "yield" "int", "float",
"bool", "string", "true", "false", "null",
"void", "iterable"};
const char* const kValidConstantNames[] = {
"int", "float", "bool", "string", "true",
"false", "null", "void", "iterable",
};
const int kReservedNamesSize = 73;
const int kReservedNamesSize = 77;
const int kValidConstantNamesSize = 9;
const int kFieldSetter = 1;
const int kFieldGetter = 2;

Loading…
Cancel
Save