Commit 1f1e4e18 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Make interface.py produce backward-compatible API names

Bug: 839389
Change-Id: I158f60540bc3187264822e637e09216d9d524815
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055911
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741771}
parent 98e49a7b
......@@ -23,12 +23,16 @@ def blink_class_name(idl_definition):
if class_name:
return class_name
assert idl_definition.identifier[0].isupper()
# Do not apply |name_style.class_| in order to respect the original name
# (Web spec'ed name) as much as possible. For example, |interface EXTsRGB|
# is implemented as |class EXTsRGB|, not as |ExtSRgb| nor |ExtsRgb|.
if isinstance(idl_definition,
(web_idl.CallbackFunction, web_idl.CallbackInterface,
web_idl.Enumeration)):
return name_style.class_("v8", idl_definition.identifier)
return "V8{}".format(idl_definition.identifier)
else:
return name_style.class_(idl_definition.identifier)
return idl_definition.identifier
def v8_bridge_class_name(idl_definition):
......@@ -37,7 +41,10 @@ def v8_bridge_class_name(idl_definition):
"""
assert isinstance(idl_definition, (web_idl.Namespace, web_idl.Interface))
return name_style.class_("v8", idl_definition.identifier)
assert idl_definition.identifier[0].isupper()
# Do not apply |name_style.class_| due to the same reason as
# |blink_class_name|.
return "V8{}".format(idl_definition.identifier)
def blink_type_info(idl_type):
......
......@@ -51,6 +51,34 @@ def _is_none_or_str(arg):
return arg is None or isinstance(arg, str)
def backward_compatible_api_func(cg_context):
"""
Returns the Blink function name compatible with the old bindings generator.
"""
assert isinstance(cg_context, CodeGenContext)
name = (cg_context.member_like.code_generator_info.property_implemented_as
or cg_context.member_like.identifier
or cg_context.property_.identifier)
if cg_context.attribute_get:
# modules/webaudio/biquad_filter_node.idl has readonly attribute "Q"
# and somehow it's implemented as "q" in Blink.
if name == "Q":
name = "q"
if cg_context.attribute_set:
tokens = name_style.raw.tokenize(name)
if tokens[0] in ("IDL", "css", "xml"):
tokens[0] = tokens[0].upper()
else:
tokens[0] = tokens[0].capitalize()
tokens.insert(0, "set")
name = "".join(tokens)
return name
def callback_function_name(cg_context, overload_index=None):
assert isinstance(cg_context, CodeGenContext)
......@@ -469,11 +497,7 @@ def _make_blink_api_call(code_node, cg_context, num_of_args=None):
if cg_context.may_throw_exception:
arguments.append("${exception_state}")
func_name = (code_generator_info.property_implemented_as
or name_style.api_func(cg_context.member_like.identifier
or cg_context.property_.identifier))
if cg_context.attribute_set:
func_name = name_style.api_func("set", func_name)
func_name = backward_compatible_api_func(cg_context)
if cg_context.constructor:
func_name = "Create"
if "Reflect" in ext_attrs: # [Reflect]
......
......@@ -14,7 +14,7 @@ xxx_f(format_string, *args, **kwargs):
The name is formatted with the given format string and arguments.
"""
from blinkbuild.name_style_converter import NameStyleConverter
from blinkbuild import name_style_converter
def api_func(*args):
......@@ -162,21 +162,27 @@ class raw(object):
This class is pretending to be a module.
"""
_NameStyleConverter = name_style_converter.NameStyleConverter
def __init__(self):
assert False
@staticmethod
def tokenize(name):
return name_style_converter.tokenize_name(name)
@staticmethod
def snake_case(name):
return NameStyleConverter(name).to_snake_case()
return raw._NameStyleConverter(name).to_snake_case()
@staticmethod
def upper_camel_case(name):
return NameStyleConverter(name).to_upper_camel_case()
return raw._NameStyleConverter(name).to_upper_camel_case()
@staticmethod
def lower_camel_case(name):
return NameStyleConverter(name).to_lower_camel_case()
return raw._NameStyleConverter(name).to_lower_camel_case()
@staticmethod
def macro_case(name):
return NameStyleConverter(name).to_macro_case()
return raw._NameStyleConverter(name).to_macro_case()
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