| OLD | NEW |
| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if 'description' not in json: | 100 if 'description' not in json: |
| 101 # TODO(kalman): Go back to throwing an error here. | 101 # TODO(kalman): Go back to throwing an error here. |
| 102 print('%s must have a "description" field. This will appear ' | 102 print('%s must have a "description" field. This will appear ' |
| 103 'on the API summary page.' % self.name) | 103 'on the API summary page.' % self.name) |
| 104 json['description'] = '' | 104 json['description'] = '' |
| 105 self.description = json['description'] | 105 self.description = json['description'] |
| 106 self.deprecated = json.get('deprecated', None) | 106 self.deprecated = json.get('deprecated', None) |
| 107 self.unix_name = UnixName(self.name) | 107 self.unix_name = UnixName(self.name) |
| 108 self.source_file = source_file | 108 self.source_file = source_file |
| 109 self.source_file_dir, self.source_file_filename = os.path.split(source_file) | 109 self.source_file_dir, self.source_file_filename = os.path.split(source_file) |
| 110 self.short_filename = os.path.basename(source_file).split('.')[0] |
| 110 self.parent = None | 111 self.parent = None |
| 111 self.platforms = _GetPlatforms(json) | 112 self.platforms = _GetPlatforms(json) |
| 112 toplevel_origin = Origin(from_client=True, from_json=True) | 113 toplevel_origin = Origin(from_client=True, from_json=True) |
| 113 self.types = _GetTypes(self, json, self, toplevel_origin) | 114 self.types = _GetTypes(self, json, self, toplevel_origin) |
| 114 self.functions = _GetFunctions(self, json, self) | 115 self.functions = _GetFunctions(self, json, self) |
| 115 self.events = _GetEvents(self, json, self) | 116 self.events = _GetEvents(self, json, self) |
| 116 self.properties = _GetProperties(self, json, self, toplevel_origin) | 117 self.properties = _GetProperties(self, json, self, toplevel_origin) |
| 117 if include_compiler_options: | 118 if include_compiler_options: |
| 118 self.compiler_options = json.get('compiler_options', {}) | 119 self.compiler_options = json.get('compiler_options', {}) |
| 119 else: | 120 else: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if json_type == 'array': | 183 if json_type == 'array': |
| 183 self.property_type = PropertyType.ARRAY | 184 self.property_type = PropertyType.ARRAY |
| 184 self.item_type = Type( | 185 self.item_type = Type( |
| 185 self, '%sType' % name, json['items'], namespace, origin) | 186 self, '%sType' % name, json['items'], namespace, origin) |
| 186 elif '$ref' in json: | 187 elif '$ref' in json: |
| 187 self.property_type = PropertyType.REF | 188 self.property_type = PropertyType.REF |
| 188 self.ref_type = json['$ref'] | 189 self.ref_type = json['$ref'] |
| 189 elif 'enum' in json and json_type == 'string': | 190 elif 'enum' in json and json_type == 'string': |
| 190 self.property_type = PropertyType.ENUM | 191 self.property_type = PropertyType.ENUM |
| 191 self.enum_values = [EnumValue(value) for value in json['enum']] | 192 self.enum_values = [EnumValue(value) for value in json['enum']] |
| 193 self.cpp_omit_enum_type = 'cpp_omit_enum_type' in json |
| 192 elif json_type == 'any': | 194 elif json_type == 'any': |
| 193 self.property_type = PropertyType.ANY | 195 self.property_type = PropertyType.ANY |
| 194 elif json_type == 'binary': | 196 elif json_type == 'binary': |
| 195 self.property_type = PropertyType.BINARY | 197 self.property_type = PropertyType.BINARY |
| 196 elif json_type == 'boolean': | 198 elif json_type == 'boolean': |
| 197 self.property_type = PropertyType.BOOLEAN | 199 self.property_type = PropertyType.BOOLEAN |
| 198 elif json_type == 'integer': | 200 elif json_type == 'integer': |
| 199 self.property_type = PropertyType.INTEGER | 201 self.property_type = PropertyType.INTEGER |
| 200 elif (json_type == 'double' or | 202 elif (json_type == 'double' or |
| 201 json_type == 'number'): | 203 json_type == 'number'): |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 # Sanity check: platforms should not be an empty list. | 570 # Sanity check: platforms should not be an empty list. |
| 569 if not json['platforms']: | 571 if not json['platforms']: |
| 570 raise ValueError('"platforms" cannot be an empty list') | 572 raise ValueError('"platforms" cannot be an empty list') |
| 571 platforms = [] | 573 platforms = [] |
| 572 for platform_name in json['platforms']: | 574 for platform_name in json['platforms']: |
| 573 for platform_enum in _Enum.GetAll(Platforms): | 575 for platform_enum in _Enum.GetAll(Platforms): |
| 574 if platform_name == platform_enum.name: | 576 if platform_name == platform_enum.name: |
| 575 platforms.append(platform_enum) | 577 platforms.append(platform_enum) |
| 576 break | 578 break |
| 577 return platforms | 579 return platforms |
| OLD | NEW |