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

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

Issue 799113004: Update mojo sdk to rev 59145288bae55b0fce4276b017df6a1117bcf00f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add mojo's ply to checklicenses whitelist Created 6 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
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 7
8 from . import ast 8 from . import ast
9 9
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 assert isinstance(struct, ast.Struct) 97 assert isinstance(struct, ast.Struct)
98 return {'name': struct.name, 98 return {'name': struct.name,
99 'attributes': _AttributeListToDict(struct.attribute_list), 99 'attributes': _AttributeListToDict(struct.attribute_list),
100 'fields': _MapTreeForType(StructFieldToDict, struct.body, 100 'fields': _MapTreeForType(StructFieldToDict, struct.body,
101 ast.StructField), 101 ast.StructField),
102 'enums': _MapTreeForType(_EnumToDict, struct.body, ast.Enum), 102 'enums': _MapTreeForType(_EnumToDict, struct.body, ast.Enum),
103 'constants': _MapTreeForType(_ConstToDict, struct.body, 103 'constants': _MapTreeForType(_ConstToDict, struct.body,
104 ast.Const)} 104 ast.Const)}
105 105
106 def UnionToDict(union):
107 def UnionFieldToDict(union_field):
108 assert isinstance(union_field, ast.UnionField)
109 return {'name': union_field.name,
110 'kind': _MapKind(union_field.typename),
111 'ordinal': union_field.ordinal.value \
112 if union_field.ordinal else None}
113 assert isinstance(union, ast.Union)
114 return {'name': union.name,
115 'fields': _MapTreeForType(UnionFieldToDict, union.body,
116 ast.UnionField)}
117
106 def InterfaceToDict(interface): 118 def InterfaceToDict(interface):
107 def MethodToDict(method): 119 def MethodToDict(method):
108 def ParameterToDict(param): 120 def ParameterToDict(param):
109 assert isinstance(param, ast.Parameter) 121 assert isinstance(param, ast.Parameter)
110 return {'name': param.name, 122 return {'name': param.name,
111 'kind': _MapKind(param.typename), 123 'kind': _MapKind(param.typename),
112 'ordinal': param.ordinal.value if param.ordinal else None} 124 'ordinal': param.ordinal.value if param.ordinal else None}
113 125
114 assert isinstance(method, ast.Method) 126 assert isinstance(method, ast.Method)
115 rv = {'name': method.name, 127 rv = {'name': method.name,
(...skipping 17 matching lines...) Expand all
133 145
134 assert isinstance(tree, ast.Mojom) 146 assert isinstance(tree, ast.Mojom)
135 self.mojom['name'] = name 147 self.mojom['name'] = name
136 self.mojom['namespace'] = tree.module.name[1] if tree.module else '' 148 self.mojom['namespace'] = tree.module.name[1] if tree.module else ''
137 self.mojom['imports'] = \ 149 self.mojom['imports'] = \
138 [{'filename': imp.import_filename} for imp in tree.import_list] 150 [{'filename': imp.import_filename} for imp in tree.import_list]
139 self.mojom['attributes'] = \ 151 self.mojom['attributes'] = \
140 _AttributeListToDict(tree.module.attribute_list) if tree.module else {} 152 _AttributeListToDict(tree.module.attribute_list) if tree.module else {}
141 self.mojom['structs'] = \ 153 self.mojom['structs'] = \
142 _MapTreeForType(StructToDict, tree.definition_list, ast.Struct) 154 _MapTreeForType(StructToDict, tree.definition_list, ast.Struct)
155 self.mojom['union'] = \
156 _MapTreeForType(UnionToDict, tree.definition_list, ast.Union)
143 self.mojom['interfaces'] = \ 157 self.mojom['interfaces'] = \
144 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface) 158 _MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface)
145 self.mojom['enums'] = \ 159 self.mojom['enums'] = \
146 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum) 160 _MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum)
147 self.mojom['constants'] = \ 161 self.mojom['constants'] = \
148 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const) 162 _MapTreeForType(_ConstToDict, tree.definition_list, ast.Const)
149 return self.mojom 163 return self.mojom
150 164
151 165
152 def Translate(tree, name): 166 def Translate(tree, name):
153 return _MojomBuilder().Build(tree, name) 167 return _MojomBuilder().Build(tree, name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698