Chromium Code Reviews| 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 typedefs = {} | |
| 148 cgen = CGen() | |
|
Mark Seaborn
2013/04/22 23:48:41
cgen seems to be unused.
| |
| 149 node_whitelist = ('PPB_Flash_BrowserOperations_GetSettingsCallback', | |
|
Mark Seaborn
2013/04/22 23:48:41
Why does this interface fail the check?
From c/pr
| |
| 150 'PP_Ext_Alarms_OnAlarm_Func_Dev_0_1') | |
|
noelallen1
2013/04/22 21:48:26
I think this is the current problem file for NaCl.
Mark Seaborn
2013/04/22 23:48:41
We'll have to change that interface if it's going
| |
| 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 not callnode: | |
| 157 typedefs[node.GetName()] = node.GetType(build_list[0]) | |
| 158 else: | |
| 159 for param in callnode.GetListOf('Param'): | |
| 160 t = param.GetType(build_list[0]) | |
| 161 if t.IsA('Struct'): | |
| 162 raise Exception('%s is a struct in callback %s. ' | |
|
noelallen1
2013/04/22 21:48:26
Isn't this only an issue of the param is [in]? Sh
Mark Seaborn
2013/04/22 23:48:41
Yes, I think so, on both counts.
| |
| 163 'See http://crbug.com/233439' % | |
| 164 (t.GetName(), node.GetName())) | |
| 165 elif t.IsA('Typedef'): | |
| 166 if t.GetName() in typedefs: | |
| 167 # We can't handle typedefs that are defined in another file. | |
| 168 if typedefs[t.GetName()].IsA('Struct'): | |
|
noelallen1
2013/04/22 21:48:26
I would expect GetType of the typedef to return th
| |
| 169 raise Exception('%s is a struct in callback %s. ' | |
| 170 'See http://crbug.com/233439' % | |
| 171 (t.GetName(), node.GetName())) | |
| 172 | |
| 142 class HGen(GeneratorByFile): | 173 class HGen(GeneratorByFile): |
| 143 def __init__(self): | 174 def __init__(self): |
| 144 Generator.__init__(self, 'C Header', 'cgen', 'Generate the C headers.') | 175 Generator.__init__(self, 'C Header', 'cgen', 'Generate the C headers.') |
| 145 | 176 |
| 146 def GenerateFile(self, filenode, releases, options): | 177 def GenerateFile(self, filenode, releases, options): |
| 178 CheckTypedefs(filenode, releases) | |
| 147 savename = GetHeaderFromNode(filenode, GetOption('dstroot')) | 179 savename = GetHeaderFromNode(filenode, GetOption('dstroot')) |
| 148 my_min, my_max = filenode.GetMinMax(releases) | 180 my_min, my_max = filenode.GetMinMax(releases) |
| 149 if my_min > releases[-1] or my_max < releases[0]: | 181 if my_min > releases[-1] or my_max < releases[0]: |
| 150 if os.path.isfile(savename): | 182 if os.path.isfile(savename): |
| 151 print "Removing stale %s for this range." % filenode.GetName() | 183 print "Removing stale %s for this range." % filenode.GetName() |
| 152 os.remove(os.path.realpath(savename)) | 184 os.remove(os.path.realpath(savename)) |
| 153 return False | 185 return False |
| 154 | 186 |
| 155 out = IDLOutFile(savename) | 187 out = IDLOutFile(savename) |
| 156 self.GenerateHead(out, filenode, releases, options) | 188 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." | 322 print "Golden file for M13-M15 failed." |
| 291 failed =1 | 323 failed =1 |
| 292 else: | 324 else: |
| 293 print "Golden file for M13-M15 passed." | 325 print "Golden file for M13-M15 passed." |
| 294 | 326 |
| 295 return failed | 327 return failed |
| 296 | 328 |
| 297 if __name__ == '__main__': | 329 if __name__ == '__main__': |
| 298 sys.exit(main(sys.argv[1:])) | 330 sys.exit(main(sys.argv[1:])) |
| 299 | 331 |
| OLD | NEW |