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
13ab0872
Commit
13ab0872
authored
Apr 25, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compile inline lists (TODO: code generation).
parent
7f20d533
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
44 deletions
+96
-44
Compiler.hs
compiler/src/Compiler.hs
+38
-23
CxxGenerator.hs
compiler/src/CxxGenerator.hs
+2
-1
Grammar.hs
compiler/src/Grammar.hs
+9
-2
Parser.hs
compiler/src/Parser.hs
+5
-1
Semantics.hs
compiler/src/Semantics.hs
+28
-13
WireFormat.hs
compiler/src/WireFormat.hs
+0
-0
c++-header.mustache
compiler/src/c++-header.mustache
+14
-4
No files found.
compiler/src/Compiler.hs
View file @
13ab0872
...
@@ -161,7 +161,10 @@ lookupDesc scope name = lookupDesc (descParent scope) name
...
@@ -161,7 +161,10 @@ lookupDesc scope name = lookupDesc (descParent scope) name
builtinTypeMap
::
Map
.
Map
String
Desc
builtinTypeMap
::
Map
.
Map
String
Desc
builtinTypeMap
=
Map
.
fromList
builtinTypeMap
=
Map
.
fromList
([(
builtinTypeName
t
,
DescBuiltinType
t
)
|
t
<-
builtinTypes
]
++
([(
builtinTypeName
t
,
DescBuiltinType
t
)
|
t
<-
builtinTypes
]
++
[(
"List"
,
DescBuiltinList
),
(
"Inline"
,
DescBuiltinInline
),
(
"id"
,
DescBuiltinId
)])
[(
"List"
,
DescBuiltinList
),
(
"Inline"
,
DescBuiltinInline
),
(
"InlineList"
,
DescBuiltinInlineList
),
(
"id"
,
DescBuiltinId
)])
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
...
@@ -246,6 +249,12 @@ compileValue pos (InlineStructType desc) v = compileValue pos (StructType desc)
...
@@ -246,6 +249,12 @@ compileValue pos (InlineStructType desc) v = compileValue pos (StructType desc)
compileValue
_
(
ListType
t
)
(
ListFieldValue
l
)
=
compileValue
_
(
ListType
t
)
(
ListFieldValue
l
)
=
fmap
ListDesc
(
doAll
[
compileValue
vpos
t
v
|
Located
vpos
v
<-
l
])
fmap
ListDesc
(
doAll
[
compileValue
vpos
t
v
|
Located
vpos
v
<-
l
])
compileValue
pos
(
InlineListType
t
s
)
(
ListFieldValue
l
)
=
do
elements
<-
doAll
[
compileValue
vpos
t
v
|
Located
vpos
v
<-
l
]
when
(
List
.
genericLength
elements
/=
s
)
$
makeError
pos
$
printf
"Fixed-size list must have exactly %d elements."
s
return
$
ListDesc
elements
compileValue
pos
(
BuiltinType
BuiltinVoid
)
_
=
makeError
pos
"Void fields cannot have values."
compileValue
pos
(
BuiltinType
BuiltinVoid
)
_
=
makeError
pos
"Void fields cannot have values."
compileValue
pos
(
BuiltinType
BuiltinBool
)
_
=
makeExpectError
pos
"boolean"
compileValue
pos
(
BuiltinType
BuiltinBool
)
_
=
makeExpectError
pos
"boolean"
compileValue
pos
(
BuiltinType
BuiltinInt8
)
_
=
makeExpectError
pos
"integer"
compileValue
pos
(
BuiltinType
BuiltinInt8
)
_
=
makeExpectError
pos
"integer"
...
@@ -263,9 +272,9 @@ compileValue pos (BuiltinType BuiltinData) _ = makeExpectError pos "string"
...
@@ -263,9 +272,9 @@ compileValue pos (BuiltinType BuiltinData) _ = makeExpectError pos "string"
compileValue
pos
(
EnumType
_
)
_
=
makeExpectError
pos
"enumerant name"
compileValue
pos
(
EnumType
_
)
_
=
makeExpectError
pos
"enumerant name"
compileValue
pos
(
StructType
_
)
_
=
makeExpectError
pos
"parenthesized list of field assignments"
compileValue
pos
(
StructType
_
)
_
=
makeExpectError
pos
"parenthesized list of field assignments"
compileValue
pos
(
InlineStructType
_
)
_
=
makeExpectError
pos
"parenthesized list of field assignments"
compileValue
pos
(
InterfaceType
_
)
_
=
makeError
pos
"Interfaces can't have default values."
compileValue
pos
(
InterfaceType
_
)
_
=
makeError
pos
"Interfaces can't have default values."
compileValue
pos
(
ListType
_
)
_
=
makeExpectError
pos
"list"
compileValue
pos
(
ListType
_
)
_
=
makeExpectError
pos
"list"
compileValue
pos
(
InlineListType
_
_
)
_
=
makeExpectError
pos
"list"
descAsType
_
(
DescEnum
desc
)
=
succeed
(
EnumType
desc
)
descAsType
_
(
DescEnum
desc
)
=
succeed
(
EnumType
desc
)
descAsType
_
(
DescStruct
desc
)
=
succeed
(
StructType
desc
)
descAsType
_
(
DescStruct
desc
)
=
succeed
(
StructType
desc
)
...
@@ -276,33 +285,39 @@ descAsType name DescBuiltinList = makeError (declNamePos name) message where
...
@@ -276,33 +285,39 @@ descAsType name DescBuiltinList = makeError (declNamePos name) message where
message
=
printf
"'List' requires exactly one type parameter."
(
declNameString
name
)
message
=
printf
"'List' requires exactly one type parameter."
(
declNameString
name
)
descAsType
name
DescBuiltinInline
=
makeError
(
declNamePos
name
)
message
where
descAsType
name
DescBuiltinInline
=
makeError
(
declNamePos
name
)
message
where
message
=
printf
"'Inline' requires exactly one type parameter."
(
declNameString
name
)
message
=
printf
"'Inline' requires exactly one type parameter."
(
declNameString
name
)
descAsType
name
DescBuiltinInlineList
=
makeError
(
declNamePos
name
)
message
where
message
=
printf
"'InlineList' requires exactly one type parameter."
(
declNameString
name
)
descAsType
name
_
=
makeError
(
declNamePos
name
)
message
where
descAsType
name
_
=
makeError
(
declNamePos
name
)
message
where
message
=
printf
"'%s' is not a type."
(
declNameString
name
)
message
=
printf
"'%s' is not a type."
(
declNameString
name
)
compileType
::
Desc
->
TypeExpression
->
Status
TypeDesc
compileType
::
Desc
->
TypeExpression
->
Status
TypeDesc
compileType
scope
(
TypeExpression
n
[]
)
=
do
compileType
scope
(
TypeExpression
n
params
)
=
do
desc
<-
lookupDesc
scope
n
descAsType
n
desc
compileType
scope
(
TypeExpression
n
(
param
:
moreParams
))
=
do
desc
<-
lookupDesc
scope
n
desc
<-
lookupDesc
scope
n
case
desc
of
case
desc
of
DescBuiltinList
->
DescBuiltinList
->
case
params
of
if
null
moreParams
[
TypeParameterType
param
]
->
fmap
ListType
(
compileType
scope
param
)
then
fmap
ListType
(
compileType
scope
param
)
_
->
makeError
(
declNamePos
n
)
"'List' requires exactly one type parameter."
else
makeError
(
declNamePos
n
)
"'List' requires exactly one type parameter."
DescBuiltinInline
->
case
params
of
DescBuiltinInline
->
[
TypeParameterType
param
]
->
do
if
null
moreParams
inner
<-
compileType
scope
param
then
do
case
inner
of
inner
<-
compileType
scope
param
StructType
s
->
if
structIsFixedWidth
s
case
inner
of
then
return
(
InlineStructType
s
)
StructType
s
->
if
structIsFixedWidth
s
else
makeError
(
declNamePos
n
)
$
then
return
(
InlineStructType
s
)
printf
"'%s' cannot be inlined because it is not fixed-width."
else
makeError
(
declNamePos
n
)
$
(
structName
s
)
printf
"'%s' cannot be inlined because it is not fixed-width."
_
->
makeError
(
declNamePos
n
)
"'Inline' parameter must be a struct type."
(
structName
s
)
_
->
makeError
(
declNamePos
n
)
"'Inline' requires exactly one type parameter."
_
->
makeError
(
declNamePos
n
)
"'Inline' parameter must be a struct type."
DescBuiltinInlineList
->
case
params
of
else
makeError
(
declNamePos
n
)
"'Inline' requires exactly one type parameter."
[
TypeParameterType
param
,
TypeParameterInteger
size
]
->
do
_
->
makeError
(
declNamePos
n
)
"Only the type 'List' can have type parameters."
inner
<-
compileType
scope
param
return
$
InlineListType
inner
size
_
->
makeError
(
declNamePos
n
)
"'InlineList' requires exactly two type parameters: a type and a size."
_
->
case
params
of
[]
->
descAsType
n
desc
_
->
makeError
(
declNamePos
n
)
$
printf
"'%s' doesn't take parameters."
(
declNameString
n
)
compileAnnotation
::
Desc
->
AnnotationTarget
->
Annotation
compileAnnotation
::
Desc
->
AnnotationTarget
->
Annotation
->
Status
(
Maybe
AnnotationDesc
,
ValueDesc
)
->
Status
(
Maybe
AnnotationDesc
,
ValueDesc
)
...
...
compiler/src/CxxGenerator.hs
View file @
13ab0872
...
@@ -91,6 +91,7 @@ isPrimitive (StructType _) = False
...
@@ -91,6 +91,7 @@ isPrimitive (StructType _) = False
isPrimitive
(
InlineStructType
_
)
=
False
isPrimitive
(
InlineStructType
_
)
=
False
isPrimitive
(
InterfaceType
_
)
=
False
isPrimitive
(
InterfaceType
_
)
=
False
isPrimitive
(
ListType
_
)
=
False
isPrimitive
(
ListType
_
)
=
False
isPrimitive
(
InlineListType
_
_
)
=
False
isBlob
(
BuiltinType
BuiltinText
)
=
True
isBlob
(
BuiltinType
BuiltinText
)
=
True
isBlob
(
BuiltinType
BuiltinData
)
=
True
isBlob
(
BuiltinType
BuiltinData
)
=
True
...
@@ -254,7 +255,7 @@ fieldContext parent desc = mkStrContext context where
...
@@ -254,7 +255,7 @@ fieldContext parent desc = mkStrContext context where
Nothing
->
MuVariable
""
Nothing
->
MuVariable
""
Just
v
->
MuVariable
(
if
isDefaultZero
v
then
""
else
", "
++
defaultMask
v
)
Just
v
->
MuVariable
(
if
isDefaultZero
v
then
""
else
", "
++
defaultMask
v
)
context
"fieldElementSize"
=
context
"fieldElementSize"
=
MuVariable
$
cxxFieldSizeString
$
element
Size
$
elementType
$
fieldType
desc
MuVariable
$
cxxFieldSizeString
$
field
Size
$
elementType
$
fieldType
desc
context
"fieldElementType"
=
context
"fieldElementType"
=
MuVariable
$
cxxTypeString
$
elementType
$
fieldType
desc
MuVariable
$
cxxTypeString
$
elementType
$
fieldType
desc
context
"fieldUnion"
=
case
fieldUnion
desc
of
context
"fieldUnion"
=
case
fieldUnion
desc
of
...
...
compiler/src/Grammar.hs
View file @
13ab0872
...
@@ -38,12 +38,19 @@ declNameImport (RelativeName _) = Nothing
...
@@ -38,12 +38,19 @@ declNameImport (RelativeName _) = Nothing
declNameImport
(
ImportName
s
)
=
Just
s
declNameImport
(
ImportName
s
)
=
Just
s
declNameImport
(
MemberName
parent
_
)
=
declNameImport
parent
declNameImport
(
MemberName
parent
_
)
=
declNameImport
parent
data
TypeExpression
=
TypeExpression
DeclName
[
TypeExpression
]
data
TypeParameter
=
TypeParameterType
TypeExpression
|
TypeParameterInteger
Integer
deriving
(
Show
)
data
TypeExpression
=
TypeExpression
DeclName
[
TypeParameter
]
deriving
(
Show
)
deriving
(
Show
)
typeParameterImports
::
TypeParameter
->
[
Located
String
]
typeParameterImports
(
TypeParameterType
t
)
=
typeImports
t
typeParameterImports
(
TypeParameterInteger
_
)
=
[]
typeImports
::
TypeExpression
->
[
Located
String
]
typeImports
::
TypeExpression
->
[
Located
String
]
typeImports
(
TypeExpression
name
params
)
=
typeImports
(
TypeExpression
name
params
)
=
maybeToList
(
declNameImport
name
)
++
concatMap
typeImports
params
maybeToList
(
declNameImport
name
)
++
concatMap
type
Parameter
Imports
params
data
Annotation
=
Annotation
DeclName
(
Located
FieldValue
)
deriving
(
Show
)
data
Annotation
=
Annotation
DeclName
(
Located
FieldValue
)
deriving
(
Show
)
...
...
compiler/src/Parser.hs
View file @
13ab0872
...
@@ -149,10 +149,14 @@ declName = do
...
@@ -149,10 +149,14 @@ declName = do
members
<-
many
(
period
>>
located
anyIdentifier
)
members
<-
many
(
period
>>
located
anyIdentifier
)
return
(
foldl
MemberName
base
members
::
DeclName
)
return
(
foldl
MemberName
base
members
::
DeclName
)
typeParameter
::
TokenParser
TypeParameter
typeParameter
=
liftM
TypeParameterInteger
literalInt
<|>
liftM
TypeParameterType
typeExpression
typeExpression
::
TokenParser
TypeExpression
typeExpression
::
TokenParser
TypeExpression
typeExpression
=
do
typeExpression
=
do
name
<-
declName
name
<-
declName
suffixes
<-
option
[]
(
parenthesizedList
type
Expression
)
suffixes
<-
option
[]
(
parenthesizedList
type
Parameter
)
return
(
TypeExpression
name
suffixes
)
return
(
TypeExpression
name
suffixes
)
nameWithOrdinal
::
TokenParser
(
Located
String
,
Located
Integer
)
nameWithOrdinal
::
TokenParser
(
Located
String
,
Located
Integer
)
...
...
compiler/src/Semantics.hs
View file @
13ab0872
...
@@ -56,6 +56,7 @@ data Desc = DescFile FileDesc
...
@@ -56,6 +56,7 @@ data Desc = DescFile FileDesc
|
DescBuiltinType
BuiltinType
|
DescBuiltinType
BuiltinType
|
DescBuiltinList
|
DescBuiltinList
|
DescBuiltinInline
|
DescBuiltinInline
|
DescBuiltinInlineList
|
DescBuiltinId
|
DescBuiltinId
descName
(
DescFile
_
)
=
"(top-level)"
descName
(
DescFile
_
)
=
"(top-level)"
...
@@ -73,6 +74,7 @@ descName (DescAnnotation d) = annotationName d
...
@@ -73,6 +74,7 @@ descName (DescAnnotation d) = annotationName d
descName
(
DescBuiltinType
d
)
=
builtinTypeName
d
descName
(
DescBuiltinType
d
)
=
builtinTypeName
d
descName
DescBuiltinList
=
"List"
descName
DescBuiltinList
=
"List"
descName
DescBuiltinInline
=
"Inline"
descName
DescBuiltinInline
=
"Inline"
descName
DescBuiltinInlineList
=
"InlineList"
descName
DescBuiltinId
=
"id"
descName
DescBuiltinId
=
"id"
descId
(
DescFile
d
)
=
fileId
d
descId
(
DescFile
d
)
=
fileId
d
...
@@ -90,6 +92,7 @@ descId (DescAnnotation d) = annotationId d
...
@@ -90,6 +92,7 @@ descId (DescAnnotation d) = annotationId d
descId
(
DescBuiltinType
_
)
=
Nothing
descId
(
DescBuiltinType
_
)
=
Nothing
descId
DescBuiltinList
=
Nothing
descId
DescBuiltinList
=
Nothing
descId
DescBuiltinInline
=
Nothing
descId
DescBuiltinInline
=
Nothing
descId
DescBuiltinInlineList
=
Nothing
descId
DescBuiltinId
=
Just
"0U0T3e_SnatEfk6UcH2tcjTt1E0"
descId
DescBuiltinId
=
Just
"0U0T3e_SnatEfk6UcH2tcjTt1E0"
-- Gets the ID if explicitly defined, or generates it by appending ".name" to the parent's ID.
-- Gets the ID if explicitly defined, or generates it by appending ".name" to the parent's ID.
...
@@ -115,6 +118,7 @@ descParent (DescAnnotation d) = annotationParent d
...
@@ -115,6 +118,7 @@ descParent (DescAnnotation d) = annotationParent d
descParent
(
DescBuiltinType
_
)
=
error
"Builtin type has no parent."
descParent
(
DescBuiltinType
_
)
=
error
"Builtin type has no parent."
descParent
DescBuiltinList
=
error
"Builtin type has no parent."
descParent
DescBuiltinList
=
error
"Builtin type has no parent."
descParent
DescBuiltinInline
=
error
"Builtin type has no parent."
descParent
DescBuiltinInline
=
error
"Builtin type has no parent."
descParent
DescBuiltinInlineList
=
error
"Builtin type has no parent."
descParent
DescBuiltinId
=
error
"Builtin annotation has no parent."
descParent
DescBuiltinId
=
error
"Builtin annotation has no parent."
descFile
(
DescFile
d
)
=
d
descFile
(
DescFile
d
)
=
d
...
@@ -135,6 +139,7 @@ descAnnotations (DescAnnotation d) = annotationAnnotations d
...
@@ -135,6 +139,7 @@ descAnnotations (DescAnnotation d) = annotationAnnotations d
descAnnotations
(
DescBuiltinType
_
)
=
Map
.
empty
descAnnotations
(
DescBuiltinType
_
)
=
Map
.
empty
descAnnotations
DescBuiltinList
=
Map
.
empty
descAnnotations
DescBuiltinList
=
Map
.
empty
descAnnotations
DescBuiltinInline
=
Map
.
empty
descAnnotations
DescBuiltinInline
=
Map
.
empty
descAnnotations
DescBuiltinInlineList
=
Map
.
empty
descAnnotations
DescBuiltinId
=
Map
.
empty
descAnnotations
DescBuiltinId
=
Map
.
empty
descRuntimeImports
(
DescFile
_
)
=
error
"Not to be called on files."
descRuntimeImports
(
DescFile
_
)
=
error
"Not to be called on files."
...
@@ -152,6 +157,7 @@ descRuntimeImports (DescAnnotation d) = annotationRuntimeImports d
...
@@ -152,6 +157,7 @@ descRuntimeImports (DescAnnotation d) = annotationRuntimeImports d
descRuntimeImports
(
DescBuiltinType
_
)
=
[]
descRuntimeImports
(
DescBuiltinType
_
)
=
[]
descRuntimeImports
DescBuiltinList
=
[]
descRuntimeImports
DescBuiltinList
=
[]
descRuntimeImports
DescBuiltinInline
=
[]
descRuntimeImports
DescBuiltinInline
=
[]
descRuntimeImports
DescBuiltinInlineList
=
[]
descRuntimeImports
DescBuiltinId
=
[]
descRuntimeImports
DescBuiltinId
=
[]
type
MemberMap
=
Map
.
Map
String
(
Maybe
Desc
)
type
MemberMap
=
Map
.
Map
String
(
Maybe
Desc
)
...
@@ -221,6 +227,7 @@ data TypeDesc = BuiltinType BuiltinType
...
@@ -221,6 +227,7 @@ data TypeDesc = BuiltinType BuiltinType
|
InlineStructType
StructDesc
|
InlineStructType
StructDesc
|
InterfaceType
InterfaceDesc
|
InterfaceType
InterfaceDesc
|
ListType
TypeDesc
|
ListType
TypeDesc
|
InlineListType
TypeDesc
Integer
typeRuntimeImports
(
BuiltinType
_
)
=
[]
typeRuntimeImports
(
BuiltinType
_
)
=
[]
typeRuntimeImports
(
EnumType
d
)
=
[
descFile
(
DescEnum
d
)]
typeRuntimeImports
(
EnumType
d
)
=
[
descFile
(
DescEnum
d
)]
...
@@ -228,6 +235,7 @@ typeRuntimeImports (StructType d) = [descFile (DescStruct d)]
...
@@ -228,6 +235,7 @@ typeRuntimeImports (StructType d) = [descFile (DescStruct d)]
typeRuntimeImports
(
InlineStructType
d
)
=
[
descFile
(
DescStruct
d
)]
typeRuntimeImports
(
InlineStructType
d
)
=
[
descFile
(
DescStruct
d
)]
typeRuntimeImports
(
InterfaceType
d
)
=
[
descFile
(
DescInterface
d
)]
typeRuntimeImports
(
InterfaceType
d
)
=
[
descFile
(
DescInterface
d
)]
typeRuntimeImports
(
ListType
d
)
=
typeRuntimeImports
d
typeRuntimeImports
(
ListType
d
)
=
typeRuntimeImports
d
typeRuntimeImports
(
InlineListType
d
_
)
=
typeRuntimeImports
d
data
DataSectionSize
=
DataSection1
|
DataSection8
|
DataSection16
|
DataSection32
data
DataSectionSize
=
DataSection1
|
DataSection8
|
DataSection16
|
DataSection32
|
DataSectionWords
Integer
|
DataSectionWords
Integer
...
@@ -310,19 +318,24 @@ fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount
...
@@ -310,19 +318,24 @@ fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount
SizeInlineComposite
ds
ps
SizeInlineComposite
ds
ps
fieldSize
(
InterfaceType
_
)
=
SizeReference
fieldSize
(
InterfaceType
_
)
=
SizeReference
fieldSize
(
ListType
_
)
=
SizeReference
fieldSize
(
ListType
_
)
=
SizeReference
fieldSize
(
InlineListType
element
size
)
=
let
elementSize
(
StructType
StructDesc
{
structDataSize
=
DataSection1
,
structPointerCount
=
0
})
=
minDataSectionForBits
bits
SizeData
Size1
|
bits
<=
1
=
DataSection1
elementSize
(
StructType
StructDesc
{
structDataSize
=
DataSection8
,
structPointerCount
=
0
})
=
|
bits
<=
8
=
DataSection8
SizeData
Size8
|
bits
<=
16
=
DataSection16
elementSize
(
StructType
StructDesc
{
structDataSize
=
DataSection16
,
structPointerCount
=
0
})
=
|
bits
<=
32
=
DataSection32
SizeData
Size16
|
otherwise
=
DataSectionWords
$
div
(
bits
+
63
)
64
elementSize
(
StructType
StructDesc
{
structDataSize
=
DataSection32
,
structPointerCount
=
0
})
=
dataSection
=
case
fieldSize
element
of
SizeData
Size32
SizeVoid
->
DataSectionWords
0
elementSize
(
StructType
StructDesc
{
structDataSize
=
ds
,
structPointerCount
=
pc
})
=
SizeData
s
->
minDataSectionForBits
$
dataSizeInBits
s
*
size
SizeInlineComposite
ds
pc
SizeReference
->
DataSectionWords
0
elementSize
(
InlineStructType
s
)
=
elementSize
(
StructType
s
)
SizeInlineComposite
ds
_
->
minDataSectionForBits
$
dataSectionBits
ds
elementSize
t
=
fieldSize
t
pointerCount
=
case
fieldSize
element
of
SizeVoid
->
0
SizeData
_
->
0
SizeReference
->
size
SizeInlineComposite
_
pc
->
pc
in
SizeInlineComposite
dataSection
pointerCount
-- Render the type descriptor's name as a string, appropriate for use in the given scope.
-- Render the type descriptor's name as a string, appropriate for use in the given scope.
typeName
::
Desc
->
TypeDesc
->
String
typeName
::
Desc
->
TypeDesc
->
String
...
@@ -332,6 +345,7 @@ typeName scope (StructType desc) = descQualifiedName scope (DescStruct desc)
...
@@ -332,6 +345,7 @@ typeName scope (StructType desc) = descQualifiedName scope (DescStruct desc)
typeName
scope
(
InlineStructType
desc
)
=
descQualifiedName
scope
(
DescStruct
desc
)
typeName
scope
(
InlineStructType
desc
)
=
descQualifiedName
scope
(
DescStruct
desc
)
typeName
scope
(
InterfaceType
desc
)
=
descQualifiedName
scope
(
DescInterface
desc
)
typeName
scope
(
InterfaceType
desc
)
=
descQualifiedName
scope
(
DescInterface
desc
)
typeName
scope
(
ListType
t
)
=
"List("
++
typeName
scope
t
++
")"
typeName
scope
(
ListType
t
)
=
"List("
++
typeName
scope
t
++
")"
typeName
scope
(
InlineListType
t
s
)
=
printf
"InlineList(%s, %d)"
(
typeName
scope
t
)
s
-- Computes the qualified name for the given descriptor within the given scope.
-- Computes the qualified name for the given descriptor within the given scope.
-- At present the scope is only used to determine whether the target is in the same file. If
-- At present the scope is only used to determine whether the target is in the same file. If
...
@@ -589,6 +603,7 @@ descToCode indent self@(DescAnnotation desc) = printf "%sannotation %s: %s on(%s
...
@@ -589,6 +603,7 @@ descToCode indent self@(DescAnnotation desc) = printf "%sannotation %s: %s on(%s
descToCode
_
(
DescBuiltinType
_
)
=
error
"Can't print code for builtin type."
descToCode
_
(
DescBuiltinType
_
)
=
error
"Can't print code for builtin type."
descToCode
_
DescBuiltinList
=
error
"Can't print code for builtin type."
descToCode
_
DescBuiltinList
=
error
"Can't print code for builtin type."
descToCode
_
DescBuiltinInline
=
error
"Can't print code for builtin type."
descToCode
_
DescBuiltinInline
=
error
"Can't print code for builtin type."
descToCode
_
DescBuiltinInlineList
=
error
"Can't print code for builtin type."
descToCode
_
DescBuiltinId
=
error
"Can't print code for builtin annotation."
descToCode
_
DescBuiltinId
=
error
"Can't print code for builtin annotation."
maybeBlockCode
::
String
->
[
Desc
]
->
String
maybeBlockCode
::
String
->
[
Desc
]
->
String
...
...
compiler/src/WireFormat.hs
View file @
13ab0872
This diff is collapsed.
Click to expand it.
compiler/src/c++-header.mustache
View file @
13ab0872
...
@@ -355,7 +355,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}()
...
@@ -355,7 +355,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}()
{{/
fieldIsInlineStruct
}}
{{/
fieldIsInlineStruct
}}
{{/
fieldIsStruct
}}
{{/
fieldIsStruct
}}
{{! ------------------------------------------------------------------------------------------- }}
{{! ------------------------------------------------------------------------------------------- }}
{{#
fieldIsList
}}
{{#
fieldIs
NonStruct
List
}}
inline
{{
fieldType
}}
::Reader
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
() {
inline
{{
fieldType
}}
::Reader
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
{{#
fieldUnion
}}
CAPNPROTO_INLINE_DPRECOND(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
CAPNPROTO_INLINE_DPRECOND(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
...
@@ -367,9 +367,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
...
@@ -367,9 +367,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
{{#
fieldDefaultBytes
}}
DEFAULT_
{{
fieldUpperCase
}}
.words
{{/
fieldDefaultBytes
}}
{{#
fieldDefaultBytes
}}
DEFAULT_
{{
fieldUpperCase
}}
.words
{{/
fieldDefaultBytes
}}
{{^
fieldDefaultBytes
}}
nullptr
{{/
fieldDefaultBytes
}}
));
{{^
fieldDefaultBytes
}}
nullptr
{{/
fieldDefaultBytes
}}
));
}
}
{{/
fieldIsList
}}
{{! ------------------------------------------------------------------------------------------- }}
{{#
fieldIsNonStructList
}}
inline
{{
fieldType
}}
::Builder
{{
typeFullName
}}
::Builder::init
{{
fieldTitleCase
}}
(unsigned int size) {
inline
{{
fieldType
}}
::Builder
{{
typeFullName
}}
::Builder::init
{{
fieldTitleCase
}}
(unsigned int size) {
{{#
fieldUnion
}}
{{#
fieldUnion
}}
_builder.setDataField
<
{{
unionTitleCase
}}
::Which>
(
_builder.setDataField
<
{{
unionTitleCase
}}
::Which>
(
...
@@ -423,6 +421,18 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(
...
@@ -423,6 +421,18 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(
{{/
fieldIsNonStructList
}}
{{/
fieldIsNonStructList
}}
{{! ------------------------------------------------------------------------------------------- }}
{{! ------------------------------------------------------------------------------------------- }}
{{#
fieldIsStructList
}}
{{#
fieldIsStructList
}}
inline
{{
fieldType
}}
::Reader
{{
typeFullName
}}
::Reader::get
{{
fieldTitleCase
}}
() {
{{#
fieldUnion
}}
CAPNPROTO_INLINE_DPRECOND(which() ==
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
,
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Reader(_reader.getListField(
{{
fieldOffset
}}
* ::capnproto::REFERENCES,
::capnproto::internal::FieldSize::INLINE_COMPOSITE,
{{#
fieldDefaultBytes
}}
DEFAULT_
{{
fieldUpperCase
}}
.words
{{/
fieldDefaultBytes
}}
{{^
fieldDefaultBytes
}}
nullptr
{{/
fieldDefaultBytes
}}
));
}
inline
{{
fieldType
}}
::Builder
{{
typeFullName
}}
::Builder::init
{{
fieldTitleCase
}}
(unsigned int size) {
inline
{{
fieldType
}}
::Builder
{{
typeFullName
}}
::Builder::init
{{
fieldTitleCase
}}
(unsigned int size) {
{{#
fieldUnion
}}
{{#
fieldUnion
}}
_builder.setDataField
<
{{
unionTitleCase
}}
::Which>
(
_builder.setDataField
<
{{
unionTitleCase
}}
::Which>
(
...
...
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