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
1a515be7
Commit
1a515be7
authored
May 09, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify generated code by using PointerHelpers templates.
parent
e4784bc8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
41 deletions
+54
-41
generated-header-support.h
c++/src/capnproto/generated-header-support.h
+42
-37
layout.h
c++/src/capnproto/layout.h
+4
-4
list.h
c++/src/capnproto/list.h
+0
-0
CxxGenerator.hs
compiler/src/CxxGenerator.hs
+8
-0
c++-header.mustache
compiler/src/c++-header.mustache
+0
-0
No files found.
c++/src/capnproto/generated-header-support.h
View file @
1a515be7
...
...
@@ -36,12 +36,19 @@ class DynamicStruct; // So that it can be declared a friend.
namespace
internal
{
template
<
typename
T
>
struct
PointerHelpers
{
static
inline
typename
T
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
)
{
return
typename
T
::
Reader
(
reader
.
getStructField
(
index
,
nullptr
));
struct
PointerHelpers
<
T
,
Kind
::
STRUCT
>
{
static
inline
typename
T
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
,
const
word
*
defaultValue
=
nullptr
)
{
return
typename
T
::
Reader
(
reader
.
getStructField
(
index
,
defaultValue
));
}
static
inline
typename
T
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
typename
T
::
Builder
(
builder
.
getStructField
(
index
,
structSize
<
T
>
(),
nullptr
));
static
inline
typename
T
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
,
const
word
*
defaultValue
=
nullptr
)
{
return
typename
T
::
Builder
(
builder
.
getStructField
(
index
,
structSize
<
T
>
(),
defaultValue
));
}
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
typename
T
::
Reader
value
)
{
// TODO(soon)
CAPNPROTO_INLINE_PRECOND
(
false
,
"Not implemented: set() for struct fields."
);
}
static
inline
typename
T
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
typename
T
::
Builder
(
builder
.
initStructField
(
index
,
structSize
<
T
>
()));
...
...
@@ -49,48 +56,46 @@ struct PointerHelpers {
};
template
<
typename
T
>
struct
PointerHelpers
<
List
<
T
>>
{
static
inline
typename
List
<
T
>::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
)
{
return
typename
List
<
T
>::
Reader
(
List
<
T
>::
getAsFieldOf
(
reader
,
index
));
}
static
inline
typename
List
<
T
>::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
typename
List
<
T
>::
Builder
(
List
<
T
>::
getAsFieldOf
(
builder
,
index
));
}
static
inline
typename
List
<
T
>::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
int
size
)
{
return
typename
List
<
T
>::
Builder
(
List
<
T
>::
initAsFieldOf
(
builder
,
index
,
size
));
struct
PointerHelpers
<
List
<
T
>
,
Kind
::
LIST
>
{
static
inline
typename
List
<
T
>::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
,
const
word
*
defaultValue
=
nullptr
)
{
return
typename
List
<
T
>::
Reader
(
List
<
T
>::
getAsFieldOf
(
reader
,
index
,
defaultValue
));
}
};
template
<>
struct
PointerHelpers
<
Text
>
{
static
inline
Text
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
)
{
return
reader
.
getBlobField
<
Text
>
(
index
,
nullptr
,
0
*
BYTES
);
static
inline
typename
List
<
T
>::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
,
const
word
*
defaultValue
=
nullptr
)
{
return
typename
List
<
T
>::
Builder
(
List
<
T
>::
getAsFieldOf
(
builder
,
index
,
defaultValue
));
}
static
inline
Text
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
builder
.
getBlobField
<
Text
>
(
index
,
nullptr
,
0
*
BYTES
);
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
typename
List
<
T
>::
Reader
value
)
{
init
(
builder
,
index
,
value
.
size
()).
copyFrom
(
value
);
}
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
Text
::
Reader
value
)
{
builder
.
setBlobField
<
Text
>
(
index
,
value
);
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
std
::
initializer_list
<
ReaderFor
<
T
>>
value
)
{
init
(
builder
,
index
,
value
.
size
()).
copyFrom
(
value
);
}
static
inline
Text
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
int
size
)
{
return
builder
.
initBlobField
<
Text
>
(
index
,
size
*
BYTES
);
static
inline
typename
List
<
T
>::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
uint
size
)
{
return
typename
List
<
T
>::
Builder
(
List
<
T
>::
initAsFieldOf
(
builder
,
index
,
size
));
}
};
template
<>
struct
PointerHelpers
<
Data
>
{
static
inline
Data
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
)
{
return
reader
.
getBlobField
<
Data
>
(
index
,
nullptr
,
0
*
BYTES
);
template
<
typename
T
>
struct
PointerHelpers
<
T
,
Kind
::
BLOB
>
{
static
inline
typename
T
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
,
const
void
*
defaultValue
=
nullptr
,
uint
defaultBytes
=
0
)
{
return
reader
.
getBlobField
<
T
>
(
index
,
defaultValue
,
defaultBytes
*
BYTES
);
}
static
inline
Data
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
builder
.
getBlobField
<
Data
>
(
index
,
nullptr
,
0
*
BYTES
);
static
inline
typename
T
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
,
const
void
*
defaultValue
=
nullptr
,
uint
defaultBytes
=
0
)
{
return
builder
.
getBlobField
<
T
>
(
index
,
defaultValue
,
defaultBytes
*
BYTES
);
}
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
Data
::
Reader
value
)
{
builder
.
setBlobField
<
Data
>
(
index
,
value
);
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
typename
T
::
Reader
value
)
{
builder
.
setBlobField
<
T
>
(
index
,
value
);
}
static
inline
Data
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
int
size
)
{
return
builder
.
initBlobField
<
Data
>
(
index
,
size
*
BYTES
);
static
inline
typename
T
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
u
int
size
)
{
return
builder
.
initBlobField
<
T
>
(
index
,
size
*
BYTES
);
}
};
...
...
c++/src/capnproto/layout.h
View file @
1a515be7
...
...
@@ -486,7 +486,7 @@ public:
:
segment
(
nullptr
),
ptr
(
nullptr
),
elementCount
(
0
*
ELEMENTS
),
step
(
0
*
BITS
/
ELEMENTS
)
{}
inline
ElementCount
size
();
inline
ElementCount
size
()
const
;
// The number of elements in the list.
Text
::
Builder
asText
();
...
...
@@ -570,7 +570,7 @@ public:
:
segment
(
nullptr
),
ptr
(
nullptr
),
elementCount
(
0
),
step
(
0
*
BITS
/
ELEMENTS
),
structDataSize
(
0
),
structReferenceCount
(
0
),
nestingLimit
(
0
)
{}
inline
ElementCount
size
();
inline
ElementCount
size
()
const
;
// The number of elements in the list.
Text
::
Reader
asText
();
...
...
@@ -767,7 +767,7 @@ T StructReader::getDataField(ElementCount offset, Mask<T> mask) const {
// -------------------------------------------------------------------
inline
ElementCount
ListBuilder
::
size
()
{
return
elementCount
;
}
inline
ElementCount
ListBuilder
::
size
()
const
{
return
elementCount
;
}
template
<
typename
T
>
inline
T
ListBuilder
::
getDataElement
(
ElementCount
index
)
const
{
...
...
@@ -814,7 +814,7 @@ inline void ListBuilder::setDataElement<Void>(ElementCount index, Void value) co
// -------------------------------------------------------------------
inline
ElementCount
ListReader
::
size
()
{
return
elementCount
;
}
inline
ElementCount
ListReader
::
size
()
const
{
return
elementCount
;
}
template
<
typename
T
>
inline
T
ListReader
::
getDataElement
(
ElementCount
index
)
const
{
...
...
c++/src/capnproto/list.h
View file @
1a515be7
This diff is collapsed.
Click to expand it.
compiler/src/CxxGenerator.hs
View file @
1a515be7
...
...
@@ -287,6 +287,9 @@ fieldContext parent desc = mkStrContext context where
context
"fieldTitleCase"
=
MuVariable
$
toTitleCase
$
fieldName
desc
context
"fieldUpperCase"
=
MuVariable
$
toUpperCaseWithUnderscores
$
fieldName
desc
context
"fieldIsPrimitive"
=
MuBool
$
isPrimitive
$
fieldType
desc
context
"fieldIsListOrBlob"
=
MuBool
$
isBlob
(
fieldType
desc
)
||
isList
(
fieldType
desc
)
context
"fieldIsBlob"
=
MuBool
$
isBlob
$
fieldType
desc
context
"fieldIsInlineBlob"
=
MuBool
$
isInlineBlob
$
fieldType
desc
context
"fieldIsStruct"
=
MuBool
$
isStruct
$
fieldType
desc
...
...
@@ -332,6 +335,11 @@ fieldContext parent desc = mkStrContext context where
MuVariable
$
cxxFieldSizeString
$
fieldSize
$
inlineElementType
$
fieldType
desc
context
"fieldElementType"
=
MuVariable
$
cxxTypeString
$
elementType
$
fieldType
desc
context
"fieldElementReaderType"
=
MuVariable
readerString
where
readerString
=
if
isPrimitiveList
$
fieldType
desc
then
tString
else
tString
++
"::Reader"
tString
=
cxxTypeString
$
elementType
$
fieldType
desc
context
"fieldInlineElementType"
=
MuVariable
$
cxxTypeString
$
inlineElementType
$
fieldType
desc
context
"fieldUnion"
=
case
fieldUnion
desc
of
...
...
compiler/src/c++-header.mustache
View file @
1a515be7
This diff is collapsed.
Click to expand it.
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