Commit 1ce0503d authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Add 'allowDuplicates' flag to json5 files for make_names.py

If a json5 file for make_names.py contains duplicated names, make_name.py
produced invalid C++ code and we had to remove duplicates.

* make_names.py should report an error for duplicated entries instead of
  producing invalid code.

* html/keywords.json5 should allow duplicated entries because it
  contains keyword sets for multiple attributes and some keywords are
  valid for multiple attributes.

Change-Id: I81c2a4a978ece5a03471fd8b37d85b61cda2a8e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032465
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737211}
parent 75142162
......@@ -216,6 +216,31 @@ class Json5File(object):
self._process(doc)
def reject_duplicates(entries):
assert isinstance(entries, list), 'The data should be a list.'
name_dict = {}
for entry in entries:
name = entry['name'].original
if name in name_dict:
raise Exception('The data contains multiple entries for "%s".' % name)
name_dict[name] = entry
def remove_duplicates(entries):
assert isinstance(entries, list), 'The data should be a list.'
name_dict = {}
filtered_list = []
for entry in entries:
name = entry['name'].original
if name in name_dict:
if entry != name_dict[name]:
raise Exception('Duplicated entries for "%s" must be identical.' % name)
else:
name_dict[name] = entry
filtered_list.append(entry)
return filtered_list
class Writer(object):
# Subclasses should override.
class_name = None
......
......@@ -52,6 +52,7 @@ class MakeNamesWriter(json5_generator.Writer):
'Symbol': {},
}
default_metadata = {
'allowDuplicates': False,
'export': '',
'namespace': '',
'suffix': '',
......@@ -77,6 +78,12 @@ class MakeNamesWriter(json5_generator.Writer):
'"%s" is specified in %s.' %
(namespace, json5_file_path))
entries = self.json5_file.name_dictionaries
if self.json5_file.metadata['allowDuplicates']:
entries = json5_generator.remove_duplicates(entries)
else:
json5_generator.reject_duplicates(entries)
basename, _ = os.path.splitext(os.path.basename(json5_file_path[0]))
self._outputs = {
(basename + '.h'): self.generate_header,
......@@ -87,7 +94,7 @@ class MakeNamesWriter(json5_generator.Writer):
'namespace': namespace,
'suffix': suffix,
'export': export,
'entries': self.json5_file.name_dictionaries,
'entries': entries,
'header_guard': self.make_header_guard(qualified_header),
'input_files': self._input_files,
'this_include_path': qualified_header,
......
......@@ -6,6 +6,7 @@
metadata: {
namespace: "keywords",
export: "CORE_EXPORT",
allowDuplicates: true,
},
data: [
......@@ -48,7 +49,7 @@
// https://wicg.github.io/priority-hints/#solution-0
"high",
"low",
// "auto",
"auto",
// inputmode attribute
// https://html.spec.whatwg.org/C/#attr-inputmode
......@@ -59,7 +60,7 @@
"email",
"numeric",
"decimal",
// "search",
"search",
// invisible attribute
// https://github.com/rakina/searchable-invisible-dom
......@@ -70,7 +71,7 @@
// https://github.com/scott-little/lazyload#ways-the-loading-attribute-can-be-used
"lazy",
"eager",
// "auto",
"auto",
// referrerpolicy attribute
// https://w3c.github.io/webappsec-referrer-policy/#referrer-policies
......
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