Commit 0cd3a53a authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

make_qualified_names: Add capability to produce code following Google C++ style

Currently make_qualifed_names.py produces blink::FooNames::baz_hogeTag
constant variables. They don't match to Google C++ style.  This CL adds
capability to produce code following Google C++ style.

If 'namespace' field in foo_tag_names.json5 or foo_attribute_names.json5
is in the following list, the behavior isn't changed.
    'HTML', 'MathML', 'SVG', 'XLink', 'XML', 'XMLNS'

Otherwise,
 - C++ namespace name is {{namespace|lower}}_names, not {{namespace}}Names
 - Prepend 'k' to UpperCamelCase tag/attribute names
So 'blink::foo_names::kBazHogeTag' will be produced.


Bug: 889726
Change-Id: I997ab91b79cc13baa46e8e519e3bccb9cecc72ce
Reviewed-on: https://chromium-review.googlesource.com/c/1290052Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601342}
parent be20a16a
...@@ -39,10 +39,14 @@ from aria_properties import ARIAReader ...@@ -39,10 +39,14 @@ from aria_properties import ARIAReader
from json5_generator import Json5File from json5_generator import Json5File
def _symbol(entry): def _legacy_symbol(entry):
return entry['name'].original.replace('-', '_') return entry['name'].original.replace('-', '_')
def _symbol(entry):
return 'k' + entry['name'].to_upper_camel_case()
class MakeQualifiedNamesWriter(json5_generator.Writer): class MakeQualifiedNamesWriter(json5_generator.Writer):
default_parameters = {} default_parameters = {}
default_metadata = { default_metadata = {
...@@ -85,6 +89,11 @@ class MakeQualifiedNamesWriter(json5_generator.Writer): ...@@ -85,6 +89,11 @@ class MakeQualifiedNamesWriter(json5_generator.Writer):
self.attrs_json5_file.merge_from(self.aria_reader.attributes_list()) self.attrs_json5_file.merge_from(self.aria_reader.attributes_list())
self.namespace = self._metadata('namespace') self.namespace = self._metadata('namespace')
cpp_namespace = self.namespace.lower() + '_names'
# TODO(tkent): Remove the following branch. crbug.com/889726
if self.namespace in ('HTML', 'MathML', 'SVG', 'XLink', 'XML', 'XMLNS'):
cpp_namespace = self.namespace + 'Names'
MakeQualifiedNamesWriter.filters['symbol'] = _legacy_symbol
namespace_prefix = self._metadata('namespacePrefix') or self.namespace.lower() namespace_prefix = self._metadata('namespacePrefix') or self.namespace.lower()
namespace_uri = self._metadata('namespaceURI') namespace_uri = self._metadata('namespaceURI')
...@@ -98,6 +107,7 @@ class MakeQualifiedNamesWriter(json5_generator.Writer): ...@@ -98,6 +107,7 @@ class MakeQualifiedNamesWriter(json5_generator.Writer):
qualified_header = self._relative_output_dir + self.namespace.lower() + '_names.h' qualified_header = self._relative_output_dir + self.namespace.lower() + '_names.h'
self._template_context = { self._template_context = {
'attrs': self.attrs_json5_file.name_dictionaries, 'attrs': self.attrs_json5_file.name_dictionaries,
'cpp_namespace': cpp_namespace,
'export': self._metadata('export'), 'export': self._metadata('export'),
'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,
......
...@@ -31,10 +31,10 @@ static {{namespace}}Element* {{namespace}}{{tag|symbol}}Constructor( ...@@ -31,10 +31,10 @@ static {{namespace}}Element* {{namespace}}{{tag|symbol}}Constructor(
const CreateElementFlags flags) { const CreateElementFlags flags) {
{% if tag.runtimeEnabled %} {% if tag.runtimeEnabled %}
if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
return {{fallback_interface}}::Create({{namespace}}Names::{{tag|symbol}}Tag, document); return {{fallback_interface}}::Create({{cpp_namespace}}::{{tag|symbol}}Tag, document);
{% endif %} {% endif %}
return {{tag.interface}}::Create( return {{tag.interface}}::Create(
{%- if tag.multipleTagNames %}{{namespace}}Names::{{tag|symbol}}Tag, {% endif -%} {%- if tag.multipleTagNames %}{{cpp_namespace}}::{{tag|symbol}}Tag, {% endif -%}
document document
{%- if tag.constructorNeedsCreateElementFlags %}, flags{% endif -%} {%- if tag.constructorNeedsCreateElementFlags %}, flags{% endif -%}
); );
...@@ -53,7 +53,7 @@ static void create{{namespace}}FunctionMap() { ...@@ -53,7 +53,7 @@ static void create{{namespace}}FunctionMap() {
// compile in MSVC. If tags list is empty, add check to skip this. // compile in MSVC. If tags list is empty, add check to skip this.
static const Create{{namespace}}FunctionMapData data[] = { static const Create{{namespace}}FunctionMapData data[] = {
{% for tag in tags|sort if not tag.noConstructor %} {% for tag in tags|sort if not tag.noConstructor %}
{ {{namespace}}Names::{{tag|symbol}}Tag, {{namespace}}{{tag|symbol}}Constructor }, { {{cpp_namespace}}::{{tag|symbol}}Tag, {{namespace}}{{tag|symbol}}Constructor },
{% endfor %} {% endfor %}
}; };
for (size_t i = 0; i < arraysize(data); i++) for (size_t i = 0; i < arraysize(data); i++)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink { namespace blink {
namespace {{namespace}}Names { namespace {{cpp_namespace}} {
using namespace blink; using namespace blink;
...@@ -104,5 +104,5 @@ void init() { ...@@ -104,5 +104,5 @@ void init() {
DCHECK_EQ(attr_i, kAttrsCount); DCHECK_EQ(attr_i, kAttrsCount);
} }
} // namespace {{namespace}}Names } // namespace {{cpp_namespace}}
} // namespace blink } // namespace blink
...@@ -16,7 +16,7 @@ namespace blink { ...@@ -16,7 +16,7 @@ namespace blink {
class {{namespace}}QualifiedName : public QualifiedName { }; class {{namespace}}QualifiedName : public QualifiedName { };
namespace {{namespace}}Names { namespace {{cpp_namespace}} {
{% set symbol_export = '%s ' % export if export else '' %} {% set symbol_export = '%s ' % export if export else '' %}
// Namespace // Namespace
...@@ -44,7 +44,7 @@ std::unique_ptr<const QualifiedName*[]> GetAttrs(); ...@@ -44,7 +44,7 @@ std::unique_ptr<const QualifiedName*[]> GetAttrs();
void init(); void init();
} // namespace {{namespace}}Names } // namespace {{cpp_namespace}}
} // namespace blink } // namespace blink
#endif // {{header_guard}} #endif // {{header_guard}}
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