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

Unified Diff: tools/check-name-clashes.py

Issue 597943002: Use runtime.h to look for runtime function names. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/check-name-clashes.py
diff --git a/tools/check-name-clashes.py b/tools/check-name-clashes.py
index e4489303270dbae94d66d075e9dc2dc9f5d759e9..01727540902ac54a9b5da4eab9dafb059caa223b 100755
--- a/tools/check-name-clashes.py
+++ b/tools/check-name-clashes.py
@@ -8,135 +8,53 @@ import os
import re
import sys
-FILENAME = "src/runtime.cc"
-FUNCTION = re.compile("^RUNTIME_FUNCTION\(Runtime_(\w+)")
-FUNCTIONEND = "}\n"
-MACRO = re.compile(r"^#define ([^ ]+)\(([^)]*)\) *([^\\]*)\\?\n$")
-FIRST_WORD = re.compile("^\s*(.*?)[\s({\[]")
-
-# Expand these macros, they define further runtime functions.
-EXPAND_MACROS = [
- "BUFFER_VIEW_GETTER",
- "DATA_VIEW_GETTER",
- "DATA_VIEW_SETTER",
- "ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION",
- "FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION",
- "RUNTIME_UNARY_MATH",
- "TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION",
-]
+FILENAME = "src/runtime.h"
+LISTHEAD = re.compile(r"#define\s+(\w+LIST\w*)\((\w+)\)")
+LISTBODY = re.compile(r".*\\$")
+BLACKLIST = ['INLINE_FUNCTION_LIST']
class Function(object):
def __init__(self, match):
- self.name = match.group(1)
+ self.name = match.group(1).strip()
+def ListMacroRe(list):
+ macro = LISTHEAD.match(list[0]).group(2)
+ re_string = "\s*%s\((\w+)" % macro
+ return re.compile(re_string)
-class Macro(object):
- def __init__(self, match):
- self.name = match.group(1)
- self.args = [s.strip() for s in match.group(2).split(",")]
- self.lines = []
- self.indentation = 0
- self.AddLine(match.group(3))
-
- def AddLine(self, line):
- if not line: return
- if not self.lines:
- # This is the first line, detect indentation.
- self.indentation = len(line) - len(line.lstrip())
- line = line.rstrip("\\\n ")
- if not line: return
- assert len(line[:self.indentation].strip()) == 0, \
- ("expected whitespace: '%s', full line: '%s'" %
- (line[:self.indentation], line))
- line = line[self.indentation:]
- if not line: return
- self.lines.append(line + "\n")
-
- def Finalize(self):
- for arg in self.args:
- pattern = re.compile(r"(##|\b)%s(##|\b)" % arg)
- for i in range(len(self.lines)):
- self.lines[i] = re.sub(pattern, "%%(%s)s" % arg, self.lines[i])
-
- def FillIn(self, arg_values):
- filler = {}
- assert len(arg_values) == len(self.args)
- for i in range(len(self.args)):
- filler[self.args[i]] = arg_values[i]
- result = []
- for line in self.lines:
- result.append(line % filler)
- return result
-
-
-def ReadFileAndExpandMacros(filename):
- found_macros = {}
- expanded_lines = []
+
+def FindLists(filename):
+ lists = []
+ current_list = []
+ mode = "SEARCHING"
with open(filename, "r") as f:
- found_macro = None
for line in f:
- if found_macro is not None:
- found_macro.AddLine(line)
- if not line.endswith("\\\n"):
- found_macro.Finalize()
- found_macro = None
- continue
-
- match = MACRO.match(line)
- if match:
- found_macro = Macro(match)
- if found_macro.name in EXPAND_MACROS:
- found_macros[found_macro.name] = found_macro
- else:
- found_macro = None
- continue
-
- match = FIRST_WORD.match(line)
- if match:
- first_word = match.group(1)
- if first_word in found_macros:
- MACRO_CALL = re.compile("%s\(([^)]*)\)" % first_word)
- match = MACRO_CALL.match(line)
- assert match
- args = [s.strip() for s in match.group(1).split(",")]
- expanded_lines += found_macros[first_word].FillIn(args)
- continue
-
- expanded_lines.append(line)
- return expanded_lines
+ if mode == "SEARCHING":
+ match = LISTHEAD.match(line)
+ if match and match.group(1) not in BLACKLIST:
+ mode = "APPENDING"
+ current_list.append(line)
+ else:
+ current_list.append(line)
+ match = LISTBODY.match(line)
+ if not match:
+ mode = "SEARCHING"
+ lists.append(current_list)
+ current_list = []
+ return lists
# Detects runtime functions by parsing FILENAME.
def FindRuntimeFunctions():
functions = []
- expanded_lines = ReadFileAndExpandMacros(FILENAME)
- function = None
- partial_line = ""
- for line in expanded_lines:
- # Multi-line definition support, ignoring macros.
- if line.startswith("RUNTIME_FUNCTION") and not line.endswith("{\n"):
- if line.endswith("\\\n"): continue
- partial_line = line.rstrip()
- continue
- if partial_line:
- partial_line += " " + line.strip()
- if partial_line.endswith("{"):
- line = partial_line
- partial_line = ""
- else:
- continue
-
- match = FUNCTION.match(line)
- if match:
- function = Function(match)
- continue
- if function is None: continue
-
- if line == FUNCTIONEND:
- if function is not None:
- functions.append(function)
- function = None
+ lists = FindLists(FILENAME)
+ for list in lists:
+ function_re = ListMacroRe(list)
+ for line in list:
+ match = function_re.match(line)
+ if match:
+ functions.append(Function(match))
return functions
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698