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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/generator.py

Issue 1824263002: Mojom backend: Stop re-computing version info and field packing data. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Code shared by the various language-specific code generators.""" 5 """Code shared by the various language-specific code generators."""
6 6
7 from functools import partial 7 from functools import partial
8 import os.path 8 import os.path
9 import re 9 import re
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 """Returns default constructor parameters for the jinja environment.""" 81 """Returns default constructor parameters for the jinja environment."""
82 return {} 82 return {}
83 83
84 def GetGlobals(self): 84 def GetGlobals(self):
85 """Returns global mappings for the template generation.""" 85 """Returns global mappings for the template generation."""
86 return {} 86 return {}
87 87
88 def _AddStructComputedData(self, exported, struct): 88 def _AddStructComputedData(self, exported, struct):
89 """Adds computed data to the given struct. The data is computed once and 89 """Adds computed data to the given struct. The data is computed once and
90 used repeatedly in the generation process.""" 90 used repeatedly in the generation process."""
91 struct.packed = pack.PackedStruct(struct) 91 if not hasattr(struct, 'packed') or struct.packed is None:
92 struct.bytes = pack.GetByteLayout(struct.packed) 92 struct.packed = pack.PackedStruct(struct)
93 struct.versions = pack.GetVersionInfo(struct.packed) 93 struct.bytes = pack.GetByteLayout(struct.packed)
94 struct.exported = exported 94 struct.exported = exported
95 return struct 95 return struct
96 96
97 def _AddInterfaceComputedData(self, interface): 97 def _AddInterfaceComputedData(self, interface):
98 """Adds computed data to the given interface. The data is computed once and 98 """Adds computed data to the given interface. The data is computed once and
99 used repeatedly in the generation process.""" 99 used repeatedly in the generation process."""
100 # Here we set the interface's |version| attribute to be the maximum value
101 # of the |min_version| attributes of all methods in the interface and all
102 # parameters in those methods.
103 # TODO(rudominer) Consider adding this value to the intermediate
104 # representation.
100 interface.version = 0 105 interface.version = 0
101 for method in interface.methods: 106 for method in interface.methods:
102 if method.min_version is not None: 107 if method.min_version is not None:
103 interface.version = max(interface.version, method.min_version) 108 interface.version = max(interface.version, method.min_version)
104 109
105 method.param_struct = self._GetStructFromMethod(method) 110 method.param_struct = self._GetStructFromMethod(method)
106 interface.version = max(interface.version, 111 interface.version = max(interface.version,
107 method.param_struct.versions[-1].version) 112 method.param_struct.versions[-1].version)
108 113
109 if method.response_parameters is not None: 114 if method.response_parameters is not None:
110 method.response_param_struct = self._GetResponseStructFromMethod(method) 115 method.response_param_struct = self._GetResponseStructFromMethod(method)
111 interface.version = max( 116 interface.version = max(
112 interface.version, 117 interface.version,
113 method.response_param_struct.versions[-1].version) 118 method.response_param_struct.versions[-1].version)
114 else: 119 else:
115 method.response_param_struct = None 120 method.response_param_struct = None
116 return interface 121 return interface
117 122
118 def _GetStructFromMethod(self, method): 123 def _GetStructFromMethod(self, method):
119 """Converts a method's parameters into the fields of a struct.""" 124 """Returns a method's parameters as a struct."""
120 params_class = "%s_%s_Params" % (method.interface.name, method.name) 125 return self._AddStructComputedData(False, method.param_struct)
121 struct = mojom.Struct(params_class, module=method.interface.module)
122 for param in method.parameters:
123 struct.AddField(param.name, param.kind, param.ordinal,
124 attributes=param.attributes)
125 return self._AddStructComputedData(False, struct)
126 126
127 def _GetResponseStructFromMethod(self, method): 127 def _GetResponseStructFromMethod(self, method):
128 """Converts a method's response_parameters into the fields of a struct.""" 128 """Returns a method's response_parameters as a struct."""
129 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) 129 return self._AddStructComputedData(False, method.response_param_struct)
130 struct = mojom.Struct(params_class, module=method.interface.module)
131 for param in method.response_parameters:
132 struct.AddField(param.name, param.kind, param.ordinal,
133 attributes=param.attributes)
134 return self._AddStructComputedData(False, struct)
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_go_generator.py ('k') | mojo/public/tools/bindings/pylib/mojom/generate/module.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698