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
e750268f
Commit
e750268f
authored
Jul 15, 2016
by
lakedaemon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang formating cpp code generator and add missing generated classes
parent
0328deda
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
53 additions
and
69 deletions
+53
-69
idl_gen_cpp.cpp
src/idl_gen_cpp.cpp
+36
-52
Any.java
tests/MyGame/Example/Any.java
+2
-2
Color.java
tests/MyGame/Example/Color.java
+2
-2
Monster.java
tests/MyGame/Example/Monster.java
+1
-1
Stat.java
tests/MyGame/Example/Stat.java
+1
-1
Test.java
tests/MyGame/Example/Test.java
+1
-1
TestSimpleTableWithEnum.java
tests/MyGame/Example/TestSimpleTableWithEnum.java
+1
-1
Vec3.java
tests/MyGame/Example/Vec3.java
+1
-1
Monster.java
tests/MyGame/Example2/Monster.java
+1
-1
EnumInNestedNS.java
.../namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
+2
-2
StructInNestedNS.java
...amespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
+1
-1
TableInNestedNS.java
...namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
+1
-1
SecondTableInA.java
tests/namespace_test/NamespaceA/SecondTableInA.java
+1
-1
TableInFirstNS.java
tests/namespace_test/NamespaceA/TableInFirstNS.java
+1
-1
TableInC.java
tests/namespace_test/NamespaceC/TableInC.java
+1
-1
No files found.
src/idl_gen_cpp.cpp
View file @
e750268f
...
...
@@ -24,9 +24,7 @@
namespace
flatbuffers
{
struct
IsAlnum
{
bool
operator
()(
char
c
)
{
return
!
isalnum
(
c
);
}
bool
operator
()(
char
c
)
{
return
!
isalnum
(
c
);
}
};
static
std
::
string
GeneratedFileName
(
const
std
::
string
&
path
,
...
...
@@ -184,7 +182,6 @@ class CppGenerator : public BaseGenerator {
code
+=
"nullptr"
;
code
+=
"); }
\n\n
"
;
if
(
parser_
.
file_extension_
.
length
())
{
// Return the extension
code
+=
"inline const char *"
+
name
;
...
...
@@ -264,30 +261,28 @@ class CppGenerator : public BaseGenerator {
// Return a C++ type for any type (scalar/pointer) specifically for
// building a flatbuffer.
std
::
string
GenTypeWire
(
const
Type
&
type
,
const
char
*
postfix
,
bool
user_facing_type
)
{
std
::
string
GenTypeWire
(
const
Type
&
type
,
const
char
*
postfix
,
bool
user_facing_type
)
{
return
IsScalar
(
type
.
base_type
)
?
GenTypeBasic
(
type
,
user_facing_type
)
+
postfix
:
IsStruct
(
type
)
?
"const "
+
GenTypePointer
(
type
)
+
" *"
:
"flatbuffers::Offset<"
+
GenTypePointer
(
type
)
+
">"
+
postfix
;
:
IsStruct
(
type
)
?
"const "
+
GenTypePointer
(
type
)
+
" *"
:
"flatbuffers::Offset<"
+
GenTypePointer
(
type
)
+
">"
+
postfix
;
}
// Return a C++ type for any type (scalar/pointer) that reflects its
// serialized size.
std
::
string
GenTypeSize
(
const
Type
&
type
)
{
return
IsScalar
(
type
.
base_type
)
?
GenTypeBasic
(
type
,
false
)
:
IsStruct
(
type
)
?
GenTypePointer
(
type
)
:
"flatbuffers::uoffset_t"
;
return
IsScalar
(
type
.
base_type
)
?
GenTypeBasic
(
type
,
false
)
:
IsStruct
(
type
)
?
GenTypePointer
(
type
)
:
"flatbuffers::uoffset_t"
;
}
// Return a C++ type for any type (scalar/pointer) specifically for
// using a flatbuffer.
std
::
string
GenTypeGet
(
const
Type
&
type
,
const
char
*
afterbasic
,
const
char
*
before
ptr
,
const
char
*
afterptr
,
bool
user_facing_type
)
{
std
::
string
GenTypeGet
(
const
Type
&
type
,
const
char
*
afterbasic
,
const
char
*
beforeptr
,
const
char
*
after
ptr
,
bool
user_facing_type
)
{
return
IsScalar
(
type
.
base_type
)
?
GenTypeBasic
(
type
,
user_facing_type
)
+
afterbasic
:
beforeptr
+
GenTypePointer
(
type
)
+
afterptr
;
...
...
@@ -388,8 +383,8 @@ class CppGenerator : public BaseGenerator {
code
+=
"()[static_cast<int>(e)"
;
if
(
enum_def
.
vals
.
vec
.
front
()
->
value
)
{
code
+=
" - static_cast<int>("
;
code
+=
GetEnumVal
(
enum_def
,
*
enum_def
.
vals
.
vec
.
front
(),
parser_
.
opts
)
+
")"
;
code
+=
GetEnumVal
(
enum_def
,
*
enum_def
.
vals
.
vec
.
front
(),
parser_
.
opts
)
+
")"
;
}
code
+=
"]; }
\n\n
"
;
}
...
...
@@ -446,8 +441,7 @@ class CppGenerator : public BaseGenerator {
return
"VT_"
+
uname
;
}
void
GenFullyQualifiedNameGetter
(
const
std
::
string
&
name
,
std
::
string
&
code
)
{
void
GenFullyQualifiedNameGetter
(
const
std
::
string
&
name
,
std
::
string
&
code
)
{
if
(
parser_
.
opts
.
generate_name_strings
)
{
code
+=
" static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() "
...
...
@@ -469,21 +463,17 @@ class CppGenerator : public BaseGenerator {
code
+=
field
.
name
+
" = "
;
if
(
field
.
value
.
type
.
enum_def
&&
IsScalar
(
field
.
value
.
type
.
base_type
))
{
auto
ev
=
field
.
value
.
type
.
enum_def
->
ReverseLookup
(
static_cast
<
int
>
(
StringToInt
(
field
.
value
.
constant
.
c_str
())),
false
);
static_cast
<
int
>
(
StringToInt
(
field
.
value
.
constant
.
c_str
())),
false
);
if
(
ev
)
{
code
+=
WrapInNameSpace
(
field
.
value
.
type
.
enum_def
->
defined_namespace
,
GetEnumVal
(
*
field
.
value
.
type
.
enum_def
,
*
ev
,
parser_
.
opts
));
}
else
{
field
.
value
.
type
.
enum_def
->
defined_namespace
,
GetEnumVal
(
*
field
.
value
.
type
.
enum_def
,
*
ev
,
parser_
.
opts
));
}
else
{
code
+=
GenUnderlyingCast
(
field
,
true
,
field
.
value
.
constant
);
}
}
else
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_BOOL
)
{
}
else
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_BOOL
)
{
code
+=
field
.
value
.
constant
==
"0"
?
"false"
:
"true"
;
}
else
{
}
else
{
code
+=
GenDefaultConstant
(
field
);
}
}
...
...
@@ -529,8 +519,7 @@ class CppGenerator : public BaseGenerator {
if
(
!
field
.
deprecated
)
{
// Deprecated fields won't be accessible.
auto
is_scalar
=
IsScalar
(
field
.
value
.
type
.
base_type
);
GenComment
(
field
.
doc_comment
,
code_ptr
,
nullptr
,
" "
);
code
+=
" "
+
GenTypeGet
(
field
.
value
.
type
,
" "
,
"const "
,
" *"
,
true
);
code
+=
" "
+
GenTypeGet
(
field
.
value
.
type
,
" "
,
"const "
,
" *"
,
true
);
code
+=
field
.
name
+
"() const { return "
;
// Call a different accessor for pointers, that indirects.
auto
accessor
=
...
...
@@ -538,8 +527,8 @@ class CppGenerator : public BaseGenerator {
?
"GetField<"
:
(
IsStruct
(
field
.
value
.
type
)
?
"GetStruct<"
:
"GetPointer<"
);
auto
offsetstr
=
GenFieldOffsetName
(
field
);
auto
call
=
accessor
+
GenTypeGet
(
field
.
value
.
type
,
""
,
"const "
,
" *"
,
false
)
+
auto
call
=
accessor
+
GenTypeGet
(
field
.
value
.
type
,
""
,
"const "
,
" *"
,
false
)
+
">("
+
offsetstr
;
// Default value as second arg for non-pointer types.
if
(
IsScalar
(
field
.
value
.
type
.
base_type
))
...
...
@@ -556,8 +545,7 @@ class CppGenerator : public BaseGenerator {
code
+=
GenUnderlyingCast
(
field
,
false
,
"_"
+
field
.
name
);
code
+=
"); }
\n
"
;
}
else
{
auto
type
=
GenTypeGet
(
field
.
value
.
type
,
" "
,
""
,
" *"
,
true
);
auto
type
=
GenTypeGet
(
field
.
value
.
type
,
" "
,
""
,
" *"
,
true
);
code
+=
" "
+
type
+
"mutable_"
+
field
.
name
+
"() { return "
;
code
+=
GenUnderlyingCast
(
field
,
true
,
accessor
+
type
+
">("
+
offsetstr
+
")"
);
...
...
@@ -739,20 +727,19 @@ class CppGenerator : public BaseGenerator {
}
code
+=
" return builder_.Finish();
\n
}
\n\n
"
;
//Generate a CreateX function with vector types as parameters
//
Generate a CreateX function with vector types as parameters
if
(
gen_vector_pars
)
{
code
+=
"inline flatbuffers::Offset<"
+
struct_def
.
name
+
"> Create"
;
code
+=
struct_def
.
name
;
code
+=
"(flatbuffers::FlatBufferBuilder &_fbb"
;
for
(
auto
it
=
struct_def
.
fields
.
vec
.
begin
();
it
!=
struct_def
.
fields
.
vec
.
end
();
++
it
)
{
it
!=
struct_def
.
fields
.
vec
.
end
();
++
it
)
{
auto
&
field
=
**
it
;
if
(
!
field
.
deprecated
)
{
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_STRING
)
{
code
+=
",
\n
const char *"
;
code
+=
field
.
name
+
" = nullptr"
;
}
else
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
}
else
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
code
+=
",
\n
const std::vector<"
;
code
+=
GenTypeWire
(
field
.
value
.
type
.
VectorType
(),
""
,
false
);
code
+=
"> *"
+
field
.
name
+
" = nullptr"
;
...
...
@@ -766,7 +753,7 @@ class CppGenerator : public BaseGenerator {
code
+=
struct_def
.
name
;
code
+=
"(_fbb"
;
for
(
auto
it
=
struct_def
.
fields
.
vec
.
begin
();
it
!=
struct_def
.
fields
.
vec
.
end
();
++
it
)
{
it
!=
struct_def
.
fields
.
vec
.
end
();
++
it
)
{
auto
&
field
=
**
it
;
if
(
!
field
.
deprecated
)
{
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_STRING
)
{
...
...
@@ -777,7 +764,8 @@ class CppGenerator : public BaseGenerator {
code
+=
"_fbb.CreateVector<"
;
code
+=
GenTypeWire
(
field
.
value
.
type
.
VectorType
(),
""
,
false
);
code
+=
">(*"
+
field
.
name
+
")"
;
}
else
code
+=
", "
+
field
.
name
;
}
else
code
+=
", "
+
field
.
name
;
}
}
code
+=
");
\n
}
\n\n
"
;
...
...
@@ -880,8 +868,7 @@ class CppGenerator : public BaseGenerator {
auto
&
field
=
**
it
;
GenComment
(
field
.
doc_comment
,
code_ptr
,
nullptr
,
" "
);
auto
is_scalar
=
IsScalar
(
field
.
value
.
type
.
base_type
);
code
+=
" "
+
GenTypeGet
(
field
.
value
.
type
,
" "
,
"const "
,
" &"
,
true
);
code
+=
" "
+
GenTypeGet
(
field
.
value
.
type
,
" "
,
"const "
,
" &"
,
true
);
code
+=
field
.
name
+
"() const { return "
;
code
+=
GenUnderlyingCast
(
field
,
true
,
is_scalar
...
...
@@ -949,19 +936,16 @@ bool GenerateCPP(const Parser &parser, const std::string &path,
return
generator
.
generate
();
}
std
::
string
CPPMakeRule
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
std
::
string
CPPMakeRule
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
{
std
::
string
filebase
=
flatbuffers
::
StripPath
(
flatbuffers
::
StripExtension
(
file_name
));
std
::
string
filebase
=
flatbuffers
::
Strip
Path
(
flatbuffers
::
Strip
Extension
(
file_name
));
std
::
string
make_rule
=
GeneratedFileName
(
path
,
filebase
)
+
": "
;
auto
included_files
=
parser
.
GetIncludedFilesRecursive
(
file_name
);
for
(
auto
it
=
included_files
.
begin
();
it
!=
included_files
.
end
();
++
it
)
{
for
(
auto
it
=
included_files
.
begin
();
it
!=
included_files
.
end
();
++
it
)
{
make_rule
+=
" "
+
*
it
;
}
return
make_rule
;
}
}
// namespace flatbuffers
tests/MyGame/Example/Any.java
View file @
e750268f
...
...
@@ -9,8 +9,8 @@ public final class Any {
public
static
final
byte
TestSimpleTableWithEnum
=
2
;
public
static
final
byte
MyGame_Example2_Monster
=
3
;
p
rivate
static
final
String
[]
names
=
{
"NONE"
,
"Monster"
,
"TestSimpleTableWithEnum"
,
"MyGame_Example2_Monster"
,
};
p
ublic
static
final
String
[]
names
=
{
"NONE"
,
"Monster"
,
"TestSimpleTableWithEnum"
,
"MyGame_Example2_Monster"
,
};
public
static
String
name
(
int
e
)
{
return
names
[
e
];
}
}
;
}
tests/MyGame/Example/Color.java
View file @
e750268f
...
...
@@ -8,8 +8,8 @@ public final class Color {
public
static
final
byte
Green
=
2
;
public
static
final
byte
Blue
=
8
;
p
rivate
static
final
String
[]
names
=
{
"Red"
,
"Green"
,
""
,
""
,
""
,
""
,
""
,
"Blue"
,
};
p
ublic
static
final
String
[]
names
=
{
"Red"
,
"Green"
,
""
,
""
,
""
,
""
,
""
,
"Blue"
,
};
public
static
String
name
(
int
e
)
{
return
names
[
e
-
Red
];
}
}
;
}
tests/MyGame/Example/Monster.java
View file @
e750268f
...
...
@@ -135,5 +135,5 @@ public final class Monster extends Table {
return
o
;
}
public
static
void
finishMonsterBuffer
(
FlatBufferBuilder
builder
,
int
offset
)
{
builder
.
finish
(
offset
,
"MONS"
);
}
}
;
}
tests/MyGame/Example/Stat.java
View file @
e750268f
...
...
@@ -39,5 +39,5 @@ public final class Stat extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
tests/MyGame/Example/Test.java
View file @
e750268f
...
...
@@ -23,5 +23,5 @@ public final class Test extends Struct {
builder
.
putShort
(
a
);
return
builder
.
offset
();
}
}
;
}
tests/MyGame/Example/TestSimpleTableWithEnum.java
View file @
e750268f
...
...
@@ -29,5 +29,5 @@ public final class TestSimpleTableWithEnum extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
tests/MyGame/Example/Vec3.java
View file @
e750268f
...
...
@@ -40,5 +40,5 @@ public final class Vec3 extends Struct {
builder
.
putFloat
(
x
);
return
builder
.
offset
();
}
}
;
}
tests/MyGame/Example2/Monster.java
View file @
e750268f
...
...
@@ -19,5 +19,5 @@ public final class Monster extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
View file @
e750268f
...
...
@@ -8,8 +8,8 @@ public final class EnumInNestedNS {
public
static
final
byte
B
=
1
;
public
static
final
byte
C
=
2
;
p
rivate
static
final
String
[]
names
=
{
"A"
,
"B"
,
"C"
,
};
p
ublic
static
final
String
[]
names
=
{
"A"
,
"B"
,
"C"
,
};
public
static
String
name
(
int
e
)
{
return
names
[
e
];
}
}
;
}
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
View file @
e750268f
...
...
@@ -22,5 +22,5 @@ public final class StructInNestedNS extends Struct {
builder
.
putInt
(
a
);
return
builder
.
offset
();
}
}
;
}
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
View file @
e750268f
...
...
@@ -29,5 +29,5 @@ public final class TableInNestedNS extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
tests/namespace_test/NamespaceA/SecondTableInA.java
View file @
e750268f
...
...
@@ -29,5 +29,5 @@ public final class SecondTableInA extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
tests/namespace_test/NamespaceA/TableInFirstNS.java
View file @
e750268f
...
...
@@ -28,5 +28,5 @@ public final class TableInFirstNS extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
tests/namespace_test/NamespaceC/TableInC.java
View file @
e750268f
...
...
@@ -34,5 +34,5 @@ public final class TableInC extends Table {
int
o
=
builder
.
endObject
();
return
o
;
}
}
;
}
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