| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 raise ValueError('Unrecognized node class: %s' % node_class) | 47 raise ValueError('Unrecognized node class: %s' % node_class) |
| 48 return file_node_to_idl_definitions(node) | 48 return file_node_to_idl_definitions(node) |
| 49 | 49 |
| 50 | 50 |
| 51 def file_node_to_idl_definitions(node): | 51 def file_node_to_idl_definitions(node): |
| 52 callback_functions = {} | 52 callback_functions = {} |
| 53 enumerations = {} | 53 enumerations = {} |
| 54 interfaces = {} | 54 interfaces = {} |
| 55 typedefs = STANDARD_TYPEDEFS | 55 typedefs = STANDARD_TYPEDEFS |
| 56 | 56 |
| 57 # FIXME: only needed for Perl, remove later | |
| 58 file_name = os.path.abspath(node.GetName()) | |
| 59 | |
| 60 children = node.GetChildren() | 57 children = node.GetChildren() |
| 61 for child in children: | 58 for child in children: |
| 62 child_class = child.GetClass() | 59 child_class = child.GetClass() |
| 63 if child_class == 'Interface': | 60 if child_class == 'Interface': |
| 64 interface = interface_node_to_idl_interface(child) | 61 interface = interface_node_to_idl_interface(child) |
| 65 interfaces[interface.name] = interface | 62 interfaces[interface.name] = interface |
| 66 elif child_class == 'Exception': | 63 elif child_class == 'Exception': |
| 67 exception = exception_node_to_idl_exception(child) | 64 exception = exception_node_to_idl_exception(child) |
| 68 # For simplicity, treat exceptions as interfaces | 65 # For simplicity, treat exceptions as interfaces |
| 69 interfaces[exception.name] = exception | 66 interfaces[exception.name] = exception |
| 70 elif child_class == 'Typedef': | 67 elif child_class == 'Typedef': |
| 71 type_name = child.GetName() | 68 type_name = child.GetName() |
| 72 typedefs[type_name] = typedef_node_to_type(child) | 69 typedefs[type_name] = typedef_node_to_type(child) |
| 73 elif child_class == 'Enum': | 70 elif child_class == 'Enum': |
| 74 enumeration = enum_node_to_idl_enum(child) | 71 enumeration = enum_node_to_idl_enum(child) |
| 75 enumerations[enumeration.name] = enumeration | 72 enumerations[enumeration.name] = enumeration |
| 76 elif child_class == 'Callback': | 73 elif child_class == 'Callback': |
| 77 callback_function = callback_node_to_idl_callback_function(child) | 74 callback_function = callback_node_to_idl_callback_function(child) |
| 78 callback_functions[callback_function.name] = callback_function | 75 callback_functions[callback_function.name] = callback_function |
| 79 elif child_class == 'Implements': | 76 elif child_class == 'Implements': |
| 80 # Implements is handled at the interface merging step | 77 # Implements is handled at the interface merging step |
| 81 pass | 78 pass |
| 82 else: | 79 else: |
| 83 raise ValueError('Unrecognized node class: %s' % child_class) | 80 raise ValueError('Unrecognized node class: %s' % child_class) |
| 84 | 81 |
| 85 return IdlDefinitions(callback_functions=callback_functions, enumerations=en
umerations, file_name=file_name, interfaces=interfaces, typedefs=typedefs) | 82 return IdlDefinitions(callback_functions=callback_functions, enumerations=en
umerations, interfaces=interfaces, typedefs=typedefs) |
| 86 | 83 |
| 87 # Constructors for Interface definitions and interface members | 84 # Constructors for Interface definitions and interface members |
| 88 | 85 |
| 89 | 86 |
| 90 def interface_node_to_idl_interface(node): | 87 def interface_node_to_idl_interface(node): |
| 91 attributes = [] | 88 attributes = [] |
| 92 constants = [] | 89 constants = [] |
| 93 constructors = None | 90 constructors = None |
| 94 custom_constructors = None | 91 custom_constructors = None |
| 95 extended_attributes = None | 92 extended_attributes = None |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 for argument_node in argument_node_list: | 210 for argument_node in argument_node_list: |
| 214 arguments.append(argument_node_to_idl_argument(argument_node)) | 211 arguments.append(argument_node_to_idl_argument(argument_node)) |
| 215 return arguments | 212 return arguments |
| 216 | 213 |
| 217 | 214 |
| 218 def argument_node_to_idl_argument(node): | 215 def argument_node_to_idl_argument(node): |
| 219 name = node.GetName() | 216 name = node.GetName() |
| 220 | 217 |
| 221 idl_type = None | 218 idl_type = None |
| 222 extended_attributes = {} | 219 extended_attributes = {} |
| 223 # FIXME: Boolean values are inconsistent due to Perl compatibility. | |
| 224 # Make all default to False once Perl removed. | |
| 225 is_nullable = False | 220 is_nullable = False |
| 226 is_optional = node.GetProperty('OPTIONAL') | 221 is_optional = node.GetProperty('OPTIONAL') |
| 227 is_variadic = None | 222 is_variadic = False |
| 228 children = node.GetChildren() | 223 children = node.GetChildren() |
| 229 for child in children: | 224 for child in children: |
| 230 child_class = child.GetClass() | 225 child_class = child.GetClass() |
| 231 if child_class == 'Type': | 226 if child_class == 'Type': |
| 232 idl_type = type_node_to_type(child) | 227 idl_type = type_node_to_type(child) |
| 233 # FIXME: Doesn't handle nullable arrays (Foo[]?), and arrays of | 228 # FIXME: Doesn't handle nullable arrays (Foo[]?), and arrays of |
| 234 # nullable (Foo?[]) are treated as nullable arrays. No actual use. | 229 # nullable (Foo?[]) are treated as nullable arrays. No actual use. |
| 235 is_nullable = child.GetProperty('NULLABLE') | 230 is_nullable = child.GetProperty('NULLABLE') |
| 236 elif child_class == 'ExtAttributes': | 231 elif child_class == 'ExtAttributes': |
| 237 extended_attributes = ext_attributes_node_to_extended_attributes(chi
ld) | 232 extended_attributes = ext_attributes_node_to_extended_attributes(chi
ld) |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 sequence_type = type_node_to_type(sequence_child) | 505 sequence_type = type_node_to_type(sequence_child) |
| 511 return 'sequence<%s>' % sequence_type | 506 return 'sequence<%s>' % sequence_type |
| 512 | 507 |
| 513 | 508 |
| 514 def union_type_node_to_idl_union_type(node): | 509 def union_type_node_to_idl_union_type(node): |
| 515 union_member_types = [] | 510 union_member_types = [] |
| 516 for member_type_node in node.GetChildren(): | 511 for member_type_node in node.GetChildren(): |
| 517 member_type = type_node_to_type(member_type_node) | 512 member_type = type_node_to_type(member_type_node) |
| 518 union_member_types.append(member_type) | 513 union_member_types.append(member_type) |
| 519 return IdlUnionType(union_member_types=union_member_types) | 514 return IdlUnionType(union_member_types=union_member_types) |
| OLD | NEW |