2 # Copyright 2014 the V8 project authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
11 FILENAME = "src/runtime/runtime.h"
12 LISTHEAD = re.compile(r"#define\s+(\w+LIST\w*)\((\w+)\)")
13 LISTBODY = re.compile(r".*\\$")
14 BLACKLIST = ['INLINE_FUNCTION_LIST']
17 class Function(object):
18 def __init__(self, match):
19 self.name = match.group(1).strip()
21 def ListMacroRe(list):
22 macro = LISTHEAD.match(list[0]).group(2)
23 re_string = "\s*%s\((\w+)" % macro
24 return re.compile(re_string)
27 def FindLists(filename):
31 with open(filename, "r") as f:
33 if mode == "SEARCHING":
34 match = LISTHEAD.match(line)
35 if match and match.group(1) not in BLACKLIST:
37 current_list.append(line)
39 current_list.append(line)
40 match = LISTBODY.match(line)
43 lists.append(current_list)
48 # Detects runtime functions by parsing FILENAME.
49 def FindRuntimeFunctions():
51 lists = FindLists(FILENAME)
53 function_re = ListMacroRe(list)
55 match = function_re.match(line)
57 functions.append(Function(match))
61 class Builtin(object):
62 def __init__(self, match):
63 self.name = match.group(1)
69 for (root, dirs, files) in os.walk(PATH):
72 fileslist.append(os.path.join(root, f))
74 regexp = re.compile("^function (\w+)\s*\((.*?)\) {")
76 for filename in fileslist:
77 with open(filename, "r") as f:
78 file_contents = f.read()
79 file_contents = js2c.ExpandInlineMacros(file_contents)
80 lines = file_contents.split("\n")
83 if line.startswith("function") and not '{' in line:
84 partial_line += line.rstrip()
87 partial_line += " " + line.strip()
93 match = regexp.match(line)
95 natives.append(Builtin(match))
100 functions = FindRuntimeFunctions()
101 natives = FindJSNatives()
105 runtime_map[f.name] = 1
107 if b.name in runtime_map:
108 print("JS_Native/Runtime_Function name clash: %s" % b.name)
113 print("Runtime/Natives name clashes: checked %d/%d functions, all good." %
114 (len(functions), len(natives)))
118 if __name__ == "__main__":