| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2012 the V8 project authors. All rights reserved. | 3 # Copyright 2012 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 macro = TextMacro(args, body) | 211 macro = TextMacro(args, body) |
| 212 | 212 |
| 213 # advance position to where the macro defintion was | 213 # advance position to where the macro defintion was |
| 214 pos = macro_match.start() | 214 pos = macro_match.start() |
| 215 | 215 |
| 216 def non_expander(s): | 216 def non_expander(s): |
| 217 return s | 217 return s |
| 218 lines = ExpandMacroDefinition(lines, pos, name_pattern, macro, non_expander) | 218 lines = ExpandMacroDefinition(lines, pos, name_pattern, macro, non_expander) |
| 219 | 219 |
| 220 | 220 |
| 221 INLINE_CONSTANT_PATTERN = re.compile(r'const\s+([a-zA-Z0-9_]+)\s*=\s*([^;\n]+)[;
\n]') | |
| 222 | |
| 223 def ExpandInlineConstants(lines): | |
| 224 pos = 0 | |
| 225 while True: | |
| 226 const_match = INLINE_CONSTANT_PATTERN.search(lines, pos) | |
| 227 if const_match is None: | |
| 228 # no more constants | |
| 229 return lines | |
| 230 name = const_match.group(1) | |
| 231 replacement = const_match.group(2) | |
| 232 name_pattern = re.compile("\\b%s\\b" % name) | |
| 233 | |
| 234 # remove constant definition and replace | |
| 235 lines = (lines[:const_match.start()] + | |
| 236 re.sub(name_pattern, replacement, lines[const_match.end():])) | |
| 237 | |
| 238 # advance position to where the constant defintion was | |
| 239 pos = const_match.start() | |
| 240 | |
| 241 | |
| 242 HEADER_TEMPLATE = """\ | 221 HEADER_TEMPLATE = """\ |
| 243 // Copyright 2011 Google Inc. All Rights Reserved. | 222 // Copyright 2011 Google Inc. All Rights Reserved. |
| 244 | 223 |
| 245 // This file was generated from .js source files by GYP. If you | 224 // This file was generated from .js source files by GYP. If you |
| 246 // want to make changes to this file you should either change the | 225 // want to make changes to this file you should either change the |
| 247 // javascript source files or the GYP script. | 226 // javascript source files or the GYP script. |
| 248 | 227 |
| 249 #include "src/v8.h" | 228 #include "src/v8.h" |
| 250 #include "src/natives.h" | 229 #include "src/natives.h" |
| 251 #include "src/utils.h" | 230 #include "src/utils.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 filter_chain = [ReadFile] | 326 filter_chain = [ReadFile] |
| 348 | 327 |
| 349 if macro_filename: | 328 if macro_filename: |
| 350 (consts, macros) = ReadMacros(ReadFile(macro_filename)) | 329 (consts, macros) = ReadMacros(ReadFile(macro_filename)) |
| 351 filter_chain.append(lambda l: ExpandConstants(l, consts)) | 330 filter_chain.append(lambda l: ExpandConstants(l, consts)) |
| 352 filter_chain.append(lambda l: ExpandMacros(l, macros)) | 331 filter_chain.append(lambda l: ExpandMacros(l, macros)) |
| 353 | 332 |
| 354 filter_chain.extend([ | 333 filter_chain.extend([ |
| 355 RemoveCommentsAndTrailingWhitespace, | 334 RemoveCommentsAndTrailingWhitespace, |
| 356 ExpandInlineMacros, | 335 ExpandInlineMacros, |
| 357 ExpandInlineConstants, | |
| 358 Validate, | 336 Validate, |
| 359 jsmin.JavaScriptMinifier().JSMinify | 337 jsmin.JavaScriptMinifier().JSMinify |
| 360 ]) | 338 ]) |
| 361 | 339 |
| 362 def chain(f1, f2): | 340 def chain(f1, f2): |
| 363 return lambda x: f2(f1(x)) | 341 return lambda x: f2(f1(x)) |
| 364 | 342 |
| 365 return reduce(chain, filter_chain) | 343 return reduce(chain, filter_chain) |
| 366 | 344 |
| 367 | 345 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 type: type parameter for NativesCollection template. | 547 type: type parameter for NativesCollection template. |
| 570 compression: type of compression used. [off|bz2] | 548 compression: type of compression used. [off|bz2] |
| 571 sources.js: JS internal sources or macros.py.""") | 549 sources.js: JS internal sources or macros.py.""") |
| 572 (options, args) = parser.parse_args() | 550 (options, args) = parser.parse_args() |
| 573 | 551 |
| 574 JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) | 552 JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) |
| 575 | 553 |
| 576 | 554 |
| 577 if __name__ == "__main__": | 555 if __name__ == "__main__": |
| 578 main() | 556 main() |
| OLD | NEW |