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
f651e5cf
Commit
f651e5cf
authored
Aug 23, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverse order of KJ_MAP to be consistent with e.g. KJ_IF_MAYBE.
parent
e65d5d0f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
54 deletions
+54
-54
capnpc-c++.c++
c++/src/capnp/compiler/capnpc-c++.c++
+38
-38
capnpc-capnp.c++
c++/src/capnp/compiler/capnpc-capnp.c++
+9
-9
compiler.c++
c++/src/capnp/compiler/compiler.c++
+1
-1
node-translator.c++
c++/src/capnp/compiler/node-translator.c++
+1
-1
stringify.c++
c++/src/capnp/stringify.c++
+1
-1
array-test.c++
c++/src/kj/array-test.c++
+1
-1
array.h
c++/src/kj/array.h
+3
-3
No files found.
c++/src/capnp/compiler/capnpc-c++.c++
View file @
f651e5cf
...
@@ -119,9 +119,9 @@ struct OrderByName {
...
@@ -119,9 +119,9 @@ struct OrderByName {
template
<
typename
MemberList
>
template
<
typename
MemberList
>
kj
::
Array
<
uint
>
makeMembersByName
(
MemberList
&&
members
)
{
kj
::
Array
<
uint
>
makeMembersByName
(
MemberList
&&
members
)
{
auto
sorted
=
KJ_MAP
(
member
s
,
member
)
{
return
member
;
};
auto
sorted
=
KJ_MAP
(
member
,
members
)
{
return
member
;
};
std
::
sort
(
sorted
.
begin
(),
sorted
.
end
(),
OrderByName
());
std
::
sort
(
sorted
.
begin
(),
sorted
.
end
(),
OrderByName
());
return
KJ_MAP
(
sorted
,
member
)
{
return
member
.
getIndex
();
};
return
KJ_MAP
(
member
,
sorted
)
{
return
member
.
getIndex
();
};
}
}
kj
::
StringPtr
baseName
(
kj
::
StringPtr
path
)
{
kj
::
StringPtr
baseName
(
kj
::
StringPtr
path
)
{
...
@@ -534,7 +534,7 @@ private:
...
@@ -534,7 +534,7 @@ private:
"inline bool "
,
scope
,
"Reader::has"
,
titleCase
,
"() const {
\n
"
,
"inline bool "
,
scope
,
"Reader::has"
,
titleCase
,
"() const {
\n
"
,
unionDiscrim
.
has
,
unionDiscrim
.
has
,
" return "
,
" return "
,
kj
::
StringTree
(
KJ_MAP
(
slot
s
,
slot
)
{
kj
::
StringTree
(
KJ_MAP
(
slot
,
slots
)
{
switch
(
sectionFor
(
slot
.
whichType
))
{
switch
(
sectionFor
(
slot
.
whichType
))
{
case
Section
:
:
NONE
:
case
Section
:
:
NONE
:
return
kj
::
strTree
();
return
kj
::
strTree
();
...
@@ -552,7 +552,7 @@ private:
...
@@ -552,7 +552,7 @@ private:
"inline bool "
,
scope
,
"Builder::has"
,
titleCase
,
"() {
\n
"
,
"inline bool "
,
scope
,
"Builder::has"
,
titleCase
,
"() {
\n
"
,
unionDiscrim
.
has
,
unionDiscrim
.
has
,
" return "
,
" return "
,
kj
::
StringTree
(
KJ_MAP
(
slot
s
,
slot
)
{
kj
::
StringTree
(
KJ_MAP
(
slot
,
slots
)
{
switch
(
sectionFor
(
slot
.
whichType
))
{
switch
(
sectionFor
(
slot
.
whichType
))
{
case
Section
:
:
NONE
:
case
Section
:
:
NONE
:
return
kj
::
strTree
();
return
kj
::
strTree
();
...
@@ -577,7 +577,7 @@ private:
...
@@ -577,7 +577,7 @@ private:
"}
\n
"
"}
\n
"
"inline "
,
scope
,
titleCase
,
"::Builder "
,
scope
,
"Builder::init"
,
titleCase
,
"() {
\n
"
,
"inline "
,
scope
,
titleCase
,
"::Builder "
,
scope
,
"Builder::init"
,
titleCase
,
"() {
\n
"
,
unionDiscrim
.
set
,
unionDiscrim
.
set
,
KJ_MAP
(
slot
s
,
slot
)
{
KJ_MAP
(
slot
,
slots
)
{
switch
(
sectionFor
(
slot
.
whichType
))
{
switch
(
sectionFor
(
slot
.
whichType
))
{
case
Section
:
:
NONE
:
case
Section
:
:
NONE
:
return
kj
::
strTree
();
return
kj
::
strTree
();
...
@@ -1094,10 +1094,10 @@ private:
...
@@ -1094,10 +1094,10 @@ private:
// Convert the encoded schema to a literal byte array.
// Convert the encoded schema to a literal byte array.
kj
::
ArrayPtr
<
const
word
>
rawSchema
=
schema
.
asUncheckedMessage
();
kj
::
ArrayPtr
<
const
word
>
rawSchema
=
schema
.
asUncheckedMessage
();
auto
schemaLiteral
=
kj
::
StringTree
(
KJ_MAP
(
rawSchema
,
w
)
{
auto
schemaLiteral
=
kj
::
StringTree
(
KJ_MAP
(
w
,
rawSchema
)
{
const
byte
*
bytes
=
reinterpret_cast
<
const
byte
*>
(
&
w
);
const
byte
*
bytes
=
reinterpret_cast
<
const
byte
*>
(
&
w
);
return
kj
::
strTree
(
KJ_MAP
(
kj
::
range
<
uint
>
(
0
,
sizeof
(
word
)),
i
)
{
return
kj
::
strTree
(
KJ_MAP
(
i
,
kj
::
range
<
uint
>
(
0
,
sizeof
(
word
))
)
{
auto
text
=
kj
::
toCharSequence
(
kj
::
implicitCast
<
uint
>
(
bytes
[
i
]));
auto
text
=
kj
::
toCharSequence
(
kj
::
implicitCast
<
uint
>
(
bytes
[
i
]));
return
kj
::
strTree
(
kj
::
repeat
(
' '
,
4
-
text
.
size
()),
text
,
","
);
return
kj
::
strTree
(
kj
::
repeat
(
' '
,
4
-
text
.
size
()),
text
,
","
);
});
});
...
@@ -1140,15 +1140,15 @@ private:
...
@@ -1140,15 +1140,15 @@ private:
" {"
,
kj
::
mv
(
schemaLiteral
),
" }
\n
"
" {"
,
kj
::
mv
(
schemaLiteral
),
" }
\n
"
"};
\n
"
"};
\n
"
"static const ::capnp::_::RawSchema* const d_"
,
hexId
,
"[] = {
\n
"
,
"static const ::capnp::_::RawSchema* const d_"
,
hexId
,
"[] = {
\n
"
,
KJ_MAP
(
dep
s
,
depId
)
{
KJ_MAP
(
dep
Id
,
deps
)
{
return
kj
::
strTree
(
" &s_"
,
kj
::
hex
(
depId
),
",
\n
"
);
return
kj
::
strTree
(
" &s_"
,
kj
::
hex
(
depId
),
",
\n
"
);
},
},
"};
\n
"
"};
\n
"
"static const uint16_t m_"
,
hexId
,
"[] = {"
,
"static const uint16_t m_"
,
hexId
,
"[] = {"
,
kj
::
StringTree
(
KJ_MAP
(
membersByName
,
index
)
{
return
kj
::
strTree
(
index
);
},
", "
),
kj
::
StringTree
(
KJ_MAP
(
index
,
membersByName
)
{
return
kj
::
strTree
(
index
);
},
", "
),
"};
\n
"
"};
\n
"
"static const uint16_t i_"
,
hexId
,
"[] = {"
,
"static const uint16_t i_"
,
hexId
,
"[] = {"
,
kj
::
StringTree
(
KJ_MAP
(
membersByDiscrim
,
index
)
{
return
kj
::
strTree
(
index
);
},
", "
),
kj
::
StringTree
(
KJ_MAP
(
index
,
membersByDiscrim
)
{
return
kj
::
strTree
(
index
);
},
", "
),
"};
\n
"
"};
\n
"
"const ::capnp::_::RawSchema s_"
,
hexId
,
" = {
\n
"
"const ::capnp::_::RawSchema s_"
,
hexId
,
" = {
\n
"
" 0x"
,
hexId
,
", b_"
,
hexId
,
".words, "
,
rawSchema
.
size
(),
", d_"
,
hexId
,
", m_"
,
hexId
,
",
\n
"
" 0x"
,
hexId
,
", b_"
,
hexId
,
".words, "
,
rawSchema
.
size
(),
", d_"
,
hexId
,
", m_"
,
hexId
,
",
\n
"
...
@@ -1161,7 +1161,7 @@ private:
...
@@ -1161,7 +1161,7 @@ private:
case
schema
:
:
Node
::
STRUCT
:
{
case
schema
:
:
Node
::
STRUCT
:
{
auto
fieldTexts
=
auto
fieldTexts
=
KJ_MAP
(
schema
.
asStruct
().
getFields
(),
f
)
{
return
makeFieldText
(
subScope
,
f
);
};
KJ_MAP
(
f
,
schema
.
asStruct
().
getFields
()
)
{
return
makeFieldText
(
subScope
,
f
);
};
auto
structNode
=
proto
.
getStruct
();
auto
structNode
=
proto
.
getStruct
();
uint
discrimOffset
=
structNode
.
getDiscriminantOffset
();
uint
discrimOffset
=
structNode
.
getDiscriminantOffset
();
...
@@ -1178,7 +1178,7 @@ private:
...
@@ -1178,7 +1178,7 @@ private:
" class Builder;
\n
"
,
" class Builder;
\n
"
,
structNode
.
getDiscriminantCount
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
structNode
.
getDiscriminantCount
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
" enum Which: uint16_t {
\n
"
,
" enum Which: uint16_t {
\n
"
,
KJ_MAP
(
structNode
.
getFields
(),
f
)
{
KJ_MAP
(
f
,
structNode
.
getFields
()
)
{
if
(
f
.
hasDiscriminantValue
())
{
if
(
f
.
hasDiscriminantValue
())
{
return
kj
::
strTree
(
" "
,
toUpperCase
(
f
.
getName
()),
",
\n
"
);
return
kj
::
strTree
(
" "
,
toUpperCase
(
f
.
getName
()),
",
\n
"
);
}
else
{
}
else
{
...
@@ -1186,17 +1186,17 @@ private:
...
@@ -1186,17 +1186,17 @@ private:
}
}
},
},
" };
\n
"
),
" };
\n
"
),
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
outerTypeDecl
);
},
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
outerTypeDecl
);
},
"};
\n
"
"};
\n
"
"
\n
"
,
"
\n
"
,
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
outerTypeDef
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
outerTypeDef
);
}),
kj
::
strTree
(
kj
::
strTree
(
makeReaderDef
(
fullName
,
name
,
structNode
.
getDiscriminantCount
()
!=
0
,
makeReaderDef
(
fullName
,
name
,
structNode
.
getDiscriminantCount
()
!=
0
,
KJ_MAP
(
f
ieldTexts
,
f
)
{
return
kj
::
mv
(
f
.
readerMethodDecls
);
}),
KJ_MAP
(
f
,
fieldTexts
)
{
return
kj
::
mv
(
f
.
readerMethodDecls
);
}),
makeBuilderDef
(
fullName
,
name
,
structNode
.
getDiscriminantCount
()
!=
0
,
makeBuilderDef
(
fullName
,
name
,
structNode
.
getDiscriminantCount
()
!=
0
,
KJ_MAP
(
f
ieldTexts
,
f
)
{
return
kj
::
mv
(
f
.
builderMethodDecls
);
}),
KJ_MAP
(
f
,
fieldTexts
)
{
return
kj
::
mv
(
f
.
builderMethodDecls
);
}),
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
readerBuilderDefs
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
readerBuilderDefs
);
}),
kj
::
strTree
(
kj
::
strTree
(
structNode
.
getDiscriminantCount
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
structNode
.
getDiscriminantCount
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
...
@@ -1207,16 +1207,16 @@ private:
...
@@ -1207,16 +1207,16 @@ private:
" return _builder.getDataField<Which>("
,
discrimOffset
,
" * ::capnp::ELEMENTS);
\n
"
" return _builder.getDataField<Which>("
,
discrimOffset
,
" * ::capnp::ELEMENTS);
\n
"
"}
\n
"
"}
\n
"
"
\n
"
),
"
\n
"
),
KJ_MAP
(
f
ieldTexts
,
f
)
{
return
kj
::
mv
(
f
.
inlineMethodDefs
);
},
KJ_MAP
(
f
,
fieldTexts
)
{
return
kj
::
mv
(
f
.
inlineMethodDefs
);
},
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
inlineMethodDefs
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
inlineMethodDefs
);
}),
kj
::
strTree
(
kj
::
strTree
(
kj
::
mv
(
schemaDecl
),
kj
::
mv
(
schemaDecl
),
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpSchemaDecls
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
capnpSchemaDecls
);
}),
kj
::
strTree
(
kj
::
strTree
(
kj
::
mv
(
schemaDef
),
kj
::
mv
(
schemaDef
),
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpSchemaDefs
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
capnpSchemaDefs
);
}),
kj
::
strTree
(
kj
::
strTree
(
"CAPNP_DECLARE_STRUCT(
\n
"
"CAPNP_DECLARE_STRUCT(
\n
"
...
@@ -1225,12 +1225,12 @@ private:
...
@@ -1225,12 +1225,12 @@ private:
structNode
.
getPointerCount
(),
", "
,
structNode
.
getPointerCount
(),
", "
,
FIELD_SIZE_NAMES
[
static_cast
<
uint
>
(
structNode
.
getPreferredListEncoding
())],
FIELD_SIZE_NAMES
[
static_cast
<
uint
>
(
structNode
.
getPreferredListEncoding
())],
");
\n
"
,
");
\n
"
,
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpPrivateDecls
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
capnpPrivateDecls
);
}),
kj
::
strTree
(
kj
::
strTree
(
"CAPNP_DEFINE_STRUCT(
\n
"
"CAPNP_DEFINE_STRUCT(
\n
"
" "
,
namespace_
,
"::"
,
fullName
,
");
\n
"
,
" "
,
namespace_
,
"::"
,
fullName
,
");
\n
"
,
KJ_MAP
(
n
estedTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpPrivateDefs
);
}),
KJ_MAP
(
n
,
nestedTexts
)
{
return
kj
::
mv
(
n
.
capnpPrivateDefs
);
}),
};
};
}
}
...
@@ -1240,7 +1240,7 @@ private:
...
@@ -1240,7 +1240,7 @@ private:
return
NodeText
{
return
NodeText
{
scope
.
size
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
scope
.
size
()
==
0
?
kj
::
strTree
()
:
kj
::
strTree
(
" enum class "
,
name
,
": uint16_t {
\n
"
,
" enum class "
,
name
,
": uint16_t {
\n
"
,
KJ_MAP
(
e
numerants
,
e
)
{
KJ_MAP
(
e
,
enumerants
)
{
return
kj
::
strTree
(
" "
,
toUpperCase
(
e
.
getProto
().
getName
()),
",
\n
"
);
return
kj
::
strTree
(
" "
,
toUpperCase
(
e
.
getProto
().
getName
()),
",
\n
"
);
},
},
" };
\n
"
" };
\n
"
...
@@ -1248,7 +1248,7 @@ private:
...
@@ -1248,7 +1248,7 @@ private:
scope
.
size
()
>
0
?
kj
::
strTree
()
:
kj
::
strTree
(
scope
.
size
()
>
0
?
kj
::
strTree
()
:
kj
::
strTree
(
"enum class "
,
name
,
": uint16_t {
\n
"
,
"enum class "
,
name
,
": uint16_t {
\n
"
,
KJ_MAP
(
e
numerants
,
e
)
{
KJ_MAP
(
e
,
enumerants
)
{
return
kj
::
strTree
(
" "
,
toUpperCase
(
e
.
getProto
().
getName
()),
",
\n
"
);
return
kj
::
strTree
(
" "
,
toUpperCase
(
e
.
getProto
().
getName
()),
",
\n
"
);
},
},
"};
\n
"
"};
\n
"
...
@@ -1363,7 +1363,7 @@ private:
...
@@ -1363,7 +1363,7 @@ private:
}
}
}
}
auto
nodeTexts
=
KJ_MAP
(
n
ode
.
getNestedNodes
(),
nested
)
{
auto
nodeTexts
=
KJ_MAP
(
n
ested
,
node
.
getNestedNodes
()
)
{
return
makeNodeText
(
namespacePrefix
,
""
,
nested
.
getName
(),
schemaLoader
.
get
(
nested
.
getId
()));
return
makeNodeText
(
namespacePrefix
,
""
,
nested
.
getName
(),
schemaLoader
.
get
(
nested
.
getId
()));
};
};
...
@@ -1391,7 +1391,7 @@ private:
...
@@ -1391,7 +1391,7 @@ private:
"use the same version of the Cap'n Proto compiler and library.
\"\n
"
"use the same version of the Cap'n Proto compiler and library.
\"\n
"
"#endif
\n
"
"#endif
\n
"
"
\n
"
,
"
\n
"
,
KJ_MAP
(
includes
,
path
)
{
KJ_MAP
(
path
,
includes
)
{
if
(
path
.
startsWith
(
"/"
))
{
if
(
path
.
startsWith
(
"/"
))
{
return
kj
::
strTree
(
"#include <"
,
path
.
slice
(
1
),
".h>
\n
"
);
return
kj
::
strTree
(
"#include <"
,
path
.
slice
(
1
),
".h>
\n
"
);
}
else
{
}
else
{
...
@@ -1400,30 +1400,30 @@ private:
...
@@ -1400,30 +1400,30 @@ private:
},
},
"
\n
"
,
"
\n
"
,
KJ_MAP
(
n
amespaceParts
,
n
)
{
return
kj
::
strTree
(
"namespace "
,
n
,
" {
\n
"
);
},
"
\n
"
,
KJ_MAP
(
n
,
namespaceParts
)
{
return
kj
::
strTree
(
"namespace "
,
n
,
" {
\n
"
);
},
"
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
outerTypeDef
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
outerTypeDef
);
},
KJ_MAP
(
n
amespaceParts
,
n
)
{
return
kj
::
strTree
(
"} // namespace
\n
"
);
},
"
\n
"
,
KJ_MAP
(
n
,
namespaceParts
)
{
return
kj
::
strTree
(
"} // namespace
\n
"
);
},
"
\n
"
,
separator
,
"
\n
"
separator
,
"
\n
"
"namespace capnp {
\n
"
"namespace capnp {
\n
"
"namespace schemas {
\n
"
"namespace schemas {
\n
"
"
\n
"
,
"
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpSchemaDecls
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
capnpSchemaDecls
);
},
"
\n
"
"
\n
"
"} // namespace schemas
\n
"
"} // namespace schemas
\n
"
"namespace _ { // private
\n
"
"namespace _ { // private
\n
"
"
\n
"
,
"
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpPrivateDecls
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
capnpPrivateDecls
);
},
"
\n
"
"
\n
"
"} // namespace _ (private)
\n
"
"} // namespace _ (private)
\n
"
"} // namespace capnp
\n
"
"} // namespace capnp
\n
"
"
\n
"
,
separator
,
"
\n
"
,
"
\n
"
,
separator
,
"
\n
"
,
KJ_MAP
(
n
amespaceParts
,
n
)
{
return
kj
::
strTree
(
"namespace "
,
n
,
" {
\n
"
);
},
"
\n
"
,
KJ_MAP
(
n
,
namespaceParts
)
{
return
kj
::
strTree
(
"namespace "
,
n
,
" {
\n
"
);
},
"
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
readerBuilderDefs
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
readerBuilderDefs
);
},
separator
,
"
\n
"
,
separator
,
"
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
inlineMethodDefs
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
inlineMethodDefs
);
},
KJ_MAP
(
n
amespaceParts
,
n
)
{
return
kj
::
strTree
(
"} // namespace
\n
"
);
},
"
\n
"
,
KJ_MAP
(
n
,
namespaceParts
)
{
return
kj
::
strTree
(
"} // namespace
\n
"
);
},
"
\n
"
,
"#endif // CAPNP_INCLUDED_"
,
kj
::
hex
(
node
.
getId
()),
"_
\n
"
),
"#endif // CAPNP_INCLUDED_"
,
kj
::
hex
(
node
.
getId
()),
"_
\n
"
),
kj
::
strTree
(
kj
::
strTree
(
...
@@ -1434,10 +1434,10 @@ private:
...
@@ -1434,10 +1434,10 @@ private:
"
\n
"
"
\n
"
"namespace capnp {
\n
"
"namespace capnp {
\n
"
"namespace schemas {
\n
"
,
"namespace schemas {
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpSchemaDefs
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
capnpSchemaDefs
);
},
"} // namespace schemas
\n
"
"} // namespace schemas
\n
"
"namespace _ { // private
\n
"
,
"namespace _ { // private
\n
"
,
KJ_MAP
(
n
odeTexts
,
n
)
{
return
kj
::
mv
(
n
.
capnpPrivateDefs
);
},
KJ_MAP
(
n
,
nodeTexts
)
{
return
kj
::
mv
(
n
.
capnpPrivateDefs
);
},
"} // namespace _ (private)
\n
"
"} // namespace _ (private)
\n
"
"} // namespace capnp
\n
"
)
"} // namespace capnp
\n
"
)
};
};
...
...
c++/src/capnp/compiler/capnpc-capnp.c++
View file @
f651e5cf
...
@@ -296,7 +296,7 @@ private:
...
@@ -296,7 +296,7 @@ private:
}
}
kj
::
StringTree
genAnnotations
(
List
<
schema
::
Annotation
>::
Reader
list
,
Schema
scope
)
{
kj
::
StringTree
genAnnotations
(
List
<
schema
::
Annotation
>::
Reader
list
,
Schema
scope
)
{
return
kj
::
strTree
(
KJ_MAP
(
list
,
ann
)
{
return
genAnnotation
(
ann
,
scope
);
});
return
kj
::
strTree
(
KJ_MAP
(
ann
,
list
)
{
return
genAnnotation
(
ann
,
scope
);
});
}
}
kj
::
StringTree
genAnnotations
(
Schema
schema
)
{
kj
::
StringTree
genAnnotations
(
Schema
schema
)
{
auto
proto
=
schema
.
getProto
();
auto
proto
=
schema
.
getProto
();
...
@@ -326,7 +326,7 @@ private:
...
@@ -326,7 +326,7 @@ private:
template
<
typename
MemberList
>
template
<
typename
MemberList
>
kj
::
Array
<
decltype
(
kj
::
instance
<
MemberList
>
()[
0
])
>
sortByCodeOrder
(
MemberList
&&
list
)
{
kj
::
Array
<
decltype
(
kj
::
instance
<
MemberList
>
()[
0
])
>
sortByCodeOrder
(
MemberList
&&
list
)
{
auto
sorted
=
KJ_MAP
(
list
,
item
)
{
return
item
;
};
auto
sorted
=
KJ_MAP
(
item
,
list
)
{
return
item
;
};
std
::
sort
(
sorted
.
begin
(),
sorted
.
end
(),
OrderByCodeOrder
());
std
::
sort
(
sorted
.
begin
(),
sorted
.
end
(),
OrderByCodeOrder
());
return
kj
::
mv
(
sorted
);
return
kj
::
mv
(
sorted
);
}
}
...
@@ -338,7 +338,7 @@ private:
...
@@ -338,7 +338,7 @@ private:
// subsequent fields.
// subsequent fields.
bool
seenUnion
=
false
;
bool
seenUnion
=
false
;
return
KJ_MAP
(
sortByCodeOrder
(
schema
.
getFields
()),
field
)
{
return
KJ_MAP
(
field
,
sortByCodeOrder
(
schema
.
getFields
())
)
{
if
(
field
.
getProto
().
hasDiscriminantValue
())
{
if
(
field
.
getProto
().
hasDiscriminantValue
())
{
if
(
seenUnion
)
{
if
(
seenUnion
)
{
return
kj
::
strTree
();
return
kj
::
strTree
();
...
@@ -350,7 +350,7 @@ private:
...
@@ -350,7 +350,7 @@ private:
auto
unionFields
=
sortByCodeOrder
(
schema
.
getUnionFields
());
auto
unionFields
=
sortByCodeOrder
(
schema
.
getUnionFields
());
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
"union { # tag bits ["
,
offset
*
16
,
", "
,
offset
*
16
+
16
,
")
\n
"
,
indent
,
"union { # tag bits ["
,
offset
*
16
,
", "
,
offset
*
16
+
16
,
")
\n
"
,
KJ_MAP
(
u
nionFields
,
uField
)
{
KJ_MAP
(
u
Field
,
unionFields
)
{
return
genStructField
(
uField
.
getProto
(),
schema
,
indent
.
next
());
return
genStructField
(
uField
.
getProto
(),
schema
,
indent
.
next
());
},
},
indent
,
"}
\n
"
);
indent
,
"}
\n
"
);
...
@@ -424,7 +424,7 @@ private:
...
@@ -424,7 +424,7 @@ private:
case
schema
:
:
Node
::
ENUM
:
{
case
schema
:
:
Node
::
ENUM
:
{
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
"enum "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
genAnnotations
(
schema
),
" {
\n
"
,
indent
,
"enum "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
genAnnotations
(
schema
),
" {
\n
"
,
KJ_MAP
(
sortByCodeOrder
(
schema
.
asEnum
().
getEnumerants
()),
enumerant
)
{
KJ_MAP
(
enumerant
,
sortByCodeOrder
(
schema
.
asEnum
().
getEnumerants
())
)
{
return
kj
::
strTree
(
indent
.
next
(),
enumerant
.
getProto
().
getName
(),
" @"
,
return
kj
::
strTree
(
indent
.
next
(),
enumerant
.
getProto
().
getName
(),
" @"
,
enumerant
.
getIndex
(),
enumerant
.
getIndex
(),
genAnnotations
(
enumerant
.
getProto
().
getAnnotations
(),
schema
),
genAnnotations
(
enumerant
.
getProto
().
getAnnotations
(),
schema
),
...
@@ -437,12 +437,12 @@ private:
...
@@ -437,12 +437,12 @@ private:
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
"interface "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
indent
,
"interface "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
genAnnotations
(
schema
),
" {
\n
"
,
genAnnotations
(
schema
),
" {
\n
"
,
KJ_MAP
(
sortByCodeOrder
(
schema
.
asInterface
().
getMethods
()),
method
)
{
KJ_MAP
(
method
,
sortByCodeOrder
(
schema
.
asInterface
().
getMethods
())
)
{
int
i
=
0
;
int
i
=
0
;
auto
methodProto
=
method
.
getProto
();
auto
methodProto
=
method
.
getProto
();
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
.
next
(),
methodProto
.
getName
(),
" @"
,
method
.
getIndex
(),
"("
,
indent
.
next
(),
methodProto
.
getName
(),
" @"
,
method
.
getIndex
(),
"("
,
KJ_MAP
(
methodProto
.
getParams
(),
param
)
{
KJ_MAP
(
param
,
methodProto
.
getParams
()
)
{
bool
hasDefault
=
i
>=
methodProto
.
getRequiredParamCount
()
||
bool
hasDefault
=
i
>=
methodProto
.
getRequiredParamCount
()
||
!
isEmptyValue
(
param
.
getDefaultValue
());
!
isEmptyValue
(
param
.
getDefaultValue
());
return
kj
::
strTree
(
return
kj
::
strTree
(
...
@@ -504,7 +504,7 @@ private:
...
@@ -504,7 +504,7 @@ private:
kj
::
StringTree
genNestedDecls
(
Schema
schema
,
Indent
indent
)
{
kj
::
StringTree
genNestedDecls
(
Schema
schema
,
Indent
indent
)
{
uint64_t
id
=
schema
.
getProto
().
getId
();
uint64_t
id
=
schema
.
getProto
().
getId
();
return
kj
::
strTree
(
KJ_MAP
(
schema
.
getProto
().
getNestedNodes
(),
nested
)
{
return
kj
::
strTree
(
KJ_MAP
(
nested
,
schema
.
getProto
().
getNestedNodes
()
)
{
return
genDecl
(
schemaLoader
.
get
(
nested
.
getId
()),
nested
.
getName
(),
id
,
indent
);
return
genDecl
(
schemaLoader
.
get
(
nested
.
getId
()),
nested
.
getName
(),
id
,
indent
);
});
});
}
}
...
@@ -516,7 +516,7 @@ private:
...
@@ -516,7 +516,7 @@ private:
return
kj
::
strTree
(
return
kj
::
strTree
(
"# "
,
proto
.
getDisplayName
(),
"
\n
"
,
"# "
,
proto
.
getDisplayName
(),
"
\n
"
,
"@0x"
,
kj
::
hex
(
proto
.
getId
()),
";
\n
"
,
"@0x"
,
kj
::
hex
(
proto
.
getId
()),
";
\n
"
,
KJ_MAP
(
proto
.
getAnnotations
(),
ann
)
{
return
genAnnotation
(
ann
,
file
,
""
,
";
\n
"
);
},
KJ_MAP
(
ann
,
proto
.
getAnnotations
()
)
{
return
genAnnotation
(
ann
,
file
,
""
,
";
\n
"
);
},
genNestedDecls
(
file
,
Indent
(
0
)));
genNestedDecls
(
file
,
Indent
(
0
)));
}
}
...
...
c++/src/capnp/compiler/compiler.c++
View file @
f651e5cf
...
@@ -523,7 +523,7 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum
...
@@ -523,7 +523,7 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum
// Create the final schema.
// Create the final schema.
KJ_IF_MAYBE
(
exception
,
kj
::
runCatchingExceptions
([
&
](){
KJ_IF_MAYBE
(
exception
,
kj
::
runCatchingExceptions
([
&
](){
auto
nodeSet
=
locked
->
translator
->
finish
();
auto
nodeSet
=
locked
->
translator
->
finish
();
locked
->
auxSchemas
=
KJ_MAP
(
nodeSet
.
auxNodes
,
auxNode
)
{
locked
->
auxSchemas
=
KJ_MAP
(
auxNode
,
nodeSet
.
auxNodes
)
{
return
module
->
getCompiler
().
getFinalLoader
().
loadOnce
(
auxNode
);
return
module
->
getCompiler
().
getFinalLoader
().
loadOnce
(
auxNode
);
};
};
locked
->
finalSchema
=
module
->
getCompiler
().
getFinalLoader
().
loadOnce
(
nodeSet
.
node
);
locked
->
finalSchema
=
module
->
getCompiler
().
getFinalLoader
().
loadOnce
(
nodeSet
.
node
);
...
...
c++/src/capnp/compiler/node-translator.c++
View file @
f651e5cf
...
@@ -536,7 +536,7 @@ NodeTranslator::NodeTranslator(
...
@@ -536,7 +536,7 @@ NodeTranslator::NodeTranslator(
NodeTranslator
::
NodeSet
NodeTranslator
::
getBootstrapNode
()
{
NodeTranslator
::
NodeSet
NodeTranslator
::
getBootstrapNode
()
{
return
NodeSet
{
return
NodeSet
{
wipNode
.
getReader
(),
wipNode
.
getReader
(),
KJ_MAP
(
g
roups
,
g
)
{
return
g
.
getReader
();
}
KJ_MAP
(
g
,
groups
)
{
return
g
.
getReader
();
}
};
};
}
}
...
...
c++/src/capnp/stringify.c++
View file @
f651e5cf
...
@@ -173,7 +173,7 @@ static kj::StringTree print(const DynamicValue::Reader& value,
...
@@ -173,7 +173,7 @@ static kj::StringTree print(const DynamicValue::Reader& value,
case
DynamicValue
:
:
LIST
:
{
case
DynamicValue
:
:
LIST
:
{
auto
listValue
=
value
.
as
<
DynamicList
>
();
auto
listValue
=
value
.
as
<
DynamicList
>
();
auto
which
=
listValue
.
getSchema
().
whichElementType
();
auto
which
=
listValue
.
getSchema
().
whichElementType
();
kj
::
Array
<
kj
::
StringTree
>
elements
=
KJ_MAP
(
listValue
,
element
)
{
kj
::
Array
<
kj
::
StringTree
>
elements
=
KJ_MAP
(
element
,
listValue
)
{
return
print
(
element
,
which
,
indent
.
next
(),
BARE
);
return
print
(
element
,
which
,
indent
.
next
(),
BARE
);
};
};
return
kj
::
strTree
(
'['
,
indent
.
delimit
(
kj
::
mv
(
elements
),
mode
),
']'
);
return
kj
::
strTree
(
'['
,
indent
.
delimit
(
kj
::
mv
(
elements
),
mode
),
']'
);
...
...
c++/src/kj/array-test.c++
View file @
f651e5cf
...
@@ -331,7 +331,7 @@ TEST(Array, OwnConst) {
...
@@ -331,7 +331,7 @@ TEST(Array, OwnConst) {
TEST
(
Array
,
Map
)
{
TEST
(
Array
,
Map
)
{
StringPtr
foo
=
"abcd"
;
StringPtr
foo
=
"abcd"
;
Array
<
char
>
bar
=
KJ_MAP
(
foo
,
c
)
->
char
{
return
c
+
1
;
};
Array
<
char
>
bar
=
KJ_MAP
(
c
,
foo
)
->
char
{
return
c
+
1
;
};
EXPECT_STREQ
(
"bcde"
,
str
(
bar
).
cStr
());
EXPECT_STREQ
(
"bcde"
,
str
(
bar
).
cStr
());
}
}
...
...
c++/src/kj/array.h
View file @
f651e5cf
...
@@ -466,15 +466,15 @@ private:
...
@@ -466,15 +466,15 @@ private:
};
};
// =======================================================================================
// =======================================================================================
// KJ_MAP
_ARRAY
// KJ_MAP
#define KJ_MAP(
array, elementName
) \
#define KJ_MAP(
elementName, array
) \
::kj::_::Mapper<KJ_DECLTYPE_REF(array)>(array) * [&](decltype(*(array).begin()) elementName)
::kj::_::Mapper<KJ_DECLTYPE_REF(array)>(array) * [&](decltype(*(array).begin()) elementName)
// Applies some function to every element of an array, returning an Array of the results, with
// Applies some function to every element of an array, returning an Array of the results, with
// nice syntax. Example:
// nice syntax. Example:
//
//
// StringPtr foo = "abcd";
// StringPtr foo = "abcd";
// Array<char> bar = KJ_MAP(
foo, c
) -> char { return c + 1; };
// Array<char> bar = KJ_MAP(
c, foo
) -> char { return c + 1; };
// KJ_ASSERT(str(bar) == "bcde");
// KJ_ASSERT(str(bar) == "bcde");
namespace
_
{
// private
namespace
_
{
// private
...
...
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