diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/bindings/scripts/bind_gen/enumeration.py')
-rw-r--r-- | chromium/third_party/blink/renderer/bindings/scripts/bind_gen/enumeration.py | 91 |
1 files changed, 65 insertions, 26 deletions
diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/enumeration.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/enumeration.py index d547b649b75..69f00def6c3 100644 --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/enumeration.py +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/enumeration.py @@ -35,18 +35,27 @@ def make_factory_methods(cg_context): T = TextNode decls = ListNode() + defs = ListNode() - func_def = CxxFuncDefNode( - name="Create", - arg_decls=[ - "v8::Isolate* isolate", - "v8::Local<v8::Value> value", - "ExceptionState& exception_state", - ], - return_type="${class_name}", - static=True) + func_decl = CxxFuncDeclNode(name="Create", + arg_decls=[ + "v8::Isolate* isolate", + "v8::Local<v8::Value> value", + "ExceptionState& exception_state", + ], + return_type="${class_name}", + static=True) + func_def = CxxFuncDefNode(name="Create", + arg_decls=[ + "v8::Isolate* isolate", + "v8::Local<v8::Value> value", + "ExceptionState& exception_state", + ], + return_type="${class_name}", + class_name=cg_context.class_name) func_def.set_base_template_vars(cg_context.template_bindings()) - decls.append(func_def) + decls.append(func_decl) + defs.append(func_def) func_def.body.extend([ T("const auto& result = bindings::FindIndexInEnumStringTable(" @@ -57,12 +66,18 @@ def make_factory_methods(cg_context): "${class_name}();"), ]) + func_decl = CxxFuncDeclNode(name="Create", + arg_decls=["const String& value"], + return_type="absl::optional<${class_name}>", + static=True) func_def = CxxFuncDefNode(name="Create", arg_decls=["const String& value"], return_type="absl::optional<${class_name}>", - static=True) + class_name=cg_context.class_name) func_def.set_base_template_vars(cg_context.template_bindings()) - decls.append(func_def) + decls.append(func_decl) + defs.append(EmptyNode()) + defs.append(func_def) func_def.body.extend([ T("const auto& result = bindings::FindIndexInEnumStringTable" @@ -72,7 +87,19 @@ def make_factory_methods(cg_context): T("return ${class_name}(static_cast<Enum>(result.value()));"), ]) - return decls, None + return decls, defs + + +def make_default_constructor(cg_context): + assert isinstance(cg_context, CodeGenContext) + + func_decl = CxxFuncDeclNode(name=cg_context.class_name, + arg_decls=[], + return_type="", + constexpr=True, + default=True) + + return func_decl, None def make_constructors(cg_context): @@ -83,12 +110,6 @@ def make_constructors(cg_context): class_name = cg_context.class_name decls = ListNode([ - CxxFuncDeclNode( - name=class_name, - arg_decls=[], - return_type="", - constexpr=True, - default=True), CxxFuncDefNode( name=class_name, arg_decls=["Enum value"], @@ -219,18 +240,23 @@ def make_nested_enum_class_def(cg_context): def make_enum_string_table(cg_context): assert isinstance(cg_context, CodeGenContext) + decls = TextNode("static const char* const string_table_[];") + str_values = [ TextNode("\"{}\"".format(value)) for value in cg_context.enumeration.values ] - decls = ListNode([ - TextNode("static constexpr const char* const string_table_[] = {"), + # Define the string table in *.cc so that there never exists a copy of + # the table (i.e. the strings in the table are interned strings in the + # scope of this IDL enumeration). This trick makes it possible to compare + # the strings by their address. + defs = ListNode([ + TextNode("constexpr const char* const " + "${class_name}::string_table_[] = {"), ListNode(str_values, separator=", "), TextNode("};"), ]) - - defs = TextNode("const char* const ${class_name}::string_table_[];") defs.set_base_template_vars(cg_context.template_bindings()) return decls, defs @@ -281,6 +307,8 @@ def generate_enumeration(enumeration_identifier): # Implementation parts factory_decls, factory_defs = make_factory_methods(cg_context) + default_ctor_decls, default_ctor_defs = make_default_constructor( + cg_context) ctor_decls, ctor_defs = make_constructors(cg_context) assign_decls, assign_defs = make_assignment_operators(cg_context) equal_decls, equal_defs = make_equality_operators(cg_context) @@ -318,11 +346,17 @@ def generate_enumeration(enumeration_identifier): ]) # Assemble the parts. + header_node.accumulator.add_class_decls([ + "ExceptionState", + ]) header_node.accumulator.add_include_headers([ component_export_header(api_component, for_testing), - "third_party/blink/renderer/bindings/core/v8/generated_code_helper.h", + "third_party/abseil-cpp/absl/types/optional.h", "third_party/blink/renderer/platform/bindings/enumeration_base.h", ]) + source_node.accumulator.add_include_headers([ + "third_party/blink/renderer/bindings/core/v8/generated_code_helper.h", + ]) header_blink_ns.body.append(class_def) header_blink_ns.body.append(EmptyNode()) @@ -330,14 +364,19 @@ def generate_enumeration(enumeration_identifier): class_def.public_section.append(nested_enum_class_def) class_def.public_section.append(EmptyNode()) + class_def.private_section.append(table_decls) + class_def.private_section.append(EmptyNode()) + source_blink_ns.body.append(table_defs) + source_blink_ns.body.append(EmptyNode()) + class_def.public_section.append(factory_decls) class_def.public_section.append(EmptyNode()) source_blink_ns.body.append(factory_defs) source_blink_ns.body.append(EmptyNode()) - class_def.private_section.append(table_decls) + class_def.private_section.append(default_ctor_decls) class_def.private_section.append(EmptyNode()) - source_blink_ns.body.append(table_defs) + source_blink_ns.body.append(default_ctor_defs) source_blink_ns.body.append(EmptyNode()) class_def.public_section.append(ctor_decls) |