diff options
Diffstat (limited to 'tools/snippets_translate')
| -rw-r--r-- | tools/snippets_translate/converter.py | 9 | ||||
| -rw-r--r-- | tools/snippets_translate/tests/test_converter.py | 8 |
2 files changed, 13 insertions, 4 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)): diff --git a/tools/snippets_translate/tests/test_converter.py b/tools/snippets_translate/tests/test_converter.py index a1f01eae1..084cc8a6d 100644 --- a/tools/snippets_translate/tests/test_converter.py +++ b/tools/snippets_translate/tests/test_converter.py @@ -166,14 +166,14 @@ def test_cout_endl(): def test_variable_declaration(): assert st("QLabel label;") == "label = QLabel()" - assert st('QLabel label("Hello")') == 'label = QLabel("Hello")' + assert st('QLabel label("Hello");') == 'label = QLabel("Hello")' assert st("Widget w;") == "w = Widget()" assert st('QLabel *label = new QLabel("Hello");') == 'label = QLabel("Hello")' assert st('QLabel label = a_function("Hello");') == 'label = a_function("Hello")' assert st('QString a = "something";') == 'a = "something"' assert st("int var;") == "var = int()" assert st("float v = 0.1;") == "v = 0.1" - assert st("QSome<thing> var") == "var = QSome()" + assert st("QSome<thing> var;") == "var = QSome()" assert st("QQueue<int> queue;") == "queue = QQueue()" assert st("QVBoxLayout *layout = new QVBoxLayout;") == "layout = QVBoxLayout()" assert st("QPointer<QLabel> label = new QLabel;") == "label = QLabel()" @@ -181,6 +181,10 @@ def test_variable_declaration(): assert st("QList<QImage> collage =") == "collage =" assert st("bool b = true;") == "b = True" assert st("Q3DBars *m_graph = nullptr;") == "m_graph = None" + # Do not fall for member function definitions + assert st("Q3DBars *Graph::bars() const") == "Q3DBars Graph.bars()" + # Do not fall for member function declarations + assert st("virtual Q3DBars *bars();") == "virtual Q3DBars bars()" def test_for(): |
