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

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

Issue 143473003: Generate ax enums from idl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add allow custom filename property to top level idl. Created 6 years, 11 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 | Annotate | Revision Log
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 self.name = json['namespace'] 98 self.name = json['namespace']
99 if 'description' not in json: 99 if 'description' not in json:
100 # TODO(kalman): Go back to throwing an error here. 100 # TODO(kalman): Go back to throwing an error here.
101 print('%s must have a "description" field. This will appear ' 101 print('%s must have a "description" field. This will appear '
102 'on the API summary page.' % self.name) 102 'on the API summary page.' % self.name)
103 json['description'] = '' 103 json['description'] = ''
104 self.description = json['description'] 104 self.description = json['description']
105 self.unix_name = UnixName(self.name) 105 self.unix_name = UnixName(self.name)
106 self.source_file = source_file 106 self.source_file = source_file
107 self.source_file_dir, self.source_file_filename = os.path.split(source_file) 107 self.source_file_dir, self.source_file_filename = os.path.split(source_file)
108 self.short_filename = os.path.basename(source_file).split('.')[0]
108 self.parent = None 109 self.parent = None
109 self.platforms = _GetPlatforms(json) 110 self.platforms = _GetPlatforms(json)
110 toplevel_origin = Origin(from_client=True, from_json=True) 111 toplevel_origin = Origin(from_client=True, from_json=True)
111 self.types = _GetTypes(self, json, self, toplevel_origin) 112 self.types = _GetTypes(self, json, self, toplevel_origin)
112 self.functions = _GetFunctions(self, json, self) 113 self.functions = _GetFunctions(self, json, self)
113 self.events = _GetEvents(self, json, self) 114 self.events = _GetEvents(self, json, self)
114 self.properties = _GetProperties(self, json, self, toplevel_origin) 115 self.properties = _GetProperties(self, json, self, toplevel_origin)
115 if include_compiler_options: 116 if include_compiler_options:
116 self.compiler_options = json.get('compiler_options', {}) 117 self.compiler_options = json.get('compiler_options', {})
117 else: 118 else:
118 self.compiler_options = {} 119 self.compiler_options = {}
119 self.documentation_options = json.get('documentation_options', {}) 120 self.documentation_options = json.get('documentation_options', {})
121 if 'allow_custom_filename' in json:
122 self.allow_custom_filename = json['allow_custom_filename']
123 else:
124 self.allow_custom_filename = False
120 125
121 126
122 class Origin(object): 127 class Origin(object):
123 """Stores the possible origin of model object as a pair of bools. These are: 128 """Stores the possible origin of model object as a pair of bools. These are:
124 129
125 |from_client| indicating that instances can originate from users of 130 |from_client| indicating that instances can originate from users of
126 generated code (for example, function results), or 131 generated code (for example, function results), or
127 |from_json| indicating that instances can originate from the JSON (for 132 |from_json| indicating that instances can originate from the JSON (for
128 example, function parameters) 133 example, function parameters)
129 134
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if json_type == 'array': 185 if json_type == 'array':
181 self.property_type = PropertyType.ARRAY 186 self.property_type = PropertyType.ARRAY
182 self.item_type = Type( 187 self.item_type = Type(
183 self, '%sType' % name, json['items'], namespace, origin) 188 self, '%sType' % name, json['items'], namespace, origin)
184 elif '$ref' in json: 189 elif '$ref' in json:
185 self.property_type = PropertyType.REF 190 self.property_type = PropertyType.REF
186 self.ref_type = json['$ref'] 191 self.ref_type = json['$ref']
187 elif 'enum' in json and json_type == 'string': 192 elif 'enum' in json and json_type == 'string':
188 self.property_type = PropertyType.ENUM 193 self.property_type = PropertyType.ENUM
189 self.enum_values = [EnumValue(value) for value in json['enum']] 194 self.enum_values = [EnumValue(value) for value in json['enum']]
195 self.cpp_omit_enum_type = 'cpp_omit_enum_type' in json
190 elif json_type == 'any': 196 elif json_type == 'any':
191 self.property_type = PropertyType.ANY 197 self.property_type = PropertyType.ANY
192 elif json_type == 'binary': 198 elif json_type == 'binary':
193 self.property_type = PropertyType.BINARY 199 self.property_type = PropertyType.BINARY
194 elif json_type == 'boolean': 200 elif json_type == 'boolean':
195 self.property_type = PropertyType.BOOLEAN 201 self.property_type = PropertyType.BOOLEAN
196 elif json_type == 'integer': 202 elif json_type == 'integer':
197 self.property_type = PropertyType.INTEGER 203 self.property_type = PropertyType.INTEGER
198 elif (json_type == 'double' or 204 elif (json_type == 'double' or
199 json_type == 'number'): 205 json_type == 'number'):
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 # Sanity check: platforms should not be an empty list. 572 # Sanity check: platforms should not be an empty list.
567 if not json['platforms']: 573 if not json['platforms']:
568 raise ValueError('"platforms" cannot be an empty list') 574 raise ValueError('"platforms" cannot be an empty list')
569 platforms = [] 575 platforms = []
570 for platform_name in json['platforms']: 576 for platform_name in json['platforms']:
571 for platform_enum in _Enum.GetAll(Platforms): 577 for platform_enum in _Enum.GetAll(Platforms):
572 if platform_name == platform_enum.name: 578 if platform_name == platform_enum.name:
573 platforms.append(platform_enum) 579 platforms.append(platform_enum)
574 break 580 break
575 return platforms 581 return platforms
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698