| 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 import re | 7 import re |
| 8 | 8 |
| 9 from . import ast | 9 from . import ast |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 def _EnumToDict(enum): | 91 def _EnumToDict(enum): |
| 92 def EnumValueToDict(enum_value): | 92 def EnumValueToDict(enum_value): |
| 93 assert isinstance(enum_value, ast.EnumValue) | 93 assert isinstance(enum_value, ast.EnumValue) |
| 94 data = {'name': enum_value.name} | 94 data = {'name': enum_value.name} |
| 95 _AddOptional(data, 'value', enum_value.value) | 95 _AddOptional(data, 'value', enum_value.value) |
| 96 _AddOptional(data, 'attributes', | 96 _AddOptional(data, 'attributes', |
| 97 _AttributeListToDict(enum_value.attribute_list)) | 97 _AttributeListToDict(enum_value.attribute_list)) |
| 98 return data | 98 return data |
| 99 | 99 |
| 100 assert isinstance(enum, ast.Enum) | 100 assert isinstance(enum, ast.Enum) |
| 101 data = {'name': enum.name, | 101 data = { 'name': enum.name, 'native_only': enum.enum_value_list is None } |
| 102 'fields': map(EnumValueToDict, enum.enum_value_list)} | 102 if not data['native_only']: |
| 103 data['fields'] = map(EnumValueToDict, enum.enum_value_list) |
| 103 _AddOptional(data, 'attributes', _AttributeListToDict(enum.attribute_list)) | 104 _AddOptional(data, 'attributes', _AttributeListToDict(enum.attribute_list)) |
| 104 return data | 105 return data |
| 105 | 106 |
| 106 def _ConstToDict(const): | 107 def _ConstToDict(const): |
| 107 assert isinstance(const, ast.Const) | 108 assert isinstance(const, ast.Const) |
| 108 return {'name': const.name, | 109 return {'name': const.name, |
| 109 'kind': _MapKind(const.typename), | 110 'kind': _MapKind(const.typename), |
| 110 'value': const.value} | 111 'value': const.value} |
| 111 | 112 |
| 112 | 113 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 self.mojom['constants'] = \ | 217 self.mojom['constants'] = \ |
| 217 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const, name) | 218 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const, name) |
| 218 _AddOptional(self.mojom, 'attributes', | 219 _AddOptional(self.mojom, 'attributes', |
| 219 _AttributeListToDict(tree.module.attribute_list) | 220 _AttributeListToDict(tree.module.attribute_list) |
| 220 if tree.module else None) | 221 if tree.module else None) |
| 221 return self.mojom | 222 return self.mojom |
| 222 | 223 |
| 223 | 224 |
| 224 def Translate(tree, name): | 225 def Translate(tree, name): |
| 225 return _MojomBuilder().Build(tree, name) | 226 return _MojomBuilder().Build(tree, name) |
| OLD | NEW |