Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
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
flatbuffers
Commits
bafd48d9
Commit
bafd48d9
authored
Jun 08, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
into fuzzer2
parents
2bdf44a2
e92ae519
Show whitespace changes
Inline
Side-by-side
Showing
75 changed files
with
398 additions
and
313 deletions
+398
-313
code_generators.h
include/flatbuffers/code_generators.h
+56
-3
flatbuffers.h
include/flatbuffers/flatbuffers.h
+41
-1
idl_gen_cpp.cpp
src/idl_gen_cpp.cpp
+17
-19
idl_gen_general.cpp
src/idl_gen_general.cpp
+35
-74
idl_gen_go.cpp
src/idl_gen_go.cpp
+28
-42
idl_gen_js.cpp
src/idl_gen_js.cpp
+4
-8
idl_gen_php.cpp
src/idl_gen_php.cpp
+33
-51
idl_gen_python.cpp
src/idl_gen_python.cpp
+34
-45
idl_parser.cpp
src/idl_parser.cpp
+45
-5
Any.cs
tests/MyGame/Example/Any.cs
+1
-1
Any.go
tests/MyGame/Example/Any.go
+1
-1
Any.java
tests/MyGame/Example/Any.java
+1
-1
Any.php
tests/MyGame/Example/Any.php
+1
-1
Any.py
tests/MyGame/Example/Any.py
+1
-1
Color.cs
tests/MyGame/Example/Color.cs
+1
-1
Color.go
tests/MyGame/Example/Color.go
+1
-1
Color.java
tests/MyGame/Example/Color.java
+1
-1
Color.php
tests/MyGame/Example/Color.php
+1
-1
Color.py
tests/MyGame/Example/Color.py
+1
-1
Monster.cs
tests/MyGame/Example/Monster.cs
+1
-1
Monster.go
tests/MyGame/Example/Monster.go
+1
-1
Monster.java
tests/MyGame/Example/Monster.java
+1
-1
Monster.php
tests/MyGame/Example/Monster.php
+1
-1
Monster.py
tests/MyGame/Example/Monster.py
+1
-1
Stat.cs
tests/MyGame/Example/Stat.cs
+1
-1
Stat.go
tests/MyGame/Example/Stat.go
+1
-1
Stat.java
tests/MyGame/Example/Stat.java
+1
-1
Stat.php
tests/MyGame/Example/Stat.php
+1
-1
Stat.py
tests/MyGame/Example/Stat.py
+1
-1
Test.cs
tests/MyGame/Example/Test.cs
+1
-1
Test.go
tests/MyGame/Example/Test.go
+1
-1
Test.java
tests/MyGame/Example/Test.java
+1
-1
Test.php
tests/MyGame/Example/Test.php
+1
-1
Test.py
tests/MyGame/Example/Test.py
+1
-1
TestSimpleTableWithEnum.cs
tests/MyGame/Example/TestSimpleTableWithEnum.cs
+1
-1
TestSimpleTableWithEnum.go
tests/MyGame/Example/TestSimpleTableWithEnum.go
+1
-1
TestSimpleTableWithEnum.java
tests/MyGame/Example/TestSimpleTableWithEnum.java
+1
-1
TestSimpleTableWithEnum.php
tests/MyGame/Example/TestSimpleTableWithEnum.php
+1
-1
TestSimpleTableWithEnum.py
tests/MyGame/Example/TestSimpleTableWithEnum.py
+1
-1
Vec3.cs
tests/MyGame/Example/Vec3.cs
+1
-1
Vec3.go
tests/MyGame/Example/Vec3.go
+1
-1
Vec3.java
tests/MyGame/Example/Vec3.java
+1
-1
Vec3.php
tests/MyGame/Example/Vec3.php
+1
-1
Vec3.py
tests/MyGame/Example/Vec3.py
+1
-1
EnumInNestedNS.cs
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.cs
+1
-1
EnumInNestedNS.go
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.go
+1
-1
EnumInNestedNS.java
.../namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
+1
-1
EnumInNestedNS.php
...s/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php
+1
-1
EnumInNestedNS.py
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
+1
-1
StructInNestedNS.cs
.../namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
+1
-1
StructInNestedNS.go
.../namespace_test/NamespaceA/NamespaceB/StructInNestedNS.go
+1
-1
StructInNestedNS.java
...amespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
+1
-1
StructInNestedNS.php
...namespace_test/NamespaceA/NamespaceB/StructInNestedNS.php
+1
-1
StructInNestedNS.py
.../namespace_test/NamespaceA/NamespaceB/StructInNestedNS.py
+1
-1
TableInNestedNS.cs
...s/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
+1
-1
TableInNestedNS.go
...s/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.go
+1
-1
TableInNestedNS.java
...namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
+1
-1
TableInNestedNS.php
.../namespace_test/NamespaceA/NamespaceB/TableInNestedNS.php
+1
-1
TableInNestedNS.py
...s/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
+1
-1
SecondTableInA.cs
tests/namespace_test/NamespaceA/SecondTableInA.cs
+1
-1
SecondTableInA.go
tests/namespace_test/NamespaceA/SecondTableInA.go
+1
-1
SecondTableInA.java
tests/namespace_test/NamespaceA/SecondTableInA.java
+1
-1
SecondTableInA.php
tests/namespace_test/NamespaceA/SecondTableInA.php
+1
-1
SecondTableInA.py
tests/namespace_test/NamespaceA/SecondTableInA.py
+1
-1
TableInC.cs
tests/namespace_test/NamespaceA/TableInC.cs
+1
-1
TableInC.go
tests/namespace_test/NamespaceA/TableInC.go
+1
-1
TableInC.java
tests/namespace_test/NamespaceA/TableInC.java
+1
-1
TableInC.php
tests/namespace_test/NamespaceA/TableInC.php
+1
-1
TableInC.py
tests/namespace_test/NamespaceA/TableInC.py
+1
-1
TableInFirstNS.cs
tests/namespace_test/NamespaceA/TableInFirstNS.cs
+1
-1
TableInFirstNS.go
tests/namespace_test/NamespaceA/TableInFirstNS.go
+1
-1
TableInFirstNS.java
tests/namespace_test/NamespaceA/TableInFirstNS.java
+1
-1
TableInFirstNS.php
tests/namespace_test/NamespaceA/TableInFirstNS.php
+1
-1
TableInFirstNS.py
tests/namespace_test/NamespaceA/TableInFirstNS.py
+1
-1
test.cpp
tests/test.cpp
+40
-0
No files found.
include/flatbuffers/code_generators.h
View file @
bafd48d9
...
@@ -21,17 +21,70 @@ namespace flatbuffers {
...
@@ -21,17 +21,70 @@ namespace flatbuffers {
class
BaseGenerator
{
class
BaseGenerator
{
public
:
public
:
BaseGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
:
parser_
(
parser
),
path_
(
path
),
file_name_
(
file_name
){};
virtual
bool
generate
()
=
0
;
virtual
bool
generate
()
=
0
;
static
const
std
::
string
NamespaceDir
(
const
Parser
&
parser
,
const
std
::
string
&
path
)
{
EnsureDirExists
(
path
.
c_str
());
if
(
parser
.
opts
.
one_file
)
return
path
;
std
::
string
namespace_dir
=
path
;
// Either empty or ends in separator.
auto
&
namespaces
=
parser
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
namespace_dir
+=
*
it
+
kPathSeparator
;
EnsureDirExists
(
namespace_dir
.
c_str
());
}
return
namespace_dir
;
}
protected
:
protected
:
BaseGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
:
parser_
(
parser
),
path_
(
path
),
file_name_
(
file_name
),
namespace_dir_
(
BaseGenerator
::
NamespaceDir
(
parser
,
path
)){};
virtual
~
BaseGenerator
(){};
virtual
~
BaseGenerator
(){};
// No copy/assign.
BaseGenerator
&
operator
=
(
const
BaseGenerator
&
);
BaseGenerator
(
const
BaseGenerator
&
);
const
char
*
FlatBuffersGeneratedWarning
()
{
return
"automatically generated by the FlatBuffers compiler,"
" do not modify
\n\n
"
;
}
bool
IsEverythingGenerated
()
{
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
++
it
)
{
if
(
!
(
*
it
)
->
generated
)
return
false
;
}
for
(
auto
it
=
parser_
.
structs_
.
vec
.
begin
();
it
!=
parser_
.
structs_
.
vec
.
end
();
++
it
)
{
if
(
!
(
*
it
)
->
generated
)
return
false
;
}
return
true
;
}
std
::
string
FullNamespace
(
const
char
*
separator
)
{
std
::
string
namespace_name
;
auto
&
namespaces
=
parser_
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
namespace_name
.
length
())
namespace_name
+=
separator
;
namespace_name
+=
*
it
;
}
return
namespace_name
;
}
const
std
::
string
LastNamespacePart
()
{
auto
&
namespaces
=
parser_
.
namespaces_
.
back
()
->
components
;
if
(
namespaces
.
size
())
return
*
(
namespaces
.
end
()
-
1
);
else
return
std
::
string
(
""
);
}
const
Parser
&
parser_
;
const
Parser
&
parser_
;
const
std
::
string
&
path_
;
const
std
::
string
&
path_
;
const
std
::
string
&
file_name_
;
const
std
::
string
&
file_name_
;
const
std
::
string
namespace_dir_
;
};
};
}
// namespace flatbuffers
}
// namespace flatbuffers
...
...
include/flatbuffers/flatbuffers.h
View file @
bafd48d9
...
@@ -337,7 +337,7 @@ public:
...
@@ -337,7 +337,7 @@ public:
// Change elements if you have a non-const pointer to this object.
// Change elements if you have a non-const pointer to this object.
// Scalars only. See reflection.h, and the documentation.
// Scalars only. See reflection.h, and the documentation.
void
Mutate
(
uoffset_t
i
,
T
val
)
{
void
Mutate
(
uoffset_t
i
,
const
T
&
val
)
{
assert
(
i
<
size
());
assert
(
i
<
size
());
WriteScalar
(
data
()
+
i
,
val
);
WriteScalar
(
data
()
+
i
,
val
);
}
}
...
@@ -1161,6 +1161,17 @@ template<typename T> const T *GetRoot(const void *buf) {
...
@@ -1161,6 +1161,17 @@ template<typename T> const T *GetRoot(const void *buf) {
return
GetMutableRoot
<
T
>
(
const_cast
<
void
*>
(
buf
));
return
GetMutableRoot
<
T
>
(
const_cast
<
void
*>
(
buf
));
}
}
/// Helpers to get a typed pointer to objects that are currently beeing built.
/// @warning Creating new objects will lead to reallocations and invalidates the pointer!
template
<
typename
T
>
T
*
GetMutableTemporaryPointer
(
FlatBufferBuilder
&
fbb
,
Offset
<
T
>
offset
)
{
return
reinterpret_cast
<
T
*>
(
fbb
.
GetCurrentBufferPointer
()
+
fbb
.
GetSize
()
-
offset
.
o
);
}
template
<
typename
T
>
const
T
*
GetTemporaryPointer
(
FlatBufferBuilder
&
fbb
,
Offset
<
T
>
offset
)
{
return
GetMutableTemporaryPointer
<
T
>
(
fbb
,
offset
);
}
// Helper to see if the identifier in a buffer has the expected value.
// Helper to see if the identifier in a buffer has the expected value.
inline
bool
BufferHasIdentifier
(
const
void
*
buf
,
const
char
*
identifier
)
{
inline
bool
BufferHasIdentifier
(
const
void
*
buf
,
const
char
*
identifier
)
{
return
strncmp
(
reinterpret_cast
<
const
char
*>
(
buf
)
+
sizeof
(
uoffset_t
),
return
strncmp
(
reinterpret_cast
<
const
char
*>
(
buf
)
+
sizeof
(
uoffset_t
),
...
@@ -1495,6 +1506,35 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
...
@@ -1495,6 +1506,35 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
#define DEFINE_BITMASK_OPERATORS(E, T)\
inline E operator | (E lhs, E rhs){\
return E(T(lhs) | T(rhs));\
}\
inline E operator & (E lhs, E rhs){\
return E(T(lhs) & T(rhs));\
}\
inline E operator ^ (E lhs, E rhs){\
return E(T(lhs) ^ T(rhs));\
}\
inline E operator ~ (E lhs){\
return E(~T(lhs));\
}\
inline E operator |= (E &lhs, E rhs){\
lhs = lhs | rhs;\
return lhs;\
}\
inline E operator &= (E &lhs, E rhs){\
lhs = lhs & rhs;\
return lhs;\
}\
inline E operator ^= (E &lhs, E rhs){\
lhs = lhs ^ rhs;\
return lhs;\
}\
inline bool operator !(E rhs) \
{\
return !bool(T(rhs)); \
}
/// @endcond
/// @endcond
}
// namespace flatbuffers
}
// namespace flatbuffers
...
...
src/idl_gen_cpp.cpp
View file @
bafd48d9
...
@@ -166,6 +166,7 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
...
@@ -166,6 +166,7 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
if
(
parser
.
opts
.
scoped_enums
)
if
(
parser
.
opts
.
scoped_enums
)
code
+=
" : "
+
GenTypeBasic
(
enum_def
.
underlying_type
,
false
);
code
+=
" : "
+
GenTypeBasic
(
enum_def
.
underlying_type
,
false
);
code
+=
" {
\n
"
;
code
+=
" {
\n
"
;
int64_t
anyv
=
0
;
EnumVal
*
minv
=
nullptr
,
*
maxv
=
nullptr
;
EnumVal
*
minv
=
nullptr
,
*
maxv
=
nullptr
;
for
(
auto
it
=
enum_def
.
vals
.
vec
.
begin
();
for
(
auto
it
=
enum_def
.
vals
.
vec
.
begin
();
it
!=
enum_def
.
vals
.
vec
.
end
();
it
!=
enum_def
.
vals
.
vec
.
end
();
...
@@ -176,13 +177,26 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
...
@@ -176,13 +177,26 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
code
+=
NumToString
(
ev
.
value
)
+
",
\n
"
;
code
+=
NumToString
(
ev
.
value
)
+
",
\n
"
;
minv
=
!
minv
||
minv
->
value
>
ev
.
value
?
&
ev
:
minv
;
minv
=
!
minv
||
minv
->
value
>
ev
.
value
?
&
ev
:
minv
;
maxv
=
!
maxv
||
maxv
->
value
<
ev
.
value
?
&
ev
:
maxv
;
maxv
=
!
maxv
||
maxv
->
value
<
ev
.
value
?
&
ev
:
maxv
;
anyv
|=
ev
.
value
;
}
}
if
(
parser
.
opts
.
scoped_enums
||
parser
.
opts
.
prefixed_enums
)
{
assert
(
minv
&&
maxv
);
assert
(
minv
&&
maxv
);
if
(
enum_def
.
attributes
.
Lookup
(
"bit_flags"
))
{
if
(
minv
->
value
!=
0
)
// If the user didn't defined NONE value
code
+=
" "
+
GenEnumVal
(
enum_def
,
"NONE"
,
parser
.
opts
)
+
" = 0,
\n
"
;
if
(
maxv
->
value
!=
anyv
)
// If the user didn't defined ANY value
code
+=
" "
+
GenEnumVal
(
enum_def
,
"ANY"
,
parser
.
opts
)
+
" = "
+
NumToString
(
anyv
)
+
"
\n
"
;
}
else
{
// MIN & MAX are useless for bit_flags
code
+=
" "
+
GenEnumVal
(
enum_def
,
"MIN"
,
parser
.
opts
)
+
" = "
;
code
+=
" "
+
GenEnumVal
(
enum_def
,
"MIN"
,
parser
.
opts
)
+
" = "
;
code
+=
GenEnumVal
(
enum_def
,
minv
->
name
,
parser
.
opts
)
+
",
\n
"
;
code
+=
GenEnumVal
(
enum_def
,
minv
->
name
,
parser
.
opts
)
+
",
\n
"
;
code
+=
" "
+
GenEnumVal
(
enum_def
,
"MAX"
,
parser
.
opts
)
+
" = "
;
code
+=
" "
+
GenEnumVal
(
enum_def
,
"MAX"
,
parser
.
opts
)
+
" = "
;
code
+=
GenEnumVal
(
enum_def
,
maxv
->
name
,
parser
.
opts
)
+
"
\n
"
;
code
+=
GenEnumVal
(
enum_def
,
maxv
->
name
,
parser
.
opts
)
+
"
\n
"
;
code
+=
"};
\n\n
"
;
}
}
code
+=
"};
\n
"
;
if
(
parser
.
opts
.
scoped_enums
&&
enum_def
.
attributes
.
Lookup
(
"bit_flags"
))
code
+=
"DEFINE_BITMASK_OPERATORS("
+
enum_def
.
name
+
", "
+
GenTypeBasic
(
enum_def
.
underlying_type
,
false
)
+
")
\n
"
;
code
+=
"
\n
"
;
// Generate a generate string table for enum values.
// Generate a generate string table for enum values.
// Problem is, if values are very sparse that could generate really big
// Problem is, if values are very sparse that could generate really big
...
@@ -730,26 +744,10 @@ class CppGenerator : public BaseGenerator {
...
@@ -730,26 +744,10 @@ class CppGenerator : public BaseGenerator {
// structs,
// structs,
// and tables) and output them to a single file.
// and tables) and output them to a single file.
bool
generate
()
{
bool
generate
()
{
// Check if we have any code to generate at all, to avoid an empty header.
if
(
IsEverythingGenerated
())
return
true
;
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
++
it
)
{
if
(
!
(
*
it
)
->
generated
)
goto
generate_code
;
}
for
(
auto
it
=
parser_
.
structs_
.
vec
.
begin
();
it
!=
parser_
.
structs_
.
vec
.
end
();
++
it
)
{
if
(
!
(
*
it
)
->
generated
)
goto
generate_code
;
}
// No code to generate, exit:
return
true
;
generate_code:
using
namespace
cpp
;
std
::
string
code
;
std
::
string
code
;
code
=
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
"// automatically generated by the FlatBuffers compiler,"
" do not modify
\n\n
"
;
// Generate include guard.
// Generate include guard.
std
::
string
include_guard_ident
=
file_name_
;
std
::
string
include_guard_ident
=
file_name_
;
...
...
src/idl_gen_general.cpp
View file @
bafd48d9
...
@@ -1115,40 +1115,6 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -1115,40 +1115,6 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code
+=
"};
\n\n
"
;
code
+=
"};
\n\n
"
;
}
}
// Save out the generated code for a single class while adding
// declaration boilerplate.
static
bool
SaveClass
(
const
LanguageParameters
&
lang
,
const
Parser
&
parser
,
const
std
::
string
&
defname
,
const
std
::
string
&
classcode
,
const
std
::
string
&
path
,
bool
needs_includes
,
bool
onefile
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
namespace_general
;
std
::
string
namespace_dir
=
path
;
// Either empty or ends in separator.
auto
&
namespaces
=
parser
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
namespace_general
.
length
())
{
namespace_general
+=
"."
;
}
namespace_general
+=
*
it
;
if
(
!
onefile
)
{
namespace_dir
+=
*
it
+
kPathSeparator
;
}
}
EnsureDirExists
(
namespace_dir
);
std
::
string
code
=
"// automatically generated, do not modify
\n\n
"
;
if
(
!
namespace_general
.
empty
())
{
code
+=
lang
.
namespace_ident
+
namespace_general
+
lang
.
namespace_begin
;
code
+=
"
\n\n
"
;
}
if
(
needs_includes
)
code
+=
lang
.
includes
;
code
+=
classcode
;
if
(
!
namespace_general
.
empty
())
code
+=
lang
.
namespace_end
;
auto
filename
=
namespace_dir
+
defname
+
lang
.
file_extension
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
namespace
general
{
namespace
general
{
class
GeneralGenerator
:
public
BaseGenerator
{
class
GeneralGenerator
:
public
BaseGenerator
{
public
:
public
:
...
@@ -1167,9 +1133,7 @@ class GeneralGenerator : public BaseGenerator {
...
@@ -1167,9 +1133,7 @@ class GeneralGenerator : public BaseGenerator {
if
(
parser_
.
opts
.
one_file
)
{
if
(
parser_
.
opts
.
one_file
)
{
one_file_code
+=
enumcode
;
one_file_code
+=
enumcode
;
}
else
{
}
else
{
if
(
!
SaveClass
(
lang
,
parser_
,
(
**
it
).
name
,
enumcode
,
path_
,
false
,
if
(
!
SaveType
(
lang
,
(
**
it
).
name
,
enumcode
,
false
))
return
false
;
false
))
return
false
;
}
}
}
}
...
@@ -1180,18 +1144,35 @@ class GeneralGenerator : public BaseGenerator {
...
@@ -1180,18 +1144,35 @@ class GeneralGenerator : public BaseGenerator {
if
(
parser_
.
opts
.
one_file
)
{
if
(
parser_
.
opts
.
one_file
)
{
one_file_code
+=
declcode
;
one_file_code
+=
declcode
;
}
else
{
}
else
{
if
(
!
SaveClass
(
lang
,
parser_
,
(
**
it
).
name
,
declcode
,
path_
,
true
,
if
(
!
SaveType
(
lang
,
(
**
it
).
name
,
declcode
,
true
))
return
false
;
false
))
return
false
;
}
}
}
}
if
(
parser_
.
opts
.
one_file
)
{
if
(
parser_
.
opts
.
one_file
)
{
return
SaveClass
(
lang
,
parser_
,
file_name_
,
one_file_code
,
path_
,
true
,
return
SaveType
(
lang
,
file_name_
,
one_file_code
,
true
);
true
);
}
}
return
true
;
return
true
;
}
}
// Save out the generated code for a single class while adding
// declaration boilerplate.
bool
SaveType
(
const
LanguageParameters
&
lang
,
const
std
::
string
&
defname
,
const
std
::
string
&
classcode
,
bool
needs_includes
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
code
;
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
std
::
string
namespace_name
=
FullNamespace
(
"."
);
if
(
!
namespace_name
.
empty
())
{
code
+=
lang
.
namespace_ident
+
namespace_name
+
lang
.
namespace_begin
;
code
+=
"
\n\n
"
;
}
if
(
needs_includes
)
code
+=
lang
.
includes
;
code
+=
classcode
;
if
(
!
namespace_name
.
empty
())
code
+=
lang
.
namespace_end
;
auto
filename
=
namespace_dir_
+
defname
+
lang
.
file_extension
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
};
};
}
// namespace general
}
// namespace general
...
@@ -1201,50 +1182,30 @@ bool GenerateGeneral(const Parser &parser, const std::string &path,
...
@@ -1201,50 +1182,30 @@ bool GenerateGeneral(const Parser &parser, const std::string &path,
return
generator
.
generate
();
return
generator
.
generate
();
}
}
static
std
::
string
ClassFileName
(
const
LanguageParameters
&
lang
,
std
::
string
GeneralMakeRule
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
Parser
&
parser
,
const
Definition
&
def
,
const
std
::
string
&
path
)
{
std
::
string
namespace_general
;
std
::
string
namespace_dir
=
path
;
auto
&
namespaces
=
parser
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
namespace_general
.
length
())
{
namespace_general
+=
"."
;
namespace_dir
+=
kPathSeparator
;
}
namespace_general
+=
*
it
;
namespace_dir
+=
*
it
;
}
return
namespace_dir
+
kPathSeparator
+
def
.
name
+
lang
.
file_extension
;
}
std
::
string
GeneralMakeRule
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
{
const
std
::
string
&
file_name
)
{
assert
(
parser
.
opts
.
lang
<=
IDLOptions
::
kMAX
);
assert
(
parser
.
opts
.
lang
<=
IDLOptions
::
kMAX
);
auto
lang
=
language_parameters
[
parser
.
opts
.
lang
];
auto
lang
=
language_parameters
[
parser
.
opts
.
lang
];
std
::
string
make_rule
;
std
::
string
make_rule
;
std
::
string
directory
=
BaseGenerator
::
NamespaceDir
(
parser
,
path
)
+
kPathSeparator
;
for
(
auto
it
=
parser
.
enums_
.
vec
.
begin
();
for
(
auto
it
=
parser
.
enums_
.
vec
.
begin
();
it
!=
parser
.
enums_
.
vec
.
end
();
it
!=
parser
.
enums_
.
vec
.
end
();
++
it
)
{
++
it
)
{
if
(
make_rule
!=
""
)
if
(
make_rule
!=
""
)
make_rule
+=
" "
;
make_rule
+=
" "
;
make_rule
+=
directory
+
(
**
it
).
name
+
lang
.
file_extension
;
make_rule
+=
ClassFileName
(
lang
,
parser
,
**
it
,
path
);
}
}
for
(
auto
it
=
parser
.
structs_
.
vec
.
begin
();
for
(
auto
it
=
parser
.
structs_
.
vec
.
begin
();
it
!=
parser
.
structs_
.
vec
.
end
();
it
!=
parser
.
structs_
.
vec
.
end
();
++
it
)
{
++
it
)
{
if
(
make_rule
!=
""
)
if
(
make_rule
!=
""
)
make_rule
+=
" "
;
make_rule
+=
" "
;
make_rule
+=
directory
+
(
**
it
).
name
+
lang
.
file_extension
;
make_rule
+=
ClassFileName
(
lang
,
parser
,
**
it
,
path
);
}
}
make_rule
+=
": "
;
make_rule
+=
": "
;
auto
included_files
=
parser
.
GetIncludedFilesRecursive
(
file_name
);
auto
included_files
=
parser
.
GetIncludedFilesRecursive
(
file_name
);
for
(
auto
it
=
included_files
.
begin
();
for
(
auto
it
=
included_files
.
begin
();
it
!=
included_files
.
end
();
++
it
)
{
it
!=
included_files
.
end
();
++
it
)
{
make_rule
+=
" "
+
*
it
;
make_rule
+=
" "
+
*
it
;
}
}
return
make_rule
;
return
make_rule
;
...
...
src/idl_gen_go.cpp
View file @
bafd48d9
...
@@ -53,20 +53,6 @@ std::string OffsetPrefix(const FieldDef &field) {
...
@@ -53,20 +53,6 @@ std::string OffsetPrefix(const FieldDef &field) {
"))
\n\t
if o != 0 {
\n
"
;
"))
\n\t
if o != 0 {
\n
"
;
}
}
// Begin by declaring namespace and imports.
static
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"// automatically generated, do not modify
\n\n
"
;
code
+=
"package "
+
name_space_name
+
"
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"import (
\n
"
;
code
+=
"
\t
flatbuffers
\"
github.com/google/flatbuffers/go
\"\n
"
;
code
+=
")
\n
"
;
}
}
// Begin a class declaration.
// Begin a class declaration.
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
std
::
string
&
code
=
*
code_ptr
;
...
@@ -589,32 +575,6 @@ static std::string GenMethod(const FieldDef &field) {
...
@@ -589,32 +575,6 @@ static std::string GenMethod(const FieldDef &field) {
:
(
IsStruct
(
field
.
value
.
type
)
?
"Struct"
:
"UOffsetT"
);
:
(
IsStruct
(
field
.
value
.
type
)
?
"Struct"
:
"UOffsetT"
);
}
}
// Save out the generated code for a Go Table type.
static
bool
SaveType
(
const
Parser
&
parser
,
const
Definition
&
def
,
const
std
::
string
&
classcode
,
const
std
::
string
&
path
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
namespace_name
;
std
::
string
namespace_dir
=
path
;
// Either empty or ends in separator.
auto
&
namespaces
=
parser
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
namespace_name
.
length
())
{
namespace_name
+=
"."
;
}
namespace_name
=
*
it
;
namespace_dir
+=
*
it
+
kPathSeparator
;
}
EnsureDirExists
(
namespace_dir
);
std
::
string
code
=
""
;
BeginFile
(
namespace_name
,
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
namespace_dir
+
def
.
name
+
".go"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
static
std
::
string
GenTypeBasic
(
const
Type
&
type
)
{
static
std
::
string
GenTypeBasic
(
const
Type
&
type
)
{
static
const
char
*
ctypename
[]
=
{
static
const
char
*
ctypename
[]
=
{
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
...
@@ -671,18 +631,44 @@ class GoGenerator : public BaseGenerator {
...
@@ -671,18 +631,44 @@ class GoGenerator : public BaseGenerator {
++
it
)
{
++
it
)
{
std
::
string
enumcode
;
std
::
string
enumcode
;
go
::
GenEnum
(
**
it
,
&
enumcode
);
go
::
GenEnum
(
**
it
,
&
enumcode
);
if
(
!
go
::
SaveType
(
parser_
,
**
it
,
enumcode
,
path_
,
false
))
return
false
;
if
(
!
SaveType
(
**
it
,
enumcode
,
false
))
return
false
;
}
}
for
(
auto
it
=
parser_
.
structs_
.
vec
.
begin
();
for
(
auto
it
=
parser_
.
structs_
.
vec
.
begin
();
it
!=
parser_
.
structs_
.
vec
.
end
();
++
it
)
{
it
!=
parser_
.
structs_
.
vec
.
end
();
++
it
)
{
std
::
string
declcode
;
std
::
string
declcode
;
go
::
GenStruct
(
**
it
,
&
declcode
,
parser_
.
root_struct_def_
);
go
::
GenStruct
(
**
it
,
&
declcode
,
parser_
.
root_struct_def_
);
if
(
!
go
::
SaveType
(
parser_
,
**
it
,
declcode
,
path_
,
true
))
return
false
;
if
(
!
SaveType
(
**
it
,
declcode
,
true
))
return
false
;
}
}
return
true
;
return
true
;
}
}
private
:
// Begin by declaring namespace and imports.
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
code
+=
"package "
+
name_space_name
+
"
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"import (
\n
"
;
code
+=
"
\t
flatbuffers
\"
github.com/google/flatbuffers/go
\"\n
"
;
code
+=
")
\n
"
;
}
}
// Save out the generated code for a Go Table type.
bool
SaveType
(
const
Definition
&
def
,
const
std
::
string
&
classcode
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
code
=
""
;
BeginFile
(
LastNamespacePart
(),
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
namespace_dir_
+
def
.
name
+
".go"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
};
};
}
// namespace go
}
// namespace go
...
...
src/idl_gen_js.cpp
View file @
bafd48d9
...
@@ -678,15 +678,13 @@ class JsGenerator : public BaseGenerator {
...
@@ -678,15 +678,13 @@ class JsGenerator : public BaseGenerator {
// Iterate through all definitions we haven't generate code for (enums,
// Iterate through all definitions we haven't generate code for (enums,
// structs, and tables) and output them to a single file.
// structs, and tables) and output them to a single file.
bool
generate
()
{
bool
generate
()
{
if
(
IsEverythingGenerated
())
return
true
;
std
::
string
enum_code
,
struct_code
,
exports_code
,
code
;
std
::
string
enum_code
,
struct_code
,
exports_code
,
code
;
generateEnums
(
&
enum_code
,
&
exports_code
);
generateEnums
(
&
enum_code
,
&
exports_code
);
generateStructs
(
&
struct_code
,
&
exports_code
);
generateStructs
(
&
struct_code
,
&
exports_code
);
// Only output file-level code if there were any declarations.
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
if
(
enum_code
.
length
()
||
struct_code
.
length
())
{
code
+=
"// automatically generated by the FlatBuffers compiler, do not "
"modify
\n\n
"
;
// Generate code for all the namespace declarations.
// Generate code for all the namespace declarations.
GenNamespaces
(
parser_
,
&
code
,
&
exports_code
);
GenNamespaces
(
parser_
,
&
code
,
&
exports_code
);
...
@@ -699,10 +697,8 @@ class JsGenerator : public BaseGenerator {
...
@@ -699,10 +697,8 @@ class JsGenerator : public BaseGenerator {
code
+=
"// Exports for Node.js and RequireJS
\n
"
;
code
+=
"// Exports for Node.js and RequireJS
\n
"
;
code
+=
exports_code
;
code
+=
exports_code
;
}
}
}
return
!
code
.
length
()
||
return
SaveFile
(
GeneratedFileName
(
path_
,
file_name_
).
c_str
(),
code
,
false
);
SaveFile
(
GeneratedFileName
(
path_
,
file_name_
).
c_str
(),
code
,
false
);
}
}
private
:
private
:
...
...
src/idl_gen_php.cpp
View file @
bafd48d9
...
@@ -54,24 +54,6 @@ namespace php {
...
@@ -54,24 +54,6 @@ namespace php {
// Hardcode spaces per indentation.
// Hardcode spaces per indentation.
const
std
::
string
Indent
=
" "
;
const
std
::
string
Indent
=
" "
;
// Begin by declaring namespace and imports.
static
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"<?php
\n
"
;
code
+=
"// automatically generated, do not modify
\n\n
"
;
code
+=
"namespace "
+
name_space_name
+
";
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Struct;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Table;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
ByteBuffer;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
FlatBufferBuilder;
\n
"
;
code
+=
"
\n
"
;
}
}
// Begin a class declaration.
// Begin a class declaration.
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
std
::
string
&
code
=
*
code_ptr
;
...
@@ -867,35 +849,6 @@ namespace php {
...
@@ -867,35 +849,6 @@ namespace php {
:
(
IsStruct
(
field
.
value
.
type
)
?
"Struct"
:
"Offset"
);
:
(
IsStruct
(
field
.
value
.
type
)
?
"Struct"
:
"Offset"
);
}
}
// Save out the generated code for a Php Table type.
static
bool
SaveType
(
const
Parser
&
parser
,
const
Definition
&
def
,
const
std
::
string
&
classcode
,
const
std
::
string
&
path
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
namespace_name
;
std
::
string
namespace_dir
=
path
;
auto
&
namespaces
=
parser
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
namespace_name
.
length
())
{
namespace_name
+=
"
\\
"
;
namespace_dir
+=
kPathSeparator
;
}
namespace_name
+=
*
it
;
namespace_dir
+=
*
it
;
EnsureDirExists
(
namespace_dir
.
c_str
());
}
std
::
string
code
=
""
;
BeginFile
(
namespace_name
,
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
namespace_dir
+
kPathSeparator
+
def
.
name
+
".php"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
static
std
::
string
GenTypeBasic
(
const
Type
&
type
)
{
static
std
::
string
GenTypeBasic
(
const
Type
&
type
)
{
static
const
char
*
ctypename
[]
=
{
static
const
char
*
ctypename
[]
=
{
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
...
@@ -993,8 +946,7 @@ namespace php {
...
@@ -993,8 +946,7 @@ namespace php {
auto
&
enum_def
=
**
it
;
auto
&
enum_def
=
**
it
;
std
::
string
enumcode
;
std
::
string
enumcode
;
GenEnum
(
enum_def
,
&
enumcode
);
GenEnum
(
enum_def
,
&
enumcode
);
if
(
!
SaveType
(
parser_
,
enum_def
,
enumcode
,
path_
,
false
))
if
(
!
SaveType
(
enum_def
,
enumcode
,
false
))
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
...
@@ -1005,11 +957,41 @@ namespace php {
...
@@ -1005,11 +957,41 @@ namespace php {
auto
&
struct_def
=
**
it
;
auto
&
struct_def
=
**
it
;
std
::
string
declcode
;
std
::
string
declcode
;
GenStruct
(
parser_
,
struct_def
,
&
declcode
);
GenStruct
(
parser_
,
struct_def
,
&
declcode
);
if
(
!
SaveType
(
parser_
,
struct_def
,
declcode
,
path_
,
true
))
if
(
!
SaveType
(
struct_def
,
declcode
,
true
))
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
// Begin by declaring namespace and imports.
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"<?php
\n
"
;
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
code
+=
"namespace "
+
name_space_name
+
";
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Struct;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Table;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
ByteBuffer;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
FlatBufferBuilder;
\n
"
;
code
+=
"
\n
"
;
}
}
// Save out the generated code for a Php Table type.
bool
SaveType
(
const
Definition
&
def
,
const
std
::
string
&
classcode
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
code
=
""
;
BeginFile
(
FullNamespace
(
"
\\
"
),
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
namespace_dir_
+
kPathSeparator
+
def
.
name
+
".php"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
};
};
}
// namespace php
}
// namespace php
...
...
src/idl_gen_python.cpp
View file @
bafd48d9
...
@@ -49,18 +49,6 @@ std::string OffsetPrefix(const FieldDef &field) {
...
@@ -49,18 +49,6 @@ std::string OffsetPrefix(const FieldDef &field) {
"))
\n
"
+
Indent
+
Indent
+
"if o != 0:
\n
"
;
"))
\n
"
+
Indent
+
Indent
+
"if o != 0:
\n
"
;
}
}
// Begin by declaring namespace and imports.
static
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"# automatically generated, do not modify
\n\n
"
;
code
+=
"# namespace: "
+
name_space_name
+
"
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"import flatbuffers
\n\n
"
;
}
}
// Begin a class declaration.
// Begin a class declaration.
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
std
::
string
&
code
=
*
code_ptr
;
...
@@ -558,37 +546,6 @@ static std::string GenMethod(const FieldDef &field) {
...
@@ -558,37 +546,6 @@ static std::string GenMethod(const FieldDef &field) {
:
(
IsStruct
(
field
.
value
.
type
)
?
"Struct"
:
"UOffsetTRelative"
);
:
(
IsStruct
(
field
.
value
.
type
)
?
"Struct"
:
"UOffsetTRelative"
);
}
}
// Save out the generated code for a Python Table type.
static
bool
SaveType
(
const
Parser
&
parser
,
const
Definition
&
def
,
const
std
::
string
&
classcode
,
const
std
::
string
&
path
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
namespace_name
;
std
::
string
namespace_dir
=
path
;
auto
&
namespaces
=
parser
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
namespace_name
.
length
())
{
namespace_name
+=
"."
;
namespace_dir
+=
kPathSeparator
;
}
namespace_name
=
*
it
;
namespace_dir
+=
*
it
;
EnsureDirExists
(
namespace_dir
.
c_str
());
std
::
string
init_py_filename
=
namespace_dir
+
"/__init__.py"
;
SaveFile
(
init_py_filename
.
c_str
(),
""
,
false
);
}
std
::
string
code
=
""
;
BeginFile
(
namespace_name
,
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
namespace_dir
+
kPathSeparator
+
def
.
name
+
".py"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
static
std
::
string
GenTypeBasic
(
const
Type
&
type
)
{
static
std
::
string
GenTypeBasic
(
const
Type
&
type
)
{
static
const
char
*
ctypename
[]
=
{
static
const
char
*
ctypename
[]
=
{
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
...
@@ -653,7 +610,7 @@ class PythonGenerator : public BaseGenerator {
...
@@ -653,7 +610,7 @@ class PythonGenerator : public BaseGenerator {
auto
&
enum_def
=
**
it
;
auto
&
enum_def
=
**
it
;
std
::
string
enumcode
;
std
::
string
enumcode
;
GenEnum
(
enum_def
,
&
enumcode
);
GenEnum
(
enum_def
,
&
enumcode
);
if
(
!
SaveType
(
parser_
,
enum_def
,
enumcode
,
path_
,
false
))
return
false
;
if
(
!
SaveType
(
enum_def
,
enumcode
,
false
))
return
false
;
}
}
return
true
;
return
true
;
}
}
...
@@ -664,10 +621,42 @@ class PythonGenerator : public BaseGenerator {
...
@@ -664,10 +621,42 @@ class PythonGenerator : public BaseGenerator {
auto
&
struct_def
=
**
it
;
auto
&
struct_def
=
**
it
;
std
::
string
declcode
;
std
::
string
declcode
;
GenStruct
(
struct_def
,
&
declcode
,
parser_
.
root_struct_def_
);
GenStruct
(
struct_def
,
&
declcode
,
parser_
.
root_struct_def_
);
if
(
!
SaveType
(
parser_
,
struct_def
,
declcode
,
path_
,
true
))
return
false
;
if
(
!
SaveType
(
struct_def
,
declcode
,
true
))
return
false
;
}
}
return
true
;
return
true
;
}
}
// Begin by declaring namespace and imports.
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
=
code
+
"# "
+
FlatBuffersGeneratedWarning
();
code
+=
"# namespace: "
+
name_space_name
+
"
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"import flatbuffers
\n\n
"
;
}
}
// Save out the generated code for a Python Table type.
bool
SaveType
(
const
Definition
&
def
,
const
std
::
string
&
classcode
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
namespace_dir
=
path_
;
auto
&
namespaces
=
parser_
.
namespaces_
.
back
()
->
components
;
for
(
auto
it
=
namespaces
.
begin
();
it
!=
namespaces
.
end
();
++
it
)
{
if
(
it
!=
namespaces
.
begin
())
namespace_dir
+=
kPathSeparator
;
namespace_dir
+=
*
it
;
std
::
string
init_py_filename
=
namespace_dir
+
"/__init__.py"
;
SaveFile
(
init_py_filename
.
c_str
(),
""
,
false
);
}
std
::
string
code
=
""
;
BeginFile
(
LastNamespacePart
(),
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
namespace_dir_
+
kPathSeparator
+
def
.
name
+
".py"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
};
};
}
// namespace python
}
// namespace python
...
...
src/idl_parser.cpp
View file @
bafd48d9
...
@@ -236,12 +236,19 @@ CheckedError Parser::Next() {
...
@@ -236,12 +236,19 @@ CheckedError Parser::Next() {
if
(
!
isdigit
(
static_cast
<
const
unsigned
char
>
(
*
cursor_
)))
return
NoError
();
if
(
!
isdigit
(
static_cast
<
const
unsigned
char
>
(
*
cursor_
)))
return
NoError
();
return
Error
(
"floating point constant can
\'
t start with
\"
.
\"
"
);
return
Error
(
"floating point constant can
\'
t start with
\"
.
\"
"
);
case
'\"'
:
case
'\"'
:
case
'\''
:
case
'\''
:
{
int
unicode_high_surrogate
=
-
1
;
while
(
*
cursor_
!=
c
)
{
while
(
*
cursor_
!=
c
)
{
if
(
*
cursor_
<
' '
&&
*
cursor_
>=
0
)
if
(
*
cursor_
<
' '
&&
*
cursor_
>=
0
)
return
Error
(
"illegal character in string constant"
);
return
Error
(
"illegal character in string constant"
);
if
(
*
cursor_
==
'\\'
)
{
if
(
*
cursor_
==
'\\'
)
{
cursor_
++
;
cursor_
++
;
if
(
unicode_high_surrogate
!=
-
1
&&
*
cursor_
!=
'u'
)
{
return
Error
(
"illegal Unicode sequence (unpaired high surrogate)"
);
}
switch
(
*
cursor_
)
{
switch
(
*
cursor_
)
{
case
'n'
:
attribute_
+=
'\n'
;
cursor_
++
;
break
;
case
'n'
:
attribute_
+=
'\n'
;
cursor_
++
;
break
;
case
't'
:
attribute_
+=
'\t'
;
cursor_
++
;
break
;
case
't'
:
attribute_
+=
'\t'
;
cursor_
++
;
break
;
...
@@ -263,18 +270,51 @@ CheckedError Parser::Next() {
...
@@ -263,18 +270,51 @@ CheckedError Parser::Next() {
cursor_
++
;
cursor_
++
;
int64_t
val
;
int64_t
val
;
ECHECK
(
ParseHexNum
(
4
,
&
val
));
ECHECK
(
ParseHexNum
(
4
,
&
val
));
if
(
val
>=
0xD800
&&
val
<=
0xDBFF
)
{
if
(
unicode_high_surrogate
!=
-
1
)
{
return
Error
(
"illegal Unicode sequence (multiple high surrogates)"
);
}
else
{
unicode_high_surrogate
=
static_cast
<
int
>
(
val
);
}
}
else
if
(
val
>=
0xDC00
&&
val
<=
0xDFFF
)
{
if
(
unicode_high_surrogate
==
-
1
)
{
return
Error
(
"illegal Unicode sequence (unpaired low surrogate)"
);
}
else
{
int
code_point
=
0x10000
+
((
unicode_high_surrogate
&
0x03FF
)
<<
10
)
+
(
val
&
0x03FF
);
ToUTF8
(
code_point
,
&
attribute_
);
unicode_high_surrogate
=
-
1
;
}
}
else
{
if
(
unicode_high_surrogate
!=
-
1
)
{
return
Error
(
"illegal Unicode sequence (unpaired high surrogate)"
);
}
ToUTF8
(
static_cast
<
int
>
(
val
),
&
attribute_
);
ToUTF8
(
static_cast
<
int
>
(
val
),
&
attribute_
);
}
break
;
break
;
}
}
default
:
return
Error
(
"unknown escape code in string constant"
);
default
:
return
Error
(
"unknown escape code in string constant"
);
}
}
}
else
{
// printable chars + UTF-8 bytes
}
else
{
// printable chars + UTF-8 bytes
if
(
unicode_high_surrogate
!=
-
1
)
{
return
Error
(
"illegal Unicode sequence (unpaired high surrogate)"
);
}
attribute_
+=
*
cursor_
++
;
attribute_
+=
*
cursor_
++
;
}
}
}
}
if
(
unicode_high_surrogate
!=
-
1
)
{
return
Error
(
"illegal Unicode sequence (unpaired high surrogate)"
);
}
cursor_
++
;
cursor_
++
;
token_
=
kTokenStringConstant
;
token_
=
kTokenStringConstant
;
return
NoError
();
return
NoError
();
}
case
'/'
:
case
'/'
:
if
(
*
cursor_
==
'/'
)
{
if
(
*
cursor_
==
'/'
)
{
const
char
*
start
=
++
cursor_
;
const
char
*
start
=
++
cursor_
;
...
@@ -1961,14 +2001,14 @@ flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<
...
@@ -1961,14 +2001,14 @@ flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<
Definition
::
SerializeAttributes
(
FlatBufferBuilder
*
builder
,
Definition
::
SerializeAttributes
(
FlatBufferBuilder
*
builder
,
const
Parser
&
parser
)
const
{
const
Parser
&
parser
)
const
{
std
::
vector
<
flatbuffers
::
Offset
<
reflection
::
KeyValue
>>
attrs
;
std
::
vector
<
flatbuffers
::
Offset
<
reflection
::
KeyValue
>>
attrs
;
for
(
auto
kv
:
attributes
.
dict
)
{
for
(
auto
kv
=
attributes
.
dict
.
begin
();
kv
!=
attributes
.
dict
.
end
();
++
kv
)
{
auto
it
=
parser
.
known_attributes_
.
find
(
kv
.
first
);
auto
it
=
parser
.
known_attributes_
.
find
(
kv
->
first
);
assert
(
it
!=
parser
.
known_attributes_
.
end
());
assert
(
it
!=
parser
.
known_attributes_
.
end
());
if
(
!
it
->
second
)
{
// Custom attribute.
if
(
!
it
->
second
)
{
// Custom attribute.
attrs
.
push_back
(
attrs
.
push_back
(
reflection
::
CreateKeyValue
(
*
builder
,
builder
->
CreateString
(
kv
.
first
),
reflection
::
CreateKeyValue
(
*
builder
,
builder
->
CreateString
(
kv
->
first
),
builder
->
CreateString
(
builder
->
CreateString
(
kv
.
second
->
constant
)));
kv
->
second
->
constant
)));
}
}
}
}
if
(
attrs
.
size
())
{
if
(
attrs
.
size
())
{
...
...
tests/MyGame/Example/Any.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/Any.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/Any.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/Any.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/Any.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/MyGame/Example/Color.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/Color.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/Color.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/Color.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/Color.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/MyGame/Example/Monster.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/Monster.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/Monster.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/Monster.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/Monster.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/MyGame/Example/Stat.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/Stat.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/Stat.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/Stat.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/Stat.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/MyGame/Example/Test.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/Test.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/Test.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/Test.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/Test.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/MyGame/Example/Vec3.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame.Example
namespace
MyGame.Example
{
{
...
...
tests/MyGame/Example/Vec3.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
Example
package
Example
...
...
tests/MyGame/Example/Vec3.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
MyGame
.
Example
;
package
MyGame
.
Example
;
...
...
tests/MyGame/Example/Vec3.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
MyGame\Example
;
namespace
MyGame\Example
;
...
...
tests/MyGame/Example/Vec3.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: Example
# namespace: Example
...
...
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA.NamespaceB
namespace
NamespaceA.NamespaceB
{
{
...
...
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceB
package
NamespaceB
...
...
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
.
NamespaceB
;
package
NamespaceA
.
NamespaceB
;
...
...
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA\NamespaceB
;
namespace
NamespaceA\NamespaceB
;
...
...
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceB
# namespace: NamespaceB
...
...
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA.NamespaceB
namespace
NamespaceA.NamespaceB
{
{
...
...
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceB
package
NamespaceB
...
...
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
.
NamespaceB
;
package
NamespaceA
.
NamespaceB
;
...
...
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA\NamespaceB
;
namespace
NamespaceA\NamespaceB
;
...
...
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceB
# namespace: NamespaceB
...
...
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA.NamespaceB
namespace
NamespaceA.NamespaceB
{
{
...
...
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceB
package
NamespaceB
...
...
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
.
NamespaceB
;
package
NamespaceA
.
NamespaceB
;
...
...
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA\NamespaceB
;
namespace
NamespaceA\NamespaceB
;
...
...
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceB
# namespace: NamespaceB
...
...
tests/namespace_test/NamespaceA/SecondTableInA.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA
namespace
NamespaceA
{
{
...
...
tests/namespace_test/NamespaceA/SecondTableInA.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
package
NamespaceA
...
...
tests/namespace_test/NamespaceA/SecondTableInA.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
;
package
NamespaceA
;
...
...
tests/namespace_test/NamespaceA/SecondTableInA.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA
;
namespace
NamespaceA
;
...
...
tests/namespace_test/NamespaceA/SecondTableInA.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceA
# namespace: NamespaceA
...
...
tests/namespace_test/NamespaceA/TableInC.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA
namespace
NamespaceA
{
{
...
...
tests/namespace_test/NamespaceA/TableInC.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
package
NamespaceA
...
...
tests/namespace_test/NamespaceA/TableInC.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
;
package
NamespaceA
;
...
...
tests/namespace_test/NamespaceA/TableInC.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA
;
namespace
NamespaceA
;
...
...
tests/namespace_test/NamespaceA/TableInC.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceA
# namespace: NamespaceA
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.cs
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA
namespace
NamespaceA
{
{
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.go
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
package
NamespaceA
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.java
View file @
bafd48d9
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
package
NamespaceA
;
package
NamespaceA
;
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.php
View file @
bafd48d9
<?php
<?php
// automatically generated, do not modify
// automatically generated
by the FlatBuffers compiler
, do not modify
namespace
NamespaceA
;
namespace
NamespaceA
;
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.py
View file @
bafd48d9
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceA
# namespace: NamespaceA
...
...
tests/test.cpp
View file @
bafd48d9
...
@@ -868,6 +868,44 @@ void UnicodeTest() {
...
@@ -868,6 +868,44 @@ void UnicodeTest() {
"
\\
u5225
\\
u30B5
\\
u30A4
\\
u30C8
\\
x01
\\
x80
\"
}"
,
true
);
"
\\
u5225
\\
u30B5
\\
u30A4
\\
u30C8
\\
x01
\\
x80
\"
}"
,
true
);
}
}
void
UnicodeSurrogatesTest
()
{
flatbuffers
::
Parser
parser
;
TEST_EQ
(
parser
.
Parse
(
"table T { F:string (id: 0); }"
"root_type T;"
"{ F:
\"\\
uD83D
\\
uDCA9
\"
}"
),
true
);
auto
root
=
flatbuffers
::
GetRoot
<
flatbuffers
::
Table
>
(
parser
.
builder_
.
GetBufferPointer
());
auto
string
=
root
->
GetPointer
<
flatbuffers
::
String
*>
(
flatbuffers
::
FieldIndexToOffset
(
0
));
TEST_EQ
(
strcmp
(
string
->
c_str
(),
"
\xF0\x9F\x92\xA9
"
),
0
);
}
void
UnicodeInvalidSurrogatesTest
()
{
TestError
(
"table T { F:string; }"
"root_type T;"
"{ F:
\"\\
uD800
\"
}"
,
"unpaired high surrogate"
);
TestError
(
"table T { F:string; }"
"root_type T;"
"{ F:
\"\\
uD800abcd
\"
}"
,
"unpaired high surrogate"
);
TestError
(
"table T { F:string; }"
"root_type T;"
"{ F:
\"\\
uD800
\\
n
\"
}"
,
"unpaired high surrogate"
);
TestError
(
"table T { F:string; }"
"root_type T;"
"{ F:
\"\\
uD800
\\
uD800
\"
}"
,
"multiple high surrogates"
);
TestError
(
"table T { F:string; }"
"root_type T;"
"{ F:
\"\\
uDC00
\"
}"
,
"unpaired low surrogate"
);
}
void
UnknownFieldsTest
()
{
void
UnknownFieldsTest
()
{
flatbuffers
::
IDLOptions
opts
;
flatbuffers
::
IDLOptions
opts
;
opts
.
skip_unexpected_fields_in_json
=
true
;
opts
.
skip_unexpected_fields_in_json
=
true
;
...
@@ -916,6 +954,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
...
@@ -916,6 +954,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
EnumStringsTest
();
EnumStringsTest
();
IntegerOutOfRangeTest
();
IntegerOutOfRangeTest
();
UnicodeTest
();
UnicodeTest
();
UnicodeSurrogatesTest
();
UnicodeInvalidSurrogatesTest
();
UnknownFieldsTest
();
UnknownFieldsTest
();
if
(
!
testing_fails
)
{
if
(
!
testing_fails
)
{
...
...
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