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
03ad8fa4
Commit
03ad8fa4
authored
Jun 14, 2016
by
lakedaemon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sharing the WrapInNameSpace methods
parent
43fedfa8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
84 deletions
+44
-84
code_generators.h
include/flatbuffers/code_generators.h
+29
-3
idl_gen_cpp.cpp
src/idl_gen_cpp.cpp
+2
-18
idl_gen_general.cpp
src/idl_gen_general.cpp
+7
-26
idl_gen_go.cpp
src/idl_gen_go.cpp
+2
-1
idl_gen_js.cpp
src/idl_gen_js.cpp
+1
-17
idl_gen_php.cpp
src/idl_gen_php.cpp
+1
-18
idl_gen_python.cpp
src/idl_gen_python.cpp
+2
-1
No files found.
include/flatbuffers/code_generators.h
View file @
03ad8fa4
...
@@ -39,11 +39,15 @@ class BaseGenerator {
...
@@ -39,11 +39,15 @@ class BaseGenerator {
protected
:
protected
:
BaseGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
BaseGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
,
const
std
::
string
qualifying_start
,
const
std
::
string
qualifying_separator
)
:
parser_
(
parser
),
:
parser_
(
parser
),
path_
(
path
),
path_
(
path
),
file_name_
(
file_name
)
{};
file_name_
(
file_name
),
virtual
~
BaseGenerator
()
{};
qualifying_start_
(
qualifying_start
),
qualifying_separator_
(
qualifying_separator
){};
virtual
~
BaseGenerator
(){};
// No copy/assign.
// No copy/assign.
BaseGenerator
&
operator
=
(
const
BaseGenerator
&
);
BaseGenerator
&
operator
=
(
const
BaseGenerator
&
);
...
@@ -85,9 +89,31 @@ class BaseGenerator {
...
@@ -85,9 +89,31 @@ class BaseGenerator {
if
(
namespaces
.
size
())
return
*
(
namespaces
.
end
()
-
1
);
else
return
std
::
string
(
""
);
if
(
namespaces
.
size
())
return
*
(
namespaces
.
end
()
-
1
);
else
return
std
::
string
(
""
);
}
}
// tracks the current namespace for early exit in WrapInNameSpace
// c++, java and csharp returns a different namespace from
// the following default (no early exit, always fully qualify),
// which works for js and php
virtual
const
Namespace
*
CurrentNameSpace
()
{
return
nullptr
;
}
// Ensure that a type is prefixed with its namespace whenever it is used
// outside of its namespace.
std
::
string
WrapInNameSpace
(
const
Namespace
*
ns
,
const
std
::
string
&
name
)
{
if
(
CurrentNameSpace
()
==
ns
)
return
name
;
std
::
string
qualified_name
=
qualifying_start_
;
for
(
auto
it
=
ns
->
components
.
begin
();
it
!=
ns
->
components
.
end
();
++
it
)
qualified_name
+=
*
it
+
qualifying_separator_
;
return
qualified_name
+
name
;
}
std
::
string
WrapInNameSpace
(
const
Definition
&
def
)
{
return
WrapInNameSpace
(
def
.
defined_namespace
,
def
.
name
);
}
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
qualifying_start_
;
const
std
::
string
qualifying_separator_
;
};
};
}
// namespace flatbuffers
}
// namespace flatbuffers
...
...
src/idl_gen_cpp.cpp
View file @
03ad8fa4
...
@@ -39,7 +39,7 @@ class CppGenerator : public BaseGenerator {
...
@@ -39,7 +39,7 @@ class CppGenerator : public BaseGenerator {
public
:
public
:
CppGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
CppGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
,
"::"
){};
// Iterate through all definitions we haven't generate code for (enums,
// Iterate through all definitions we haven't generate code for (enums,
// structs,
// structs,
// and tables) and output them to a single file.
// and tables) and output them to a single file.
...
@@ -208,23 +208,7 @@ class CppGenerator : public BaseGenerator {
...
@@ -208,23 +208,7 @@ class CppGenerator : public BaseGenerator {
// This tracks the current namespace so we can insert namespace declarations.
// This tracks the current namespace so we can insert namespace declarations.
const
Namespace
*
cur_name_space_
=
nullptr
;
const
Namespace
*
cur_name_space_
=
nullptr
;
// Ensure that a type is prefixed with its namespace whenever it is used
const
Namespace
*
CurrentNameSpace
()
{
return
cur_name_space_
;}
// outside of its namespace.
std
::
string
WrapInNameSpace
(
const
Namespace
*
ns
,
const
std
::
string
&
name
)
{
if
(
cur_name_space_
!=
ns
)
{
std
::
string
qualified_name
;
for
(
auto
it
=
ns
->
components
.
begin
();
it
!=
ns
->
components
.
end
();
++
it
)
{
qualified_name
+=
*
it
+
"::"
;
}
return
qualified_name
+
name
;
}
else
{
return
name
;
}
}
std
::
string
WrapInNameSpace
(
const
Definition
&
def
)
{
return
WrapInNameSpace
(
def
.
defined_namespace
,
def
.
name
);
}
// Translates a qualified name in flatbuffer text format to the same name in
// Translates a qualified name in flatbuffer text format to the same name in
// the equivalent C++ namespace.
// the equivalent C++ namespace.
...
...
src/idl_gen_general.cpp
View file @
03ad8fa4
...
@@ -193,7 +193,7 @@ class GeneralGenerator : public BaseGenerator {
...
@@ -193,7 +193,7 @@ class GeneralGenerator : public BaseGenerator {
public
:
public
:
GeneralGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
GeneralGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
,
"."
){
assert
(
parser_
.
opts
.
lang
<=
IDLOptions
::
kMAX
);
assert
(
parser_
.
opts
.
lang
<=
IDLOptions
::
kMAX
);
};
};
bool
generate
()
{
bool
generate
()
{
...
@@ -251,38 +251,19 @@ class GeneralGenerator : public BaseGenerator {
...
@@ -251,38 +251,19 @@ class GeneralGenerator : public BaseGenerator {
auto
filename
=
NamespaceDir
(
ns
)
+
defname
+
lang_
.
file_extension
;
auto
filename
=
NamespaceDir
(
ns
)
+
defname
+
lang_
.
file_extension
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
}
std
::
string
FunctionStart
(
char
upper
)
{
const
Namespace
*
CurrentNameSpace
()
{
return
parser_
.
namespaces_
.
back
();
}
return
std
::
string
()
+
(
lang_
.
language
==
IDLOptions
::
kJava
std
::
string
FunctionStart
(
char
upper
)
{
?
static_cast
<
char
>
(
tolower
(
upper
))
return
std
::
string
()
+
(
lang_
.
language
==
IDLOptions
::
kJava
:
upper
);
?
static_cast
<
char
>
(
tolower
(
upper
))
:
upper
);
}
}
static
bool
IsEnum
(
const
Type
&
type
)
{
static
bool
IsEnum
(
const
Type
&
type
)
{
return
type
.
enum_def
!=
nullptr
&&
IsInteger
(
type
.
base_type
);
return
type
.
enum_def
!=
nullptr
&&
IsInteger
(
type
.
base_type
);
}
}
// Ensure that a type is prefixed with its namespace whenever it is used
// outside of its namespace.
std
::
string
WrapInNameSpace
(
const
Namespace
*
ns
,
const
std
::
string
&
name
)
{
if
(
parser_
.
namespaces_
.
back
()
!=
ns
)
{
std
::
string
qualified_name
;
for
(
auto
it
=
ns
->
components
.
begin
();
it
!=
ns
->
components
.
end
();
++
it
)
{
qualified_name
+=
*
it
+
"."
;
}
return
qualified_name
+
name
;
}
else
{
return
name
;
}
}
std
::
string
WrapInNameSpace
(
const
Definition
&
def
)
{
return
WrapInNameSpace
(
def
.
defined_namespace
,
def
.
name
);
}
std
::
string
GenTypeBasic
(
const
Type
&
type
,
bool
enableLangOverrides
)
{
std
::
string
GenTypeBasic
(
const
Type
&
type
,
bool
enableLangOverrides
)
{
static
const
char
*
gtypename
[]
=
{
static
const
char
*
gtypename
[]
=
{
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
...
...
src/idl_gen_go.cpp
View file @
03ad8fa4
...
@@ -625,7 +625,8 @@ class GoGenerator : public BaseGenerator {
...
@@ -625,7 +625,8 @@ class GoGenerator : public BaseGenerator {
public
:
public
:
GoGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
GoGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
/* not used*/
,
""
/* not used */
){};
bool
generate
()
{
bool
generate
()
{
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
)
{
...
...
src/idl_gen_js.cpp
View file @
03ad8fa4
...
@@ -35,7 +35,7 @@ class JsGenerator : public BaseGenerator {
...
@@ -35,7 +35,7 @@ class JsGenerator : public BaseGenerator {
public
:
public
:
JsGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
JsGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
,
"."
){};
// 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
()
{
...
@@ -119,22 +119,6 @@ class JsGenerator : public BaseGenerator {
...
@@ -119,22 +119,6 @@ class JsGenerator : public BaseGenerator {
}
}
}
}
// Ensure that a type is prefixed with its namespace whenever it is used
// outside of its namespace.
std
::
string
WrapInNameSpace
(
const
Namespace
*
ns
,
const
std
::
string
&
name
)
{
std
::
string
qualified_name
;
for
(
auto
it
=
ns
->
components
.
begin
();
it
!=
ns
->
components
.
end
();
++
it
)
{
qualified_name
+=
*
it
+
"."
;
}
return
qualified_name
+
name
;
}
std
::
string
WrapInNameSpace
(
const
Definition
&
def
)
{
return
WrapInNameSpace
(
def
.
defined_namespace
,
def
.
name
);
}
// Generate a documentation comment, if available.
// Generate a documentation comment, if available.
static
void
GenDocComment
(
const
std
::
vector
<
std
::
string
>
&
dc
,
static
void
GenDocComment
(
const
std
::
vector
<
std
::
string
>
&
dc
,
std
::
string
*
code_ptr
,
std
::
string
*
code_ptr
,
...
...
src/idl_gen_php.cpp
View file @
03ad8fa4
...
@@ -31,7 +31,7 @@ namespace php {
...
@@ -31,7 +31,7 @@ namespace php {
public
:
public
:
PhpGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
PhpGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
:
BaseGenerator
(
parser
,
path
,
file_name
,
"
\\
"
,
"
\\
"
){};
bool
generate
()
{
bool
generate
()
{
if
(
!
generateEnums
())
return
false
;
if
(
!
generateEnums
())
return
false
;
if
(
!
generateStructs
())
return
false
;
if
(
!
generateStructs
())
return
false
;
...
@@ -93,23 +93,6 @@ namespace php {
...
@@ -93,23 +93,6 @@ namespace php {
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
}
// Ensure that a type is prefixed with its namespace whenever it is used
// outside of its namespace.
std
::
string
WrapInNameSpace
(
const
Namespace
*
ns
,
const
std
::
string
&
name
)
{
std
::
string
qualified_name
=
"
\\
"
;
for
(
auto
it
=
ns
->
components
.
begin
();
it
!=
ns
->
components
.
end
();
++
it
)
{
qualified_name
+=
*
it
+
"
\\
"
;
}
return
qualified_name
+
name
;
}
std
::
string
WrapInNameSpace
(
const
Definition
&
def
)
{
return
WrapInNameSpace
(
def
.
defined_namespace
,
def
.
name
);
}
// 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
;
...
...
src/idl_gen_python.cpp
View file @
03ad8fa4
...
@@ -596,7 +596,8 @@ class PythonGenerator : public BaseGenerator {
...
@@ -596,7 +596,8 @@ class PythonGenerator : public BaseGenerator {
public
:
public
:
PythonGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
PythonGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
:
BaseGenerator
(
parser
,
path
,
file_name
,
""
/* not used */
,
""
/* not used */
){};
bool
generate
()
{
bool
generate
()
{
if
(
!
generateEnums
())
return
false
;
if
(
!
generateEnums
())
return
false
;
if
(
!
generateStructs
())
return
false
;
if
(
!
generateStructs
())
return
false
;
...
...
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