Commit d843375f authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

blinkbuild: Remove class_member_name() in name_utilities.py.

Add to_class_data_member() to NameStyleConverter, and use it instead
of class_member_name().

* make_runtime_features.py:
 - Remove feature.class_member_name. Replace its usage with
   {{feature.name.to_class_data_member()}}.
 - Introduce _data_member_name() and feature.data_member_name.
   'is_{{snake_case_name}}_enabled_' is used repeatedly in the python
   code and the templates.

This CL doesn't change generated C++ code.

Bug: 843927
Change-Id: I3b80460a05b155278a5f0bf46bddf0051a768457
Reviewed-on: https://chromium-review.googlesource.com/1073173Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561821}
parent c6fb49f6
...@@ -178,3 +178,11 @@ class NameStyleConverter(object): ...@@ -178,3 +178,11 @@ class NameStyleConverter(object):
'upper_camel_case': self.to_upper_camel_case(), 'upper_camel_case': self.to_upper_camel_case(),
'macro_case': self.to_macro_case(), 'macro_case': self.to_macro_case(),
} }
# Use the following high level naming functions which describe the semantics
# of the name, rather than a particular style.
def to_class_data_member(self, prefix=None, suffix=None):
lower_prefix = prefix.lower() + '_' if prefix else ''
lower_suffix = suffix.lower() + '_' if suffix else ''
return lower_prefix + self.to_snake_case() + '_' + lower_suffix
...@@ -130,6 +130,14 @@ class NameStyleConverterTest(unittest.TestCase): ...@@ -130,6 +130,14 @@ class NameStyleConverterTest(unittest.TestCase):
converter = NameStyleConverter('HTMLElement') converter = NameStyleConverter('HTMLElement')
self.assertEqual(converter.to_snake_case(), 'html_element') self.assertEqual(converter.to_snake_case(), 'html_element')
def test_to_class_data_member(self):
converter = NameStyleConverter('HTMLElement')
self.assertEqual(converter.to_class_data_member(), 'html_element_')
self.assertEqual(converter.to_class_data_member(prefix='is'), 'is_html_element_')
self.assertEqual(converter.to_class_data_member(suffix='enabled'), 'html_element_enabled_')
self.assertEqual(converter.to_class_data_member(prefix='is', suffix='enabled'), 'is_html_element_enabled_')
self.assertEqual(converter.to_class_data_member(prefix='fooBar', suffix='V0V8'), 'foobar_html_element_v0v8_')
def test_upper_camel_case(self): def test_upper_camel_case(self):
converter = NameStyleConverter('someSuperThing') converter = NameStyleConverter('someSuperThing')
self.assertEqual(converter.to_upper_camel_case(), 'SomeSuperThing') self.assertEqual(converter.to_upper_camel_case(), 'SomeSuperThing')
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
from name_utilities import (
enum_value_name, class_member_name, method_name, class_name
)
from itertools import chain from itertools import chain
from blinkbuild.name_style_converter import NameStyleConverter
from name_utilities import class_name, enum_value_name, method_name
def _flatten_list(x): def _flatten_list(x):
"""Flattens a list of lists into a single list.""" """Flattens a list of lists into a single list."""
...@@ -31,7 +30,7 @@ class Group(object): ...@@ -31,7 +30,7 @@ class Group(object):
"""Represents a group of fields stored together in a class. """Represents a group of fields stored together in a class.
Attributes: Attributes:
name: The name of the group as a string. name: The name of the group as a string, or None.
subgroups: List of Group instances that are stored as subgroups under subgroups: List of Group instances that are stored as subgroups under
this group. this group.
fields: List of Field instances stored directly under this group. fields: List of Field instances stored directly under this group.
...@@ -43,8 +42,9 @@ class Group(object): ...@@ -43,8 +42,9 @@ class Group(object):
self.fields = fields self.fields = fields
self.parent = None self.parent = None
name = name or ''
self.type_name = class_name(['style', name, 'data']) self.type_name = class_name(['style', name, 'data'])
self.member_name = class_member_name([name, 'data']) self.member_name = NameStyleConverter(name).to_class_data_member(suffix='data')
self.num_32_bit_words_for_bit_fields = _num_32_bit_words_for_bit_fields( self.num_32_bit_words_for_bit_fields = _num_32_bit_words_for_bit_fields(
field for field in fields if field.is_bit_field field for field in fields if field.is_bit_field
) )
...@@ -138,7 +138,7 @@ class Field(object): ...@@ -138,7 +138,7 @@ class Field(object):
custom_copy, custom_compare, mutable, getter_method_name, custom_copy, custom_compare, mutable, getter_method_name,
setter_method_name, initial_method_name, setter_method_name, initial_method_name,
computed_style_custom_functions, **kwargs): computed_style_custom_functions, **kwargs):
self.name = class_member_name(name_for_methods) self.name = NameStyleConverter(name_for_methods).to_class_data_member()
self.property_name = property_name self.property_name = property_name
self.type_name = type_name self.type_name = type_name
self.wrapper_pointer_name = wrapper_pointer_name self.wrapper_pointer_name = wrapper_pointer_name
......
...@@ -12,7 +12,7 @@ import keyword_utils ...@@ -12,7 +12,7 @@ import keyword_utils
import bisect import bisect
from name_utilities import ( from name_utilities import (
enum_value_name, class_member_name, method_name, class_name, join_names enum_value_name, method_name, class_name, join_names
) )
from core.css import css_properties from core.css import css_properties
......
...@@ -31,8 +31,6 @@ import sys ...@@ -31,8 +31,6 @@ import sys
from blinkbuild.name_style_converter import NameStyleConverter from blinkbuild.name_style_converter import NameStyleConverter
import json5_generator import json5_generator
import name_utilities
from name_utilities import class_member_name
import template_expander import template_expander
...@@ -49,19 +47,24 @@ class RuntimeFeatureWriter(json5_generator.Writer): ...@@ -49,19 +47,24 @@ class RuntimeFeatureWriter(json5_generator.Writer):
self._features = self.json5_file.name_dictionaries self._features = self.json5_file.name_dictionaries
# Make sure the resulting dictionaries have all the keys we expect. # Make sure the resulting dictionaries have all the keys we expect.
for feature in self._features: for feature in self._features:
feature['class_member_name'] = class_member_name(feature['name'].original) feature['data_member_name'] = self._data_member_name(feature['name'])
# Most features just check their isFooEnabled bool # Most features just check their is_foo_enabled_ bool
# but some depend on or are implied by other bools. # but some depend on or are implied by other bools.
enabled_condition = 'is_%senabled_' % feature['class_member_name'] enabled_condition = feature['data_member_name']
assert not feature['implied_by'] or not feature['depends_on'], 'Only one of implied_by and depends_on is allowed' assert not feature['implied_by'] or not feature['depends_on'], 'Only one of implied_by and depends_on is allowed'
for implied_by_name in feature['implied_by']: for implied_by_name in feature['implied_by']:
enabled_condition += ' || is_%senabled_' % class_member_name(implied_by_name) enabled_condition += ' || ' + self._data_member_name(implied_by_name)
for dependant_name in feature['depends_on']: for dependant_name in feature['depends_on']:
enabled_condition += ' && is_%senabled_' % class_member_name(dependant_name) enabled_condition += ' && ' + self._data_member_name(dependant_name)
feature['enabled_condition'] = enabled_condition feature['enabled_condition'] = enabled_condition
self._standard_features = [feature for feature in self._features if not feature['custom']] self._standard_features = [feature for feature in self._features if not feature['custom']]
self._origin_trial_features = [feature for feature in self._features if feature['origin_trial_feature_name']] self._origin_trial_features = [feature for feature in self._features if feature['origin_trial_feature_name']]
@staticmethod
def _data_member_name(str_or_converter):
converter = NameStyleConverter(str_or_converter) if type(str_or_converter) is str else str_or_converter
return converter.to_class_data_member(prefix='is', suffix='enabled')
def _feature_sets(self): def _feature_sets(self):
# Another way to think of the status levels is as "sets of features" # Another way to think of the status levels is as "sets of features"
# which is how we're referring to them in this generator. # which is how we're referring to them in this generator.
......
...@@ -132,11 +132,6 @@ def class_name(words): ...@@ -132,11 +132,6 @@ def class_name(words):
return upper_camel_case(words) return upper_camel_case(words)
@naming_style
def class_member_name(words):
return snake_case(words) + "_"
@naming_style @naming_style
def method_name(words): def method_name(words):
return upper_camel_case(words) return upper_camel_case(words)
...@@ -13,9 +13,9 @@ namespace blink { ...@@ -13,9 +13,9 @@ namespace blink {
RuntimeEnabledFeatures::Backup::Backup() RuntimeEnabledFeatures::Backup::Backup()
: {% for feature in standard_features -%} : {% for feature in standard_features -%}
{% if feature.origin_trial_feature_name %} {% if feature.origin_trial_feature_name %}
{{feature.class_member_name}}(RuntimeEnabledFeatures::{{feature.name}}EnabledByRuntimeFlag()) {{feature.name.to_class_data_member()}}(RuntimeEnabledFeatures::{{feature.name}}EnabledByRuntimeFlag())
{% else %} {% else %}
{{feature.class_member_name}}(RuntimeEnabledFeatures::{{feature.name}}Enabled()) {{feature.name.to_class_data_member()}}(RuntimeEnabledFeatures::{{feature.name}}Enabled())
{% endif %} {% endif %}
{%- if not loop.last %}, {%- if not loop.last %},
{%+ endif -%} {%+ endif -%}
...@@ -23,7 +23,7 @@ RuntimeEnabledFeatures::Backup::Backup() ...@@ -23,7 +23,7 @@ RuntimeEnabledFeatures::Backup::Backup()
void RuntimeEnabledFeatures::Backup::Restore() { void RuntimeEnabledFeatures::Backup::Restore() {
{% for feature in standard_features %} {% for feature in standard_features %}
RuntimeEnabledFeatures::Set{{feature.name}}Enabled({{feature.class_member_name}}); RuntimeEnabledFeatures::Set{{feature.name}}Enabled({{feature.name.to_class_data_member()}});
{% endfor %} {% endfor %}
} }
...@@ -49,7 +49,7 @@ void RuntimeEnabledFeatures::SetFeatureEnabledFromString( ...@@ -49,7 +49,7 @@ void RuntimeEnabledFeatures::SetFeatureEnabledFromString(
bool* setting; bool* setting;
} kFeatures[] = { } kFeatures[] = {
{% for feature in standard_features %} {% for feature in standard_features %}
{"{{feature.name}}", &is_{{feature.class_member_name}}enabled_}, {"{{feature.name}}", &{{feature.data_member_name}}},
{% endfor %} {% endfor %}
}; };
for (const auto& feature : kFeatures) { for (const auto& feature : kFeatures) {
...@@ -62,7 +62,7 @@ void RuntimeEnabledFeatures::SetFeatureEnabledFromString( ...@@ -62,7 +62,7 @@ void RuntimeEnabledFeatures::SetFeatureEnabledFromString(
} }
{% for feature in standard_features %} {% for feature in standard_features %}
bool RuntimeEnabledFeatures::is_{{feature.class_member_name}}enabled_ = {{'true' if feature.status == 'stable' else 'false'}}; bool RuntimeEnabledFeatures::{{feature.data_member_name}} = {{'true' if feature.status == 'stable' else 'false'}};
{% endfor %} {% endfor %}
} // namespace blink } // namespace blink
...@@ -26,7 +26,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures { ...@@ -26,7 +26,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures {
private: private:
{% for feature in standard_features %} {% for feature in standard_features %}
bool {{feature.class_member_name}}; bool {{feature.name.to_class_data_member()}};
{% endfor %} {% endfor %}
}; };
...@@ -42,7 +42,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures { ...@@ -42,7 +42,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures {
{% if feature.custom %} {% if feature.custom %}
static bool {{feature.name}}Enabled(); static bool {{feature.name}}Enabled();
{% else %} {% else %}
static void Set{{feature.name}}Enabled(bool enabled) { is_{{feature.class_member_name}}enabled_ = enabled; } static void Set{{feature.name}}Enabled(bool enabled) { {{feature.data_member_name}} = enabled; }
static bool {{feature.name}}Enabled() { return {{feature.enabled_condition}}; } static bool {{feature.name}}Enabled() { return {{feature.enabled_condition}}; }
{% endif %} {% endif %}
...@@ -64,7 +64,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures { ...@@ -64,7 +64,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures {
{% if feature.custom %} {% if feature.custom %}
static bool {{feature.name}}EnabledByRuntimeFlag(); static bool {{feature.name}}EnabledByRuntimeFlag();
{% else %} {% else %}
static void Set{{feature.name}}Enabled(bool enabled) { is_{{feature.class_member_name}}enabled_ = enabled; } static void Set{{feature.name}}Enabled(bool enabled) { {{feature.data_member_name}} = enabled; }
static bool {{feature.name}}EnabledByRuntimeFlag() { return {{feature.enabled_condition}}; } static bool {{feature.name}}EnabledByRuntimeFlag() { return {{feature.enabled_condition}}; }
{% endif %} {% endif %}
...@@ -73,7 +73,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures { ...@@ -73,7 +73,7 @@ class PLATFORM_EXPORT RuntimeEnabledFeatures {
private: private:
{% for feature in standard_features %} {% for feature in standard_features %}
static bool is_{{feature.class_member_name}}enabled_; static bool {{feature.data_member_name}};
{% endfor %} {% endfor %}
}; };
......
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