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
ca32eb77
Commit
ca32eb77
authored
Jun 02, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3885 from Lakedaemon/shareWarningAndTwoMethods
Share warning and two methods
parents
886441df
61b101d4
Hide whitespace changes
Inline
Side-by-side
Showing
73 changed files
with
255 additions
and
287 deletions
+255
-287
code_generators.h
include/flatbuffers/code_generators.h
+40
-3
monster_generated.h
samples/monster_generated.h
+18
-1
idl_gen_cpp.cpp
src/idl_gen_cpp.cpp
+1
-3
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
+1
-3
idl_gen_php.cpp
src/idl_gen_php.cpp
+33
-51
idl_gen_python.cpp
src/idl_gen_python.cpp
+34
-45
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
No files found.
include/flatbuffers/code_generators.h
View file @
ca32eb77
...
@@ -21,14 +21,35 @@ namespace flatbuffers {
...
@@ -21,14 +21,35 @@ 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
(){};
const
char
*
FlatBuffersGeneratedWarning
()
{
return
"automatically generated by the FlatBuffers compiler,"
" do not modify
\n\n
"
;
}
bool
IsEverythingGenerated
()
{
bool
IsEverythingGenerated
()
{
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
++
it
)
{
++
it
)
{
...
@@ -41,9 +62,25 @@ class BaseGenerator {
...
@@ -41,9 +62,25 @@ class BaseGenerator {
return
true
;
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
...
...
samples/monster_generated.h
View file @
ca32eb77
...
@@ -5,12 +5,13 @@
...
@@ -5,12 +5,13 @@
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/flatbuffers.h"
namespace
MyGame
{
namespace
MyGame
{
namespace
Sample
{
namespace
Sample
{
struct
Vec3
;
struct
Vec3
;
struct
Monster
;
struct
Monster
;
struct
Weapon
;
struct
Weapon
;
enum
Color
{
enum
Color
{
...
@@ -55,8 +56,11 @@ MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
...
@@ -55,8 +56,11 @@ MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
:
x_
(
flatbuffers
::
EndianScalar
(
_x
)),
y_
(
flatbuffers
::
EndianScalar
(
_y
)),
z_
(
flatbuffers
::
EndianScalar
(
_z
))
{
}
:
x_
(
flatbuffers
::
EndianScalar
(
_x
)),
y_
(
flatbuffers
::
EndianScalar
(
_y
)),
z_
(
flatbuffers
::
EndianScalar
(
_z
))
{
}
float
x
()
const
{
return
flatbuffers
::
EndianScalar
(
x_
);
}
float
x
()
const
{
return
flatbuffers
::
EndianScalar
(
x_
);
}
void
mutate_x
(
float
_x
)
{
flatbuffers
::
WriteScalar
(
&
x_
,
_x
);
}
float
y
()
const
{
return
flatbuffers
::
EndianScalar
(
y_
);
}
float
y
()
const
{
return
flatbuffers
::
EndianScalar
(
y_
);
}
void
mutate_y
(
float
_y
)
{
flatbuffers
::
WriteScalar
(
&
y_
,
_y
);
}
float
z
()
const
{
return
flatbuffers
::
EndianScalar
(
z_
);
}
float
z
()
const
{
return
flatbuffers
::
EndianScalar
(
z_
);
}
void
mutate_z
(
float
_z
)
{
flatbuffers
::
WriteScalar
(
&
z_
,
_z
);
}
};
};
STRUCT_END
(
Vec3
,
12
);
STRUCT_END
(
Vec3
,
12
);
...
@@ -73,14 +77,23 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
...
@@ -73,14 +77,23 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_EQUIPPED
=
22
VT_EQUIPPED
=
22
};
};
const
Vec3
*
pos
()
const
{
return
GetStruct
<
const
Vec3
*>
(
VT_POS
);
}
const
Vec3
*
pos
()
const
{
return
GetStruct
<
const
Vec3
*>
(
VT_POS
);
}
Vec3
*
mutable_pos
()
{
return
GetStruct
<
Vec3
*>
(
VT_POS
);
}
int16_t
mana
()
const
{
return
GetField
<
int16_t
>
(
VT_MANA
,
150
);
}
int16_t
mana
()
const
{
return
GetField
<
int16_t
>
(
VT_MANA
,
150
);
}
bool
mutate_mana
(
int16_t
_mana
)
{
return
SetField
(
VT_MANA
,
_mana
);
}
int16_t
hp
()
const
{
return
GetField
<
int16_t
>
(
VT_HP
,
100
);
}
int16_t
hp
()
const
{
return
GetField
<
int16_t
>
(
VT_HP
,
100
);
}
bool
mutate_hp
(
int16_t
_hp
)
{
return
SetField
(
VT_HP
,
_hp
);
}
const
flatbuffers
::
String
*
name
()
const
{
return
GetPointer
<
const
flatbuffers
::
String
*>
(
VT_NAME
);
}
const
flatbuffers
::
String
*
name
()
const
{
return
GetPointer
<
const
flatbuffers
::
String
*>
(
VT_NAME
);
}
flatbuffers
::
String
*
mutable_name
()
{
return
GetPointer
<
flatbuffers
::
String
*>
(
VT_NAME
);
}
const
flatbuffers
::
Vector
<
uint8_t
>
*
inventory
()
const
{
return
GetPointer
<
const
flatbuffers
::
Vector
<
uint8_t
>
*>
(
VT_INVENTORY
);
}
const
flatbuffers
::
Vector
<
uint8_t
>
*
inventory
()
const
{
return
GetPointer
<
const
flatbuffers
::
Vector
<
uint8_t
>
*>
(
VT_INVENTORY
);
}
flatbuffers
::
Vector
<
uint8_t
>
*
mutable_inventory
()
{
return
GetPointer
<
flatbuffers
::
Vector
<
uint8_t
>
*>
(
VT_INVENTORY
);
}
Color
color
()
const
{
return
static_cast
<
Color
>
(
GetField
<
int8_t
>
(
VT_COLOR
,
2
));
}
Color
color
()
const
{
return
static_cast
<
Color
>
(
GetField
<
int8_t
>
(
VT_COLOR
,
2
));
}
bool
mutate_color
(
Color
_color
)
{
return
SetField
(
VT_COLOR
,
static_cast
<
int8_t
>
(
_color
));
}
const
flatbuffers
::
Vector
<
flatbuffers
::
Offset
<
Weapon
>>
*
weapons
()
const
{
return
GetPointer
<
const
flatbuffers
::
Vector
<
flatbuffers
::
Offset
<
Weapon
>>
*>
(
VT_WEAPONS
);
}
const
flatbuffers
::
Vector
<
flatbuffers
::
Offset
<
Weapon
>>
*
weapons
()
const
{
return
GetPointer
<
const
flatbuffers
::
Vector
<
flatbuffers
::
Offset
<
Weapon
>>
*>
(
VT_WEAPONS
);
}
flatbuffers
::
Vector
<
flatbuffers
::
Offset
<
Weapon
>>
*
mutable_weapons
()
{
return
GetPointer
<
flatbuffers
::
Vector
<
flatbuffers
::
Offset
<
Weapon
>>
*>
(
VT_WEAPONS
);
}
Equipment
equipped_type
()
const
{
return
static_cast
<
Equipment
>
(
GetField
<
uint8_t
>
(
VT_EQUIPPED_TYPE
,
0
));
}
Equipment
equipped_type
()
const
{
return
static_cast
<
Equipment
>
(
GetField
<
uint8_t
>
(
VT_EQUIPPED_TYPE
,
0
));
}
bool
mutate_equipped_type
(
Equipment
_equipped_type
)
{
return
SetField
(
VT_EQUIPPED_TYPE
,
static_cast
<
uint8_t
>
(
_equipped_type
));
}
const
void
*
equipped
()
const
{
return
GetPointer
<
const
void
*>
(
VT_EQUIPPED
);
}
const
void
*
equipped
()
const
{
return
GetPointer
<
const
void
*>
(
VT_EQUIPPED
);
}
void
*
mutable_equipped
()
{
return
GetPointer
<
void
*>
(
VT_EQUIPPED
);
}
bool
Verify
(
flatbuffers
::
Verifier
&
verifier
)
const
{
bool
Verify
(
flatbuffers
::
Verifier
&
verifier
)
const
{
return
VerifyTableStart
(
verifier
)
&&
return
VerifyTableStart
(
verifier
)
&&
VerifyField
<
Vec3
>
(
verifier
,
VT_POS
)
&&
VerifyField
<
Vec3
>
(
verifier
,
VT_POS
)
&&
...
@@ -150,7 +163,9 @@ struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
...
@@ -150,7 +163,9 @@ struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_DAMAGE
=
6
VT_DAMAGE
=
6
};
};
const
flatbuffers
::
String
*
name
()
const
{
return
GetPointer
<
const
flatbuffers
::
String
*>
(
VT_NAME
);
}
const
flatbuffers
::
String
*
name
()
const
{
return
GetPointer
<
const
flatbuffers
::
String
*>
(
VT_NAME
);
}
flatbuffers
::
String
*
mutable_name
()
{
return
GetPointer
<
flatbuffers
::
String
*>
(
VT_NAME
);
}
int16_t
damage
()
const
{
return
GetField
<
int16_t
>
(
VT_DAMAGE
,
0
);
}
int16_t
damage
()
const
{
return
GetField
<
int16_t
>
(
VT_DAMAGE
,
0
);
}
bool
mutate_damage
(
int16_t
_damage
)
{
return
SetField
(
VT_DAMAGE
,
_damage
);
}
bool
Verify
(
flatbuffers
::
Verifier
&
verifier
)
const
{
bool
Verify
(
flatbuffers
::
Verifier
&
verifier
)
const
{
return
VerifyTableStart
(
verifier
)
&&
return
VerifyTableStart
(
verifier
)
&&
VerifyField
<
flatbuffers
::
uoffset_t
>
(
verifier
,
VT_NAME
)
&&
VerifyField
<
flatbuffers
::
uoffset_t
>
(
verifier
,
VT_NAME
)
&&
...
@@ -192,6 +207,8 @@ inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *union_o
...
@@ -192,6 +207,8 @@ inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *union_o
inline
const
MyGame
::
Sample
::
Monster
*
GetMonster
(
const
void
*
buf
)
{
return
flatbuffers
::
GetRoot
<
MyGame
::
Sample
::
Monster
>
(
buf
);
}
inline
const
MyGame
::
Sample
::
Monster
*
GetMonster
(
const
void
*
buf
)
{
return
flatbuffers
::
GetRoot
<
MyGame
::
Sample
::
Monster
>
(
buf
);
}
inline
Monster
*
GetMutableMonster
(
void
*
buf
)
{
return
flatbuffers
::
GetMutableRoot
<
Monster
>
(
buf
);
}
inline
bool
VerifyMonsterBuffer
(
flatbuffers
::
Verifier
&
verifier
)
{
return
verifier
.
VerifyBuffer
<
MyGame
::
Sample
::
Monster
>
();
}
inline
bool
VerifyMonsterBuffer
(
flatbuffers
::
Verifier
&
verifier
)
{
return
verifier
.
VerifyBuffer
<
MyGame
::
Sample
::
Monster
>
();
}
inline
void
FinishMonsterBuffer
(
flatbuffers
::
FlatBufferBuilder
&
fbb
,
flatbuffers
::
Offset
<
MyGame
::
Sample
::
Monster
>
root
)
{
fbb
.
Finish
(
root
);
}
inline
void
FinishMonsterBuffer
(
flatbuffers
::
FlatBufferBuilder
&
fbb
,
flatbuffers
::
Offset
<
MyGame
::
Sample
::
Monster
>
root
)
{
fbb
.
Finish
(
root
);
}
...
...
src/idl_gen_cpp.cpp
View file @
ca32eb77
...
@@ -747,9 +747,7 @@ class CppGenerator : public BaseGenerator {
...
@@ -747,9 +747,7 @@ class CppGenerator : public BaseGenerator {
if
(
IsEverythingGenerated
())
return
true
;
if
(
IsEverythingGenerated
())
return
true
;
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 @
ca32eb77
...
@@ -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 @
ca32eb77
...
@@ -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 @
ca32eb77
...
@@ -684,9 +684,7 @@ class JsGenerator : public BaseGenerator {
...
@@ -684,9 +684,7 @@ class JsGenerator : public BaseGenerator {
generateEnums
(
&
enum_code
,
&
exports_code
);
generateEnums
(
&
enum_code
,
&
exports_code
);
generateStructs
(
&
struct_code
,
&
exports_code
);
generateStructs
(
&
struct_code
,
&
exports_code
);
code
+=
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
"// 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
);
...
...
src/idl_gen_php.cpp
View file @
ca32eb77
...
@@ -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 @
ca32eb77
...
@@ -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
...
...
tests/MyGame/Example/Any.cs
View file @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
// 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 @
ca32eb77
<?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 @
ca32eb77
# automatically generated, do not modify
# automatically generated
by the FlatBuffers compiler
, do not modify
# namespace: NamespaceA
# namespace: NamespaceA
...
...
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