Commit 439dda01 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Give union types backward-compatible names

Bug: 839389
Change-Id: I09c7ac3589b2d9f7c0b63a7f4f96a2682ff542e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056194
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741386}
parent 0ee99fe1
......@@ -3284,10 +3284,6 @@ def generate_interface(interface):
def generate_interfaces(web_idl_database):
interface = web_idl_database.find("MemoryInfo")
generate_interface(interface)
return
# multiprocessing.cpu_count()
pool = multiprocessing.Pool(8)
pool.map_async(generate_interface, web_idl_database.interfaces).get(3600)
......@@ -121,8 +121,11 @@ class PathManager(object):
# produce the same filepaths with the old bindings generator for the
# time being.
if isinstance(idl_definition, web_idl.Union):
self._api_basename = name_style.file(idl_definition.identifier)
self._impl_basename = name_style.file(idl_definition.identifier)
union_class_name = idl_definition.identifier
union_filepath = _BACKWARD_COMPATIBLE_UNION_FILEPATHS.get(
union_class_name, union_class_name)
self._api_basename = name_style.file(union_filepath)
self._impl_basename = name_style.file(union_filepath)
if not isinstance(idl_definition, web_idl.Union):
idl_path = idl_definition.debug_info.location.filepath
......@@ -177,3 +180,33 @@ class PathManager(object):
if ext is not None:
filename = posixpath.extsep.join([filename, ext])
return posixpath.join(dirpath, filename)
# A hack to make the filepaths to generated IDL unions compatible with the old
# bindings generator.
#
# Copied from |shorten_union_name| defined in
# //third_party/blink/renderer/bindings/scripts/utilities.py
_BACKWARD_COMPATIBLE_UNION_FILEPATHS = {
# modules/canvas2d/CanvasRenderingContext2D.idl
"CSSImageValueOrHTMLImageElementOrSVGImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmapOrOffscreenCanvas":
"CanvasImageSource",
# modules/canvas/htmlcanvas/html_canvas_element_module_support_webgl2_compute.idl
"CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrGPUCanvasContext":
"RenderingContext",
# modules/canvas/htmlcanvas/html_canvas_element_module.idl
"CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrGPUCanvasContext":
"RenderingContext",
# core/frame/window_or_worker_global_scope.idl
"HTMLImageElementOrSVGImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrImageBitmapOrOffscreenCanvas":
"ImageBitmapSource",
# bindings/tests/idls/core/TestTypedefs.idl
"NodeOrLongSequenceOrEventOrXMLHttpRequestOrStringOrStringByteStringOrNodeListRecord":
"NestedUnionType",
# modules/canvas/offscreencanvas/offscreen_canvas_module_support_webgl2_compute.idl.
# Due to offscreen_canvas_module_support_webgl2_compute.idl and offscreen_canvas_module.idl are exclusive in modules_idl_files.gni, they have same shorten name.
"OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContext":
"OffscreenRenderingContext",
# modules/canvas/offscreencanvas/offscreen_canvas_module.idl
"OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContext":
"OffscreenRenderingContext",
}
......@@ -79,6 +79,14 @@ class Union(WithIdentifier, WithCodeGeneratorInfo, WithComponent,
for idl_type in flattened_members:
idl_type.apply_to_all_composing_elements(collect_primary_component)
# Make this union type look defined in 'modules' if the union type is
# used in 'modules' in order to keep the backward compatibility with
# the old bindings generator.
for idl_type in union_types:
filepath = idl_type.debug_info.location.filepath
if filepath.startswith('third_party/blink/renderer/modules/'):
from .composition_parts import Component
components.add(Component('modules'))
# TODO(peria, yukishiino): Produce unique union names. Trying to
# produce the names compatible to the old bindings generator for the
......@@ -86,12 +94,17 @@ class Union(WithIdentifier, WithCodeGeneratorInfo, WithComponent,
#
# type_names = sorted(
# [idl_type.type_name for idl_type in flattened_members])
type_names = [
idl_type.type_name for idl_type in union_types[0].member_types
]
if does_include_nullable_type:
type_names.append('Null')
identifier = Identifier('Or'.join(type_names))
def backward_compatible_member_name(idl_type):
name = idl_type.unwrap().type_name
if name == 'StringTreatNullAs':
return 'StringTreatNullAsEmptyString'
else:
return name
identifier = Identifier('Or'.join([
backward_compatible_member_name(idl_type)
for idl_type in union_types[0].member_types
]))
WithIdentifier.__init__(self, identifier)
WithCodeGeneratorInfo.__init__(self, readonly=True)
......
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