Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: tools/js2c.py

Issue 1110963003: Use "define" instead of "const" for natives macros (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/third_party/fdlibm/fdlibm.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 class PythonMacro: 151 class PythonMacro:
152 def __init__(self, args, fun): 152 def __init__(self, args, fun):
153 self.args = args 153 self.args = args
154 self.fun = fun 154 self.fun = fun
155 def expand(self, mapping): 155 def expand(self, mapping):
156 args = [] 156 args = []
157 for arg in self.args: 157 for arg in self.args:
158 args.append(mapping[arg]) 158 args.append(mapping[arg])
159 return str(self.fun(*args)) 159 return str(self.fun(*args))
160 160
161 CONST_PATTERN = re.compile(r'^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$') 161 CONST_PATTERN = re.compile(r'^define\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$')
162 MACRO_PATTERN = re.compile(r'^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]* );$') 162 MACRO_PATTERN = re.compile(r'^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]* );$')
163 PYTHON_MACRO_PATTERN = re.compile(r'^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]* )\)\s*=\s*([^;]*);$') 163 PYTHON_MACRO_PATTERN = re.compile(r'^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]* )\)\s*=\s*([^;]*);$')
164 164
165 165
166 def ReadMacros(lines): 166 def ReadMacros(lines):
167 constants = [] 167 constants = []
168 macros = [] 168 macros = []
169 for line in lines.split('\n'): 169 for line in lines.split('\n'):
170 hash = line.find('#') 170 hash = line.find('#')
171 if hash != -1: line = line[:hash] 171 if hash != -1: line = line[:hash]
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 macro = TextMacro(args, body) 233 macro = TextMacro(args, body)
234 234
235 # advance position to where the macro defintion was 235 # advance position to where the macro defintion was
236 pos = macro_match.start() 236 pos = macro_match.start()
237 237
238 def non_expander(s): 238 def non_expander(s):
239 return s 239 return s
240 lines = ExpandMacroDefinition(lines, pos, name_pattern, macro, non_expander) 240 lines = ExpandMacroDefinition(lines, pos, name_pattern, macro, non_expander)
241 241
242 242
243 INLINE_CONSTANT_PATTERN = re.compile(r'const\s+([a-zA-Z0-9_]+)\s*=\s*([^;\n]+)[; \n]') 243 INLINE_CONSTANT_PATTERN = re.compile(r'define\s+([a-zA-Z0-9_]+)\s*=\s*([^;\n]+)[ ;\n]')
244 244
245 def ExpandInlineConstants(lines): 245 def ExpandInlineConstants(lines):
246 pos = 0 246 pos = 0
247 while True: 247 while True:
248 const_match = INLINE_CONSTANT_PATTERN.search(lines, pos) 248 const_match = INLINE_CONSTANT_PATTERN.search(lines, pos)
249 if const_match is None: 249 if const_match is None:
250 # no more constants 250 # no more constants
251 return lines 251 return lines
252 name = const_match.group(1) 252 name = const_match.group(1)
253 replacement = const_match.group(2) 253 replacement = const_match.group(2)
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 out.cc: C code to be generated. 561 out.cc: C code to be generated.
562 type: type parameter for NativesCollection template. 562 type: type parameter for NativesCollection template.
563 sources.js: JS internal sources or macros.py.""") 563 sources.js: JS internal sources or macros.py.""")
564 (options, args) = parser.parse_args() 564 (options, args) = parser.parse_args()
565 565
566 JS2C(args[2:], args[0], args[1], options.raw, options.startup_blob) 566 JS2C(args[2:], args[0], args[1], options.raw, options.startup_blob)
567 567
568 568
569 if __name__ == "__main__": 569 if __name__ == "__main__":
570 main() 570 main()
OLDNEW
« no previous file with comments | « src/third_party/fdlibm/fdlibm.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698