| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Translates parse tree to Mojom IR.""" | 5 """Translates parse tree to Mojom IR.""" |
| 6 | 6 |
| 7 | 7 |
| 8 import ast | 8 import ast |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 'uint32': 'u32', | 28 'uint32': 'u32', |
| 29 'uint64': 'u64', | 29 'uint64': 'u64', |
| 30 'float': 'f', | 30 'float': 'f', |
| 31 'double': 'd', | 31 'double': 'd', |
| 32 'string': 's', | 32 'string': 's', |
| 33 'handle': 'h', | 33 'handle': 'h', |
| 34 'handle<data_pipe_consumer>': 'h:d:c', | 34 'handle<data_pipe_consumer>': 'h:d:c', |
| 35 'handle<data_pipe_producer>': 'h:d:p', | 35 'handle<data_pipe_producer>': 'h:d:p', |
| 36 'handle<message_pipe>': 'h:m', | 36 'handle<message_pipe>': 'h:m', |
| 37 'handle<shared_buffer>': 'h:s'} | 37 'handle<shared_buffer>': 'h:s'} |
| 38 if kind.endswith('?'): |
| 39 base_kind = _MapKind(kind[0:-1]) |
| 40 # NOTE: This doesn't rule out enum types. Those will be detected later, when |
| 41 # cross-reference is established. |
| 42 reference_kinds = ('s', 'h', 'a', 'r', 'x') |
| 43 if base_kind[0] not in reference_kinds: |
| 44 raise Exception( |
| 45 'A type (spec "%s") cannot be made nullable' % base_kind) |
| 46 return '?' + base_kind |
| 38 if kind.endswith('[]'): | 47 if kind.endswith('[]'): |
| 39 typename = kind[0:-2] | 48 typename = kind[0:-2] |
| 40 if _FIXED_ARRAY_REGEXP.search(typename): | 49 if _FIXED_ARRAY_REGEXP.search(typename): |
| 41 raise Exception("Arrays of fixed sized arrays not supported") | 50 raise Exception('Arrays of fixed sized arrays not supported') |
| 42 return 'a:' + _MapKind(typename) | 51 return 'a:' + _MapKind(typename) |
| 43 if kind.endswith(']'): | 52 if kind.endswith(']'): |
| 44 lbracket = kind.rfind('[') | 53 lbracket = kind.rfind('[') |
| 45 typename = kind[0:lbracket] | 54 typename = kind[0:lbracket] |
| 46 if typename.find('[') != -1: | 55 if typename.find('[') != -1: |
| 47 raise Exception("Fixed sized arrays of arrays not supported") | 56 raise Exception('Fixed sized arrays of arrays not supported') |
| 48 return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) | 57 return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) |
| 49 if kind.endswith('&'): | 58 if kind.endswith('&'): |
| 50 return 'r:' + _MapKind(kind[0:-1]) | 59 return 'r:' + _MapKind(kind[0:-1]) |
| 51 if kind in map_to_kind: | 60 if kind in map_to_kind: |
| 52 return map_to_kind[kind] | 61 return map_to_kind[kind] |
| 53 return 'x:' + kind | 62 return 'x:' + kind |
| 54 | 63 |
| 55 def _AttributeListToDict(attribute_list): | 64 def _AttributeListToDict(attribute_list): |
| 56 if attribute_list is None: | 65 if attribute_list is None: |
| 57 return {} | 66 return {} |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) | 150 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) |
| 142 self.mojom['enums'] = \ | 151 self.mojom['enums'] = \ |
| 143 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) | 152 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) |
| 144 self.mojom['constants'] = \ | 153 self.mojom['constants'] = \ |
| 145 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) | 154 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) |
| 146 return self.mojom | 155 return self.mojom |
| 147 | 156 |
| 148 | 157 |
| 149 def Translate(tree, name): | 158 def Translate(tree, name): |
| 150 return _MojomBuilder().Build(tree, name) | 159 return _MojomBuilder().Build(tree, name) |
| OLD | NEW |