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 |
221 HEADER_TEMPLATE = """\ | 242 HEADER_TEMPLATE = """\ |
222 // Copyright 2011 Google Inc. All Rights Reserved. | 243 // Copyright 2011 Google Inc. All Rights Reserved. |
223 | 244 |
224 // This file was generated from .js source files by GYP. If you | 245 // This file was generated from .js source files by GYP. If you |
225 // want to make changes to this file you should either change the | 246 // want to make changes to this file you should either change the |
226 // javascript source files or the GYP script. | 247 // javascript source files or the GYP script. |
227 | 248 |
228 #include "src/v8.h" | 249 #include "src/v8.h" |
229 #include "src/natives.h" | 250 #include "src/natives.h" |
230 #include "src/utils.h" | 251 #include "src/utils.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 filter_chain = [ReadFile] | 347 filter_chain = [ReadFile] |
327 | 348 |
328 if macro_filename: | 349 if macro_filename: |
329 (consts, macros) = ReadMacros(ReadFile(macro_filename)) | 350 (consts, macros) = ReadMacros(ReadFile(macro_filename)) |
330 filter_chain.append(lambda l: ExpandConstants(l, consts)) | 351 filter_chain.append(lambda l: ExpandConstants(l, consts)) |
331 filter_chain.append(lambda l: ExpandMacros(l, macros)) | 352 filter_chain.append(lambda l: ExpandMacros(l, macros)) |
332 | 353 |
333 filter_chain.extend([ | 354 filter_chain.extend([ |
334 RemoveCommentsAndTrailingWhitespace, | 355 RemoveCommentsAndTrailingWhitespace, |
335 ExpandInlineMacros, | 356 ExpandInlineMacros, |
| 357 ExpandInlineConstants, |
336 Validate, | 358 Validate, |
337 jsmin.JavaScriptMinifier().JSMinify | 359 jsmin.JavaScriptMinifier().JSMinify |
338 ]) | 360 ]) |
339 | 361 |
340 def chain(f1, f2): | 362 def chain(f1, f2): |
341 return lambda x: f2(f1(x)) | 363 return lambda x: f2(f1(x)) |
342 | 364 |
343 return reduce(chain, filter_chain) | 365 return reduce(chain, filter_chain) |
344 | 366 |
345 | 367 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 type: type parameter for NativesCollection template. | 569 type: type parameter for NativesCollection template. |
548 compression: type of compression used. [off|bz2] | 570 compression: type of compression used. [off|bz2] |
549 sources.js: JS internal sources or macros.py.""") | 571 sources.js: JS internal sources or macros.py.""") |
550 (options, args) = parser.parse_args() | 572 (options, args) = parser.parse_args() |
551 | 573 |
552 JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) | 574 JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) |
553 | 575 |
554 | 576 |
555 if __name__ == "__main__": | 577 if __name__ == "__main__": |
556 main() | 578 main() |
OLD | NEW |