OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ Generator for C style prototypes and definitions """ | 6 """ Generator for C style prototypes and definitions """ |
7 | 7 |
8 import glob | 8 import glob |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n' | 132 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n' |
133 else: | 133 else: |
134 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n' | 134 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n' |
135 item += form % (name, asize[0]) | 135 item += form % (name, asize[0]) |
136 | 136 |
137 if item: out.Write(item) | 137 if item: out.Write(item) |
138 if last_group: | 138 if last_group: |
139 out.Write(CommentLines(['*',' @}', '']) + '\n') | 139 out.Write(CommentLines(['*',' @}', '']) + '\n') |
140 | 140 |
141 | 141 |
| 142 def CheckTypedefs(filenode, releases): |
| 143 """Checks that typedefs don't specify callbacks that take some structs. |
| 144 |
| 145 See http://crbug.com/233439 for details. |
| 146 """ |
| 147 cgen = CGen() |
| 148 # TODO(teravest): Fix the following callback to pass PP_Var by pointer |
| 149 # instead of by value. |
| 150 node_whitelist = ['PP_Ext_Alarms_OnAlarm_Func_Dev_0_1'] |
| 151 for node in filenode.GetListOf('Typedef'): |
| 152 if node.GetName() in node_whitelist: |
| 153 continue |
| 154 build_list = node.GetUniqueReleases(releases) |
| 155 callnode = node.GetOneOf('Callspec') |
| 156 if callnode: |
| 157 for param in callnode.GetListOf('Param'): |
| 158 if param.GetListOf('Array'): |
| 159 continue |
| 160 if cgen.GetParamMode(param) != 'in': |
| 161 continue |
| 162 t = param.GetType(build_list[0]) |
| 163 while t.IsA('Typedef'): |
| 164 t = t.GetType(build_list[0]) |
| 165 if t.IsA('Struct'): |
| 166 raise Exception('%s is a struct in callback %s. ' |
| 167 'See http://crbug.com/233439' % |
| 168 (t.GetName(), node.GetName())) |
| 169 |
142 class HGen(GeneratorByFile): | 170 class HGen(GeneratorByFile): |
143 def __init__(self): | 171 def __init__(self): |
144 Generator.__init__(self, 'C Header', 'cgen', 'Generate the C headers.') | 172 Generator.__init__(self, 'C Header', 'cgen', 'Generate the C headers.') |
145 | 173 |
146 def GenerateFile(self, filenode, releases, options): | 174 def GenerateFile(self, filenode, releases, options): |
| 175 CheckTypedefs(filenode, releases) |
147 savename = GetHeaderFromNode(filenode, GetOption('dstroot')) | 176 savename = GetHeaderFromNode(filenode, GetOption('dstroot')) |
148 my_min, my_max = filenode.GetMinMax(releases) | 177 my_min, my_max = filenode.GetMinMax(releases) |
149 if my_min > releases[-1] or my_max < releases[0]: | 178 if my_min > releases[-1] or my_max < releases[0]: |
150 if os.path.isfile(savename): | 179 if os.path.isfile(savename): |
151 print "Removing stale %s for this range." % filenode.GetName() | 180 print "Removing stale %s for this range." % filenode.GetName() |
152 os.remove(os.path.realpath(savename)) | 181 os.remove(os.path.realpath(savename)) |
153 return False | 182 return False |
154 | 183 |
155 out = IDLOutFile(savename) | 184 out = IDLOutFile(savename) |
156 self.GenerateHead(out, filenode, releases, options) | 185 self.GenerateHead(out, filenode, releases, options) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 print "Golden file for M13-M15 failed." | 319 print "Golden file for M13-M15 failed." |
291 failed =1 | 320 failed =1 |
292 else: | 321 else: |
293 print "Golden file for M13-M15 passed." | 322 print "Golden file for M13-M15 passed." |
294 | 323 |
295 return failed | 324 return failed |
296 | 325 |
297 if __name__ == '__main__': | 326 if __name__ == '__main__': |
298 sys.exit(main(sys.argv[1:])) | 327 sys.exit(main(sys.argv[1:])) |
299 | 328 |
OLD | NEW |