Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-flatbuffers
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-flatbuffers
Commits
eab9cfbe
Commit
eab9cfbe
authored
9 years ago
by
gwvo
Browse files
Options
Downloads
Plain Diff
Merge pull request #217 from amoldeshpande/master
option to generate one file for C#
parents
622b8d05
ab4801a8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/source/Compiler.md
+2
-0
2 additions, 0 deletions
docs/source/Compiler.md
include/flatbuffers/idl.h
+2
-0
2 additions, 0 deletions
include/flatbuffers/idl.h
src/flatc.cpp
+4
-1
4 additions, 1 deletion
src/flatc.cpp
src/idl_gen_general.cpp
+26
-9
26 additions, 9 deletions
src/idl_gen_general.cpp
with
34 additions
and
10 deletions
docs/source/Compiler.md
+
2
−
0
View file @
eab9cfbe
...
@@ -58,6 +58,8 @@ be generated for each file processed:
...
@@ -58,6 +58,8 @@ be generated for each file processed:
- `
--gen-mutable
` : Generate additional non-const accessors for mutating
- `
--gen-mutable
` : Generate additional non-const accessors for mutating
FlatBuffers in-place.
FlatBuffers in-place.
- `
--gen-onefile
` : Generate single output file (useful for C#)
- `
--raw-binary
` : Allow binaries without a file_indentifier to be read.
- `
--raw-binary
` : Allow binaries without a file_indentifier to be read.
This may crash flatc given a mismatched schema.
This may crash flatc given a mismatched schema.
...
...
This diff is collapsed.
Click to expand it.
include/flatbuffers/idl.h
+
2
−
0
View file @
eab9cfbe
...
@@ -427,6 +427,7 @@ struct GeneratorOptions {
...
@@ -427,6 +427,7 @@ struct GeneratorOptions {
bool
prefixed_enums
;
bool
prefixed_enums
;
bool
include_dependence_headers
;
bool
include_dependence_headers
;
bool
mutable_buffer
;
bool
mutable_buffer
;
bool
one_file
;
// Possible options for the more general generator below.
// Possible options for the more general generator below.
enum
Language
{
kJava
,
kCSharp
,
kGo
,
kMAX
};
enum
Language
{
kJava
,
kCSharp
,
kGo
,
kMAX
};
...
@@ -439,6 +440,7 @@ struct GeneratorOptions {
...
@@ -439,6 +440,7 @@ struct GeneratorOptions {
output_enum_identifiers
(
true
),
prefixed_enums
(
true
),
output_enum_identifiers
(
true
),
prefixed_enums
(
true
),
include_dependence_headers
(
true
),
include_dependence_headers
(
true
),
mutable_buffer
(
false
),
mutable_buffer
(
false
),
one_file
(
false
),
lang
(
GeneratorOptions
::
kJava
)
{}
lang
(
GeneratorOptions
::
kJava
)
{}
};
};
...
...
This diff is collapsed.
Click to expand it.
src/flatc.cpp
+
4
−
1
View file @
eab9cfbe
...
@@ -94,6 +94,7 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
...
@@ -94,6 +94,7 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
" --no-includes Don
\'
t generate include statements for included
\n
"
" --no-includes Don
\'
t generate include statements for included
\n
"
" schemas the generated file depends on (C++).
\n
"
" schemas the generated file depends on (C++).
\n
"
" --gen-mutable Generate accessors that can mutate buffers in-place.
\n
"
" --gen-mutable Generate accessors that can mutate buffers in-place.
\n
"
" --gen-onefile Generate single output file for C#
\n
"
" --raw-binary Allow binaries without file_indentifier to be read.
\n
"
" --raw-binary Allow binaries without file_indentifier to be read.
\n
"
" This may crash flatc given a mismatched schema.
\n
"
" This may crash flatc given a mismatched schema.
\n
"
" --proto Input is a .proto, translate to .fbs.
\n
"
" --proto Input is a .proto, translate to .fbs.
\n
"
...
@@ -146,7 +147,9 @@ int main(int argc, const char *argv[]) {
...
@@ -146,7 +147,9 @@ int main(int argc, const char *argv[]) {
printf
(
"warning: --gen-includes is deprecated (it is now default)
\n
"
);
printf
(
"warning: --gen-includes is deprecated (it is now default)
\n
"
);
}
else
if
(
arg
==
"--no-includes"
)
{
}
else
if
(
arg
==
"--no-includes"
)
{
opts
.
include_dependence_headers
=
false
;
opts
.
include_dependence_headers
=
false
;
}
else
if
(
arg
==
"--raw-binary"
)
{
}
else
if
(
arg
==
"--gen-onefile"
)
{
opts
.
one_file
=
true
;
}
else
if
(
arg
==
"--raw-binary"
)
{
raw_binary
=
true
;
raw_binary
=
true
;
}
else
if
(
arg
==
"--"
)
{
// Separator between text and binary inputs.
}
else
if
(
arg
==
"--"
)
{
// Separator between text and binary inputs.
binary_files_from
=
filenames
.
size
();
binary_files_from
=
filenames
.
size
();
...
...
This diff is collapsed.
Click to expand it.
src/idl_gen_general.cpp
+
26
−
9
View file @
eab9cfbe
...
@@ -858,8 +858,8 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -858,8 +858,8 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
// Save out the generated code for a single class while adding
// Save out the generated code for a single class while adding
// declaration boilerplate.
// declaration boilerplate.
static
bool
SaveClass
(
const
LanguageParameters
&
lang
,
const
Parser
&
parser
,
static
bool
SaveClass
(
const
LanguageParameters
&
lang
,
const
Parser
&
parser
,
const
Definition
&
def
,
const
std
::
string
&
classcode
,
const
std
::
string
&
def
name
,
const
std
::
string
&
classcode
,
const
std
::
string
&
path
,
bool
needs_includes
)
{
const
std
::
string
&
path
,
bool
needs_includes
,
bool
onefile
)
{
if
(
!
classcode
.
length
())
return
true
;
if
(
!
classcode
.
length
())
return
true
;
std
::
string
namespace_general
;
std
::
string
namespace_general
;
...
@@ -870,7 +870,10 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
...
@@ -870,7 +870,10 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
namespace_general
+=
"."
;
namespace_general
+=
"."
;
}
}
namespace_general
+=
*
it
;
namespace_general
+=
*
it
;
namespace_dir
+=
*
it
+
kPathSeparator
;
if
(
!
onefile
)
{
namespace_dir
+=
*
it
+
kPathSeparator
;
}
}
}
EnsureDirExists
(
namespace_dir
);
EnsureDirExists
(
namespace_dir
);
...
@@ -882,34 +885,48 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
...
@@ -882,34 +885,48 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
if
(
needs_includes
)
code
+=
lang
.
includes
;
if
(
needs_includes
)
code
+=
lang
.
includes
;
code
+=
classcode
;
code
+=
classcode
;
if
(
!
namespace_general
.
empty
())
code
+=
lang
.
namespace_end
;
if
(
!
namespace_general
.
empty
())
code
+=
lang
.
namespace_end
;
auto
filename
=
namespace_dir
+
def
.
name
+
lang
.
file_extension
;
auto
filename
=
namespace_dir
+
defname
+
lang
.
file_extension
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
}
bool
GenerateGeneral
(
const
Parser
&
parser
,
bool
GenerateGeneral
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
path
,
const
std
::
string
&
/*
file_name
*/
,
const
std
::
string
&
file_name
,
const
GeneratorOptions
&
opts
)
{
const
GeneratorOptions
&
opts
)
{
assert
(
opts
.
lang
<=
GeneratorOptions
::
kMAX
);
assert
(
opts
.
lang
<=
GeneratorOptions
::
kMAX
);
auto
lang
=
language_parameters
[
opts
.
lang
];
auto
lang
=
language_parameters
[
opts
.
lang
];
std
::
string
one_file_code
;
for
(
auto
it
=
parser
.
enums_
.
vec
.
begin
();
for
(
auto
it
=
parser
.
enums_
.
vec
.
begin
();
it
!=
parser
.
enums_
.
vec
.
end
();
++
it
)
{
it
!=
parser
.
enums_
.
vec
.
end
();
++
it
)
{
std
::
string
enumcode
;
std
::
string
enumcode
;
GenEnum
(
lang
,
**
it
,
&
enumcode
);
GenEnum
(
lang
,
**
it
,
&
enumcode
);
if
(
!
SaveClass
(
lang
,
parser
,
**
it
,
enumcode
,
path
,
false
))
if
(
opts
.
one_file
)
{
return
false
;
one_file_code
+=
enumcode
;
}
else
{
if
(
!
SaveClass
(
lang
,
parser
,
(
**
it
).
name
,
enumcode
,
path
,
false
,
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
;
GenStruct
(
lang
,
parser
,
**
it
,
&
declcode
);
GenStruct
(
lang
,
parser
,
**
it
,
&
declcode
);
if
(
!
SaveClass
(
lang
,
parser
,
**
it
,
declcode
,
path
,
true
))
if
(
opts
.
one_file
)
{
return
false
;
one_file_code
+=
declcode
;
}
else
{
if
(
!
SaveClass
(
lang
,
parser
,
(
**
it
).
name
,
declcode
,
path
,
true
,
false
))
return
false
;
}
}
}
if
(
opts
.
one_file
)
{
return
SaveClass
(
lang
,
parser
,
file_name
,
one_file_code
,
path
,
true
,
true
);
}
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment