| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| 11 import os | 11 import os |
| 12 import re | 12 import re |
| 13 import shutil | 13 import shutil |
| 14 from generator import * | 14 from generator import * |
| 15 | 15 |
| 16 _logger = logging.getLogger('dartgenerator') | 16 _logger = logging.getLogger('dartgenerator') |
| 17 | 17 |
| 18 def MergeNodes(node, other): | 18 def MergeNodes(node, other): |
| 19 node.operations.extend(other.operations) | 19 node.operations.extend(other.operations) |
| 20 for attribute in other.attributes: | 20 for attribute in other.attributes: |
| 21 if not node.has_attribute(attribute): | 21 if not node.has_attribute(attribute): |
| 22 node.attributes.append(attribute) | 22 node.attributes.append(attribute) |
| 23 | 23 |
| 24 node.constants.extend(other.constants) | 24 node.constants.extend(other.constants) |
| 25 | 25 |
| 26 class DartGenerator(object): | 26 class DartGenerator(object): |
| 27 """Utilities to generate Dart APIs and corresponding JavaScript.""" | 27 """Utilities to generate Dart APIs and corresponding JavaScript.""" |
| 28 | 28 |
| 29 def __init__(self): | 29 def __init__(self, logging_level=logging.WARNING): |
| 30 self._auxiliary_files = {} | 30 self._auxiliary_files = {} |
| 31 self._dart_templates_re = re.compile(r'[\w.:]+<([\w\.<>:]+)>') | 31 self._dart_templates_re = re.compile(r'[\w.:]+<([\w\.<>:]+)>') |
| 32 _logger.setLevel(logging_level) |
| 32 | 33 |
| 33 def _StripModules(self, type_name): | 34 def _StripModules(self, type_name): |
| 34 return type_name.split('::')[-1] | 35 return type_name.split('::')[-1] |
| 35 | 36 |
| 36 def _IsCompoundType(self, database, type_name): | 37 def _IsCompoundType(self, database, type_name): |
| 37 if IsRegisteredType(type_name): | 38 if IsRegisteredType(type_name): |
| 38 return True | 39 return True |
| 39 | 40 |
| 40 if type_name.endswith('?'): | 41 if type_name.endswith('?'): |
| 41 return self._IsCompoundType(database, type_name[:-len('?')]) | 42 return self._IsCompoundType(database, type_name[:-len('?')]) |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 def AddMissingArguments(self, database): | 228 def AddMissingArguments(self, database): |
| 228 ARG = idlnode.IDLArgument([('Type', ('ScopedName', 'object')), ('Id', 'arg')
]) | 229 ARG = idlnode.IDLArgument([('Type', ('ScopedName', 'object')), ('Id', 'arg')
]) |
| 229 for interface in database.GetInterfaces(): | 230 for interface in database.GetInterfaces(): |
| 230 for operation in interface.operations: | 231 for operation in interface.operations: |
| 231 call_with = (operation.ext_attrs.get('CallWith', '').split('|') + | 232 call_with = (operation.ext_attrs.get('CallWith', '').split('|') + |
| 232 operation.ext_attrs.get('ConstructorCallWith', '').split('|
') + | 233 operation.ext_attrs.get('ConstructorCallWith', '').split('|
') + |
| 233 operation.ext_attrs.get('CallWith', '').split('&') + | 234 operation.ext_attrs.get('CallWith', '').split('&') + |
| 234 operation.ext_attrs.get('ConstructorCallWith', '').split('&
')) | 235 operation.ext_attrs.get('ConstructorCallWith', '').split('&
')) |
| 235 if 'ScriptArguments' in call_with: | 236 if 'ScriptArguments' in call_with: |
| 236 operation.arguments.append(ARG) | 237 operation.arguments.append(ARG) |
| OLD | NEW |