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

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

Issue 363033004: Mojo: bindings generator: Add an AST type for parameter lists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 5 months 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 | Annotate | Revision Log
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 import ast 8 import ast
9 import re 9 import re
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return out 66 return out
67 67
68 def _MapField(tree): 68 def _MapField(tree):
69 assert isinstance(tree[3], ast.Ordinal) 69 assert isinstance(tree[3], ast.Ordinal)
70 return {'name': tree[2], 70 return {'name': tree[2],
71 'kind': _MapKind(tree[1]), 71 'kind': _MapKind(tree[1]),
72 'ordinal': tree[3].value, 72 'ordinal': tree[3].value,
73 'default': tree[4]} 73 'default': tree[4]}
74 74
75 def _MapMethod(tree): 75 def _MapMethod(tree):
76 assert isinstance(tree[2], ast.ParameterList)
77 assert isinstance(tree[3], ast.Ordinal)
78 assert tree[4] is None or isinstance(tree[2], ast.ParameterList)
79
76 def ParameterToDict(param): 80 def ParameterToDict(param):
77 assert isinstance(param, ast.Parameter) 81 assert isinstance(param, ast.Parameter)
78 return {'name': param.name, 82 return {'name': param.name,
79 'kind': _MapKind(param.typename), 83 'kind': _MapKind(param.typename),
80 'ordinal': param.ordinal.value} 84 'ordinal': param.ordinal.value}
81 85
82 assert isinstance(tree[2], list)
83 assert isinstance(tree[3], ast.Ordinal)
84 method = {'name': tree[1], 86 method = {'name': tree[1],
85 'parameters': map(ParameterToDict, tree[2]), 87 'parameters': map(ParameterToDict, tree[2]),
86 'ordinal': tree[3].value} 88 'ordinal': tree[3].value}
87 # Note: |tree[4]| may be an empty list, indicating a parameter-less response. 89 if tree[4]:
88 if tree[4] is not None:
89 method['response_parameters'] = map(ParameterToDict, tree[4]) 90 method['response_parameters'] = map(ParameterToDict, tree[4])
90 return method 91 return method
91 92
92 def _MapEnumField(tree): 93 def _MapEnumField(tree):
93 return {'name': tree[1], 94 return {'name': tree[1],
94 'value': tree[2]} 95 'value': tree[2]}
95 96
96 def _MapStruct(tree): 97 def _MapStruct(tree):
97 struct = {} 98 struct = {}
98 struct['name'] = tree[1] 99 struct['name'] = tree[1]
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 modules = [_MapModule(item, name) for item in tree if item[0] == 'MODULE'] 150 modules = [_MapModule(item, name) for item in tree if item[0] == 'MODULE']
150 if len(modules) != 1: 151 if len(modules) != 1:
151 raise Exception('A mojom file must contain exactly 1 module.') 152 raise Exception('A mojom file must contain exactly 1 module.')
152 self.mojom = modules[0] 153 self.mojom = modules[0]
153 self.mojom['imports'] = _MapTree(_MapImport, tree, 'IMPORT') 154 self.mojom['imports'] = _MapTree(_MapImport, tree, 'IMPORT')
154 return self.mojom 155 return self.mojom
155 156
156 157
157 def Translate(tree, name): 158 def Translate(tree, name):
158 return _MojomBuilder().Build(tree, name) 159 return _MojomBuilder().Build(tree, name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698