aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-27 14:57:02 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-29 17:34:22 +0100
commit9b887937f971887a32aefd584cc247bc7ec0f36e (patch)
treed26946ce4c67be071d2a9d2d18cbbba4ad74ce77 /tools
parent49353faf76fd8d9a26e6304a5816ccc026c5f9a1 (diff)
snippets_translate: Enable all modules
Fix a fixme commment. To make this pass, make the conditions matches more strict and add some warnings and error handling. Remove the checking of stderr from the CMake statement as this will produce some warnings. Pick-to: 6.2 Task-number: PYSIDE-1721 Change-Id: I8aeefa8355144d98524a622733d82d337cd3c23b Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/snippets_translate/handlers.py34
-rw-r--r--tools/snippets_translate/main.py3
2 files changed, 25 insertions, 12 deletions
diff --git a/tools/snippets_translate/handlers.py b/tools/snippets_translate/handlers.py
index 510498a30..7da983bc4 100644
--- a/tools/snippets_translate/handlers.py
+++ b/tools/snippets_translate/handlers.py
@@ -42,6 +42,11 @@ import sys
from parse_utils import get_indent, dstrip, remove_ref, parse_arguments, replace_main_commas, get_qt_module_class
+IF_PATTERN = re.compile(r'^if\s*\(')
+ELSE_IF_PATTERN = re.compile(r'^}?\s*else if\s*\(')
+WHILE_PATTERN = re.compile(r'^while\s*\(')
+
+
def handle_condition(x, name):
# Make sure it's not a multi line condition
x = x.replace("}", "")
@@ -57,8 +62,13 @@ def handle_condition(x, name):
x = x.replace(f"//{comment_content[-1]}", "")
re_par = re.compile(r"\((.+)\)")
- condition = re_par.search(x).group(1)
- return f"{get_indent(x)}{name} {condition.strip()}:{comment}"
+ match = re_par.search(x)
+ if match:
+ condition = re_par.search(x).group(1)
+ return f"{get_indent(x)}{name} {condition.strip()}:{comment}"
+ else:
+ print(f'snippets_translate: Warning "{x}" does not match condition pattern',
+ file=sys.stderr)
return x
@@ -138,11 +148,11 @@ def handle_include(x):
def handle_conditions(x):
x_strip = x.strip()
- if x_strip.startswith("while") and "(" in x:
+ if WHILE_PATTERN.match(x):
x = handle_condition(x, "while")
- elif x_strip.startswith("if") and "(" in x:
+ elif IF_PATTERN.match(x):
x = handle_condition(x, "if")
- elif x_strip.startswith(("else if", "} else if")):
+ elif ELSE_IF_PATTERN.match(x):
x = handle_condition(x, "else if")
x = x.replace("else if", "elif")
x = x.replace("::", ".")
@@ -187,7 +197,7 @@ def handle_for(x):
# Malformed for-loop:
# for (; pixel1 > start; pixel1 -= stride)
# We return the same line
- if not start.strip():
+ if not start.strip() or not "=" in start:
return f"{get_indent(x)}{dstrip(x)}"
raw_var, value = start.split("=")
raw_var = raw_var.strip()
@@ -333,9 +343,14 @@ def handle_constructor_default_values(x):
elif arg:
var_name = arg.split("(")[0]
re_par = re.compile(r"\((.+)\)")
- content = re_par.search(arg).group(1)
- return f" self.{var_name} = {content}"
-
+ match = re_par.search(arg)
+ if match:
+ content = match.group(1)
+ return f" self.{var_name} = {content}"
+ else:
+ print(f'snippets_translate: Warning "{arg}" does not match pattern',
+ file=sys.stderr)
+ return ""
return return_values.rstrip()
@@ -409,6 +424,7 @@ def handle_void_functions(x):
method_name = class_method.strip()
# if the arguments are in the same line:
+ arguments = None
if ")" in x:
re_content = re.compile(r"\((.*)\)")
parenthesis = re_content.search(x).group(1)
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index 94408a483..29a445fd9 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -397,9 +397,6 @@ def process(options):
else:
for i in qt_path.iterdir():
module_name = i.name
- # FIXME: remove this, since it's just for testing.
- if i.name != "qtbase":
- continue
# Filter only Qt modules
if not module_name.startswith("qt"):