From 123031b6efa9e95c787b2069fed6f6777a92dc13 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 11 Dec 2018 09:44:50 +0100 Subject: shiboken: Make warning about non-existing templates fatal It should abort as it will usually result in broken code. Change-Id: I81d930c4516b0ee97dec985525fab8140fdce3dc Reviewed-by: Qt CI Bot Reviewed-by: Cristian Maureira-Fredes --- .../ApiExtractor/tests/testinserttemplate.cpp | 46 ---------------------- .../ApiExtractor/tests/testinserttemplate.h | 2 - sources/shiboken2/ApiExtractor/typesystem.cpp | 31 +++++++-------- 3 files changed, 14 insertions(+), 65 deletions(-) diff --git a/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp b/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp index 766265def..8962f83ff 100644 --- a/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp @@ -81,50 +81,4 @@ void TestInsertTemplate::testInsertTemplateOnModuleInjectCode() QVERIFY(code.contains(QLatin1String("code template content"))); } -void TestInsertTemplate::testInvalidTypeSystemTemplate() -{ - const char* cppCode =""; - const char* xmlCode = "\ - \n\ - \n\ - \n\ - \n\ - \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); - AbstractMetaClassList classes = builder->classes(); - QVERIFY(classes.isEmpty()); - - TypeEntry* module = TypeDatabase::instance()->findType(QLatin1String("Foo")); - QVERIFY(module); - QCOMPARE(module->codeSnips().count(), 1); - QString code = module->codeSnips().first().code().trimmed(); - QVERIFY(code.isEmpty()); -} - -void TestInsertTemplate::testValidAndInvalidTypeSystemTemplate() -{ - const char* cppCode =""; - const char* xmlCode = "\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); - AbstractMetaClassList classes = builder->classes(); - QVERIFY(classes.isEmpty()); - - TypeEntry* module = TypeDatabase::instance()->findType(QLatin1String("Foo")); - QVERIFY(module); - QCOMPARE(module->codeSnips().count(), 1); - QString code = module->codeSnips().first().code().trimmed(); - QVERIFY(code.contains(QLatin1String("code template content"))); -} - QTEST_APPLESS_MAIN(TestInsertTemplate) diff --git a/sources/shiboken2/ApiExtractor/tests/testinserttemplate.h b/sources/shiboken2/ApiExtractor/tests/testinserttemplate.h index 45a85493c..99b171933 100644 --- a/sources/shiboken2/ApiExtractor/tests/testinserttemplate.h +++ b/sources/shiboken2/ApiExtractor/tests/testinserttemplate.h @@ -37,8 +37,6 @@ class TestInsertTemplate : public QObject private slots: void testInsertTemplateOnClassInjectCode(); void testInsertTemplateOnModuleInjectCode(); - void testInvalidTypeSystemTemplate(); - void testValidAndInvalidTypeSystemTemplate(); }; #endif diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index e82221a40..ff4f74d8c 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -3053,23 +3053,20 @@ QString fixCppTypeName(const QString &name) QString TemplateInstance::expandCode() const { TemplateEntry *templateEntry = TypeDatabase::instance()->findTemplate(m_name); - if (templateEntry) { - typedef QHash::const_iterator ConstIt; - QString code = templateEntry->code(); - for (ConstIt it = replaceRules.begin(), end = replaceRules.end(); it != end; ++it) - code.replace(it.key(), it.value()); - while (!code.isEmpty() && code.at(code.size() - 1).isSpace()) - code.chop(1); - QString result = QLatin1String("// TEMPLATE - ") + m_name + QLatin1String(" - START"); - if (!code.startsWith(QLatin1Char('\n'))) - result += QLatin1Char('\n'); - result += code; - result += QLatin1String("\n// TEMPLATE - ") + m_name + QLatin1String(" - END"); - return result; - } - qCWarning(lcShiboken).noquote().nospace() - << "insert-template referring to non-existing template '" << m_name << '\''; - return QString(); + if (!templateEntry) + qFatal(" referring to non-existing template '%s'.", qPrintable(m_name)); + + QString code = templateEntry->code(); + for (auto it = replaceRules.cbegin(), end = replaceRules.cend(); it != end; ++it) + code.replace(it.key(), it.value()); + while (!code.isEmpty() && code.at(code.size() - 1).isSpace()) + code.chop(1); + QString result = QLatin1String("// TEMPLATE - ") + m_name + QLatin1String(" - START"); + if (!code.startsWith(QLatin1Char('\n'))) + result += QLatin1Char('\n'); + result += code; + result += QLatin1String("\n// TEMPLATE - ") + m_name + QLatin1String(" - END"); + return result; } -- cgit v1.2.3