Chromium Code Reviews| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 """ | 81 """ |
| 82 __metaclass__ = abc.ABCMeta | 82 __metaclass__ = abc.ABCMeta |
| 83 idl_type_attributes = ('idl_type',) | 83 idl_type_attributes = ('idl_type',) |
| 84 | 84 |
| 85 | 85 |
| 86 ################################################################################ | 86 ################################################################################ |
| 87 # Definitions (main container class) | 87 # Definitions (main container class) |
| 88 ################################################################################ | 88 ################################################################################ |
| 89 | 89 |
| 90 class IdlDefinitions(object): | 90 class IdlDefinitions(object): |
| 91 def __init__(self, idl_name, node): | 91 def __init__(self, node): |
| 92 """Args: node: AST root node, class == 'File'""" | 92 """Args: node: AST root node, class == 'File'""" |
| 93 self.callback_functions = {} | 93 self.callback_functions = {} |
| 94 self.dictionaries = {} | 94 self.dictionaries = {} |
| 95 self.enumerations = {} | 95 self.enumerations = {} |
| 96 self.implements = [] | 96 self.implements = [] |
| 97 self.interfaces = {} | 97 self.interfaces = {} |
| 98 self.idl_name = idl_name | |
| 99 self.typedefs = {} | 98 self.typedefs = {} |
| 100 | 99 |
| 101 node_class = node.GetClass() | 100 node_class = node.GetClass() |
| 102 if node_class != 'File': | 101 if node_class != 'File': |
| 103 raise ValueError('Unrecognized node class: %s' % node_class) | 102 raise ValueError('Unrecognized node class: %s' % node_class) |
| 104 | 103 |
| 105 children = node.GetChildren() | 104 children = node.GetChildren() |
| 106 for child in children: | 105 for child in children: |
| 107 child_class = child.GetClass() | 106 child_class = child.GetClass() |
| 108 if child_class == 'Interface': | 107 if child_class == 'Interface': |
| 109 interface = IdlInterface(idl_name, child) | 108 interface = IdlInterface(child) |
| 110 self.interfaces[interface.name] = interface | 109 self.interfaces[interface.name] = interface |
| 111 elif child_class == 'Exception': | 110 elif child_class == 'Exception': |
| 112 exception = IdlException(idl_name, child) | 111 exception = IdlException(child) |
| 113 # For simplicity, treat exceptions as interfaces | 112 # For simplicity, treat exceptions as interfaces |
| 114 self.interfaces[exception.name] = exception | 113 self.interfaces[exception.name] = exception |
| 115 elif child_class == 'Typedef': | 114 elif child_class == 'Typedef': |
| 116 typedef = IdlTypedef(child) | 115 typedef = IdlTypedef(child) |
| 117 self.typedefs[typedef.name] = typedef | 116 self.typedefs[typedef.name] = typedef |
| 118 elif child_class == 'Enum': | 117 elif child_class == 'Enum': |
| 119 enumeration = IdlEnum(idl_name, child) | 118 enumeration = IdlEnum(child) |
| 120 self.enumerations[enumeration.name] = enumeration | 119 self.enumerations[enumeration.name] = enumeration |
| 121 elif child_class == 'Callback': | 120 elif child_class == 'Callback': |
| 122 callback_function = IdlCallbackFunction(idl_name, child) | 121 callback_function = IdlCallbackFunction(child) |
| 123 self.callback_functions[callback_function.name] = callback_funct ion | 122 self.callback_functions[callback_function.name] = callback_funct ion |
| 124 elif child_class == 'Implements': | 123 elif child_class == 'Implements': |
| 125 self.implements.append(IdlImplement(child)) | 124 self.implements.append(IdlImplement(child)) |
| 126 elif child_class == 'Dictionary': | 125 elif child_class == 'Dictionary': |
| 127 dictionary = IdlDictionary(idl_name, child) | 126 dictionary = IdlDictionary(child) |
| 128 self.dictionaries[dictionary.name] = dictionary | 127 self.dictionaries[dictionary.name] = dictionary |
| 129 else: | 128 else: |
| 130 raise ValueError('Unrecognized node class: %s' % child_class) | 129 raise ValueError('Unrecognized node class: %s' % child_class) |
| 131 | 130 |
| 132 def accept(self, visitor): | 131 def accept(self, visitor): |
| 133 visitor.visit_definitions(self) | 132 visitor.visit_definitions(self) |
| 134 for interface in self.interfaces.itervalues(): | 133 for interface in self.interfaces.itervalues(): |
| 135 interface.accept(visitor) | 134 interface.accept(visitor) |
| 136 for callback_function in self.callback_functions.itervalues(): | 135 for callback_function in self.callback_functions.itervalues(): |
| 137 callback_function.accept(visitor) | 136 callback_function.accept(visitor) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 163 # Merge callbacks and enumerations | 162 # Merge callbacks and enumerations |
| 164 self.enumerations.update(other.enumerations) | 163 self.enumerations.update(other.enumerations) |
| 165 self.callback_functions.update(other.callback_functions) | 164 self.callback_functions.update(other.callback_functions) |
| 166 | 165 |
| 167 | 166 |
| 168 ################################################################################ | 167 ################################################################################ |
| 169 # Callback Functions | 168 # Callback Functions |
| 170 ################################################################################ | 169 ################################################################################ |
| 171 | 170 |
| 172 class IdlCallbackFunction(TypedObject): | 171 class IdlCallbackFunction(TypedObject): |
| 173 def __init__(self, idl_name, node): | 172 def __init__(self, node): |
| 174 children = node.GetChildren() | 173 children = node.GetChildren() |
| 175 num_children = len(children) | 174 num_children = len(children) |
| 176 if num_children < 2 or num_children > 3: | 175 if num_children < 2 or num_children > 3: |
| 177 raise ValueError('Expected 2 or 3 children, got %s' % num_children) | 176 raise ValueError('Expected 2 or 3 children, got %s' % num_children) |
| 178 type_node = children[0] | 177 type_node = children[0] |
| 179 arguments_node = children[1] | 178 arguments_node = children[1] |
| 180 if num_children == 3: | 179 if num_children == 3: |
| 181 ext_attributes_node = children[2] | 180 ext_attributes_node = children[2] |
| 182 self.extended_attributes = ( | 181 self.extended_attributes = ( |
| 183 ext_attributes_node_to_extended_attributes(idl_name, ext_attribu tes_node)) | 182 ext_attributes_node_to_extended_attributes(ext_attributes_node)) |
| 184 else: | 183 else: |
| 185 self.extended_attributes = {} | 184 self.extended_attributes = {} |
| 186 arguments_node_class = arguments_node.GetClass() | 185 arguments_node_class = arguments_node.GetClass() |
| 187 if arguments_node_class != 'Arguments': | 186 if arguments_node_class != 'Arguments': |
| 188 raise ValueError('Expected Arguments node, got %s' % arguments_node_ class) | 187 raise ValueError('Expected Arguments node, got %s' % arguments_node_ class) |
| 189 | 188 |
| 190 self.idl_name = idl_name | |
| 191 self.name = node.GetName() | 189 self.name = node.GetName() |
| 192 self.idl_type = type_node_to_type(type_node) | 190 self.idl_type = type_node_to_type(type_node) |
| 193 self.arguments = arguments_node_to_arguments(idl_name, arguments_node) | 191 self.arguments = arguments_node_to_arguments(arguments_node) |
| 194 | 192 |
| 195 def accept(self, visitor): | 193 def accept(self, visitor): |
| 196 visitor.visit_callback_function(self) | 194 visitor.visit_callback_function(self) |
| 197 for argument in self.arguments: | 195 for argument in self.arguments: |
| 198 argument.accept(visitor) | 196 argument.accept(visitor) |
| 199 | 197 |
| 200 | 198 |
| 201 ################################################################################ | 199 ################################################################################ |
| 202 # Dictionary | 200 # Dictionary |
| 203 ################################################################################ | 201 ################################################################################ |
| 204 | 202 |
| 205 class IdlDictionary(object): | 203 class IdlDictionary(object): |
| 206 def __init__(self, idl_name, node): | 204 def __init__(self, node): |
| 207 self.extended_attributes = {} | 205 self.extended_attributes = {} |
| 208 self.is_partial = bool(node.GetProperty('Partial')) | 206 self.is_partial = bool(node.GetProperty('Partial')) |
| 209 self.idl_name = idl_name | |
| 210 self.name = node.GetName() | 207 self.name = node.GetName() |
| 211 self.members = [] | 208 self.members = [] |
| 212 self.parent = None | 209 self.parent = None |
| 213 for child in node.GetChildren(): | 210 for child in node.GetChildren(): |
| 214 child_class = child.GetClass() | 211 child_class = child.GetClass() |
| 215 if child_class == 'Inherit': | 212 if child_class == 'Inherit': |
| 216 self.parent = child.GetName() | 213 self.parent = child.GetName() |
| 217 elif child_class == 'Key': | 214 elif child_class == 'Key': |
| 218 self.members.append(IdlDictionaryMember(idl_name, child)) | 215 self.members.append(IdlDictionaryMember(child)) |
| 219 elif child_class == 'ExtAttributes': | 216 elif child_class == 'ExtAttributes': |
| 220 self.extended_attributes = ( | 217 self.extended_attributes = ( |
| 221 ext_attributes_node_to_extended_attributes(idl_name, child)) | 218 ext_attributes_node_to_extended_attributes(child)) |
| 222 else: | 219 else: |
| 223 raise ValueError('Unrecognized node class: %s' % child_class) | 220 raise ValueError('Unrecognized node class: %s' % child_class) |
| 224 | 221 |
| 225 def accept(self, visitor): | 222 def accept(self, visitor): |
| 226 visitor.visit_dictionary(self) | 223 visitor.visit_dictionary(self) |
| 227 for member in self.members: | 224 for member in self.members: |
| 228 member.accept(visitor) | 225 member.accept(visitor) |
| 229 | 226 |
| 230 | 227 |
| 231 class IdlDictionaryMember(TypedObject): | 228 class IdlDictionaryMember(TypedObject): |
| 232 def __init__(self, idl_name, node): | 229 def __init__(self, node): |
| 233 self.default_value = None | 230 self.default_value = None |
| 234 self.extended_attributes = {} | 231 self.extended_attributes = {} |
| 235 self.idl_type = None | 232 self.idl_type = None |
| 236 self.idl_name = idl_name | |
| 237 self.is_required = bool(node.GetProperty('REQUIRED')) | 233 self.is_required = bool(node.GetProperty('REQUIRED')) |
| 238 self.name = node.GetName() | 234 self.name = node.GetName() |
| 239 for child in node.GetChildren(): | 235 for child in node.GetChildren(): |
| 240 child_class = child.GetClass() | 236 child_class = child.GetClass() |
| 241 if child_class == 'Type': | 237 if child_class == 'Type': |
| 242 self.idl_type = type_node_to_type(child) | 238 self.idl_type = type_node_to_type(child) |
| 243 elif child_class == 'Default': | 239 elif child_class == 'Default': |
| 244 self.default_value = default_node_to_idl_literal(child) | 240 self.default_value = default_node_to_idl_literal(child) |
| 245 elif child_class == 'ExtAttributes': | 241 elif child_class == 'ExtAttributes': |
| 246 self.extended_attributes = ( | 242 self.extended_attributes = ( |
| 247 ext_attributes_node_to_extended_attributes(idl_name, child)) | 243 ext_attributes_node_to_extended_attributes(child)) |
| 248 else: | 244 else: |
| 249 raise ValueError('Unrecognized node class: %s' % child_class) | 245 raise ValueError('Unrecognized node class: %s' % child_class) |
| 250 | 246 |
| 251 def accept(self, visitor): | 247 def accept(self, visitor): |
| 252 visitor.visit_dictionary_member(self) | 248 visitor.visit_dictionary_member(self) |
| 253 | 249 |
| 254 | 250 |
| 255 ################################################################################ | 251 ################################################################################ |
| 256 # Enumerations | 252 # Enumerations |
| 257 ################################################################################ | 253 ################################################################################ |
| 258 | 254 |
| 259 class IdlEnum(object): | 255 class IdlEnum(object): |
| 260 # FIXME: remove, just treat enums as a dictionary | 256 def __init__(self, node): |
|
bashi
2016/10/25 02:09:31
We do want to represent an enum as a class instanc
| |
| 261 def __init__(self, idl_name, node): | |
| 262 self.idl_name = idl_name | |
| 263 self.name = node.GetName() | 257 self.name = node.GetName() |
| 264 self.values = [] | 258 self.values = [] |
| 265 for child in node.GetChildren(): | 259 for child in node.GetChildren(): |
| 266 self.values.append(child.GetName()) | 260 self.values.append(child.GetName()) |
| 267 | 261 |
| 268 def accept(self, visitor): | 262 def accept(self, visitor): |
| 269 visitor.visit_enumeration(self) | 263 visitor.visit_enumeration(self) |
| 270 | 264 |
| 271 | 265 |
| 272 ################################################################################ | 266 ################################################################################ |
| 273 # Typedefs | 267 # Typedefs |
| 274 ################################################################################ | 268 ################################################################################ |
| 275 | 269 |
| 276 class IdlTypedef(object): | 270 class IdlTypedef(object): |
| 277 idl_type_attributes = ('idl_type',) | 271 idl_type_attributes = ('idl_type',) |
| 278 | 272 |
| 279 def __init__(self, node): | 273 def __init__(self, node): |
| 280 self.name = node.GetName() | 274 self.name = node.GetName() |
| 281 self.idl_type = typedef_node_to_type(node) | 275 self.idl_type = typedef_node_to_type(node) |
| 282 | 276 |
| 283 def accept(self, visitor): | 277 def accept(self, visitor): |
| 284 visitor.visit_typedef(self) | 278 visitor.visit_typedef(self) |
| 285 | 279 |
| 286 | 280 |
| 287 ################################################################################ | 281 ################################################################################ |
| 288 # Interfaces and Exceptions | 282 # Interfaces and Exceptions |
| 289 ################################################################################ | 283 ################################################################################ |
| 290 | 284 |
| 291 class IdlInterface(object): | 285 class IdlInterface(object): |
| 292 def __init__(self, idl_name, node=None): | 286 def __init__(self, node=None): |
| 293 self.attributes = [] | 287 self.attributes = [] |
| 294 self.constants = [] | 288 self.constants = [] |
| 295 self.constructors = [] | 289 self.constructors = [] |
| 296 self.custom_constructors = [] | 290 self.custom_constructors = [] |
| 297 self.extended_attributes = {} | 291 self.extended_attributes = {} |
| 298 self.operations = [] | 292 self.operations = [] |
| 299 self.parent = None | 293 self.parent = None |
| 300 self.serializer = None | 294 self.serializer = None |
| 301 self.stringifier = None | 295 self.stringifier = None |
| 302 self.iterable = None | 296 self.iterable = None |
| 303 self.has_indexed_elements = False | 297 self.has_indexed_elements = False |
| 304 self.maplike = None | 298 self.maplike = None |
| 305 self.setlike = None | 299 self.setlike = None |
| 306 self.original_interface = None | 300 self.original_interface = None |
| 307 self.partial_interfaces = [] | 301 self.partial_interfaces = [] |
| 308 if not node: # Early exit for IdlException.__init__ | 302 if not node: # Early exit for IdlException.__init__ |
| 309 return | 303 return |
| 310 | 304 |
| 311 self.is_callback = bool(node.GetProperty('CALLBACK')) | 305 self.is_callback = bool(node.GetProperty('CALLBACK')) |
| 312 self.is_exception = False | 306 self.is_exception = False |
| 313 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser | 307 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser |
| 314 self.is_partial = bool(node.GetProperty('Partial')) | 308 self.is_partial = bool(node.GetProperty('Partial')) |
| 315 self.idl_name = idl_name | |
| 316 self.name = node.GetName() | 309 self.name = node.GetName() |
| 317 self.idl_type = IdlType(self.name) | 310 self.idl_type = IdlType(self.name) |
| 318 | 311 |
| 319 has_indexed_property_getter = False | 312 has_indexed_property_getter = False |
| 320 has_integer_typed_length = False | 313 has_integer_typed_length = False |
| 321 | 314 |
| 322 children = node.GetChildren() | 315 children = node.GetChildren() |
| 323 for child in children: | 316 for child in children: |
| 324 child_class = child.GetClass() | 317 child_class = child.GetClass() |
| 325 if child_class == 'Attribute': | 318 if child_class == 'Attribute': |
| 326 attr = IdlAttribute(idl_name, child) | 319 attr = IdlAttribute(child) |
| 327 if attr.idl_type.is_integer_type and attr.name == 'length': | 320 if attr.idl_type.is_integer_type and attr.name == 'length': |
| 328 has_integer_typed_length = True | 321 has_integer_typed_length = True |
| 329 self.attributes.append(attr) | 322 self.attributes.append(attr) |
| 330 elif child_class == 'Const': | 323 elif child_class == 'Const': |
| 331 self.constants.append(IdlConstant(idl_name, child)) | 324 self.constants.append(IdlConstant(child)) |
| 332 elif child_class == 'ExtAttributes': | 325 elif child_class == 'ExtAttributes': |
| 333 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child) | 326 extended_attributes = ext_attributes_node_to_extended_attributes (child) |
| 334 self.constructors, self.custom_constructors = ( | 327 self.constructors, self.custom_constructors = ( |
| 335 extended_attributes_to_constructors(idl_name, extended_attri butes)) | 328 extended_attributes_to_constructors(extended_attributes)) |
| 336 clear_constructor_attributes(extended_attributes) | 329 clear_constructor_attributes(extended_attributes) |
| 337 self.extended_attributes = extended_attributes | 330 self.extended_attributes = extended_attributes |
| 338 elif child_class == 'Operation': | 331 elif child_class == 'Operation': |
| 339 op = IdlOperation(idl_name, child) | 332 op = IdlOperation(child) |
| 340 if 'getter' in op.specials and str(op.arguments[0].idl_type) == 'unsigned long': | 333 if 'getter' in op.specials and str(op.arguments[0].idl_type) == 'unsigned long': |
| 341 has_indexed_property_getter = True | 334 has_indexed_property_getter = True |
| 342 self.operations.append(op) | 335 self.operations.append(op) |
| 343 elif child_class == 'Inherit': | 336 elif child_class == 'Inherit': |
| 344 self.parent = child.GetName() | 337 self.parent = child.GetName() |
| 345 elif child_class == 'Serializer': | 338 elif child_class == 'Serializer': |
| 346 self.serializer = IdlSerializer(idl_name, child) | 339 self.serializer = IdlSerializer(child) |
| 347 self.process_serializer() | 340 self.process_serializer() |
| 348 elif child_class == 'Stringifier': | 341 elif child_class == 'Stringifier': |
| 349 self.stringifier = IdlStringifier(idl_name, child) | 342 self.stringifier = IdlStringifier(child) |
| 350 self.process_stringifier() | 343 self.process_stringifier() |
| 351 elif child_class == 'Iterable': | 344 elif child_class == 'Iterable': |
| 352 self.iterable = IdlIterable(idl_name, child) | 345 self.iterable = IdlIterable(child) |
| 353 elif child_class == 'Maplike': | 346 elif child_class == 'Maplike': |
| 354 self.maplike = IdlMaplike(idl_name, child) | 347 self.maplike = IdlMaplike(child) |
| 355 elif child_class == 'Setlike': | 348 elif child_class == 'Setlike': |
| 356 self.setlike = IdlSetlike(idl_name, child) | 349 self.setlike = IdlSetlike(child) |
| 357 else: | 350 else: |
| 358 raise ValueError('Unrecognized node class: %s' % child_class) | 351 raise ValueError('Unrecognized node class: %s' % child_class) |
| 359 | 352 |
| 360 if len(filter(None, [self.iterable, self.maplike, self.setlike])) > 1: | 353 if len(filter(None, [self.iterable, self.maplike, self.setlike])) > 1: |
| 361 raise ValueError('Interface can only have one of iterable<>, maplike <> and setlike<>.') | 354 raise ValueError('Interface can only have one of iterable<>, maplike <> and setlike<>.') |
| 362 | 355 |
| 363 if has_integer_typed_length and has_indexed_property_getter: | 356 if has_integer_typed_length and has_indexed_property_getter: |
| 364 self.has_indexed_elements = True | 357 self.has_indexed_elements = True |
| 365 | 358 |
| 366 def accept(self, visitor): | 359 def accept(self, visitor): |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 self.stringifier = other.stringifier | 400 self.stringifier = other.stringifier |
| 408 | 401 |
| 409 | 402 |
| 410 class IdlException(IdlInterface): | 403 class IdlException(IdlInterface): |
| 411 # Properly exceptions and interfaces are distinct, and thus should inherit a | 404 # Properly exceptions and interfaces are distinct, and thus should inherit a |
| 412 # common base class (say, "IdlExceptionOrInterface"). | 405 # common base class (say, "IdlExceptionOrInterface"). |
| 413 # However, there is only one exception (DOMException), and new exceptions | 406 # However, there is only one exception (DOMException), and new exceptions |
| 414 # are not expected. Thus it is easier to implement exceptions as a | 407 # are not expected. Thus it is easier to implement exceptions as a |
| 415 # restricted subclass of interfaces. | 408 # restricted subclass of interfaces. |
| 416 # http://www.w3.org/TR/WebIDL/#idl-exceptions | 409 # http://www.w3.org/TR/WebIDL/#idl-exceptions |
| 417 def __init__(self, idl_name, node): | 410 def __init__(self, node): |
| 418 # Exceptions are similar to Interfaces, but simpler | 411 # Exceptions are similar to Interfaces, but simpler |
| 419 IdlInterface.__init__(self, idl_name) | 412 IdlInterface.__init__(self) |
| 420 self.is_callback = False | 413 self.is_callback = False |
| 421 self.is_exception = True | 414 self.is_exception = True |
| 422 self.is_partial = False | 415 self.is_partial = False |
| 423 self.idl_name = idl_name | |
| 424 self.name = node.GetName() | 416 self.name = node.GetName() |
| 425 self.idl_type = IdlType(self.name) | 417 self.idl_type = IdlType(self.name) |
| 426 | 418 |
| 427 children = node.GetChildren() | 419 children = node.GetChildren() |
| 428 for child in children: | 420 for child in children: |
| 429 child_class = child.GetClass() | 421 child_class = child.GetClass() |
| 430 if child_class == 'Attribute': | 422 if child_class == 'Attribute': |
| 431 attribute = IdlAttribute(idl_name, child) | 423 attribute = IdlAttribute(child) |
| 432 self.attributes.append(attribute) | 424 self.attributes.append(attribute) |
| 433 elif child_class == 'Const': | 425 elif child_class == 'Const': |
| 434 self.constants.append(IdlConstant(idl_name, child)) | 426 self.constants.append(IdlConstant(child)) |
| 435 elif child_class == 'ExtAttributes': | 427 elif child_class == 'ExtAttributes': |
| 436 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child) | 428 extended_attributes = ext_attributes_node_to_extended_attributes (child) |
| 437 self.constructors, self.custom_constructors = ( | 429 self.constructors, self.custom_constructors = ( |
| 438 extended_attributes_to_constructors(idl_name, extended_attri butes)) | 430 extended_attributes_to_constructors(extended_attributes)) |
| 439 clear_constructor_attributes(extended_attributes) | 431 clear_constructor_attributes(extended_attributes) |
| 440 self.extended_attributes = extended_attributes | 432 self.extended_attributes = extended_attributes |
| 441 elif child_class == 'ExceptionOperation': | 433 elif child_class == 'ExceptionOperation': |
| 442 self.operations.append(IdlOperation.from_exception_operation_nod e(idl_name, child)) | 434 self.operations.append(IdlOperation.from_exception_operation_nod e(child)) |
| 443 else: | 435 else: |
| 444 raise ValueError('Unrecognized node class: %s' % child_class) | 436 raise ValueError('Unrecognized node class: %s' % child_class) |
| 445 | 437 |
| 446 | 438 |
| 447 ################################################################################ | 439 ################################################################################ |
| 448 # Attributes | 440 # Attributes |
| 449 ################################################################################ | 441 ################################################################################ |
| 450 | 442 |
| 451 class IdlAttribute(TypedObject): | 443 class IdlAttribute(TypedObject): |
| 452 def __init__(self, idl_name, node): | 444 def __init__(self, node): |
| 453 self.is_read_only = bool(node.GetProperty('READONLY')) | 445 self.is_read_only = bool(node.GetProperty('READONLY')) |
| 454 self.is_static = bool(node.GetProperty('STATIC')) | 446 self.is_static = bool(node.GetProperty('STATIC')) |
| 455 self.idl_name = idl_name | |
| 456 self.name = node.GetName() | 447 self.name = node.GetName() |
| 457 # Defaults, overridden below | 448 # Defaults, overridden below |
| 458 self.idl_type = None | 449 self.idl_type = None |
| 459 self.extended_attributes = {} | 450 self.extended_attributes = {} |
| 460 | 451 |
| 461 children = node.GetChildren() | 452 children = node.GetChildren() |
| 462 for child in children: | 453 for child in children: |
| 463 child_class = child.GetClass() | 454 child_class = child.GetClass() |
| 464 if child_class == 'Type': | 455 if child_class == 'Type': |
| 465 self.idl_type = type_node_to_type(child) | 456 self.idl_type = type_node_to_type(child) |
| 466 elif child_class == 'ExtAttributes': | 457 elif child_class == 'ExtAttributes': |
| 467 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child) | 458 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 468 else: | 459 else: |
| 469 raise ValueError('Unrecognized node class: %s' % child_class) | 460 raise ValueError('Unrecognized node class: %s' % child_class) |
| 470 | 461 |
| 471 def accept(self, visitor): | 462 def accept(self, visitor): |
| 472 visitor.visit_attribute(self) | 463 visitor.visit_attribute(self) |
| 473 | 464 |
| 474 | 465 |
| 475 ################################################################################ | 466 ################################################################################ |
| 476 # Constants | 467 # Constants |
| 477 ################################################################################ | 468 ################################################################################ |
| 478 | 469 |
| 479 class IdlConstant(TypedObject): | 470 class IdlConstant(TypedObject): |
| 480 def __init__(self, idl_name, node): | 471 def __init__(self, node): |
| 481 children = node.GetChildren() | 472 children = node.GetChildren() |
| 482 num_children = len(children) | 473 num_children = len(children) |
| 483 if num_children < 2 or num_children > 3: | 474 if num_children < 2 or num_children > 3: |
| 484 raise ValueError('Expected 2 or 3 children, got %s' % num_children) | 475 raise ValueError('Expected 2 or 3 children, got %s' % num_children) |
| 485 type_node = children[0] | 476 type_node = children[0] |
| 486 value_node = children[1] | 477 value_node = children[1] |
| 487 value_node_class = value_node.GetClass() | 478 value_node_class = value_node.GetClass() |
| 488 if value_node_class != 'Value': | 479 if value_node_class != 'Value': |
| 489 raise ValueError('Expected Value node, got %s' % value_node_class) | 480 raise ValueError('Expected Value node, got %s' % value_node_class) |
| 490 | 481 |
| 491 self.idl_name = idl_name | |
| 492 self.name = node.GetName() | 482 self.name = node.GetName() |
| 493 # ConstType is more limited than Type, so subtree is smaller and | 483 # ConstType is more limited than Type, so subtree is smaller and |
| 494 # we don't use the full type_node_to_type function. | 484 # we don't use the full type_node_to_type function. |
| 495 self.idl_type = type_node_inner_to_type(type_node) | 485 self.idl_type = type_node_inner_to_type(type_node) |
| 496 # FIXME: This code is unnecessarily complicated due to the rather | 486 # FIXME: This code is unnecessarily complicated due to the rather |
| 497 # inconsistent way the upstream IDL parser outputs default values. | 487 # inconsistent way the upstream IDL parser outputs default values. |
| 498 # http://crbug.com/374178 | 488 # http://crbug.com/374178 |
| 499 if value_node.GetProperty('TYPE') == 'float': | 489 if value_node.GetProperty('TYPE') == 'float': |
| 500 self.value = value_node.GetProperty('VALUE') | 490 self.value = value_node.GetProperty('VALUE') |
| 501 else: | 491 else: |
| 502 self.value = value_node.GetName() | 492 self.value = value_node.GetName() |
| 503 | 493 |
| 504 if num_children == 3: | 494 if num_children == 3: |
| 505 ext_attributes_node = children[2] | 495 ext_attributes_node = children[2] |
| 506 self.extended_attributes = ext_attributes_node_to_extended_attribute s(idl_name, ext_attributes_node) | 496 self.extended_attributes = ext_attributes_node_to_extended_attribute s(ext_attributes_node) |
| 507 else: | 497 else: |
| 508 self.extended_attributes = {} | 498 self.extended_attributes = {} |
| 509 | 499 |
| 510 def accept(self, visitor): | 500 def accept(self, visitor): |
| 511 visitor.visit_constant(self) | 501 visitor.visit_constant(self) |
| 512 | 502 |
| 513 | 503 |
| 514 ################################################################################ | 504 ################################################################################ |
| 515 # Literals | 505 # Literals |
| 516 ################################################################################ | 506 ################################################################################ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 if idl_type == 'NULL': | 552 if idl_type == 'NULL': |
| 563 return IdlLiteralNull() | 553 return IdlLiteralNull() |
| 564 raise ValueError('Unrecognized default value type: %s' % idl_type) | 554 raise ValueError('Unrecognized default value type: %s' % idl_type) |
| 565 | 555 |
| 566 | 556 |
| 567 ################################################################################ | 557 ################################################################################ |
| 568 # Operations | 558 # Operations |
| 569 ################################################################################ | 559 ################################################################################ |
| 570 | 560 |
| 571 class IdlOperation(TypedObject): | 561 class IdlOperation(TypedObject): |
| 572 def __init__(self, idl_name, node=None): | 562 def __init__(self, node=None): |
| 573 self.arguments = [] | 563 self.arguments = [] |
| 574 self.extended_attributes = {} | 564 self.extended_attributes = {} |
| 575 self.specials = [] | 565 self.specials = [] |
| 576 self.is_constructor = False | 566 self.is_constructor = False |
| 577 self.idl_name = idl_name | |
| 578 self.idl_type = None | 567 self.idl_type = None |
| 579 self.is_static = False | 568 self.is_static = False |
| 580 | 569 |
| 581 if not node: | 570 if not node: |
| 582 return | 571 return |
| 583 | 572 |
| 584 self.name = node.GetName() # FIXME: should just be: or '' | 573 self.name = node.GetName() # FIXME: should just be: or '' |
| 585 # FIXME: AST should use None internally | 574 # FIXME: AST should use None internally |
| 586 if self.name == '_unnamed_': | 575 if self.name == '_unnamed_': |
| 587 self.name = '' | 576 self.name = '' |
| 588 | 577 |
| 589 self.is_static = bool(node.GetProperty('STATIC')) | 578 self.is_static = bool(node.GetProperty('STATIC')) |
| 590 property_dictionary = node.GetProperties() | 579 property_dictionary = node.GetProperties() |
| 591 for special_keyword in SPECIAL_KEYWORD_LIST: | 580 for special_keyword in SPECIAL_KEYWORD_LIST: |
| 592 if special_keyword in property_dictionary: | 581 if special_keyword in property_dictionary: |
| 593 self.specials.append(special_keyword.lower()) | 582 self.specials.append(special_keyword.lower()) |
| 594 | 583 |
| 595 children = node.GetChildren() | 584 children = node.GetChildren() |
| 596 for child in children: | 585 for child in children: |
| 597 child_class = child.GetClass() | 586 child_class = child.GetClass() |
| 598 if child_class == 'Arguments': | 587 if child_class == 'Arguments': |
| 599 self.arguments = arguments_node_to_arguments(idl_name, child) | 588 self.arguments = arguments_node_to_arguments(child) |
| 600 elif child_class == 'Type': | 589 elif child_class == 'Type': |
| 601 self.idl_type = type_node_to_type(child) | 590 self.idl_type = type_node_to_type(child) |
| 602 elif child_class == 'ExtAttributes': | 591 elif child_class == 'ExtAttributes': |
| 603 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child) | 592 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 604 else: | 593 else: |
| 605 raise ValueError('Unrecognized node class: %s' % child_class) | 594 raise ValueError('Unrecognized node class: %s' % child_class) |
| 606 | 595 |
| 607 @classmethod | 596 @classmethod |
| 608 def from_exception_operation_node(cls, idl_name, node): | 597 def from_exception_operation_node(cls, node): |
| 609 # Needed to handle one case in DOMException.idl: | 598 # Needed to handle one case in DOMException.idl: |
| 610 # // Override in a Mozilla compatible format | 599 # // Override in a Mozilla compatible format |
| 611 # [NotEnumerable] DOMString toString(); | 600 # [NotEnumerable] DOMString toString(); |
| 612 # FIXME: can we remove this? replace with a stringifier? | 601 # FIXME: can we remove this? replace with a stringifier? |
| 613 operation = cls(idl_name) | 602 operation = cls() |
| 614 operation.name = node.GetName() | 603 operation.name = node.GetName() |
| 615 children = node.GetChildren() | 604 children = node.GetChildren() |
| 616 if len(children) < 1 or len(children) > 2: | 605 if len(children) < 1 or len(children) > 2: |
| 617 raise ValueError('ExceptionOperation node with %s children, expected 1 or 2' % len(children)) | 606 raise ValueError('ExceptionOperation node with %s children, expected 1 or 2' % len(children)) |
| 618 | 607 |
| 619 type_node = children[0] | 608 type_node = children[0] |
| 620 operation.idl_type = type_node_to_type(type_node) | 609 operation.idl_type = type_node_to_type(type_node) |
| 621 | 610 |
| 622 if len(children) > 1: | 611 if len(children) > 1: |
| 623 ext_attributes_node = children[1] | 612 ext_attributes_node = children[1] |
| 624 operation.extended_attributes = ext_attributes_node_to_extended_attr ibutes(idl_name, ext_attributes_node) | 613 operation.extended_attributes = ext_attributes_node_to_extended_attr ibutes(ext_attributes_node) |
| 625 | 614 |
| 626 return operation | 615 return operation |
| 627 | 616 |
| 628 @classmethod | 617 @classmethod |
| 629 def constructor_from_arguments_node(cls, name, idl_name, arguments_node): | 618 def constructor_from_arguments_node(cls, name, arguments_node): |
| 630 constructor = cls(idl_name) | 619 constructor = cls() |
| 631 constructor.name = name | 620 constructor.name = name |
| 632 constructor.arguments = arguments_node_to_arguments(idl_name, arguments_ node) | 621 constructor.arguments = arguments_node_to_arguments(arguments_node) |
| 633 constructor.is_constructor = True | 622 constructor.is_constructor = True |
| 634 return constructor | 623 return constructor |
| 635 | 624 |
| 636 def accept(self, visitor): | 625 def accept(self, visitor): |
| 637 visitor.visit_operation(self) | 626 visitor.visit_operation(self) |
| 638 for argument in self.arguments: | 627 for argument in self.arguments: |
| 639 argument.accept(visitor) | 628 argument.accept(visitor) |
| 640 | 629 |
| 641 | 630 |
| 642 ################################################################################ | 631 ################################################################################ |
| 643 # Arguments | 632 # Arguments |
| 644 ################################################################################ | 633 ################################################################################ |
| 645 | 634 |
| 646 class IdlArgument(TypedObject): | 635 class IdlArgument(TypedObject): |
| 647 def __init__(self, idl_name, node=None): | 636 def __init__(self, node=None): |
| 648 self.extended_attributes = {} | 637 self.extended_attributes = {} |
| 649 self.idl_type = None | 638 self.idl_type = None |
| 650 self.is_optional = False # syntax: (optional T) | 639 self.is_optional = False # syntax: (optional T) |
| 651 self.is_variadic = False # syntax: (T...) | 640 self.is_variadic = False # syntax: (T...) |
| 652 self.idl_name = idl_name | |
| 653 self.default_value = None | 641 self.default_value = None |
| 654 | 642 |
| 655 if not node: | 643 if not node: |
| 656 return | 644 return |
| 657 | 645 |
| 658 self.is_optional = node.GetProperty('OPTIONAL') | 646 self.is_optional = node.GetProperty('OPTIONAL') |
| 659 self.name = node.GetName() | 647 self.name = node.GetName() |
| 660 | 648 |
| 661 children = node.GetChildren() | 649 children = node.GetChildren() |
| 662 for child in children: | 650 for child in children: |
| 663 child_class = child.GetClass() | 651 child_class = child.GetClass() |
| 664 if child_class == 'Type': | 652 if child_class == 'Type': |
| 665 self.idl_type = type_node_to_type(child) | 653 self.idl_type = type_node_to_type(child) |
| 666 elif child_class == 'ExtAttributes': | 654 elif child_class == 'ExtAttributes': |
| 667 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child) | 655 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 668 elif child_class == 'Argument': | 656 elif child_class == 'Argument': |
| 669 child_name = child.GetName() | 657 child_name = child.GetName() |
| 670 if child_name != '...': | 658 if child_name != '...': |
| 671 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) | 659 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) |
| 672 self.is_variadic = bool(child.GetProperty('ELLIPSIS')) | 660 self.is_variadic = bool(child.GetProperty('ELLIPSIS')) |
| 673 elif child_class == 'Default': | 661 elif child_class == 'Default': |
| 674 self.default_value = default_node_to_idl_literal(child) | 662 self.default_value = default_node_to_idl_literal(child) |
| 675 else: | 663 else: |
| 676 raise ValueError('Unrecognized node class: %s' % child_class) | 664 raise ValueError('Unrecognized node class: %s' % child_class) |
| 677 | 665 |
| 678 def accept(self, visitor): | 666 def accept(self, visitor): |
| 679 visitor.visit_argument(self) | 667 visitor.visit_argument(self) |
| 680 | 668 |
| 681 | 669 |
| 682 def arguments_node_to_arguments(idl_name, node): | 670 def arguments_node_to_arguments(node): |
| 683 # [Constructor] and [CustomConstructor] without arguments (the bare form) | 671 # [Constructor] and [CustomConstructor] without arguments (the bare form) |
| 684 # have None instead of an arguments node, but have the same meaning as using | 672 # have None instead of an arguments node, but have the same meaning as using |
| 685 # an empty argument list, [Constructor()], so special-case this. | 673 # an empty argument list, [Constructor()], so special-case this. |
| 686 # http://www.w3.org/TR/WebIDL/#Constructor | 674 # http://www.w3.org/TR/WebIDL/#Constructor |
| 687 if node is None: | 675 if node is None: |
| 688 return [] | 676 return [] |
| 689 return [IdlArgument(idl_name, argument_node) | 677 return [IdlArgument(argument_node) for argument_node in node.GetChildren()] |
| 690 for argument_node in node.GetChildren()] | |
| 691 | 678 |
| 692 | 679 |
| 693 ################################################################################ | 680 ################################################################################ |
| 694 # Serializers | 681 # Serializers |
| 695 ################################################################################ | 682 ################################################################################ |
| 696 | 683 |
| 697 class IdlSerializer(object): | 684 class IdlSerializer(object): |
| 698 def __init__(self, idl_name, node): | 685 def __init__(self, node): |
| 699 self.attribute_name = node.GetProperty('ATTRIBUTE') | 686 self.attribute_name = node.GetProperty('ATTRIBUTE') |
| 700 self.attribute_names = None | 687 self.attribute_names = None |
| 701 self.operation = None | 688 self.operation = None |
| 702 self.extended_attributes = {} | 689 self.extended_attributes = {} |
| 703 self.is_attribute = False | 690 self.is_attribute = False |
| 704 self.is_getter = False | 691 self.is_getter = False |
| 705 self.is_inherit = False | 692 self.is_inherit = False |
| 706 self.is_list = False | 693 self.is_list = False |
| 707 self.is_map = False | 694 self.is_map = False |
| 708 self.idl_name = idl_name | |
| 709 | 695 |
| 710 for child in node.GetChildren(): | 696 for child in node.GetChildren(): |
| 711 child_class = child.GetClass() | 697 child_class = child.GetClass() |
| 712 if child_class == 'Operation': | 698 if child_class == 'Operation': |
| 713 self.operation = IdlOperation(idl_name, child) | 699 self.operation = IdlOperation(child) |
| 714 elif child_class == 'List': | 700 elif child_class == 'List': |
| 715 self.is_list = True | 701 self.is_list = True |
| 716 self.is_getter = bool(child.GetProperty('GETTER')) | 702 self.is_getter = bool(child.GetProperty('GETTER')) |
| 717 self.attributes = child.GetProperty('ATTRIBUTES') | 703 self.attributes = child.GetProperty('ATTRIBUTES') |
| 718 elif child_class == 'Map': | 704 elif child_class == 'Map': |
| 719 self.is_map = True | 705 self.is_map = True |
| 720 self.is_attribute = bool(child.GetProperty('ATTRIBUTE')) | 706 self.is_attribute = bool(child.GetProperty('ATTRIBUTE')) |
| 721 self.is_getter = bool(child.GetProperty('GETTER')) | 707 self.is_getter = bool(child.GetProperty('GETTER')) |
| 722 self.is_inherit = bool(child.GetProperty('INHERIT')) | 708 self.is_inherit = bool(child.GetProperty('INHERIT')) |
| 723 self.attributes = child.GetProperty('ATTRIBUTES') | 709 self.attributes = child.GetProperty('ATTRIBUTES') |
| 724 elif child_class == 'ExtAttributes': | 710 elif child_class == 'ExtAttributes': |
| 725 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child) | 711 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 726 else: | 712 else: |
| 727 raise ValueError('Unrecognized node class: %s' % child_class) | 713 raise ValueError('Unrecognized node class: %s' % child_class) |
| 728 | 714 |
| 729 | 715 |
| 730 ################################################################################ | 716 ################################################################################ |
| 731 # Stringifiers | 717 # Stringifiers |
| 732 ################################################################################ | 718 ################################################################################ |
| 733 | 719 |
| 734 class IdlStringifier(object): | 720 class IdlStringifier(object): |
| 735 def __init__(self, idl_name, node): | 721 def __init__(self, node): |
| 736 self.attribute = None | 722 self.attribute = None |
| 737 self.operation = None | 723 self.operation = None |
| 738 self.extended_attributes = {} | 724 self.extended_attributes = {} |
| 739 self.idl_name = idl_name | |
| 740 | 725 |
| 741 for child in node.GetChildren(): | 726 for child in node.GetChildren(): |
| 742 child_class = child.GetClass() | 727 child_class = child.GetClass() |
| 743 if child_class == 'Attribute': | 728 if child_class == 'Attribute': |
| 744 self.attribute = IdlAttribute(idl_name, child) | 729 self.attribute = IdlAttribute(child) |
| 745 elif child_class == 'Operation': | 730 elif child_class == 'Operation': |
| 746 operation = IdlOperation(idl_name, child) | 731 operation = IdlOperation(child) |
| 747 if operation.name: | 732 if operation.name: |
| 748 self.operation = operation | 733 self.operation = operation |
| 749 elif child_class == 'ExtAttributes': | 734 elif child_class == 'ExtAttributes': |
| 750 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child) | 735 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 751 else: | 736 else: |
| 752 raise ValueError('Unrecognized node class: %s' % child_class) | 737 raise ValueError('Unrecognized node class: %s' % child_class) |
| 753 | 738 |
| 754 # Copy the stringifier's extended attributes (such as [Unforgable]) onto | 739 # Copy the stringifier's extended attributes (such as [Unforgable]) onto |
| 755 # the underlying attribute or operation, if there is one. | 740 # the underlying attribute or operation, if there is one. |
| 756 if self.attribute or self.operation: | 741 if self.attribute or self.operation: |
| 757 (self.attribute or self.operation).extended_attributes.update( | 742 (self.attribute or self.operation).extended_attributes.update( |
| 758 self.extended_attributes) | 743 self.extended_attributes) |
| 759 | 744 |
| 760 | 745 |
| 761 ################################################################################ | 746 ################################################################################ |
| 762 # Iterable, Maplike, Setlike | 747 # Iterable, Maplike, Setlike |
| 763 ################################################################################ | 748 ################################################################################ |
| 764 | 749 |
| 765 class IdlIterableOrMaplikeOrSetlike(TypedObject): | 750 class IdlIterableOrMaplikeOrSetlike(TypedObject): |
| 766 def __init__(self, idl_name, node): | 751 def __init__(self, node): |
| 767 self.extended_attributes = {} | 752 self.extended_attributes = {} |
| 768 self.type_children = [] | 753 self.type_children = [] |
| 769 | 754 |
| 770 for child in node.GetChildren(): | 755 for child in node.GetChildren(): |
| 771 child_class = child.GetClass() | 756 child_class = child.GetClass() |
| 772 if child_class == 'ExtAttributes': | 757 if child_class == 'ExtAttributes': |
| 773 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child) | 758 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 774 elif child_class == 'Type': | 759 elif child_class == 'Type': |
| 775 self.type_children.append(child) | 760 self.type_children.append(child) |
| 776 else: | 761 else: |
| 777 raise ValueError('Unrecognized node class: %s' % child_class) | 762 raise ValueError('Unrecognized node class: %s' % child_class) |
| 778 | 763 |
| 779 | 764 |
| 780 class IdlIterable(IdlIterableOrMaplikeOrSetlike): | 765 class IdlIterable(IdlIterableOrMaplikeOrSetlike): |
| 781 idl_type_attributes = ('key_type', 'value_type') | 766 idl_type_attributes = ('key_type', 'value_type') |
| 782 | 767 |
| 783 def __init__(self, idl_name, node): | 768 def __init__(self, node): |
| 784 super(IdlIterable, self).__init__(idl_name, node) | 769 super(IdlIterable, self).__init__(node) |
| 785 | 770 |
| 786 if len(self.type_children) == 1: | 771 if len(self.type_children) == 1: |
| 787 self.key_type = None | 772 self.key_type = None |
| 788 self.value_type = type_node_to_type(self.type_children[0]) | 773 self.value_type = type_node_to_type(self.type_children[0]) |
| 789 elif len(self.type_children) == 2: | 774 elif len(self.type_children) == 2: |
| 790 self.key_type = type_node_to_type(self.type_children[0]) | 775 self.key_type = type_node_to_type(self.type_children[0]) |
| 791 self.value_type = type_node_to_type(self.type_children[1]) | 776 self.value_type = type_node_to_type(self.type_children[1]) |
| 792 else: | 777 else: |
| 793 raise ValueError('Unexpected number of type children: %d' % len(self .type_children)) | 778 raise ValueError('Unexpected number of type children: %d' % len(self .type_children)) |
| 794 del self.type_children | 779 del self.type_children |
| 795 | 780 |
| 796 def accept(self, visitor): | 781 def accept(self, visitor): |
| 797 visitor.visit_iterable(self) | 782 visitor.visit_iterable(self) |
| 798 | 783 |
| 799 | 784 |
| 800 class IdlMaplike(IdlIterableOrMaplikeOrSetlike): | 785 class IdlMaplike(IdlIterableOrMaplikeOrSetlike): |
| 801 idl_type_attributes = ('key_type', 'value_type') | 786 idl_type_attributes = ('key_type', 'value_type') |
| 802 | 787 |
| 803 def __init__(self, idl_name, node): | 788 def __init__(self, node): |
| 804 super(IdlMaplike, self).__init__(idl_name, node) | 789 super(IdlMaplike, self).__init__(node) |
| 805 | 790 |
| 806 self.is_read_only = bool(node.GetProperty('READONLY')) | 791 self.is_read_only = bool(node.GetProperty('READONLY')) |
| 807 | 792 |
| 808 if len(self.type_children) == 2: | 793 if len(self.type_children) == 2: |
| 809 self.key_type = type_node_to_type(self.type_children[0]) | 794 self.key_type = type_node_to_type(self.type_children[0]) |
| 810 self.value_type = type_node_to_type(self.type_children[1]) | 795 self.value_type = type_node_to_type(self.type_children[1]) |
| 811 else: | 796 else: |
| 812 raise ValueError('Unexpected number of children: %d' % len(self.type _children)) | 797 raise ValueError('Unexpected number of children: %d' % len(self.type _children)) |
| 813 del self.type_children | 798 del self.type_children |
| 814 | 799 |
| 815 def accept(self, visitor): | 800 def accept(self, visitor): |
| 816 visitor.visit_maplike(self) | 801 visitor.visit_maplike(self) |
| 817 | 802 |
| 818 | 803 |
| 819 class IdlSetlike(IdlIterableOrMaplikeOrSetlike): | 804 class IdlSetlike(IdlIterableOrMaplikeOrSetlike): |
| 820 idl_type_attributes = ('value_type',) | 805 idl_type_attributes = ('value_type',) |
| 821 | 806 |
| 822 def __init__(self, idl_name, node): | 807 def __init__(self, node): |
| 823 super(IdlSetlike, self).__init__(idl_name, node) | 808 super(IdlSetlike, self).__init__(node) |
| 824 | 809 |
| 825 self.is_read_only = bool(node.GetProperty('READONLY')) | 810 self.is_read_only = bool(node.GetProperty('READONLY')) |
| 826 | 811 |
| 827 if len(self.type_children) == 1: | 812 if len(self.type_children) == 1: |
| 828 self.value_type = type_node_to_type(self.type_children[0]) | 813 self.value_type = type_node_to_type(self.type_children[0]) |
| 829 else: | 814 else: |
| 830 raise ValueError('Unexpected number of children: %d' % len(self.type _children)) | 815 raise ValueError('Unexpected number of children: %d' % len(self.type _children)) |
| 831 del self.type_children | 816 del self.type_children |
| 832 | 817 |
| 833 def accept(self, visitor): | 818 def accept(self, visitor): |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 855 """An Exposure holds one Exposed or RuntimeEnabled condition. | 840 """An Exposure holds one Exposed or RuntimeEnabled condition. |
| 856 Each exposure has two properties: exposed and runtime_enabled. | 841 Each exposure has two properties: exposed and runtime_enabled. |
| 857 Exposure(e, r) corresponds to [Exposed(e r)]. Exposure(e) corresponds to | 842 Exposure(e, r) corresponds to [Exposed(e r)]. Exposure(e) corresponds to |
| 858 [Exposed=e]. | 843 [Exposed=e]. |
| 859 """ | 844 """ |
| 860 def __init__(self, exposed, runtime_enabled=None): | 845 def __init__(self, exposed, runtime_enabled=None): |
| 861 self.exposed = exposed | 846 self.exposed = exposed |
| 862 self.runtime_enabled = runtime_enabled | 847 self.runtime_enabled = runtime_enabled |
| 863 | 848 |
| 864 | 849 |
| 865 def ext_attributes_node_to_extended_attributes(idl_name, node): | 850 def ext_attributes_node_to_extended_attributes(node): |
| 866 """ | 851 """ |
| 867 Returns: | 852 Returns: |
| 868 Dictionary of {ExtAttributeName: ExtAttributeValue}. | 853 Dictionary of {ExtAttributeName: ExtAttributeValue}. |
| 869 Value is usually a string, with these exceptions: | 854 Value is usually a string, with these exceptions: |
| 870 Constructors: value is a list of Arguments nodes, corresponding to | 855 Constructors: value is a list of Arguments nodes, corresponding to |
| 871 possible signatures of the constructor. | 856 possible signatures of the constructor. |
| 872 CustomConstructors: value is a list of Arguments nodes, corresponding to | 857 CustomConstructors: value is a list of Arguments nodes, corresponding to |
| 873 possible signatures of the custom constructor. | 858 possible signatures of the custom constructor. |
| 874 NamedConstructor: value is a Call node, corresponding to the single | 859 NamedConstructor: value is a Call node, corresponding to the single |
| 875 signature of the named constructor. | 860 signature of the named constructor. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 raise ValueError('[NamedConstructor] only supports Call as child , but has child of class: %s' % child_class) | 898 raise ValueError('[NamedConstructor] only supports Call as child , but has child of class: %s' % child_class) |
| 914 extended_attributes[name] = child | 899 extended_attributes[name] = child |
| 915 elif name == 'SetWrapperReferenceTo': | 900 elif name == 'SetWrapperReferenceTo': |
| 916 if not child: | 901 if not child: |
| 917 raise ValueError('[SetWrapperReferenceTo] requires a child, but has none.') | 902 raise ValueError('[SetWrapperReferenceTo] requires a child, but has none.') |
| 918 children = child.GetChildren() | 903 children = child.GetChildren() |
| 919 if len(children) != 1: | 904 if len(children) != 1: |
| 920 raise ValueError('[SetWrapperReferenceTo] supports only one chil d.') | 905 raise ValueError('[SetWrapperReferenceTo] supports only one chil d.') |
| 921 if child_class != 'Arguments': | 906 if child_class != 'Arguments': |
| 922 raise ValueError('[SetWrapperReferenceTo] only supports Argument s as child, but has child of class: %s' % child_class) | 907 raise ValueError('[SetWrapperReferenceTo] only supports Argument s as child, but has child of class: %s' % child_class) |
| 923 extended_attributes[name] = IdlArgument(idl_name, children[0]) | 908 extended_attributes[name] = IdlArgument(children[0]) |
| 924 elif name == 'Exposed': | 909 elif name == 'Exposed': |
| 925 if child_class and child_class != 'Arguments': | 910 if child_class and child_class != 'Arguments': |
| 926 raise ValueError('[Exposed] only supports Arguments as child, bu t has child of class: %s' % child_class) | 911 raise ValueError('[Exposed] only supports Arguments as child, bu t has child of class: %s' % child_class) |
| 927 exposures = [] | 912 exposures = [] |
| 928 if child_class == 'Arguments': | 913 if child_class == 'Arguments': |
| 929 exposures = [Exposure(exposed=str(arg.idl_type), | 914 exposures = [Exposure(exposed=str(arg.idl_type), |
| 930 runtime_enabled=arg.name) | 915 runtime_enabled=arg.name) |
| 931 for arg in arguments_node_to_arguments('*', child)] | 916 for arg in arguments_node_to_arguments(child)] |
| 932 else: | 917 else: |
| 933 value = extended_attribute_node.GetProperty('VALUE') | 918 value = extended_attribute_node.GetProperty('VALUE') |
| 934 if type(value) is str: | 919 if type(value) is str: |
| 935 exposures = [Exposure(exposed=value)] | 920 exposures = [Exposure(exposed=value)] |
| 936 else: | 921 else: |
| 937 exposures = [Exposure(exposed=v) for v in value] | 922 exposures = [Exposure(exposed=v) for v in value] |
| 938 extended_attributes[name] = exposures | 923 extended_attributes[name] = exposures |
| 939 elif child: | 924 elif child: |
| 940 raise ValueError('ExtAttributes node with unexpected children: %s' % name) | 925 raise ValueError('ExtAttributes node with unexpected children: %s' % name) |
| 941 else: | 926 else: |
| 942 value = extended_attribute_node.GetProperty('VALUE') | 927 value = extended_attribute_node.GetProperty('VALUE') |
| 943 extended_attributes[name] = value | 928 extended_attributes[name] = value |
| 944 | 929 |
| 945 # Store constructors and custom constructors in special list attributes, | 930 # Store constructors and custom constructors in special list attributes, |
| 946 # which are deleted later. Note plural in key. | 931 # which are deleted later. Note plural in key. |
| 947 if constructors: | 932 if constructors: |
| 948 extended_attributes['Constructors'] = constructors | 933 extended_attributes['Constructors'] = constructors |
| 949 if custom_constructors: | 934 if custom_constructors: |
| 950 extended_attributes['CustomConstructors'] = custom_constructors | 935 extended_attributes['CustomConstructors'] = custom_constructors |
| 951 | 936 |
| 952 return extended_attributes | 937 return extended_attributes |
| 953 | 938 |
| 954 | 939 |
| 955 def extended_attributes_to_constructors(idl_name, extended_attributes): | 940 def extended_attributes_to_constructors(extended_attributes): |
| 956 """Returns constructors and custom_constructors (lists of IdlOperations). | 941 """Returns constructors and custom_constructors (lists of IdlOperations). |
| 957 | 942 |
| 958 Auxiliary function for IdlInterface.__init__. | 943 Auxiliary function for IdlInterface.__init__. |
| 959 """ | 944 """ |
| 960 | 945 |
| 961 constructor_list = extended_attributes.get('Constructors', []) | 946 constructor_list = extended_attributes.get('Constructors', []) |
| 962 constructors = [ | 947 constructors = [ |
| 963 IdlOperation.constructor_from_arguments_node('Constructor', idl_name, ar guments_node) | 948 IdlOperation.constructor_from_arguments_node('Constructor', arguments_no de) |
| 964 for arguments_node in constructor_list] | 949 for arguments_node in constructor_list] |
| 965 | 950 |
| 966 custom_constructor_list = extended_attributes.get('CustomConstructors', []) | 951 custom_constructor_list = extended_attributes.get('CustomConstructors', []) |
| 967 custom_constructors = [ | 952 custom_constructors = [ |
| 968 IdlOperation.constructor_from_arguments_node('CustomConstructor', idl_na me, arguments_node) | 953 IdlOperation.constructor_from_arguments_node('CustomConstructor', argume nts_node) |
| 969 for arguments_node in custom_constructor_list] | 954 for arguments_node in custom_constructor_list] |
| 970 | 955 |
| 971 if 'NamedConstructor' in extended_attributes: | 956 if 'NamedConstructor' in extended_attributes: |
| 972 # FIXME: support overloaded named constructors, and make homogeneous | 957 # FIXME: support overloaded named constructors, and make homogeneous |
| 973 name = 'NamedConstructor' | 958 name = 'NamedConstructor' |
| 974 call_node = extended_attributes['NamedConstructor'] | 959 call_node = extended_attributes['NamedConstructor'] |
| 975 extended_attributes['NamedConstructor'] = call_node.GetName() | 960 extended_attributes['NamedConstructor'] = call_node.GetName() |
| 976 children = call_node.GetChildren() | 961 children = call_node.GetChildren() |
| 977 if len(children) != 1: | 962 if len(children) != 1: |
| 978 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children)) | 963 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children)) |
| 979 arguments_node = children[0] | 964 arguments_node = children[0] |
| 980 named_constructor = IdlOperation.constructor_from_arguments_node('NamedC onstructor', idl_name, arguments_node) | 965 named_constructor = IdlOperation.constructor_from_arguments_node('NamedC onstructor', arguments_node) |
| 981 # FIXME: should return named_constructor separately; appended for Perl | 966 # FIXME: should return named_constructor separately; appended for Perl |
| 982 constructors.append(named_constructor) | 967 constructors.append(named_constructor) |
| 983 | 968 |
| 984 return constructors, custom_constructors | 969 return constructors, custom_constructors |
| 985 | 970 |
| 986 | 971 |
| 987 def clear_constructor_attributes(extended_attributes): | 972 def clear_constructor_attributes(extended_attributes): |
| 988 # Deletes Constructor*s* (plural), sets Constructor (singular) | 973 # Deletes Constructor*s* (plural), sets Constructor (singular) |
| 989 if 'Constructors' in extended_attributes: | 974 if 'Constructors' in extended_attributes: |
| 990 del extended_attributes['Constructors'] | 975 del extended_attributes['Constructors'] |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 self.visit_typed_object(argument) | 1111 self.visit_typed_object(argument) |
| 1127 | 1112 |
| 1128 def visit_iterable(self, iterable): | 1113 def visit_iterable(self, iterable): |
| 1129 self.visit_typed_object(iterable) | 1114 self.visit_typed_object(iterable) |
| 1130 | 1115 |
| 1131 def visit_maplike(self, maplike): | 1116 def visit_maplike(self, maplike): |
| 1132 self.visit_typed_object(maplike) | 1117 self.visit_typed_object(maplike) |
| 1133 | 1118 |
| 1134 def visit_setlike(self, setlike): | 1119 def visit_setlike(self, setlike): |
| 1135 self.visit_typed_object(setlike) | 1120 self.visit_typed_object(setlike) |
| OLD | NEW |