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 10 matching lines...) Expand all Loading... |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Functions shared by various parts of the code generator. | 29 """Functions shared by various parts of the code generator. |
30 | 30 |
31 Extends IdlTypeBase type with |enum_validation_expression| property. | |
32 | |
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 31 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
34 """ | 32 """ |
35 | 33 |
36 import re | 34 import re |
37 | 35 |
38 from idl_types import IdlTypeBase | 36 from idl_types import IdlTypeBase |
39 import idl_types | 37 import idl_types |
40 from idl_definitions import Exposure, IdlInterface | 38 from idl_definitions import Exposure, IdlInterface |
41 from v8_globals import includes | 39 from v8_globals import includes |
42 import v8_types | 40 import v8_types |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 for acronym in ACRONYMS: | 110 for acronym in ACRONYMS: |
113 if name.startswith(acronym): | 111 if name.startswith(acronym): |
114 return name.replace(acronym, acronym.lower()) | 112 return name.replace(acronym, acronym.lower()) |
115 return name[0].lower() + name[1:] | 113 return name[0].lower() + name[1:] |
116 | 114 |
117 | 115 |
118 ################################################################################ | 116 ################################################################################ |
119 # C++ | 117 # C++ |
120 ################################################################################ | 118 ################################################################################ |
121 | 119 |
122 def enum_validation_expression(idl_type): | |
123 # FIXME: Add IdlEnumType, move property to derived type, and remove this che
ck | |
124 if not idl_type.is_enum: | |
125 return None | |
126 return ' || '.join(['string == "%s"' % enum_value | |
127 for enum_value in idl_type.enum_values]) | |
128 IdlTypeBase.enum_validation_expression = property(enum_validation_expression) | |
129 | |
130 | |
131 def scoped_name(interface, definition, base_name): | 120 def scoped_name(interface, definition, base_name): |
132 if 'ImplementedInPrivateScript' in definition.extended_attributes: | 121 if 'ImplementedInPrivateScript' in definition.extended_attributes: |
133 return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name) | 122 return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name) |
134 # partial interfaces are implemented as separate classes, with their members | 123 # partial interfaces are implemented as separate classes, with their members |
135 # implemented as static member functions | 124 # implemented as static member functions |
136 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') | 125 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') |
137 if partial_interface_implemented_as: | 126 if partial_interface_implemented_as: |
138 return '%s::%s' % (partial_interface_implemented_as, base_name) | 127 return '%s::%s' % (partial_interface_implemented_as, base_name) |
139 if (definition.is_static or | 128 if (definition.is_static or |
140 definition.name in ('Constructor', 'NamedConstructor')): | 129 definition.name in ('Constructor', 'NamedConstructor')): |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 except StopIteration: | 508 except StopIteration: |
520 return None | 509 return None |
521 | 510 |
522 | 511 |
523 IdlInterface.indexed_property_getter = property(indexed_property_getter) | 512 IdlInterface.indexed_property_getter = property(indexed_property_getter) |
524 IdlInterface.indexed_property_setter = property(indexed_property_setter) | 513 IdlInterface.indexed_property_setter = property(indexed_property_setter) |
525 IdlInterface.indexed_property_deleter = property(indexed_property_deleter) | 514 IdlInterface.indexed_property_deleter = property(indexed_property_deleter) |
526 IdlInterface.named_property_getter = property(named_property_getter) | 515 IdlInterface.named_property_getter = property(named_property_getter) |
527 IdlInterface.named_property_setter = property(named_property_setter) | 516 IdlInterface.named_property_setter = property(named_property_setter) |
528 IdlInterface.named_property_deleter = property(named_property_deleter) | 517 IdlInterface.named_property_deleter = property(named_property_deleter) |
OLD | NEW |