OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/env python |
2 | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
4 # 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 |
5 # found in the LICENSE file. | 4 # found in the LICENSE file. |
6 | 5 |
7 """This script should be run manually on occasion to make sure all PPAPI types | 6 """This script should be run manually on occasion to make sure all PPAPI types |
8 have appropriate size checking. | 7 have appropriate size checking. |
9 | |
10 """ | 8 """ |
11 | 9 |
12 import optparse | 10 import optparse |
13 import os | 11 import os |
14 import subprocess | 12 import subprocess |
15 import sys | 13 import sys |
16 | 14 |
17 | 15 |
18 # The string that the PrintNamesAndSizes plugin uses to indicate a type is | 16 # The string that the PrintNamesAndSizes plugin uses to indicate a type is |
19 # expected to have architecture-dependent size. | 17 # expected to have architecture-dependent size. |
20 ARCH_DEPENDENT_STRING = "ArchDependentSize" | 18 ARCH_DEPENDENT_STRING = "ArchDependentSize" |
21 | 19 |
22 | 20 |
| 21 COPYRIGHT_STRING_C = ( |
| 22 """/* Copyright (c) %s The Chromium Authors. All rights reserved. |
| 23 * Use of this source code is governed by a BSD-style license that can be |
| 24 * found in the LICENSE file. |
| 25 * |
| 26 * This file has compile assertions for the sizes of types that are dependent |
| 27 * on the architecture for which they are compiled (i.e., 32-bit vs 64-bit). |
| 28 */ |
23 | 29 |
24 class SourceLocation: | 30 """) % datetime.date.today().year |
25 | 31 |
| 32 |
| 33 class SourceLocation(object): |
26 """A class representing the source location of a definiton.""" | 34 """A class representing the source location of a definiton.""" |
27 | 35 |
28 def __init__(self, filename="", start_line=-1, end_line=-1): | 36 def __init__(self, filename="", start_line=-1, end_line=-1): |
29 self.filename = os.path.normpath(filename) | 37 self.filename = os.path.normpath(filename) |
30 self.start_line = start_line | 38 self.start_line = start_line |
31 self.end_line = end_line | 39 self.end_line = end_line |
32 | 40 |
33 | 41 |
34 | 42 class TypeInfo(object): |
35 class TypeInfo: | |
36 | |
37 """A class representing information about a C++ type. It contains the | 43 """A class representing information about a C++ type. It contains the |
38 following fields: | 44 following fields: |
39 - kind: The Clang TypeClassName (Record, Enum, Typedef, Union, etc) | 45 - kind: The Clang TypeClassName (Record, Enum, Typedef, Union, etc) |
40 - name: The unmangled string name of the type. | 46 - name: The unmangled string name of the type. |
41 - size: The size in bytes of the type. | 47 - size: The size in bytes of the type. |
42 - arch_dependent: True if the type may have architecture dependent size | 48 - arch_dependent: True if the type may have architecture dependent size |
43 according to PrintNamesAndSizes. False otherwise. Types | 49 according to PrintNamesAndSizes. False otherwise. Types |
44 which are considered architecture-dependent from 32-bit | 50 which are considered architecture-dependent from 32-bit |
45 to 64-bit are pointers, longs, unsigned longs, and any | 51 to 64-bit are pointers, longs, unsigned longs, and any |
46 type that contains an architecture-dependent type. | 52 type that contains an architecture-dependent type. |
(...skipping 26 matching lines...) Expand all Loading... |
73 start_line, end_line] = info_string.split(',') | 79 start_line, end_line] = info_string.split(',') |
74 self.target = target | 80 self.target = target |
75 self.parsed_line = info_string | 81 self.parsed_line = info_string |
76 # Note that Clang counts line numbers from 1, but we want to count from 0. | 82 # Note that Clang counts line numbers from 1, but we want to count from 0. |
77 self.source_location = SourceLocation(source_file, | 83 self.source_location = SourceLocation(source_file, |
78 int(start_line)-1, | 84 int(start_line)-1, |
79 int(end_line)-1) | 85 int(end_line)-1) |
80 self.arch_dependent = (arch_dependent_string == ARCH_DEPENDENT_STRING) | 86 self.arch_dependent = (arch_dependent_string == ARCH_DEPENDENT_STRING) |
81 | 87 |
82 | 88 |
83 class FilePatch: | 89 class FilePatch(object): |
84 | |
85 """A class representing a set of line-by-line changes to a particular file. | 90 """A class representing a set of line-by-line changes to a particular file. |
86 None of the changes are applied until Apply is called. All line numbers are | 91 None of the changes are applied until Apply is called. All line numbers are |
87 counted from 0. | 92 counted from 0. |
88 """ | 93 """ |
89 | 94 |
90 def __init__(self, filename): | 95 def __init__(self, filename): |
91 self.filename = filename | 96 self.filename = filename |
92 self.linenums_to_delete = set() | 97 self.linenums_to_delete = set() |
93 # A dictionary from line number to an array of strings to be inserted at | 98 # A dictionary from line number to an array of strings to be inserted at |
94 # that line number. | 99 # that line number. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 line += typeinfo.size | 217 line += typeinfo.size |
213 line += ");\n" | 218 line += ");\n" |
214 return line | 219 return line |
215 | 220 |
216 | 221 |
217 def IsMacroDefinedName(typename): | 222 def IsMacroDefinedName(typename): |
218 """Return true iff the given typename came from a PPAPI compile assertion.""" | 223 """Return true iff the given typename came from a PPAPI compile assertion.""" |
219 return typename.find("PP_Dummy_Struct_For_") == 0 | 224 return typename.find("PP_Dummy_Struct_For_") == 0 |
220 | 225 |
221 | 226 |
222 COPYRIGHT_STRING_C = \ | |
223 """/* Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
224 * Use of this source code is governed by a BSD-style license that can be | |
225 * found in the LICENSE file. | |
226 * | |
227 * This file has compile assertions for the sizes of types that are dependent | |
228 * on the architecture for which they are compiled (i.e., 32-bit vs 64-bit). | |
229 */ | |
230 | |
231 """ | |
232 | |
233 | |
234 def WriteArchSpecificCode(types, root, filename): | 227 def WriteArchSpecificCode(types, root, filename): |
235 """Write a header file that contains a compile-time assertion for the size of | 228 """Write a header file that contains a compile-time assertion for the size of |
236 each of the given typeinfos, in to a file named filename rooted at root. | 229 each of the given typeinfos, in to a file named filename rooted at root. |
237 """ | 230 """ |
238 assertion_lines = [ToAssertionCode(typeinfo) for typeinfo in types] | 231 assertion_lines = [ToAssertionCode(typeinfo) for typeinfo in types] |
239 assertion_lines.sort() | 232 assertion_lines.sort() |
240 outfile = open(os.path.join(root, filename), "w") | 233 outfile = open(os.path.join(root, filename), "w") |
241 header_guard = "PPAPI_TESTS_" + filename.upper().replace(".", "_") + "_" | 234 header_guard = "PPAPI_TESTS_" + filename.upper().replace(".", "_") + "_" |
242 outfile.write(COPYRIGHT_STRING_C) | 235 outfile.write(COPYRIGHT_STRING_C) |
243 outfile.write('#ifndef ' + header_guard + '\n') | 236 outfile.write('#ifndef ' + header_guard + '\n') |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 "arch_dependent_sizes_32.h") | 415 "arch_dependent_sizes_32.h") |
423 WriteArchSpecificCode(types64.values(), | 416 WriteArchSpecificCode(types64.values(), |
424 c_source_root, | 417 c_source_root, |
425 "arch_dependent_sizes_64.h") | 418 "arch_dependent_sizes_64.h") |
426 | 419 |
427 return 0 | 420 return 0 |
428 | 421 |
429 | 422 |
430 if __name__ == '__main__': | 423 if __name__ == '__main__': |
431 sys.exit(main(sys.argv[1:])) | 424 sys.exit(main(sys.argv[1:])) |
432 | |
OLD | NEW |