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
9baabb1d
Commit
9baabb1d
authored
Apr 20, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fully implement and test 'using'.
parent
08c0a048
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
4 deletions
+34
-4
encoding-test.c++
c++/src/capnproto/encoding-test.c++
+11
-0
test-util.h
c++/src/capnproto/test-util.h
+1
-0
test.capnp
c++/src/capnproto/test.capnp
+8
-0
Parser.hs
compiler/src/Parser.hs
+14
-4
No files found.
c++/src/capnproto/encoding-test.c++
View file @
9baabb1d
...
...
@@ -287,6 +287,10 @@ TEST(Encoding, UnionDefault) {
}
}
// =======================================================================================
// Tests of generated code, not really of the encoding.
// TODO(cleanup): Move to a different test?
TEST
(
Encoding
,
NestedTypes
)
{
// This is more of a test of the generated code than the encoding.
...
...
@@ -310,6 +314,13 @@ TEST(Encoding, Imports) {
checkTestMessage
(
root
.
asReader
().
getField
());
}
TEST
(
Encoding
,
Using
)
{
MallocMessageBuilder
builder
;
TestUsing
::
Reader
reader
=
builder
.
getRoot
<
TestUsing
>
().
asReader
();
EXPECT_EQ
(
TestNestedTypes
::
NestedEnum
::
BAR
,
reader
.
getOuterNestedEnum
());
EXPECT_EQ
(
TestNestedTypes
::
NestedStruct
::
NestedEnum
::
QUUX
,
reader
.
getInnerNestedEnum
());
}
}
// namespace
}
// namespace internal
}
// namespace capnproto
c++/src/capnproto/test-util.h
View file @
9baabb1d
...
...
@@ -56,6 +56,7 @@ using ::capnproto::test::TestEnum;
using
::
capnproto
::
test
::
TestUnion
;
using
::
capnproto
::
test
::
TestUnionDefaults
;
using
::
capnproto
::
test
::
TestNestedTypes
;
using
::
capnproto
::
test
::
TestUsing
;
void
initTestMessage
(
test
::
TestAllTypes
::
Builder
builder
);
void
initTestMessage
(
test
::
TestDefaults
::
Builder
builder
);
...
...
c++/src/capnproto/test.capnp
View file @
9baabb1d
...
...
@@ -266,3 +266,11 @@ struct TestNestedTypes {
outerNestedEnum @1 :NestedEnum = bar;
innerNestedEnum @2 :NestedStruct.NestedEnum = quux;
}
struct TestUsing {
using OuterNestedEnum = TestNestedTypes.NestedEnum;
using TestNestedTypes.NestedStruct.NestedEnum;
outerNestedEnum @1 :OuterNestedEnum = bar;
innerNestedEnum @0 :NestedEnum = quux;
}
compiler/src/Parser.hs
View file @
9baabb1d
...
...
@@ -173,9 +173,19 @@ topLine (Just statements) = liftM Left $ typeDecl statements
usingDecl
=
do
usingKeyword
name
<-
located
typeIdentifier
equalsSign
maybeName
<-
optionMaybe
$
try
(
do
name
<-
located
typeIdentifier
equalsSign
return
name
)
target
<-
declName
name
<-
let
inferredName
=
case
target
of
AbsoluteName
s
->
return
s
RelativeName
s
->
return
s
ImportName
_
->
fail
"When 'using' an 'import' you must specify a name, e.g.:
\
\
using Foo = import
\"
foo.capnp
\"
;"
MemberName
_
s
->
return
s
in
maybe
inferredName
return
maybeName
return
(
UsingDecl
name
target
)
constantDecl
=
do
...
...
@@ -216,7 +226,7 @@ structDecl statements = do
return
(
StructDecl
name
annotations
children
)
structLine
::
Maybe
[
Located
Statement
]
->
TokenParser
Declaration
structLine
Nothing
=
constantDecl
<|>
fieldDecl
<|>
annotationDecl
structLine
Nothing
=
usingDecl
<|>
constantDecl
<|>
fieldDecl
<|>
annotationDecl
structLine
(
Just
statements
)
=
typeDecl
statements
<|>
unionDecl
statements
<|>
unionDecl
statements
unionDecl
statements
=
do
...
...
@@ -272,7 +282,7 @@ interfaceDecl statements = do
return
(
InterfaceDecl
name
annotations
children
)
interfaceLine
::
Maybe
[
Located
Statement
]
->
TokenParser
Declaration
interfaceLine
Nothing
=
constantDecl
<|>
methodDecl
<|>
annotationDecl
interfaceLine
Nothing
=
usingDecl
<|>
constantDecl
<|>
methodDecl
<|>
annotationDecl
interfaceLine
(
Just
statements
)
=
typeDecl
statements
methodDecl
=
do
...
...
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