Commit 54c33402 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

CodeGen: Generate IDL dictionary (1/N)

Generates basic code for accessors of dictionary members.


Bug: 839389
Change-Id: I710f090a0cd66bb9821bbe0274cce3f120a93e57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900522
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714156}
parent 493aa6a4
......@@ -150,10 +150,12 @@ action_with_pydeps("generate_bindings_example") {
]
outputs = [
"${bindings_output_dir}/core/v8/v8_example.cc",
"${bindings_output_dir}/core/v8/example_dictionary.cc",
]
args = [
"example",
"dictionary",
"--web_idl_database",
rebase_path(web_idl_database, root_build_dir),
"--output_dir_core",
......
......@@ -31,6 +31,7 @@ _setup_sys_path()
from . import clang_format
from .dictionary import generate_dictionaries
from .example import run_example
from .interface import generate_interfaces
from .path_manager import PathManager
......
# Copyright 2019 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
from . import name_style
from .blink_v8_bridge import blink_class_name
from .blink_v8_bridge import blink_type_info
from .code_node import CodeNode
from .code_node import FunctionDefinitionNode
from .code_node import SymbolScopeNode
from .code_node import TextNode
from .codegen_context import CodeGenContext
from .codegen_utils import enclose_with_namespace
from .codegen_utils import make_copyright_header
from .codegen_utils import write_code_node_to_file
from .mako_renderer import MakoRenderer
_format = CodeNode.format_template
def make_dict_member_get_def(cg_context):
assert isinstance(cg_context, CodeGenContext)
T = TextNode
member = cg_context.dict_member
func_name = "{}::{}".format(
blink_class_name(cg_context.dictionary),
name_style.api_func(member.identifier))
func_def = FunctionDefinitionNode(
name=T(func_name),
arg_decls=[],
return_type=T(blink_type_info(member.idl_type).ref_t))
body = func_def.body
body.add_template_vars(cg_context.template_bindings())
_1 = name_style.member_var(member.identifier)
body.append(T(_format("return {_1};", _1=_1)))
return func_def
def make_dict_member_has_def(cg_context):
assert isinstance(cg_context, CodeGenContext)
T = TextNode
member = cg_context.dict_member
func_name = "{}::{}".format(
blink_class_name(cg_context.dictionary),
name_style.api_func("has", member.identifier))
func_def = FunctionDefinitionNode(
name=T(func_name), arg_decls=[], return_type=T("bool"))
body = func_def.body
body.add_template_vars(cg_context.template_bindings())
_1 = name_style.member_var("has", member.identifier)
body.append(T(_format("return {_1};", _1=_1)))
return func_def
def make_dict_member_set_def(cg_context):
assert isinstance(cg_context, CodeGenContext)
T = TextNode
member = cg_context.dict_member
func_name = "{}::{}".format(
blink_class_name(cg_context.dictionary),
name_style.api_func("set", member.identifier))
func_def = FunctionDefinitionNode(
name=T(func_name),
arg_decls=[
T(_format("{} value",
blink_type_info(member.idl_type).ref_t))
],
return_type=T("void"))
body = func_def.body
body.add_template_vars(cg_context.template_bindings())
_1 = name_style.member_var(member.identifier)
body.append(T(_format("{_1} = value;", _1=_1)))
return func_def
def generate_dictionaries(web_idl_database, output_dirs):
dictionary = web_idl_database.find("ExampleDictionary")
filename = "{}.cc".format(name_style.file(dictionary.identifier))
filepath = os.path.join(output_dirs['core'], filename)
cg_context = CodeGenContext(dictionary=dictionary)
root_node = SymbolScopeNode(separator_last="\n")
root_node.set_renderer(MakoRenderer())
code_node = SymbolScopeNode()
for member in sorted(dictionary.own_members, key=lambda x: x.identifier):
code_node.extend([
make_dict_member_get_def(cg_context.make_copy(dict_member=member)),
make_dict_member_has_def(cg_context.make_copy(dict_member=member)),
make_dict_member_set_def(cg_context.make_copy(dict_member=member)),
])
root_node.extend([
make_copyright_header(),
TextNode(""),
enclose_with_namespace(code_node, name_style.namespace("blink")),
])
write_code_node_to_file(root_node, filepath)
......@@ -39,6 +39,7 @@ def main():
options, tasks = parse_options()
dispatch_table = {
'dictionary': bind_gen.generate_dictionaries,
'example': bind_gen.run_example,
'interface': bind_gen.generate_interfaces,
}
......
......@@ -17,6 +17,9 @@
../../../../mako/mako/runtime.py
../../../../mako/mako/template.py
../../../../mako/mako/util.py
../../../../markupsafe/__init__.py
../../../../markupsafe/_compat.py
../../../../markupsafe/_native.py
../../../../pyjson5/src/json5/__init__.py
../../../../pyjson5/src/json5/arg_parser.py
../../../../pyjson5/src/json5/host.py
......@@ -33,6 +36,7 @@ bind_gen/code_node.py
bind_gen/codegen_accumulator.py
bind_gen/codegen_context.py
bind_gen/codegen_utils.py
bind_gen/dictionary.py
bind_gen/example.py
bind_gen/interface.py
bind_gen/mako_renderer.py
......
......@@ -22,3 +22,8 @@ namespace TestNamespace {
readonly attribute TestInterfaceConstructor attr2;
void op1(long x, boolean y, TestInterfaceConstructor z);
};
dictionary ExampleDictionary {
Node node;
long fooMember;
};
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