| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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. | |
| 5 | |
| 6 import js2c | |
| 7 import os | |
| 8 import re | |
| 9 import sys | |
| 10 | |
| 11 FILENAME = "src/runtime/runtime.h" | |
| 12 LISTHEAD = re.compile(r"#define\s+(FOR_EACH_\w+)\((\w+)\)") | |
| 13 LISTBODY = re.compile(r".*\\$") | |
| 14 | |
| 15 | |
| 16 class Function(object): | |
| 17 def __init__(self, match): | |
| 18 self.name = match.group(1).strip() | |
| 19 | |
| 20 def ListMacroRe(list): | |
| 21 macro = LISTHEAD.match(list[0]).group(2) | |
| 22 re_string = "\s*%s\((\w+)" % macro | |
| 23 return re.compile(re_string) | |
| 24 | |
| 25 | |
| 26 def FindLists(filename): | |
| 27 lists = [] | |
| 28 current_list = [] | |
| 29 mode = "SEARCHING" | |
| 30 with open(filename, "r") as f: | |
| 31 for line in f: | |
| 32 if mode == "SEARCHING": | |
| 33 match = LISTHEAD.match(line) | |
| 34 if match: | |
| 35 mode = "APPENDING" | |
| 36 current_list.append(line) | |
| 37 else: | |
| 38 current_list.append(line) | |
| 39 match = LISTBODY.match(line) | |
| 40 if not match: | |
| 41 mode = "SEARCHING" | |
| 42 lists.append(current_list) | |
| 43 current_list = [] | |
| 44 return lists | |
| 45 | |
| 46 | |
| 47 # Detects runtime functions by parsing FILENAME. | |
| 48 def FindRuntimeFunctions(): | |
| 49 functions = [] | |
| 50 lists = FindLists(FILENAME) | |
| 51 for list in lists: | |
| 52 function_re = ListMacroRe(list) | |
| 53 for line in list: | |
| 54 match = function_re.match(line) | |
| 55 if match: | |
| 56 functions.append(Function(match)) | |
| 57 return functions | |
| 58 | |
| 59 | |
| 60 class Builtin(object): | |
| 61 def __init__(self, match): | |
| 62 self.name = match.group(1) | |
| 63 | |
| 64 | |
| 65 def FindJSNatives(): | |
| 66 PATH = "src" | |
| 67 fileslist = [] | |
| 68 for (root, dirs, files) in os.walk(PATH): | |
| 69 for f in files: | |
| 70 if f.endswith(".js"): | |
| 71 fileslist.append(os.path.join(root, f)) | |
| 72 natives = [] | |
| 73 regexp = re.compile("^function (\w+)\s*\((.*?)\) {") | |
| 74 matches = 0 | |
| 75 for filename in fileslist: | |
| 76 with open(filename, "r") as f: | |
| 77 file_contents = f.read() | |
| 78 file_contents = js2c.ExpandInlineMacros(file_contents) | |
| 79 lines = file_contents.split("\n") | |
| 80 partial_line = "" | |
| 81 for line in lines: | |
| 82 if line.startswith("function") and not '{' in line: | |
| 83 partial_line += line.rstrip() | |
| 84 continue | |
| 85 if partial_line: | |
| 86 partial_line += " " + line.strip() | |
| 87 if '{' in line: | |
| 88 line = partial_line | |
| 89 partial_line = "" | |
| 90 else: | |
| 91 continue | |
| 92 match = regexp.match(line) | |
| 93 if match: | |
| 94 natives.append(Builtin(match)) | |
| 95 return natives | |
| 96 | |
| 97 | |
| 98 def Main(): | |
| 99 functions = FindRuntimeFunctions() | |
| 100 natives = FindJSNatives() | |
| 101 errors = 0 | |
| 102 runtime_map = {} | |
| 103 for f in functions: | |
| 104 runtime_map[f.name] = 1 | |
| 105 for b in natives: | |
| 106 if b.name in runtime_map: | |
| 107 print("JS_Native/Runtime_Function name clash: %s" % b.name) | |
| 108 errors += 1 | |
| 109 | |
| 110 if errors > 0: | |
| 111 return 1 | |
| 112 print("Runtime/Natives name clashes: checked %d/%d functions, all good." % | |
| 113 (len(functions), len(natives))) | |
| 114 return 0 | |
| 115 | |
| 116 | |
| 117 if __name__ == "__main__": | |
| 118 sys.exit(Main()) | |
| OLD | NEW |