| 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 # FIXME: move Constructor logic into separate function, instead of modifying | 355 # FIXME: move Constructor logic into separate function, instead of modifying |
| 356 # extended attributes in-place. | 356 # extended attributes in-place. |
| 357 constructors = [] | 357 constructors = [] |
| 358 custom_constructors = [] | 358 custom_constructors = [] |
| 359 extended_attributes = {} | 359 extended_attributes = {} |
| 360 | 360 |
| 361 attribute_list = node.GetChildren() | 361 attribute_list = node.GetChildren() |
| 362 for attribute in attribute_list: | 362 for attribute in attribute_list: |
| 363 name = attribute.GetName() | 363 name = attribute.GetName() |
| 364 children = attribute.GetChildren() | 364 children = attribute.GetChildren() |
| 365 if name in ['Constructor', 'CustomConstructor', 'NamedConstructor']: | 365 if children: |
| 366 if len(children) > 1: |
| 367 raise ValueError('ExtAttributes node with %s children, expected
at most 1' % len(children)) |
| 368 child = children[0] |
| 369 child_class = child.GetClass() |
| 370 else: |
| 366 child = None | 371 child = None |
| 367 child_class = None | 372 child_class = None |
| 368 if children: | 373 if name == 'Constructor': |
| 369 if len(children) > 1: | 374 if child_class and child_class != 'Arguments': |
| 370 raise ValueError('ExtAttributes node with %s children, expec
ted at most 1' % len(children)) | 375 raise ValueError('Constructor only supports Arguments as child,
but has child of class: %s' % child_class) |
| 371 child = children[0] | 376 constructors.append(child) |
| 372 child_class = child.GetClass() | 377 elif name == 'CustomConstructor': |
| 373 if name == 'Constructor': | 378 if child_class and child_class != 'Arguments': |
| 374 if child_class and child_class != 'Arguments': | 379 raise ValueError('[CustomConstructor] only supports Arguments as
child, but has child of class: %s' % child_class) |
| 375 raise ValueError('Constructor only supports Arguments as chi
ld, but has child of class: %s' % child_class) | 380 custom_constructors.append(child) |
| 376 constructors.append(child) | 381 elif name == 'NamedConstructor': |
| 377 elif name == 'CustomConstructor': | 382 if child_class and child_class != 'Call': |
| 378 if child_class and child_class != 'Arguments': | 383 raise ValueError('[NamedConstructor] only supports Call as child
, but has child of class: %s' % child_class) |
| 379 raise ValueError('Custom Constructor only supports Arguments
as child, but has child of class: %s' % child_class) | 384 extended_attributes[name] = child |
| 380 custom_constructors.append(child) | 385 elif name == 'SetReference': |
| 381 else: # name == 'NamedConstructor' | 386 if not child: |
| 382 if child_class and child_class != 'Call': | 387 raise ValueError('[SetReference] requires a child, but has none.
') |
| 383 raise ValueError('Named Constructor only supports Call as ch
ild, but has child of class: %s' % child_class) | 388 if child_class != 'Arguments': |
| 384 extended_attributes[name] = child | 389 raise ValueError('[SetReference] only supports Arguments as chil
d, but has child of class: %s' % child_class) |
| 390 extended_attributes[name] = arguments_node_to_arguments(child) |
| 385 elif children: | 391 elif children: |
| 386 raise ValueError('Non-constructor ExtAttributes node with children:
%s' % name) | 392 raise ValueError('ExtAttributes node with unexpected children: %s' %
name) |
| 387 else: | 393 else: |
| 388 value = attribute.GetProperty('VALUE') | 394 value = attribute.GetProperty('VALUE') |
| 389 extended_attributes[name] = value | 395 extended_attributes[name] = value |
| 390 | 396 |
| 391 # Store constructors and custom constructors in special list attributes, | 397 # Store constructors and custom constructors in special list attributes, |
| 392 # which are deleted later. Note plural in key. | 398 # which are deleted later. Note plural in key. |
| 393 if constructors: | 399 if constructors: |
| 394 extended_attributes['Constructors'] = constructors | 400 extended_attributes['Constructors'] = constructors |
| 395 if custom_constructors: | 401 if custom_constructors: |
| 396 extended_attributes['CustomConstructors'] = custom_constructors | 402 extended_attributes['CustomConstructors'] = custom_constructors |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 sequence_type = type_node_to_type(sequence_child) | 508 sequence_type = type_node_to_type(sequence_child) |
| 503 return 'sequence<%s>' % sequence_type | 509 return 'sequence<%s>' % sequence_type |
| 504 | 510 |
| 505 | 511 |
| 506 def union_type_node_to_idl_union_type(node): | 512 def union_type_node_to_idl_union_type(node): |
| 507 union_member_types = [] | 513 union_member_types = [] |
| 508 for member_type_node in node.GetChildren(): | 514 for member_type_node in node.GetChildren(): |
| 509 member_type = type_node_to_type(member_type_node) | 515 member_type = type_node_to_type(member_type_node) |
| 510 union_member_types.append(member_type) | 516 union_member_types.append(member_type) |
| 511 return IdlUnionType(union_member_types=union_member_types) | 517 return IdlUnionType(union_member_types=union_member_types) |
| OLD | NEW |