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
fd1f0a4d
Commit
fd1f0a4d
authored
Aug 21, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix capnpc-capnp.
parent
fe18f08f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
243 additions
and
219 deletions
+243
-219
capnp.ekam-manifest
c++/src/capnp/compiler/capnp.ekam-manifest
+1
-0
capnpc-capnp.c++
c++/src/capnp/compiler/capnpc-capnp.c++
+242
-219
No files found.
c++/src/capnp/compiler/capnp.ekam-manifest
View file @
fd1f0a4d
capnp bin
capnp bin
capnpc-capnp bin
capnpc-c++ bin
capnpc-c++ bin
c++/src/capnp/compiler/capnpc-capnp.c++
View file @
fd1f0a4d
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include <unistd.h>
#include <unistd.h>
#include <unordered_map>
#include <unordered_map>
#include <kj/main.h>
#include <kj/main.h>
#include <algorithm>
#if HAVE_CONFIG_H
#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
...
@@ -155,152 +156,146 @@ private:
...
@@ -155,152 +156,146 @@ private:
return
kj
::
strTree
(
kj
::
mv
(
path
),
getUnqualifiedName
(
target
));
return
kj
::
strTree
(
kj
::
mv
(
path
),
getUnqualifiedName
(
target
));
}
}
kj
::
StringTree
genType
(
schema
::
Type
::
Reader
type
,
Schema
scope
)
{
kj
::
StringTree
genType
(
schema2
::
Type
::
Reader
type
,
Schema
scope
)
{
auto
body
=
type
.
getBody
();
switch
(
type
.
which
())
{
switch
(
body
.
which
())
{
case
schema2
:
:
Type
::
VOID
:
return
kj
::
strTree
(
"Void"
);
case
schema
:
:
Type
::
Body
::
VOID_TYPE
:
return
kj
::
strTree
(
"Void"
);
case
schema2
:
:
Type
::
BOOL
:
return
kj
::
strTree
(
"Bool"
);
case
schema
:
:
Type
::
Body
::
BOOL_TYPE
:
return
kj
::
strTree
(
"Bool"
);
case
schema2
:
:
Type
::
INT8
:
return
kj
::
strTree
(
"Int8"
);
case
schema
:
:
Type
::
Body
::
INT8_TYPE
:
return
kj
::
strTree
(
"Int8"
);
case
schema2
:
:
Type
::
INT16
:
return
kj
::
strTree
(
"Int16"
);
case
schema
:
:
Type
::
Body
::
INT16_TYPE
:
return
kj
::
strTree
(
"Int16"
);
case
schema2
:
:
Type
::
INT32
:
return
kj
::
strTree
(
"Int32"
);
case
schema
:
:
Type
::
Body
::
INT32_TYPE
:
return
kj
::
strTree
(
"Int32"
);
case
schema2
:
:
Type
::
INT64
:
return
kj
::
strTree
(
"Int64"
);
case
schema
:
:
Type
::
Body
::
INT64_TYPE
:
return
kj
::
strTree
(
"Int64"
);
case
schema2
:
:
Type
::
UINT8
:
return
kj
::
strTree
(
"UInt8"
);
case
schema
:
:
Type
::
Body
::
UINT8_TYPE
:
return
kj
::
strTree
(
"UInt8"
);
case
schema2
:
:
Type
::
UINT16
:
return
kj
::
strTree
(
"UInt16"
);
case
schema
:
:
Type
::
Body
::
UINT16_TYPE
:
return
kj
::
strTree
(
"UInt16"
);
case
schema2
:
:
Type
::
UINT32
:
return
kj
::
strTree
(
"UInt32"
);
case
schema
:
:
Type
::
Body
::
UINT32_TYPE
:
return
kj
::
strTree
(
"UInt32"
);
case
schema2
:
:
Type
::
UINT64
:
return
kj
::
strTree
(
"UInt64"
);
case
schema
:
:
Type
::
Body
::
UINT64_TYPE
:
return
kj
::
strTree
(
"UInt64"
);
case
schema2
:
:
Type
::
FLOAT32
:
return
kj
::
strTree
(
"Float32"
);
case
schema
:
:
Type
::
Body
::
FLOAT32_TYPE
:
return
kj
::
strTree
(
"Float32"
);
case
schema2
:
:
Type
::
FLOAT64
:
return
kj
::
strTree
(
"Float64"
);
case
schema
:
:
Type
::
Body
::
FLOAT64_TYPE
:
return
kj
::
strTree
(
"Float64"
);
case
schema2
:
:
Type
::
TEXT
:
return
kj
::
strTree
(
"Text"
);
case
schema
:
:
Type
::
Body
::
TEXT_TYPE
:
return
kj
::
strTree
(
"Text"
);
case
schema2
:
:
Type
::
DATA
:
return
kj
::
strTree
(
"Data"
);
case
schema
:
:
Type
::
Body
::
DATA_TYPE
:
return
kj
::
strTree
(
"Data"
);
case
schema2
:
:
Type
::
LIST
:
case
schema
:
:
Type
::
Body
::
LIST_TYPE
:
return
kj
::
strTree
(
"List("
,
genType
(
type
.
getList
(),
scope
),
")"
);
return
kj
::
strTree
(
"List("
,
genType
(
body
.
getListType
(),
scope
),
")"
);
case
schema2
:
:
Type
::
ENUM
:
case
schema
:
:
Type
::
Body
::
ENUM_TYPE
:
return
nodeName
(
scope
.
getDependency
(
type
.
getEnum
()),
scope
);
return
nodeName
(
scope
.
getDependency
(
body
.
getEnumType
()),
scope
);
case
schema2
:
:
Type
::
STRUCT
:
case
schema
:
:
Type
::
Body
::
STRUCT_TYPE
:
return
nodeName
(
scope
.
getDependency
(
type
.
getStruct
()),
scope
);
return
nodeName
(
scope
.
getDependency
(
body
.
getStructType
()),
scope
);
case
schema2
:
:
Type
::
INTERFACE
:
case
schema
:
:
Type
::
Body
::
INTERFACE_TYPE
:
return
nodeName
(
scope
.
getDependency
(
type
.
getInterface
()),
scope
);
return
nodeName
(
scope
.
getDependency
(
body
.
getInterfaceType
()),
scope
);
case
schema2
:
:
Type
::
OBJECT
:
return
kj
::
strTree
(
"Object"
);
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
return
kj
::
strTree
(
"Object"
);
}
}
return
kj
::
strTree
();
return
kj
::
strTree
();
}
}
int
typeSizeBits
(
schema
::
Type
::
Reader
type
)
{
int
typeSizeBits
(
schema
2
::
Type
::
Reader
type
)
{
switch
(
type
.
getBody
().
which
())
{
switch
(
type
.
which
())
{
case
schema
:
:
Type
::
Body
::
VOID_TYPE
:
return
0
;
case
schema
2
:
:
Type
::
VOID
:
return
0
;
case
schema
:
:
Type
::
Body
::
BOOL_TYPE
:
return
1
;
case
schema
2
:
:
Type
::
BOOL
:
return
1
;
case
schema
:
:
Type
::
Body
::
INT8_TYPE
:
return
8
;
case
schema
2
:
:
Type
::
INT8
:
return
8
;
case
schema
:
:
Type
::
Body
::
INT16_TYPE
:
return
16
;
case
schema
2
:
:
Type
::
INT16
:
return
16
;
case
schema
:
:
Type
::
Body
::
INT32_TYPE
:
return
32
;
case
schema
2
:
:
Type
::
INT32
:
return
32
;
case
schema
:
:
Type
::
Body
::
INT64_TYPE
:
return
64
;
case
schema
2
:
:
Type
::
INT64
:
return
64
;
case
schema
:
:
Type
::
Body
::
UINT8_TYPE
:
return
8
;
case
schema
2
:
:
Type
::
UINT8
:
return
8
;
case
schema
:
:
Type
::
Body
::
UINT16_TYPE
:
return
16
;
case
schema
2
:
:
Type
::
UINT16
:
return
16
;
case
schema
:
:
Type
::
Body
::
UINT32_TYPE
:
return
32
;
case
schema
2
:
:
Type
::
UINT32
:
return
32
;
case
schema
:
:
Type
::
Body
::
UINT64_TYPE
:
return
64
;
case
schema
2
:
:
Type
::
UINT64
:
return
64
;
case
schema
:
:
Type
::
Body
::
FLOAT32_TYPE
:
return
32
;
case
schema
2
:
:
Type
::
FLOAT32
:
return
32
;
case
schema
:
:
Type
::
Body
::
FLOAT64_TYPE
:
return
64
;
case
schema
2
:
:
Type
::
FLOAT64
:
return
64
;
case
schema
:
:
Type
::
Body
::
TEXT_TYPE
:
return
-
1
;
case
schema
2
:
:
Type
::
TEXT
:
return
-
1
;
case
schema
:
:
Type
::
Body
::
DATA_TYPE
:
return
-
1
;
case
schema
2
:
:
Type
::
DATA
:
return
-
1
;
case
schema
:
:
Type
::
Body
::
LIST_TYPE
:
return
-
1
;
case
schema
2
:
:
Type
::
LIST
:
return
-
1
;
case
schema
:
:
Type
::
Body
::
ENUM_TYPE
:
return
16
;
case
schema
2
:
:
Type
::
ENUM
:
return
16
;
case
schema
:
:
Type
::
Body
::
STRUCT_TYPE
:
return
-
1
;
case
schema
2
:
:
Type
::
STRUCT
:
return
-
1
;
case
schema
:
:
Type
::
Body
::
INTERFACE_TYP
E
:
return
-
1
;
case
schema
2
:
:
Type
::
INTERFAC
E
:
return
-
1
;
case
schema
:
:
Type
::
Body
::
OBJECT_TYPE
:
return
-
1
;
case
schema
2
:
:
Type
::
OBJECT
:
return
-
1
;
}
}
return
0
;
return
0
;
}
}
bool
isEmptyValue
(
schema
::
Value
::
Reader
value
)
{
bool
isEmptyValue
(
schema2
::
Value
::
Reader
value
)
{
auto
body
=
value
.
getBody
();
switch
(
value
.
which
())
{
switch
(
body
.
which
())
{
case
schema2
:
:
Value
::
VOID
:
return
true
;
case
schema
:
:
Value
::
Body
::
VOID_VALUE
:
return
true
;
case
schema2
:
:
Value
::
BOOL
:
return
value
.
getBool
()
==
false
;
case
schema
:
:
Value
::
Body
::
BOOL_VALUE
:
return
body
.
getBoolValue
()
==
false
;
case
schema2
:
:
Value
::
INT8
:
return
value
.
getInt8
()
==
0
;
case
schema
:
:
Value
::
Body
::
INT8_VALUE
:
return
body
.
getInt8Value
()
==
0
;
case
schema2
:
:
Value
::
INT16
:
return
value
.
getInt16
()
==
0
;
case
schema
:
:
Value
::
Body
::
INT16_VALUE
:
return
body
.
getInt16Value
()
==
0
;
case
schema2
:
:
Value
::
INT32
:
return
value
.
getInt32
()
==
0
;
case
schema
:
:
Value
::
Body
::
INT32_VALUE
:
return
body
.
getInt32Value
()
==
0
;
case
schema2
:
:
Value
::
INT64
:
return
value
.
getInt64
()
==
0
;
case
schema
:
:
Value
::
Body
::
INT64_VALUE
:
return
body
.
getInt64Value
()
==
0
;
case
schema2
:
:
Value
::
UINT8
:
return
value
.
getUint8
()
==
0
;
case
schema
:
:
Value
::
Body
::
UINT8_VALUE
:
return
body
.
getUint8Value
()
==
0
;
case
schema2
:
:
Value
::
UINT16
:
return
value
.
getUint16
()
==
0
;
case
schema
:
:
Value
::
Body
::
UINT16_VALUE
:
return
body
.
getUint16Value
()
==
0
;
case
schema2
:
:
Value
::
UINT32
:
return
value
.
getUint32
()
==
0
;
case
schema
:
:
Value
::
Body
::
UINT32_VALUE
:
return
body
.
getUint32Value
()
==
0
;
case
schema2
:
:
Value
::
UINT64
:
return
value
.
getUint64
()
==
0
;
case
schema
:
:
Value
::
Body
::
UINT64_VALUE
:
return
body
.
getUint64Value
()
==
0
;
case
schema2
:
:
Value
::
FLOAT32
:
return
value
.
getFloat32
()
==
0
;
case
schema
:
:
Value
::
Body
::
FLOAT32_VALUE
:
return
body
.
getFloat32Value
()
==
0
;
case
schema2
:
:
Value
::
FLOAT64
:
return
value
.
getFloat64
()
==
0
;
case
schema
:
:
Value
::
Body
::
FLOAT64_VALUE
:
return
body
.
getFloat64Value
()
==
0
;
case
schema2
:
:
Value
::
TEXT
:
return
!
value
.
hasText
();
case
schema
:
:
Value
::
Body
::
TEXT_VALUE
:
return
!
body
.
hasTextValue
();
case
schema2
:
:
Value
::
DATA
:
return
!
value
.
hasData
();
case
schema
:
:
Value
::
Body
::
DATA_VALUE
:
return
!
body
.
hasDataValue
();
case
schema2
:
:
Value
::
LIST
:
return
!
value
.
hasList
();
case
schema
:
:
Value
::
Body
::
LIST_VALUE
:
return
!
body
.
hasListValue
();
case
schema2
:
:
Value
::
ENUM
:
return
value
.
getEnum
()
==
0
;
case
schema
:
:
Value
::
Body
::
ENUM_VALUE
:
return
body
.
getEnumValue
()
==
0
;
case
schema2
:
:
Value
::
STRUCT
:
return
!
value
.
hasStruct
();
case
schema
:
:
Value
::
Body
::
STRUCT_VALUE
:
return
!
body
.
hasStructValue
();
case
schema2
:
:
Value
::
INTERFACE
:
return
true
;
case
schema
:
:
Value
::
Body
::
INTERFACE_VALUE
:
return
true
;
case
schema2
:
:
Value
::
OBJECT
:
return
true
;
case
schema
:
:
Value
::
Body
::
OBJECT_VALUE
:
return
true
;
}
}
return
true
;
return
true
;
}
}
kj
::
StringTree
genValue
(
schema
::
Type
::
Reader
type
,
schema
::
Value
::
Reader
value
,
Schema
scope
)
{
kj
::
StringTree
genValue
(
schema2
::
Type
::
Reader
type
,
schema2
::
Value
::
Reader
value
,
Schema
scope
)
{
auto
body
=
value
.
getBody
();
switch
(
value
.
which
())
{
switch
(
body
.
which
())
{
case
schema2
:
:
Value
::
VOID
:
return
kj
::
strTree
(
"void"
);
case
schema
:
:
Value
::
Body
::
VOID_VALUE
:
return
kj
::
strTree
(
"void"
);
case
schema2
:
:
Value
::
BOOL
:
case
schema
:
:
Value
::
Body
::
BOOL_VALUE
:
return
kj
::
strTree
(
value
.
getBool
()
?
"true"
:
"false"
);
return
kj
::
strTree
(
body
.
getBoolValue
()
?
"true"
:
"false"
);
case
schema2
:
:
Value
::
INT8
:
return
kj
::
strTree
((
int
)
value
.
getInt8
());
case
schema
:
:
Value
::
Body
::
INT8_VALUE
:
return
kj
::
strTree
((
int
)
body
.
getInt8Value
());
case
schema2
:
:
Value
::
INT16
:
return
kj
::
strTree
(
value
.
getInt16
());
case
schema
:
:
Value
::
Body
::
INT16_VALUE
:
return
kj
::
strTree
(
body
.
getInt16Value
());
case
schema2
:
:
Value
::
INT32
:
return
kj
::
strTree
(
value
.
getInt32
());
case
schema
:
:
Value
::
Body
::
INT32_VALUE
:
return
kj
::
strTree
(
body
.
getInt32Value
());
case
schema2
:
:
Value
::
INT64
:
return
kj
::
strTree
(
value
.
getInt64
());
case
schema
:
:
Value
::
Body
::
INT64_VALUE
:
return
kj
::
strTree
(
body
.
getInt64Value
());
case
schema2
:
:
Value
::
UINT8
:
return
kj
::
strTree
((
uint
)
value
.
getUint8
());
case
schema
:
:
Value
::
Body
::
UINT8_VALUE
:
return
kj
::
strTree
((
uint
)
body
.
getUint8Value
());
case
schema2
:
:
Value
::
UINT16
:
return
kj
::
strTree
(
value
.
getUint16
());
case
schema
:
:
Value
::
Body
::
UINT16_VALUE
:
return
kj
::
strTree
(
body
.
getUint16Value
());
case
schema2
:
:
Value
::
UINT32
:
return
kj
::
strTree
(
value
.
getUint32
());
case
schema
:
:
Value
::
Body
::
UINT32_VALUE
:
return
kj
::
strTree
(
body
.
getUint32Value
());
case
schema2
:
:
Value
::
UINT64
:
return
kj
::
strTree
(
value
.
getUint64
());
case
schema
:
:
Value
::
Body
::
UINT64_VALUE
:
return
kj
::
strTree
(
body
.
getUint64Value
());
case
schema2
:
:
Value
::
FLOAT32
:
return
kj
::
strTree
(
value
.
getFloat32
());
case
schema
:
:
Value
::
Body
::
FLOAT32_VALUE
:
return
kj
::
strTree
(
body
.
getFloat32Value
());
case
schema2
:
:
Value
::
FLOAT64
:
return
kj
::
strTree
(
value
.
getFloat64
());
case
schema
:
:
Value
::
Body
::
FLOAT64_VALUE
:
return
kj
::
strTree
(
body
.
getFloat64Value
());
case
schema2
:
:
Value
::
TEXT
:
case
schema
:
:
Value
::
Body
::
TEXT_VALUE
:
return
kj
::
strTree
(
DynamicValue
::
Reader
(
value
.
getText
()));
return
kj
::
strTree
(
DynamicValue
::
Reader
(
body
.
getTextValue
()));
case
schema2
:
:
Value
::
DATA
:
case
schema
:
:
Value
::
Body
::
DATA_VALUE
:
return
kj
::
strTree
(
DynamicValue
::
Reader
(
value
.
getData
()));
return
kj
::
strTree
(
DynamicValue
::
Reader
(
body
.
getDataValue
()));
case
schema2
:
:
Value
::
LIST
:
{
case
schema
:
:
Value
::
Body
::
LIST_VALUE
:
{
KJ_REQUIRE
(
type
.
which
()
==
schema2
::
Type
::
LIST
,
"type/value mismatch"
);
KJ_REQUIRE
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
LIST_TYPE
,
"type/value mismatch"
);
auto
listValue
=
value
.
getList
<
DynamicList
>
(
ListSchema
::
of
(
type
.
getList
(),
scope
));
auto
value
=
body
.
getListValue
<
DynamicList
>
(
return
kj
::
strTree
(
listValue
);
ListSchema
::
of
(
type
.
getBody
().
getListType
(),
scope
));
return
kj
::
strTree
(
value
);
}
}
case
schema
:
:
Value
::
Body
::
ENUM_VALUE
:
{
case
schema2
:
:
Value
::
ENUM
:
{
KJ_REQUIRE
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
ENUM_TYPE
,
"type/value mismatch"
);
KJ_REQUIRE
(
type
.
which
()
==
schema2
::
Type
::
ENUM
,
"type/value mismatch"
);
auto
enumNode
=
scope
.
getDependency
(
type
.
getBody
().
getEnumType
()).
asEnum
().
getProto
();
auto
enumNode
=
scope
.
getDependency
(
type
.
getEnum
()).
asEnum
().
getProto
();
auto
enumType
=
enumNode
.
getBody
().
getEnumNode
();
auto
enumerants
=
enumNode
.
getEnum
();
auto
enumerants
=
enumType
.
getEnumerants
();
KJ_REQUIRE
(
value
.
getEnum
()
<
enumerants
.
size
(),
KJ_REQUIRE
(
body
.
getEnumValue
()
<
enumerants
.
size
(),
"Enum value out-of-range."
,
value
.
getEnum
(),
enumNode
.
getDisplayName
());
"Enum value out-of-range."
,
body
.
getEnumValue
(),
enumNode
.
getDisplayName
());
return
kj
::
strTree
(
enumerants
[
value
.
getEnum
()].
getName
());
return
kj
::
strTree
(
enumerants
[
body
.
getEnumValue
()].
getName
());
}
}
case
schema
:
:
Value
::
Body
::
STRUCT_VALUE
:
{
case
schema2
:
:
Value
::
STRUCT
:
{
KJ_REQUIRE
(
type
.
getBody
().
which
()
==
schema
::
Type
::
Body
::
STRUCT_TYPE
,
KJ_REQUIRE
(
type
.
which
()
==
schema2
::
Type
::
STRUCT
,
"type/value mismatch"
);
"type/value mismatch"
);
auto
structValue
=
value
.
getStruct
<
DynamicStruct
>
(
auto
value
=
body
.
getStructValue
<
DynamicStruct
>
(
scope
.
getDependency
(
type
.
getStruct
()).
asStruct
());
scope
.
getDependency
(
type
.
getBody
().
getStructType
()).
asStruct
());
return
kj
::
strTree
(
structValue
);
return
kj
::
strTree
(
value
);
}
}
case
schema
:
:
Value
::
Body
::
INTERFACE_VALU
E
:
{
case
schema
2
:
:
Value
::
INTERFAC
E
:
{
return
kj
::
strTree
(
""
);
return
kj
::
strTree
(
""
);
}
}
case
schema
:
:
Value
::
Body
::
OBJECT_VALUE
:
{
case
schema
2
:
:
Value
::
OBJECT
:
{
return
kj
::
strTree
(
""
);
return
kj
::
strTree
(
""
);
}
}
}
}
return
kj
::
strTree
(
""
);
return
kj
::
strTree
(
""
);
}
}
kj
::
StringTree
genAnnotation
(
schema
::
Annotation
::
Reader
annotation
,
kj
::
StringTree
genAnnotation
(
schema
2
::
Annotation
::
Reader
annotation
,
Schema
scope
,
Schema
scope
,
const
char
*
prefix
=
" "
,
const
char
*
suffix
=
""
)
{
const
char
*
prefix
=
" "
,
const
char
*
suffix
=
""
)
{
auto
decl
=
schemaLoader
.
get
(
annotation
.
getId
());
auto
decl
=
schemaLoader
.
get
(
annotation
.
getId
());
auto
body
=
decl
.
getProto
().
getBody
();
auto
proto
=
decl
.
getProto
();
KJ_REQUIRE
(
body
.
which
()
==
schema
::
Node
::
Body
::
ANNOTATION_NODE
);
KJ_REQUIRE
(
proto
.
which
()
==
schema2
::
Node
::
ANNOTATION
);
auto
annDecl
=
body
.
getAnnotationNode
();
auto
annDecl
=
proto
.
getAnnotation
();
return
kj
::
strTree
(
prefix
,
"$"
,
nodeName
(
decl
,
scope
),
"("
,
return
kj
::
strTree
(
prefix
,
"$"
,
nodeName
(
decl
,
scope
),
"("
,
genValue
(
annDecl
.
getType
(),
annotation
.
getValue
(),
scope
),
")"
,
suffix
);
genValue
(
annDecl
.
getType
(),
annotation
.
getValue
(),
scope
),
")"
,
suffix
);
}
}
kj
::
StringTree
genAnnotations
(
List
<
schema
::
Annotation
>::
Reader
list
,
Schema
scope
)
{
kj
::
StringTree
genAnnotations
(
List
<
schema
2
::
Annotation
>::
Reader
list
,
Schema
scope
)
{
return
kj
::
strTree
(
KJ_MAP
(
list
,
ann
)
{
return
genAnnotation
(
ann
,
scope
);
});
return
kj
::
strTree
(
KJ_MAP
(
list
,
ann
)
{
return
genAnnotation
(
ann
,
scope
);
});
}
}
kj
::
StringTree
genAnnotations
(
Schema
schema
)
{
kj
::
StringTree
genAnnotations
(
Schema
schema
)
{
...
@@ -308,60 +303,89 @@ private:
...
@@ -308,60 +303,89 @@ private:
return
genAnnotations
(
proto
.
getAnnotations
(),
schemaLoader
.
get
(
proto
.
getScopeId
()));
return
genAnnotations
(
proto
.
getAnnotations
(),
schemaLoader
.
get
(
proto
.
getScopeId
()));
}
}
const
char
*
elementSizeName
(
schema
::
ElementSize
size
)
{
const
char
*
elementSizeName
(
schema
2
::
ElementSize
size
)
{
switch
(
size
)
{
switch
(
size
)
{
case
schema
:
:
ElementSize
::
EMPTY
:
return
"void"
;
case
schema
2
:
:
ElementSize
::
EMPTY
:
return
"void"
;
case
schema
:
:
ElementSize
::
BIT
:
return
"1-bit"
;
case
schema
2
:
:
ElementSize
::
BIT
:
return
"1-bit"
;
case
schema
:
:
ElementSize
::
BYTE
:
return
"8-bit"
;
case
schema
2
:
:
ElementSize
::
BYTE
:
return
"8-bit"
;
case
schema
:
:
ElementSize
::
TWO_BYTES
:
return
"16-bit"
;
case
schema
2
:
:
ElementSize
::
TWO_BYTES
:
return
"16-bit"
;
case
schema
:
:
ElementSize
::
FOUR_BYTES
:
return
"32-bit"
;
case
schema
2
:
:
ElementSize
::
FOUR_BYTES
:
return
"32-bit"
;
case
schema
:
:
ElementSize
::
EIGHT_BYTES
:
return
"64-bit"
;
case
schema
2
:
:
ElementSize
::
EIGHT_BYTES
:
return
"64-bit"
;
case
schema
:
:
ElementSize
::
POINTER
:
return
"pointer"
;
case
schema
2
:
:
ElementSize
::
POINTER
:
return
"pointer"
;
case
schema
:
:
ElementSize
::
INLINE_COMPOSITE
:
return
"inline composite"
;
case
schema
2
:
:
ElementSize
::
INLINE_COMPOSITE
:
return
"inline composite"
;
}
}
return
""
;
return
""
;
}
}
kj
::
StringTree
genStructMember
(
schema
::
StructNode
::
Member
::
Reader
member
,
struct
OrderByCodeOrder
{
Schema
scope
,
Indent
indent
,
int
unionTag
=
-
1
)
{
template
<
typename
T
>
switch
(
member
.
getBody
().
which
())
{
inline
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
case
schema
:
:
StructNode
::
Member
::
Body
::
FIELD_MEMBER
:
{
return
a
.
getProto
().
getCodeOrder
()
<
b
.
getProto
().
getCodeOrder
();
auto
field
=
member
.
getBody
().
getFieldMember
();
}
int
size
=
typeSizeBits
(
field
.
getType
());
};
return
kj
::
strTree
(
indent
,
member
.
getName
(),
" @"
,
member
.
getOrdinal
(),
template
<
typename
MemberList
>
" :"
,
genType
(
field
.
getType
(),
scope
),
kj
::
Array
<
decltype
(
kj
::
instance
<
MemberList
>
()[
0
])
>
sortByCodeOrder
(
MemberList
&&
list
)
{
isEmptyValue
(
field
.
getDefaultValue
())
?
kj
::
strTree
(
""
)
:
auto
sorted
=
KJ_MAP
(
list
,
item
)
{
return
item
;
};
kj
::
strTree
(
" = "
,
genValue
(
field
.
getType
(),
field
.
getDefaultValue
(),
scope
)),
std
::
sort
(
sorted
.
begin
(),
sorted
.
end
(),
OrderByCodeOrder
());
genAnnotations
(
member
.
getAnnotations
(),
scope
),
return
kj
::
mv
(
sorted
);
"; # "
,
size
==
-
1
?
kj
::
strTree
(
"ptr["
,
field
.
getOffset
(),
"]"
)
}
:
kj
::
strTree
(
"bits["
,
field
.
getOffset
()
*
size
,
", "
,
(
field
.
getOffset
()
+
1
)
*
size
,
")"
),
kj
::
Array
<
kj
::
StringTree
>
genStructFields
(
StructSchema
schema
,
Indent
indent
)
{
unionTag
!=
-
1
?
kj
::
strTree
(
", union tag = "
,
unionTag
)
:
kj
::
strTree
(),
// Slightly hacky: We want to print in code order, but we also need to print the union in one
"
\n
"
);
// chunk. Its fields should be together in code order anyway, but it's easier to simply
// output the whole union in place of the first union field, and then output nothing for the
// subsequent fields.
bool
seenUnion
=
false
;
return
KJ_MAP
(
sortByCodeOrder
(
schema
.
getFields
()),
field
)
{
if
(
field
.
getProto
().
hasDiscriminantValue
())
{
if
(
seenUnion
)
{
return
kj
::
strTree
();
}
else
{
seenUnion
=
true
;
uint
offset
=
schema
.
getProto
().
getStruct
().
getDiscriminantOffset
();
return
kj
::
strTree
(
indent
,
"union { # tag bits ["
,
offset
*
16
,
", "
,
offset
*
16
+
16
,
")
\n
"
,
KJ_MAP
(
sortByCodeOrder
(
schema
.
getUnionFields
()),
uField
)
{
return
genStructField
(
uField
.
getProto
(),
schema
,
indent
.
next
());
},
indent
,
"}
\n
"
);
}
}
else
{
return
genStructField
(
field
.
getProto
(),
schema
,
indent
);
}
}
case
schema
:
:
StructNode
::
Member
::
Body
::
UNION_MEMBER
:
{
};
auto
un
=
member
.
getBody
().
getUnionMember
();
}
int
i
=
0
;
kj
::
StringTree
genStructField
(
schema2
::
Field
::
Reader
field
,
Schema
scope
,
Indent
indent
)
{
switch
(
field
.
which
())
{
case
schema2
:
:
Field
::
REGULAR
:
{
auto
regularField
=
field
.
getRegular
();
int
size
=
typeSizeBits
(
regularField
.
getType
());
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
member
.
getName
(),
" @"
,
member
.
getOrdinal
(),
indent
,
field
.
getName
(),
" @"
,
field
.
getOrdinal
().
getExplicit
(),
" union"
,
genAnnotations
(
member
.
getAnnotations
(),
scope
),
" :"
,
genType
(
regularField
.
getType
(),
scope
),
" { # tag bits["
,
un
.
getDiscriminantOffset
()
*
16
,
", "
,
isEmptyValue
(
regularField
.
getDefaultValue
())
?
kj
::
strTree
(
""
)
:
un
.
getDiscriminantOffset
()
*
16
+
16
,
")
\n
"
,
kj
::
strTree
(
" = "
,
genValue
(
KJ_MAP
(
un
.
getMembers
(),
member
)
{
regularField
.
getType
(),
regularField
.
getDefaultValue
(),
scope
)),
return
genStructMember
(
member
,
scope
,
indent
.
next
(),
i
++
);
genAnnotations
(
field
.
getAnnotations
(),
scope
),
},
"; # "
,
size
==
-
1
?
kj
::
strTree
(
"ptr["
,
regularField
.
getOffset
(),
"]"
)
indent
,
"}
\n
"
);
:
kj
::
strTree
(
"bits["
,
regularField
.
getOffset
()
*
size
,
", "
,
(
regularField
.
getOffset
()
+
1
)
*
size
,
")"
),
field
.
hasDiscriminantValue
()
?
kj
::
strTree
(
", union tag = "
,
field
.
getDiscriminantValue
())
:
kj
::
strTree
(),
"
\n
"
);
}
}
case
schema
:
:
StructNode
::
Member
::
Body
::
GROUP_MEMBER
:
{
case
schema
2
:
:
Field
::
GROUP
:
{
auto
group
=
member
.
getBody
().
getGroupMember
();
auto
group
=
scope
.
getDependency
(
field
.
getGroup
()).
asStruct
();
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
member
.
getName
(),
indent
,
field
.
getName
(),
"
group"
,
genAnnotations
(
member
.
getAnnotations
(),
scope
),
" {"
,
"
:group"
,
genAnnotations
(
field
.
getAnnotations
(),
scope
),
" {"
,
unionTag
!=
-
1
?
kj
::
strTree
(
" # union tag = "
,
unionTag
)
:
kj
::
strTree
(),
"
\n
"
,
field
.
hasDiscriminantValue
()
KJ_MAP
(
group
.
getMembers
(),
member
)
{
?
kj
::
strTree
(
", union tag = "
,
field
.
getDiscriminantValue
())
:
kj
::
strTree
(),
return
genStructMember
(
member
,
scope
,
indent
.
next
());
"
\n
"
,
}
,
genStructFields
(
group
,
indent
.
next
())
,
indent
,
"}
\n
"
);
indent
,
"}
\n
"
);
}
}
}
}
...
@@ -375,54 +399,51 @@ private:
...
@@ -375,54 +399,51 @@ private:
KJ_FAIL_REQUIRE
(
"Aliases not implemented."
);
KJ_FAIL_REQUIRE
(
"Aliases not implemented."
);
}
}
switch
(
proto
.
getBody
().
which
())
{
switch
(
proto
.
which
())
{
case
schema
:
:
Node
::
Body
::
FILE_NOD
E
:
case
schema
2
:
:
Node
::
FIL
E
:
KJ_FAIL_REQUIRE
(
"Encountered nested file node."
);
KJ_FAIL_REQUIRE
(
"Encountered nested file node."
);
break
;
break
;
case
schema
:
:
Node
::
Body
::
STRUCT_NODE
:
{
case
schema
2
:
:
Node
::
STRUCT
:
{
auto
body
=
proto
.
getBody
().
getStructNode
();
auto
structProto
=
proto
.
getStruct
();
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
"struct "
,
name
,
indent
,
"struct "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
genAnnotations
(
schema
),
" { # "
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
genAnnotations
(
schema
),
" { # "
,
body
.
getDataSectionWordSize
()
*
8
,
" bytes, "
,
structProto
.
getDataSectionWordSize
()
*
8
,
" bytes, "
,
body
.
getPointerSectionSize
(),
" ptrs"
,
structProto
.
getPointerSectionSize
(),
" ptrs"
,
body
.
getPreferredListEncoding
()
==
schema
::
ElementSize
::
INLINE_COMPOSITE
structProto
.
getPreferredListEncoding
()
==
schema2
::
ElementSize
::
INLINE_COMPOSITE
?
kj
::
strTree
()
?
kj
::
strTree
()
:
kj
::
strTree
(
", packed as "
,
elementSizeName
(
body
.
getPreferredListEncoding
())),
:
kj
::
strTree
(
", packed as "
,
elementSizeName
(
structProto
.
getPreferredListEncoding
())),
"
\n
"
,
"
\n
"
,
KJ_MAP
(
body
.
getMembers
(),
member
)
{
genStructFields
(
schema
.
asStruct
(),
indent
.
next
()),
return
genStructMember
(
member
,
schema
,
indent
.
next
());
},
genNestedDecls
(
schema
,
indent
.
next
()),
genNestedDecls
(
schema
,
indent
.
next
()),
indent
,
"}
\n
"
);
indent
,
"}
\n
"
);
}
}
case
schema
:
:
Node
::
Body
::
ENUM_NODE
:
{
case
schema2
:
:
Node
::
ENUM
:
{
auto
body
=
proto
.
getBody
().
getEnumNode
();
uint
i
=
0
;
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
(
body
.
getEnumerants
(),
enumerant
)
{
KJ_MAP
(
sortByCodeOrder
(
schema
.
asEnum
().
getEnumerants
()),
enumerant
)
{
return
kj
::
strTree
(
indent
.
next
(),
enumerant
.
getName
(),
" @"
,
i
++
,
return
kj
::
strTree
(
indent
.
next
(),
enumerant
.
getProto
().
getName
(),
" @"
,
genAnnotations
(
enumerant
.
getAnnotations
(),
schema
),
";
\n
"
);
enumerant
.
getIndex
(),
genAnnotations
(
enumerant
.
getProto
().
getAnnotations
(),
schema
),
";
\n
"
);
},
},
genNestedDecls
(
schema
,
indent
.
next
()),
genNestedDecls
(
schema
,
indent
.
next
()),
indent
,
"}
\n
"
);
indent
,
"}
\n
"
);
}
}
case
schema
:
:
Node
::
Body
::
INTERFACE_NODE
:
{
case
schema2
:
:
Node
::
INTERFACE
:
{
auto
body
=
proto
.
getBody
().
getInterfaceNode
();
uint
i
=
0
;
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
(
body
.
getMethods
(),
method
)
{
KJ_MAP
(
sortByCodeOrder
(
schema
.
asInterface
().
getMethods
()),
method
)
{
int
j
=
0
;
int
i
=
0
;
auto
methodProto
=
method
.
getProto
();
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
.
next
(),
method
.
getName
(),
" @"
,
i
++
,
"("
,
indent
.
next
(),
method
Proto
.
getName
(),
" @"
,
method
.
getIndex
()
,
"("
,
KJ_MAP
(
method
.
getParams
(),
param
)
{
KJ_MAP
(
method
Proto
.
getParams
(),
param
)
{
bool
hasDefault
=
j
>=
method
.
getRequiredParamCount
()
||
bool
hasDefault
=
i
>=
methodProto
.
getRequiredParamCount
()
||
!
isEmptyValue
(
param
.
getDefaultValue
());
!
isEmptyValue
(
param
.
getDefaultValue
());
return
kj
::
strTree
(
return
kj
::
strTree
(
j
++
>
0
?
", "
:
""
,
i
++
>
0
?
", "
:
""
,
param
.
getName
(),
": "
,
genType
(
param
.
getType
(),
schema
),
param
.
getName
(),
": "
,
genType
(
param
.
getType
(),
schema
),
hasDefault
hasDefault
?
kj
::
strTree
(
" = "
,
genValue
(
?
kj
::
strTree
(
" = "
,
genValue
(
...
@@ -430,44 +451,48 @@ private:
...
@@ -430,44 +451,48 @@ private:
:
kj
::
strTree
(),
:
kj
::
strTree
(),
genAnnotations
(
param
.
getAnnotations
(),
schema
));
genAnnotations
(
param
.
getAnnotations
(),
schema
));
},
},
") :"
,
genType
(
method
.
getReturnType
(),
schema
),
") :"
,
genType
(
method
Proto
.
getReturnType
(),
schema
),
genAnnotations
(
method
.
getAnnotations
(),
schema
),
";
\n
"
);
genAnnotations
(
method
Proto
.
getAnnotations
(),
schema
),
";
\n
"
);
},
},
genNestedDecls
(
schema
,
indent
.
next
()),
genNestedDecls
(
schema
,
indent
.
next
()),
indent
,
"}
\n
"
);
indent
,
"}
\n
"
);
}
}
case
schema
:
:
Node
::
Body
::
CONST_NODE
:
{
case
schema
2
:
:
Node
::
CONST
:
{
auto
body
=
proto
.
getBody
().
getConstNode
();
auto
constProto
=
proto
.
getConst
();
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
"const "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
" :"
,
indent
,
"const "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
" :"
,
genType
(
body
.
getType
(),
schema
),
" = "
,
genType
(
constProto
.
getType
(),
schema
),
" = "
,
genValue
(
body
.
getType
(),
body
.
getValue
(),
schema
),
";
\n
"
);
genValue
(
constProto
.
getType
(),
constProto
.
getValue
(),
schema
),
";
\n
"
);
}
}
case
schema
:
:
Node
::
Body
::
ANNOTATION_NODE
:
{
case
schema2
:
:
Node
::
ANNOTATION
:
{
auto
body
=
proto
.
getBody
().
getAnnotationNode
();
auto
annotationProto
=
proto
.
getAnnotation
();
kj
::
CappedArray
<
const
char
*
,
11
>
targets
;
uint
i
=
0
;
kj
::
Vector
<
kj
::
String
>
targets
(
8
);
if
(
body
.
getTargetsFile
())
targets
[
i
++
]
=
"file"
;
bool
targetsAll
=
true
;
if
(
body
.
getTargetsConst
())
targets
[
i
++
]
=
"const"
;
if
(
body
.
getTargetsEnum
())
targets
[
i
++
]
=
"enum"
;
auto
dynamic
=
toDynamic
(
annotationProto
);
if
(
body
.
getTargetsEnumerant
())
targets
[
i
++
]
=
"enumerant"
;
for
(
auto
field
:
dynamic
.
getSchema
().
getFields
())
{
if
(
body
.
getTargetsStruct
())
targets
[
i
++
]
=
"struct"
;
auto
fieldName
=
field
.
getProto
().
getName
();
if
(
body
.
getTargetsField
())
targets
[
i
++
]
=
"field"
;
if
(
fieldName
.
startsWith
(
"targets"
))
{
if
(
body
.
getTargetsUnion
())
targets
[
i
++
]
=
"union"
;
if
(
dynamic
.
get
(
field
).
as
<
bool
>
())
{
if
(
body
.
getTargetsInterface
())
targets
[
i
++
]
=
"interface"
;
auto
target
=
kj
::
str
(
fieldName
.
slice
(
strlen
(
"targets"
)));
if
(
body
.
getTargetsMethod
())
targets
[
i
++
]
=
"method"
;
target
[
0
]
=
target
[
0
]
-
'A'
+
'a'
;
if
(
body
.
getTargetsParam
())
targets
[
i
++
]
=
"param"
;
targets
.
add
(
kj
::
mv
(
target
));
if
(
body
.
getTargetsAnnotation
())
targets
[
i
++
]
=
"annotation"
;
}
else
{
if
(
i
==
targets
.
size
())
{
targetsAll
=
false
;
targets
[
0
]
=
"*"
;
}
targets
.
setSize
(
1
);
}
}
else
{
targets
.
setSize
(
i
);
}
}
if
(
targetsAll
)
{
targets
=
kj
::
Vector
<
kj
::
String
>
(
1
);
targets
[
0
]
=
kj
::
heapString
(
"*"
);
}
return
kj
::
strTree
(
return
kj
::
strTree
(
indent
,
"annotation "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
indent
,
"annotation "
,
name
,
" @0x"
,
kj
::
hex
(
proto
.
getId
()),
" ("
,
strArray
(
targets
,
", "
),
") :"
,
" ("
,
strArray
(
targets
,
", "
),
") :"
,
genType
(
body
.
getType
(),
schema
),
genAnnotations
(
schema
),
";
\n
"
);
genType
(
annotationProto
.
getType
(),
schema
),
genAnnotations
(
schema
),
";
\n
"
);
}
}
}
}
...
@@ -483,9 +508,7 @@ private:
...
@@ -483,9 +508,7 @@ private:
kj
::
StringTree
genFile
(
Schema
file
)
{
kj
::
StringTree
genFile
(
Schema
file
)
{
auto
proto
=
file
.
getProto
();
auto
proto
=
file
.
getProto
();
auto
body
=
proto
.
getBody
();
KJ_REQUIRE
(
proto
.
which
()
==
schema2
::
Node
::
FILE
,
"Expected a file node."
,
(
uint
)
proto
.
which
());
KJ_REQUIRE
(
body
.
which
()
==
schema
::
Node
::
Body
::
FILE_NODE
,
"Expected a file node."
,
(
uint
)
body
.
which
());
return
kj
::
strTree
(
return
kj
::
strTree
(
"# "
,
proto
.
getDisplayName
(),
"
\n
"
,
"# "
,
proto
.
getDisplayName
(),
"
\n
"
,
...
@@ -498,7 +521,7 @@ private:
...
@@ -498,7 +521,7 @@ private:
ReaderOptions
options
;
ReaderOptions
options
;
options
.
traversalLimitInWords
=
1
<<
30
;
// Don't limit.
options
.
traversalLimitInWords
=
1
<<
30
;
// Don't limit.
StreamFdMessageReader
reader
(
STDIN_FILENO
,
options
);
StreamFdMessageReader
reader
(
STDIN_FILENO
,
options
);
auto
request
=
reader
.
getRoot
<
schema
::
CodeGeneratorRequest
>
();
auto
request
=
reader
.
getRoot
<
schema
2
::
CodeGeneratorRequest
>
();
for
(
auto
node
:
request
.
getNodes
())
{
for
(
auto
node
:
request
.
getNodes
())
{
schemaLoader
.
load
(
node
);
schemaLoader
.
load
(
node
);
...
@@ -507,8 +530,8 @@ private:
...
@@ -507,8 +530,8 @@ private:
kj
::
FdOutputStream
rawOut
(
STDOUT_FILENO
);
kj
::
FdOutputStream
rawOut
(
STDOUT_FILENO
);
kj
::
BufferedOutputStreamWrapper
out
(
rawOut
);
kj
::
BufferedOutputStreamWrapper
out
(
rawOut
);
for
(
auto
fileId
:
request
.
getRequestedFiles
())
{
for
(
auto
requestedFile
:
request
.
getRequestedFiles
())
{
genFile
(
schemaLoader
.
get
(
fileId
)).
visit
(
genFile
(
schemaLoader
.
get
(
requestedFile
.
getId
()
)).
visit
(
[
&
](
kj
::
ArrayPtr
<
const
char
>
text
)
{
[
&
](
kj
::
ArrayPtr
<
const
char
>
text
)
{
out
.
write
(
text
.
begin
(),
text
.
size
());
out
.
write
(
text
.
begin
(),
text
.
size
());
});
});
...
...
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