Commit ec24b76c authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

CodeGen: Generate code for Union (1 of N)

Defines an almost empty class.


Bug: 839389
Change-Id: Ide0536992f1247d7e53aa8109083519d41db7892
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1990894
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730093}
parent e99344af
......@@ -34,6 +34,7 @@ from . import clang_format
from .dictionary import generate_dictionaries
from .interface import generate_interfaces
from .path_manager import PathManager
from .union import generate_unions
def _setup_clang_format():
......
......@@ -4,6 +4,8 @@
import copy
import web_idl
from . import name_style
from .codegen_format import NonRenderable
from .path_manager import PathManager
......@@ -169,7 +171,7 @@ class CodeGenContext(object):
@property
def idl_location(self):
idl_def = self.member_like or self.idl_definition
if idl_def:
if idl_def and not isinstance(idl_def, web_idl.Union):
location = idl_def.debug_info.location
text = PathManager.relpath_to_project_root(location.filepath)
if location.line_number is not None:
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os.path
import web_idl
from . import name_style
from .code_node import ListNode
from .code_node import TextNode
from .code_node_cxx import CxxClassDefNode
from .code_node_cxx import CxxNamespaceNode
from .codegen_accumulator import CodeGenAccumulator
from .codegen_context import CodeGenContext
from .codegen_utils import collect_include_headers
from .codegen_utils import component_export
from .codegen_utils import enclose_with_header_guard
from .codegen_utils import enclose_with_namespace
from .codegen_utils import make_copyright_header
from .codegen_utils import make_forward_declarations
from .codegen_utils import make_header_include_directives
from .codegen_utils import write_code_node_to_file
from .mako_renderer import MakoRenderer
from .path_manager import PathManager
def make_union_class_def(cg_context):
assert isinstance(cg_context, CodeGenContext)
T = TextNode
union = cg_context.union
component = union.components[0]
class_def = CxxClassDefNode(
cg_context.class_name, export=component_export(component))
class_def.set_base_template_vars(cg_context.template_bindings())
class_def.top_section.extend([
T("DISALLOW_NEW();"),
])
class_def.public_section.extend([
T("void Trace(Visitor*);"),
])
return class_def
def generate_union(union):
path_manager = PathManager(union)
class_name = union.identifier
cg_context = CodeGenContext(union=union, class_name=class_name)
filename = "union_example.h"
header_path = path_manager.api_path(filename=filename)
header_node = ListNode(tail="\n")
header_node.set_accumulator(CodeGenAccumulator())
header_node.set_renderer(MakoRenderer())
header_node.accumulator.add_include_headers(collect_include_headers(union))
header_blink_ns = CxxNamespaceNode(name_style.namespace("blink"))
class_def = make_union_class_def(cg_context)
header_node.extend([
make_copyright_header(),
TextNode(""),
enclose_with_header_guard(
ListNode([
make_header_include_directives(header_node.accumulator),
TextNode(""),
header_blink_ns,
]), name_style.header_guard(header_path)),
])
header_blink_ns.body.extend([
make_forward_declarations(header_node.accumulator),
TextNode(""),
])
header_blink_ns.body.append(class_def)
# Write down to the files.
write_code_node_to_file(header_node, path_manager.gen_path_to(header_path))
def generate_unions(web_idl_database):
union = list(web_idl_database.union_types)[0]
generate_union(union)
......@@ -49,6 +49,7 @@ def main():
dispatch_table = {
'dictionary': bind_gen.generate_dictionaries,
'interface': bind_gen.generate_interfaces,
'union': bind_gen.generate_unions,
}
for task in tasks:
......
......@@ -43,6 +43,7 @@ bind_gen/interface.py
bind_gen/mako_renderer.py
bind_gen/name_style.py
bind_gen/path_manager.py
bind_gen/union.py
generate_bindings.py
web_idl/__init__.py
web_idl/argument.py
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment