| 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 re | 8 import re |
| 9 | 9 |
| 10 from . import ast | 10 from . import ast |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 'string': 's', | 33 'string': 's', |
| 34 'handle': 'h', | 34 'handle': 'h', |
| 35 'handle<data_pipe_consumer>': 'h:d:c', | 35 'handle<data_pipe_consumer>': 'h:d:c', |
| 36 'handle<data_pipe_producer>': 'h:d:p', | 36 'handle<data_pipe_producer>': 'h:d:p', |
| 37 'handle<message_pipe>': 'h:m', | 37 'handle<message_pipe>': 'h:m', |
| 38 'handle<shared_buffer>': 'h:s'} | 38 'handle<shared_buffer>': 'h:s'} |
| 39 if kind.endswith('?'): | 39 if kind.endswith('?'): |
| 40 base_kind = _MapKind(kind[0:-1]) | 40 base_kind = _MapKind(kind[0:-1]) |
| 41 # NOTE: This doesn't rule out enum types. Those will be detected later, when | 41 # NOTE: This doesn't rule out enum types. Those will be detected later, when |
| 42 # cross-reference is established. | 42 # cross-reference is established. |
| 43 reference_kinds = ('s', 'h', 'a', 'r', 'x') | 43 reference_kinds = ('m', 's', 'h', 'a', 'r', 'x') |
| 44 if base_kind[0] not in reference_kinds: | 44 if base_kind[0] not in reference_kinds: |
| 45 raise Exception( | 45 raise Exception( |
| 46 'A type (spec "%s") cannot be made nullable' % base_kind) | 46 'A type (spec "%s") cannot be made nullable' % base_kind) |
| 47 return '?' + base_kind | 47 return '?' + base_kind |
| 48 if kind.endswith('}'): |
| 49 lbracket = kind.rfind('{') |
| 50 value = kind[0:lbracket] |
| 51 return 'm[' + _MapKind(kind[lbracket+1:-1]) + '][' + _MapKind(value) + ']' |
| 48 if kind.endswith('[]'): | 52 if kind.endswith('[]'): |
| 49 typename = kind[0:-2] | 53 typename = kind[0:-2] |
| 50 if _FIXED_ARRAY_REGEXP.search(typename): | 54 if _FIXED_ARRAY_REGEXP.search(typename): |
| 51 raise Exception('Arrays of fixed sized arrays not supported') | 55 raise Exception('Arrays of fixed sized arrays not supported') |
| 52 return 'a:' + _MapKind(typename) | 56 return 'a:' + _MapKind(typename) |
| 53 if kind.endswith(']'): | 57 if kind.endswith(']'): |
| 54 lbracket = kind.rfind('[') | 58 lbracket = kind.rfind('[') |
| 55 typename = kind[0:lbracket] | 59 typename = kind[0:lbracket] |
| 56 if typename.find('[') != -1: | 60 if typename.find('[') != -1: |
| 57 raise Exception('Fixed sized arrays of arrays not supported') | 61 raise Exception('Fixed sized arrays of arrays not supported') |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) | 155 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) |
| 152 self.mojom['enums'] = \ | 156 self.mojom['enums'] = \ |
| 153 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) | 157 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) |
| 154 self.mojom['constants'] = \ | 158 self.mojom['constants'] = \ |
| 155 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) | 159 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) |
| 156 return self.mojom | 160 return self.mojom |
| 157 | 161 |
| 158 | 162 |
| 159 def Translate(tree, name): | 163 def Translate(tree, name): |
| 160 return _MojomBuilder().Build(tree, name) | 164 return _MojomBuilder().Build(tree, name) |
| OLD | NEW |