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

Side by Side Diff: tools/json_schema_compiler/cc_generator.py

Issue 1100333006: Make the JSON Schema compiler handle enums declared in other namespaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import schema_util 8 import schema_util
9 import util_cc_helper 9 import util_cc_helper
10 from cpp_namespace_environment import CppNamespaceEnvironment 10 from cpp_namespace_environment import CppNamespaceEnvironment
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 (c.Sblock('scoped_ptr<base::DictionaryValue> %s::ToValue() const {' % 356 (c.Sblock('scoped_ptr<base::DictionaryValue> %s::ToValue() const {' %
357 cpp_namespace) 357 cpp_namespace)
358 .Append('scoped_ptr<base::DictionaryValue> value(' 358 .Append('scoped_ptr<base::DictionaryValue> value('
359 'new base::DictionaryValue());') 359 'new base::DictionaryValue());')
360 .Append() 360 .Append()
361 ) 361 )
362 362
363 for prop in type_.properties.values(): 363 for prop in type_.properties.values():
364 prop_var = 'this->%s' % prop.unix_name 364 prop_var = 'this->%s' % prop.unix_name
365 if prop.optional: 365 if prop.optional:
366 # Optional enum values are generated with a NONE enum value.
367 underlying_type = self._type_helper.FollowRef(prop.type_) 366 underlying_type = self._type_helper.FollowRef(prop.type_)
368 if underlying_type.property_type == PropertyType.ENUM: 367 if underlying_type.property_type == PropertyType.ENUM:
369 c.Sblock('if (%s != %s) {' % 368 # Optional enum values are generated with a NONE enum value,
369 # potentially from another namespace.
370 maybe_namespace = ''
371 if underlying_type.namespace != self._namespace:
372 maybe_namespace = '%s::' % underlying_type.namespace.unix_name
373 c.Sblock('if (%s != %s%s) {' %
Devlin 2015/04/23 23:26:51 Honestly, we should probably just fully specify ev
not at google - send to devlin 2015/04/23 23:28:45 Hah, yes, that would make things simpler.
370 (prop_var, 374 (prop_var,
375 maybe_namespace,
371 self._type_helper.GetEnumNoneValue(prop.type_))) 376 self._type_helper.GetEnumNoneValue(prop.type_)))
372 else: 377 else:
373 c.Sblock('if (%s.get()) {' % prop_var) 378 c.Sblock('if (%s.get()) {' % prop_var)
374 379
375 # ANY is a base::Value which is abstract and cannot be a direct member, so 380 # ANY is a base::Value which is abstract and cannot be a direct member, so
376 # it will always be a pointer. 381 # it will always be a pointer.
377 is_ptr = prop.optional or prop.type_.property_type == PropertyType.ANY 382 is_ptr = prop.optional or prop.type_.property_type == PropertyType.ANY
378 c.Cblock(self._CreateValueFromType( 383 c.Cblock(self._CreateValueFromType(
379 'value->SetWithoutPathExpansion("%s", %%s);' % prop.name, 384 'value->SetWithoutPathExpansion("%s", %%s);' % prop.name,
380 prop.name, 385 prop.name,
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 if self._generate_error_messages: 1068 if self._generate_error_messages:
1064 params = list(params) + ['base::string16* error'] 1069 params = list(params) + ['base::string16* error']
1065 return ', '.join(str(p) for p in params) 1070 return ', '.join(str(p) for p in params)
1066 1071
1067 def _GenerateArgs(self, args): 1072 def _GenerateArgs(self, args):
1068 """Builds the argument list for a function, given an array of arguments. 1073 """Builds the argument list for a function, given an array of arguments.
1069 """ 1074 """
1070 if self._generate_error_messages: 1075 if self._generate_error_messages:
1071 args = list(args) + ['error'] 1076 args = list(args) + ['error']
1072 return ', '.join(str(a) for a in args) 1077 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/h_generator.py » ('j') | tools/json_schema_compiler/h_generator.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698