| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 TypedObject :: Object with one or more attributes that is a type. | 58 TypedObject :: Object with one or more attributes that is a type. |
| 59 | 59 |
| 60 IdlArgument is 'picklable', as it is stored in interfaces_info. | 60 IdlArgument is 'picklable', as it is stored in interfaces_info. |
| 61 | 61 |
| 62 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 62 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| 63 """ | 63 """ |
| 64 | 64 |
| 65 import abc | 65 import abc |
| 66 | 66 |
| 67 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlN
ullableType | 67 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlF
rozenArrayType, IdlNullableType |
| 68 | 68 |
| 69 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] | 69 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] |
| 70 | 70 |
| 71 | 71 |
| 72 ################################################################################ | 72 ################################################################################ |
| 73 # TypedObject | 73 # TypedObject |
| 74 ################################################################################ | 74 ################################################################################ |
| 75 | 75 |
| 76 class TypedObject(object): | 76 class TypedObject(object): |
| 77 """Object with a type, such as an Attribute or Operation (return value). | 77 """Object with a type, such as an Attribute or Operation (return value). |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 node_class = node.GetClass() | 1012 node_class = node.GetClass() |
| 1013 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus | 1013 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus |
| 1014 # either a typedef shorthand (but not a Typedef declaration itself) or an | 1014 # either a typedef shorthand (but not a Typedef declaration itself) or an |
| 1015 # interface type. We do not distinguish these, and just use the type name. | 1015 # interface type. We do not distinguish these, and just use the type name. |
| 1016 if node_class in ['PrimitiveType', 'Typeref']: | 1016 if node_class in ['PrimitiveType', 'Typeref']: |
| 1017 # unrestricted syntax: unrestricted double | unrestricted float | 1017 # unrestricted syntax: unrestricted double | unrestricted float |
| 1018 is_unrestricted = bool(node.GetProperty('UNRESTRICTED')) | 1018 is_unrestricted = bool(node.GetProperty('UNRESTRICTED')) |
| 1019 return IdlType(node.GetName(), is_unrestricted=is_unrestricted) | 1019 return IdlType(node.GetName(), is_unrestricted=is_unrestricted) |
| 1020 elif node_class == 'Any': | 1020 elif node_class == 'Any': |
| 1021 return IdlType('any') | 1021 return IdlType('any') |
| 1022 elif node_class == 'Sequence': | 1022 elif node_class in ['Sequence', 'FrozenArray']: |
| 1023 return sequence_node_to_type(node) | 1023 return sequence_node_to_type(node) |
| 1024 elif node_class == 'UnionType': | 1024 elif node_class == 'UnionType': |
| 1025 return union_type_node_to_idl_union_type(node) | 1025 return union_type_node_to_idl_union_type(node) |
| 1026 elif node_class == 'Promise': | 1026 elif node_class == 'Promise': |
| 1027 return IdlType('Promise') | 1027 return IdlType('Promise') |
| 1028 raise ValueError('Unrecognized node class: %s' % node_class) | 1028 raise ValueError('Unrecognized node class: %s' % node_class) |
| 1029 | 1029 |
| 1030 | 1030 |
| 1031 def sequence_node_to_type(node): | 1031 def sequence_node_to_type(node): |
| 1032 children = node.GetChildren() | 1032 children = node.GetChildren() |
| 1033 class_name = node.GetClass() |
| 1033 if len(children) != 1: | 1034 if len(children) != 1: |
| 1034 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c
hildren)) | 1035 raise ValueError('%s node expects exactly 1 child, got %s' % (class_name
, len(children))) |
| 1035 sequence_child = children[0] | 1036 sequence_child = children[0] |
| 1036 sequence_child_class = sequence_child.GetClass() | 1037 sequence_child_class = sequence_child.GetClass() |
| 1037 if sequence_child_class != 'Type': | 1038 if sequence_child_class != 'Type': |
| 1038 raise ValueError('Unrecognized node class: %s' % sequence_child_class) | 1039 raise ValueError('Unrecognized node class: %s' % sequence_child_class) |
| 1039 element_type = type_node_to_type(sequence_child) | 1040 element_type = type_node_to_type(sequence_child) |
| 1040 sequence_type = IdlSequenceType(element_type) | 1041 if class_name == 'Sequence': |
| 1042 sequence_type = IdlSequenceType(element_type) |
| 1043 elif class_name == 'FrozenArray': |
| 1044 sequence_type = IdlFrozenArrayType(element_type) |
| 1045 else: |
| 1046 raise ValueError('Unexpected node: %s' % class_name) |
| 1041 if node.GetProperty('NULLABLE'): | 1047 if node.GetProperty('NULLABLE'): |
| 1042 return IdlNullableType(sequence_type) | 1048 return IdlNullableType(sequence_type) |
| 1043 return sequence_type | 1049 return sequence_type |
| 1044 | 1050 |
| 1045 | 1051 |
| 1046 def typedef_node_to_type(node): | 1052 def typedef_node_to_type(node): |
| 1047 children = node.GetChildren() | 1053 children = node.GetChildren() |
| 1048 if len(children) != 1: | 1054 if len(children) != 1: |
| 1049 raise ValueError('Typedef node with %s children, expected 1' % len(child
ren)) | 1055 raise ValueError('Typedef node with %s children, expected 1' % len(child
ren)) |
| 1050 child = children[0] | 1056 child = children[0] |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 self.visit_typed_object(argument) | 1107 self.visit_typed_object(argument) |
| 1102 | 1108 |
| 1103 def visit_iterable(self, iterable): | 1109 def visit_iterable(self, iterable): |
| 1104 self.visit_typed_object(iterable) | 1110 self.visit_typed_object(iterable) |
| 1105 | 1111 |
| 1106 def visit_maplike(self, maplike): | 1112 def visit_maplike(self, maplike): |
| 1107 self.visit_typed_object(maplike) | 1113 self.visit_typed_object(maplike) |
| 1108 | 1114 |
| 1109 def visit_setlike(self, setlike): | 1115 def visit_setlike(self, setlike): |
| 1110 self.visit_typed_object(setlike) | 1116 self.visit_typed_object(setlike) |
| OLD | NEW |