| 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 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 | 19 |
| 20 def __repr__(self): | 20 def __repr__(self): |
| 21 """Generates string of the form <class id extra extra ... 0x12345678>.""" | 21 """Generates string of the form <class id extra extra ... 0x12345678>.""" |
| 22 extras = self._extra_repr() | 22 extras = self._extra_repr() |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 v = v.to_dict() | 238 v = v.to_dict() |
| 239 res[k] = v | 239 res[k] = v |
| 240 return res | 240 return res |
| 241 | 241 |
| 242 def _all_subnodes(self): | 242 def _all_subnodes(self): |
| 243 # Usually an IDLDictNode does not contain further IDLNodes. | 243 # Usually an IDLDictNode does not contain further IDLNodes. |
| 244 return [] | 244 return [] |
| 245 | 245 |
| 246 | 246 |
| 247 class IDLFile(IDLNode): | 247 class IDLFile(IDLNode): |
| 248 """IDLFile is the top-level node in each IDL file. It may contain | 248 """IDLFile is the top-level node in each IDL file. It may contain interfaces."
"" |
| 249 modules or interfaces.""" | |
| 250 | 249 |
| 251 def __init__(self, ast, filename=None): | 250 def __init__(self, ast, filename=None): |
| 252 IDLNode.__init__(self, ast) | 251 IDLNode.__init__(self, ast) |
| 253 self.filename = filename | 252 self.filename = filename |
| 254 self.modules = self._convert_all(ast, 'Module', IDLModule) | |
| 255 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) | 253 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) |
| 254 modules = self._convert_all(ast, 'Module', IDLModule) |
| 255 self.implementsStatements = self._convert_all(ast, 'ImplStmt', |
| 256 IDLImplementsStatement) |
| 257 for module in modules: |
| 258 self.interfaces.extend(module.interfaces) |
| 259 self.implementsStatements.extend(module.implementsStatements) |
| 256 | 260 |
| 257 | 261 |
| 258 class IDLModule(IDLNode): | 262 class IDLModule(IDLNode): |
| 259 """IDLModule has an id, and may contain interfaces, type defs and | 263 """IDLModule has an id, and may contain interfaces, type defs and |
| 260 implements statements.""" | 264 implements statements.""" |
| 261 def __init__(self, ast): | 265 def __init__(self, ast): |
| 262 IDLNode.__init__(self, ast) | 266 IDLNode.__init__(self, ast) |
| 263 self._convert_ext_attrs(ast) | 267 self._convert_ext_attrs(ast) |
| 264 self._convert_annotations(ast) | 268 self._convert_annotations(ast) |
| 265 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) | 269 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 """IDLDictNode specialization for one annotation.""" | 514 """IDLDictNode specialization for one annotation.""" |
| 511 def __init__(self, ast=None): | 515 def __init__(self, ast=None): |
| 512 IDLDictNode.__init__(self, ast) | 516 IDLDictNode.__init__(self, ast) |
| 513 self.id = None | 517 self.id = None |
| 514 if not ast: | 518 if not ast: |
| 515 return | 519 return |
| 516 for arg in self._find_all(ast, 'AnnotationArg'): | 520 for arg in self._find_all(ast, 'AnnotationArg'): |
| 517 name = self._find_first(arg, 'Id') | 521 name = self._find_first(arg, 'Id') |
| 518 value = self._find_first(arg, 'AnnotationArgValue') | 522 value = self._find_first(arg, 'AnnotationArgValue') |
| 519 self[name] = value | 523 self[name] = value |
| OLD | NEW |