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
f7961072
Commit
f7961072
authored
Apr 29, 2014
by
Jason Choy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for structs to the name annotation and fixed discriminant check names
parent
fb952aa6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
38 deletions
+55
-38
c++.capnp
c++/src/capnp/c++.capnp
+1
-1
c++.capnp.c++
c++/src/capnp/c++.capnp.c++
+20
-17
capnpc-c++.c++
c++/src/capnp/compiler/capnpc-c++.c++
+34
-20
No files found.
c++/src/capnp/c++.capnp
View file @
f7961072
...
...
@@ -25,4 +25,4 @@
$namespace("capnp::annotations");
annotation namespace(file): Text;
annotation name(field, enumerant): Text;
annotation name(field, enumerant
, struct, enum
): Text;
c++/src/capnp/c++.capnp.c++
View file @
f7961072
...
...
@@ -5,51 +5,54 @@
namespace
capnp
{
namespace
schemas
{
static
const
::
capnp
::
_
::
AlignedData
<
1
8
>
b_b9c6f99ebf805f2c
=
{
static
const
::
capnp
::
_
::
AlignedData
<
1
9
>
b_b9c6f99ebf805f2c
=
{
{
0
,
0
,
0
,
0
,
5
,
0
,
5
,
0
,
44
,
95
,
128
,
191
,
158
,
249
,
198
,
185
,
1
0
,
0
,
0
,
0
,
5
,
0
,
1
,
0
,
2
0
,
0
,
0
,
0
,
5
,
0
,
1
,
0
,
129
,
78
,
48
,
184
,
123
,
125
,
248
,
189
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
17
,
0
,
0
,
0
,
16
2
,
0
,
0
,
0
,
2
5
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
17
,
0
,
0
,
0
,
24
2
,
0
,
0
,
0
,
2
9
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
2
0
,
0
,
0
,
0
,
2
,
0
,
1
,
0
,
2
4
,
0
,
0
,
0
,
2
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
99
,
43
,
43
,
46
,
99
,
97
,
112
,
110
,
112
,
58
,
110
,
97
,
109
,
101
,
115
,
112
,
97
,
99
,
101
,
0
,
0
,
0
,
0
,
0
,
115
,
114
,
99
,
47
,
99
,
97
,
112
,
110
,
112
,
47
,
99
,
43
,
43
,
46
,
99
,
97
,
112
,
110
,
112
,
58
,
110
,
97
,
109
,
101
,
115
,
112
,
97
,
99
,
101
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0
,
1
,
0
,
12
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
}
};
const
::
capnp
::
_
::
RawSchema
s_b9c6f99ebf805f2c
=
{
0xb9c6f99ebf805f2c
,
b_b9c6f99ebf805f2c
.
words
,
1
8
,
nullptr
,
nullptr
,
0xb9c6f99ebf805f2c
,
b_b9c6f99ebf805f2c
.
words
,
1
9
,
nullptr
,
nullptr
,
0
,
0
,
nullptr
,
nullptr
,
nullptr
};
static
const
::
capnp
::
_
::
AlignedData
<
1
7
>
b_f264a779fef191ce
=
{
static
const
::
capnp
::
_
::
AlignedData
<
1
9
>
b_f264a779fef191ce
=
{
{
0
,
0
,
0
,
0
,
5
,
0
,
5
,
0
,
206
,
145
,
241
,
254
,
121
,
167
,
100
,
242
,
10
,
0
,
0
,
0
,
5
,
0
,
40
,
0
,
20
,
0
,
0
,
0
,
5
,
0
,
126
,
0
,
129
,
78
,
48
,
184
,
123
,
125
,
248
,
189
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
17
,
0
,
0
,
0
,
12
2
,
0
,
0
,
0
,
2
1
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
17
,
0
,
0
,
0
,
20
2
,
0
,
0
,
0
,
2
9
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
16
,
0
,
0
,
0
,
2
,
0
,
1
,
0
,
24
,
0
,
0
,
0
,
2
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
115
,
114
,
99
,
47
,
99
,
97
,
112
,
110
,
112
,
47
,
99
,
43
,
43
,
46
,
99
,
97
,
112
,
110
,
112
,
58
,
110
,
97
,
109
,
101
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
99
,
43
,
43
,
46
,
99
,
97
,
112
,
110
,
112
,
58
,
110
,
97
,
109
,
101
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0
,
1
,
0
,
12
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
}
};
const
::
capnp
::
_
::
RawSchema
s_f264a779fef191ce
=
{
0xf264a779fef191ce
,
b_f264a779fef191ce
.
words
,
1
7
,
nullptr
,
nullptr
,
0xf264a779fef191ce
,
b_f264a779fef191ce
.
words
,
1
9
,
nullptr
,
nullptr
,
0
,
0
,
nullptr
,
nullptr
,
nullptr
};
}
// namespace schemas
...
...
c++/src/capnp/compiler/capnpc-c++.c++
View file @
f7961072
...
...
@@ -191,14 +191,15 @@ private:
auto
node
=
schema
.
getProto
();
if
(
node
.
getScopeId
()
==
0
)
{
usedImports
.
insert
(
node
.
getId
());
for
(
auto
annotation
:
node
.
getAnnotations
())
{
if
(
annotation
.
getId
()
==
NAMESPACE_ANNOTATION_ID
)
{
return
kj
::
strTree
(
" ::"
,
annotation
.
getValue
().
getText
());
}
KJ_IF_MAYBE
(
ns
,
annotationValue
(
node
,
NAMESPACE_ANNOTATION_ID
))
{
return
kj
::
strTree
(
" ::"
,
ns
->
getText
());
}
return
kj
::
strTree
(
" "
);
}
else
{
Schema
parent
=
schemaLoader
.
get
(
node
.
getScopeId
());
KJ_IF_MAYBE
(
annotatedName
,
annotationValue
(
node
,
NAME_ANNOTATION_ID
))
{
return
kj
::
strTree
(
cppFullName
(
parent
),
"::"
,
annotatedName
->
getText
());
}
for
(
auto
nested
:
parent
.
getProto
().
getNestedNodes
())
{
if
(
nested
.
getId
()
==
node
.
getId
())
{
return
kj
::
strTree
(
cppFullName
(
parent
),
"::"
,
nested
.
getName
());
...
...
@@ -271,13 +272,23 @@ private:
KJ_UNREACHABLE
;
}
kj
::
StringPtr
enumerantName
(
schema
::
Enumerant
::
Reader
proto
)
{
template
<
typename
P
>
kj
::
Maybe
<
schema
::
Value
::
Reader
>
annotationValue
(
P
proto
,
uint64_t
annotationId
)
{
for
(
auto
annotation
:
proto
.
getAnnotations
())
{
if
(
annotation
.
getId
()
==
NAME_ANNOTATION_ID
)
{
return
annotation
.
getValue
()
.
getText
()
;
if
(
annotation
.
getId
()
==
annotationId
)
{
return
annotation
.
getValue
();
}
}
return
proto
.
getName
();
return
kj
::
Maybe
<
schema
::
Value
::
Reader
>
();
}
template
<
typename
P
>
kj
::
StringPtr
protoName
(
P
proto
)
{
KJ_IF_MAYBE
(
name
,
annotationValue
(
proto
,
NAME_ANNOTATION_ID
))
{
return
name
->
getText
();
}
else
{
return
proto
.
getName
();
}
}
kj
::
StringTree
literalValue
(
schema
::
Type
::
Reader
type
,
schema
::
Value
::
Reader
value
)
{
...
...
@@ -299,7 +310,7 @@ private:
if
(
value
.
getEnum
()
<
schema
.
getEnumerants
().
size
())
{
return
kj
::
strTree
(
cppFullName
(
schema
),
"::"
,
toUpperCase
(
enumerant
Name
(
schema
.
getEnumerants
()[
value
.
getEnum
()].
getProto
())));
toUpperCase
(
proto
Name
(
schema
.
getEnumerants
()[
value
.
getEnum
()].
getProto
())));
}
else
{
return
kj
::
strTree
(
"static_cast<"
,
cppFullName
(
schema
),
">("
,
value
.
getEnum
(),
")"
);
}
...
...
@@ -581,18 +592,12 @@ private:
FieldText
makeFieldText
(
kj
::
StringPtr
scope
,
StructSchema
::
Field
field
)
{
auto
proto
=
field
.
getProto
();
auto
baseName
=
proto
.
getName
();
for
(
auto
annotation
:
proto
.
getAnnotations
())
{
if
(
annotation
.
getId
()
==
NAME_ANNOTATION_ID
)
{
baseName
=
annotation
.
getValue
().
getText
();
break
;
}
}
auto
baseName
=
protoName
(
proto
);
kj
::
String
titleCase
=
toTitleCase
(
baseName
);
DiscriminantChecks
unionDiscrim
;
if
(
hasDiscriminantValue
(
proto
))
{
unionDiscrim
=
makeDiscriminantChecks
(
scope
,
proto
.
getName
()
,
field
.
getContainingStruct
());
unionDiscrim
=
makeDiscriminantChecks
(
scope
,
baseName
,
field
.
getContainingStruct
());
}
switch
(
proto
.
which
())
{
...
...
@@ -1170,6 +1175,9 @@ private:
StructText
makeStructText
(
kj
::
StringPtr
scope
,
kj
::
StringPtr
name
,
StructSchema
schema
,
kj
::
Array
<
kj
::
StringTree
>
nestedTypeDecls
)
{
auto
proto
=
schema
.
getProto
();
KJ_IF_MAYBE
(
annotatedName
,
annotationValue
(
proto
,
NAME_ANNOTATION_ID
))
{
name
=
annotatedName
->
getText
();
}
auto
fullName
=
kj
::
str
(
scope
,
name
);
auto
subScope
=
kj
::
str
(
fullName
,
"::"
);
auto
fieldTexts
=
KJ_MAP
(
f
,
schema
.
getFields
())
{
return
makeFieldText
(
subScope
,
f
);
};
...
...
@@ -1192,7 +1200,7 @@ private:
" enum Which: uint16_t {
\n
"
,
KJ_MAP
(
f
,
structNode
.
getFields
())
{
if
(
hasDiscriminantValue
(
f
))
{
return
kj
::
strTree
(
" "
,
toUpperCase
(
f
.
getName
(
)),
",
\n
"
);
return
kj
::
strTree
(
" "
,
toUpperCase
(
protoName
(
f
)),
",
\n
"
);
}
else
{
return
kj
::
strTree
();
}
...
...
@@ -1556,6 +1564,9 @@ private:
NodeText
makeNodeText
(
kj
::
StringPtr
namespace_
,
kj
::
StringPtr
scope
,
kj
::
StringPtr
name
,
Schema
schema
)
{
auto
proto
=
schema
.
getProto
();
KJ_IF_MAYBE
(
annotatedName
,
annotationValue
(
proto
,
NAME_ANNOTATION_ID
))
{
name
=
annotatedName
->
getText
();
}
auto
fullName
=
kj
::
str
(
scope
,
name
);
auto
subScope
=
kj
::
str
(
fullName
,
"::"
);
auto
hexId
=
kj
::
hex
(
proto
.
getId
());
...
...
@@ -1711,6 +1722,9 @@ private:
kj
::
StringPtr
name
,
Schema
schema
,
kj
::
Array
<
kj
::
StringTree
>
nestedTypeDecls
)
{
auto
proto
=
schema
.
getProto
();
KJ_IF_MAYBE
(
annotatedName
,
annotationValue
(
proto
,
NAME_ANNOTATION_ID
))
{
name
=
annotatedName
->
getText
();
}
auto
fullName
=
kj
::
str
(
scope
,
name
);
auto
hexId
=
kj
::
hex
(
proto
.
getId
());
...
...
@@ -1751,7 +1765,7 @@ private:
scope
.
size
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
" enum class "
,
name
,
": uint16_t {
\n
"
,
KJ_MAP
(
e
,
enumerants
)
{
return
kj
::
strTree
(
" "
,
toUpperCase
(
enumerant
Name
(
e
.
getProto
())),
",
\n
"
);
return
kj
::
strTree
(
" "
,
toUpperCase
(
proto
Name
(
e
.
getProto
())),
",
\n
"
);
},
" };
\n
"
"
\n
"
),
...
...
@@ -1759,7 +1773,7 @@ private:
scope
.
size
()
>
0
?
kj
::
strTree
()
:
kj
::
strTree
(
"enum class "
,
name
,
": uint16_t {
\n
"
,
KJ_MAP
(
e
,
enumerants
)
{
return
kj
::
strTree
(
" "
,
toUpperCase
(
enumerant
Name
(
e
.
getProto
())),
",
\n
"
);
return
kj
::
strTree
(
" "
,
toUpperCase
(
proto
Name
(
e
.
getProto
())),
",
\n
"
);
},
"};
\n
"
"
\n
"
),
...
...
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