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
328c9a83
Commit
328c9a83
authored
May 30, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kj/common.h
parent
ed6b71aa
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
190 additions
and
116 deletions
+190
-116
arena.h
c++/src/capnproto/arena.h
+1
-1
blob.h
c++/src/capnproto/blob.h
+1
-1
common.h
c++/src/capnproto/common.h
+1
-0
capnpc-capnp.c++
c++/src/capnproto/compiler/capnpc-capnp.c++
+16
-16
dynamic.c++
c++/src/capnproto/dynamic.c++
+4
-4
layout.h
c++/src/capnproto/layout.h
+1
-1
list.h
c++/src/capnproto/list.h
+1
-1
message.h
c++/src/capnproto/message.h
+2
-2
serialize-packed.c++
c++/src/capnproto/serialize-packed.c++
+1
-1
serialize.c++
c++/src/capnproto/serialize.c++
+1
-1
serialize.h
c++/src/capnproto/serialize.h
+1
-1
common.c++
c++/src/kj/common.c++
+1
-2
common.h
c++/src/kj/common.h
+135
-21
exception.c++
c++/src/kj/exception.c++
+2
-2
exception.h
c++/src/kj/exception.h
+1
-1
io.h
c++/src/kj/io.h
+3
-3
logging.c++
c++/src/kj/logging.c++
+2
-2
type-safety.h
c++/src/kj/type-safety.h
+13
-53
c++-header.mustache
compiler/src/c++-header.mustache
+3
-3
No files found.
c++/src/capnproto/arena.h
View file @
328c9a83
...
...
@@ -31,7 +31,7 @@
#include <vector>
#include <memory>
#include <unordered_map>
#include <kj/
macros
.h>
#include <kj/
common
.h>
#include "common.h"
#include "message.h"
...
...
c++/src/capnproto/blob.h
View file @
328c9a83
...
...
@@ -24,7 +24,7 @@
#ifndef CAPNPROTO_BLOB_H_
#define CAPNPROTO_BLOB_H_
#include <kj/
macros
.h>
#include <kj/
common
.h>
#include "common.h"
#include <string.h>
...
...
c++/src/capnproto/common.h
View file @
328c9a83
...
...
@@ -29,6 +29,7 @@
#define CAPNPROTO_COMMON_H_
#include <kj/type-safety.h>
#include <inttypes.h>
namespace
capnproto
{
...
...
c++/src/capnproto/compiler/capnpc-capnp.c++
View file @
328c9a83
...
...
@@ -71,7 +71,7 @@ private:
return
kj
::
STR
*
t
;
}
TextBlob
&&
toContainer
(
TextBlob
&&
t
)
{
return
kj
::
m
ove
(
t
);
return
kj
::
m
v
(
t
);
}
TextBlob
&
toContainer
(
TextBlob
&
t
)
{
return
t
;
...
...
@@ -91,14 +91,14 @@ struct TextBlob::Branch {
template
<
typename
...
Params
>
TextBlob
::
TextBlob
(
Params
&&
...
params
)
{
init
(
toContainer
(
kj
::
f
orwar
d
<
Params
>
(
params
))...);
init
(
toContainer
(
kj
::
f
w
d
<
Params
>
(
params
))...);
}
TextBlob
::
TextBlob
(
kj
::
Array
<
TextBlob
>&&
params
)
{
branches
=
kj
::
newArray
<
Branch
>
(
params
.
size
());
for
(
size_t
i
=
0
;
i
<
params
.
size
();
i
++
)
{
branches
[
i
].
pos
=
nullptr
;
branches
[
i
].
content
=
kj
::
m
ove
(
params
[
i
]);
branches
[
i
].
content
=
kj
::
m
v
(
params
[
i
]);
}
}
...
...
@@ -119,13 +119,13 @@ void TextBlob::allocate(size_t textSize, size_t branchCount) {
template
<
typename
First
,
typename
...
Rest
>
void
TextBlob
::
allocate
(
size_t
textSize
,
size_t
branchCount
,
const
First
&
first
,
Rest
&&
...
rest
)
{
allocate
(
textSize
+
first
.
size
(),
branchCount
,
kj
::
f
orwar
d
<
Rest
>
(
rest
)...);
allocate
(
textSize
+
first
.
size
(),
branchCount
,
kj
::
f
w
d
<
Rest
>
(
rest
)...);
}
template
<
typename
...
Rest
>
void
TextBlob
::
allocate
(
size_t
textSize
,
size_t
branchCount
,
const
TextBlob
&
first
,
Rest
&&
...
rest
)
{
allocate
(
textSize
,
branchCount
+
1
,
kj
::
f
orwar
d
<
Rest
>
(
rest
)...);
allocate
(
textSize
,
branchCount
+
1
,
kj
::
f
w
d
<
Rest
>
(
rest
)...);
}
void
TextBlob
::
fill
(
char
*
textPos
,
Branch
*
branchesPos
)
{
...
...
@@ -135,27 +135,27 @@ void TextBlob::fill(char* textPos, Branch* branchesPos) {
template
<
typename
First
,
typename
...
Rest
>
void
TextBlob
::
fill
(
char
*
textPos
,
Branch
*
branchesPos
,
First
&&
first
,
Rest
&&
...
rest
)
{
textPos
=
kj
::
fill
(
textPos
,
kj
::
f
orwar
d
<
First
>
(
first
));
fill
(
textPos
,
branchesPos
,
kj
::
f
orwar
d
<
Rest
>
(
rest
)...);
textPos
=
kj
::
fill
(
textPos
,
kj
::
f
w
d
<
First
>
(
first
));
fill
(
textPos
,
branchesPos
,
kj
::
f
w
d
<
Rest
>
(
rest
)...);
}
template
<
typename
...
Rest
>
void
TextBlob
::
fill
(
char
*
textPos
,
Branch
*
branchesPos
,
TextBlob
&&
first
,
Rest
&&
...
rest
)
{
branchesPos
->
pos
=
textPos
;
branchesPos
->
content
=
kj
::
m
ove
(
first
);
branchesPos
->
content
=
kj
::
m
v
(
first
);
++
branchesPos
;
fill
(
textPos
,
branchesPos
,
kj
::
f
orwar
d
<
Rest
>
(
rest
)...);
fill
(
textPos
,
branchesPos
,
kj
::
f
w
d
<
Rest
>
(
rest
)...);
}
template
<
typename
...
Params
>
void
TextBlob
::
init
(
Params
&&
...
params
)
{
allocate
(
0
,
0
,
params
...);
fill
(
text
.
begin
(),
branches
.
begin
(),
kj
::
f
orwar
d
<
Params
>
(
params
)...);
fill
(
text
.
begin
(),
branches
.
begin
(),
kj
::
f
w
d
<
Params
>
(
params
)...);
}
template
<
typename
...
Params
>
TextBlob
text
(
Params
&&
...
params
)
{
return
TextBlob
(
kj
::
f
orwar
d
<
Params
>
(
params
)...);
return
TextBlob
(
kj
::
f
w
d
<
Params
>
(
params
)...);
}
template
<
typename
List
,
typename
Func
>
...
...
@@ -164,13 +164,13 @@ TextBlob forText(List&& list, Func&& func) {
for
(
size_t
i
=
0
;
i
<
list
.
size
();
i
++
)
{
items
[
i
]
=
func
(
list
[
i
]);
}
return
TextBlob
(
kj
::
m
ove
(
items
));
return
TextBlob
(
kj
::
m
v
(
items
));
}
template
<
typename
T
>
struct
ForTextHack
{
T
list
;
ForTextHack
(
T
list
)
:
list
(
kj
::
f
orwar
d
<
T
>
(
list
))
{}
ForTextHack
(
T
list
)
:
list
(
kj
::
f
w
d
<
T
>
(
list
))
{}
template
<
typename
Func
>
TextBlob
operator
*
(
Func
&&
func
)
{
return
forText
(
list
,
func
);
...
...
@@ -259,14 +259,14 @@ TextBlob nodeName(Schema target, Schema scope) {
auto
part
=
targetParents
.
back
();
auto
proto
=
part
.
getProto
();
if
(
proto
.
getScopeId
()
==
0
)
{
path
=
text
(
kj
::
m
ove
(
path
),
"import
\"
"
,
proto
.
getDisplayName
(),
"
\"
."
);
path
=
text
(
kj
::
m
v
(
path
),
"import
\"
"
,
proto
.
getDisplayName
(),
"
\"
."
);
}
else
{
path
=
text
(
kj
::
m
ove
(
path
),
getUnqualifiedName
(
part
),
"."
);
path
=
text
(
kj
::
m
v
(
path
),
getUnqualifiedName
(
part
),
"."
);
}
targetParents
.
pop_back
();
}
return
text
(
kj
::
m
ove
(
path
),
getUnqualifiedName
(
target
));
return
text
(
kj
::
m
v
(
path
),
getUnqualifiedName
(
target
));
}
TextBlob
genType
(
schema
::
Type
::
Reader
type
,
Schema
scope
)
{
...
...
c++/src/capnproto/dynamic.c++
View file @
328c9a83
...
...
@@ -1396,13 +1396,13 @@ typeName DynamicValue::Builder::AsImpl<typeName>::apply(Builder builder) { \
HANDLE_NUMERIC_TYPE
(
int8_t
,
checkRoundTrip
,
unsignedToSigned
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
int16_t
,
checkRoundTrip
,
unsignedToSigned
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
int32_t
,
checkRoundTrip
,
unsignedToSigned
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
int64_t
,
kj
::
implicit_
cast
,
unsignedToSigned
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
int64_t
,
kj
::
up
cast
,
unsignedToSigned
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
uint8_t
,
signedToUnsigned
,
checkRoundTrip
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
uint16_t
,
signedToUnsigned
,
checkRoundTrip
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
uint32_t
,
signedToUnsigned
,
checkRoundTrip
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
uint64_t
,
signedToUnsigned
,
kj
::
implicit_
cast
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
float
,
kj
::
implicit_cast
,
kj
::
implicit_cast
,
kj
::
implicit_
cast
)
HANDLE_NUMERIC_TYPE
(
double
,
kj
::
implicit_cast
,
kj
::
implicit_cast
,
kj
::
implicit_
cast
)
HANDLE_NUMERIC_TYPE
(
uint64_t
,
signedToUnsigned
,
kj
::
up
cast
,
checkRoundTrip
)
HANDLE_NUMERIC_TYPE
(
float
,
kj
::
upcast
,
kj
::
upcast
,
kj
::
up
cast
)
HANDLE_NUMERIC_TYPE
(
double
,
kj
::
upcast
,
kj
::
upcast
,
kj
::
up
cast
)
#undef HANDLE_NUMERIC_TYPE
...
...
c++/src/capnproto/layout.h
View file @
328c9a83
...
...
@@ -31,7 +31,7 @@
#ifndef CAPNPROTO_LAYOUT_H_
#define CAPNPROTO_LAYOUT_H_
#include <kj/
macros
.h>
#include <kj/
common
.h>
#include "common.h"
#include "blob.h"
...
...
c++/src/capnproto/list.h
View file @
328c9a83
...
...
@@ -120,7 +120,7 @@ class TemporaryPointer {
// able to return a real pointer to its member.
public
:
TemporaryPointer
(
T
&&
value
)
:
value
(
kj
::
m
ove
(
value
))
{}
TemporaryPointer
(
T
&&
value
)
:
value
(
kj
::
m
v
(
value
))
{}
TemporaryPointer
(
const
T
&
value
)
:
value
(
value
)
{}
inline
T
*
operator
->
()
{
return
&
value
;
}
...
...
c++/src/capnproto/message.h
View file @
328c9a83
...
...
@@ -23,7 +23,7 @@
#include <cstddef>
#include <memory>
#include <kj/
macros
.h>
#include <kj/
common
.h>
#include "common.h"
#include "layout.h"
...
...
@@ -359,7 +359,7 @@ typename RootType::Reader readMessageUnchecked(const word* data) {
template
<
typename
Reader
>
void
copyToUnchecked
(
Reader
&&
reader
,
kj
::
ArrayPtr
<
word
>
uncheckedBuffer
)
{
FlatMessageBuilder
builder
(
uncheckedBuffer
);
builder
.
setRoot
(
kj
::
f
orwar
d
<
Reader
>
(
reader
));
builder
.
setRoot
(
kj
::
f
w
d
<
Reader
>
(
reader
));
builder
.
requireFilled
();
}
...
...
c++/src/capnproto/serialize-packed.c++
View file @
328c9a83
...
...
@@ -452,7 +452,7 @@ PackedFdMessageReader::PackedFdMessageReader(
PackedFdMessageReader
::
PackedFdMessageReader
(
kj
::
AutoCloseFd
fd
,
ReaderOptions
options
,
kj
::
ArrayPtr
<
word
>
scratchSpace
)
:
FdInputStream
(
kj
::
m
ove
(
fd
)),
:
FdInputStream
(
kj
::
m
v
(
fd
)),
BufferedInputStreamWrapper
(
static_cast
<
FdInputStream
&>
(
*
this
)),
PackedMessageReader
(
static_cast
<
BufferedInputStreamWrapper
&>
(
*
this
),
options
,
scratchSpace
)
{}
...
...
c++/src/capnproto/serialize.c++
View file @
328c9a83
...
...
@@ -124,7 +124,7 @@ kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>>
DCHECK
(
dst
==
result
.
end
(),
"Buffer overrun/underrun bug in code above."
);
return
move
(
result
);
return
kj
::
mv
(
result
);
}
// =======================================================================================
...
...
c++/src/capnproto/serialize.h
View file @
328c9a83
...
...
@@ -115,7 +115,7 @@ public:
StreamFdMessageReader
(
kj
::
AutoCloseFd
fd
,
ReaderOptions
options
=
ReaderOptions
(),
kj
::
ArrayPtr
<
word
>
scratchSpace
=
nullptr
)
:
FdInputStream
(
kj
::
m
ove
(
fd
)),
InputStreamMessageReader
(
*
this
,
options
,
scratchSpace
)
{}
:
FdInputStream
(
kj
::
m
v
(
fd
)),
InputStreamMessageReader
(
*
this
,
options
,
scratchSpace
)
{}
// Read a message from a file descriptor, taking ownership of the descriptor.
~
StreamFdMessageReader
();
...
...
c++/src/kj/
macros
.c++
→
c++/src/kj/
common
.c++
View file @
328c9a83
...
...
@@ -21,8 +21,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define KJ_PRIVATE
#include "macros.h"
#include "common.h"
#include "logging.h"
#include <stdlib.h>
...
...
c++/src/kj/
macros
.h
→
c++/src/kj/
common
.h
View file @
328c9a83
...
...
@@ -21,33 +21,47 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef KJ_MACROS_H_
#define KJ_MACROS_H_
// Header that should be #included by everyone.
//
// This defines very simple utilities that are widely applicable.
#include <inttypes.h>
#ifndef KJ_COMMON_H_
#define KJ_COMMON_H_
#ifdef __GNUC__
#ifndef __GXX_EXPERIMENTAL_CXX0X__
#warning "Did you forget to enable C++11? Make sure to pass -std=gnu++11 to GCC."
#if __cplusplus < 201103L
#error "This code requires C++11. Either your compiler does not support it or it is not enabled."
#ifdef __GNUC__
// Compiler claims compatibility with GCC, so presumably supports -std.
#error "Pass -std=c++11 on the compiler command line to enable C++11."
#endif
#endif
#if __clang__
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)
#warning "This library requires at least Clang 3.2."
#endif
#elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
#warning "This library requires at least GCC 4.7."
#endif
#ifdef __GNUC__
#if __clang__
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)
#warning "This library requires at least Clang 3.2."
#endif
#else
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
#warning "This library requires at least GCC 4.7."
#endif
#endif
#endif
// =======================================================================================
namespace
kj
{
typedef
unsigned
int
uint
;
typedef
unsigned
char
byte
;
// =======================================================================================
// Common macros, especially for common yet compiler-specific features.
#define KJ_DISALLOW_COPY(classname) \
classname(const classname&) = delete; \
classname& operator=(const classname&) = delete
namespace
internal
{
#define KJ_OFFSETOF(type, member) __builtin_offsetof(type, member)
#define KJ_EXPECT_TRUE(condition) __builtin_expect(condition, true)
...
...
@@ -69,14 +83,20 @@ namespace internal {
#if __clang__
#define KJ_UNUSED_FOR_CLANG __attribute__((unused));
// Clang reports "unused" warnings in some places where GCC does not even allow the "unused"
// attribute.
#else
#define KJ_UNUSED_FOR_CLANG
#endif
namespace
internal
{
void
inlinePreconditionFailure
(
const
char
*
file
,
int
line
,
const
char
*
expectation
,
const
char
*
macroArgs
,
const
char
*
message
=
nullptr
)
KJ_NORETURN
;
}
// namespace internal
#define KJ_INLINE_PRECOND(condition, ...) \
if (KJ_EXPECT_TRUE(condition)); else ::kj::internal::inlinePreconditionFailure( \
__FILE__, __LINE__, #condition, #__VA_ARGS__, ##__VA_ARGS__)
...
...
@@ -91,8 +111,12 @@ void inlinePreconditionFailure(
#define KJ_INLINE_DPRECOND KJ_INLINE_PRECOND
#endif
// #define KJ_STACK_ARRAY(type, name, size, minStack, maxStack)
//
// Allocate an array, preferably on the stack, unless it is too big. On GCC this will use
// variable-sized arrays. For other compilers we could just use a fixed-size array.
// variable-sized arrays. For other compilers we could just use a fixed-size array. `minStack`
// is the stack array size to use if variable-width arrays are not supported. `maxStack` is the
// maximum stack array size if variable-width arrays *are* supported.
#if __clang__
#define KJ_STACK_ARRAY(type, name, size, minStack, maxStack) \
size_t name##_size = (size); \
...
...
@@ -113,13 +137,103 @@ void inlinePreconditionFailure(
kj::arrayPtr(name##_stack, name##_size) : name##_heap
#endif
}
// namespace internal
// =======================================================================================
// Template metaprogramming helpers.
template
<
typename
T
>
struct
NoInfer_
{
// Use NoInfer<T>::Type in place of T for a template function parameter to prevent inference of
// the type based on the parameter value. There's something in the standard library for this but
// I didn't want to #include type_traits or whatever.
typedef
T
Type
;
};
template
<
typename
T
>
using
NoInfer
=
typename
NoInfer_
<
T
>::
Type
;
template
<
typename
T
>
struct
RemoveReference_
{
typedef
T
Type
;
};
template
<
typename
T
>
struct
RemoveReference_
<
T
&>
{
typedef
T
Type
;
};
template
<
typename
T
>
using
RemoveReference
=
typename
RemoveReference_
<
T
>::
Type
;
template
<
typename
>
struct
IsLvalueReference_
{
static
constexpr
bool
value
=
false
;
};
template
<
typename
T
>
struct
IsLvalueReference_
<
T
&>
{
static
constexpr
bool
value
=
true
;
};
template
<
typename
T
>
inline
constexpr
bool
isLvalueReference
()
{
return
IsLvalueReference_
<
T
>::
value
;
}
template
<
typename
T
>
T
instance
()
noexcept
;
// Like std::declval, but doesn't transform T into an rvalue reference. If you want that, specify
// instance<T&&>().
// =======================================================================================
// Equivalents to std::move() and std::forward(), since these are very commonly needed and the
// std header <utility> pulls in lots of other stuff.
//
// We use abbreviated names mv and fwd because these helpers (especially mv) are so commonly used
// that the cost of typing more letters outweighs the cost of being slightly harder to understand
// when first encountered.
template
<
typename
T
>
constexpr
T
&&
mv
(
T
&
t
)
noexcept
{
return
static_cast
<
T
&&>
(
t
);
}
template
<
typename
T
>
constexpr
T
&&
fwd
(
RemoveReference
<
T
>&
t
)
noexcept
{
return
static_cast
<
T
&&>
(
t
);
}
template
<
typename
T
>
constexpr
T
&&
fwd
(
RemoveReference
<
T
>&&
t
)
noexcept
{
static_assert
(
!
isLvalueReference
<
T
>
(),
"Attempting to forward rvalue as lvalue reference."
);
return
static_cast
<
T
&&>
(
t
);
}
// =======================================================================================
// Upcast/downcast
template
<
typename
To
,
typename
From
>
To
upcast
(
From
&&
from
)
{
// `upcast<T>(value)` casts `value` to type `T` only if the conversion is implicit. Useful for
// e.g. resolving ambiguous overloads without sacrificing type-safety.
return
kj
::
fwd
<
From
>
(
from
);
}
template
<
typename
To
,
typename
From
>
To
dynamicDowncastIfAvailable
(
From
*
from
)
{
// If RTTI is disabled, always returns nullptr. Otherwise, works like dynamic_cast. Useful
// in situations where dynamic_cast could allow an optimization, but isn't strictly necessary
// for correctness. It is highly recommended that you try to arrange all your dynamic_casts
// this way, as a dynamic_cast that is necessary for correctness implies a flaw in the interface
// design.
#if KJ_NO_RTTI
return
nullptr
;
#else
return
dynamic_cast
<
To
>
(
from
);
#endif
}
template
<
typename
To
,
typename
From
>
To
downcast
(
From
*
from
)
{
// Down-cast a value to a sub-type, asserting that the cast is valid. In opt mode this is a
// static_cast, but in debug mode (when RTTI is enabled) a dynamic_cast will be used to verify
// that the value really has the requested type.
// Force a compile error if To is not a subtype of From.
if
(
false
)
{
kj
::
upcast
<
From
*>
(
To
());
}
#if !KJ_NO_RTTI
KJ_INLINE_DPRECOND
(
from
==
nullptr
||
dynamic_cast
<
To
>
(
from
)
!=
nullptr
,
"Value cannot be downcast() to requested type."
);
#endif
return
static_cast
<
To
>
(
from
);
}
template
<
typename
T
,
typename
U
>
T
implicit_cast
(
U
u
)
{
return
u
;
template
<
typename
To
,
typename
From
>
To
downcast
(
From
&&
from
)
{
// Reference version of downcast().
return
*
kj
::
downcast
<
To
*>
(
&
from
);
}
}
// namespace kj
#endif // KJ_
MACROS
_H_
#endif // KJ_
COMMON
_H_
c++/src/kj/exception.c++
View file @
328c9a83
...
...
@@ -58,7 +58,7 @@ ArrayPtr<const char> operator*(const Stringifier&, Exception::Durability durabil
Exception
::
Exception
(
Nature
nature
,
Durability
durability
,
const
char
*
file
,
int
line
,
Array
<
char
>
description
)
noexcept
:
file
(
file
),
line
(
line
),
nature
(
nature
),
durability
(
durability
),
description
(
m
ove
(
description
))
{
description
(
m
v
(
description
))
{
traceCount
=
backtrace
(
trace
,
16
);
}
...
...
@@ -82,7 +82,7 @@ Exception::Context::Context(const Context& other) noexcept
}
void
Exception
::
wrapContext
(
const
char
*
file
,
int
line
,
Array
<
char
>&&
description
)
{
context
=
heap
<
Context
>
(
file
,
line
,
m
ove
(
description
),
move
(
context
));
context
=
heap
<
Context
>
(
file
,
line
,
m
v
(
description
),
mv
(
context
));
}
const
char
*
Exception
::
what
()
const
noexcept
{
...
...
c++/src/kj/exception.h
View file @
328c9a83
...
...
@@ -83,7 +83,7 @@ public:
Maybe
<
Own
<
Context
>>
next
;
Context
(
const
char
*
file
,
int
line
,
Array
<
char
>&&
description
,
Maybe
<
Own
<
Context
>>&&
next
)
:
file
(
file
),
line
(
line
),
description
(
m
ove
(
description
)),
next
(
move
(
next
))
{}
:
file
(
file
),
line
(
line
),
description
(
m
v
(
description
)),
next
(
mv
(
next
))
{}
Context
(
const
Context
&
other
)
noexcept
;
};
...
...
c++/src/kj/io.h
View file @
328c9a83
...
...
@@ -25,7 +25,7 @@
#define KJ_IO_H_
#include <cstddef>
#include "
macros
.h"
#include "
common
.h"
#include "type-safety.h"
namespace
kj
{
...
...
@@ -243,7 +243,7 @@ class FdInputStream: public InputStream {
public
:
explicit
FdInputStream
(
int
fd
)
:
fd
(
fd
)
{};
explicit
FdInputStream
(
AutoCloseFd
fd
)
:
fd
(
fd
),
autoclose
(
m
ove
(
fd
))
{}
explicit
FdInputStream
(
AutoCloseFd
fd
)
:
fd
(
fd
),
autoclose
(
m
v
(
fd
))
{}
KJ_DISALLOW_COPY
(
FdInputStream
);
~
FdInputStream
();
...
...
@@ -259,7 +259,7 @@ class FdOutputStream: public OutputStream {
public
:
explicit
FdOutputStream
(
int
fd
)
:
fd
(
fd
)
{};
explicit
FdOutputStream
(
AutoCloseFd
fd
)
:
fd
(
fd
),
autoclose
(
m
ove
(
fd
))
{}
explicit
FdOutputStream
(
AutoCloseFd
fd
)
:
fd
(
fd
),
autoclose
(
m
v
(
fd
))
{}
KJ_DISALLOW_COPY
(
FdOutputStream
);
~
FdOutputStream
();
...
...
c++/src/kj/logging.c++
View file @
328c9a83
...
...
@@ -245,11 +245,11 @@ Log::Context::~Context() {}
void
Log
::
Context
::
onRecoverableException
(
Exception
&&
exception
)
{
addTo
(
exception
);
next
.
onRecoverableException
(
kj
::
m
ove
(
exception
));
next
.
onRecoverableException
(
kj
::
m
v
(
exception
));
}
void
Log
::
Context
::
onFatalException
(
Exception
&&
exception
)
{
addTo
(
exception
);
next
.
onFatalException
(
kj
::
m
ove
(
exception
));
next
.
onFatalException
(
kj
::
m
v
(
exception
));
}
void
Log
::
Context
::
logMessage
(
ArrayPtr
<
const
char
>
text
)
{
// TODO(someday): We could do something like log the context and then indent all log messages
...
...
c++/src/kj/type-safety.h
View file @
328c9a83
...
...
@@ -28,52 +28,12 @@
#ifndef KJ_TYPE_SAFETY_H_
#define KJ_TYPE_SAFETY_H_
#include "
macros
.h"
#include "
common
.h"
#include <cstddef>
#include <string.h>
namespace
kj
{
typedef
unsigned
int
uint
;
typedef
unsigned
char
byte
;
template
<
typename
T
>
struct
NoInfer_
{
// Use NoInfer<T>::Type in place of T for a template function parameter to prevent inference of
// the type based on the parameter value. There's something in the standard library for this but
// I didn't want to #include type_traits or whatever.
typedef
T
Type
;
};
template
<
typename
T
>
using
NoInfer
=
typename
NoInfer_
<
T
>::
Type
;
template
<
typename
T
>
struct
RemoveReference_
{
typedef
T
Type
;
};
template
<
typename
T
>
struct
RemoveReference_
<
T
&>
{
typedef
T
Type
;
};
template
<
typename
>
struct
IsLvalueReference
{
static
constexpr
bool
value
=
false
;
};
template
<
typename
T
>
struct
IsLvalueReference
<
T
&>
{
static
constexpr
bool
value
=
true
;
};
template
<
typename
T
>
using
RemoveReference
=
typename
RemoveReference_
<
T
>::
Type
;
// #including <utility> just for std::move() and std::forward() is excessive. Instead, we
// re-define them here.
template
<
typename
T
>
constexpr
T
&&
move
(
T
&
t
)
noexcept
{
return
static_cast
<
T
&&>
(
t
);
}
template
<
typename
T
>
constexpr
T
&&
forward
(
RemoveReference
<
T
>&
t
)
noexcept
{
return
static_cast
<
T
&&>
(
t
);
}
template
<
typename
T
>
constexpr
T
&&
forward
(
RemoveReference
<
T
>&&
t
)
noexcept
{
static_assert
(
!
IsLvalueReference
<
T
>::
value
,
"Attempting to forward rvalue as lvalue reference."
);
return
static_cast
<
T
&&>
(
t
);
}
template
<
typename
T
>
T
instance
()
noexcept
;
// Like std::declval, but doesn't transform T into an rvalue reference. If you want that, specify
// instance<T&&>().
// #including <new> pulls in a lot of crap, but we want placement news. But operator new cannot
// be defined in a namespace, and defining it globally conflicts with the standard library
// definition. So...
...
...
@@ -91,7 +51,7 @@ namespace kj {
template
<
typename
T
,
typename
...
Params
>
void
constructAt
(
T
*
location
,
Params
&&
...
params
)
{
new
(
internal
::
PlacementNew
(),
location
)
T
(
kj
::
f
orwar
d
<
Params
>
(
params
)...);
new
(
internal
::
PlacementNew
(),
location
)
T
(
kj
::
f
w
d
<
Params
>
(
params
)...);
}
// =======================================================================================
...
...
@@ -103,16 +63,16 @@ public:
Maybe
()
:
isSet
(
false
)
{}
Maybe
(
T
&&
t
)
:
isSet
(
true
)
{
constructAt
(
&
value
,
kj
::
m
ove
(
t
));
constructAt
(
&
value
,
kj
::
m
v
(
t
));
}
Maybe
(
const
T
&
t
)
:
isSet
(
true
)
{
constructAt
(
&
value
,
t
);
}
Maybe
(
Maybe
&&
other
)
noexcept
(
noexcept
(
T
(
kj
::
m
ove
(
other
.
value
))))
Maybe
(
Maybe
&&
other
)
noexcept
(
noexcept
(
T
(
kj
::
m
v
(
other
.
value
))))
:
isSet
(
other
.
isSet
)
{
if
(
isSet
)
{
constructAt
(
&
value
,
kj
::
m
ove
(
other
.
value
));
constructAt
(
&
value
,
kj
::
m
v
(
other
.
value
));
}
}
Maybe
(
const
Maybe
&
other
)
...
...
@@ -122,10 +82,10 @@ public:
}
}
template
<
typename
U
>
Maybe
(
Maybe
<
U
>&&
other
)
noexcept
(
noexcept
(
T
(
kj
::
m
ove
(
other
.
value
))))
Maybe
(
Maybe
<
U
>&&
other
)
noexcept
(
noexcept
(
T
(
kj
::
m
v
(
other
.
value
))))
:
isSet
(
other
.
isSet
)
{
if
(
isSet
)
{
constructAt
(
&
value
,
kj
::
m
ove
(
other
.
value
));
constructAt
(
&
value
,
kj
::
m
v
(
other
.
value
));
}
}
template
<
typename
U
>
...
...
@@ -156,7 +116,7 @@ public:
value
.
~
T
();
}
isSet
=
true
;
constructAt
(
&
value
,
kj
::
f
orwar
d
(
params
)...);
constructAt
(
&
value
,
kj
::
f
w
d
(
params
)...);
}
inline
T
&
operator
*
()
{
return
value
;
}
...
...
@@ -171,7 +131,7 @@ public:
}
isSet
=
other
.
isSet
;
if
(
isSet
)
{
constructAt
(
&
value
,
kj
::
m
ove
(
other
.
value
));
constructAt
(
&
value
,
kj
::
m
v
(
other
.
value
));
}
}
return
*
this
;
...
...
@@ -232,7 +192,7 @@ public:
// Like map() but allows the function to take an rvalue reference to the value.
if
(
isSet
)
{
return
func
(
kj
::
m
ove
(
value
));
return
func
(
kj
::
m
v
(
value
));
}
else
{
return
nullptr
;
}
...
...
@@ -371,7 +331,7 @@ template <typename T>
class
HeapValue
final
:
public
Disposer
{
public
:
template
<
typename
...
Params
>
inline
HeapValue
(
Params
&&
...
params
)
:
value
(
kj
::
f
orwar
d
<
Params
>
(
params
)...)
{}
inline
HeapValue
(
Params
&&
...
params
)
:
value
(
kj
::
f
w
d
<
Params
>
(
params
)...)
{}
virtual
void
dispose
(
void
*
)
override
{
delete
this
;
}
...
...
@@ -386,7 +346,7 @@ Own<T> heap(Params&&... params) {
// exact heap implementation is unspecified -- for now it is operator new, but you should not
// assume anything.
auto
result
=
new
internal
::
HeapValue
<
T
>
(
kj
::
f
orwar
d
<
Params
>
(
params
)...);
auto
result
=
new
internal
::
HeapValue
<
T
>
(
kj
::
f
w
d
<
Params
>
(
params
)...);
return
Own
<
T
>
(
&
result
->
value
,
result
);
}
...
...
@@ -562,7 +522,7 @@ public:
template
<
typename
...
Params
>
void
add
(
Params
&&
...
params
)
{
KJ_INLINE_DPRECOND
(
pos
<
endPtr
,
"Added too many elements to ArrayBuilder."
);
new
(
&
pos
->
value
)
T
(
forwar
d
<
Params
>
(
params
)...);
new
(
&
pos
->
value
)
T
(
kj
::
fw
d
<
Params
>
(
params
)...);
++
pos
;
}
...
...
compiler/src/c++-header.mustache
View file @
328c9a83
...
...
@@ -415,7 +415,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::getDynamic(
_reader,
{{
fieldOffset
}}
* ::capnproto::POINTERS, ::kj::f
orwar
d
<Param>
(param));
_reader,
{{
fieldOffset
}}
* ::capnproto::POINTERS, ::kj::f
w
d
<Param>
(param));
}
template
<typename
T
,
typename
Param
>
...
...
@@ -425,7 +425,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Para
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::getDynamic(
_builder,
{{
fieldOffset
}}
* ::capnproto::POINTERS, ::kj::f
orwar
d
<Param>
(param));
_builder,
{{
fieldOffset
}}
* ::capnproto::POINTERS, ::kj::f
w
d
<Param>
(param));
}
template
<typename
T
>
...
...
@@ -455,7 +455,7 @@ inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(Par
{{
unionTagOffset
}}
* ::capnproto::ELEMENTS,
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
);
{{/
fieldUnion
}}
return ::capnproto::internal::PointerHelpers
<T>
::init(
_builder,
{{
fieldOffset
}}
* ::capnproto::POINTERS, ::kj::f
orwar
d
<Params>
(params)...);
_builder,
{{
fieldOffset
}}
* ::capnproto::POINTERS, ::kj::f
w
d
<Params>
(params)...);
}
{{/
fieldIsGenericObject
}}
...
...
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