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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 typename = kind[0:-2] | 49 typename = kind[0:-2] |
50 if _FIXED_ARRAY_REGEXP.search(typename): | 50 if _FIXED_ARRAY_REGEXP.search(typename): |
51 raise Exception('Arrays of fixed sized arrays not supported') | 51 raise Exception('Arrays of fixed sized arrays not supported') |
52 return 'a:' + _MapKind(typename) | 52 return 'a:' + _MapKind(typename) |
53 if kind.endswith(']'): | 53 if kind.endswith(']'): |
54 lbracket = kind.rfind('[') | 54 lbracket = kind.rfind('[') |
55 typename = kind[0:lbracket] | 55 typename = kind[0:lbracket] |
56 if typename.find('[') != -1: | 56 if typename.find('[') != -1: |
57 raise Exception('Fixed sized arrays of arrays not supported') | 57 raise Exception('Fixed sized arrays of arrays not supported') |
58 return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) | 58 return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) |
| 59 if kind.endswith('}'): |
| 60 lbracket = kind.rfind('{') |
| 61 value = kind[0:lbracket] |
| 62 return 'm[' + _MapKind(kind[lbracket+1:-1]) + '][' + _MapKind(value) + ']' |
59 if kind.endswith('&'): | 63 if kind.endswith('&'): |
60 return 'r:' + _MapKind(kind[0:-1]) | 64 return 'r:' + _MapKind(kind[0:-1]) |
61 if kind in map_to_kind: | 65 if kind in map_to_kind: |
62 return map_to_kind[kind] | 66 return map_to_kind[kind] |
63 return 'x:' + kind | 67 return 'x:' + kind |
64 | 68 |
65 def _AttributeListToDict(attribute_list): | 69 def _AttributeListToDict(attribute_list): |
66 if attribute_list is None: | 70 if attribute_list is None: |
67 return {} | 71 return {} |
68 assert isinstance(attribute_list, ast.AttributeList) | 72 assert isinstance(attribute_list, ast.AttributeList) |
(...skipping 82 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 |