Commit 55100ec8 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

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

Currently make_names.py produces blink::FooBarNames::baz_hoge 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_bar_names.json5 contains capital letters,
the behavior isn't changed.
Otherwise,
 - Don't append 'Names' to C++ namespace
 - Prepend 'k' to UpperCamelCase names
So 'blink::foo_bar::kBazHoge' will be produced.

Bug: 889726
Change-Id: Iac8ca8040782c440d755067bec7c738d92189878
Reviewed-on: https://chromium-review.googlesource.com/c/1288518Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601343}
parent 0cd3a53a
......@@ -14,9 +14,12 @@ import media_feature_symbol
class MakeMediaFeatureNamesWriter(make_names.MakeNamesWriter):
pass
MakeMediaFeatureNamesWriter.filters['symbol'] = media_feature_symbol.getMediaFeatureSymbolWithSuffix('MediaFeature')
def __init__(self, json5_file_path, output_dir):
super(MakeMediaFeatureNamesWriter, self).__init__(json5_file_path, output_dir)
MakeMediaFeatureNamesWriter.filters['symbol'] = (
media_feature_symbol.getMediaFeatureSymbolWithSuffix('MediaFeature'))
if __name__ == "__main__":
json5_generator.Maker(MakeMediaFeatureNamesWriter).main()
......@@ -35,7 +35,8 @@ import json5_generator
import template_expander
import name_utilities
def _symbol(entry):
def _legacy_symbol(entry):
if entry['Symbol'] is not None:
return entry['Symbol']
# FIXME: Remove this special case for the ugly x-webkit-foo attributes.
......@@ -44,6 +45,12 @@ def _symbol(entry):
return name_utilities.cpp_name(entry).replace('-', '_').replace(' ', '_')
def _symbol(entry):
if entry['Symbol'] is not None:
return entry['Symbol']
return 'k' + entry['name'].to_upper_camel_case()
class MakeNamesWriter(json5_generator.Writer):
default_parameters = {
'Conditional': {}, # FIXME: Add support for Conditional.
......@@ -71,6 +78,11 @@ class MakeNamesWriter(json5_generator.Writer):
export = self.json5_file.metadata['export'].strip('"')
assert namespace, 'A namespace is required.'
# TODO(tkent): Remove the following condition. Namespace fields of all
# foo_names.json5 should be lower-cased. crbug.com/889726
if namespace.lower() != namespace:
namespace = namespace + 'Names'
MakeNamesWriter.filters['symbol'] = _legacy_symbol
basename, _ = os.path.splitext(os.path.basename(json5_file_path[0]))
self._outputs = {
......
......@@ -8,7 +8,7 @@
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink {
namespace {{namespace}}Names {
namespace {{namespace}} {
void* {{suffix}}NamesStorage[k{{suffix}}NamesCount * ((sizeof(AtomicString) + sizeof(void *) - 1) / sizeof(void *))];
......@@ -40,5 +40,5 @@ void init{{suffix}}() {
}
}
} // {{namespace}}Names
} // namespace blink
} // namespace {{namespace}}
} // namespace blink
......@@ -17,7 +17,7 @@
{% endif %}
namespace blink {
namespace {{namespace}}Names {
namespace {{namespace}} {
{% for entry in entries|sort %}
{{symbol_export}}extern const WTF::AtomicString& {{entry|symbol}};
......@@ -27,7 +27,7 @@ constexpr unsigned k{{suffix}}NamesCount = {{entries|length}};
{{symbol_export}}void init{{suffix}}();
} // {{namespace}}Names
} // namespace {{namespace}}
} // namespace blink
#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