Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/parse/translate.py

Issue 1515423002: [mojo] Add mojom parser support for native-only structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pickle2
Patch Set: oops Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/parser.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 _AddOptional(data, 'ordinal', 123 _AddOptional(data, 'ordinal',
124 struct_field.ordinal.value 124 struct_field.ordinal.value
125 if struct_field.ordinal else None) 125 if struct_field.ordinal else None)
126 _AddOptional(data, 'default', struct_field.default_value) 126 _AddOptional(data, 'default', struct_field.default_value)
127 _AddOptional(data, 'attributes', 127 _AddOptional(data, 'attributes',
128 _AttributeListToDict(struct_field.attribute_list)) 128 _AttributeListToDict(struct_field.attribute_list))
129 return data 129 return data
130 130
131 assert isinstance(struct, ast.Struct) 131 assert isinstance(struct, ast.Struct)
132 data = {'name': struct.name, 132 data = {'name': struct.name,
133 'fields': _MapTreeForType(StructFieldToDict, struct.body, 133 'native_only': struct.body is None}
134 ast.StructField, struct.name), 134 if not data['native_only']:
135 'enums': _MapTreeForType(_EnumToDict, struct.body, ast.Enum, 135 data.update({
136 struct.name), 136 'fields': _MapTreeForType(StructFieldToDict, struct.body,
137 'constants': _MapTreeForType(_ConstToDict, struct.body, 137 ast.StructField, struct.name),
138 ast.Const, struct.name)} 138 'enums': _MapTreeForType(_EnumToDict, struct.body, ast.Enum,
139 struct.name),
140 'constants': _MapTreeForType(_ConstToDict, struct.body,
141 ast.Const, struct.name)})
139 _AddOptional(data, 'attributes', 142 _AddOptional(data, 'attributes',
140 _AttributeListToDict(struct.attribute_list)) 143 _AttributeListToDict(struct.attribute_list))
141 return data 144 return data
142 145
143 def UnionToDict(union): 146 def UnionToDict(union):
144 def UnionFieldToDict(union_field): 147 def UnionFieldToDict(union_field):
145 assert isinstance(union_field, ast.UnionField) 148 assert isinstance(union_field, ast.UnionField)
146 data = {'name': union_field.name, 149 data = {'name': union_field.name,
147 'kind': _MapKind(union_field.typename)} 150 'kind': _MapKind(union_field.typename)}
148 _AddOptional(data, 'ordinal', 151 _AddOptional(data, 'ordinal',
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 self.mojom['constants'] = \ 216 self.mojom['constants'] = \
214 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const, name) 217 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const, name)
215 _AddOptional(self.mojom, 'attributes', 218 _AddOptional(self.mojom, 'attributes',
216 _AttributeListToDict(tree.module.attribute_list) 219 _AttributeListToDict(tree.module.attribute_list)
217 if tree.module else None) 220 if tree.module else None)
218 return self.mojom 221 return self.mojom
219 222
220 223
221 def Translate(tree, name): 224 def Translate(tree, name):
222 return _MojomBuilder().Build(tree, name) 225 return _MojomBuilder().Build(tree, name)
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698