Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: tools/json_schema_compiler/cc_generator.py

Issue 1829753003: [Extensions] Update generated code to support movable additional properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Antony's Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/cc_generator.py
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index 499671fde496b63bc79e33258811908fc9ff49e9..9bfd3e6c4e9b28f8686341cd352a0620829d4d07 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -213,14 +213,15 @@ class _Generator(object):
t = prop.type_
real_t = self._type_helper.FollowRef(t)
- if (prop.optional or
- t.property_type == PropertyType.ANY or
- t.property_type == PropertyType.ARRAY or
- t.property_type == PropertyType.BINARY or
- t.property_type == PropertyType.CHOICES or
- t.property_type == PropertyType.OBJECT or
- t.property_type == PropertyType.REF or
- t.property_type == PropertyType.STRING):
+ if (real_t.property_type != PropertyType.ENUM and
+ (prop.optional or
+ t.property_type == PropertyType.ANY or
+ t.property_type == PropertyType.ARRAY or
+ t.property_type == PropertyType.BINARY or
+ t.property_type == PropertyType.CHOICES or
+ t.property_type == PropertyType.OBJECT or
+ t.property_type == PropertyType.REF or
+ t.property_type == PropertyType.STRING)):
props.append(move_str % (prop.unix_name, prop.unix_name))
elif t.property_type == PropertyType.FUNCTION:
dicts.append(prop.unix_name)
@@ -232,6 +233,14 @@ class _Generator(object):
else:
raise TypeError(t)
+ if (type_.property_type == PropertyType.OBJECT and
+ type_.additional_properties is not None):
+ if type_.additional_properties.property_type == PropertyType.ANY:
+ dicts.append('additional_properties')
+ else:
+ props.append(move_str % ('additional_properties',
+ 'additional_properties'))
+
return (props, dicts)
def _GenerateMoveCtor(self, type_):
@@ -254,7 +263,7 @@ class _Generator(object):
if props:
s = s + '\n'.join(props)
for item in dicts:
- s = s + ('\n%s.Swap(&rhs.%s);' % (item, item))
+ s = s + ('%s.Swap(&rhs.%s);' % (item, item))
s = s + '\nreturn *this;\n}'
return Code().Append(s)
@@ -472,6 +481,7 @@ class _Generator(object):
# Non-copyable types will be wrapped in a linked_ptr for inclusion in
# maps, so we need to unwrap them.
needs_unwrap = (
+ not 'use_movable_types' in type_.namespace.compiler_options and
not self._type_helper.IsCopyable(type_.additional_properties))
(c.Sblock('for (const auto& it : additional_properties) {')
.Cblock(self._CreateValueFromType(
« no previous file with comments | « no previous file | tools/json_schema_compiler/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698