| 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) | 
| 99     for node in self.node.children: | 105     for node in self.node.children: | 
| 100       parameter = Param(node).process(callbacks) | 106       parameter = Param(node).process(callbacks) | 
| 101       if parameter['name'] in self.comment: | 107       if parameter['name'] in self.comment: | 
| 102         parameter['description'] = self.comment[parameter['name']] | 108         parameter['description'] = self.comment[parameter['name']] | 
| 103       parameters.append(parameter) | 109       parameters.append(parameter) | 
| 104     return self.node.GetName(), parameters | 110     return (self.node.GetName(), parameters, return_type) | 
| 105 | 111 | 
| 106 class Param(object): | 112 class Param(object): | 
| 107   ''' | 113   ''' | 
| 108   Given a Param node representing a function parameter, converts into a Python | 114   Given a Param node representing a function parameter, converts into a Python | 
| 109   dictionary that the JSON schema compiler expects to see. | 115   dictionary that the JSON schema compiler expects to see. | 
| 110   ''' | 116   ''' | 
| 111   def __init__(self, param_node): | 117   def __init__(self, param_node): | 
| 112     self.node = param_node | 118     self.node = param_node | 
| 113 | 119 | 
| 114   def process(self, callbacks): | 120   def process(self, callbacks): | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154       if self.node.GetProperty(property_name): | 160       if self.node.GetProperty(property_name): | 
| 155         properties[property_name.lower()] = True | 161         properties[property_name.lower()] = True | 
| 156     is_function = False | 162     is_function = False | 
| 157     parameter_comments = OrderedDict() | 163     parameter_comments = OrderedDict() | 
| 158     for node in self.node.children: | 164     for node in self.node.children: | 
| 159       if node.cls == 'Comment': | 165       if node.cls == 'Comment': | 
| 160         (parent_comment, parameter_comments) = ProcessComment(node.GetName()) | 166         (parent_comment, parameter_comments) = ProcessComment(node.GetName()) | 
| 161         properties['description'] = parent_comment | 167         properties['description'] = parent_comment | 
| 162       elif node.cls == 'Callspec': | 168       elif node.cls == 'Callspec': | 
| 163         is_function = True | 169         is_function = True | 
| 164         name, parameters = Callspec(node, parameter_comments).process(callbacks) | 170         name, parameters, return_type = (Callspec(node, parameter_comments) | 
|  | 171                                          .process(callbacks)) | 
| 165         properties['parameters'] = parameters | 172         properties['parameters'] = parameters | 
|  | 173         if return_type is not None: | 
|  | 174           properties['returns'] = return_type | 
| 166     properties['name'] = name | 175     properties['name'] = name | 
| 167     if is_function: | 176     if is_function: | 
| 168       properties['type'] = 'function' | 177       properties['type'] = 'function' | 
| 169     else: | 178     else: | 
| 170       properties = Typeref(self.node.GetProperty('TYPEREF'), | 179       properties = Typeref(self.node.GetProperty('TYPEREF'), | 
| 171                            self.node, properties).process(callbacks) | 180                            self.node, properties).process(callbacks) | 
| 172     enum_values = self.node.GetProperty('legalValues') | 181     enum_values = self.node.GetProperty('legalValues') | 
| 173     if enum_values: | 182     if enum_values: | 
| 174       if properties['type'] == 'integer': | 183       if properties['type'] == 'integer': | 
| 175         enum_values = map(int, enum_values) | 184         enum_values = map(int, enum_values) | 
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 373   ''' | 382   ''' | 
| 374   Dump a json serialization of parse result for the IDL files whose names | 383   Dump a json serialization of parse result for the IDL files whose names | 
| 375   were passed in on the command line. | 384   were passed in on the command line. | 
| 376   ''' | 385   ''' | 
| 377   for filename in sys.argv[1:]: | 386   for filename in sys.argv[1:]: | 
| 378     schema = Load(filename) | 387     schema = Load(filename) | 
| 379     print json.dumps(schema, indent=2) | 388     print json.dumps(schema, indent=2) | 
| 380 | 389 | 
| 381 if __name__ == '__main__': | 390 if __name__ == '__main__': | 
| 382   Main() | 391   Main() | 
| OLD | NEW | 
|---|