Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
5dd818cd
Commit
5dd818cd
authored
Sep 15, 2017
by
Paul Yang
Committed by
GitHub
Sep 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3612 from TeBoring/php-bug
Add prefix to php reserved keywords.
parents
b04e5cba
a425dd97
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
643 additions
and
30 deletions
+643
-30
Makefile.am
Makefile.am
+6
-0
def.c
php/ext/google/protobuf/def.c
+9
-8
protobuf.c
php/ext/google/protobuf/protobuf.c
+43
-0
protobuf.h
php/ext/google/protobuf/protobuf.h
+26
-0
GPBUtil.php
php/src/Google/Protobuf/Internal/GPBUtil.php
+23
-8
generated_class_test.php
php/tests/generated_class_test.php
+0
-0
test_reserved_enum_lower.proto
php/tests/proto/test_reserved_enum_lower.proto
+77
-0
test_reserved_enum_upper.proto
php/tests/proto/test_reserved_enum_upper.proto
+77
-0
test_reserved_enum_value_lower.proto
php/tests/proto/test_reserved_enum_value_lower.proto
+79
-0
test_reserved_enum_value_upper.proto
php/tests/proto/test_reserved_enum_value_upper.proto
+79
-0
test_reserved_message_lower.proto
php/tests/proto/test_reserved_message_lower.proto
+77
-0
test_reserved_message_upper.proto
php/tests/proto/test_reserved_message_upper.proto
+77
-0
php_generator.cc
src/google/protobuf/compiler/php/php_generator.cc
+55
-5
tests.sh
tests.sh
+15
-9
No files found.
Makefile.am
View file @
5dd818cd
...
...
@@ -686,6 +686,12 @@ php_EXTRA_DIST= \
php/tests/proto/test_no_namespace.proto
\
php/tests/proto/test_php_namespace.proto
\
php/tests/proto/test_prefix.proto
\
php/tests/proto/test_reserved_enum_lower.proto
\
php/tests/proto/test_reserved_enum_upper.proto
\
php/tests/proto/test_reserved_enum_value_lower.proto
\
php/tests/proto/test_reserved_enum_value_upper.proto
\
php/tests/proto/test_reserved_message_lower.proto
\
php/tests/proto/test_reserved_message_upper.proto
\
php/tests/proto/test_service.proto
\
php/tests/proto/test_service_namespace.proto
\
php/tests/test.sh
\
...
...
php/ext/google/protobuf/def.c
View file @
5dd818cd
...
...
@@ -30,9 +30,6 @@
#include "protobuf.h"
const
char
*
const
kReservedNames
[]
=
{
"Empty"
,
"ECHO"
,
"ARRAY"
};
const
int
kReservedNamesSize
=
3
;
// Forward declare.
static
void
descriptor_init_c_instance
(
Descriptor
*
intern
TSRMLS_DC
);
static
void
descriptor_free_c
(
Descriptor
*
object
TSRMLS_DC
);
...
...
@@ -774,12 +771,16 @@ static const char *classname_prefix(const char *classname,
return
prefix_given
;
}
for
(
i
=
0
;
i
<
kReservedNamesSize
;
i
++
)
{
if
(
strcmp
(
kReservedNames
[
i
],
classname
)
==
0
)
{
is_reserved
=
true
;
break
;
}
char
*
lower
=
ALLOC_N
(
char
,
strlen
(
classname
)
+
1
);
i
=
0
;
while
(
classname
[
i
])
{
lower
[
i
]
=
(
char
)
tolower
(
classname
[
i
])
;
i
++
;
}
lower
[
i
]
=
0
;
is_reserved
=
is_reserved_name
(
lower
);
FREE
(
lower
);
if
(
is_reserved
)
{
if
(
package_name
!=
NULL
&&
strcmp
(
"google.protobuf"
,
package_name
)
==
0
)
{
...
...
php/ext/google/protobuf/protobuf.c
View file @
5dd818cd
...
...
@@ -46,6 +46,7 @@ static HashTable* upb_def_to_php_obj_map;
// Global map from message/enum's php class entry to corresponding wrapper
// Descriptor/EnumDescriptor instances.
static
HashTable
*
ce_to_php_obj_map
;
static
HashTable
*
reserved_names
;
// -----------------------------------------------------------------------------
// Global maps.
...
...
@@ -110,6 +111,36 @@ bool class_added(const void* ce) {
return
exist_in_table
(
ce_to_php_obj_map
,
ce
);
}
// -----------------------------------------------------------------------------
// Reserved Name.
// -----------------------------------------------------------------------------
// Although we already have kReservedNames, we still add them to hash table to
// speed up look up.
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"
};
const
int
kReservedNamesSize
=
73
;
bool
is_reserved_name
(
const
char
*
name
)
{
void
**
value
;
return
(
php_proto_zend_hash_find
(
reserved_names
,
name
,
strlen
(
name
),
(
void
**
)
&
value
)
==
SUCCESS
);
}
// -----------------------------------------------------------------------------
// Utilities.
// -----------------------------------------------------------------------------
...
...
@@ -157,12 +188,21 @@ static void php_proto_hashtable_descriptor_release(zval* value) {
#endif
static
PHP_RINIT_FUNCTION
(
protobuf
)
{
int
i
=
0
;
ALLOC_HASHTABLE
(
upb_def_to_php_obj_map
);
zend_hash_init
(
upb_def_to_php_obj_map
,
16
,
NULL
,
HASHTABLE_VALUE_DTOR
,
0
);
ALLOC_HASHTABLE
(
ce_to_php_obj_map
);
zend_hash_init
(
ce_to_php_obj_map
,
16
,
NULL
,
HASHTABLE_VALUE_DTOR
,
0
);
ALLOC_HASHTABLE
(
reserved_names
);
zend_hash_init
(
reserved_names
,
16
,
NULL
,
NULL
,
0
);
for
(
i
=
0
;
i
<
kReservedNamesSize
;
i
++
)
{
php_proto_zend_hash_update
(
reserved_names
,
kReservedNames
[
i
],
strlen
(
kReservedNames
[
i
]));
}
generated_pool
=
NULL
;
generated_pool_php
=
NULL
;
internal_generated_pool_php
=
NULL
;
...
...
@@ -177,6 +217,9 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) {
zend_hash_destroy
(
ce_to_php_obj_map
);
FREE_HASHTABLE
(
ce_to_php_obj_map
);
zend_hash_destroy
(
reserved_names
);
FREE_HASHTABLE
(
reserved_names
);
#if PHP_MAJOR_VERSION < 7
if
(
generated_pool_php
!=
NULL
)
{
zval_dtor
(
generated_pool_php
);
...
...
php/ext/google/protobuf/protobuf.h
View file @
5dd818cd
...
...
@@ -77,12 +77,18 @@
#define php_proto_zend_hash_index_update_zval(ht, h, pData) \
zend_hash_index_update(ht, h, &(pData), sizeof(void*), NULL)
#define php_proto_zend_hash_update(ht, key, key_len) \
zend_hash_update(ht, key, key_len, 0, 0, NULL)
#define php_proto_zend_hash_index_update_mem(ht, h, pData, nDataSize, pDest) \
zend_hash_index_update(ht, h, pData, nDataSize, pDest)
#define php_proto_zend_hash_index_find_zval(ht, h, pDest) \
zend_hash_index_find(ht, h, pDest)
#define php_proto_zend_hash_find(ht, key, key_len, pDest) \
zend_hash_find(ht, key, key_len, pDest)
#define php_proto_zend_hash_index_find_mem(ht, h, pDest) \
zend_hash_index_find(ht, h, pDest)
...
...
@@ -234,6 +240,15 @@ static inline int php_proto_zend_hash_index_update_zval(HashTable* ht, ulong h,
return
result
!=
NULL
?
SUCCESS
:
FAILURE
;
}
static
inline
int
php_proto_zend_hash_update
(
HashTable
*
ht
,
const
char
*
key
,
size_t
key_len
)
{
void
*
result
=
NULL
;
zval
temp
;
ZVAL_LONG
(
&
temp
,
0
);
result
=
zend_hash_str_update
(
ht
,
key
,
key_len
,
&
temp
);
return
result
!=
NULL
?
SUCCESS
:
FAILURE
;
}
static
inline
int
php_proto_zend_hash_index_update_mem
(
HashTable
*
ht
,
ulong
h
,
void
*
pData
,
uint
nDataSize
,
void
**
pDest
)
{
...
...
@@ -250,6 +265,13 @@ static inline int php_proto_zend_hash_index_find_zval(const HashTable* ht,
return
result
!=
NULL
?
SUCCESS
:
FAILURE
;
}
static
inline
int
php_proto_zend_hash_find
(
const
HashTable
*
ht
,
const
char
*
key
,
size_t
key_len
,
void
**
pDest
)
{
void
*
result
=
NULL
;
result
=
zend_hash_str_find
(
ht
,
key
,
key_len
);
return
result
!=
NULL
?
SUCCESS
:
FAILURE
;
}
static
inline
int
php_proto_zend_hash_index_find_mem
(
const
HashTable
*
ht
,
ulong
h
,
void
**
pDest
)
{
void
*
result
=
NULL
;
...
...
@@ -910,4 +932,8 @@ const zend_class_entry* field_type_class(
.bucket.obj.object))
#endif
// Reserved name
bool
is_reserved_name
(
const
char
*
name
);
bool
is_valid_constant_name
(
const
char
*
name
);
#endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__
php/src/Google/Protobuf/Internal/GPBUtil.php
View file @
5dd818cd
...
...
@@ -252,14 +252,29 @@ class GPBUtil
return
$prefix
;
}
$reserved_words
=
array
(
"Empty"
,
"ECHO"
,
"ARRAY"
);
foreach
(
$reserved_words
as
$reserved_word
)
{
if
(
$classname
===
$reserved_word
)
{
if
(
$file_proto
->
getPackage
()
===
"google.protobuf"
)
{
return
"GPB"
;
}
else
{
return
"PB"
;
}
$reserved_words
=
array
(
"abstract"
=>
0
,
"and"
=>
0
,
"array"
=>
0
,
"as"
=>
0
,
"break"
=>
0
,
"callable"
=>
0
,
"case"
=>
0
,
"catch"
=>
0
,
"class"
=>
0
,
"clone"
=>
0
,
"const"
=>
0
,
"continue"
=>
0
,
"declare"
=>
0
,
"default"
=>
0
,
"die"
=>
0
,
"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
);
if
(
array_key_exists
(
strtolower
(
$classname
),
$reserved_words
))
{
if
(
$file_proto
->
getPackage
()
===
"google.protobuf"
)
{
return
"GPB"
;
}
else
{
return
"PB"
;
}
}
...
...
php/tests/generated_class_test.php
View file @
5dd818cd
This diff is collapsed.
Click to expand it.
php/tests/proto/test_reserved_enum_lower.proto
0 → 100644
View file @
5dd818cd
syntax
=
"proto3"
;
package
lower_enum
;
enum
abstract
{
ZERO1
=
0
;
}
enum
and
{
ZERO2
=
0
;
}
enum
array
{
ZERO3
=
0
;
}
enum
as
{
ZERO4
=
0
;
}
enum
break
{
ZERO5
=
0
;
}
enum
callable
{
ZERO6
=
0
;
}
enum
case
{
ZERO7
=
0
;
}
enum
catch
{
ZERO8
=
0
;
}
enum
class
{
ZERO9
=
0
;
}
enum
clone
{
ZERO10
=
0
;
}
enum
const
{
ZERO11
=
0
;
}
enum
continue
{
ZERO12
=
0
;
}
enum
declare
{
ZERO13
=
0
;
}
enum
default
{
ZERO14
=
0
;
}
enum
die
{
ZERO15
=
0
;
}
enum
do
{
ZERO16
=
0
;
}
enum
echo
{
ZERO17
=
0
;
}
enum
else
{
ZERO18
=
0
;
}
enum
elseif
{
ZERO19
=
0
;
}
enum
empty
{
ZERO20
=
0
;
}
enum
enddeclare
{
ZERO21
=
0
;
}
enum
endfor
{
ZERO22
=
0
;
}
enum
endforeach
{
ZERO23
=
0
;
}
enum
endif
{
ZERO24
=
0
;
}
enum
endswitch
{
ZERO25
=
0
;
}
enum
endwhile
{
ZERO26
=
0
;
}
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
;
}
php/tests/proto/test_reserved_enum_upper.proto
0 → 100644
View file @
5dd818cd
syntax
=
"proto3"
;
package
upper_enum
;
enum
ABSTRACT
{
ZERO1
=
0
;
}
enum
AND
{
ZERO2
=
0
;
}
enum
ARRAY
{
ZERO3
=
0
;
}
enum
AS
{
ZERO4
=
0
;
}
enum
BREAK
{
ZERO5
=
0
;
}
enum
CALLABLE
{
ZERO6
=
0
;
}
enum
CASE
{
ZERO7
=
0
;
}
enum
CATCH
{
ZERO8
=
0
;
}
enum
CLASS
{
ZERO9
=
0
;
}
enum
CLONE
{
ZERO10
=
0
;
}
enum
CONST
{
ZERO11
=
0
;
}
enum
CONTINUE
{
ZERO12
=
0
;
}
enum
DECLARE
{
ZERO13
=
0
;
}
enum
DEFAULT
{
ZERO14
=
0
;
}
enum
DIE
{
ZERO15
=
0
;
}
enum
DO
{
ZERO16
=
0
;
}
enum
ECHO
{
ZERO17
=
0
;
}
enum
ELSE
{
ZERO18
=
0
;
}
enum
ELSEIF
{
ZERO19
=
0
;
}
enum
EMPTY
{
ZERO20
=
0
;
}
enum
ENDDECLARE
{
ZERO21
=
0
;
}
enum
ENDFOR
{
ZERO22
=
0
;
}
enum
ENDFOREACH
{
ZERO23
=
0
;
}
enum
ENDIF
{
ZERO24
=
0
;
}
enum
ENDSWITCH
{
ZERO25
=
0
;
}
enum
ENDWHILE
{
ZERO26
=
0
;
}
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
;
}
php/tests/proto/test_reserved_enum_value_lower.proto
0 → 100644
View file @
5dd818cd
syntax
=
"proto3"
;
package
lower_enum_value
;
enum
NotAllowed
{
abstract
=
0
;
and
=
1
;
array
=
2
;
as
=
3
;
break
=
4
;
callable
=
5
;
case
=
6
;
catch
=
7
;
class
=
8
;
clone
=
9
;
const
=
10
;
continue
=
11
;
declare
=
12
;
default
=
13
;
die
=
14
;
do
=
15
;
echo
=
16
;
else
=
17
;
elseif
=
18
;
empty
=
19
;
enddeclare
=
20
;
endfor
=
21
;
endforeach
=
22
;
endif
=
23
;
endswitch
=
24
;
endwhile
=
25
;
eval
=
26
;
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
;
}
php/tests/proto/test_reserved_enum_value_upper.proto
0 → 100644
View file @
5dd818cd
syntax
=
"proto3"
;
package
upper_enum_value
;
enum
NotAllowed
{
ABSTRACT
=
0
;
AND
=
1
;
ARRAY
=
2
;
AS
=
3
;
BREAK
=
4
;
CALLABLE
=
5
;
CASE
=
6
;
CATCH
=
7
;
CLASS
=
8
;
CLONE
=
9
;
CONST
=
10
;
CONTINUE
=
11
;
DECLARE
=
12
;
DEFAULT
=
13
;
DIE
=
14
;
DO
=
15
;
ECHO
=
16
;
ELSE
=
17
;
ELSEIF
=
18
;
EMPTY
=
19
;
ENDDECLARE
=
20
;
ENDFOR
=
21
;
ENDFOREACH
=
22
;
ENDIF
=
23
;
ENDSWITCH
=
24
;
ENDWHILE
=
25
;
EVAL
=
26
;
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
;
}
php/tests/proto/test_reserved_message_lower.proto
0 → 100644
View file @
5dd818cd
syntax
=
"proto3"
;
package
lower
;
message
abstract
{}
message
and
{}
message
array
{}
message
as
{}
message
break
{}
message
callable
{}
message
case
{}
message
catch
{}
message
class
{}
message
clone
{}
message
const
{}
message
continue
{}
message
declare
{}
message
default
{}
message
die
{}
message
do
{}
message
echo
{}
message
else
{}
message
elseif
{}
message
empty
{}
message
enddeclare
{}
message
endfor
{}
message
endforeach
{}
message
endif
{}
message
endswitch
{}
message
endwhile
{}
message
eval
{}
message
exit
{}
message
extends
{}
message
final
{}
message
for
{}
message
foreach
{}
message
function
{}
message
global
{}
message
goto
{}
message
if
{}
message
implements
{}
message
include
{}
message
include_once
{}
message
instanceof
{}
message
insteadof
{}
message
interface
{}
message
isset
{}
message
list
{}
message
namespace
{}
message
new
{}
message
or
{}
message
print
{}
message
private
{}
message
protected
{}
message
public
{}
message
require
{}
message
require_once
{}
message
return
{}
message
static
{}
message
switch
{}
message
throw
{}
message
trait
{}
message
try
{}
message
unset
{}
message
use
{}
message
var
{}
message
while
{}
message
xor
{}
message
int
{}
message
float
{}
message
bool
{}
message
string
{}
message
true
{}
message
false
{}
message
null
{}
message
void
{}
message
iterable
{}
php/tests/proto/test_reserved_message_upper.proto
0 → 100644
View file @
5dd818cd
syntax
=
"proto3"
;
package
upper
;
message
ABSTRACT
{}
message
AND
{}
message
ARRAY
{}
message
AS
{}
message
BREAK
{}
message
CALLABLE
{}
message
CASE
{}
message
CATCH
{}
message
CLASS
{}
message
CLONE
{}
message
CONST
{}
message
CONTINUE
{}
message
DECLARE
{}
message
DEFAULT
{}
message
DIE
{}
message
DO
{}
message
ECHO
{}
message
ELSE
{}
message
ELSEIF
{}
message
EMPTY
{}
message
ENDDECLARE
{}
message
ENDFOR
{}
message
ENDFOREACH
{}
message
ENDIF
{}
message
ENDSWITCH
{}
message
ENDWHILE
{}
message
EVAL
{}
message
EXIT
{}
message
EXTENDS
{}
message
FINAL
{}
message
FOR
{}
message
FOREACH
{}
message
FUNCTION
{}
message
GLOBAL
{}
message
GOTO
{}
message
IF
{}
message
IMPLEMENTS
{}
message
INCLUDE
{}
message
INCLUDE_ONCE
{}
message
INSTANCEOF
{}
message
INSTEADOF
{}
message
INTERFACE
{}
message
ISSET
{}
message
LIST
{}
message
NAMESPACE
{}
message
NEW
{}
message
OR
{}
message
PRINT
{}
message
PRIVATE
{}
message
PROTECTED
{}
message
PUBLIC
{}
message
REQUIRE
{}
message
REQUIRE_ONCE
{}
message
RETURN
{}
message
STATIC
{}
message
SWITCH
{}
message
THROW
{}
message
TRAIT
{}
message
TRY
{}
message
UNSET
{}
message
USE
{}
message
VAR
{}
message
WHILE
{}
message
XOR
{}
message
INT
{}
message
FLOAT
{}
message
BOOL
{}
message
STRING
{}
message
TRUE
{}
message
FALSE
{}
message
NULL
{}
message
VOID
{}
message
ITERABLE
{}
src/google/protobuf/compiler/php/php_generator.cc
View file @
5dd818cd
...
...
@@ -49,8 +49,28 @@ const std::string kDescriptorMetadataFile =
"GPBMetadata/Google/Protobuf/Internal/Descriptor.php"
;
const
std
::
string
kDescriptorDirName
=
"Google/Protobuf/Internal"
;
const
std
::
string
kDescriptorPackageName
=
"Google
\\
Protobuf
\\
Internal"
;
const
char
*
const
kReservedNames
[]
=
{
"ARRAY"
,
"Empty"
,
"ECHO"
};
const
int
kReservedNamesSize
=
3
;
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"
};
const
char
*
const
kValidConstantNames
[]
=
{
"int"
,
"float"
,
"bool"
,
"string"
,
"true"
,
"false"
,
"null"
,
"void"
,
"iterable"
,
};
const
int
kReservedNamesSize
=
73
;
const
int
kValidConstantNamesSize
=
9
;
const
int
kFieldSetter
=
1
;
const
int
kFieldGetter
=
2
;
const
int
kFieldProperty
=
3
;
...
...
@@ -125,8 +145,11 @@ std::string ClassNamePrefix(const string& classname,
bool
is_reserved
=
false
;
string
lower
=
classname
;
transform
(
lower
.
begin
(),
lower
.
end
(),
lower
.
begin
(),
::
tolower
);
for
(
int
i
=
0
;
i
<
kReservedNamesSize
;
i
++
)
{
if
(
classname
==
kReservedNames
[
i
])
{
if
(
lower
==
kReservedNames
[
i
])
{
is_reserved
=
true
;
break
;
}
...
...
@@ -143,6 +166,33 @@ std::string ClassNamePrefix(const string& classname,
return
""
;
}
std
::
string
ConstantNamePrefix
(
const
string
&
classname
)
{
bool
is_reserved
=
false
;
string
lower
=
classname
;
transform
(
lower
.
begin
(),
lower
.
end
(),
lower
.
begin
(),
::
tolower
);
for
(
int
i
=
0
;
i
<
kReservedNamesSize
;
i
++
)
{
if
(
lower
==
kReservedNames
[
i
])
{
is_reserved
=
true
;
break
;
}
}
for
(
int
i
=
0
;
i
<
kValidConstantNamesSize
;
i
++
)
{
if
(
lower
==
kValidConstantNames
[
i
])
{
is_reserved
=
false
;
break
;
}
}
if
(
is_reserved
)
{
return
"PB"
;
}
return
""
;
}
template
<
typename
DescriptorType
>
std
::
string
NamespacedName
(
const
string
&
classname
,
const
DescriptorType
*
desc
,
bool
is_descriptor
)
{
...
...
@@ -678,7 +728,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) {
const
EnumValueDescriptor
*
value
=
en
->
value
(
i
);
printer
->
Print
(
"->value(
\"
^name^
\"
, ^number^)
\n
"
,
"name"
,
C
lassNamePrefix
(
value
->
name
(),
en
)
+
value
->
name
(),
"name"
,
C
onstantNamePrefix
(
value
->
name
()
)
+
value
->
name
(),
"number"
,
IntToString
(
value
->
number
()));
}
printer
->
Print
(
"->finalizeToPool();
\n\n
"
);
...
...
@@ -981,7 +1031,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
const
EnumValueDescriptor
*
value
=
en
->
value
(
i
);
GenerateEnumValueDocComment
(
&
printer
,
value
);
printer
.
Print
(
"const ^name^ = ^number^;
\n
"
,
"name"
,
C
lassNamePrefix
(
value
->
name
(),
en
)
+
value
->
name
(),
"name"
,
C
onstantNamePrefix
(
value
->
name
()
)
+
value
->
name
(),
"number"
,
IntToString
(
value
->
number
()));
}
...
...
tests.sh
View file @
5dd818cd
...
...
@@ -346,15 +346,21 @@ generate_php_test_proto() {
# Generate test file
rm
-rf
generated
mkdir
generated
../../src/protoc
--php_out
=
generated
\
proto/test.proto
\
proto/test_include.proto
\
proto/test_no_namespace.proto
\
proto/test_prefix.proto
\
proto/test_php_namespace.proto
\
proto/test_empty_php_namespace.proto
\
proto/test_service.proto
\
proto/test_service_namespace.proto
\
../../src/protoc
--php_out
=
generated
\
proto/test.proto
\
proto/test_include.proto
\
proto/test_no_namespace.proto
\
proto/test_prefix.proto
\
proto/test_php_namespace.proto
\
proto/test_empty_php_namespace.proto
\
proto/test_reserved_enum_lower.proto
\
proto/test_reserved_enum_upper.proto
\
proto/test_reserved_enum_value_lower.proto
\
proto/test_reserved_enum_value_upper.proto
\
proto/test_reserved_message_lower.proto
\
proto/test_reserved_message_upper.proto
\
proto/test_service.proto
\
proto/test_service_namespace.proto
\
proto/test_descriptors.proto
pushd
../../src
./protoc
--php_out
=
../php/tests/generated google/protobuf/empty.proto
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment