diff --git a/flatdata-cpp/include/flatdata/DebugDataAccessStatistics.h b/flatdata-cpp/include/flatdata/DebugDataAccessStatistics.h index 9114d6d3..a057f8b1 100644 --- a/flatdata-cpp/include/flatdata/DebugDataAccessStatistics.h +++ b/flatdata-cpp/include/flatdata/DebugDataAccessStatistics.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace flatdata { diff --git a/flatdata-generator/flatdata/generator/templates/cpp/constant.jinja2 b/flatdata-generator/flatdata/generator/templates/cpp/constant.jinja2 index b561513f..3a85d8e7 100644 --- a/flatdata-generator/flatdata/generator/templates/cpp/constant.jinja2 +++ b/flatdata-generator/flatdata/generator/templates/cpp/constant.jinja2 @@ -4,6 +4,6 @@ enum : {{ node.type|cpp_base_type}} {% if node.doc %} {{- node.doc|cpp_doc }} {% endif %} - {{ node.name }} = {{ node.value }} + {{ node.name }} = {{ node.value }}{{ node.type.annotation }} }; {%- endmacro %} diff --git a/flatdata-generator/flatdata/generator/templates/cpp/enumeration.jinja2 b/flatdata-generator/flatdata/generator/templates/cpp/enumeration.jinja2 index 6150fbad..b52543d0 100644 --- a/flatdata-generator/flatdata/generator/templates/cpp/enumeration.jinja2 +++ b/flatdata-generator/flatdata/generator/templates/cpp/enumeration.jinja2 @@ -9,7 +9,7 @@ enum class {{ enum.name }} : {{ enum.type|cpp_base_type }} {% if value.doc %} {{ value.doc|cpp_doc }} {% endif %} - {{ value.name }} = {{ value.value }}{{ "," if not loop.last }} + {{ value.name }} = {{ value.value }}{{ enum.type.annotation }}{{ "," if not loop.last }} {% endfor %} }; diff --git a/flatdata-generator/flatdata/generator/tree/helpers/basictype.py b/flatdata-generator/flatdata/generator/tree/helpers/basictype.py index 6a166f1b..53831131 100644 --- a/flatdata-generator/flatdata/generator/tree/helpers/basictype.py +++ b/flatdata-generator/flatdata/generator/tree/helpers/basictype.py @@ -16,6 +16,18 @@ class BasicType: "i64": 64 } + _TYPE_ANNOTATION = { + "bool": "", + "u8": "", + "i8": "", + "u16": "", + "i16": "", + "u32": "UL", + "i32": "L", + "u64": "ULL", + "i64": "LL" + } + @staticmethod def is_basic_type(name): return name in grammar.BASIC_TYPES @@ -41,6 +53,10 @@ def width(self): def is_signed(self): return self._name[0] == 'i' + @property + def annotation(self): + return self._TYPE_ANNOTATION[self._name] + def bits_required(self, value): if self.is_signed: if value >= 0: diff --git a/flatdata-generator/flatdata/generator/tree/helpers/enumtype.py b/flatdata-generator/flatdata/generator/tree/helpers/enumtype.py index d0b6ee77..51ba9e1c 100644 --- a/flatdata-generator/flatdata/generator/tree/helpers/enumtype.py +++ b/flatdata-generator/flatdata/generator/tree/helpers/enumtype.py @@ -15,6 +15,10 @@ def name(self): def width(self): return self._type.width + @property + def annotation(self): + return self._type.annotation + @property def is_signed(self): return self._type.is_signed diff --git a/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.1 b/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.1 index 5828b902..12baecae 100644 --- a/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.1 +++ b/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.1 @@ -1,5 +1,5 @@ enum : uint32_t { // This is a comment about foo - FOO = 0 + FOO = 0UL }; diff --git a/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.2 b/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.2 index 25fc96ed..7708bbff 100644 --- a/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.2 +++ b/flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.2 @@ -3,5 +3,5 @@ enum : uint64_t /* * This is a comment about bar */ - BAR = 0 + BAR = 0ULL }; \ No newline at end of file diff --git a/flatdata-generator/tests/generators/cpp_expectations/constants/values.h b/flatdata-generator/tests/generators/cpp_expectations/constants/values.h index a3dd44f5..463e9b21 100644 --- a/flatdata-generator/tests/generators/cpp_expectations/constants/values.h +++ b/flatdata-generator/tests/generators/cpp_expectations/constants/values.h @@ -141,139 +141,139 @@ enum : uint16_t namespace n { enum : int32_t { - FOO_I32_NEG = -2147483648 + FOO_I32_NEG = -2147483648L }; } // namespace n namespace n { enum : int32_t { - FOO_I32_POS = 2147483647 + FOO_I32_POS = 2147483647L }; } // namespace n namespace n { enum : int32_t { - FOO_I32_ZERO = 0 + FOO_I32_ZERO = 0L }; } // namespace n namespace n { enum : int32_t { - FOO_I32_NEG_HEX = -2147483648 + FOO_I32_NEG_HEX = -2147483648L }; } // namespace n namespace n { enum : int32_t { - FOO_I32_POS_HEX = 2147483647 + FOO_I32_POS_HEX = 2147483647L }; } // namespace n namespace n { enum : int32_t { - FOO_I32_ZERO_HEX = 0 + FOO_I32_ZERO_HEX = 0L }; } // namespace n namespace n { enum : uint32_t { - FOO_U32_POS = 4294967295 + FOO_U32_POS = 4294967295UL }; } // namespace n namespace n { enum : uint32_t { - FOO_U32_ZERO = 0 + FOO_U32_ZERO = 0UL }; } // namespace n namespace n { enum : uint32_t { - FOO_U32_POS_HEX = 4294967295 + FOO_U32_POS_HEX = 4294967295UL }; } // namespace n namespace n { enum : uint32_t { - FOO_U32_ZERO_HEX = 0 + FOO_U32_ZERO_HEX = 0UL }; } // namespace n namespace n { enum : int64_t { - FOO_I64_NEG = -9223372036854775808 + FOO_I64_NEG = -9223372036854775808LL }; } // namespace n namespace n { enum : int64_t { - FOO_I64_POS = 9223372036854775807 + FOO_I64_POS = 9223372036854775807LL }; } // namespace n namespace n { enum : int64_t { - FOO_I64_ZERO = 0 + FOO_I64_ZERO = 0LL }; } // namespace n namespace n { enum : int64_t { - FOO_I64_NEG_HEX = -9223372036854775808 + FOO_I64_NEG_HEX = -9223372036854775808LL }; } // namespace n namespace n { enum : int64_t { - FOO_I64_POS_HEX = 9223372036854775807 + FOO_I64_POS_HEX = 9223372036854775807LL }; } // namespace n namespace n { enum : int64_t { - FOO_I64_ZERO_HEX = 0 + FOO_I64_ZERO_HEX = 0LL }; } // namespace n namespace n { enum : uint64_t { - FOO_U64_POS = 18446744073709551615 + FOO_U64_POS = 18446744073709551615ULL }; } // namespace n namespace n { enum : uint64_t { - FOO_U64_ZERO = 0 + FOO_U64_ZERO = 0ULL }; } // namespace n namespace n { enum : uint64_t { - FOO_U64_POS_HEX = 18446744073709551615 + FOO_U64_POS_HEX = 18446744073709551615ULL }; } // namespace n namespace n { enum : uint64_t { - FOO_U64_ZERO_HEX = 0 + FOO_U64_ZERO_HEX = 0ULL }; } // namespace n \ No newline at end of file diff --git a/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.1 b/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.1 index 07f13a59..148b5537 100644 --- a/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.1 +++ b/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.1 @@ -2,7 +2,7 @@ enum class Foo : uint64_t { // This is a comment about Foo.a - A = 0, + A = 0ULL, // This is a comment about Foo.b - B = 1 + B = 1ULL }; diff --git a/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.2 b/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.2 index 2e7af6b0..f2c1151a 100644 --- a/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.2 +++ b/flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.2 @@ -6,9 +6,9 @@ enum class Bar : uint64_t /* * This is a comment about Bar.a */ - A = 0, + A = 0ULL, /* * This is a comment about Bar.b */ - B = 1 + B = 1ULL }; \ No newline at end of file diff --git a/flatdata-generator/tests/generators/cpp_expectations/enums/structs.h b/flatdata-generator/tests/generators/cpp_expectations/enums/structs.h index 7327b70b..6390d057 100644 --- a/flatdata-generator/tests/generators/cpp_expectations/enums/structs.h +++ b/flatdata-generator/tests/generators/cpp_expectations/enums/structs.h @@ -282,8 +282,8 @@ namespace n { enum class EnumI32 : int32_t { - VALUE = 0, - UNKNOWN_VALUE_MINUS_1 = -1 + VALUE = 0L, + UNKNOWN_VALUE_MINUS_1 = -1L }; inline @@ -350,8 +350,8 @@ namespace n { enum class EnumU32 : uint32_t { - VALUE = 0, - UNKNOWN_VALUE_1 = 1 + VALUE = 0UL, + UNKNOWN_VALUE_1 = 1UL }; inline @@ -418,8 +418,8 @@ namespace n { enum class EnumI64 : int64_t { - VALUE = 0, - UNKNOWN_VALUE_MINUS_1 = -1 + VALUE = 0LL, + UNKNOWN_VALUE_MINUS_1 = -1LL }; inline @@ -486,8 +486,8 @@ namespace n { enum class EnumU64 : uint64_t { - VALUE = 0, - UNKNOWN_VALUE_1 = 1 + VALUE = 0ULL, + UNKNOWN_VALUE_1 = 1ULL }; inline