aboutsummaryrefslogtreecommitdiff
path: root/tools/cddl/codegen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/cddl/codegen.cc')
-rw-r--r--tools/cddl/codegen.cc46
1 files changed, 23 insertions, 23 deletions
diff --git a/tools/cddl/codegen.cc b/tools/cddl/codegen.cc
index ac58eed9..a763b721 100644
--- a/tools/cddl/codegen.cc
+++ b/tools/cddl/codegen.cc
@@ -7,6 +7,7 @@
#include <cinttypes>
#include <iostream>
#include <limits>
+#include <memory>
#include <set>
#include <sstream>
#include <string>
@@ -381,7 +382,7 @@ bool EnsureDependentTypeDefinitionsWritten(int fd,
case CppType::Which::kVector: {
return EnsureDependentTypeDefinitionsWritten(
fd, *cpp_type.vector_type.element_type, defs);
- } break;
+ }
case CppType::Which::kEnum: {
if (defs->find(cpp_type.name) != defs->end())
return true;
@@ -406,7 +407,7 @@ bool EnsureDependentTypeDefinitionsWritten(int fd,
case CppType::Which::kOptional: {
return EnsureDependentTypeDefinitionsWritten(fd, *cpp_type.optional_type,
defs);
- } break;
+ }
case CppType::Which::kDiscriminatedUnion: {
for (const auto* x : cpp_type.discriminated_union.members)
if (!EnsureDependentTypeDefinitionsWritten(fd, *x, defs))
@@ -559,12 +560,10 @@ bool WriteEncoder(int fd,
}
return true;
}
- break;
case CppType::Which::kUint64:
dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_encode_uint(&encoder%d, %s));\n",
encoder_depth, ToUnderscoreId(name).c_str());
return true;
- break;
case CppType::Which::kString: {
std::string cid = ToUnderscoreId(name);
dprintf(fd, " if (!IsValidUtf8(%s)) {\n", cid.c_str());
@@ -575,7 +574,7 @@ bool WriteEncoder(int fd,
"%s.c_str(), %s.size()));\n",
encoder_depth, cid.c_str(), cid.c_str());
return true;
- } break;
+ }
case CppType::Which::kBytes: {
std::string cid = ToUnderscoreId(name);
dprintf(fd,
@@ -584,7 +583,7 @@ bool WriteEncoder(int fd,
"%s.size()));\n",
encoder_depth, cid.c_str(), cid.c_str());
return true;
- } break;
+ }
case CppType::Which::kVector: {
std::string cid = ToUnderscoreId(name);
dprintf(fd, " {\n");
@@ -619,14 +618,14 @@ bool WriteEncoder(int fd,
encoder_depth, encoder_depth + 1);
dprintf(fd, " }\n");
return true;
- } break;
+ }
case CppType::Which::kEnum: {
dprintf(fd,
" CBOR_RETURN_ON_ERROR(cbor_encode_uint(&encoder%d, "
"static_cast<uint64_t>(%s)));\n",
encoder_depth, ToUnderscoreId(name).c_str());
return true;
- } break;
+ }
case CppType::Which::kDiscriminatedUnion: {
for (const auto* union_member : cpp_type.discriminated_union.members) {
switch (union_member->which) {
@@ -670,7 +669,7 @@ bool WriteEncoder(int fd,
ToCamelCase(cpp_type.name).c_str());
dprintf(fd, " return -CborUnknownError;\n");
return true;
- } break;
+ }
case CppType::Which::kTaggedType: {
dprintf(fd,
" CBOR_RETURN_ON_ERROR(cbor_encode_tag(&encoder%d, %" PRIu64
@@ -681,7 +680,7 @@ bool WriteEncoder(int fd,
return false;
}
return true;
- } break;
+ }
default:
break;
}
@@ -1042,7 +1041,7 @@ bool WriteDecoder(int fd,
dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n",
decoder_depth);
return true;
- } break;
+ }
case CppType::Which::kString: {
int temp_length = (*temporary_count)++;
dprintf(fd, " size_t length%d = 0;", temp_length);
@@ -1073,7 +1072,7 @@ bool WriteDecoder(int fd,
dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance(&it%d));\n",
decoder_depth);
return true;
- } break;
+ }
case CppType::Which::kBytes: {
int temp_length = (*temporary_count)++;
dprintf(fd, " size_t length%d = 0;", temp_length);
@@ -1110,7 +1109,7 @@ bool WriteDecoder(int fd,
dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance(&it%d));\n",
decoder_depth);
return true;
- } break;
+ }
case CppType::Which::kVector: {
dprintf(fd, " if (cbor_value_get_type(&it%d) != CborArrayType) {\n",
decoder_depth);
@@ -1157,7 +1156,7 @@ bool WriteDecoder(int fd,
decoder_depth, decoder_depth + 1);
dprintf(fd, " }\n");
return true;
- } break;
+ }
case CppType::Which::kEnum: {
dprintf(fd,
" CBOR_RETURN_ON_ERROR(cbor_value_get_uint64(&it%d, "
@@ -1167,7 +1166,7 @@ bool WriteDecoder(int fd,
decoder_depth);
// TODO(btolsch): Validate against enum members.
return true;
- } break;
+ }
case CppType::Which::kStruct: {
if (cpp_type.struct_type.key_type == CppType::Struct::KeyType::kMap) {
return WriteMapDecoder(fd, name, member_accessor,
@@ -1235,7 +1234,7 @@ bool WriteDecoder(int fd,
}
dprintf(fd, " else { return -1; }\n");
return true;
- } break;
+ }
case CppType::Which::kTaggedType: {
int temp_tag = (*temporary_count)++;
dprintf(fd, " uint64_t tag%d = 0;\n", temp_tag);
@@ -1253,7 +1252,7 @@ bool WriteDecoder(int fd,
return false;
}
return true;
- } break;
+ }
default:
break;
}
@@ -1586,15 +1585,16 @@ namespace openscreen {
namespace msgs {
namespace {
+/*
+ * Encoder-specific errors, so it's fine to check these even in the
+ * parser.
+ */
#define CBOR_RETURN_WHAT_ON_ERROR(stmt, what) \
{ \
CborError error = stmt; \
- /* Encoder-specific errors, so it's fine to check these even in the \
- * parser. \
- */ \
- OSP_DCHECK_NE(error, CborErrorTooFewItems); \
- OSP_DCHECK_NE(error, CborErrorTooManyItems); \
- OSP_DCHECK_NE(error, CborErrorDataTooLarge); \
+ OSP_DCHECK_NE(error, CborErrorTooFewItems); \
+ OSP_DCHECK_NE(error, CborErrorTooManyItems); \
+ OSP_DCHECK_NE(error, CborErrorDataTooLarge); \
if (error != CborNoError && error != CborErrorOutOfMemory) \
return what; \
}