| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 typedefs[type_name] = typedef_node_to_type(child) | 131 typedefs[type_name] = typedef_node_to_type(child) |
| 132 elif child_class == 'Enum': | 132 elif child_class == 'Enum': |
| 133 enumeration = IdlEnum(idl_name, child) | 133 enumeration = IdlEnum(idl_name, child) |
| 134 self.enumerations[enumeration.name] = enumeration | 134 self.enumerations[enumeration.name] = enumeration |
| 135 elif child_class == 'Callback': | 135 elif child_class == 'Callback': |
| 136 callback_function = IdlCallbackFunction(idl_name, child) | 136 callback_function = IdlCallbackFunction(idl_name, child) |
| 137 self.callback_functions[callback_function.name] = callback_funct
ion | 137 self.callback_functions[callback_function.name] = callback_funct
ion |
| 138 elif child_class == 'Implements': | 138 elif child_class == 'Implements': |
| 139 # Implements is handled at the interface merging step | 139 # Implements is handled at the interface merging step |
| 140 pass | 140 pass |
| 141 elif child_class == 'Dictionary': | |
| 142 dictionary = IdlDictionary(idl_name, child) | |
| 143 self.dictionaries[dictionary.name] = dictionary | |
| 144 else: | 141 else: |
| 145 raise ValueError('Unrecognized node class: %s' % child_class) | 142 raise ValueError('Unrecognized node class: %s' % child_class) |
| 146 | 143 |
| 147 # Typedefs are not stored in IR: | 144 # Typedefs are not stored in IR: |
| 148 # Resolve typedefs with the actual types and then discard the Typedefs. | 145 # Resolve typedefs with the actual types and then discard the Typedefs. |
| 149 # http://www.w3.org/TR/WebIDL/#idl-typedefs | 146 # http://www.w3.org/TR/WebIDL/#idl-typedefs |
| 150 self.resolve_typedefs(typedefs) | 147 self.resolve_typedefs(typedefs) |
| 151 | 148 |
| 152 def resolve_typedefs(self, typedefs): | 149 def resolve_typedefs(self, typedefs): |
| 153 for callback_function in self.callback_functions.itervalues(): | 150 for callback_function in self.callback_functions.itervalues(): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 self.idl_type = type_node_to_type(type_node) | 193 self.idl_type = type_node_to_type(type_node) |
| 197 self.arguments = arguments_node_to_arguments(idl_name, arguments_node) | 194 self.arguments = arguments_node_to_arguments(idl_name, arguments_node) |
| 198 | 195 |
| 199 def resolve_typedefs(self, typedefs): | 196 def resolve_typedefs(self, typedefs): |
| 200 TypedObject.resolve_typedefs(self, typedefs) | 197 TypedObject.resolve_typedefs(self, typedefs) |
| 201 for argument in self.arguments: | 198 for argument in self.arguments: |
| 202 argument.resolve_typedefs(typedefs) | 199 argument.resolve_typedefs(typedefs) |
| 203 | 200 |
| 204 | 201 |
| 205 ################################################################################ | 202 ################################################################################ |
| 206 # Dictionary | |
| 207 ################################################################################ | |
| 208 | |
| 209 class IdlDictionary(object): | |
| 210 def __init__(self, idl_name, node): | |
| 211 self.extended_attributes = {} | |
| 212 self.is_partial = node.GetProperty('Partial') or False | |
| 213 self.idl_name = idl_name | |
| 214 self.name = node.GetName() | |
| 215 self.members = [] | |
| 216 self.parent = None | |
| 217 for child in node.GetChildren(): | |
| 218 child_class = child.GetClass() | |
| 219 if child_class == 'Inherit': | |
| 220 self.parent = child.GetName() | |
| 221 elif child_class == 'Key': | |
| 222 self.members.append(IdlDictionaryMember(idl_name, child)) | |
| 223 elif child_class == 'ExtAttributes': | |
| 224 self.extended_attributes = ( | |
| 225 ext_attributes_node_to_extended_attributes(idl_name, child)) | |
| 226 else: | |
| 227 raise ValueError('Unrecognized node class: %s' % child_class) | |
| 228 | |
| 229 | |
| 230 class IdlDictionaryMember(object): | |
| 231 def __init__(self, idl_name, node): | |
| 232 self.default_value = None | |
| 233 self.extended_attributes = {} | |
| 234 self.idl_type = None | |
| 235 self.idl_name = idl_name | |
| 236 self.name = node.GetName() | |
| 237 for child in node.GetChildren(): | |
| 238 child_class = child.GetClass() | |
| 239 if child_class == 'Type': | |
| 240 self.idl_type = type_node_to_type(child) | |
| 241 elif child_class == 'Default': | |
| 242 self.default_value = default_node_to_idl_literal(child) | |
| 243 elif child_class == 'ExtAttributes': | |
| 244 self.extended_attributes = ( | |
| 245 ext_attributes_node_to_extended_attributes(idl_name, child)) | |
| 246 else: | |
| 247 raise ValueError('Unrecognized node class: %s' % child_class) | |
| 248 | |
| 249 | |
| 250 ################################################################################ | |
| 251 # Enumerations | 203 # Enumerations |
| 252 ################################################################################ | 204 ################################################################################ |
| 253 | 205 |
| 254 class IdlEnum(object): | 206 class IdlEnum(object): |
| 255 # FIXME: remove, just treat enums as a dictionary | 207 # FIXME: remove, just treat enums as a dictionary |
| 256 def __init__(self, idl_name, node): | 208 def __init__(self, idl_name, node): |
| 257 self.idl_name = idl_name | 209 self.idl_name = idl_name |
| 258 self.name = node.GetName() | 210 self.name = node.GetName() |
| 259 self.values = [] | 211 self.values = [] |
| 260 for child in node.GetChildren(): | 212 for child in node.GetChildren(): |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 child_class = child.GetClass() | 769 child_class = child.GetClass() |
| 818 if child_class != 'Type': | 770 if child_class != 'Type': |
| 819 raise ValueError('Unrecognized node class: %s' % child_class) | 771 raise ValueError('Unrecognized node class: %s' % child_class) |
| 820 return type_node_to_type(child) | 772 return type_node_to_type(child) |
| 821 | 773 |
| 822 | 774 |
| 823 def union_type_node_to_idl_union_type(node): | 775 def union_type_node_to_idl_union_type(node): |
| 824 member_types = [type_node_to_type(member_type_node) | 776 member_types = [type_node_to_type(member_type_node) |
| 825 for member_type_node in node.GetChildren()] | 777 for member_type_node in node.GetChildren()] |
| 826 return IdlUnionType(member_types) | 778 return IdlUnionType(member_types) |
| OLD | NEW |