From 2355c4f80915deac98ddeb2ee507c72d8995fb1c Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 2 Apr 2012 13:00:52 +0200 Subject: [PATCH 01/11] We should not touch QMAKE_MKSPECS qmake variable. Change-Id: I954ad9a231207b175ac9116ca310290dfaa2980f Reviewed-by: Daniel Teske --- src/plugins/qtsupport/baseqtversion.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp index 3769089ff8d..49c6c447082 100644 --- a/src/plugins/qtsupport/baseqtversion.cpp +++ b/src/plugins/qtsupport/baseqtversion.cpp @@ -803,9 +803,6 @@ void BaseQtVersion::updateVersionInfo() const const QString qtInstallData = m_versionInfo.value(installDataKey); const QString qtInstallBins = m_versionInfo.value(installBinsKey); const QString qtHeaderData = m_versionInfo.value(installHeadersKey); - m_versionInfo.insert(QLatin1String("QMAKE_MKSPECS"), - QDir::cleanPath(qtInstallData + QLatin1String("/mkspecs"))); - if (!qtInstallData.isEmpty()) { m_hasDebuggingHelper = !ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData).isEmpty(); m_hasQmlDump From 332072019a5ebdef9158e6e31b4657b0411ae08a Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Mon, 2 Apr 2012 08:46:56 +0200 Subject: [PATCH 02/11] Preprocessor: Fix client notification. - Notify end of macro if function expansion is skipped. - Do not notify client of generated macros expansion. Change-Id: Ic027fc13ee391425a5ebadc8e84b9305912dbcf0 Reviewed-by: Roberto Raggi --- src/libs/cplusplus/pp-engine.cpp | 9 ++-- .../preprocessor/tst_preprocessor.cpp | 46 ++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index e8c425e284f..752008f32b0 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -800,14 +800,17 @@ bool Preprocessor::handleIdentifier(PPToken *tk) return false; // qDebug() << "expanding" << macro->name() << "on line" << tk->lineno; - if (m_client) + if (m_client && !tk->generated()) m_client->startExpandingMacro(tk->offset, *macro, macroName); QVector body = macro->definitionTokens(); if (macro->isFunctionLike()) { - if (!expandMacros() || !handleFunctionLikeMacro(tk, macro, body, !m_state.m_inDefine)) + if (!expandMacros() || !handleFunctionLikeMacro(tk, macro, body, !m_state.m_inDefine)) { // the call is not function like or expandMacros() returns false, so stop + if (m_client && !tk->generated()) + m_client->stopExpandingMacro(tk->offset, *macro); return false; + } } @@ -829,7 +832,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk) m_state.pushTokenBuffer(body.begin(), body.end(), macro); - if (m_client) + if (m_client && !tk->generated()) m_client->stopExpandingMacro(tk->offset, *macro); return true; diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index aa063e034a9..e9f05113017 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -111,9 +111,10 @@ public: virtual void startExpandingMacro(unsigned /*offset*/, const Macro &/*macro*/, - const QByteArray &/*originalText*/, + const QByteArray &originalText, const QVector &/*actuals*/ - = QVector()) {} + = QVector()) + { m_expandedMacros.append(originalText); } virtual void stopExpandingMacro(unsigned /*offset*/, const Macro &/*macro*/) {} @@ -206,6 +207,9 @@ public: QList recordedIncludes() const { return m_recordedIncludes; } + QList expandedMacros() const + { return m_expandedMacros; } + private: Environment *m_env; QByteArray *m_output; @@ -214,6 +218,7 @@ private: unsigned m_includeDepth; QList m_skippedBlocks; QList m_recordedIncludes; + QList m_expandedMacros; }; QDebug &operator<<(QDebug& d, const MockClient::Block &b) { d << '[' << b.start << ',' << b.end << ']'; return d; } @@ -240,6 +245,8 @@ private slots: void named_va_args(); void first_empty_macro_arg(); void invalid_param_count(); + void objmacro_expanding_as_fnmacro_notification(); + void macro_arguments_notificatin(); void unfinished_function_like_macro_call(); void nasty_macro_expansion(); void tstst(); @@ -362,6 +369,39 @@ void tst_Preprocessor::macro_definition_lineno() QVERIFY(preprocessed.contains("#gen true\n# 2 ")); } +void tst_Preprocessor::objmacro_expanding_as_fnmacro_notification() +{ + QByteArray output; + Environment env; + MockClient client(&env, &output); + + Preprocessor preprocess(&client, &env); + QByteArray preprocessed = preprocess(QLatin1String(""), + QByteArray("\n#define bar(a,b) a + b" + "\n#define foo bar" + "\nfoo(1, 2)\n")); + + QVERIFY(client.expandedMacros() == (QList() << QByteArray("foo"))); +} + +void tst_Preprocessor::macro_arguments_notificatin() +{ + QByteArray output; + Environment env; + MockClient client(&env, &output); + + Preprocessor preprocess(&client, &env); + QByteArray preprocessed = preprocess(QLatin1String(""), + QByteArray("\n#define foo(a,b) a + b" + "\n#define arg(a) a" + "\n#define value 2" + "\nfoo(arg(1), value)\n")); + + QVERIFY(client.expandedMacros() == (QList() << QByteArray("foo") + << QByteArray("arg") + << QByteArray("value"))); +} + void tst_Preprocessor::unfinished_function_like_macro_call() { Client *client = 0; // no client. @@ -483,6 +523,7 @@ void tst_Preprocessor::test_file_builtin() void tst_Preprocessor::comparisons_data() { + /* QTest::addColumn("infile"); QTest::addColumn("outfile"); QTest::addColumn("errorfile"); @@ -500,6 +541,7 @@ void tst_Preprocessor::comparisons_data() QTest::newRow("macro-test") << "macro-test.cpp" << "macro-test.out.cpp" << ""; QTest::newRow("empty-macro") << "empty-macro.cpp" << "empty-macro.out.cpp" << ""; QTest::newRow("empty-macro 2") << "empty-macro.2.cpp" << "empty-macro.2.out.cpp" << ""; + */ } void tst_Preprocessor::comparisons() From 4f239ff00d3e90744ac5721e701c8a1343107ce4 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Tue, 27 Mar 2012 19:32:03 +0200 Subject: [PATCH 03/11] mdnsd: cope better with large changes in time Large changes in time can happen due to sleep, or long uptime. Maybe calling the sleep hooks should be considered for a future fix. Change-Id: I746c2176a9b36cbafd5679ec1529ad59f8b691b5 Reviewed-by: Daniel Molkentin Reviewed-by: Fawzi Mohamed --- src/tools/mdnssd/mDNSPosix.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/mdnssd/mDNSPosix.c b/src/tools/mdnssd/mDNSPosix.c index a1868709dbe..682dc3a28c1 100755 --- a/src/tools/mdnssd/mDNSPosix.c +++ b/src/tools/mdnssd/mDNSPosix.c @@ -1441,6 +1441,12 @@ mDNSexport void mDNSPosixGetFDSet(mDNS *m, int *nfds, fd_set *readfds, struct ti if (timeout->tv_sec > interval.tv_sec || (timeout->tv_sec == interval.tv_sec && timeout->tv_usec > interval.tv_usec)) *timeout = interval; + // cope well with vey large changes in time (for example after sleep) + if (timeout->tv_sec > 1000) timeout->tv_sec = 1000; + if (timeout->tv_usec > 999999) timeout->tv_usec = 999999; + // should not happen, but let's be paranoid... + if (timeout->tv_sec < 0) timeout->tv_sec = 0; + if (timeout->tv_usec < 0) timeout->tv_usec = 1000; } mDNSexport void mDNSPosixProcessFDSet(mDNS *const m, fd_set *readfds) From f19c170a1e5ab26c3f9309a4732af806d5e9717a Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Mon, 2 Apr 2012 14:07:19 +0200 Subject: [PATCH 04/11] zeroconf: increase wait for daemon to reduce the possibility of starting multiple daemons Change-Id: I406e5e86f1d549471d7b0f178763a4dd283e369c Reviewed-by: Christian Kandeler --- src/libs/zeroconf/embed/dnssd_clientstub.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/zeroconf/embed/dnssd_clientstub.c b/src/libs/zeroconf/embed/dnssd_clientstub.c index 7c6d9eaf0ba..1f57a520efd 100644 --- a/src/libs/zeroconf/embed/dnssd_clientstub.c +++ b/src/libs/zeroconf/embed/dnssd_clientstub.c @@ -220,8 +220,8 @@ static int read_all(dnssd_sock_t sd, char *buf, int len) while (len) { timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 100000; + timeout.tv_sec = 1; + timeout.tv_usec = 0; fd_set readFds, writeFds, exceptFds; memset(&readFds,0,sizeof(readFds)); memset(&writeFds,0,sizeof(writeFds)); @@ -233,7 +233,7 @@ static int read_all(dnssd_sock_t sd, char *buf, int len) int nVal=select(sd+1, &readFds, &writeFds, &exceptFds, &timeout); if (nVal < 1 || !FD_ISSET(sd, &readFds)) { ++nErr; - if (nErr < 5) // wait max 0.5s without reading + if (nErr < 6) // wait max 6s without reading continue; } else { num_read = recv(sd, buf, len, 0); From 5c7bc3949c885a9fd9ecfa21ee914a2a3db56dff Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 30 Mar 2012 16:44:28 +0200 Subject: [PATCH 05/11] QtVersion: Get version string from qmake -query We need to run qmake -query during initialization anyway, so it makes no sense to use the faste qmake --version to get the Qt version number. Change-Id: If4f5efa074885a9be8938d54767008d8f1dc0d6b Reviewed-by: Daniel Teske --- src/plugins/qtsupport/baseqtversion.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp index 49c6c447082..f4c6854eda7 100644 --- a/src/plugins/qtsupport/baseqtversion.cpp +++ b/src/plugins/qtsupport/baseqtversion.cpp @@ -755,16 +755,7 @@ BaseQtVersion::QmakeBuildConfigs BaseQtVersion::defaultBuildConfig() const QString BaseQtVersion::qtVersionString() const { - if (!m_qtVersionString.isNull()) - return m_qtVersionString; - m_qtVersionString.clear(); - if (m_qmakeIsExecutable) { - const QString qmake = qmakeCommand().toString(); - m_qtVersionString = - ProjectExplorer::DebuggingHelperLibrary::qtVersionForQMake(qmake, &m_qmakeIsExecutable); - } else { - qWarning("Cannot determine the Qt version: %s cannot be run.", qPrintable(qmakeCommand().toString())); - } + updateVersionInfo(); return m_qtVersionString; } @@ -844,6 +835,7 @@ void BaseQtVersion::updateVersionInfo() const if (fi.exists()) m_hasDemos = true; } + m_qtVersionString = m_versionInfo.value(QLatin1String("QT_VERSION"), QString()); m_versionInfoUpToDate = true; } From 1a10bcdaade2e797b56a02f68699b8cf2ad0f776 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Mon, 2 Apr 2012 13:46:53 +0200 Subject: [PATCH 06/11] Add test case to preprocessor. - This enables some tests which had been unexpectedly disabled in earlier test. - Tests to show issue QTCREATORBUG-7225. - Tests which validates somehow behavior of preprocessor for QTCREATORBUG-7217: the test passes, so the problem is likely not in the startExpandingMacro() notification. Change-Id: Ib7c1433e4dcdd8c1d19fa117371f94c1645ec3fb Reviewed-by: Roberto Raggi --- .../preprocessor/tst_preprocessor.cpp | 137 +++++++++++++++--- 1 file changed, 119 insertions(+), 18 deletions(-) diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index e9f05113017..91819d3175a 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -109,12 +109,15 @@ public: virtual void passedMacroDefinitionCheck(unsigned /*offset*/, const Macro &/*macro*/) {} virtual void failedMacroDefinitionCheck(unsigned /*offset*/, const QByteArray &/*name*/) {} - virtual void startExpandingMacro(unsigned /*offset*/, + virtual void startExpandingMacro(unsigned offset, const Macro &/*macro*/, const QByteArray &originalText, const QVector &/*actuals*/ = QVector()) - { m_expandedMacros.append(originalText); } + { + m_expandedMacros.append(originalText); + m_expandedMacrosOffset.append(offset); + } virtual void stopExpandingMacro(unsigned /*offset*/, const Macro &/*macro*/) {} @@ -210,6 +213,9 @@ public: QList expandedMacros() const { return m_expandedMacros; } + QList expandedMacrosOffset() const + { return m_expandedMacrosOffset; } + private: Environment *m_env; QByteArray *m_output; @@ -219,8 +225,34 @@ private: QList m_skippedBlocks; QList m_recordedIncludes; QList m_expandedMacros; + QList m_expandedMacrosOffset; }; +namespace QTest { + template<> char *toString(const QList &list) + { + QByteArray ba = "QList("; + foreach (const unsigned& item, list) { + ba += QTest::toString(item); + ba += ','; + } + if (!list.isEmpty()) + ba[ba.size() - 1] = ')'; + return qstrdup(ba.data()); + } + template<> char *toString(const QList &list) + { + QByteArray ba = "QList("; + foreach (const QByteArray& item, list) { + ba += QTest::toString(item); + ba += ','; + } + if (!list.isEmpty()) + ba[ba.size() - 1] = ')'; + return qstrdup(ba.data()); + } +} + QDebug &operator<<(QDebug& d, const MockClient::Block &b) { d << '[' << b.start << ',' << b.end << ']'; return d; } class tst_Preprocessor: public QObject @@ -236,9 +268,12 @@ protected: client.sourceNeeded("data/" + fileName, nolines); return output; } + static QString simplified(QByteArray buf); private /* not corrected yet */: void macro_definition_lineno(); + void param_expanding_as_multiple_params(); + void macro_argument_expansion(); private slots: void va_args(); @@ -246,6 +281,7 @@ private slots: void first_empty_macro_arg(); void invalid_param_count(); void objmacro_expanding_as_fnmacro_notification(); + void macro_uses(); void macro_arguments_notificatin(); void unfinished_function_like_macro_call(); void nasty_macro_expansion(); @@ -259,6 +295,30 @@ private slots: void comparisons(); }; +// Remove all #... lines, and 'simplify' string, to allow easily comparing the result +// Also, remove all unneeded spaces: keep only to ensure identifiers are separated. +// NOTE: may not correctly handle underscore in identifiers +QString tst_Preprocessor::simplified(QByteArray buf) +{ + QString out; + QList lines = buf.split('\n'); + foreach (QByteArray line, lines) + if (!line.startsWith('#')) { + out.append(' '); + out.append(line); + } + + out = out.simplified(); + for (int i=1; i"), + QByteArray("\n#define foo(a,b) int f(a,b);" + "\n#define ARGS(t) t a,t b" + "\nfoo(ARGS(int))")); + QCOMPARE(simplified(preprocessed), QString("int f(int a,int b);")); +} + +void tst_Preprocessor::macro_argument_expansion() //QTCREATORBUG-7225 +{ + Client *client = 0; // no client. + Environment env; + + Preprocessor preprocess(client, &env); + QByteArray preprocessed = preprocess(QLatin1String(""), + QByteArray("\n#define BAR1 2,3,4" + "\n#define FOO1(a,b,c) a+b+c" + "\nvoid test2(){" + "\nint x=FOO1(BAR1);" + "\n}")); + QCOMPARE(simplified(preprocessed), QString("void test2(){int x=2+3+4;}")); + +} + +void tst_Preprocessor::macro_uses() +{ + QByteArray buffer = QByteArray("\n#define FOO 8" + "\n#define BAR 9" + "\nvoid test(){" + "\n\tint x=FOO;" + "\n\tint y=BAR;" + "\n}"); + + QByteArray output; + Environment env; + MockClient client(&env, &output); + + Preprocessor preprocess(&client, &env); + QByteArray preprocessed = preprocess(QLatin1String(""), buffer); + QCOMPARE(simplified(preprocessed), QString("void test(){int x=8;int y=9;}")); + QCOMPARE(client.expandedMacros(), QList() << QByteArray("FOO") << QByteArray("BAR")); + QCOMPARE(client.expandedMacrosOffset(), QList() << buffer.indexOf("FOO;") << buffer.indexOf("BAR;")); +} + void tst_Preprocessor::macro_definition_lineno() { Client *client = 0; // no client. @@ -343,30 +446,30 @@ void tst_Preprocessor::macro_definition_lineno() QByteArray preprocessed = preprocess(QLatin1String(""), QByteArray("#define foo(ARGS) int f(ARGS)\n" "foo(int a);\n")); - QVERIFY(preprocessed.contains("#gen true\n# 2 ")); + QVERIFY(preprocessed.contains("#gen true\n# 2 \"\"\nint f")); preprocessed = preprocess(QLatin1String(""), QByteArray("#define foo(ARGS) int f(ARGS)\n" "foo(int a)\n" ";\n")); - QVERIFY(preprocessed.contains("#gen true\n# 2 ")); + QVERIFY(preprocessed.contains("#gen true\n# 2 \"\"\nint f")); preprocessed = preprocess(QLatin1String(""), QByteArray("#define foo(ARGS) int f(ARGS)\n" "foo(int \n" " a);\n")); - QVERIFY(preprocessed.contains("#gen true\n# 2 ")); + QVERIFY(preprocessed.contains("#gen true\n# 2 \"\"\nint f")); preprocessed = preprocess(QLatin1String(""), QByteArray("#define foo int f\n" "foo;\n")); - QVERIFY(preprocessed.contains("#gen true\n# 2 ")); + QVERIFY(preprocessed.contains("#gen true\n# 2 \"\"\nint f")); preprocessed = preprocess(QLatin1String(""), QByteArray("#define foo int f\n" "foo\n" ";\n")); - QVERIFY(preprocessed.contains("#gen true\n# 2 ")); + QVERIFY(preprocessed.contains("#gen true\n# 2 \"\"\nint f")); } void tst_Preprocessor::objmacro_expanding_as_fnmacro_notification() @@ -523,7 +626,6 @@ void tst_Preprocessor::test_file_builtin() void tst_Preprocessor::comparisons_data() { - /* QTest::addColumn("infile"); QTest::addColumn("outfile"); QTest::addColumn("errorfile"); @@ -541,7 +643,6 @@ void tst_Preprocessor::comparisons_data() QTest::newRow("macro-test") << "macro-test.cpp" << "macro-test.out.cpp" << ""; QTest::newRow("empty-macro") << "empty-macro.cpp" << "empty-macro.out.cpp" << ""; QTest::newRow("empty-macro 2") << "empty-macro.2.cpp" << "empty-macro.2.out.cpp" << ""; - */ } void tst_Preprocessor::comparisons() From 94569488845581f1d8b60969966bb20876c2354d Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 2 Apr 2012 13:36:42 +0200 Subject: [PATCH 07/11] qbs files: missing dependency fixed texteditor_dependencies.pri adapted. Change-Id: Id8e2a12701deb6b2e3754dd67d583cfb58c21d95 Reviewed-by: Christian Kandeler --- src/plugins/texteditor/texteditor.qbs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index c12adef8c5e..752535cfbf5 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -257,5 +257,9 @@ QtcPlugin { "tooltip/tooltip.cpp", "tooltip/tooltip.h" ] + ProductModule { + Depends { name: "Find" } + Depends { name: "Locator" } + } } From 79f238fb75712f519fe5cb5d48b3a358f7ebbbbd Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 2 Apr 2012 15:33:49 +0200 Subject: [PATCH 08/11] RemoteLinux: Allow deriving from LinuxDeviceConfiguration. Change-Id: Ifd8405c079e047a40264c8310731cedbf7bd652f Reviewed-by: Nikolai Kosjar --- src/plugins/remotelinux/linuxdeviceconfiguration.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/remotelinux/linuxdeviceconfiguration.h b/src/plugins/remotelinux/linuxdeviceconfiguration.h index 58c9d11e8d2..c03b29bef11 100644 --- a/src/plugins/remotelinux/linuxdeviceconfiguration.h +++ b/src/plugins/remotelinux/linuxdeviceconfiguration.h @@ -72,16 +72,18 @@ public: void fromMap(const QVariantMap &map); ProjectExplorer::IDevice::Ptr clone() const; -private: + +protected: LinuxDeviceConfiguration(); LinuxDeviceConfiguration(const QString &name, const QString &type, MachineType machineType, Origin origin, const QString &fingerprint); - LinuxDeviceConfiguration(const LinuxDeviceConfiguration &other); - LinuxDeviceConfiguration &operator=(const LinuxDeviceConfiguration &); QVariantMap toMap() const; +private: + LinuxDeviceConfiguration &operator=(const LinuxDeviceConfiguration &); + Internal::LinuxDeviceConfigurationPrivate *d; }; From fcb825d4f6f1641be6aee5a7fe1108ff950f2198 Mon Sep 17 00:00:00 2001 From: Takumi ASAKI Date: Wed, 28 Mar 2012 11:31:03 +0900 Subject: [PATCH 09/11] Qml/C++: Add finding C++ qmlRegisterUncreatableType calls. Change-Id: I4e1b87cc247a04236a9c9f157d04b1fc817530d0 Reviewed-by: Christian Kamm Reviewed-by: Fawzi Mohamed --- .../qmljstools/qmljsfindexportedcpptypes.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp b/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp index 1f064dc6aca..9f9f66f373f 100644 --- a/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp +++ b/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp @@ -143,7 +143,12 @@ protected: if (!templateIdentifier) return false; const QString callName = QString::fromUtf8(templateIdentifier->chars()); - if (callName != QLatin1String("qmlRegisterType")) + int argCount = 0; + if (callName == QLatin1String("qmlRegisterType")) + argCount = 4; + else if (callName == QLatin1String("qmlRegisterUncreatableType")) + argCount = 5; + else return false; // must have a single typeid template argument @@ -154,16 +159,21 @@ protected: if (!typeId) return false; - // must have four arguments + // must have four arguments for qmlRegisterType and five for qmlRegisterUncreatableType if (!ast->expression_list || !ast->expression_list->value || !ast->expression_list->next || !ast->expression_list->next->value || !ast->expression_list->next->next || !ast->expression_list->next->next->value || !ast->expression_list->next->next->next - || !ast->expression_list->next->next->next->value - || ast->expression_list->next->next->next->next) + || !ast->expression_list->next->next->next->value) + return false; + if (argCount == 4 && ast->expression_list->next->next->next->next) + return false; + if (argCount == 5 && (!ast->expression_list->next->next->next->next + || !ast->expression_list->next->next->next->next->value + || ast->expression_list->next->next->next->next->next)) return false; - // last argument must be a string literal + // 4th argument must be a string literal const StringLiteral *nameLit = 0; if (StringLiteralAST *nameAst = skipStringCall(ast->expression_list->next->next->next->value)->asStringLiteral()) nameLit = translationUnit()->stringLiteral(nameAst->literal_token); @@ -748,11 +758,16 @@ bool FindExportedCppTypes::maybeExportsTypes(const Document::Ptr &document) if (!document->control()) return false; const QByteArray qmlRegisterTypeToken("qmlRegisterType"); + const QByteArray qmlRegisterUncreatableTypeToken("qmlRegisterUncreatableType"); const QByteArray setContextPropertyToken("setContextProperty"); if (document->control()->findIdentifier( qmlRegisterTypeToken.constData(), qmlRegisterTypeToken.size())) { return true; } + if (document->control()->findIdentifier( + qmlRegisterUncreatableTypeToken.constData(), qmlRegisterUncreatableTypeToken.size())) { + return true; + } if (document->control()->findIdentifier( setContextPropertyToken.constData(), setContextPropertyToken.size())) { return true; From 68471c2100384390989fbef50351bf7e76fe61a8 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Mon, 2 Apr 2012 14:57:13 +0200 Subject: [PATCH 10/11] Preprocessor: fix macro definition line. The line corresponding to the macro definition is simply the token's line. This caused errors in the macro definitions, since there were multiple macros defined on the same line of the same file. Task-number: QTCREATORBUG-7217 Change-Id: I56d17eeba677ac51f9eed283c0e964019bdfe4b7 Reviewed-by: Roberto Raggi --- src/libs/cplusplus/pp-engine.cpp | 2 +- .../cplusplus/preprocessor/tst_preprocessor.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 752008f32b0..d92edb2115b 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -1189,7 +1189,7 @@ void Preprocessor::handleDefineDirective(PPToken *tk) Macro macro; macro.setFileName(m_env->currentFile); - macro.setLine(m_env->currentLine); + macro.setLine(tk->lineno); QByteArray macroName = tk->asByteArrayRef().toByteArray(); macro.setName(macroName); macro.setOffset(tk->offset); diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index 91819d3175a..95e41111534 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -104,7 +104,11 @@ public: virtual ~MockClient() {} - virtual void macroAdded(const Macro &/*macro*/) {} + virtual void macroAdded(const Macro & macro) + { + m_definedMacros.append(macro.name()); + m_definedMacrosLine.append(macro.line()); + } virtual void passedMacroDefinitionCheck(unsigned /*offset*/, const Macro &/*macro*/) {} virtual void failedMacroDefinitionCheck(unsigned /*offset*/, const QByteArray &/*name*/) {} @@ -216,6 +220,12 @@ public: QList expandedMacrosOffset() const { return m_expandedMacrosOffset; } + QList definedMacros() const + { return m_definedMacros; } + + QList definedMacrosLine() const + { return m_definedMacrosLine; } + private: Environment *m_env; QByteArray *m_output; @@ -226,6 +236,8 @@ private: QList m_recordedIncludes; QList m_expandedMacros; QList m_expandedMacrosOffset; + QList m_definedMacros; + QList m_definedMacrosLine; }; namespace QTest { @@ -436,6 +448,8 @@ void tst_Preprocessor::macro_uses() QCOMPARE(simplified(preprocessed), QString("void test(){int x=8;int y=9;}")); QCOMPARE(client.expandedMacros(), QList() << QByteArray("FOO") << QByteArray("BAR")); QCOMPARE(client.expandedMacrosOffset(), QList() << buffer.indexOf("FOO;") << buffer.indexOf("BAR;")); + QCOMPARE(client.definedMacros(), QList() << QByteArray("FOO") << QByteArray("BAR")); + QCOMPARE(client.definedMacrosLine(), QList() << 2 << 3); } void tst_Preprocessor::macro_definition_lineno() From ecdecd4e97397afeeb83af0f5c9e3fef9a1ba522 Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Mon, 2 Apr 2012 13:09:37 +0200 Subject: [PATCH 11/11] DebuggerTreeView: Move base class to utils Change-Id: I3313789be5f835d218cad5ed5f3143aee18e9f5f Reviewed-by: hjk --- src/libs/utils/basetreeview.cpp | 137 ++++++++++++++++++ src/libs/utils/basetreeview.h | 76 ++++++++++ src/libs/utils/utils-lib.pri | 6 +- src/plugins/debugger/basewindow.cpp | 96 +----------- src/plugins/debugger/basewindow.h | 27 +--- src/plugins/debugger/registerwindow.cpp | 1 - .../qmljsinspector/qmljspropertyinspector.cpp | 21 +-- .../qmljsinspector/qmljspropertyinspector.h | 7 +- 8 files changed, 228 insertions(+), 143 deletions(-) create mode 100644 src/libs/utils/basetreeview.cpp create mode 100644 src/libs/utils/basetreeview.h diff --git a/src/libs/utils/basetreeview.cpp b/src/libs/utils/basetreeview.cpp new file mode 100644 index 00000000000..b1307bc0083 --- /dev/null +++ b/src/libs/utils/basetreeview.cpp @@ -0,0 +1,137 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "basetreeview.h" + +#include +#include +#include + +namespace Utils { + +BaseTreeView::BaseTreeView(QWidget *parent) + : QTreeView(parent) +{ + setAttribute(Qt::WA_MacShowFocusRect, false); + setFrameStyle(QFrame::NoFrame); + setRootIsDecorated(false); + setIconSize(QSize(10, 10)); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setUniformRowHeights(true); + + header()->setDefaultAlignment(Qt::AlignLeft); + header()->setClickable(true); + + connect(this, SIGNAL(activated(QModelIndex)), + SLOT(rowActivatedHelper(QModelIndex))); + connect(header(), SIGNAL(sectionClicked(int)), + SLOT(headerSectionClicked(int))); + + m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0); + m_alwaysAdjustColumnsAction = 0; +} + +void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action) +{ + m_alwaysAdjustColumnsAction = action; + connect(action, SIGNAL(toggled(bool)), + SLOT(setAlwaysResizeColumnsToContents(bool))); +} + +void BaseTreeView::addBaseContextActions(QMenu *menu) +{ + menu->addSeparator(); + if (m_alwaysAdjustColumnsAction) + menu->addAction(m_alwaysAdjustColumnsAction); + menu->addAction(m_adjustColumnsAction); + menu->addSeparator(); +} + +bool BaseTreeView::handleBaseContextAction(QAction *act) +{ + if (act == 0) + return true; + if (act == m_adjustColumnsAction) { + resizeColumnsToContents(); + return true; + } + if (act == m_alwaysAdjustColumnsAction) { + if (act->isChecked()) + resizeColumnsToContents(); + // Action triggered automatically. + return true; + } + return false; +} + +void BaseTreeView::setModel(QAbstractItemModel *model) +{ + QTreeView::setModel(model); + if (header() && m_alwaysAdjustColumnsAction) + setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked()); +} + +void BaseTreeView::mousePressEvent(QMouseEvent *ev) +{ + QTreeView::mousePressEvent(ev); + if (!indexAt(ev->pos()).isValid()) + resizeColumnsToContents(); +} + +void BaseTreeView::resizeColumnsToContents() +{ + const int columnCount = model()->columnCount(); + for (int c = 0 ; c != columnCount; ++c) + resizeColumnToContents(c); +} + +void BaseTreeView::setAlwaysResizeColumnsToContents(bool on) +{ + QHeaderView::ResizeMode mode = on + ? QHeaderView::ResizeToContents : QHeaderView::Interactive; + header()->setResizeMode(0, mode); +} + +void BaseTreeView::headerSectionClicked(int logicalIndex) +{ + resizeColumnToContents(logicalIndex); +} + +void BaseTreeView::reset() +{ + QTreeView::reset(); + if (header() && m_alwaysAdjustColumnsAction + && m_alwaysAdjustColumnsAction->isChecked()) + resizeColumnsToContents(); +} + +} // namespace Utils diff --git a/src/libs/utils/basetreeview.h b/src/libs/utils/basetreeview.h new file mode 100644 index 00000000000..c78860ebd0f --- /dev/null +++ b/src/libs/utils/basetreeview.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef BASETREEVIEW_H +#define BASETREEVIEW_H + +#include "utils_global.h" + +#include + +namespace Utils { + +class QTCREATOR_UTILS_EXPORT BaseTreeView : public QTreeView +{ + Q_OBJECT + +public: + BaseTreeView(QWidget *parent = 0); + + void setAlwaysAdjustColumnsAction(QAction *action); + virtual void addBaseContextActions(QMenu *menu); + bool handleBaseContextAction(QAction *action); + + void setModel(QAbstractItemModel *model); + virtual void rowActivated(const QModelIndex &) {} + void mousePressEvent(QMouseEvent *ev); + +public slots: + void resizeColumnsToContents(); + void setAlwaysResizeColumnsToContents(bool on); + void reset(); + +protected slots: + void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); } + +private slots: + void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); } + void headerSectionClicked(int logicalIndex); + +private: + QAction *m_alwaysAdjustColumnsAction; + QAction *m_adjustColumnsAction; +}; + +} // namespace Utils + +#endif // BASETREEVIEW_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 152c0ad47d9..6327f3fbdcc 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -97,7 +97,8 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/json.cpp \ $$PWD/portlist.cpp \ $$PWD/tcpportsgatherer.cpp \ - $$PWD/appmainwindow.cpp + $$PWD/appmainwindow.cpp \ + $$PWD/basetreeview.cpp win32 { SOURCES += \ @@ -211,7 +212,8 @@ HEADERS += \ $$PWD/runextensions.h \ $$PWD/portlist.h \ $$PWD/tcpportsgatherer.h \ - $$PWD/appmainwindow.h + $$PWD/appmainwindow.h \ + $$PWD/basetreeview.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/plugins/debugger/basewindow.cpp b/src/plugins/debugger/basewindow.cpp index bf77f3f37d8..92fdcd0d913 100644 --- a/src/plugins/debugger/basewindow.cpp +++ b/src/plugins/debugger/basewindow.cpp @@ -40,9 +40,6 @@ #include #include -#include -#include -#include #include #include @@ -50,107 +47,20 @@ namespace Debugger { namespace Internal { BaseTreeView::BaseTreeView(QWidget *parent) - : QTreeView(parent) + : Utils::BaseTreeView(parent) { QAction *act = debuggerCore()->action(UseAlternatingRowColors); - - setAttribute(Qt::WA_MacShowFocusRect, false); - setFrameStyle(QFrame::NoFrame); setAlternatingRowColors(act->isChecked()); - setRootIsDecorated(false); - setIconSize(QSize(10, 10)); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setUniformRowHeights(true); - - header()->setDefaultAlignment(Qt::AlignLeft); - header()->setClickable(true); - connect(act, SIGNAL(toggled(bool)), - SLOT(setAlternatingRowColorsHelper(bool))); - connect(this, SIGNAL(activated(QModelIndex)), - SLOT(rowActivatedHelper(QModelIndex))); - connect(header(), SIGNAL(sectionClicked(int)), - SLOT(headerSectionClicked(int))); - - m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0); - m_alwaysAdjustColumnsAction = 0; -} - -void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action) -{ - m_alwaysAdjustColumnsAction = action; - connect(action, SIGNAL(toggled(bool)), - SLOT(setAlwaysResizeColumnsToContents(bool))); + SLOT(setAlternatingRowColorsHelper(bool))); } void BaseTreeView::addBaseContextActions(QMenu *menu) { - menu->addSeparator(); - if (m_alwaysAdjustColumnsAction) - menu->addAction(m_alwaysAdjustColumnsAction); - menu->addAction(m_adjustColumnsAction); - menu->addSeparator(); + Utils::BaseTreeView::addBaseContextActions(menu); menu->addAction(debuggerCore()->action(SettingsDialog)); } -bool BaseTreeView::handleBaseContextAction(QAction *act) -{ - if (act == 0) - return true; - if (act == m_adjustColumnsAction) { - resizeColumnsToContents(); - return true; - } - if (act == m_alwaysAdjustColumnsAction) { - if (act->isChecked()) - resizeColumnsToContents(); - // Action triggered automatically. - return true; - } - return false; -} - -void BaseTreeView::setModel(QAbstractItemModel *model) -{ - QTreeView::setModel(model); - if (header() && m_alwaysAdjustColumnsAction) - setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked()); -} - -void BaseTreeView::mousePressEvent(QMouseEvent *ev) -{ - QTreeView::mousePressEvent(ev); - if (!indexAt(ev->pos()).isValid()) - resizeColumnsToContents(); -} - -void BaseTreeView::resizeColumnsToContents() -{ - const int columnCount = model()->columnCount(); - for (int c = 0 ; c != columnCount; ++c) - resizeColumnToContents(c); -} - -void BaseTreeView::setAlwaysResizeColumnsToContents(bool on) -{ - QHeaderView::ResizeMode mode = on - ? QHeaderView::ResizeToContents : QHeaderView::Interactive; - header()->setResizeMode(0, mode); -} - -void BaseTreeView::headerSectionClicked(int logicalIndex) -{ - resizeColumnToContents(logicalIndex); -} - -void BaseTreeView::reset() -{ - QTreeView::reset(); - if (header() && m_alwaysAdjustColumnsAction - && m_alwaysAdjustColumnsAction->isChecked()) - resizeColumnsToContents(); -} - BaseWindow::BaseWindow(QTreeView *treeView, QWidget *parent) : QWidget(parent), m_treeView(treeView) { diff --git a/src/plugins/debugger/basewindow.h b/src/plugins/debugger/basewindow.h index f4f79f7e329..4a0b95d8b86 100644 --- a/src/plugins/debugger/basewindow.h +++ b/src/plugins/debugger/basewindow.h @@ -33,39 +33,18 @@ #ifndef DEBUGGER_BASEWINDOW_H #define DEBUGGER_BASEWINDOW_H -#include +#include namespace Debugger { namespace Internal { -class BaseTreeView : public QTreeView +class BaseTreeView : public Utils::BaseTreeView { Q_OBJECT public: - BaseTreeView(QWidget *parent = 0); - - void setAlwaysAdjustColumnsAction(QAction *action); + explicit BaseTreeView(QWidget *parent = 0); void addBaseContextActions(QMenu *menu); - bool handleBaseContextAction(QAction *action); - - void setModel(QAbstractItemModel *model); - virtual void rowActivated(const QModelIndex &) {} - void mousePressEvent(QMouseEvent *ev); - -public slots: - void resizeColumnsToContents(); - void setAlwaysResizeColumnsToContents(bool on); - -private slots: - void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); } - void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); } - void headerSectionClicked(int logicalIndex); - void reset(); - -private: - QAction *m_alwaysAdjustColumnsAction; - QAction *m_adjustColumnsAction; }; class BaseWindow : public QWidget diff --git a/src/plugins/debugger/registerwindow.cpp b/src/plugins/debugger/registerwindow.cpp index 4314cf6fbd6..bf796bb43dd 100644 --- a/src/plugins/debugger/registerwindow.cpp +++ b/src/plugins/debugger/registerwindow.cpp @@ -166,7 +166,6 @@ public: RegisterTreeView::RegisterTreeView(QWidget *parent) : BaseTreeView(parent) { - setAlwaysAdjustColumnsAction(debuggerCore()->action(UseAlternatingRowColors)); setItemDelegate(new RegisterDelegate(this)); } diff --git a/src/plugins/qmljsinspector/qmljspropertyinspector.cpp b/src/plugins/qmljsinspector/qmljspropertyinspector.cpp index 36d2db1bcc8..9f4c325c48c 100644 --- a/src/plugins/qmljsinspector/qmljspropertyinspector.cpp +++ b/src/plugins/qmljsinspector/qmljspropertyinspector.cpp @@ -292,28 +292,13 @@ bool QmlJSPropertyInspectorModel::contentsValid() const } QmlJSPropertyInspector::QmlJSPropertyInspector(QWidget *parent) - : QTreeView(parent) + : Utils::BaseTreeView(parent) { - setAttribute(Qt::WA_MacShowFocusRect, false); - setFrameStyle(QFrame::NoFrame); - setExpandsOnDoubleClick(true); - - header()->setDefaultAlignment(Qt::AlignLeft); - header()->setClickable(true); - setRootIsDecorated(false); - setItemDelegateForColumn(PROPERTY_VALUE_COLUMN, new PropertyEditDelegate(this)); setModel(&m_model); //Add an empty Row to make the headers visible! addRow(QString(), QString(), QString(), -1, false); - connect(header(), SIGNAL(sectionClicked(int)), - SLOT(headerSectionClicked(int))); -} - -void QmlJSPropertyInspector::headerSectionClicked(int logicalIndex) -{ - resizeColumnToContents(logicalIndex); } void QmlJSPropertyInspector::clear() @@ -491,8 +476,6 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev) { QMenu menu; QModelIndex itemIndex = indexAt(ev->pos()); - if (!itemIndex.isValid()) - return; bool isEditable = false; bool isColor = false; if (itemIndex.isValid()) { @@ -507,6 +490,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev) QAction colorAction(tr("Choose color"), this); if (isColor) menu.addAction(&colorAction); + addBaseContextActions(&menu); QAction *action = menu.exec(ev->globalPos()); if (action == 0) @@ -516,6 +500,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev) openExpressionEditor(itemIndex); if (action == &colorAction) openColorSelector(itemIndex); + handleBaseContextAction(action); } void QmlJSPropertyInspector::openExpressionEditor(const QModelIndex &itemIndex) diff --git a/src/plugins/qmljsinspector/qmljspropertyinspector.h b/src/plugins/qmljsinspector/qmljspropertyinspector.h index 568f28624bb..3080c646527 100644 --- a/src/plugins/qmljsinspector/qmljspropertyinspector.h +++ b/src/plugins/qmljsinspector/qmljspropertyinspector.h @@ -33,7 +33,7 @@ #define PROPERTYINSPECTOR_H #include -#include +#include #include #include @@ -108,7 +108,7 @@ private: bool m_contentsValid; }; -class QmlJSPropertyInspector : public QTreeView +class QmlJSPropertyInspector : public Utils::BaseTreeView { Q_OBJECT public: @@ -138,9 +138,6 @@ public slots: void openExpressionEditor(const QModelIndex &itemIndex); void openColorSelector(const QModelIndex &itemIndex); -private slots: - void headerSectionClicked(int logicalIndex); - private: friend class PropertyEditDelegate; void buildPropertyTree(const QmlDebugObjectReference &);