summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2015-01-15 17:49:49 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-16 01:50:32 +0000
commit51a694fc3fa02dbae89f8bf177aa0c0390fe1a9a (patch)
tree8b8793cf9d440af04812188d88cf7d5bd46790ca /tools/json_schema_compiler
parentbc20dbe7307d501ef132905845eb13e2db89539e (diff)
downloadchromium_src-51a694fc3fa02dbae89f8bf177aa0c0390fe1a9a.zip
chromium_src-51a694fc3fa02dbae89f8bf177aa0c0390fe1a9a.tar.gz
chromium_src-51a694fc3fa02dbae89f8bf177aa0c0390fe1a9a.tar.bz2
json_schema_compiler: Use range based for loops.
Review URL: https://codereview.chromium.org/853653002 Cr-Commit-Position: refs/heads/master@{#311811}
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r--tools/json_schema_compiler/cc_generator.py26
-rw-r--r--tools/json_schema_compiler/features_cc_generator.py7
-rw-r--r--tools/json_schema_compiler/util.h5
3 files changed, 13 insertions, 25 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index 23056db..0cc3a431 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -385,17 +385,12 @@ class _Generator(object):
# maps, so we need to unwrap them.
needs_unwrap = (
not self._type_helper.IsCopyable(type_.additional_properties))
- cpp_type = self._type_helper.GetCppType(type_.additional_properties,
- is_in_container=True)
- (c.Sblock('for (std::map<std::string, %s>::const_iterator it =' %
- cpp_util.PadForGenerics(cpp_type))
- .Append(' additional_properties.begin();')
- .Append(' it != additional_properties.end(); ++it) {')
+ (c.Sblock('for (const auto& it : additional_properties) {')
.Cblock(self._CreateValueFromType(
- 'value->SetWithoutPathExpansion(it->first, %s);',
+ 'value->SetWithoutPathExpansion(it.first, %s);',
type_.additional_properties.name,
type_.additional_properties,
- '%sit->second' % ('*' if needs_unwrap else '')))
+ '%sit.second' % ('*' if needs_unwrap else '')))
.Eblock('}')
)
@@ -491,7 +486,7 @@ class _Generator(object):
# not support passing a namespace as an argument.
item_type = self._type_helper.FollowRef(underlying_type.item_type)
if item_type.property_type == PropertyType.ENUM:
- vardot = '(%s)%s' % (var, '->' if is_ptr else '.')
+ varname = ('*' if is_ptr else '') + '(%s)' % var
maybe_namespace = ''
if type_.item_type.property_type == PropertyType.REF:
@@ -501,11 +496,9 @@ class _Generator(object):
# Scope the std::vector variable declaration inside braces.
(c.Sblock('{')
.Append('std::vector<std::string> %s;' % enum_list_var)
- .Append('for (std::vector<%s>::const_iterator it = %sbegin();'
- % (self._type_helper.GetCppType(item_type), vardot))
- .Sblock(' it != %send(); ++it) {' % vardot)
- .Append('%s.push_back(%sToString(*it));' % (enum_list_var,
- maybe_namespace))
+ .Append('for (const auto& it : %s) {' % varname)
+ .Append('%s.push_back(%sToString(it));' % (enum_list_var,
+ maybe_namespace))
.Eblock('}'))
# Because the std::vector above is always created for both required and
@@ -853,11 +846,10 @@ class _Generator(object):
cpp_type = self._type_helper.GetCppType(item_type, is_in_container=True)
c.Append('%s.reset(new std::vector<%s>);' %
(dst_var, cpp_util.PadForGenerics(cpp_type)))
- (c.Sblock('for (base::ListValue::const_iterator it = %s->begin(); '
- 'it != %s->end(); ++it) {' % (src_var, src_var))
+ (c.Sblock('for (const auto& it : *(%s)) {' % src_var)
.Append('%s tmp;' % self._type_helper.GetCppType(item_type))
.Concat(self._GenerateStringToEnumConversion(item_type,
- '(*it)',
+ '(it)',
'tmp',
failure_value))
.Append('%s%spush_back(tmp);' % (dst_var, accessor))
diff --git a/tools/json_schema_compiler/features_cc_generator.py b/tools/json_schema_compiler/features_cc_generator.py
index d3b3717..4af9aa7 100644
--- a/tools/json_schema_compiler/features_cc_generator.py
+++ b/tools/json_schema_compiler/features_cc_generator.py
@@ -81,11 +81,8 @@ class _Generator(object):
'const std::string& id) const {'
% (self._class_name, self._class_name))
.Sblock()
- .Append('std::map<std::string, %s::ID>::const_iterator it'
- ' = features_.find(id);' % self._class_name)
- .Append('if (it == features_.end())')
- .Append(' return kUnknown;')
- .Append('return it->second;')
+ .Append('const auto& it = features_.find(id);' % self._class_name)
+ .Append('return (it == features_.end()) ? kUnknown : it->second;')
.Eblock()
.Append('}')
.Append()
diff --git a/tools/json_schema_compiler/util.h b/tools/json_schema_compiler/util.h
index 228eced..a7e0a6e 100644
--- a/tools/json_schema_compiler/util.h
+++ b/tools/json_schema_compiler/util.h
@@ -141,9 +141,8 @@ void PopulateListFromArray(
const std::vector<T>& from,
base::ListValue* out) {
out->Clear();
- for (typename std::vector<T>::const_iterator it = from.begin();
- it != from.end(); ++it) {
- AddItemToList(*it, out);
+ for (const auto& it : from) {
+ AddItemToList(it, out);
}
}