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 decorated_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 if decorated_kind[0] not in ('s', 'h', 'a', 'r', 'x'): | |
darin (slow to review)
2014/08/03 05:57:58
nit: might be nice to get this tuple a name, like
yzshen1
2014/08/03 08:27:46
Sounds good.
| |
43 raise Exception( | |
44 'A type (spec "%s") cannot be made nullable' % decorated_kind) | |
45 return '?' + decorated_kind | |
38 if kind.endswith('[]'): | 46 if kind.endswith('[]'): |
39 typename = kind[0:-2] | 47 typename = kind[0:-2] |
40 if _FIXED_ARRAY_REGEXP.search(typename): | 48 if _FIXED_ARRAY_REGEXP.search(typename): |
41 raise Exception("Arrays of fixed sized arrays not supported") | 49 raise Exception('Arrays of fixed sized arrays not supported') |
42 return 'a:' + _MapKind(typename) | 50 return 'a:' + _MapKind(typename) |
43 if kind.endswith(']'): | 51 if kind.endswith(']'): |
44 lbracket = kind.rfind('[') | 52 lbracket = kind.rfind('[') |
45 typename = kind[0:lbracket] | 53 typename = kind[0:lbracket] |
46 if typename.find('[') != -1: | 54 if typename.find('[') != -1: |
47 raise Exception("Fixed sized arrays of arrays not supported") | 55 raise Exception('Fixed sized arrays of arrays not supported') |
48 return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) | 56 return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) |
49 if kind.endswith('&'): | 57 if kind.endswith('&'): |
50 return 'r:' + _MapKind(kind[0:-1]) | 58 return 'r:' + _MapKind(kind[0:-1]) |
51 if kind in map_to_kind: | 59 if kind in map_to_kind: |
52 return map_to_kind[kind] | 60 return map_to_kind[kind] |
53 return 'x:' + kind | 61 return 'x:' + kind |
54 | 62 |
55 def _AttributeListToDict(attribute_list): | 63 def _AttributeListToDict(attribute_list): |
56 if attribute_list is None: | 64 if attribute_list is None: |
57 return {} | 65 return {} |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) | 149 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) |
142 self.mojom['enums'] = \ | 150 self.mojom['enums'] = \ |
143 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) | 151 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) |
144 self.mojom['constants'] = \ | 152 self.mojom['constants'] = \ |
145 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) | 153 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) |
146 return self.mojom | 154 return self.mojom |
147 | 155 |
148 | 156 |
149 def Translate(tree, name): | 157 def Translate(tree, name): |
150 return _MojomBuilder().Build(tree, name) | 158 return _MojomBuilder().Build(tree, name) |
OLD | NEW |