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 os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
9 import idl_definitions | 9 import idl_definitions |
10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type | 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 DART_IDL = 'dart.idl' | 377 DART_IDL = 'dart.idl' |
378 | 378 |
379 def __init__(self, ast, filename=None): | 379 def __init__(self, ast, filename=None): |
380 IDLNode.__init__(self, ast) | 380 IDLNode.__init__(self, ast) |
381 self.filename = filename | 381 self.filename = filename |
382 | 382 |
383 filename_basename = os.path.basename(filename) | 383 filename_basename = os.path.basename(filename) |
384 | 384 |
385 # Report of union types mapped to any. | 385 # Report of union types mapped to any. |
386 | 386 |
| 387 # Remember all the typedefs before we start walking the AST. Some |
| 388 # IDLs now have typedefs before interfaces. So we need to remember |
| 389 # to resolve the typedefs. |
| 390 self.typeDefs = self._convert_all(ast, 'TypeDef', IDLTypeDef) |
| 391 for typedefName in ast.typedefs: |
| 392 typedef_type = ast.typedefs[typedefName] |
| 393 # Ignore unions and dictionaries for now we just want normal typedefs to r
esolve our arguments/types. |
| 394 if not(isinstance(typedef_type.idl_type, IdlUnionType)) and not(typedef_ty
pe.idl_type.base_type == 'Dictionary'): |
| 395 _addTypedef(IDLTypeDef(typedef_type)) |
| 396 |
387 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) | 397 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) |
388 self.dictionaries = self._convert_all(ast, 'Dictionary', IDLDictionary) | 398 self.dictionaries = self._convert_all(ast, 'Dictionary', IDLDictionary) |
389 | 399 |
390 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions
' | 400 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions
' |
391 | 401 |
392 if is_blink: | 402 if is_blink: |
393 # implements is handled by the interface merging step (see the function | 403 # implements is handled by the interface merging step (see the function |
394 # merge_interface_dependencies). | 404 # merge_interface_dependencies). |
395 for interface in self.interfaces: | 405 for interface in self.interfaces: |
396 blink_interface = ast.interfaces.get(interface.id) | 406 blink_interface = ast.interfaces.get(interface.id) |
(...skipping 28 matching lines...) Expand all Loading... |
425 for implemented_name in implements: | 435 for implemented_name in implements: |
426 implement_statement = self._createImplementsStatement(implementor, | 436 implement_statement = self._createImplementsStatement(implementor, |
427 implemented_
name) | 437 implemented_
name) |
428 self.implementsStatements.append(implement_statement) | 438 self.implementsStatements.append(implement_statement) |
429 else: | 439 else: |
430 self.implementsStatements = [] | 440 self.implementsStatements = [] |
431 else: | 441 else: |
432 self.implementsStatements = self._convert_all(ast, 'ImplStmt', | 442 self.implementsStatements = self._convert_all(ast, 'ImplStmt', |
433 IDLImplementsStatement) | 443 IDLImplementsStatement) |
434 | 444 |
435 # No reason to handle typedef they're already aliased in Blink's AST. | 445 # Record typedefs that are unions. |
436 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) | |
437 | |
438 # Hack to record typedefs that are unions. | |
439 for typedefName in ast.typedefs: | 446 for typedefName in ast.typedefs: |
440 typedef_type = ast.typedefs[typedefName] | 447 typedef_type = ast.typedefs[typedefName] |
441 if isinstance(typedef_type.idl_type, IdlUnionType): | 448 if isinstance(typedef_type.idl_type, IdlUnionType): |
442 self.typeDefs.append(IDLTypeDef(typedef_type)) | 449 self.typeDefs.append(IDLTypeDef(typedef_type)) |
443 elif typedef_type.idl_type.base_type == 'Dictionary': | 450 elif typedef_type.idl_type.base_type == 'Dictionary': |
444 dictionary = IDLDictionary(typedef_type, True) | 451 dictionary = IDLDictionary(typedef_type, True) |
445 self.dictionaries.append(dictionary) | 452 self.dictionaries.append(dictionary) |
446 else: | |
447 # All other typedefs we record | |
448 _addTypedef(IDLTypeDef(typedef_type)) | |
449 | 453 |
450 self.enums = self._convert_all(ast, 'Enum', IDLEnum) | 454 self.enums = self._convert_all(ast, 'Enum', IDLEnum) |
451 | 455 |
452 def _createImplementsStatement(self, implementor, implemented_name): | 456 def _createImplementsStatement(self, implementor, implemented_name): |
453 implemented = new_asts[implemented_name].interfaces.get(implemented_name) | 457 implemented = new_asts[implemented_name].interfaces.get(implemented_name) |
454 | 458 |
455 implement_statement = IDLImplementsStatement(implemented) | 459 implement_statement = IDLImplementsStatement(implemented) |
456 | 460 |
457 implement_statement.implementor = IDLType(implementor) | 461 implement_statement.implementor = IDLType(implementor) |
458 implement_statement.implemented = IDLType(implemented) | 462 implement_statement.implemented = IDLType(implemented) |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 """IDLDictNode specialization for one annotation.""" | 1042 """IDLDictNode specialization for one annotation.""" |
1039 def __init__(self, ast=None): | 1043 def __init__(self, ast=None): |
1040 IDLDictNode.__init__(self, ast) | 1044 IDLDictNode.__init__(self, ast) |
1041 self.id = None | 1045 self.id = None |
1042 if not ast: | 1046 if not ast: |
1043 return | 1047 return |
1044 for arg in self._find_all(ast, 'AnnotationArg'): | 1048 for arg in self._find_all(ast, 'AnnotationArg'): |
1045 name = self._find_first(arg, 'Id') | 1049 name = self._find_first(arg, 'Id') |
1046 value = self._find_first(arg, 'AnnotationArgValue') | 1050 value = self._find_first(arg, 'AnnotationArgValue') |
1047 self[name] = value | 1051 self[name] = value |
OLD | NEW |