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
4cd71d67
Commit
4cd71d67
authored
8 years ago
by
Flier Lu
Committed by
Wouter van Oortmerssen
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
GO: add _ postfix to identiy conflict golang keyword (#4221)
* add _ postfix to identiy conflict golang keyword * make VS2010 happy
parent
d9bc5ec0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/idl_gen_go.cpp
+21
-5
21 additions, 5 deletions
src/idl_gen_go.cpp
with
21 additions
and
5 deletions
src/idl_gen_go.cpp
+
21
−
5
View file @
4cd71d67
...
...
@@ -35,6 +35,13 @@
namespace
flatbuffers
{
namespace
go
{
// see https://golang.org/ref/spec#Keywords
static
const
char
*
g_golang_keywords
[]
=
{
"break"
,
"default"
,
"func"
,
"interface"
,
"select"
,
"case"
,
"defer"
,
"go"
,
"map"
,
"struct"
,
"chan"
,
"else"
,
"goto"
,
"package"
,
"switch"
,
"const"
,
"fallthrough"
,
"if"
,
"range"
,
"type"
,
"continue"
,
"for"
,
"import"
,
"return"
,
"var"
,
};
static
std
::
string
GenGetter
(
const
Type
&
type
);
static
std
::
string
GenMethod
(
const
FieldDef
&
field
);
static
void
GenStructBuilder
(
const
StructDef
&
struct_def
,
...
...
@@ -43,6 +50,15 @@ static void GenReceiver(const StructDef &struct_def, std::string *code_ptr);
static
std
::
string
GenTypeBasic
(
const
Type
&
type
);
static
std
::
string
GenTypeGet
(
const
Type
&
type
);
static
std
::
string
TypeName
(
const
FieldDef
&
field
);
static
std
::
string
GoIdentity
(
const
std
::
string
&
name
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
g_golang_keywords
)
/
sizeof
(
g_golang_keywords
[
0
]);
i
++
)
{
if
(
name
==
g_golang_keywords
[
i
])
{
return
MakeCamel
(
name
+
"_"
,
false
);
}
}
return
MakeCamel
(
name
,
false
);
}
// Most field accessors need to retrieve and test the field offset first,
...
...
@@ -368,7 +384,7 @@ static void StructBuilderArgs(const StructDef &struct_def,
}
else
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
(
std
::
string
)
", "
+
nameprefix
;
code
+=
MakeCamel
(
field
.
name
,
false
);
code
+=
GoIdentity
(
field
.
name
);
code
+=
" "
+
GenTypeBasic
(
field
.
value
.
type
);
}
}
...
...
@@ -400,7 +416,7 @@ static void StructBuilderBody(const StructDef &struct_def,
code_ptr
);
}
else
{
code
+=
"
\t
builder.Prepend"
+
GenMethod
(
field
)
+
"("
;
code
+=
nameprefix
+
MakeCamel
(
field
.
name
,
false
)
+
")
\n
"
;
code
+=
nameprefix
+
GoIdentity
(
field
.
name
)
+
")
\n
"
;
}
}
}
...
...
@@ -430,7 +446,7 @@ static void BuildFieldOfTable(const StructDef &struct_def,
std
::
string
&
code
=
*
code_ptr
;
code
+=
"func "
+
struct_def
.
name
+
"Add"
+
MakeCamel
(
field
.
name
);
code
+=
"(builder *flatbuffers.Builder, "
;
code
+=
MakeCamel
(
field
.
name
,
false
)
+
" "
;
code
+=
GoIdentity
(
field
.
name
)
+
" "
;
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
)
&&
(
!
struct_def
.
fixed
))
{
code
+=
"flatbuffers.UOffsetT"
;
}
else
{
...
...
@@ -443,9 +459,9 @@ static void BuildFieldOfTable(const StructDef &struct_def,
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
)
&&
(
!
struct_def
.
fixed
))
{
code
+=
"flatbuffers.UOffsetT"
;
code
+=
"("
;
code
+=
MakeCamel
(
field
.
name
,
false
)
+
")"
;
code
+=
GoIdentity
(
field
.
name
)
+
")"
;
}
else
{
code
+=
MakeCamel
(
field
.
name
,
false
);
code
+=
GoIdentity
(
field
.
name
);
}
code
+=
", "
+
field
.
value
.
constant
;
code
+=
")
\n
}
\n
"
;
...
...
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