diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-09-19 14:40:37 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-09-21 10:01:15 +0200 |
| commit | 68883026da79c4f380411237731d761429760c23 (patch) | |
| tree | c8e79f30cf02350eb983ab1898964eb276566a3a /tools/snippets_translate/handlers.py | |
| parent | 2a3c2d88940e44c658e1a54e9834765683c127ff (diff) | |
snippets_translate: Fix handling of operator new, take 2
Change e48dce39c1450e73f7cdef58cfeba29e1c3b8be3 introduced a bug
appending "()" to member initalizer lists "m_member(new X()),". Fix
that by using a regexp to loop through the expressions.
Pick-to: 6.3
Change-Id: I6ce095749bcab74e92fb6dd630f25fb9fd517cc5
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools/snippets_translate/handlers.py')
| -rw-r--r-- | tools/snippets_translate/handlers.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/snippets_translate/handlers.py b/tools/snippets_translate/handlers.py index 05c3cfba1..57b00e9da 100644 --- a/tools/snippets_translate/handlers.py +++ b/tools/snippets_translate/handlers.py @@ -39,6 +39,7 @@ COUT_ENDL_PATTERN = re.compile(r"cout *<<(.*)<< *.*endl") COUT1_PATTERN = re.compile(r" *<< *") COUT2_PATTERN = re.compile(r".*cout *<<") COUT_ENDL2_PATTERN = re.compile(r"<< +endl") +NEW_PATTERN = re.compile(r"new +([a-zA-Z][a-zA-Z0-9_]*)") def handle_condition(x, name): @@ -512,6 +513,23 @@ def handle_useless_qt_classes(x): return x +def handle_new(x): + """Parse operator new() and add parentheses were needed: + func(new Foo, new Bar(x))" -> "func(Foo(), Bar(x))""" + result = "" + last_pos = 0 + for match in NEW_PATTERN.finditer(x): + end = match.end(0) + parentheses_needed = end >= len(x) or x[end] != "(" + type_name = match.group(1) + result += x[last_pos:match.start(0)] + type_name + if parentheses_needed: + result += "()" + last_pos = end + result += x[last_pos:] + return result + + # The code below handles pairs of instance/pointer to member functions (PMF) # which appear in Qt in connect statements like: # "connect(fontButton, &QAbstractButton::clicked, this, &Dialog::setFont)". |
