diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-07-03 11:35:18 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-07-05 11:58:10 +0200 |
| commit | 1f3f99bf62df78981c839c95ee98adad649a5ef4 (patch) | |
| tree | 2b380e5ceb25914e4541e5e451ed03ee61ba1cf4 /tools/snippets_translate/converter.py | |
| parent | 0faa54831af8ef7deedd2b6885ea2b3657179d7b (diff) | |
snippets_translate: Prevent the variable initialization code from triggering for functions
The code trying to change a constructor initialization:
"Foo foo(2);" into "foo = Foo(2)"
also triggered for member function definitions returning pointers
"Foo *Foo:foo()" and many function declarations in headers.
Restrict this by checking for a semicolon and non-presence of some
function qualifiers.
Pick-to: 6.5
Task-number: PYSIDE-1106
Change-Id: I224ac3e7321e57f1c5beecdcdb568a273330a664
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'tools/snippets_translate/converter.py')
| -rw-r--r-- | tools/snippets_translate/converter.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/snippets_translate/converter.py b/tools/snippets_translate/converter.py index 784e4e45f..d45bf277f 100644 --- a/tools/snippets_translate/converter.py +++ b/tools/snippets_translate/converter.py @@ -45,6 +45,9 @@ QUALIFIERS = {"public:", "protected:", "private:", "public slots:", "protected slots:", "private slots:", "signals:"} +FUNCTION_QUALIFIERS = ["virtual ", " override", "inline ", " noexcept"] + + switch_var = None switch_branch = 0 @@ -60,7 +63,8 @@ def snippet_translate(x): ## General Rules # Remove ';' at the end of the lines - if x.endswith(";"): + has_semicolon = x.endswith(";") + if has_semicolon: x = x[:-1] # Remove lines with only '{' or '}' @@ -260,7 +264,8 @@ def snippet_translate(x): # At the end we skip methods with the form: # QStringView Message::body() # to threat them as methods. - if (VAR1_PATTERN.search(xs) + if (has_semicolon and VAR1_PATTERN.search(xs) + and not ([f for f in FUNCTION_QUALIFIERS if f in x]) and xs.split()[0] not in ("def", "return", "and", "or") and not VAR2_PATTERN.search(xs) and ("{" not in x and "}" not in x)): |
