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 | 9 |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 struct = {} | 81 struct = {} |
82 struct['name'] = tree[1] | 82 struct['name'] = tree[1] |
83 struct['attributes'] = _MapAttributes(tree[2]) | 83 struct['attributes'] = _MapAttributes(tree[2]) |
84 struct['fields'] = _MapTree(_MapField, tree[3], 'FIELD') | 84 struct['fields'] = _MapTree(_MapField, tree[3], 'FIELD') |
85 struct['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM') | 85 struct['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM') |
86 return struct | 86 return struct |
87 | 87 |
88 def _MapInterface(tree): | 88 def _MapInterface(tree): |
89 interface = {} | 89 interface = {} |
90 interface['name'] = tree[1] | 90 interface['name'] = tree[1] |
91 interface['peer'] = _GetAttribute(tree[2], 'Peer') | 91 interface['client'] = _GetAttribute(tree[2], 'Client') |
92 interface['methods'] = _MapTree(_MapMethod, tree[3], 'METHOD') | 92 interface['methods'] = _MapTree(_MapMethod, tree[3], 'METHOD') |
93 interface['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM') | 93 interface['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM') |
94 return interface | 94 return interface |
95 | 95 |
96 def _MapEnum(tree): | 96 def _MapEnum(tree): |
97 enum = {} | 97 enum = {} |
98 enum['name'] = tree[1] | 98 enum['name'] = tree[1] |
99 enum['fields'] = _MapTree(_MapEnumField, tree[2], 'ENUM_FIELD') | 99 enum['fields'] = _MapTree(_MapEnumField, tree[2], 'ENUM_FIELD') |
100 return enum | 100 return enum |
101 | 101 |
(...skipping 21 matching lines...) Expand all Loading... |
123 modules = [_MapModule(item, name) for item in tree if item[0] == 'MODULE'] | 123 modules = [_MapModule(item, name) for item in tree if item[0] == 'MODULE'] |
124 if len(modules) != 1: | 124 if len(modules) != 1: |
125 raise Exception('A mojom file must contain exactly 1 module.') | 125 raise Exception('A mojom file must contain exactly 1 module.') |
126 self.mojom = modules[0] | 126 self.mojom = modules[0] |
127 self.mojom['imports'] = _MapTree(_MapImport, tree, 'IMPORT') | 127 self.mojom['imports'] = _MapTree(_MapImport, tree, 'IMPORT') |
128 return self.mojom | 128 return self.mojom |
129 | 129 |
130 | 130 |
131 def Translate(tree, name): | 131 def Translate(tree, name): |
132 return _MojomBuilder().Build(tree, name) | 132 return _MojomBuilder().Build(tree, name) |
OLD | NEW |