OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2006-2008 the V8 project authors. All rights reserved. | 3 # Copyright 2006-2008 the V8 project authors. All rights reserved. |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 result.append("0") | 43 result.append("0") |
44 return ", ".join(result) | 44 return ", ".join(result) |
45 | 45 |
46 | 46 |
47 def CompressScript(lines): | 47 def CompressScript(lines): |
48 # Remove stuff from the source that we don't want to appear when | 48 # Remove stuff from the source that we don't want to appear when |
49 # people print the source code using Function.prototype.toString(). | 49 # people print the source code using Function.prototype.toString(). |
50 # Note that we could easily compress the scripts mode but don't | 50 # Note that we could easily compress the scripts mode but don't |
51 # since we want it to remain readable. | 51 # since we want it to remain readable. |
52 lines = re.sub('//.*\n', '\n', lines) # end-of-line comments | 52 lines = re.sub('//.*\n', '\n', lines) # end-of-line comments |
| 53 lines = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', lines) # comments. |
53 lines = re.sub('\s+\n+', '\n', lines) # trailing whitespace | 54 lines = re.sub('\s+\n+', '\n', lines) # trailing whitespace |
54 return lines | 55 return lines |
55 | 56 |
56 | 57 |
57 def ReadFile(filename): | 58 def ReadFile(filename): |
58 file = open(filename, "rt") | 59 file = open(filename, "rt") |
59 try: | 60 try: |
60 lines = file.read() | 61 lines = file.read() |
61 finally: | 62 finally: |
62 file.close() | 63 file.close() |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 349 |
349 def main(): | 350 def main(): |
350 natives = sys.argv[1] | 351 natives = sys.argv[1] |
351 natives_empty = sys.argv[2] | 352 natives_empty = sys.argv[2] |
352 type = sys.argv[3] | 353 type = sys.argv[3] |
353 source_files = sys.argv[4:] | 354 source_files = sys.argv[4:] |
354 JS2C(source_files, [natives, natives_empty], { 'TYPE': type }) | 355 JS2C(source_files, [natives, natives_empty], { 'TYPE': type }) |
355 | 356 |
356 if __name__ == "__main__": | 357 if __name__ == "__main__": |
357 main() | 358 main() |
OLD | NEW |