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

Unified Diff: tools/js2c.py

Issue 1087633005: Start migrating error message templates to the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows build Created 5 years, 8 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 | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/js2c.py
diff --git a/tools/js2c.py b/tools/js2c.py
index 327e7d916c3141e1044e0c81c279e6c33aa9f307..c72afbc5d66a9b8d34e81abf75b2ec2b3b203cb4 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -69,6 +69,7 @@ def ReadFile(filename):
EVAL_PATTERN = re.compile(r'\beval\s*\(')
WITH_PATTERN = re.compile(r'\bwith\s*\(')
+INVALID_ERROR_MESSAGE_PATTERN = re.compile(r'Make\w*Error\((k\w+),')
def Validate(lines):
# Because of simplified context setup, eval and with is not
@@ -77,7 +78,9 @@ def Validate(lines):
raise Error("Eval disallowed in natives.")
if WITH_PATTERN.search(lines):
raise Error("With statements disallowed in natives.")
-
+ invalid_error = INVALID_ERROR_MESSAGE_PATTERN.search(lines)
+ if invalid_error:
+ raise Error("Unknown error message template '%s'" % invalid_error.group(1))
# Pass lines through unchanged.
return lines
@@ -188,6 +191,21 @@ def ReadMacros(lines):
raise Error("Illegal line: " + line)
return (constants, macros)
+
+TEMPLATE_PATTERN = re.compile(r'^\s+T\(([a-zA-Z]+), ".+"\)')
+
+def ReadMessageTemplates(lines):
+ templates = []
+ index = 0
+ for line in lines.split('\n'):
+ template_match = TEMPLATE_PATTERN.match(line)
+ if template_match:
+ name = "k%s" % template_match.group(1)
+ value = index
+ index = index + 1
+ templates.append((re.compile("\\b%s\\b" % name), value))
+ return templates
+
INLINE_MACRO_PATTERN = re.compile(r'macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*\n')
INLINE_MACRO_END_PATTERN = re.compile(r'endmacro\s*\n')
@@ -311,7 +329,7 @@ GET_SCRIPT_NAME_CASE = """\
"""
-def BuildFilterChain(macro_filename):
+def BuildFilterChain(macro_filename, message_template_file):
"""Build the chain of filter functions to be applied to the sources.
Args:
@@ -327,6 +345,10 @@ def BuildFilterChain(macro_filename):
filter_chain.append(lambda l: ExpandConstants(l, consts))
filter_chain.append(lambda l: ExpandMacros(l, macros))
+ if message_template_file:
+ message_templates = ReadMessageTemplates(ReadFile(message_template_file))
+ filter_chain.append(lambda l: ExpandConstants(l, message_templates))
+
filter_chain.extend([
RemoveCommentsAndTrailingWhitespace,
ExpandInlineMacros,
@@ -354,6 +376,9 @@ def IsDebuggerFile(filename):
def IsMacroFile(filename):
return filename.endswith("macros.py")
+def IsMessageTemplateFile(filename):
+ return filename.endswith("messages.h")
+
def PrepareSources(source_files):
"""Read, prepare and assemble the list of source files.
@@ -372,7 +397,14 @@ def PrepareSources(source_files):
source_files.remove(macro_files[0])
macro_file = macro_files[0]
- filters = BuildFilterChain(macro_file)
+ message_template_file = None
+ message_template_files = filter(IsMessageTemplateFile, source_files)
+ assert len(message_template_files) in [0, 1]
+ if message_template_files:
+ source_files.remove(message_template_files[0])
+ message_template_file = message_template_files[0]
+
+ filters = BuildFilterChain(macro_file, message_template_file)
# Sort 'debugger' sources first.
source_files = sorted(source_files,
« no previous file with comments | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698