Commit abf4ed59 authored by Kenton Varda's avatar Kenton Varda

Support Clang compiler.

parent eeae230c
......@@ -17,6 +17,12 @@ continuous-opt:
continuous-opt3:
CXX=g++-4.7 CXXFLAGS='-std=gnu++0x -O3 -DNDEBUG -Wall' LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
continuous-clang:
CXX=clang++ CXXFLAGS='-fno-caret-diagnostics -std=c++1y -g -Wall' LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
continuous-clang-opt:
CXX=clang++ CXXFLAGS='-fno-caret-diagnostics -std=c++11 -O2 -DNDEBUG -Wall' LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
clean:
rm -rf bin lib tmp
......@@ -579,7 +579,8 @@ TextBlob genNestedDecls(Schema schema, Indent indent) {
TextBlob genFile(Schema file) {
auto proto = file.getProto();
auto body = proto.getBody();
PRECOND(body.which() == schema::Node::Body::FILE_NODE, "Expected a file node.", body.which());
PRECOND(body.which() == schema::Node::Body::FILE_NODE, "Expected a file node.",
(uint)body.which());
return text(
"# ", proto.getDisplayName(), "\n",
......
......@@ -37,18 +37,18 @@ inline T bitCast(U value) {
static_assert(sizeof(T) == sizeof(U), "Size must match.");
return value;
}
template <>
inline float bitCast<float, uint32_t>(uint32_t value) {
float result;
memcpy(&result, &value, sizeof(value));
return result;
}
template <>
inline double bitCast<double, uint64_t>(uint64_t value) {
double result;
memcpy(&result, &value, sizeof(value));
return result;
}
//template <>
//inline float bitCast<float, uint32_t>(uint32_t value) {
// float result;
// memcpy(&result, &value, sizeof(value));
// return result;
//}
//template <>
//inline double bitCast<double, uint64_t>(uint64_t value) {
// double result;
// memcpy(&result, &value, sizeof(value));
// return result;
//}
template <>
inline uint32_t bitCast<uint32_t, float>(float value) {
uint32_t result;
......@@ -454,7 +454,7 @@ DynamicStruct::Builder DynamicStruct::Builder::getObject(
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicStruct::Builder();
}
DynamicList::Builder DynamicStruct::Builder::getObject(
......@@ -473,7 +473,7 @@ DynamicList::Builder DynamicStruct::Builder::getObject(
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicList::Builder();
}
Text::Builder DynamicStruct::Builder::getObjectAsText(StructSchema::Member member) {
......@@ -491,7 +491,7 @@ Text::Builder DynamicStruct::Builder::getObjectAsText(StructSchema::Member membe
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return Text::Builder();
}
Data::Builder DynamicStruct::Builder::getObjectAsData(StructSchema::Member member) {
......@@ -509,7 +509,7 @@ Data::Builder DynamicStruct::Builder::getObjectAsData(StructSchema::Member membe
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return Data::Builder();
}
......@@ -529,7 +529,7 @@ DynamicStruct::Builder DynamicStruct::Builder::initObject(
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicStruct::Builder();
}
DynamicList::Builder DynamicStruct::Builder::initObject(
......@@ -548,7 +548,7 @@ DynamicList::Builder DynamicStruct::Builder::initObject(
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicList::Builder();
}
Text::Builder DynamicStruct::Builder::initObjectAsText(StructSchema::Member member, uint size) {
......@@ -566,7 +566,7 @@ Text::Builder DynamicStruct::Builder::initObjectAsText(StructSchema::Member memb
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return Text::Builder();
}
Data::Builder DynamicStruct::Builder::initObjectAsData(StructSchema::Member member, uint size) {
......@@ -584,7 +584,7 @@ Data::Builder DynamicStruct::Builder::initObjectAsData(StructSchema::Member memb
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return Data::Builder();
}
......@@ -660,7 +660,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
case schema::Type::Body::discrim##_TYPE: \
return DynamicValue::Reader(reader.getDataField<type>( \
field.getOffset() * ELEMENTS, \
bitCast<typename internal::MaskType<type>::Type>(dval.get##titleCase##Value())));
bitCast<internal::Mask<type>>(dval.get##titleCase##Value())));
HANDLE_TYPE(BOOL, Bool, bool)
HANDLE_TYPE(INT8, Int8, int8_t)
......@@ -729,7 +729,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return nullptr;
}
......@@ -752,7 +752,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
case schema::Type::Body::discrim##_TYPE: \
return DynamicValue::Builder(builder.getDataField<type>( \
field.getOffset() * ELEMENTS, \
bitCast<typename internal::MaskType<type>::Type>(dval.get##titleCase##Value())));
bitCast<internal::Mask<type>>(dval.get##titleCase##Value())));
HANDLE_TYPE(BOOL, Bool, bool)
HANDLE_TYPE(INT8, Int8, int8_t)
......@@ -832,7 +832,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
return nullptr;
}
DynamicStruct::Builder DynamicStruct::Builder::getObjectImpl(
......@@ -964,12 +964,12 @@ void DynamicStruct::Builder::setImpl(
return;
}
FAIL_RECOVERABLE_PRECOND("can't set field of unknown type", type.which());
FAIL_RECOVERABLE_PRECOND("can't set field of unknown type", (uint)type.which());
return;
}
}
FAIL_CHECK("switch() missing case.", member.getProto().getBody().which());
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
}
DynamicValue::Builder DynamicStruct::Builder::initImpl(
......@@ -992,7 +992,7 @@ DynamicValue::Builder DynamicStruct::Builder::initImpl(
return initFieldAsDataImpl(builder, member, size);
default:
FAIL_PRECOND(
"init() with size is only valid for list, text, or data fields.", type.which());
"init() with size is only valid for list, text, or data fields.", (uint)type.which());
break;
}
break;
......@@ -1245,7 +1245,7 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
return;
}
FAIL_RECOVERABLE_PRECOND("can't set element of unknown type", schema.whichElementType());
FAIL_RECOVERABLE_PRECOND("can't set element of unknown type", (uint)schema.whichElementType());
}
DynamicValue::Builder DynamicList::Builder::init(uint index, uint size) {
......
......@@ -277,7 +277,7 @@ private:
static DynamicValue::Reader getImpl(internal::StructReader reader, StructSchema::Member member);
template <typename T>
template <typename T, Kind K>
friend struct internal::PointerHelpers;
friend class DynamicUnion::Reader;
friend class DynamicObject;
......@@ -287,7 +287,8 @@ private:
friend class MessageBuilder;
template <typename T, ::capnproto::Kind k>
friend struct ::capnproto::ToDynamic_;
friend String internal::debugString(StructReader reader, const RawSchema& schema);
friend String internal::debugString(
internal::StructReader reader, const internal::RawSchema& schema);
};
class DynamicStruct::Builder {
......@@ -382,7 +383,7 @@ private:
static Data::Builder initFieldAsDataImpl(
internal::StructBuilder builder, StructSchema::Member field, uint size);
template <typename T>
template <typename T, Kind k>
friend struct internal::PointerHelpers;
friend class DynamicUnion::Builder;
friend struct DynamicList;
......@@ -421,7 +422,7 @@ private:
Reader(ListSchema schema, internal::ListReader reader): schema(schema), reader(reader) {}
template <typename T>
template <typename T, Kind k>
friend struct internal::PointerHelpers;
friend struct DynamicStruct;
friend class DynamicObject;
......@@ -463,7 +464,7 @@ private:
Builder(ListSchema schema, internal::ListBuilder builder): schema(schema), builder(builder) {}
template <typename T>
template <typename T, Kind k>
friend struct internal::PointerHelpers;
friend struct DynamicStruct;
template <typename T, ::capnproto::Kind k>
......@@ -855,14 +856,14 @@ struct DynamicValue::Builder::AsImpl<T, Kind::LIST> {
template <typename T>
struct DynamicObject::AsImpl<T, Kind::STRUCT> {
static T apply(DynamicObject value) {
return value.as(Schema::from<T>()).as<T>();
return value.as(Schema::from<T>()).template as<T>();
}
};
template <typename T>
struct DynamicObject::AsImpl<T, Kind::LIST> {
static T apply(DynamicObject value) {
return value.as(Schema::from<T>()).as<T>();
return value.as(Schema::from<T>()).template as<T>();
}
};
......
......@@ -114,7 +114,7 @@ private:
mutable Array<char> whatBuffer;
};
class Stringifier;
struct Stringifier;
ArrayPtr<const char> operator*(const Stringifier&, Exception::Nature nature);
ArrayPtr<const char> operator*(const Stringifier&, Exception::Durability durability);
......
......@@ -36,7 +36,7 @@ class MessageBuilder; // So that it can be declared a friend.
template <typename T, Kind k = kind<T>()>
struct ToDynamic_; // Defined in dynamic.h, needs to be declared as everyone's friend.
class DynamicStruct; // So that it can be declared a friend.
struct DynamicStruct; // So that it can be declared a friend.
namespace internal {
......@@ -195,6 +195,9 @@ inline constexpr uint64_t typeId() { return internal::TypeIdFor<T>::typeId; }
template <> struct RawSchemaFor<type> { \
static inline const RawSchema& getSchema() { return schemas::s_##id; } \
}
#define CAPNPROTO_DEFINE_ENUM(type) \
constexpr Kind KindOf<type>::kind; \
constexpr uint64_t TypeIdFor<type>::typeId;
#define CAPNPROTO_DECLARE_STRUCT(type, id, dataWordSize, pointerCount, preferredElementEncoding) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \
......@@ -205,11 +208,18 @@ inline constexpr uint64_t typeId() { return internal::TypeIdFor<T>::typeId; }
template <> struct RawSchemaFor<type> { \
static inline const RawSchema& getSchema() { return schemas::s_##id; } \
}
#define CAPNPROTO_DEFINE_STRUCT(type) \
constexpr Kind KindOf<type>::kind; \
constexpr StructSize StructSizeFor<type>::value; \
constexpr uint64_t TypeIdFor<type>::typeId;
#define CAPNPROTO_DECLARE_INTERFACE(type, id) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::INTERFACE; }; \
template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchemaFor<type> { \
static inline const RawSchema& getSchema() { return schemas::s_##id; } \
}
#define CAPNPROTO_DEFINE_INTERFACE(type) \
constexpr Kind KindOf<type>::kind; \
constexpr uint64_t TypeIdFor<type>::typeId;
#endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_
......@@ -265,7 +265,7 @@ void FdOutputStream::write(const void* buffer, size_t size) {
}
void FdOutputStream::write(ArrayPtr<const ArrayPtr<const byte>> pieces) {
CAPNPROTO_STACK_ARRAY(struct iovec, iov, pieces.size(), 128);
CAPNPROTO_STACK_ARRAY(struct iovec, iov, pieces.size(), 16, 128);
for (uint i = 0; i < pieces.size(); i++) {
// writev() interface is not const-correct. :(
......
......@@ -42,8 +42,8 @@ class StructBuilder;
class StructReader;
class ListBuilder;
class ListReader;
class ObjectBuilder;
class ObjectReader;
struct ObjectBuilder;
struct ObjectReader;
struct WirePointer;
struct WireHelpers;
class SegmentReader;
......@@ -100,18 +100,16 @@ enum class FieldSize: uint8_t {
typedef decltype(BITS / ELEMENTS) BitsPerElement;
typedef decltype(POINTERS / ELEMENTS) PointersPerElement;
namespace internal {
static constexpr BitsPerElement BITS_PER_ELEMENT_TABLE[8] = {
0 * BITS / ELEMENTS,
1 * BITS / ELEMENTS,
8 * BITS / ELEMENTS,
16 * BITS / ELEMENTS,
32 * BITS / ELEMENTS,
64 * BITS / ELEMENTS,
0 * BITS / ELEMENTS,
0 * BITS / ELEMENTS
};
}
static constexpr BitsPerElement BITS_PER_ELEMENT_TABLE[8] = {
0 * BITS / ELEMENTS,
1 * BITS / ELEMENTS,
8 * BITS / ELEMENTS,
16 * BITS / ELEMENTS,
32 * BITS / ELEMENTS,
64 * BITS / ELEMENTS,
0 * BITS / ELEMENTS,
0 * BITS / ELEMENTS
};
inline constexpr BitsPerElement dataBitsPerElement(FieldSize size) {
return internal::BITS_PER_ELEMENT_TABLE[static_cast<int>(size)];
......
......@@ -266,7 +266,7 @@ private:
}
template <typename U, Kind k>
friend class List;
friend struct List;
template <typename U, Kind K>
friend struct internal::PointerHelpers;
};
......@@ -359,7 +359,7 @@ private:
}
template <typename U, Kind k>
friend class List;
friend struct List;
template <typename U, Kind K>
friend struct internal::PointerHelpers;
};
......@@ -457,7 +457,7 @@ private:
}
template <typename U, Kind k>
friend class List;
friend struct List;
template <typename U, Kind K>
friend struct internal::PointerHelpers;
};
......@@ -546,7 +546,7 @@ private:
}
template <typename U, Kind k>
friend class List;
friend struct List;
template <typename U, Kind K>
friend struct internal::PointerHelpers;
};
......
......@@ -54,7 +54,7 @@ enum DescriptionStyle {
static Array<char> makeDescription(DescriptionStyle style, const char* code, int errorNumber,
const char* macroArgs, ArrayPtr<Array<char>> argValues) {
ArrayPtr<const char> argNames[argValues.size()];
CAPNPROTO_STACK_ARRAY(ArrayPtr<const char>, argNames, argValues.size(), 8, 64);
if (argValues.size() > 0) {
size_t index = 0;
......
......@@ -31,7 +31,11 @@
#warning "Did you forget to enable C++11? Make sure to pass -std=gnu++11 to GCC."
#endif
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
#if __clang__
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)
#warning "Cap'n Proto requires at least Clang 3.2."
#endif
#elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
#warning "Cap'n Proto requires at least GCC 4.7."
#endif
#endif
......@@ -61,6 +65,13 @@ namespace internal {
#endif
#define CAPNPROTO_NORETURN __attribute__((noreturn));
#define CAPNPROTO_UNUSED __attribute__((unused));
#if __clang__
#define CAPNPROTO_UNUSED_FOR_CLANG __attribute__((unused));
#else
#define CAPNPROTO_UNUSED_FOR_CLANG
#endif
void inlinePreconditionFailure(
const char* file, int line, const char* expectation, const char* macroArgs,
......@@ -82,7 +93,17 @@ void inlinePreconditionFailure(
// 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.
#define CAPNPROTO_STACK_ARRAY(type, name, size, maxStack) \
#if __clang__
#define CAPNPROTO_STACK_ARRAY(type, name, size, minStack, maxStack) \
size_t name##_size = (size); \
bool name##_isOnStack = name##_size <= (minStack); \
type name##_stack[minStack]; \
::capnproto::Array<type> name##_heap = name##_isOnStack ? \
nullptr : newArray<type>(name##_size); \
::capnproto::ArrayPtr<type> name = name##_isOnStack ? \
arrayPtr(name##_stack, name##_size) : name##_heap
#else
#define CAPNPROTO_STACK_ARRAY(type, name, size, minStack, maxStack) \
size_t name##_size = (size); \
bool name##_isOnStack = name##_size <= (maxStack); \
type name##_stack[name##_isOnStack ? size : 0]; \
......@@ -90,6 +111,7 @@ void inlinePreconditionFailure(
nullptr : newArray<type>(name##_size); \
::capnproto::ArrayPtr<type> name = name##_isOnStack ? \
arrayPtr(name##_stack, name##_size) : name##_heap
#endif
} // namespace internal
......
......@@ -171,7 +171,7 @@ private:
void setRootInternal(internal::StructReader reader);
internal::StructBuilder getRoot(internal::StructSize size);
friend struct SchemaLoader; // for a dirty hack, see schema-loader.c++.
friend class SchemaLoader; // for a dirty hack, see schema-loader.c++.
};
template <typename RootType>
......@@ -207,7 +207,7 @@ void copyToUnchecked(Reader&& reader, ArrayPtr<word> uncheckedBuffer);
// otherwise an exception will be thrown.
template <typename Type>
typename Type::Reader defaultValue();
static typename Type::Reader defaultValue();
// Get a default instance of the given struct or list type.
//
// TODO(cleanup): Find a better home for this function?
......
......@@ -84,7 +84,7 @@ public:
nodeName = node.getDisplayName();
dependencies.clear();
CONTEXT("validating schema node", nodeName, node.getBody().which());
CONTEXT("validating schema node", nodeName, (uint)node.getBody().which());
switch (node.getBody().which()) {
case schema::Node::Body::FILE_NODE:
......@@ -211,9 +211,9 @@ private:
}
}
CAPNPROTO_STACK_ARRAY(bool, sawCodeOrder, members.size(), 256);
CAPNPROTO_STACK_ARRAY(bool, sawCodeOrder, members.size(), 32, 256);
memset(sawCodeOrder.begin(), 0, sawCodeOrder.size() * sizeof(sawCodeOrder[0]));
CAPNPROTO_STACK_ARRAY(bool, sawOrdinal, ordinalCount, 256);
CAPNPROTO_STACK_ARRAY(bool, sawOrdinal, ordinalCount, 32, 256);
memset(sawOrdinal.begin(), 0, sawOrdinal.size() * sizeof(sawOrdinal[0]));
uint index = 0;
......@@ -265,7 +265,7 @@ private:
"Schema invalid: Union discriminant out-of-bounds.");
auto uMembers = u.getMembers();
CAPNPROTO_STACK_ARRAY(bool, uSawCodeOrder, uMembers.size(), 256);
CAPNPROTO_STACK_ARRAY(bool, uSawCodeOrder, uMembers.size(), 32, 256);
memset(uSawCodeOrder.begin(), 0, uSawCodeOrder.size() * sizeof(uSawCodeOrder[0]));
uint subIndex = 0;
......@@ -285,7 +285,7 @@ private:
void validate(schema::EnumNode::Reader enumNode) {
auto enumerants = enumNode.getEnumerants();
CAPNPROTO_STACK_ARRAY(bool, sawCodeOrder, enumerants.size(), 256);
CAPNPROTO_STACK_ARRAY(bool, sawCodeOrder, enumerants.size(), 32, 256);
memset(sawCodeOrder.begin(), 0, sawCodeOrder.size() * sizeof(sawCodeOrder[0]));
uint index = 0;
......@@ -302,7 +302,7 @@ private:
void validate(schema::InterfaceNode::Reader interfaceNode) {
auto methods = interfaceNode.getMethods();
CAPNPROTO_STACK_ARRAY(bool, sawCodeOrder, methods.size(), 256);
CAPNPROTO_STACK_ARRAY(bool, sawCodeOrder, methods.size(), 32, 256);
memset(sawCodeOrder.begin(), 0, sawCodeOrder.size() * sizeof(sawCodeOrder[0]));
uint index = 0;
......@@ -422,7 +422,7 @@ private:
auto node = readMessageUnchecked<schema::Node>(existing->encodedNode);
VALIDATE_SCHEMA(node.getBody().which() == expectedKind,
"expected a different kind of node for this ID",
id, expectedKind, node.getBody().which(), node.getDisplayName());
id, (uint)expectedKind, (uint)node.getBody().which(), node.getDisplayName());
dependencies.insert(std::make_pair(id, existing));
return;
}
......
......@@ -124,7 +124,8 @@ private:
return StructSchema(&internal::rawSchema<T>());
}
friend class Schema;
friend String internal::debugString(StructReader reader, const RawSchema& schema);
friend String internal::debugString(
internal::StructReader reader, const internal::RawSchema& schema);
};
class StructSchema::Member {
......
......@@ -119,28 +119,28 @@ private:
std::string::size_type readPos;
};
struct DisplayByteArray {
DisplayByteArray(const std::string& str)
: data(reinterpret_cast<const uint8_t*>(str.data())), size(str.size()) {}
DisplayByteArray(const std::initializer_list<uint8_t>& list)
: data(list.begin()), size(list.size()) {}
const uint8_t* data;
size_t size;
};
std::ostream& operator<<(std::ostream& os, const DisplayByteArray& bytes) {
os << "{ ";
for (size_t i = 0; i < bytes.size; i++) {
if (i > 0) {
os << ", ";
}
os << (uint)bytes.data[i];
}
os << " }";
return os;
}
//struct DisplayByteArray {
// DisplayByteArray(const std::string& str)
// : data(reinterpret_cast<const uint8_t*>(str.data())), size(str.size()) {}
// DisplayByteArray(const std::initializer_list<uint8_t>& list)
// : data(list.begin()), size(list.size()) {}
//
// const uint8_t* data;
// size_t size;
//};
//
//std::ostream& operator<<(std::ostream& os, const DisplayByteArray& bytes) {
// os << "{ ";
// for (size_t i = 0; i < bytes.size; i++) {
// if (i > 0) {
// os << ", ";
// }
// os << (uint)bytes.data[i];
// }
// os << " }";
//
// return os;
//}
TEST(Snappy, RoundTrip) {
TestMessageBuilder builder(1);
......
......@@ -252,7 +252,7 @@ void writeMessage(OutputStream& output, ArrayPtr<const ArrayPtr<const word>> seg
table[segments.size() + 1].set(0);
}
ArrayPtr<const byte> pieces[segments.size() + 1];
CAPNPROTO_STACK_ARRAY(ArrayPtr<const byte>, pieces, segments.size() + 1, 4, 32);
pieces[0] = arrayPtr(reinterpret_cast<byte*>(table), sizeof(table));
for (uint i = 0; i < segments.size(); i++) {
......@@ -260,7 +260,7 @@ void writeMessage(OutputStream& output, ArrayPtr<const ArrayPtr<const word>> seg
reinterpret_cast<const byte*>(segments[i].end()));
}
output.write(arrayPtr(pieces, segments.size() + 1));
output.write(pieces);
}
// =======================================================================================
......
......@@ -449,7 +449,7 @@ inline constexpr ArrayPtr<T> arrayPtr(T* begin, T* end) {
return ArrayPtr<T>(begin, end);
}
inline constexpr ArrayPtr<const char> arrayPtr(const char* s) {
inline ArrayPtr<const char> arrayPtr(const char* s) {
// Use this function to construct an ArrayPtr from a NUL-terminated string, especially a literal.
return arrayPtr(s, strlen(s));
}
......@@ -963,8 +963,8 @@ inline constexpr auto operator*(UnitRatio<Number1, Unit2, Unit> ratio,
// =======================================================================================
// Raw memory types and measures
class byte { uint8_t content; CAPNPROTO_DISALLOW_COPY(byte); public: byte() = default; };
class word { uint64_t content; CAPNPROTO_DISALLOW_COPY(word); public: word() = default; };
class byte { uint8_t content CAPNPROTO_UNUSED_FOR_CLANG; CAPNPROTO_DISALLOW_COPY(byte); public: byte() = default; };
class word { uint64_t content CAPNPROTO_UNUSED_FOR_CLANG; CAPNPROTO_DISALLOW_COPY(word); public: word() = default; };
// byte and word are opaque types with sizes of 8 and 64 bits, respectively. These types are useful
// only to make pointer arithmetic clearer. Since the contents are private, the only way to access
// them is to first reinterpret_cast to some other pointer type.
......@@ -978,7 +978,7 @@ class word { uint64_t content; CAPNPROTO_DISALLOW_COPY(word); public: word() = d
static_assert(sizeof(byte) == 1, "uint8_t is not one byte?");
static_assert(sizeof(word) == 8, "uint64_t is not 8 bytes?");
namespace internal { class BitLabel; class ElementLabel; class WirePointer; }
namespace internal { class BitLabel; class ElementLabel; struct WirePointer; }
#ifndef CAPNPROTO_DEBUG_TYPES
#define CAPNPROTO_DEBUG_TYPES 1
......
......@@ -209,7 +209,7 @@ struct Stringifier {
template <typename T>
Array<char> operator*(const Array<T>& arr) const;
};
static constexpr Stringifier STR;
static constexpr Stringifier STR = Stringifier();
CappedArray<char, sizeof(unsigned short) * 4> hex(unsigned short i);
CappedArray<char, sizeof(unsigned int) * 4> hex(unsigned int i);
......@@ -230,7 +230,7 @@ Array<char> str(Params&&... params) {
template <typename T>
Array<char> strArray(T&& arr, const char* delim) {
size_t delimLen = strlen(delim);
decltype(STR * arr[0]) pieces[arr.size()];
CAPNPROTO_STACK_ARRAY(decltype(STR * arr[0]), pieces, arr.size(), 8, 32);
size_t size = 0;
for (size_t i = 0; i < arr.size(); i++) {
if (i > 0) size += delimLen;
......
......@@ -185,7 +185,7 @@ private:
friend struct ::capnproto::ToDynamic_;
template <typename T, ::capnproto::Kind k>
friend struct ::capnproto::internal::PointerHelpers;
friend struct ::capnproto::MessageBuilder;
friend class ::capnproto::MessageBuilder;
};
{{! ------------------------------------------------------------------------------------------- }}
......
......@@ -74,6 +74,23 @@ const ::capnproto::internal::RawSchema s_{{schemaId}} = {
};
{{/typeSchema}}
{{/fileTypes}}
} // namespace schemas
namespace internal {
{{#fileTypes}}
{{#typeStructOrUnion}}
{{#typeStruct}}
CAPNPROTO_DEFINE_STRUCT(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}});
{{#structNestedEnums}}
CAPNPROTO_DEFINE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}});
{{/structNestedEnums}}
{{/typeStruct}}
{{/typeStructOrUnion}}
{{/fileTypes}}
{{#fileEnums}}
CAPNPROTO_DEFINE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{enumName}});
{{/fileEnums}}
} // namespace internal
} // namespace capnproto
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment