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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 # we don't allow self-dependecies or recursion. | 121 # we don't allow self-dependecies or recursion. |
122 for name_pattern, macro in reversed(macros): | 122 for name_pattern, macro in reversed(macros): |
123 pattern_match = name_pattern.search(lines, 0) | 123 pattern_match = name_pattern.search(lines, 0) |
124 while pattern_match is not None: | 124 while pattern_match is not None: |
125 # Scan over the arguments | 125 # Scan over the arguments |
126 height = 1 | 126 height = 1 |
127 start = pattern_match.start() | 127 start = pattern_match.start() |
128 end = pattern_match.end() | 128 end = pattern_match.end() |
129 assert lines[end - 1] == '(' | 129 assert lines[end - 1] == '(' |
130 last_match = end | 130 last_match = end |
131 arg_index = 0 | 131 arg_index = [0] |
132 mapping = { } | 132 mapping = { } |
133 def add_arg(str): | 133 def add_arg(str): |
134 # Remember to expand recursively in the arguments | 134 # Remember to expand recursively in the arguments |
135 replacement = ExpandMacros(str.strip(), macros) | 135 replacement = ExpandMacros(str.strip(), macros) |
136 mapping[macro.args[arg_index]] = replacement | 136 mapping[macro.args[arg_index[0]]] = replacement |
| 137 arg_index[0] += 1 |
137 while end < len(lines) and height > 0: | 138 while end < len(lines) and height > 0: |
138 # We don't count commas at higher nesting levels. | 139 # We don't count commas at higher nesting levels. |
139 if lines[end] == ',' and height == 1: | 140 if lines[end] == ',' and height == 1: |
140 add_arg(lines[last_match:end]) | 141 add_arg(lines[last_match:end]) |
141 last_match = end + 1 | 142 last_match = end + 1 |
142 elif lines[end] in ['(', '{', '[']: | 143 elif lines[end] in ['(', '{', '[']: |
143 height = height + 1 | 144 height = height + 1 |
144 elif lines[end] in [')', '}', ']']: | 145 elif lines[end] in [')', '}', ']']: |
145 height = height - 1 | 146 height = height - 1 |
146 end = end + 1 | 147 end = end + 1 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 387 |
387 def main(): | 388 def main(): |
388 natives = sys.argv[1] | 389 natives = sys.argv[1] |
389 type = sys.argv[2] | 390 type = sys.argv[2] |
390 compression = sys.argv[3] | 391 compression = sys.argv[3] |
391 source_files = sys.argv[4:] | 392 source_files = sys.argv[4:] |
392 JS2C(source_files, [natives], { 'TYPE': type, 'COMPRESSION': compression }) | 393 JS2C(source_files, [natives], { 'TYPE': type, 'COMPRESSION': compression }) |
393 | 394 |
394 if __name__ == "__main__": | 395 if __name__ == "__main__": |
395 main() | 396 main() |
OLD | NEW |