 Chromium Code Reviews
 Chromium Code Reviews Issue 12315074:
  Fix problem with non void return types in extension API IDL.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 12315074:
  Fix problem with non void return types in extension API IDL.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python | 
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be | 
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. | 
| 5 | 5 | 
| 6 import itertools | 6 import itertools | 
| 7 import json | 7 import json | 
| 8 import os.path | 8 import os.path | 
| 9 import re | 9 import re | 
| 10 import sys | 10 import sys | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 param_comment_start = cur_param.end() | 81 param_comment_start = cur_param.end() | 
| 82 param_comment_end = next_param.start() if next_param else len(comment) | 82 param_comment_end = next_param.start() if next_param else len(comment) | 
| 83 params[param_name] = (comment[param_comment_start:param_comment_end | 83 params[param_name] = (comment[param_comment_start:param_comment_end | 
| 84 ].strip().replace('\n\n', '<br/><br/>') | 84 ].strip().replace('\n\n', '<br/><br/>') | 
| 85 .replace('\n', '')) | 85 .replace('\n', '')) | 
| 86 return (parent_comment, params) | 86 return (parent_comment, params) | 
| 87 | 87 | 
| 88 class Callspec(object): | 88 class Callspec(object): | 
| 89 ''' | 89 ''' | 
| 90 Given a Callspec node representing an IDL function declaration, converts into | 90 Given a Callspec node representing an IDL function declaration, converts into | 
| 91 a name/value pair where the value is a list of function parameters. | 91 a tuple: | 
| 92 (name, list of function parameters, return type) | |
| 92 ''' | 93 ''' | 
| 93 def __init__(self, callspec_node, comment): | 94 def __init__(self, callspec_node, comment): | 
| 94 self.node = callspec_node | 95 self.node = callspec_node | 
| 95 self.comment = comment | 96 self.comment = comment | 
| 96 | 97 | 
| 97 def process(self, callbacks): | 98 def process(self, callbacks): | 
| 98 parameters = [] | 99 parameters = [] | 
| 100 return_type = None | |
| 101 if self.node.GetProperty('TYPEREF') not in ['void', None]: | |
| 102 return_type = Typeref(self.node.GetProperty('TYPEREF'), | |
| 103 self.node, | |
| 104 {'name': self.node.GetName()}).process(callbacks) | |
| 105 if return_type.get('type', '') == 'object' or '$ref' in return_type: | |
| 
not at google - send to devlin
2013/02/25 18:00:43
the second argument to .get is unnecessary, it's i
 
benwells
2013/02/26 04:19:07
Done.
 | |
| 106 return_type['optional'] = True; | |
| 
not at google - send to devlin
2013/02/25 18:00:43
Yes it would be much preferable to fix this by ann
 
benwells
2013/02/26 04:19:07
Yep, that would be nicer. The idl parser doesn't s
 | |
| 99 for node in self.node.children: | 107 for node in self.node.children: | 
| 100 parameter = Param(node).process(callbacks) | 108 parameter = Param(node).process(callbacks) | 
| 101 if parameter['name'] in self.comment: | 109 if parameter['name'] in self.comment: | 
| 102 parameter['description'] = self.comment[parameter['name']] | 110 parameter['description'] = self.comment[parameter['name']] | 
| 103 parameters.append(parameter) | 111 parameters.append(parameter) | 
| 104 return self.node.GetName(), parameters | 112 return (self.node.GetName(), parameters, return_type) | 
| 105 | 113 | 
| 106 class Param(object): | 114 class Param(object): | 
| 107 ''' | 115 ''' | 
| 108 Given a Param node representing a function parameter, converts into a Python | 116 Given a Param node representing a function parameter, converts into a Python | 
| 109 dictionary that the JSON schema compiler expects to see. | 117 dictionary that the JSON schema compiler expects to see. | 
| 110 ''' | 118 ''' | 
| 111 def __init__(self, param_node): | 119 def __init__(self, param_node): | 
| 112 self.node = param_node | 120 self.node = param_node | 
| 113 | 121 | 
| 114 def process(self, callbacks): | 122 def process(self, callbacks): | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 if self.node.GetProperty(property_name): | 162 if self.node.GetProperty(property_name): | 
| 155 properties[property_name.lower()] = True | 163 properties[property_name.lower()] = True | 
| 156 is_function = False | 164 is_function = False | 
| 157 parameter_comments = OrderedDict() | 165 parameter_comments = OrderedDict() | 
| 158 for node in self.node.children: | 166 for node in self.node.children: | 
| 159 if node.cls == 'Comment': | 167 if node.cls == 'Comment': | 
| 160 (parent_comment, parameter_comments) = ProcessComment(node.GetName()) | 168 (parent_comment, parameter_comments) = ProcessComment(node.GetName()) | 
| 161 properties['description'] = parent_comment | 169 properties['description'] = parent_comment | 
| 162 elif node.cls == 'Callspec': | 170 elif node.cls == 'Callspec': | 
| 163 is_function = True | 171 is_function = True | 
| 164 name, parameters = Callspec(node, parameter_comments).process(callbacks) | 172 name, parameters, return_type = (Callspec(node, parameter_comments) | 
| 173 .process(callbacks)) | |
| 165 properties['parameters'] = parameters | 174 properties['parameters'] = parameters | 
| 175 if return_type is not None: | |
| 176 properties['returns'] = return_type | |
| 166 properties['name'] = name | 177 properties['name'] = name | 
| 167 if is_function: | 178 if is_function: | 
| 168 properties['type'] = 'function' | 179 properties['type'] = 'function' | 
| 169 else: | 180 else: | 
| 170 properties = Typeref(self.node.GetProperty('TYPEREF'), | 181 properties = Typeref(self.node.GetProperty('TYPEREF'), | 
| 171 self.node, properties).process(callbacks) | 182 self.node, properties).process(callbacks) | 
| 172 enum_values = self.node.GetProperty('legalValues') | 183 enum_values = self.node.GetProperty('legalValues') | 
| 173 if enum_values: | 184 if enum_values: | 
| 174 if properties['type'] == 'integer': | 185 if properties['type'] == 'integer': | 
| 175 enum_values = map(int, enum_values) | 186 enum_values = map(int, enum_values) | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 properties['type'] = 'object' | 230 properties['type'] = 'object' | 
| 220 if 'additionalProperties' not in properties: | 231 if 'additionalProperties' not in properties: | 
| 221 properties['additionalProperties'] = OrderedDict() | 232 properties['additionalProperties'] = OrderedDict() | 
| 222 properties['additionalProperties']['type'] = 'any' | 233 properties['additionalProperties']['type'] = 'any' | 
| 223 instance_of = self.parent.GetProperty('instanceOf') | 234 instance_of = self.parent.GetProperty('instanceOf') | 
| 224 if instance_of: | 235 if instance_of: | 
| 225 properties['isInstanceOf'] = instance_of | 236 properties['isInstanceOf'] = instance_of | 
| 226 elif self.typeref == 'ArrayBuffer': | 237 elif self.typeref == 'ArrayBuffer': | 
| 227 properties['type'] = 'binary' | 238 properties['type'] = 'binary' | 
| 228 properties['isInstanceOf'] = 'ArrayBuffer' | 239 properties['isInstanceOf'] = 'ArrayBuffer' | 
| 240 elif self.typeref == 'FileEntry': | |
| 241 properties['type'] = 'object' | |
| 242 properties['isInstanceOf'] = 'FileEntry' | |
| 243 if 'additionalProperties' not in properties: | |
| 244 properties['additionalProperties'] = OrderedDict() | |
| 245 properties['additionalProperties']['type'] = 'any' | |
| 
not at google - send to devlin
2013/02/25 18:00:43
I think we're going to want a way to actually anno
 
benwells
2013/02/26 04:19:07
Sounds good.
 
not at google - send to devlin
2013/02/26 05:31:58
which I suppose would just be adding support for [
 
not at google - send to devlin
2013/02/26 05:54:20
I haven't dealt with it much; my understanding was
 | |
| 229 elif self.typeref is None: | 246 elif self.typeref is None: | 
| 230 properties['type'] = 'function' | 247 properties['type'] = 'function' | 
| 231 else: | 248 else: | 
| 232 if self.typeref in callbacks: | 249 if self.typeref in callbacks: | 
| 233 # Do not override name and description if they are already specified. | 250 # Do not override name and description if they are already specified. | 
| 234 name = properties.get('name', None) | 251 name = properties.get('name', None) | 
| 235 description = properties.get('description', None) | 252 description = properties.get('description', None) | 
| 236 properties.update(callbacks[self.typeref]) | 253 properties.update(callbacks[self.typeref]) | 
| 237 if description is not None: | 254 if description is not None: | 
| 238 properties['description'] = description | 255 properties['description'] = description | 
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 ''' | 390 ''' | 
| 374 Dump a json serialization of parse result for the IDL files whose names | 391 Dump a json serialization of parse result for the IDL files whose names | 
| 375 were passed in on the command line. | 392 were passed in on the command line. | 
| 376 ''' | 393 ''' | 
| 377 for filename in sys.argv[1:]: | 394 for filename in sys.argv[1:]: | 
| 378 schema = Load(filename) | 395 schema = Load(filename) | 
| 379 print json.dumps(schema, indent=2) | 396 print json.dumps(schema, indent=2) | 
| 380 | 397 | 
| 381 if __name__ == '__main__': | 398 if __name__ == '__main__': | 
| 382 Main() | 399 Main() | 
| OLD | NEW |