Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
capnproto
Commits
24dc6ae7
Commit
24dc6ae7
authored
Apr 01, 2014
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When an RPC method name matches a C++ keyword, add an underscore to avoid compilation errors.
parent
45f3133d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
3 deletions
+62
-3
capability-test.c++
c++/src/capnp/capability-test.c++
+26
-0
capnpc-c++.c++
c++/src/capnp/compiler/capnpc-c++.c++
+29
-3
test.capnp
c++/src/capnp/test.capnp
+7
-0
No files found.
c++/src/capnp/capability-test.c++
View file @
24dc6ae7
...
...
@@ -742,6 +742,32 @@ TEST(Capability, Lists) {
verifyClient
(
dynamicListReader
[
2
].
as
<
DynamicCapability
>
(),
callCount3
,
waitScope
);
}
TEST
(
Capability
,
KeywordMethods
)
{
// Verify that keywords are only munged where necessary.
kj
::
EventLoop
loop
;
kj
::
WaitScope
waitScope
(
loop
);
bool
called
=
false
;
class
TestKeywordMethodsImpl
:
public
test
::
TestKeywordMethods
::
Server
{
public
:
TestKeywordMethodsImpl
(
bool
&
called
)
:
called
(
called
)
{}
kj
::
Promise
<
void
>
delete_
(
DeleteContext
context
)
override
{
called
=
true
;
return
kj
::
READY_NOW
;
}
private
:
bool
&
called
;
};
test
::
TestKeywordMethods
::
Client
client
=
kj
::
heap
<
TestKeywordMethodsImpl
>
(
called
);
client
.
deleteRequest
().
send
().
wait
(
waitScope
);
EXPECT_TRUE
(
called
);
}
}
// namespace
}
// namespace _
}
// namespace capnp
c++/src/capnp/compiler/capnpc-c++.c++
View file @
24dc6ae7
...
...
@@ -139,6 +139,31 @@ kj::StringPtr baseName(kj::StringPtr path) {
}
}
kj
::
String
safeIdentifier
(
kj
::
StringPtr
identifier
)
{
// Given a desired identifier name, munge it to make it safe for use in generated code.
//
// If the identifier is a keyword, this adds an underscore to the end.
static
const
std
::
set
<
kj
::
StringPtr
>
keywords
({
"alignas"
,
"alignof"
,
"and"
,
"and_eq"
,
"asm"
,
"auto"
,
"bitand"
,
"bitor"
,
"bool"
,
"break"
,
"case"
,
"catch"
,
"char"
,
"char16_t"
,
"char32_t"
,
"class"
,
"compl"
,
"const"
,
"constexpr"
,
"const_cast"
,
"continue"
,
"decltype"
,
"default"
,
"delete"
,
"do"
,
"double"
,
"dynamic_cast"
,
"else"
,
"enum"
,
"explicit"
,
"export"
,
"extern"
,
"false"
,
"float"
,
"for"
,
"friend"
,
"goto"
,
"if"
,
"inline"
,
"int"
,
"long"
,
"mutable"
,
"namespace"
,
"new"
,
"noexcept"
,
"not"
,
"not_eq"
,
"nullptr"
,
"operator"
,
"or"
,
"or_eq"
,
"private"
,
"protected"
,
"public"
,
"register"
,
"reinterpret_cast"
,
"return"
,
"short"
,
"signed"
,
"sizeof"
,
"static"
,
"static_assert"
,
"static_cast"
,
"struct"
,
"switch"
,
"template"
,
"this"
,
"thread_local"
,
"throw"
,
"true"
,
"try"
,
"typedef"
,
"typeid"
,
"typename"
,
"union"
,
"unsigned"
,
"using"
,
"virtual"
,
"void"
,
"volatile"
,
"wchar_t"
,
"while"
,
"xor"
,
"xor_eq"
});
if
(
keywords
.
count
(
identifier
)
>
0
)
{
return
kj
::
str
(
identifier
,
'_'
);
}
else
{
return
kj
::
heapString
(
identifier
);
}
}
// =======================================================================================
class
CapnpcCppMain
{
...
...
@@ -1197,6 +1222,7 @@ private:
auto
titleCase
=
toTitleCase
(
name
);
auto
paramSchema
=
schemaLoader
.
get
(
proto
.
getParamStructType
()).
asStruct
();
auto
resultSchema
=
schemaLoader
.
get
(
proto
.
getResultStructType
()).
asStruct
();
auto
identifierName
=
safeIdentifier
(
name
);
auto
paramProto
=
paramSchema
.
getProto
();
auto
resultProto
=
resultSchema
.
getProto
();
...
...
@@ -1228,7 +1254,7 @@ private:
" typedef "
,
resultType
,
" "
,
titleCase
,
"Results;
\n
"
),
" typedef ::capnp::CallContext<"
,
shortParamType
,
", "
,
shortResultType
,
"> "
,
titleCase
,
"Context;
\n
"
" virtual ::kj::Promise<void> "
,
n
ame
,
"("
,
titleCase
,
"Context context);
\n
"
),
" virtual ::kj::Promise<void> "
,
identifierN
ame
,
"("
,
titleCase
,
"Context context);
\n
"
),
kj
::
strTree
(),
...
...
@@ -1238,7 +1264,7 @@ private:
" return newCall<"
,
paramType
,
", "
,
resultType
,
">(
\n
"
" 0x"
,
interfaceIdHex
,
"ull, "
,
methodId
,
", sizeHint);
\n
"
"}
\n
"
"::kj::Promise<void> "
,
interfaceName
,
"::Server::"
,
n
ame
,
"("
,
titleCase
,
"Context) {
\n
"
"::kj::Promise<void> "
,
interfaceName
,
"::Server::"
,
identifierN
ame
,
"("
,
titleCase
,
"Context) {
\n
"
" return ::capnp::Capability::Server::internalUnimplemented(
\n
"
"
\"
"
,
interfaceProto
.
getDisplayName
(),
"
\"
,
\"
"
,
name
,
"
\"
,
\n
"
" 0x"
,
interfaceIdHex
,
"ull, "
,
methodId
,
");
\n
"
...
...
@@ -1246,7 +1272,7 @@ private:
kj
::
strTree
(
" case "
,
methodId
,
":
\n
"
" return "
,
n
ame
,
"(::capnp::Capability::Server::internalGetTypedContext<
\n
"
" return "
,
identifierN
ame
,
"(::capnp::Capability::Server::internalGetTypedContext<
\n
"
" "
,
paramType
,
", "
,
resultType
,
">(context));
\n
"
)
};
}
...
...
c++/src/capnp/test.capnp
View file @
24dc6ae7
...
...
@@ -661,6 +661,13 @@ interface TestMoreStuff extends(TestCallOrder) {
methodWithDefaults @8 (a :Text, b :UInt32 = 123, c :Text = "foo") -> (d :Text, e :Text = "bar");
}
interface TestKeywordMethods {
delete @0 ();
class @1 ();
void @2 ();
return @3 ();
}
struct TestSturdyRefHostId {
host @0 :Text;
}
...
...
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