diff --git a/cel-c/alloc.cc b/cel-c/alloc.cc index 66ce147..2855d65 100644 --- a/cel-c/alloc.cc +++ b/cel-c/alloc.cc @@ -69,7 +69,7 @@ static CEL_NULLABILITY_UNKNOWN(void*) _cel_DefaultAllocator_AllocFunc( } static cel_Allocator _cel_DefaultAllocator = { - .func = &_cel_DefaultAllocator_AllocFunc, + /*func=*/&_cel_DefaultAllocator_AllocFunc, }; extern "C" CEL_NONNULL(cel_Allocator*) const cel_DefaultAllocator = diff --git a/cel-c/config.h b/cel-c/config.h index 2a0b5e0..c292358 100644 --- a/cel-c/config.h +++ b/cel-c/config.h @@ -121,6 +121,21 @@ CEL_STATIC_ASSERT(sizeof(unsigned char) == 1); #define cel_nullptr NULL #endif +#ifdef CEL_COMPOUND_LITERAL +#error CEL_COMPOUND_LITERAL cannot be directly set +#endif + +// CEL_COMPOUND_LITERAL +// +// `CEL_COMPOUND_LITERAL(T){...}` expands to the compound literal `(T){...}` in +// C and to the equivalent explicit type conversion `T{...}` in C++, where +// compound literals are a non-standard extension (e.g. MSVC warning C4576). +#ifdef __cplusplus +#define CEL_COMPOUND_LITERAL(T) T +#else +#define CEL_COMPOUND_LITERAL(T) (T) +#endif + #ifdef CEL_HAVE_BUILTIN #error CEL_HAVE_BUILTIN cannot be directly set #endif diff --git a/cel-c/duration.h b/cel-c/duration.h index 4b91a31..05b87fb 100644 --- a/cel-c/duration.h +++ b/cel-c/duration.h @@ -60,28 +60,28 @@ CEL_BEGIN_DECLS #ifdef _CEL_IS_BIG_ENDIAN #define cel_Duration_kZero \ - ((cel_Duration){{INT32_C(0), UINT32_C{0}}, INT32_C(0)}) + (CEL_COMPOUND_LITERAL(cel_Duration){{INT32_C(0), UINT32_C(0)}, INT32_C(0)}) #define cel_Duration_kMin \ - ((cel_Duration){ \ + (CEL_COMPOUND_LITERAL(cel_Duration){ \ {(int32_t)(uint32_t)(((uint64_t)cel_Duration_kMinSeconds) >> 32), \ ((uint32_t)(uint64_t)cel_Duration_kMinSeconds)}, \ cel_Duration_kMinNanos}) #define cel_Duration_kMax \ - ((cel_Duration){ \ + (CEL_COMPOUND_LITERAL(cel_Duration){ \ {(int32_t)(uint32_t)(((uint64_t)cel_Duration_kMaxSeconds) >> 32), \ ((uint32_t)(uint64_t)cel_Duration_kMaxSeconds)}, \ cel_Duration_kMaxNanos}) #endif #ifdef _CEL_IS_LITTLE_ENDIAN #define cel_Duration_kZero \ - ((cel_Duration){{UINT32_C(0), INT32_C(0)}, INT32_C(0)}) + (CEL_COMPOUND_LITERAL(cel_Duration){{UINT32_C(0), INT32_C(0)}, INT32_C(0)}) #define cel_Duration_kMin \ - ((cel_Duration){ \ + (CEL_COMPOUND_LITERAL(cel_Duration){ \ {((uint32_t)(uint64_t)cel_Duration_kMinSeconds), \ (int32_t)(uint32_t)(((uint64_t)cel_Duration_kMinSeconds) >> 32)}, \ cel_Duration_kMinNanos}) #define cel_Duration_kMax \ - ((cel_Duration){ \ + (CEL_COMPOUND_LITERAL(cel_Duration){ \ {((uint32_t)(uint64_t)cel_Duration_kMaxSeconds), \ (int32_t)(uint32_t)(((uint64_t)cel_Duration_kMaxSeconds) >> 32)}, \ cel_Duration_kMaxNanos}) diff --git a/cel-c/error.cc b/cel-c/error.cc index 6ea2e61..8bb9642 100644 --- a/cel-c/error.cc +++ b/cel-c/error.cc @@ -48,13 +48,13 @@ struct cel_Error { }; static const cel_Error _cel_DefaultError = { - .message = CEL_STRINGVIEW_C(""), - .space = cel_nullptr, - .raw_code = cel_ErrorCode_kUnknown, - .code = cel_ErrorCode_kUnknown, - .payloads_len = 0, - .payloads_head = cel_nullptr, - .payloads_tail = cel_nullptr, + /*message=*/CEL_STRINGVIEW_C(""), + /*space=*/cel_nullptr, + /*raw_code=*/cel_ErrorCode_kUnknown, + /*code=*/cel_ErrorCode_kUnknown, + /*payloads_len=*/0, + /*payloads_head=*/cel_nullptr, + /*payloads_tail=*/cel_nullptr, }; extern "C" const cel_Error* const cel_nonnull cel_DefaultError = diff --git a/cel-c/error_space.cc b/cel-c/error_space.cc index 1004244..c30c426 100644 --- a/cel-c/error_space.cc +++ b/cel-c/error_space.cc @@ -91,14 +91,14 @@ static int _cel_CanonicalErrorSpace_Message(CEL_NONNULL(const cel_ErrorSpace*) } static const cel_ErrorSpaceVTable _cel_CanonicalErrorSpaceVTable = { - .name = CEL_CSTRINGVIEW_C("canonical"), - .OutOfMemory = _cel_CanonicalErrorSpace_OutOfMemory, - .Canonical = _cel_CanonicalErrorSpace_Canonical, - .Message = _cel_CanonicalErrorSpace_Message, + /*name=*/CEL_CSTRINGVIEW_C("canonical"), + /*OutOfMemory=*/_cel_CanonicalErrorSpace_OutOfMemory, + /*Canonical=*/_cel_CanonicalErrorSpace_Canonical, + /*Message=*/_cel_CanonicalErrorSpace_Message, }; static const cel_ErrorSpace _cel_CanonicalErrorSpace = { - .vtable = &_cel_CanonicalErrorSpaceVTable, + /*vtable=*/&_cel_CanonicalErrorSpaceVTable, }; extern "C" CEL_NONNULL(const cel_ErrorSpace*) @@ -427,14 +427,14 @@ static int _cel_GenericErrorSpace_Message(CEL_NONNULL(const cel_ErrorSpace*) } static const cel_ErrorSpaceVTable _cel_GenericErrorSpaceVTable = { - .name = CEL_CSTRINGVIEW_C("generic"), - .OutOfMemory = _cel_GenericErrorSpace_OutOfMemory, - .Canonical = _cel_GenericErrorSpace_Canonical, - .Message = _cel_GenericErrorSpace_Message, + /*name=*/CEL_CSTRINGVIEW_C("generic"), + /*OutOfMemory=*/_cel_GenericErrorSpace_OutOfMemory, + /*Canonical=*/_cel_GenericErrorSpace_Canonical, + /*Message=*/_cel_GenericErrorSpace_Message, }; static const cel_ErrorSpace _cel_GenericErrorSpace = { - .vtable = &_cel_GenericErrorSpaceVTable, + /*vtable=*/&_cel_GenericErrorSpaceVTable, }; extern "C" CEL_NONNULL(const cel_ErrorSpace*) @@ -672,14 +672,14 @@ static int _cel_SystemErrorSpace_Message(CEL_NONNULL(const cel_ErrorSpace*) } static const cel_ErrorSpaceVTable _cel_SystemErrorSpaceVTable = { - .name = CEL_CSTRINGVIEW_C("system"), - .OutOfMemory = _cel_SystemErrorSpace_OutOfMemory, - .Canonical = _cel_SystemErrorSpace_Canonical, - .Message = _cel_SystemErrorSpace_Message, + /*name=*/CEL_CSTRINGVIEW_C("system"), + /*OutOfMemory=*/_cel_SystemErrorSpace_OutOfMemory, + /*Canonical=*/_cel_SystemErrorSpace_Canonical, + /*Message=*/_cel_SystemErrorSpace_Message, }; static const cel_ErrorSpace _cel_SystemErrorSpace = { - .vtable = &_cel_SystemErrorSpaceVTable, + /*vtable=*/&_cel_SystemErrorSpaceVTable, }; extern "C" CEL_NONNULL(const cel_ErrorSpace*) diff --git a/cel-c/internal/BUILD b/cel-c/internal/BUILD index 2108fbf..3cdcec1 100644 --- a/cel-c/internal/BUILD +++ b/cel-c/internal/BUILD @@ -256,6 +256,20 @@ cc_test( ], ) +# Compiled as C to cover the C99 versions of the macros in constant.h and +# attribute.h, which C++ translation units do not see. +cc_test( + name = "c_macros_test", + srcs = ["c_macros_test.c"], + deps = [ + ":attribute", + ":constant", + "//cel-c:duration", + "//cel-c:string_view", + "//cel-c:timestamp", + ], +) + cc_library( name = "binary_search", hdrs = ["binary_search.h"], diff --git a/cel-c/internal/attribute.h b/cel-c/internal/attribute.h index 6cc4da8..7c953c3 100644 --- a/cel-c/internal/attribute.h +++ b/cel-c/internal/attribute.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "cel-c/assert.h" #include "cel-c/config.h" @@ -62,6 +63,8 @@ typedef struct { CEL_STATIC_ASSERT(sizeof(cel_AttributeQualifier) == 16); CEL_STATIC_ASSERT(alignof(cel_AttributeQualifier) == 8); +#ifndef __cplusplus + // cel_UnspecifiedAttributeQualifier // // Returns an unspecified attribute qualifier. @@ -109,6 +112,24 @@ CEL_STATIC_ASSERT(alignof(cel_AttributeQualifier) == 8); }, \ .kind = cel_AttributeQualifierKind_kString}) +#else // __cplusplus + +// In C++ the attribute-qualifier-returning macros are implemented with the +// inline functions defined below, since designated initializers are a C++20 +// feature and are rejected by some compilers (e.g. MSVC) in earlier language +// modes. +#define cel_UnspecifiedAttributeQualifier() \ + (_cel_AttributeQualifier_MakeUnspecified()) +#define cel_BoolAttributeQualifier(val) \ + (_cel_AttributeQualifier_MakeBool((val))) +#define cel_IntAttributeQualifier(val) (_cel_AttributeQualifier_MakeInt((val))) +#define cel_UintAttributeQualifier(val) \ + (_cel_AttributeQualifier_MakeUint((val))) +#define cel_StringAttributeQualifier(val) \ + (_cel_AttributeQualifier_MakeString((val))) + +#endif // __cplusplus + // cel_AttributeQualifier_SetBool // // Sets the attribute qualifier to be bool. @@ -116,7 +137,9 @@ static CEL_INLINE void cel_AttributeQualifier_SetBool( CEL_NONNULL(cel_AttributeQualifier*) attribute_qualifier, bool val) { CEL_ASSERT_NOT_NULL(attribute_qualifier); - *attribute_qualifier = cel_BoolAttributeQualifier(val); + memset(&attribute_qualifier->data, 0, sizeof(attribute_qualifier->data)); + attribute_qualifier->data.b = val; + attribute_qualifier->kind = cel_AttributeQualifierKind_kBool; } // cel_AttributeQualifier_SetInt @@ -126,7 +149,9 @@ static CEL_INLINE void cel_AttributeQualifier_SetInt( CEL_NONNULL(cel_AttributeQualifier*) attribute_qualifier, int64_t val) { CEL_ASSERT_NOT_NULL(attribute_qualifier); - *attribute_qualifier = cel_IntAttributeQualifier(val); + memset(&attribute_qualifier->data, 0, sizeof(attribute_qualifier->data)); + attribute_qualifier->data.i = val; + attribute_qualifier->kind = cel_AttributeQualifierKind_kInt; } // cel_AttributeQualifier_SetUint @@ -136,7 +161,9 @@ static CEL_INLINE void cel_AttributeQualifier_SetUint( CEL_NONNULL(cel_AttributeQualifier*) attribute_qualifier, uint64_t val) { CEL_ASSERT_NOT_NULL(attribute_qualifier); - *attribute_qualifier = cel_UintAttributeQualifier(val); + memset(&attribute_qualifier->data, 0, sizeof(attribute_qualifier->data)); + attribute_qualifier->data.u = val; + attribute_qualifier->kind = cel_AttributeQualifierKind_kUint; } // cel_AttributeQualifier_SetString @@ -147,9 +174,55 @@ static CEL_INLINE void cel_AttributeQualifier_SetString( cel_StringView val) { CEL_ASSERT_NOT_NULL(attribute_qualifier); - *attribute_qualifier = cel_StringAttributeQualifier(val); + memset(&attribute_qualifier->data, 0, sizeof(attribute_qualifier->data)); + attribute_qualifier->data.s.data = cel_StringView_Data(val); + attribute_qualifier->data.s.size = cel_StringView_Size32(val); + attribute_qualifier->kind = cel_AttributeQualifierKind_kString; +} + +#ifdef __cplusplus + +// Implementation details of the C++ versions of the +// `cel_*AttributeQualifier()` macros. + +static CEL_INLINE cel_AttributeQualifier +_cel_AttributeQualifier_MakeUnspecified(void) { + cel_AttributeQualifier attribute_qualifier; + memset(&attribute_qualifier.data, 0, sizeof(attribute_qualifier.data)); + attribute_qualifier.kind = cel_AttributeQualifierKind_kUnspecified; + return attribute_qualifier; } +static CEL_INLINE cel_AttributeQualifier +_cel_AttributeQualifier_MakeBool(bool val) { + cel_AttributeQualifier attribute_qualifier; + cel_AttributeQualifier_SetBool(&attribute_qualifier, val); + return attribute_qualifier; +} + +static CEL_INLINE cel_AttributeQualifier +_cel_AttributeQualifier_MakeInt(int64_t val) { + cel_AttributeQualifier attribute_qualifier; + cel_AttributeQualifier_SetInt(&attribute_qualifier, val); + return attribute_qualifier; +} + +static CEL_INLINE cel_AttributeQualifier +_cel_AttributeQualifier_MakeUint(uint64_t val) { + cel_AttributeQualifier attribute_qualifier; + cel_AttributeQualifier_SetUint(&attribute_qualifier, val); + return attribute_qualifier; +} + +static CEL_INLINE cel_AttributeQualifier +_cel_AttributeQualifier_MakeString(cel_StringView val) { + cel_AttributeQualifier attribute_qualifier; + cel_AttributeQualifier_SetString(&attribute_qualifier, val); + return attribute_qualifier; +} + +#endif // __cplusplus + // cel_AttributeQualifier_Kind // // Returns the kind of the attribute qualifier. diff --git a/cel-c/internal/c_macros_test.c b/cel-c/internal/c_macros_test.c new file mode 100644 index 0000000..cf38ae7 --- /dev/null +++ b/cel-c/internal/c_macros_test.c @@ -0,0 +1,136 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Compiled as C to exercise the C99 versions of the `cel_*Constant()` and +// `cel_*AttributeQualifier()` macros, which are not visible to C++ code, and +// checks that they agree with the corresponding `*_Set*` functions. + +#include +#include +#include + +#include "cel-c/duration.h" +#include "cel-c/internal/attribute.h" +#include "cel-c/internal/constant.h" +#include "cel-c/string_view.h" +#include "cel-c/timestamp.h" + +static int failures = 0; + +#define EXPECT(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, "%s:%d: EXPECT(%s) failed\n", __FILE__, __LINE__, \ + #cond); \ + ++failures; \ + } \ + } while (0) + +static void TestConstantMacros(void) { + const cel_StringView str = cel_StringView_FromString("foo"); + const cel_Duration duration = cel_Duration_FromUnix(1, 2); + const cel_Timestamp timestamp = cel_Timestamp_FromUnix(3, 4); + cel_Constant set; + + cel_Constant c = cel_UnspecifiedConstant(); + EXPECT(cel_Constant_Kind(&c) == cel_ConstantKind_kUnspecified); + + c = cel_NullConstant(); + cel_Constant_SetNull(&set); + EXPECT(cel_Constant_Kind(&c) == cel_ConstantKind_kNull); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_BoolConstant(true); + cel_Constant_SetBool(&set, true); + EXPECT(cel_Constant_GetBool(&c)); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_IntConstant(-42); + cel_Constant_SetInt(&set, -42); + EXPECT(cel_Constant_GetInt(&c) == -42); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_UintConstant(42u); + cel_Constant_SetUint(&set, 42u); + EXPECT(cel_Constant_GetUint(&c) == 42u); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_DoubleConstant(1.5); + cel_Constant_SetDouble(&set, 1.5); + EXPECT(cel_Constant_GetDouble(&c) == 1.5); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_BytesConstant(str); + cel_Constant_SetBytes(&set, str); + EXPECT(cel_StringView_Equals(cel_Constant_GetBytes(&c), str)); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_StringConstant(str); + cel_Constant_SetString(&set, str); + EXPECT(cel_StringView_Equals(cel_Constant_GetString(&c), str)); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_DurationConstant(duration); + cel_Constant_SetDuration(&set, duration); + EXPECT(cel_Duration_Equals(cel_Constant_GetDuration(&c), duration)); + EXPECT(cel_Constant_Equals(&c, &set)); + + c = cel_TimestampConstant(timestamp); + cel_Constant_SetTimestamp(&set, timestamp); + EXPECT(cel_Timestamp_Equals(cel_Constant_GetTimestamp(&c), timestamp)); + EXPECT(cel_Constant_Equals(&c, &set)); +} + +static void TestAttributeQualifierMacros(void) { + const cel_StringView str = cel_StringView_FromString("bar"); + cel_AttributeQualifier set; + + cel_AttributeQualifier q = cel_UnspecifiedAttributeQualifier(); + EXPECT(cel_AttributeQualifier_Kind(&q) == + cel_AttributeQualifierKind_kUnspecified); + + q = cel_BoolAttributeQualifier(true); + cel_AttributeQualifier_SetBool(&set, true); + EXPECT(cel_AttributeQualifier_Kind(&q) == cel_AttributeQualifier_Kind(&set)); + EXPECT(cel_AttributeQualifier_GetBool(&q) == + cel_AttributeQualifier_GetBool(&set)); + + q = cel_IntAttributeQualifier(-7); + cel_AttributeQualifier_SetInt(&set, -7); + EXPECT(cel_AttributeQualifier_Kind(&q) == cel_AttributeQualifier_Kind(&set)); + EXPECT(cel_AttributeQualifier_GetInt(&q) == -7); + EXPECT(cel_AttributeQualifier_GetInt(&set) == -7); + + q = cel_UintAttributeQualifier(7u); + cel_AttributeQualifier_SetUint(&set, 7u); + EXPECT(cel_AttributeQualifier_Kind(&q) == cel_AttributeQualifier_Kind(&set)); + EXPECT(cel_AttributeQualifier_GetUint(&q) == 7u); + EXPECT(cel_AttributeQualifier_GetUint(&set) == 7u); + + q = cel_StringAttributeQualifier(str); + cel_AttributeQualifier_SetString(&set, str); + EXPECT(cel_AttributeQualifier_Kind(&q) == cel_AttributeQualifier_Kind(&set)); + EXPECT(cel_StringView_Equals(cel_AttributeQualifier_GetString(&q), str)); + EXPECT(cel_StringView_Equals(cel_AttributeQualifier_GetString(&set), str)); +} + +int main(void) { + TestConstantMacros(); + TestAttributeQualifierMacros(); + if (failures != 0) { + fprintf(stderr, "%d failure(s)\n", failures); + return 1; + } + return 0; +} diff --git a/cel-c/internal/constant.h b/cel-c/internal/constant.h index 36cad59..751c9f3 100644 --- a/cel-c/internal/constant.h +++ b/cel-c/internal/constant.h @@ -18,6 +18,7 @@ #include #include // IWYU pragma: keep #include +#include #include "cel-c/assert.h" #include "cel-c/config.h" @@ -74,6 +75,8 @@ typedef struct { CEL_STATIC_ASSERT(sizeof(cel_Constant) == 16); CEL_STATIC_ASSERT(alignof(cel_Constant) == 8); +#ifndef __cplusplus + // cel_UnspecifiedConstant // // Returns an unspecified constant. @@ -167,6 +170,24 @@ CEL_STATIC_ASSERT(alignof(cel_Constant) == 8); }, \ .kind = cel_ConstantKind_kTimestamp}) +#else // __cplusplus + +// In C++ the constant-returning macros are implemented with the inline +// functions defined below, since designated initializers are a C++20 feature +// and are rejected by some compilers (e.g. MSVC) in earlier language modes. +#define cel_UnspecifiedConstant() (_cel_Constant_MakeUnspecified()) +#define cel_NullConstant() (_cel_Constant_MakeNull()) +#define cel_BoolConstant(val) (_cel_Constant_MakeBool((val))) +#define cel_IntConstant(val) (_cel_Constant_MakeInt((val))) +#define cel_UintConstant(val) (_cel_Constant_MakeUint((val))) +#define cel_DoubleConstant(val) (_cel_Constant_MakeDouble((val))) +#define cel_BytesConstant(val) (_cel_Constant_MakeBytes((val))) +#define cel_StringConstant(val) (_cel_Constant_MakeString((val))) +#define cel_DurationConstant(val) (_cel_Constant_MakeDuration((val))) +#define cel_TimestampConstant(val) (_cel_Constant_MakeTimestamp((val))) + +#endif // __cplusplus + // cel_Constant_SetNull // // Sets the constant to be null. @@ -174,7 +195,8 @@ static CEL_INLINE void cel_Constant_SetNull(CEL_NONNULL(cel_Constant*) constant) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_NullConstant(); + memset(&constant->data, 0, sizeof(constant->data)); + constant->kind = cel_ConstantKind_kNull; } // cel_Constant_SetBool @@ -184,7 +206,9 @@ static CEL_INLINE void cel_Constant_SetBool(CEL_NONNULL(cel_Constant*) constant, bool val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_BoolConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.b = val; + constant->kind = cel_ConstantKind_kBool; } // cel_Constant_SetInt @@ -194,7 +218,9 @@ static CEL_INLINE void cel_Constant_SetInt(CEL_NONNULL(cel_Constant*) constant, int64_t val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_IntConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.i = val; + constant->kind = cel_ConstantKind_kInt; } // cel_Constant_SetUint @@ -204,7 +230,9 @@ static CEL_INLINE void cel_Constant_SetUint(CEL_NONNULL(cel_Constant*) constant, uint64_t val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_UintConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.u = val; + constant->kind = cel_ConstantKind_kUint; } // cel_Constant_SetDouble @@ -215,7 +243,9 @@ static CEL_INLINE void cel_Constant_SetDouble(CEL_NONNULL(cel_Constant*) double val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_DoubleConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.f = val; + constant->kind = cel_ConstantKind_kDouble; } // cel_Constant_SetBytes @@ -226,7 +256,10 @@ static CEL_INLINE void cel_Constant_SetBytes(CEL_NONNULL(cel_Constant*) cel_StringView val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_BytesConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.s.data = cel_StringView_Data(val); + constant->data.s.size = cel_StringView_Size32(val); + constant->kind = cel_ConstantKind_kBytes; } // cel_Constant_SetString @@ -237,7 +270,10 @@ static CEL_INLINE void cel_Constant_SetString(CEL_NONNULL(cel_Constant*) cel_StringView val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_StringConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.s.data = cel_StringView_Data(val); + constant->data.s.size = cel_StringView_Size32(val); + constant->kind = cel_ConstantKind_kString; } // cel_Constant_SetDuration @@ -248,7 +284,9 @@ static CEL_INLINE void cel_Constant_SetDuration(CEL_NONNULL(cel_Constant*) cel_Duration val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_DurationConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.d = val; + constant->kind = cel_ConstantKind_kDuration; } // cel_Constant_SetTimestamp @@ -259,9 +297,78 @@ static CEL_INLINE void cel_Constant_SetTimestamp(CEL_NONNULL(cel_Constant*) cel_Timestamp val) { CEL_ASSERT_NOT_NULL(constant); - *constant = cel_TimestampConstant(val); + memset(&constant->data, 0, sizeof(constant->data)); + constant->data.t = val; + constant->kind = cel_ConstantKind_kTimestamp; +} + +#ifdef __cplusplus + +// Implementation details of the C++ versions of the `cel_*Constant()` macros. + +static CEL_INLINE cel_Constant _cel_Constant_MakeUnspecified(void) { + cel_Constant constant; + memset(&constant.data, 0, sizeof(constant.data)); + constant.kind = cel_ConstantKind_kUnspecified; + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeNull(void) { + cel_Constant constant; + cel_Constant_SetNull(&constant); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeBool(bool val) { + cel_Constant constant; + cel_Constant_SetBool(&constant, val); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeInt(int64_t val) { + cel_Constant constant; + cel_Constant_SetInt(&constant, val); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeUint(uint64_t val) { + cel_Constant constant; + cel_Constant_SetUint(&constant, val); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeDouble(double val) { + cel_Constant constant; + cel_Constant_SetDouble(&constant, val); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeBytes(cel_StringView val) { + cel_Constant constant; + cel_Constant_SetBytes(&constant, val); + return constant; } +static CEL_INLINE cel_Constant _cel_Constant_MakeString(cel_StringView val) { + cel_Constant constant; + cel_Constant_SetString(&constant, val); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeDuration(cel_Duration val) { + cel_Constant constant; + cel_Constant_SetDuration(&constant, val); + return constant; +} + +static CEL_INLINE cel_Constant _cel_Constant_MakeTimestamp(cel_Timestamp val) { + cel_Constant constant; + cel_Constant_SetTimestamp(&constant, val); + return constant; +} + +#endif // __cplusplus + // cel_Constant_Kind // // Returns the kind of the constant. diff --git a/cel-c/internal/container.h b/cel-c/internal/container.h index a1efebe..c906195 100644 --- a/cel-c/internal/container.h +++ b/cel-c/internal/container.h @@ -25,7 +25,7 @@ #include "cel-c/string_view.h" struct _cel_ContainerIterator { - cel_StringView name = cel_StringView{.data = "", .size = 0}; + cel_StringView name = cel_StringView{/*data=*/"", /*size=*/0}; size_t size = 0; [[nodiscard]] diff --git a/cel-c/internal/empty_list_value.cc b/cel-c/internal/empty_list_value.cc index 22df8fb..af0230d 100644 --- a/cel-c/internal/empty_list_value.cc +++ b/cel-c/internal/empty_list_value.cc @@ -96,11 +96,11 @@ static cel_ListValueIterator* cel_nullable _cel_EmptyListValue_NewIterator( } const cel_ListValueVTable _cel_EmptyListValueVTable = { - .Equals = cel_nullptr, - .FastSize = &_cel_EmptyListValue_FastSize, - .SlowSize = &_cel_EmptyListValue_SlowSize, - .Get = &_cel_EmptyListValue_Get, - .NewIterator = &_cel_EmptyListValue_NewIterator, + /*Equals=*/cel_nullptr, + /*FastSize=*/&_cel_EmptyListValue_FastSize, + /*SlowSize=*/&_cel_EmptyListValue_SlowSize, + /*Get=*/&_cel_EmptyListValue_Get, + /*NewIterator=*/&_cel_EmptyListValue_NewIterator, }; static bool _cel_EmptyListValueIterator_Next1( @@ -155,16 +155,16 @@ static bool _cel_EmptyListValueIterator_Next( } const cel_ListValueIteratorVTable _cel_EmptyListValueIteratorVTable = { - .super = - { - .Delete = cel_nullptr, - .Next1 = &_cel_EmptyListValueIterator_Next1, - .Next2 = &_cel_EmptyListValueIterator_Next2, - .Remaining = &_cel_EmptyListValueIterator_Remaining, - }, - .Next = &_cel_EmptyListValueIterator_Next, + /*super=*/ + { + /*Delete=*/cel_nullptr, + /*Next1=*/&_cel_EmptyListValueIterator_Next1, + /*Next2=*/&_cel_EmptyListValueIterator_Next2, + /*Remaining=*/&_cel_EmptyListValueIterator_Remaining, + }, + /*Next=*/&_cel_EmptyListValueIterator_Next, }; extern "C" cel_ListValueIterator _cel_EmptyListValueIterator = { - .vtable = &_cel_EmptyListValueIteratorVTable, + /*vtable=*/&_cel_EmptyListValueIteratorVTable, }; diff --git a/cel-c/internal/empty_map_value.cc b/cel-c/internal/empty_map_value.cc index 8944b3b..a8d59c9 100644 --- a/cel-c/internal/empty_map_value.cc +++ b/cel-c/internal/empty_map_value.cc @@ -133,13 +133,13 @@ static cel_MapValueIterator* cel_nullable _cel_EmptyMapValue_NewIterator( } const cel_MapValueVTable _cel_EmptyMapValueVTable = { - .Equals = cel_nullptr, - .FastSize = &_cel_EmptyMapValue_FastSize, - .SlowSize = &_cel_EmptyMapValue_SlowSize, - .Get = &_cel_EmptyMapValue_Get, - .Find = &_cel_EmptyMapValue_Find, - .Has = &_cel_EmptyMapValue_Has, - .NewIterator = &_cel_EmptyMapValue_NewIterator, + /*Equals=*/cel_nullptr, + /*FastSize=*/&_cel_EmptyMapValue_FastSize, + /*SlowSize=*/&_cel_EmptyMapValue_SlowSize, + /*Get=*/&_cel_EmptyMapValue_Get, + /*Find=*/&_cel_EmptyMapValue_Find, + /*Has=*/&_cel_EmptyMapValue_Has, + /*NewIterator=*/&_cel_EmptyMapValue_NewIterator, }; static bool _cel_EmptyMapValueIterator_Next1( @@ -196,16 +196,16 @@ static bool _cel_EmptyMapValueIterator_Next( } const cel_MapValueIteratorVTable _cel_EmptyMapValueIteratorVTable = { - .super = - { - .Delete = cel_nullptr, - .Next1 = &_cel_EmptyMapValueIterator_Next1, - .Next2 = &_cel_EmptyMapValueIterator_Next2, - .Remaining = &_cel_EmptyMapValueIterator_Remaining, - }, - .Next = &_cel_EmptyMapValueIterator_Next, + /*super=*/ + { + /*Delete=*/cel_nullptr, + /*Next1=*/&_cel_EmptyMapValueIterator_Next1, + /*Next2=*/&_cel_EmptyMapValueIterator_Next2, + /*Remaining=*/&_cel_EmptyMapValueIterator_Remaining, + }, + /*Next=*/&_cel_EmptyMapValueIterator_Next, }; extern "C" cel_MapValueIterator _cel_EmptyMapValueIterator = { - .vtable = &_cel_EmptyMapValueIteratorVTable, + /*vtable=*/&_cel_EmptyMapValueIteratorVTable, }; diff --git a/cel-c/internal/message_equality.cc b/cel-c/internal/message_equality.cc index 409c6b2..19777bf 100644 --- a/cel-c/internal/message_equality.cc +++ b/cel-c/internal/message_equality.cc @@ -1013,11 +1013,12 @@ extern "C" _cel_MessageEquality _cel_Message_Equals( CEL_ASSERT_NOT_NULL(alloc); _cel_MessageEqualityState state = { - .def_pool = def_pool, - .wkts = wkts, - .alloc = alloc, - .arena = cel_nullptr, - .depth = 100, + /*def_pool=*/def_pool, + /*wkts=*/wkts, + /*alloc=*/alloc, + /*arena=*/cel_nullptr, + /*result=*/{}, + /*depth=*/100, }; _cel_MessageEqualityState* volatile state_ptr = &state; if (_cel_setjmp(state_ptr->jmp)) { @@ -1046,11 +1047,12 @@ extern "C" _cel_MessageEquality _cel_MessageField_Equals( CEL_ASSERT_NOT_NULL(alloc); _cel_MessageEqualityState state = { - .def_pool = def_pool, - .wkts = wkts, - .alloc = alloc, - .arena = cel_nullptr, - .depth = 100, + /*def_pool=*/def_pool, + /*wkts=*/wkts, + /*alloc=*/alloc, + /*arena=*/cel_nullptr, + /*result=*/{}, + /*depth=*/100, }; _cel_MessageEqualityState* volatile state_ptr = &state; if (_cel_setjmp(state_ptr->jmp)) { diff --git a/cel-c/internal/mutable_list_value.cc b/cel-c/internal/mutable_list_value.cc index b07a776..37a30b4 100644 --- a/cel-c/internal/mutable_list_value.cc +++ b/cel-c/internal/mutable_list_value.cc @@ -241,11 +241,11 @@ static cel_ListValueIterator* cel_nullable _cel_MutableListValue_NewIterator( } extern "C" const cel_ListValueVTable _cel_MutableListValueVTable = { - .Equals = cel_nullptr, - .FastSize = &_cel_MutableListValue_FastSize, - .SlowSize = &_cel_MutableListValue_SlowSize, - .Get = &_cel_MutableListValue_Get, - .NewIterator = &_cel_MutableListValue_NewIterator, + /*Equals=*/cel_nullptr, + /*FastSize=*/&_cel_MutableListValue_FastSize, + /*SlowSize=*/&_cel_MutableListValue_SlowSize, + /*Get=*/&_cel_MutableListValue_Get, + /*NewIterator=*/&_cel_MutableListValue_NewIterator, }; static void _cel_MutableListValueIterator_Delete( @@ -355,12 +355,12 @@ static bool _cel_MutableListValueIterator_Next( } const cel_ListValueIteratorVTable _cel_MutableListValueIteratorVTable = { - .super = - { - .Delete = &_cel_MutableListValueIterator_Delete, - .Next1 = &_cel_MutableListValueIterator_Next1, - .Next2 = &_cel_MutableListValueIterator_Next2, - .Remaining = &_cel_MutableListValueIterator_Remaining, - }, - .Next = &_cel_MutableListValueIterator_Next, + /*super=*/ + { + /*Delete=*/&_cel_MutableListValueIterator_Delete, + /*Next1=*/&_cel_MutableListValueIterator_Next1, + /*Next2=*/&_cel_MutableListValueIterator_Next2, + /*Remaining=*/&_cel_MutableListValueIterator_Remaining, + }, + /*Next=*/&_cel_MutableListValueIterator_Next, }; diff --git a/cel-c/internal/mutable_map_value.cc b/cel-c/internal/mutable_map_value.cc index 4664fff..b4a8526 100644 --- a/cel-c/internal/mutable_map_value.cc +++ b/cel-c/internal/mutable_map_value.cc @@ -412,13 +412,13 @@ static cel_MapValueIterator* cel_nullable _cel_MutableMapValue_NewIterator( } extern "C" const cel_MapValueVTable _cel_MutableMapValueVTable = { - .Equals = cel_nullptr, - .FastSize = &_cel_MutableMapValue_FastSize, - .SlowSize = &_cel_MutableMapValue_SlowSize, - .Get = &_cel_MutableMapValue_Get, - .Find = &_cel_MutableMapValue_Find, - .Has = &_cel_MutableMapValue_Has, - .NewIterator = &_cel_MutableMapValue_NewIterator, + /*Equals=*/cel_nullptr, + /*FastSize=*/&_cel_MutableMapValue_FastSize, + /*SlowSize=*/&_cel_MutableMapValue_SlowSize, + /*Get=*/&_cel_MutableMapValue_Get, + /*Find=*/&_cel_MutableMapValue_Find, + /*Has=*/&_cel_MutableMapValue_Has, + /*NewIterator=*/&_cel_MutableMapValue_NewIterator, }; static void _cel_MutableMapValueIterator_Delete( @@ -541,12 +541,12 @@ static bool _cel_MutableMapValueIterator_Next( } const cel_MapValueIteratorVTable _cel_MutableMapValueIteratorVTable = { - .super = - { - .Delete = &_cel_MutableMapValueIterator_Delete, - .Next1 = &_cel_MutableMapValueIterator_Next1, - .Next2 = &_cel_MutableMapValueIterator_Next2, - .Remaining = &_cel_MutableMapValueIterator_Remaining, - }, - .Next = &_cel_MutableMapValueIterator_Next, + /*super=*/ + { + /*Delete=*/&_cel_MutableMapValueIterator_Delete, + /*Next1=*/&_cel_MutableMapValueIterator_Next1, + /*Next2=*/&_cel_MutableMapValueIterator_Next2, + /*Remaining=*/&_cel_MutableMapValueIterator_Remaining, + }, + /*Next=*/&_cel_MutableMapValueIterator_Next, }; diff --git a/cel-c/internal/optional_value.cc b/cel-c/internal/optional_value.cc index f456992..e3625af 100644 --- a/cel-c/internal/optional_value.cc +++ b/cel-c/internal/optional_value.cc @@ -446,113 +446,113 @@ static bool _cel_OptionalValue_Value( const cel_OptionalValueVTable _cel_OptionalValueVTables[11] = { // _cel_EmptyOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_EmptyOptionalValue_HasValue, - .Value = &_cel_EmptyOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_EmptyOptionalValue_HasValue, + /*Value=*/&_cel_EmptyOptionalValue_Value, }, // _cel_NullOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_NullOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_NullOptionalValue_Value, }, // _cel_BoolOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_BoolOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_BoolOptionalValue_Value, }, // _cel_IntOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_IntOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_IntOptionalValue_Value, }, // _cel_UintOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_UintOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_UintOptionalValue_Value, }, // _cel_DoubleOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_DoubleOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_DoubleOptionalValue_Value, }, // _cel_BytesOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_BytesOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_BytesOptionalValue_Value, }, // _cel_StringOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_StringOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_StringOptionalValue_Value, }, // _cel_DurationOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_DurationOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_DurationOptionalValue_Value, }, // _cel_TimestampOptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_TimestampOptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_TimestampOptionalValue_Value, }, // _cel_OptionalValueVTable { - .super = - { - .Equals = &_cel_OptionalValue_Equals, - .TypeName = &_cel_OptionalValue_TypeName, - }, - .HasValue = &_cel_OptionalValue_HasValue, - .Value = &_cel_OptionalValue_Value, + /*super=*/ + { + /*Equals=*/&_cel_OptionalValue_Equals, + /*TypeName=*/&_cel_OptionalValue_TypeName, + }, + /*HasValue=*/&_cel_OptionalValue_HasValue, + /*Value=*/&_cel_OptionalValue_Value, }, }; diff --git a/cel-c/internal/parsed_map_field_value.cc b/cel-c/internal/parsed_map_field_value.cc index 1050064..5f9a8e2 100644 --- a/cel-c/internal/parsed_map_field_value.cc +++ b/cel-c/internal/parsed_map_field_value.cc @@ -301,13 +301,13 @@ static cel_MapValueIterator* cel_nullable _cel_ParsedMapFieldValue_NewIterator( } extern "C" const cel_MapValueVTable _cel_ParsedMapFieldValueVTable = { - .Equals = &_cel_ParsedMapFieldValue_Equals, - .FastSize = &_cel_ParsedMapFieldValue_FastSize, - .SlowSize = &_cel_ParsedMapFieldValue_SlowSize, - .Get = &_cel_ParsedMapFieldValue_Get, - .Find = &_cel_ParsedMapFieldValue_Find, - .Has = &_cel_ParsedMapFieldValue_Has, - .NewIterator = &_cel_ParsedMapFieldValue_NewIterator, + /*Equals=*/&_cel_ParsedMapFieldValue_Equals, + /*FastSize=*/&_cel_ParsedMapFieldValue_FastSize, + /*SlowSize=*/&_cel_ParsedMapFieldValue_SlowSize, + /*Get=*/&_cel_ParsedMapFieldValue_Get, + /*Find=*/&_cel_ParsedMapFieldValue_Find, + /*Has=*/&_cel_ParsedMapFieldValue_Has, + /*NewIterator=*/&_cel_ParsedMapFieldValue_NewIterator, }; static void _cel_ParsedMapFieldValueIterator_Delete( @@ -449,12 +449,12 @@ static bool _cel_ParsedMapFieldValueIterator_Next( } const cel_MapValueIteratorVTable _cel_ParsedMapFieldValueIteratorVTable = { - .super = - { - .Delete = &_cel_ParsedMapFieldValueIterator_Delete, - .Next1 = &_cel_ParsedMapFieldValueIterator_Next1, - .Next2 = &_cel_ParsedMapFieldValueIterator_Next2, - .Remaining = &_cel_ParsedMapFieldValueIterator_Remaining, - }, - .Next = &_cel_ParsedMapFieldValueIterator_Next, + /*super=*/ + { + /*Delete=*/&_cel_ParsedMapFieldValueIterator_Delete, + /*Next1=*/&_cel_ParsedMapFieldValueIterator_Next1, + /*Next2=*/&_cel_ParsedMapFieldValueIterator_Next2, + /*Remaining=*/&_cel_ParsedMapFieldValueIterator_Remaining, + }, + /*Next=*/&_cel_ParsedMapFieldValueIterator_Next, }; diff --git a/cel-c/internal/parsed_message_value.cc b/cel-c/internal/parsed_message_value.cc index fd69717..a2ff3c8 100644 --- a/cel-c/internal/parsed_message_value.cc +++ b/cel-c/internal/parsed_message_value.cc @@ -275,11 +275,11 @@ _cel_ParsedMessageValue_NewIterator( } extern "C" const cel_StructValueVTable _cel_ParsedMessageValueVTable = { - .Equals = &_cel_ParsedMessageValue_Equals, - .TypeName = &_cel_ParsedMessageValue_TypeName, - .Get = &_cel_ParsedMessageValue_Get, - .Has = &_cel_ParsedMessageValue_Has, - .NewIterator = &_cel_ParsedMessageValue_NewIterator, + /*Equals=*/&_cel_ParsedMessageValue_Equals, + /*TypeName=*/&_cel_ParsedMessageValue_TypeName, + /*Get=*/&_cel_ParsedMessageValue_Get, + /*Has=*/&_cel_ParsedMessageValue_Has, + /*NewIterator=*/&_cel_ParsedMessageValue_NewIterator, }; static void _cel_ParsedMessageValueIterator_Delete( @@ -342,7 +342,7 @@ static bool _cel_ParsedMessageValueIterator_Remaining( } const cel_StructValueIteratorVTable _cel_ParsedMessageValueIteratorVTable = { - .Delete = &_cel_ParsedMessageValueIterator_Delete, - .Next = &_cel_ParsedMessageValueIterator_Next, - .Remaining = &_cel_ParsedMessageValueIterator_Remaining, + /*Delete=*/&_cel_ParsedMessageValueIterator_Delete, + /*Next=*/&_cel_ParsedMessageValueIterator_Next, + /*Remaining=*/&_cel_ParsedMessageValueIterator_Remaining, }; diff --git a/cel-c/internal/parsed_repeated_field_value.cc b/cel-c/internal/parsed_repeated_field_value.cc index d2bcee0..d006b88 100644 --- a/cel-c/internal/parsed_repeated_field_value.cc +++ b/cel-c/internal/parsed_repeated_field_value.cc @@ -193,11 +193,11 @@ _cel_ParsedRepeatedFieldValue_NewIterator( } extern "C" const cel_ListValueVTable _cel_ParsedRepeatedFieldValueVTable = { - .Equals = &_cel_ParsedRepeatedFieldValue_Equals, - .FastSize = &_cel_ParsedRepeatedFieldValue_FastSize, - .SlowSize = &_cel_ParsedRepeatedFieldValue_SlowSize, - .Get = &_cel_ParsedRepeatedFieldValue_Get, - .NewIterator = &_cel_ParsedRepeatedFieldValue_NewIterator, + /*Equals=*/&_cel_ParsedRepeatedFieldValue_Equals, + /*FastSize=*/&_cel_ParsedRepeatedFieldValue_FastSize, + /*SlowSize=*/&_cel_ParsedRepeatedFieldValue_SlowSize, + /*Get=*/&_cel_ParsedRepeatedFieldValue_Get, + /*NewIterator=*/&_cel_ParsedRepeatedFieldValue_NewIterator, }; static void _cel_ParsedRepeatedFieldValueIterator_Delete( @@ -328,12 +328,12 @@ static bool _cel_ParsedRepeatedFieldValueIterator_Next( const cel_ListValueIteratorVTable _cel_ParsedRepeatedFieldValueIteratorVTable = { - .super = - { - .Delete = &_cel_ParsedRepeatedFieldValueIterator_Delete, - .Next1 = &_cel_ParsedRepeatedFieldValueIterator_Next1, - .Next2 = &_cel_ParsedRepeatedFieldValueIterator_Next2, - .Remaining = &_cel_ParsedRepeatedFieldValueIterator_Remaining, - }, - .Next = &_cel_ParsedRepeatedFieldValueIterator_Next, + /*super=*/ + { + /*Delete=*/&_cel_ParsedRepeatedFieldValueIterator_Delete, + /*Next1=*/&_cel_ParsedRepeatedFieldValueIterator_Next1, + /*Next2=*/&_cel_ParsedRepeatedFieldValueIterator_Next2, + /*Remaining=*/&_cel_ParsedRepeatedFieldValueIterator_Remaining, + }, + /*Next=*/&_cel_ParsedRepeatedFieldValueIterator_Next, }; diff --git a/cel-c/internal/runtime/interpreter.cc b/cel-c/internal/runtime/interpreter.cc index 39512c5..b604dd0 100644 --- a/cel-c/internal/runtime/interpreter.cc +++ b/cel-c/internal/runtime/interpreter.cc @@ -1838,41 +1838,94 @@ static void _cel_Interpreter_PostVisitBindExprBound( } static const cel_AstVisitorVTable _cel_InterpreterVTable = { - .PreVisitExpr = &_cel_Interpreter_PreVisitExpr, - .VisitUnspecifiedExpr = &_cel_Interpreter_VisitUnspecifiedExpr, - .VisitIdentExpr = &_cel_Interpreter_VisitIdentExpr, - .VisitConstExpr = &_cel_Interpreter_VisitConstExpr, - .PreVisitSelectExpr = &_cel_Interpreter_PreVisitSelectExpr, - .PostVisitSelectExpr = &_cel_Interpreter_PostVisitSelectExpr, - .PreVisitUnaryExpr = &_cel_Interpreter_PreVisitUnaryExpr, - .PostVisitUnaryExpr = &_cel_Interpreter_PostVisitUnaryExpr, - .PreVisitBinaryExpr = &_cel_Interpreter_PreVisitBinaryExpr, - .PostVisitBinaryExpr = &_cel_Interpreter_PostVisitBinaryExpr, - .PostVisitBinaryExprLeft = &_cel_Interpreter_PostVisitBinaryExprLeft, - .PreVisitTernaryExpr = &_cel_Interpreter_PreVisitTernaryExpr, - .PostVisitTernaryExpr = &_cel_Interpreter_PostVisitTernaryExpr, - .PostVisitTernaryExprCondition = - &_cel_Interpreter_PostVisitTernaryExprCondition, - .PostVisitTernaryExprIfTrue = &_cel_Interpreter_PostVisitTernaryExprIfTrue, - .PreVisitCallArgExpr = &_cel_Interpreter_PreVisitCallArgExpr, - .PostVisitCallExpr = &_cel_Interpreter_PostVisitCallExpr, - .PreVisitListElementExpr = &_cel_Interpreter_PreVisitListElementExpr, - .PostVisitListElementExpr = &_cel_Interpreter_PostVisitListElementExpr, - .PreVisitListExpr = &_cel_Interpreter_PreVisitListExpr, - .PostVisitListExpr = &_cel_Interpreter_PostVisitListExpr, - .PreVisitMapEntryExpr = &_cel_Interpreter_PreVisitMapEntryExpr, - .PostVisitMapEntryExprKey = &_cel_Interpreter_PostVisitMapEntryExprKey, - .PostVisitMapEntryExprValue = &_cel_Interpreter_PostVisitMapEntryExprValue, - .PreVisitMapExpr = &_cel_Interpreter_PreVisitMapExpr, - .PostVisitMapExpr = &_cel_Interpreter_PostVisitMapExpr, - .PreVisitComprehensionExpr = &_cel_Interpreter_PreVisitComprehensionExpr, - .PostVisitComprehensionExpr = &_cel_Interpreter_PostVisitComprehensionExpr, - .PreVisitBindExpr = &_cel_Interpreter_PreVisitBindExpr, - .PostVisitBindExpr = &_cel_Interpreter_PostVisitBindExpr, - .PreVisitBindExprBinding = &_cel_Interpreter_PreVisitBindExprBinding, - .PostVisitBindExprBinding = &_cel_Interpreter_PostVisitBindExprBinding, - .PreVisitBindExprBound = &_cel_Interpreter_PreVisitBindExprBound, - .PostVisitBindExprBound = &_cel_Interpreter_PostVisitBindExprBound, + /*PreVisitExpr=*/&_cel_Interpreter_PreVisitExpr, + /*PostVisitExpr=*/cel_nullptr, + /*VisitUnspecifiedExpr=*/&_cel_Interpreter_VisitUnspecifiedExpr, + /*VisitIdentExpr=*/&_cel_Interpreter_VisitIdentExpr, + /*VisitConstExpr=*/&_cel_Interpreter_VisitConstExpr, + /*PreVisitSelectExpr=*/&_cel_Interpreter_PreVisitSelectExpr, + /*PostVisitSelectExpr=*/&_cel_Interpreter_PostVisitSelectExpr, + /*PreVisitSelectExprOperand=*/cel_nullptr, + /*PostVisitSelectExprOperand=*/cel_nullptr, + /*PreVisitUnaryExpr=*/&_cel_Interpreter_PreVisitUnaryExpr, + /*PostVisitUnaryExpr=*/&_cel_Interpreter_PostVisitUnaryExpr, + /*PreVisitUnaryExprArg=*/cel_nullptr, + /*PostVisitUnaryExprArg=*/cel_nullptr, + /*PreVisitBinaryExpr=*/&_cel_Interpreter_PreVisitBinaryExpr, + /*PostVisitBinaryExpr=*/&_cel_Interpreter_PostVisitBinaryExpr, + /*PreVisitBinaryExprLeft=*/cel_nullptr, + /*PostVisitBinaryExprLeft=*/&_cel_Interpreter_PostVisitBinaryExprLeft, + /*PreVisitBinaryExprRight=*/cel_nullptr, + /*PostVisitBinaryExprRight=*/cel_nullptr, + /*PreVisitTernaryExpr=*/&_cel_Interpreter_PreVisitTernaryExpr, + /*PostVisitTernaryExpr=*/&_cel_Interpreter_PostVisitTernaryExpr, + /*PreVisitTernaryExprCondition=*/cel_nullptr, + /*PostVisitTernaryExprCondition=*/ + &_cel_Interpreter_PostVisitTernaryExprCondition, + /*PreVisitTernaryExprIfTrue=*/cel_nullptr, + /*PostVisitTernaryExprIfTrue=*/&_cel_Interpreter_PostVisitTernaryExprIfTrue, + /*PreVisitTernaryExprIfFalse=*/cel_nullptr, + /*PostVisitTernaryExprIfFalse=*/cel_nullptr, + /*PreVisitCallArgExpr=*/&_cel_Interpreter_PreVisitCallArgExpr, + /*PostVisitCallArgExpr=*/cel_nullptr, + /*PreVisitCallArgExprValue=*/cel_nullptr, + /*PostVisitCallArgExprValue=*/cel_nullptr, + /*PreVisitCallExpr=*/cel_nullptr, + /*PostVisitCallExpr=*/&_cel_Interpreter_PostVisitCallExpr, + /*PreVisitCallExprTarget=*/cel_nullptr, + /*PostVisitCallExprTarget=*/cel_nullptr, + /*PreVisitListElementExpr=*/&_cel_Interpreter_PreVisitListElementExpr, + /*PostVisitListElementExpr=*/&_cel_Interpreter_PostVisitListElementExpr, + /*PreVisitListElementExprValue=*/cel_nullptr, + /*PostVisitListElementExprValue=*/cel_nullptr, + /*PreVisitListExpr=*/&_cel_Interpreter_PreVisitListExpr, + /*PostVisitListExpr=*/&_cel_Interpreter_PostVisitListExpr, + /*PreVisitMapEntryExpr=*/&_cel_Interpreter_PreVisitMapEntryExpr, + /*PostVisitMapEntryExpr=*/cel_nullptr, + /*PreVisitMapEntryExprKey=*/cel_nullptr, + /*PostVisitMapEntryExprKey=*/&_cel_Interpreter_PostVisitMapEntryExprKey, + /*PreVisitMapEntryExprValue=*/cel_nullptr, + /*PostVisitMapEntryExprValue=*/&_cel_Interpreter_PostVisitMapEntryExprValue, + /*PreVisitMapExpr=*/&_cel_Interpreter_PreVisitMapExpr, + /*PostVisitMapExpr=*/&_cel_Interpreter_PostVisitMapExpr, + /*PreVisitStructFieldExpr=*/cel_nullptr, + /*PostVisitStructFieldExpr=*/cel_nullptr, + /*PreVisitStructFieldExprValue=*/cel_nullptr, + /*PostVisitStructFieldExprValue=*/cel_nullptr, + /*PreVisitStructExpr=*/cel_nullptr, + /*PostVisitStructExpr=*/cel_nullptr, + /*PreVisitComprehensionExpr=*/&_cel_Interpreter_PreVisitComprehensionExpr, + /*PostVisitComprehensionExpr=*/&_cel_Interpreter_PostVisitComprehensionExpr, + /*PreVisitComprehensionExprIterRange=*/cel_nullptr, + /*PostVisitComprehensionExprIterRange=*/cel_nullptr, + /*PreVisitComprehensionExprAccuInit=*/cel_nullptr, + /*PostVisitComprehensionExprAccuInit=*/cel_nullptr, + /*PreVisitComprehensionExprLoopCondition=*/cel_nullptr, + /*PostVisitComprehensionExprLoopCondition=*/cel_nullptr, + /*PreVisitComprehensionExprLoopStep=*/cel_nullptr, + /*PostVisitComprehensionExprLoopStep=*/cel_nullptr, + /*PreVisitComprehensionExprResult=*/cel_nullptr, + /*PostVisitComprehensionExprResult=*/cel_nullptr, + /*PreVisitBindExpr=*/&_cel_Interpreter_PreVisitBindExpr, + /*PostVisitBindExpr=*/&_cel_Interpreter_PostVisitBindExpr, + /*PreVisitBindExprBinding=*/&_cel_Interpreter_PreVisitBindExprBinding, + /*PostVisitBindExprBinding=*/&_cel_Interpreter_PostVisitBindExprBinding, + /*PreVisitBindExprBound=*/&_cel_Interpreter_PreVisitBindExprBound, + /*PostVisitBindExprBound=*/&_cel_Interpreter_PostVisitBindExprBound, + /*VisitBlockIndexExpr=*/cel_nullptr, + /*PreVisitBlockBindingExpr=*/cel_nullptr, + /*PostVisitBlockBindingExpr=*/cel_nullptr, + /*PreVisitBlockBindingExprBound=*/cel_nullptr, + /*PostVisitBlockBindingExprBound=*/cel_nullptr, + /*PreVisitBlockExpr=*/cel_nullptr, + /*PostVisitBlockExpr=*/cel_nullptr, + /*PreVisitBlockExprBound=*/cel_nullptr, + /*PostVisitBlockExprBound=*/cel_nullptr, + /*VisitAttrQualExpr=*/cel_nullptr, + /*PreVisitAttrExpr=*/cel_nullptr, + /*PostVisitAttrExpr=*/cel_nullptr, + /*PreVisitAttrExprOperand=*/cel_nullptr, + /*PostVisitAttrExprOperand=*/cel_nullptr, }; static size_t _cel_Interpreter_StringViewHasher(const void* cel_nonnull key) { diff --git a/cel-c/internal/testing/compiler.cc b/cel-c/internal/testing/compiler.cc index 8d1867d..6d50d32 100644 --- a/cel-c/internal/testing/compiler.cc +++ b/cel-c/internal/testing/compiler.cc @@ -42,13 +42,12 @@ extern "C" CEL_ATTRIBUTE_NOTHROW _cel_TestingCompiler* cel_nonnull _cel_TestingCompiler_New() { + cel::CompilerOptions compiler_options; + compiler_options.parser_options.enable_optional_syntax = true; + compiler_options.checker_options.enable_cross_numeric_comparisons = true; + compiler_options.checker_options.update_struct_type_names = true; auto status_or_compiler_builder = cel::NewCompilerBuilder( - cel::internal::GetTestingDescriptorPool(), - cel::CompilerOptions{ - .parser_options = cel::ParserOptions{.enable_optional_syntax = true}, - .checker_options = - cel::CheckerOptions{.enable_cross_numeric_comparisons = true, - .update_struct_type_names = true}}); + cel::internal::GetTestingDescriptorPool(), compiler_options); ABSL_CHECK_OK(status_or_compiler_builder); auto compiler_builder = std::move(*status_or_compiler_builder); ABSL_CHECK_OK(compiler_builder->AddLibrary(cel::StandardCheckerLibrary())); diff --git a/cel-c/internal/testing/parser.cc b/cel-c/internal/testing/parser.cc index 5720f1e..b4ed3dc 100644 --- a/cel-c/internal/testing/parser.cc +++ b/cel-c/internal/testing/parser.cc @@ -42,8 +42,9 @@ extern "C" CEL_ATTRIBUTE_NOTHROW _cel_TestingParser* cel_nonnull _cel_TestingParser_New() { - auto parser_builder = - cel::NewParserBuilder(cel::ParserOptions{.enable_optional_syntax = true}); + cel::ParserOptions parser_options; + parser_options.enable_optional_syntax = true; + auto parser_builder = cel::NewParserBuilder(parser_options); for (const cel::Macro& macro : cel::extensions::bindings_macros()) { ABSL_CHECK_OK(parser_builder->AddMacro(macro)); } diff --git a/cel-c/internal/value.cc b/cel-c/internal/value.cc index 31efab0..f1b91e1 100644 --- a/cel-c/internal/value.cc +++ b/cel-c/internal/value.cc @@ -44,30 +44,29 @@ #define _cel_kDoubleToUintMax ((double)(uint64_t)UINT64_MAX) extern "C" const cel_Value cel_NullValue = { - .data = - { - .v = {(char)0}, - }, - .kind = cel_ValueKind_kNull, - .padding = {(char)0}, + /*data=*/{/*v=*/{(char)0}}, + /*kind=*/cel_ValueKind_kNull, + /*padding=*/{(char)0}, }; +// `cel_Value::data` is a union whose first member is `v` (`char[24]`). Standard +// C++17 aggregate initialization can only initialize the first member of a +// union, so `cel_FalseValue` and `cel_TrueValue` initialize `data.bl` through +// its object representation: a `bool` occupies the first byte of `data` and is +// represented as `0` (false) or `1` (true), with the remaining bytes zeroed. +// This produces exactly the same bytes as designating `data.bl` directly. +CEL_STATIC_ASSERT(sizeof(bool) == 1); + extern "C" const cel_Value cel_FalseValue = { - .data = - { - .bl = false, - }, - .kind = cel_ValueKind_kBool, - .padding = {(char)0}, + /*data=*/{/*v=*/{(char)false}}, + /*kind=*/cel_ValueKind_kBool, + /*padding=*/{(char)0}, }; extern "C" const cel_Value cel_TrueValue = { - .data = - { - .bl = true, - }, - .kind = cel_ValueKind_kBool, - .padding = {(char)0}, + /*data=*/{/*v=*/{(char)true}}, + /*kind=*/cel_ValueKind_kBool, + /*padding=*/{(char)0}, }; extern "C" cel_StringView cel_Value_TypeName( diff --git a/cel-c/operators.cc b/cel-c/operators.cc index 1ffbaa5..0480ad7 100644 --- a/cel-c/operators.cc +++ b/cel-c/operators.cc @@ -29,24 +29,24 @@ typedef struct { static const cel_OpData cel_kUnaryOpData[] = { { - .string = CEL_STRINGVIEW_C(""), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 0, + /*string=*/CEL_STRINGVIEW_C(""), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/0, }, { - .string = CEL_STRINGVIEW_C("!_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 2, + /*string=*/CEL_STRINGVIEW_C("!_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/2, }, { - .string = CEL_STRINGVIEW_C("-_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 2, + /*string=*/CEL_STRINGVIEW_C("-_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/2, }, { - .string = CEL_STRINGVIEW_C("@not_strictly_false"), - .alias = CEL_STRINGVIEW_C("__not_strictly_false__"), - .precedence = 0, + /*string=*/CEL_STRINGVIEW_C("@not_strictly_false"), + /*alias=*/CEL_STRINGVIEW_C("__not_strictly_false__"), + /*precedence=*/0, }, }; @@ -82,94 +82,94 @@ extern "C" int cel_UnaryOp_Precedence(cel_UnaryOp op) { static const cel_OpData cel_kBinaryOpData[] = { { - .string = CEL_STRINGVIEW_C(""), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 0, + /*string=*/CEL_STRINGVIEW_C(""), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/0, }, { - .string = CEL_STRINGVIEW_C("_&&_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 6, + /*string=*/CEL_STRINGVIEW_C("_&&_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/6, }, { - .string = CEL_STRINGVIEW_C("_||_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 7, + /*string=*/CEL_STRINGVIEW_C("_||_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/7, }, { - .string = CEL_STRINGVIEW_C("_==_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("_==_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_!=_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("_!=_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_<_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("_<_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_<=_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("_<=_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_>_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("_>_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_>=_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("_>=_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_+_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 4, + /*string=*/CEL_STRINGVIEW_C("_+_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/4, }, { - .string = CEL_STRINGVIEW_C("_-_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 4, + /*string=*/CEL_STRINGVIEW_C("_-_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/4, }, { - .string = CEL_STRINGVIEW_C("_*_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 3, + /*string=*/CEL_STRINGVIEW_C("_*_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/3, }, { - .string = CEL_STRINGVIEW_C("_/_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 3, + /*string=*/CEL_STRINGVIEW_C("_/_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/3, }, { - .string = CEL_STRINGVIEW_C("_%_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 3, + /*string=*/CEL_STRINGVIEW_C("_%_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/3, }, { - .string = CEL_STRINGVIEW_C("_[_]"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 1, + /*string=*/CEL_STRINGVIEW_C("_[_]"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/1, }, { - .string = CEL_STRINGVIEW_C("@in"), - .alias = CEL_STRINGVIEW_C("_in_"), - .precedence = 5, + /*string=*/CEL_STRINGVIEW_C("@in"), + /*alias=*/CEL_STRINGVIEW_C("_in_"), + /*precedence=*/5, }, { - .string = CEL_STRINGVIEW_C("_[?_]"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 0, + /*string=*/CEL_STRINGVIEW_C("_[?_]"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/0, }, { - .string = CEL_STRINGVIEW_C("_?._"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 0, + /*string=*/CEL_STRINGVIEW_C("_?._"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/0, }, }; @@ -205,14 +205,14 @@ extern "C" int cel_BinaryOp_Precedence(cel_BinaryOp op) { static const cel_OpData cel_kTernaryOpData[] = { { - .string = CEL_STRINGVIEW_C(""), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 0, + /*string=*/CEL_STRINGVIEW_C(""), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/0, }, { - .string = CEL_STRINGVIEW_C("_?_:_"), - .alias = CEL_STRINGVIEW_C(""), - .precedence = 8, + /*string=*/CEL_STRINGVIEW_C("_?_:_"), + /*alias=*/CEL_STRINGVIEW_C(""), + /*precedence=*/8, }, }; diff --git a/cel-c/source.h b/cel-c/source.h index 5245e3b..d992a0d 100644 --- a/cel-c/source.h +++ b/cel-c/source.h @@ -30,7 +30,8 @@ typedef struct { int32_t end; } cel_SourceRange; -#define cel_SourceRange(begin, end) ((cel_SourceRange){(begin), (end)}) +#define cel_SourceRange(begin, end) \ + (CEL_COMPOUND_LITERAL(cel_SourceRange){(begin), (end)}) CEL_ATTRIBUTE_NODISCARD static CEL_INLINE bool cel_SourceRange_Equals(cel_SourceRange lhs, diff --git a/cel-c/timestamp.h b/cel-c/timestamp.h index 5c8b120..2624ca6 100644 --- a/cel-c/timestamp.h +++ b/cel-c/timestamp.h @@ -61,28 +61,28 @@ CEL_BEGIN_DECLS #ifdef _CEL_IS_BIG_ENDIAN #define cel_Timestamp_kUnixEpoch \ - ((cel_Timestamp){{INT32_C(0), UINT32_C{0}}, INT32_C(0)}) + (CEL_COMPOUND_LITERAL(cel_Timestamp){{INT32_C(0), UINT32_C(0)}, INT32_C(0)}) #define cel_Timestamp_kMin \ - ((cel_Timestamp){ \ + (CEL_COMPOUND_LITERAL(cel_Timestamp){ \ {(int32_t)(uint32_t)(((uint64_t)cel_Timestamp_kMinSeconds) >> 32), \ ((uint32_t)(uint64_t)cel_Timestamp_kMinSeconds)}, \ cel_Timestamp_kMinNanos}) #define cel_Timestamp_kMax \ - ((cel_Timestamp){ \ + (CEL_COMPOUND_LITERAL(cel_Timestamp){ \ {(int32_t)(uint32_t)(((uint64_t)cel_Timestamp_kMaxSeconds) >> 32), \ ((uint32_t)(uint64_t)cel_Timestamp_kMaxSeconds)}, \ cel_Timestamp_kMaxNanos}) #endif #ifdef _CEL_IS_LITTLE_ENDIAN #define cel_Timestamp_kUnixEpoch \ - ((cel_Timestamp){{UINT32_C(0), INT32_C(0)}, INT32_C(0)}) + (CEL_COMPOUND_LITERAL(cel_Timestamp){{UINT32_C(0), INT32_C(0)}, INT32_C(0)}) #define cel_Timestamp_kMin \ - ((cel_Timestamp){ \ + (CEL_COMPOUND_LITERAL(cel_Timestamp){ \ {((uint32_t)(uint64_t)cel_Timestamp_kMinSeconds), \ (int32_t)(uint32_t)(((uint64_t)cel_Timestamp_kMinSeconds) >> 32)}, \ cel_Timestamp_kMinNanos}) #define cel_Timestamp_kMax \ - ((cel_Timestamp){ \ + (CEL_COMPOUND_LITERAL(cel_Timestamp){ \ {((uint32_t)(uint64_t)cel_Timestamp_kMaxSeconds), \ (int32_t)(uint32_t)(((uint64_t)cel_Timestamp_kMaxSeconds) >> 32)}, \ cel_Timestamp_kMaxNanos}) diff --git a/cel-c/type.cc b/cel-c/type.cc index 10cc62a..9e33ae8 100644 --- a/cel-c/type.cc +++ b/cel-c/type.cc @@ -178,123 +178,123 @@ extern "C" bool cel_IsWellKnownEnumTypeName(cel_StringView name) { } static const cel_Type _cel_DynType = { - .kind = cel_TypeKind_kDyn, + {{/*kind=*/cel_TypeKind_kDyn}}, }; extern "C" const cel_Type* const cel_nonnull cel_DynType = &_cel_DynType; static const cel_Type _cel_NullType = { - .kind = cel_TypeKind_kNull, + {{/*kind=*/cel_TypeKind_kNull}}, }; extern "C" const cel_Type* const cel_nonnull cel_NullType = &_cel_NullType; static const cel_Type _cel_BoolType = { - .kind = cel_TypeKind_kBool, + {{/*kind=*/cel_TypeKind_kBool}}, }; extern "C" const cel_Type* const cel_nonnull cel_BoolType = &_cel_BoolType; static const cel_Type _cel_IntType = { - .kind = cel_TypeKind_kInt, + {{/*kind=*/cel_TypeKind_kInt}}, }; extern "C" const cel_Type* const cel_nonnull cel_IntType = &_cel_IntType; static const cel_Type _cel_UintType = { - .kind = cel_TypeKind_kUint, + {{/*kind=*/cel_TypeKind_kUint}}, }; extern "C" const cel_Type* const cel_nonnull cel_UintType = &_cel_UintType; static const cel_Type _cel_DoubleType = { - .kind = cel_TypeKind_kDouble, + {{/*kind=*/cel_TypeKind_kDouble}}, }; extern "C" const cel_Type* const cel_nonnull cel_DoubleType = &_cel_DoubleType; static const cel_Type _cel_StringType = { - .kind = cel_TypeKind_kString, + {{/*kind=*/cel_TypeKind_kString}}, }; extern "C" const cel_Type* const cel_nonnull cel_StringType = &_cel_StringType; static const cel_Type _cel_BytesType = { - .kind = cel_TypeKind_kBytes, + {{/*kind=*/cel_TypeKind_kBytes}}, }; extern "C" const cel_Type* const cel_nonnull cel_BytesType = &_cel_BytesType; static const cel_Type _cel_AnyType = { - .kind = cel_TypeKind_kAny, + {{/*kind=*/cel_TypeKind_kAny}}, }; extern "C" const cel_Type* const cel_nonnull cel_AnyType = &_cel_AnyType; static const cel_Type _cel_DurationType = { - .kind = cel_TypeKind_kDuration, + {{/*kind=*/cel_TypeKind_kDuration}}, }; extern "C" const cel_Type* const cel_nonnull cel_DurationType = &_cel_DurationType; static const cel_Type _cel_TimestampType = { - .kind = cel_TypeKind_kTimestamp, + {{/*kind=*/cel_TypeKind_kTimestamp}}, }; extern "C" const cel_Type* const cel_nonnull cel_TimestampType = &_cel_TimestampType; static const cel_Type _cel_UnknownType = { - .kind = cel_TypeKind_kUnknown, + {{/*kind=*/cel_TypeKind_kUnknown}}, }; extern "C" const cel_Type* const cel_nonnull cel_UnknownType = &_cel_UnknownType; static const cel_Type _cel_ErrorType = { - .kind = cel_TypeKind_kError, + {{/*kind=*/cel_TypeKind_kError}}, }; extern "C" const cel_Type* const cel_nonnull cel_ErrorType = &_cel_ErrorType; static const cel_Type _cel_BoolWrapperType = { - .kind = cel_TypeKind_kBoolWrapper, + {{/*kind=*/cel_TypeKind_kBoolWrapper}}, }; extern "C" const cel_Type* const cel_nonnull cel_BoolWrapperType = &_cel_BoolWrapperType; static const cel_Type _cel_IntWrapperType = { - .kind = cel_TypeKind_kIntWrapper, + {{/*kind=*/cel_TypeKind_kIntWrapper}}, }; extern "C" const cel_Type* const cel_nonnull cel_IntWrapperType = &_cel_IntWrapperType; static const cel_Type _cel_UintWrapperType = { - .kind = cel_TypeKind_kUintWrapper, + {{/*kind=*/cel_TypeKind_kUintWrapper}}, }; extern "C" const cel_Type* const cel_nonnull cel_UintWrapperType = &_cel_UintWrapperType; static const cel_Type _cel_DoubleWrapperType = { - .kind = cel_TypeKind_kDoubleWrapper, + {{/*kind=*/cel_TypeKind_kDoubleWrapper}}, }; extern "C" const cel_Type* const cel_nonnull cel_DoubleWrapperType = &_cel_DoubleWrapperType; static const cel_Type _cel_StringWrapperType = { - .kind = cel_TypeKind_kStringWrapper, + {{/*kind=*/cel_TypeKind_kStringWrapper}}, }; extern "C" const cel_Type* const cel_nonnull cel_StringWrapperType = &_cel_StringWrapperType; static const cel_Type _cel_BytesWrapperType = { - .kind = cel_TypeKind_kBytesWrapper, + {{/*kind=*/cel_TypeKind_kBytesWrapper}}, }; extern "C" const cel_Type* const cel_nonnull cel_BytesWrapperType = diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 47d50a7..fb710bd 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -26,6 +26,12 @@ steps: - '...' - '--enable_bzlmod' - '--copt=-Wno-deprecated-declarations' + # Designated initializers are C++20; MSVC rejects them with /std:c++17. + # Reject them in non-test cel-c C++ sources (clang only; GCC lacks the flag). + # google3 builds cel-c as C++20 and cannot detect this, so this step is the + # guard. External sources are excluded by both label (@@repo//...) and exec + # path (external/...), since Bazel applies the copt if either one matches. + - '--per_file_copt=\.cc$,-^@,-^external/,-_test\.cc$@-Werror=c++20-designator,-Werror=c99-designator' - '--compilation_mode=fastbuild' - '--test_output=errors' - '--show_timestamps'