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): ...@@ -216,6 +216,31 @@ class Json5File(object):
self._process(doc) 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): class Writer(object):
# Subclasses should override. # Subclasses should override.
class_name = None class_name = None
......
...@@ -52,6 +52,7 @@ class MakeNamesWriter(json5_generator.Writer): ...@@ -52,6 +52,7 @@ class MakeNamesWriter(json5_generator.Writer):
'Symbol': {}, 'Symbol': {},
} }
default_metadata = { default_metadata = {
'allowDuplicates': False,
'export': '', 'export': '',
'namespace': '', 'namespace': '',
'suffix': '', 'suffix': '',
...@@ -77,6 +78,12 @@ class MakeNamesWriter(json5_generator.Writer): ...@@ -77,6 +78,12 @@ class MakeNamesWriter(json5_generator.Writer):
'"%s" is specified in %s.' % '"%s" is specified in %s.' %
(namespace, json5_file_path)) (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])) basename, _ = os.path.splitext(os.path.basename(json5_file_path[0]))
self._outputs = { self._outputs = {
(basename + '.h'): self.generate_header, (basename + '.h'): self.generate_header,
...@@ -87,7 +94,7 @@ class MakeNamesWriter(json5_generator.Writer): ...@@ -87,7 +94,7 @@ class MakeNamesWriter(json5_generator.Writer):
'namespace': namespace, 'namespace': namespace,
'suffix': suffix, 'suffix': suffix,
'export': export, 'export': export,
'entries': self.json5_file.name_dictionaries, 'entries': entries,
'header_guard': self.make_header_guard(qualified_header), 'header_guard': self.make_header_guard(qualified_header),
'input_files': self._input_files, 'input_files': self._input_files,
'this_include_path': qualified_header, 'this_include_path': qualified_header,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
metadata: { metadata: {
namespace: "keywords", namespace: "keywords",
export: "CORE_EXPORT", export: "CORE_EXPORT",
allowDuplicates: true,
}, },
data: [ data: [
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
// https://wicg.github.io/priority-hints/#solution-0 // https://wicg.github.io/priority-hints/#solution-0
"high", "high",
"low", "low",
// "auto", "auto",
// inputmode attribute // inputmode attribute
// https://html.spec.whatwg.org/C/#attr-inputmode // https://html.spec.whatwg.org/C/#attr-inputmode
...@@ -59,7 +60,7 @@ ...@@ -59,7 +60,7 @@
"email", "email",
"numeric", "numeric",
"decimal", "decimal",
// "search", "search",
// invisible attribute // invisible attribute
// https://github.com/rakina/searchable-invisible-dom // https://github.com/rakina/searchable-invisible-dom
...@@ -70,7 +71,7 @@ ...@@ -70,7 +71,7 @@
// https://github.com/scott-little/lazyload#ways-the-loading-attribute-can-be-used // https://github.com/scott-little/lazyload#ways-the-loading-attribute-can-be-used
"lazy", "lazy",
"eager", "eager",
// "auto", "auto",
// referrerpolicy attribute // referrerpolicy attribute
// https://w3c.github.io/webappsec-referrer-policy/#referrer-policies // 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