diff options
author | George Wangensteen <george.wangensteen@mongodb.com> | 2022-07-28 13:45:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-28 14:51:50 +0000 |
commit | 0ee599ffdf49064e2d29368810d7ee9eb9eee6a3 (patch) | |
tree | 9b575b339220fcb470ce3c4092ce947af4768328 /buildscripts | |
parent | 22bc6ca8fc701670a556f2e5a1253e93cff41f23 (diff) | |
download | mongo-0ee599ffdf49064e2d29368810d7ee9eb9eee6a3.tar.gz |
SERVER-67649 Teach IDL reply types to ignore generic fields
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/idl/idl/ast.py | 1 | ||||
-rw-r--r-- | buildscripts/idl/idl/binder.py | 1 | ||||
-rw-r--r-- | buildscripts/idl/idl/generator.py | 35 | ||||
-rw-r--r-- | buildscripts/idl/idl/parser.py | 1 | ||||
-rw-r--r-- | buildscripts/idl/idl/syntax.py | 1 |
5 files changed, 34 insertions, 5 deletions
diff --git a/buildscripts/idl/idl/ast.py b/buildscripts/idl/idl/ast.py index 63cb4502039..840ee8689da 100644 --- a/buildscripts/idl/idl/ast.py +++ b/buildscripts/idl/idl/ast.py @@ -145,6 +145,7 @@ class Struct(common.SourceLocation): self.allow_global_collection_name = False # type: bool self.non_const_getter = False # type: bool self.cpp_validator_func = None # type: str + self.is_command_reply = False # type: bool super(Struct, self).__init__(file_name, line, column) diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py index 56cb2a53636..e50e8322410 100644 --- a/buildscripts/idl/idl/binder.py +++ b/buildscripts/idl/idl/binder.py @@ -271,6 +271,7 @@ def _bind_struct_common(ctxt, parsed_spec, struct, ast_struct): ast_struct.qualified_cpp_name = _get_struct_qualified_cpp_name(struct) ast_struct.allow_global_collection_name = struct.allow_global_collection_name ast_struct.non_const_getter = struct.non_const_getter + ast_struct.is_command_reply = struct.is_command_reply # Validate naming restrictions if ast_struct.name.startswith("array<"): diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index f48fd3542d2..b4a996a17a2 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -36,7 +36,7 @@ import re import sys import textwrap from abc import ABCMeta, abstractmethod -from typing import Dict, Iterable, List, Mapping, Tuple, Union +from typing import Dict, Iterable, List, Mapping, Tuple, Union, cast from . import (ast, bson, common, cpp_types, enum_types, generic_field_list_types, struct_types, writer) @@ -589,6 +589,12 @@ class _CppHeaderFileWriter(_CppFileWriterBase): set_has = f'{_get_has_field_member_name(field)} = true;' if is_serial else '' self._writer.write_line(f'void {memfn}({param_type} value) {{ {body} {set_has} }}') + def gen_constexpr_getters(self): + # type: () -> None + """Generate the getters for constexpr data.""" + self._writer.write_line( + 'constexpr bool getIsCommandReply() const { return _isCommandReply; }') + def gen_member(self, field): # type: (ast.Field) -> None """Generate the C++ class member definition for a field.""" @@ -609,6 +615,12 @@ class _CppHeaderFileWriter(_CppFileWriterBase): else: self._writer.write_line('%s %s;' % (member_type, member_name)) + def gen_constexpr_members(self, struct): + # type: (ast.Struct) -> None + """Generate the C++ class member definition for constexpr data.""" + cpp_string_val = "true" if struct.is_command_reply else "false" + self._writer.write_line(f'static constexpr bool _isCommandReply{{{cpp_string_val}}};') + def gen_serializer_member(self, field): # type: (ast.Field) -> None """Generate the C++ class bool has_<field> member definition for a field.""" @@ -1038,10 +1050,9 @@ class _CppHeaderFileWriter(_CppFileWriterBase): self.gen_enum_functions(idl_enum) self._writer.write_empty_line() - spec_and_structs = spec.structs - spec_and_structs += spec.commands + all_structs = spec.structs + cast(List[ast.Struct], spec.commands) - for struct in spec_and_structs: + for struct in all_structs: self.gen_description_comment(struct.description) with self.gen_class_declaration_block(struct.cpp_name): self.write_unindented_line('public:') @@ -1078,6 +1089,11 @@ class _CppHeaderFileWriter(_CppFileWriterBase): self.gen_getter(struct, field) if not struct.immutable and not field.chained_struct_field: self.gen_setter(field) + + # Generate getters for any constexpr/compile-time struct data + self.write_empty_line() + self.gen_constexpr_getters() + self.write_unindented_line('protected:') self.gen_protected_serializer_methods(struct) @@ -1112,6 +1128,9 @@ class _CppHeaderFileWriter(_CppFileWriterBase): if _is_required_serializer_field(field): self.gen_serializer_member(field) + # Write constexpr struct data + self.gen_constexpr_members(struct) + self.write_empty_line() field_lists_list: Iterable[Iterable[ast.FieldListBase]] @@ -1657,6 +1676,10 @@ class _CppSourceFileWriter(_CppFileWriterBase): if isinstance(struct, ast.Command): command_predicate = "!mongo::isGenericArgument(fieldName)" + # Ditto for command replies + if struct.is_command_reply: + command_predicate = "!mongo::isGenericReply(fieldName)" + with self._block('else {', '}'): with self._predicate(command_predicate): self._writer.write_line('ctxt.throwUnknownField(fieldName);') @@ -2670,7 +2693,9 @@ class _CppSourceFileWriter(_CppFileWriterBase): self.gen_description_comment(idl_enum.description) self.gen_enum_definition(idl_enum) - for struct in spec.structs: + all_structs = spec.structs + cast(List[ast.Struct], spec.commands) + + for struct in all_structs: self.gen_string_constants_definitions(struct) self.write_empty_line() diff --git a/buildscripts/idl/idl/parser.py b/buildscripts/idl/idl/parser.py index d62dd69bb6e..870f6142f68 100644 --- a/buildscripts/idl/idl/parser.py +++ b/buildscripts/idl/idl/parser.py @@ -528,6 +528,7 @@ def _parse_struct(ctxt, spec, name, node): "generate_comparison_operators": _RuleDesc("bool_scalar"), "non_const_getter": _RuleDesc('bool_scalar'), "cpp_validator_func": _RuleDesc('scalar'), + "is_command_reply": _RuleDesc('bool_scalar'), }) # PyLint has difficulty with some iterables: https://github.com/PyCQA/pylint/issues/3105 diff --git a/buildscripts/idl/idl/syntax.py b/buildscripts/idl/idl/syntax.py index 79bfdd002be..1e24a445df2 100644 --- a/buildscripts/idl/idl/syntax.py +++ b/buildscripts/idl/idl/syntax.py @@ -531,6 +531,7 @@ class Struct(common.SourceLocation): self.allow_global_collection_name = False # type: bool self.non_const_getter = False # type: bool self.cpp_validator_func = None # type: str + self.is_command_reply = False # type: bool # Command only property self.cpp_name = None # type: str |