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

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

Issue 1982193002: Add enum class support to json_schema_compiler (idl files) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit python style Created 4 years, 7 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 import os.path 5 import os.path
6 6
7 from json_parse import OrderedDict 7 from json_parse import OrderedDict
8 from memoize import memoize 8 from memoize import memoize
9 9
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 self.ref_type = json['$ref'] 203 self.ref_type = json['$ref']
204 elif 'enum' in json and json_type == 'string': 204 elif 'enum' in json and json_type == 'string':
205 if not namespace.allow_inline_enums and not isinstance(parent, Namespace): 205 if not namespace.allow_inline_enums and not isinstance(parent, Namespace):
206 raise ParseException( 206 raise ParseException(
207 self, 207 self,
208 'Inline enum "%s" found in namespace "%s". These are not allowed. ' 208 'Inline enum "%s" found in namespace "%s". These are not allowed. '
209 'See crbug.com/472279' % (name, namespace.name)) 209 'See crbug.com/472279' % (name, namespace.name))
210 self.property_type = PropertyType.ENUM 210 self.property_type = PropertyType.ENUM
211 self.enum_values = [EnumValue(value) for value in json['enum']] 211 self.enum_values = [EnumValue(value) for value in json['enum']]
212 self.cpp_enum_prefix_override = json.get('cpp_enum_prefix_override', None) 212 self.cpp_enum_prefix_override = json.get('cpp_enum_prefix_override', None)
213 self.is_class = json.get('class', False)
213 elif json_type == 'any': 214 elif json_type == 'any':
214 self.property_type = PropertyType.ANY 215 self.property_type = PropertyType.ANY
215 elif json_type == 'binary': 216 elif json_type == 'binary':
216 self.property_type = PropertyType.BINARY 217 self.property_type = PropertyType.BINARY
217 elif json_type == 'boolean': 218 elif json_type == 'boolean':
218 self.property_type = PropertyType.BOOLEAN 219 self.property_type = PropertyType.BOOLEAN
219 elif json_type == 'integer': 220 elif json_type == 'integer':
220 self.property_type = PropertyType.INTEGER 221 self.property_type = PropertyType.INTEGER
221 elif (json_type == 'double' or 222 elif (json_type == 'double' or
222 json_type == 'number'): 223 json_type == 'number'):
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 # Sanity check: platforms should not be an empty list. 609 # Sanity check: platforms should not be an empty list.
609 if not json['platforms']: 610 if not json['platforms']:
610 raise ValueError('"platforms" cannot be an empty list') 611 raise ValueError('"platforms" cannot be an empty list')
611 platforms = [] 612 platforms = []
612 for platform_name in json['platforms']: 613 for platform_name in json['platforms']:
613 for platform_enum in _Enum.GetAll(Platforms): 614 for platform_enum in _Enum.GetAll(Platforms):
614 if platform_name == platform_enum.name: 615 if platform_name == platform_enum.name:
615 platforms.append(platform_enum) 616 platforms.append(platform_enum)
616 break 617 break
617 return platforms 618 return platforms
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698