OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, 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 import sys | 6 import sys |
7 | 7 |
8 | 8 |
9 class IDLNode(object): | 9 class IDLNode(object): |
10 """Base class for all IDL elements. | 10 """Base class for all IDL elements. |
11 IDLNode may contain various child nodes, and have properties. Examples | 11 IDLNode may contain various child nodes, and have properties. Examples |
12 of IDLNode are modules, interfaces, interface members, function arguments, | 12 of IDLNode are modules, interfaces, interface members, function arguments, |
13 etc. | 13 etc. |
14 """ | 14 """ |
15 | 15 |
16 def __init__(self, ast): | 16 def __init__(self, ast): |
17 """Initializes an IDLNode from a PegParser AST output.""" | 17 """Initializes an IDLNode from a PegParser AST output.""" |
18 self.id = self._find_first(ast, 'Id') if ast is not None else None | 18 self.id = self._find_first(ast, 'Id') if ast is not None else None |
19 # TODO(jacobr): move back to native_name | |
19 | 20 |
20 def __repr__(self): | 21 def __repr__(self): |
21 """Generates string of the form <class id extra extra ... 0x12345678>.""" | 22 """Generates string of the form <class id extra extra ... 0x12345678>.""" |
22 extras = self._extra_repr() | 23 extras = self._extra_repr() |
23 if isinstance(extras, list): | 24 if isinstance(extras, list): |
24 extras = ' '.join([str(e) for e in extras]) | 25 extras = ' '.join([str(e) for e in extras]) |
25 try: | 26 try: |
26 if self.id: | 27 if self.id: |
27 return '<%s %s 0x%x>' % ( | 28 return '<%s %s 0x%x>' % ( |
28 type(self).__name__, | 29 type(self).__name__, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 self._convert_ext_attrs(ast) | 345 self._convert_ext_attrs(ast) |
345 self._convert_annotations(ast) | 346 self._convert_annotations(ast) |
346 self.parents = self._convert_all(ast, 'ParentInterface', | 347 self.parents = self._convert_all(ast, 'ParentInterface', |
347 IDLParentInterface) | 348 IDLParentInterface) |
348 self.operations = self._convert_all(ast, 'Operation', IDLOperation) | 349 self.operations = self._convert_all(ast, 'Operation', IDLOperation) |
349 self.attributes = self._convert_all(ast, 'Attribute', IDLAttribute) | 350 self.attributes = self._convert_all(ast, 'Attribute', IDLAttribute) |
350 self.constants = self._convert_all(ast, 'Const', IDLConstant) | 351 self.constants = self._convert_all(ast, 'Const', IDLConstant) |
351 self.is_supplemental = 'Supplemental' in self.ext_attrs | 352 self.is_supplemental = 'Supplemental' in self.ext_attrs |
352 self.is_no_interface_object = 'NoInterfaceObject' in self.ext_attrs | 353 self.is_no_interface_object = 'NoInterfaceObject' in self.ext_attrs |
353 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs | 354 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs |
355 self.native_name = self.id | |
354 | 356 |
357 def has_attribute(self, candidate): | |
sra1
2012/02/16 04:43:28
This is pretty much _FindMatchingAttribute
| |
358 for attribute in self.attributes: | |
359 if attribute.id == candidate.id and attribute.is_fc_getter == candidate.is _fc_getter and attribute.is_fc_setter == candidate.is_fc_setter: | |
360 return True | |
361 return False | |
362 | |
363 def merge(self, other): | |
sra1
2012/02/16 04:43:28
Please move the merge logic, including above funct
| |
364 self.operations.extend(other.operations) | |
365 for attribute in other.attributes: | |
366 if not self.has_attribute(attribute): | |
367 self.attributes.append(attribute) | |
368 | |
369 self.constants.extend(other.constants) | |
355 | 370 |
356 class IDLParentInterface(IDLNode): | 371 class IDLParentInterface(IDLNode): |
357 """This IDLNode specialization is for 'Interface Child : Parent {}' | 372 """This IDLNode specialization is for 'Interface Child : Parent {}' |
358 declarations.""" | 373 declarations.""" |
359 def __init__(self, ast): | 374 def __init__(self, ast): |
360 IDLNode.__init__(self, ast) | 375 IDLNode.__init__(self, ast) |
361 self._convert_annotations(ast) | 376 self._convert_annotations(ast) |
362 self.type = self._convert_first(ast, 'InterfaceType', IDLType) | 377 self.type = self._convert_first(ast, 'InterfaceType', IDLType) |
363 | 378 |
364 | 379 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 """IDLDictNode specialization for one annotation.""" | 469 """IDLDictNode specialization for one annotation.""" |
455 def __init__(self, ast=None): | 470 def __init__(self, ast=None): |
456 IDLDictNode.__init__(self, ast) | 471 IDLDictNode.__init__(self, ast) |
457 self.id = None | 472 self.id = None |
458 if not ast: | 473 if not ast: |
459 return | 474 return |
460 for arg in self._find_all(ast, 'AnnotationArg'): | 475 for arg in self._find_all(ast, 'AnnotationArg'): |
461 name = self._find_first(arg, 'Id') | 476 name = self._find_first(arg, 'Id') |
462 value = self._find_first(arg, 'AnnotationArgValue') | 477 value = self._find_first(arg, 'AnnotationArgValue') |
463 self[name] = value | 478 self[name] = value |
OLD | NEW |