diff options
Diffstat (limited to 'src/plugins/cpptools')
78 files changed, 770 insertions, 1077 deletions
diff --git a/src/plugins/cpptools/CMakeLists.txt b/src/plugins/cpptools/CMakeLists.txt index c99705cbc1..e6e5bc129c 100644 --- a/src/plugins/cpptools/CMakeLists.txt +++ b/src/plugins/cpptools/CMakeLists.txt @@ -48,7 +48,6 @@ add_qtc_plugin(CppTools cpphoverhandler.cpp cpphoverhandler.h cppincludesfilter.cpp cppincludesfilter.h cppindexingsupport.cpp cppindexingsupport.h - cppkitinfo.cpp cppkitinfo.h cpplocalsymbols.cpp cpplocalsymbols.h cpplocatordata.cpp cpplocatordata.h cpplocatorfilter.cpp cpplocatorfilter.h @@ -62,8 +61,8 @@ add_qtc_plugin(CppTools cppprojectinfogenerator.cpp cppprojectinfogenerator.h cppprojectpartchooser.cpp cppprojectpartchooser.h cppprojectupdater.cpp cppprojectupdater.h + cppprojectupdaterinterface.h cppqtstyleindenter.cpp cppqtstyleindenter.h - cpprawprojectpart.cpp cpprawprojectpart.h cpprefactoringchanges.cpp cpprefactoringchanges.h cpprefactoringengine.cpp cpprefactoringengine.h cppselectionchanger.cpp cppselectionchanger.h @@ -71,7 +70,6 @@ add_qtc_plugin(CppTools cppsemanticinfoupdater.cpp cppsemanticinfoupdater.h cppsourceprocessor.cpp cppsourceprocessor.h cppsymbolinfo.h - cpptools.qrc cpptools_clangtidychecks.h cpptools_clazychecks.h cpptools_global.h diff --git a/src/plugins/cpptools/baseeditordocumentparser.cpp b/src/plugins/cpptools/baseeditordocumentparser.cpp index 91c6a3aa79..0616182376 100644 --- a/src/plugins/cpptools/baseeditordocumentparser.cpp +++ b/src/plugins/cpptools/baseeditordocumentparser.cpp @@ -55,7 +55,7 @@ BaseEditorDocumentParser::BaseEditorDocumentParser(const QString &filePath) : m_filePath(filePath) { static int meta = qRegisterMetaType<ProjectPartInfo>("CppTools::ProjectPartInfo"); - Q_UNUSED(meta); + Q_UNUSED(meta) } BaseEditorDocumentParser::~BaseEditorDocumentParser() = default; diff --git a/src/plugins/cpptools/builtincursorinfo.cpp b/src/plugins/cpptools/builtincursorinfo.cpp index 486db2c503..c1e4a9c8c7 100644 --- a/src/plugins/cpptools/builtincursorinfo.cpp +++ b/src/plugins/cpptools/builtincursorinfo.cpp @@ -55,26 +55,24 @@ CursorInfo::Range toRange(const SemanticInfo::Use &use) CursorInfo::Range toRange(int tokenIndex, TranslationUnit *translationUnit) { - unsigned line, column; - translationUnit->getTokenPosition(static_cast<unsigned>(tokenIndex), &line, &column); + int line, column; + translationUnit->getTokenPosition(tokenIndex, &line, &column); if (column) --column; // adjust the column position. return {line, column + 1, - translationUnit->tokenAt(static_cast<unsigned>(tokenIndex)).utf16chars()}; + translationUnit->tokenAt(tokenIndex).utf16chars()}; } -CursorInfo::Range toRange(const QTextCursor &textCursor, - unsigned utf16offset, - unsigned length) +CursorInfo::Range toRange(const QTextCursor &textCursor, int utf16offset, int length) { QTextCursor cursor(textCursor.document()); - cursor.setPosition(static_cast<int>(utf16offset)); + cursor.setPosition(utf16offset); const QTextBlock textBlock = cursor.block(); - return {static_cast<unsigned>(textBlock.blockNumber() + 1), - static_cast<unsigned>(cursor.position() - textBlock.position() + 1), + return {textBlock.blockNumber() + 1, + cursor.position() - textBlock.position() + 1, length}; } @@ -102,8 +100,8 @@ CursorInfo::Ranges toRanges(const QList<int> &tokenIndices, TranslationUnit *tra class FunctionDefinitionUnderCursor: protected ASTVisitor { - unsigned m_line = 0; - unsigned m_column = 0; + int m_line = 0; + int m_column = 0; DeclarationAST *m_functionDefinition = nullptr; public: @@ -111,7 +109,7 @@ public: : ASTVisitor(translationUnit) { } - DeclarationAST *operator()(AST *ast, unsigned line, unsigned column) + DeclarationAST *operator()(AST *ast, int line, int column) { m_functionDefinition = nullptr; m_line = line; @@ -140,8 +138,8 @@ protected: private: bool checkDeclaration(DeclarationAST *ast) { - unsigned startLine, startColumn; - unsigned endLine, endColumn; + int startLine, startColumn; + int endLine, endColumn; getTokenStartPosition(ast->firstToken(), &startLine, &startColumn); getTokenEndPosition(ast->lastToken() - 1, &endLine, &endColumn); @@ -207,16 +205,13 @@ private: LookupContext context(m_document, m_snapshot); - CppTools::SemanticInfo::LocalUseIterator it(uses); - while (it.hasNext()) { - it.next(); + for (auto it = uses.cbegin(), end = uses.cend(); it != end; ++it) { const SemanticUses &uses = it.value(); bool good = false; foreach (const CppTools::SemanticInfo::Use &use, uses) { - const auto l = static_cast<unsigned>(m_line); - const auto c = static_cast<unsigned>(m_column); - if (l == use.line && c >= use.column && c <= (use.column + use.length)) { + if (m_line == use.line && m_column >= use.column + && m_column <= static_cast<int>(use.column + use.length)) { good = true; break; } @@ -293,7 +288,7 @@ bool handleMacroCase(const Document::Ptr document, if (!macro) return false; - const unsigned length = static_cast<unsigned>(macro->nameToQString().size()); + const int length = macro->nameToQString().size(); // Macro definition if (macro->fileName() == document->fileName()) @@ -359,9 +354,7 @@ BuiltinCursorInfo::findLocalUses(const Document::Ptr &document, int line, int co AST *ast = document->translationUnit()->ast(); FunctionDefinitionUnderCursor functionDefinitionUnderCursor(document->translationUnit()); - DeclarationAST *declaration = functionDefinitionUnderCursor(ast, - static_cast<unsigned>(line), - static_cast<unsigned>(column)); + DeclarationAST *declaration = functionDefinitionUnderCursor(ast, line, column); return CppTools::LocalSymbols(document, declaration).uses; } diff --git a/src/plugins/cpptools/builtineditordocumentprocessor.cpp b/src/plugins/cpptools/builtineditordocumentprocessor.cpp index 9232750684..c9f69f644c 100644 --- a/src/plugins/cpptools/builtineditordocumentprocessor.cpp +++ b/src/plugins/cpptools/builtineditordocumentprocessor.cpp @@ -71,7 +71,7 @@ QList<QTextEdit::ExtraSelection> toTextEditorSelections( QTextCursor c(textDocument->findBlockByNumber(m.line() - 1)); const QString text = c.block().text(); const int startPos = m.column() > 0 ? m.column() - 1 : 0; - if (m.length() > 0 && startPos + m.length() <= (unsigned)text.size()) { + if (m.length() > 0 && startPos + m.length() <= text.size()) { c.setPosition(c.position() + startPos); c.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length()); } else { diff --git a/src/plugins/cpptools/clangdiagnosticconfigsselectionwidget.cpp b/src/plugins/cpptools/clangdiagnosticconfigsselectionwidget.cpp index 7899fcae4c..217ca95cb2 100644 --- a/src/plugins/cpptools/clangdiagnosticconfigsselectionwidget.cpp +++ b/src/plugins/cpptools/clangdiagnosticconfigsselectionwidget.cpp @@ -45,7 +45,7 @@ ClangDiagnosticConfigsSelectionWidget::ClangDiagnosticConfigsSelectionWidget(QWi , m_selectionComboBox(new QComboBox(this)) { auto *layout = new QHBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); layout->addWidget(m_label); layout->addWidget(m_selectionComboBox, 1); @@ -108,7 +108,7 @@ void ClangDiagnosticConfigsSelectionWidget::connectToClangDiagnosticConfigsDialo { connect(button, &QPushButton::clicked, [this]() { ClangDiagnosticConfigsWidget *widget = new ClangDiagnosticConfigsWidget(currentConfigId()); - widget->layout()->setMargin(0); + widget->layout()->setContentsMargins(0, 0, 0, 0); QDialog dialog; dialog.setWindowTitle(ClangDiagnosticConfigsWidget::tr("Diagnostic Configurations")); dialog.setLayout(new QVBoxLayout); diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp index 3d74ad8d32..e2858fb368 100644 --- a/src/plugins/cpptools/compileroptionsbuilder.cpp +++ b/src/plugins/cpptools/compileroptionsbuilder.cpp @@ -656,7 +656,7 @@ void CompilerOptionsBuilder::addWrappedQtHeadersIncludePath(QStringList &list) c static QString wrappedQtHeadersPath = resourcePath + "/cplusplus/wrappedQtHeaders"; QTC_ASSERT(QDir(wrappedQtHeadersPath).exists(), return;); - if (m_projectPart.qtVersion != ProjectPart::NoQt) { + if (m_projectPart.qtVersion != Utils::QtVersion::None) { const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore"; list.append({includeUserPathOption, QDir::toNativeSeparators(wrappedQtHeadersPath), diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp index ea534531e6..f4458bd059 100644 --- a/src/plugins/cpptools/cppchecksymbols.cpp +++ b/src/plugins/cpptools/cppchecksymbols.cpp @@ -314,9 +314,9 @@ CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, cons : ASTVisitor(doc->translationUnit()), _doc(doc), _context(context) , _lineOfLastUsage(0), _macroUses(macroUses) { - unsigned line = 0; + int line = 0; getTokenEndPosition(translationUnit()->ast()->lastToken(), &line, nullptr); - _chunkSize = qMax(50U, line / 200); + _chunkSize = qMax(50, line / 200); _usages.reserve(_chunkSize); _astStack.reserve(200); @@ -365,7 +365,7 @@ bool CheckSymbols::warning(AST *ast, const QString &text) const Token &lastToken = tokenAt(ast->lastToken() - 1); const unsigned length = lastToken.utf16charsEnd() - firstToken.utf16charsBegin(); - unsigned line = 1, column = 1; + int line = 1, column = 1; getTokenStartPosition(ast->firstToken(), &line, &column); warning(line, column, text, length); @@ -478,7 +478,7 @@ bool CheckSymbols::visit(NamespaceAST *ast) if (ast->identifier_token) { const Token &tok = tokenAt(ast->identifier_token); if (!tok.generated()) { - unsigned line, column; + int line, column; getTokenStartPosition(ast->identifier_token, &line, &column); Result use(line, column, tok.utf16chars(), SemanticHighlighter::TypeUse); addUse(use); @@ -786,7 +786,7 @@ void CheckSymbols::checkNamespace(NameAST *name) if (!name) return; - unsigned line, column; + int line, column; getTokenStartPosition(name->firstToken(), &line, &column); if (ClassOrNamespace *b = _context.lookupType(name->name, enclosingScope())) { @@ -1184,7 +1184,7 @@ void CheckSymbols::addUse(unsigned tokenIndex, Kind kind) if (tok.generated()) return; - unsigned line, column; + int line, column; getTokenStartPosition(tokenIndex, &line, &column); const unsigned length = tok.utf16chars(); @@ -1221,7 +1221,7 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast) if (tok.generated()) return; - unsigned line, column; + int line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); const Result use(line, column, length, SemanticHighlighter::TypeUse); @@ -1263,7 +1263,7 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam c->isClass() || c->isEnum() || isTemplateClass(c) || c->isForwardClassDeclaration() || c->isTypenameArgument() || c->enclosingEnum() != nullptr) { - unsigned line, column; + int line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); @@ -1305,7 +1305,7 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a else if (c->isTypedef() || (c->type() && c->type()->isFunctionType())) return false; // shadowed - unsigned line, column; + int line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); @@ -1319,9 +1319,9 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a } bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST *ast, - unsigned argumentCount, FunctionKind functionKind) + int argumentCount, FunctionKind functionKind) { - unsigned startToken = ast->firstToken(); + int startToken = ast->firstToken(); bool isDestructor = false; bool isConstructor = false; if (DestructorNameAST *dtor = ast->asDestructorName()) { @@ -1399,7 +1399,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST return false; } - unsigned line, column; + int line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); diff --git a/src/plugins/cpptools/cppchecksymbols.h b/src/plugins/cpptools/cppchecksymbols.h index 9a686c2995..fa1229977d 100644 --- a/src/plugins/cpptools/cppchecksymbols.h +++ b/src/plugins/cpptools/cppchecksymbols.h @@ -132,7 +132,7 @@ protected: bool maybeAddField(const QList<CPlusPlus::LookupItem> &candidates, CPlusPlus::NameAST *ast); bool maybeAddFunction(const QList<CPlusPlus::LookupItem> &candidates, - CPlusPlus::NameAST *ast, unsigned argumentCount, + CPlusPlus::NameAST *ast, int argumentCount, FunctionKind functionKind); bool isTemplateClass(CPlusPlus::Symbol *s) const; @@ -201,7 +201,7 @@ private: QVector<Result> _usages; QList<CPlusPlus::Document::DiagnosticMessage> _diagMsgs; int _chunkSize; - unsigned _lineOfLastUsage; + int _lineOfLastUsage; QList<Result> _macroUses; }; diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 069359d869..fca7998ece 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -1054,6 +1054,8 @@ int CodeFormatter::tokenizeBlock(const QTextBlock &block, bool *endedJoined) features.qtKeywordsEnabled = true; features.cxxEnabled = true; features.objCEnabled = true; + features.cxx11Enabled = true; + features.cxx14Enabled = true; SimpleLexer tokenize; tokenize.setLanguageFeatures(features); diff --git a/src/plugins/cpptools/cppcodegen_test.cpp b/src/plugins/cpptools/cppcodegen_test.cpp index 01d8973904..088e55c9de 100644 --- a/src/plugins/cpptools/cppcodegen_test.cpp +++ b/src/plugins/cpptools/cppcodegen_test.cpp @@ -45,7 +45,7 @@ using namespace CppTools::Internal; namespace { Document::Ptr createDocument(const QString &filePath, const QByteArray &text, - unsigned expectedGlobalSymbolCount) + int expectedGlobalSymbolCount) { Document::Ptr document = Document::create(filePath); document->setUtf8Source(text); @@ -59,7 +59,7 @@ Document::Ptr createDocument(const QString &filePath, const QByteArray &text, Document::Ptr createDocumentAndFile(Tests::TemporaryDir *temporaryDir, const QByteArray relativeFilePath, const QByteArray text, - unsigned expectedGlobalSymbolCount) + int expectedGlobalSymbolCount) { QTC_ASSERT(temporaryDir, return Document::Ptr()); const QString absoluteFilePath = temporaryDir->createFile(relativeFilePath, text); @@ -80,13 +80,13 @@ void CppToolsPlugin::test_codegen_public_in_empty_class() "{\n" "};\n" "\n"; - Document::Ptr doc = createDocument(QLatin1String("public_in_empty_class"), src, 1U); + Document::Ptr doc = createDocument(QLatin1String("public_in_empty_class"), src, 1); QVERIFY(doc); Class *foo = doc->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -99,8 +99,8 @@ void CppToolsPlugin::test_codegen_public_in_empty_class() QVERIFY(loc.isValid()); QCOMPARE(loc.prefix(), QLatin1String("public:\n")); QVERIFY(loc.suffix().isEmpty()); - QCOMPARE(loc.line(), 3U); - QCOMPARE(loc.column(), 1U); + QCOMPARE(loc.line(), 3); + QCOMPARE(loc.column(), 1); } /*! @@ -114,13 +114,13 @@ void CppToolsPlugin::test_codegen_public_in_nonempty_class() "public:\n" // line 3 "};\n" // line 4 "\n"; - Document::Ptr doc = createDocument(QLatin1String("public_in_nonempty_class"), src, 1U); + Document::Ptr doc = createDocument(QLatin1String("public_in_nonempty_class"), src, 1); QVERIFY(doc); Class *foo = doc->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -133,8 +133,8 @@ void CppToolsPlugin::test_codegen_public_in_nonempty_class() QVERIFY(loc.isValid()); QVERIFY(loc.prefix().isEmpty()); QVERIFY(loc.suffix().isEmpty()); - QCOMPARE(loc.line(), 4U); - QCOMPARE(loc.column(), 1U); + QCOMPARE(loc.line(), 4); + QCOMPARE(loc.column(), 1); } /*! @@ -148,13 +148,13 @@ void CppToolsPlugin::test_codegen_public_before_protected() "protected:\n" // line 3 "};\n" "\n"; - Document::Ptr doc = createDocument(QLatin1String("public_before_protected"), src, 1U); + Document::Ptr doc = createDocument(QLatin1String("public_before_protected"), src, 1); QVERIFY(doc); Class *foo = doc->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -167,8 +167,8 @@ void CppToolsPlugin::test_codegen_public_before_protected() QVERIFY(loc.isValid()); QCOMPARE(loc.prefix(), QLatin1String("public:\n")); QCOMPARE(loc.suffix(), QLatin1String("\n")); - QCOMPARE(loc.column(), 1U); - QCOMPARE(loc.line(), 3U); + QCOMPARE(loc.column(), 1); + QCOMPARE(loc.line(), 3); } /*! @@ -183,13 +183,13 @@ void CppToolsPlugin::test_codegen_private_after_protected() "protected:\n" // line 3 "};\n" "\n"; - Document::Ptr doc = createDocument(QLatin1String("private_after_protected"), src, 1U); + Document::Ptr doc = createDocument(QLatin1String("private_after_protected"), src, 1); QVERIFY(doc); Class *foo = doc->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -202,8 +202,8 @@ void CppToolsPlugin::test_codegen_private_after_protected() QVERIFY(loc.isValid()); QCOMPARE(loc.prefix(), QLatin1String("private:\n")); QVERIFY(loc.suffix().isEmpty()); - QCOMPARE(loc.column(), 1U); - QCOMPARE(loc.line(), 4U); + QCOMPARE(loc.column(), 1); + QCOMPARE(loc.line(), 4); } /*! @@ -218,13 +218,13 @@ void CppToolsPlugin::test_codegen_protected_in_nonempty_class() "public:\n" // line 3 "};\n" // line 4 "\n"; - Document::Ptr doc = createDocument(QLatin1String("protected_in_nonempty_class"), src, 1U); + Document::Ptr doc = createDocument(QLatin1String("protected_in_nonempty_class"), src, 1); QVERIFY(doc); Class *foo = doc->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -237,8 +237,8 @@ void CppToolsPlugin::test_codegen_protected_in_nonempty_class() QVERIFY(loc.isValid()); QCOMPARE(loc.prefix(), QLatin1String("protected:\n")); QVERIFY(loc.suffix().isEmpty()); - QCOMPARE(loc.column(), 1U); - QCOMPARE(loc.line(), 4U); + QCOMPARE(loc.column(), 1); + QCOMPARE(loc.line(), 4); } /*! @@ -253,13 +253,13 @@ void CppToolsPlugin::test_codegen_protected_between_public_and_private() "private:\n" // line 4 "};\n" // line 5 "\n"; - Document::Ptr doc = createDocument(QLatin1String("protected_betwee_public_and_private"), src, 1U); + Document::Ptr doc = createDocument(QLatin1String("protected_betwee_public_and_private"), src, 1); QVERIFY(doc); Class *foo = doc->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -272,8 +272,8 @@ void CppToolsPlugin::test_codegen_protected_between_public_and_private() QVERIFY(loc.isValid()); QCOMPARE(loc.prefix(), QLatin1String("protected:\n")); QCOMPARE(loc.suffix(), QLatin1String("\n")); - QCOMPARE(loc.column(), 1U); - QCOMPARE(loc.line(), 4U); + QCOMPARE(loc.column(), 1); + QCOMPARE(loc.line(), 4); } /*! @@ -309,13 +309,13 @@ void CppToolsPlugin::test_codegen_qtdesigner_integration() "\n" "#endif // MAINWINDOW_H\n"; - Document::Ptr doc = createDocument(QLatin1String("qtdesigner_integration"), src, 2U); + Document::Ptr doc = createDocument(QLatin1String("qtdesigner_integration"), src, 2); QVERIFY(doc); Class *foo = doc->globalSymbolAt(1)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 10U); - QCOMPARE(foo->column(), 7U); + QCOMPARE(foo->line(), 10); + QCOMPARE(foo->column(), 7); Snapshot snapshot; snapshot.insert(doc); @@ -328,8 +328,8 @@ void CppToolsPlugin::test_codegen_qtdesigner_integration() QVERIFY(loc.isValid()); QCOMPARE(loc.prefix(), QLatin1String("private slots:\n")); QCOMPARE(loc.suffix(), QLatin1String("\n")); - QCOMPARE(loc.line(), 18U); - QCOMPARE(loc.column(), 1U); + QCOMPARE(loc.line(), 18); + QCOMPARE(loc.column(), 1); } void CppToolsPlugin::test_codegen_definition_empty_class() @@ -343,13 +343,13 @@ void CppToolsPlugin::test_codegen_definition_empty_class() "void foo();\n" // line 3 "};\n" "\n"; - Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1U); + Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1); QVERIFY(headerDocument); const QByteArray sourceText = "\n" "int x;\n" // line 1 "\n"; - Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 1U); + Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 1); QVERIFY(sourceDocument); Snapshot snapshot; @@ -358,13 +358,13 @@ void CppToolsPlugin::test_codegen_definition_empty_class() Class *foo = headerDocument->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); - QCOMPARE(foo->memberCount(), 1U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); + QCOMPARE(foo->memberCount(), 1); Declaration *decl = foo->memberAt(0)->asDeclaration(); QVERIFY(decl); - QCOMPARE(decl->line(), 3U); - QCOMPARE(decl->column(), 6U); + QCOMPARE(decl->line(), 3); + QCOMPARE(decl->column(), 6); CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); @@ -374,8 +374,8 @@ void CppToolsPlugin::test_codegen_definition_empty_class() QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.suffix(), QString()); - QCOMPARE(loc.line(), 3U); - QCOMPARE(loc.column(), 1U); + QCOMPARE(loc.line(), 3); + QCOMPARE(loc.column(), 1); } void CppToolsPlugin::test_codegen_definition_first_member() @@ -390,7 +390,7 @@ void CppToolsPlugin::test_codegen_definition_first_member() "void bar();\n" // line 4 "};\n" "\n"; - Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1U); + Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1); QVERIFY(headerDocument); const QByteArray sourceText = QString::fromLatin1( @@ -404,7 +404,7 @@ void CppToolsPlugin::test_codegen_definition_first_member() "}\n" "\n" "int y;\n").arg(temporaryDir.path()).toLatin1(); - Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3U); + Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), headerDocument->fileName(), 1, @@ -416,13 +416,13 @@ void CppToolsPlugin::test_codegen_definition_first_member() Class *foo = headerDocument->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); - QCOMPARE(foo->memberCount(), 2U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); + QCOMPARE(foo->memberCount(), 2); Declaration *decl = foo->memberAt(0)->asDeclaration(); QVERIFY(decl); - QCOMPARE(decl->line(), 3U); - QCOMPARE(decl->column(), 6U); + QCOMPARE(decl->line(), 3); + QCOMPARE(decl->column(), 6); CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); @@ -430,8 +430,8 @@ void CppToolsPlugin::test_codegen_definition_first_member() QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); QCOMPARE(loc.fileName(), sourceDocument->fileName()); - QCOMPARE(loc.line(), 4U); - QCOMPARE(loc.column(), 1U); + QCOMPARE(loc.line(), 4); + QCOMPARE(loc.column(), 1); QCOMPARE(loc.suffix(), QLatin1String("\n\n")); QCOMPARE(loc.prefix(), QString()); } @@ -448,7 +448,7 @@ void CppToolsPlugin::test_codegen_definition_last_member() "void bar();\n" // line 4 "};\n" "\n"; - Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1U); + Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1); QVERIFY(headerDocument); const QByteArray sourceText = QString::fromLatin1( @@ -463,7 +463,7 @@ void CppToolsPlugin::test_codegen_definition_last_member() "\n" "int y;\n").arg(temporaryDir.path()).toLatin1(); - Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3U); + Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), headerDocument->fileName(), 1, @@ -475,13 +475,13 @@ void CppToolsPlugin::test_codegen_definition_last_member() Class *foo = headerDocument->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); - QCOMPARE(foo->memberCount(), 2U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); + QCOMPARE(foo->memberCount(), 2); Declaration *decl = foo->memberAt(1)->asDeclaration(); QVERIFY(decl); - QCOMPARE(decl->line(), 4U); - QCOMPARE(decl->column(), 6U); + QCOMPARE(decl->line(), 4); + QCOMPARE(decl->column(), 6); CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); @@ -489,8 +489,8 @@ void CppToolsPlugin::test_codegen_definition_last_member() QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); QCOMPARE(loc.fileName(), sourceDocument->fileName()); - QCOMPARE(loc.line(), 7U); - QCOMPARE(loc.column(), 2U); + QCOMPARE(loc.line(), 7); + QCOMPARE(loc.column(), 2); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.suffix(), QString()); } @@ -509,7 +509,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member() "};\n" "\n"; - Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1U); + Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1); QVERIFY(headerDocument); const QByteArray sourceText = QString::fromLatin1( @@ -529,7 +529,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member() "\n" "int y;\n").arg(Utils::TemporaryDirectory::masterDirectoryPath()).toLatin1(); - Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 4U); + Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 4); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), headerDocument->fileName(), 1, @@ -541,13 +541,13 @@ void CppToolsPlugin::test_codegen_definition_middle_member() Class *foo = headerDocument->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); - QCOMPARE(foo->memberCount(), 3U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); + QCOMPARE(foo->memberCount(), 3); Declaration *decl = foo->memberAt(1)->asDeclaration(); QVERIFY(decl); - QCOMPARE(decl->line(), 4U); - QCOMPARE(decl->column(), 6U); + QCOMPARE(decl->line(), 4); + QCOMPARE(decl->column(), 6); CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); @@ -555,8 +555,8 @@ void CppToolsPlugin::test_codegen_definition_middle_member() QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); QCOMPARE(loc.fileName(), sourceDocument->fileName()); - QCOMPARE(loc.line(), 7U); - QCOMPARE(loc.column(), 2U); + QCOMPARE(loc.line(), 7); + QCOMPARE(loc.column(), 2); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.suffix(), QString()); } @@ -575,7 +575,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin "void car();\n" // line 6 "};\n" "\n"; - Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1U); + Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 1); QVERIFY(headerDocument); const QByteArray sourceText = QString::fromLatin1( @@ -589,7 +589,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin "}\n" "\n" "int y;\n").arg(temporaryDir.path()).toLatin1(); - Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3U); + Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), headerDocument->fileName(), 1, @@ -601,13 +601,13 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin Class *foo = headerDocument->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); - QCOMPARE(foo->memberCount(), 4U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); + QCOMPARE(foo->memberCount(), 4); Declaration *decl = foo->memberAt(1)->asDeclaration(); QVERIFY(decl); - QCOMPARE(decl->line(), 4U); - QCOMPARE(decl->column(), 6U); + QCOMPARE(decl->line(), 4); + QCOMPARE(decl->column(), 6); CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); @@ -615,8 +615,8 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); QCOMPARE(loc.fileName(), sourceDocument->fileName()); - QCOMPARE(loc.line(), 4U); - QCOMPARE(loc.column(), 1U); + QCOMPARE(loc.line(), 4); + QCOMPARE(loc.column(), 1); QCOMPARE(loc.prefix(), QString()); QCOMPARE(loc.suffix(), QLatin1String("\n\n")); } @@ -638,7 +638,7 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file() "{\n" "\n" "}\n"; - Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 2U); + Document::Ptr headerDocument = createDocumentAndFile(&temporaryDir, "file.h", headerText, 2); QVERIFY(headerDocument); const QByteArray sourceText = QString::fromLatin1( @@ -652,7 +652,7 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file() "}\n" // line 7 "\n" "int y;\n").arg(temporaryDir.path()).toLatin1(); - Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3U); + Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), headerDocument->fileName(), 1, @@ -664,13 +664,13 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file() Class *foo = headerDocument->globalSymbolAt(0)->asClass(); QVERIFY(foo); - QCOMPARE(foo->line(), 1U); - QCOMPARE(foo->column(), 7U); - QCOMPARE(foo->memberCount(), 3U); + QCOMPARE(foo->line(), 1); + QCOMPARE(foo->column(), 7); + QCOMPARE(foo->memberCount(), 3); Declaration *decl = foo->memberAt(2)->asDeclaration(); QVERIFY(decl); - QCOMPARE(decl->line(), 5U); - QCOMPARE(decl->column(), 6U); + QCOMPARE(decl->line(), 5); + QCOMPARE(decl->column(), 6); CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); @@ -678,8 +678,8 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file() QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); QCOMPARE(loc.fileName(), sourceDocument->fileName()); - QCOMPARE(loc.line(), 7U); - QCOMPARE(loc.column(), 2U); + QCOMPARE(loc.line(), 7); + QCOMPARE(loc.column(), 2); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.suffix(), QString()); } diff --git a/src/plugins/cpptools/cppcodemodelinspectordumper.cpp b/src/plugins/cpptools/cppcodemodelinspectordumper.cpp index efde14abc4..0907db98c6 100644 --- a/src/plugins/cpptools/cppcodemodelinspectordumper.cpp +++ b/src/plugins/cpptools/cppcodemodelinspectordumper.cpp @@ -53,6 +53,11 @@ QString Utils::toString(bool value) return value ? QLatin1String("Yes") : QLatin1String("No"); } +QString Utils::toString(int value) +{ + return QString::number(value); +} + QString Utils::toString(unsigned value) { return QString::number(value); @@ -143,23 +148,27 @@ QString Utils::toString(::Utils::LanguageExtensions languageExtension) return result; } -QString Utils::toString(ProjectPart::QtVersion qtVersion) +QString Utils::toString(::Utils::QtVersion qtVersion) { -#define CASE_QTVERSION(x) case ProjectPart::x: return QLatin1String(#x) +#define CASE_QTVERSION(x) \ + case ::Utils::QtVersion::x: \ + return QLatin1String(#x) switch (qtVersion) { - CASE_QTVERSION(UnknownQt); - CASE_QTVERSION(NoQt); - CASE_QTVERSION(Qt4); - CASE_QTVERSION(Qt5); - // no default to get a compiler warning if anything is added + CASE_QTVERSION(Unknown); + CASE_QTVERSION(None); + CASE_QTVERSION(Qt4); + CASE_QTVERSION(Qt5); + // no default to get a compiler warning if anything is added } #undef CASE_QTVERSION return QString(); } -QString Utils::toString(ProjectPart::BuildTargetType buildTargetType) +QString Utils::toString(ProjectExplorer::BuildTargetType buildTargetType) { -#define CASE_BUILDTARGETTYPE(x) case ProjectPart::x: return QLatin1String(#x) +#define CASE_BUILDTARGETTYPE(x) \ + case ProjectExplorer::BuildTargetType::x: \ + return QLatin1String(#x) switch (buildTargetType) { CASE_BUILDTARGETTYPE(Unknown); CASE_BUILDTARGETTYPE(Executable); @@ -613,9 +622,8 @@ void Dumper::dumpWorkingCopy(const WorkingCopy &workingCopy) m_out << "Working Copy contains " << workingCopy.size() << " entries{{{1\n"; const QByteArray i1 = indent(1); - QHashIterator< ::Utils::FilePath, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); - while (it.hasNext()) { - it.next(); + const WorkingCopy::Table &elements = workingCopy.elements(); + for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) { const ::Utils::FilePath &filePath = it.key(); unsigned sourcRevision = it.value().second; m_out << i1 << "rev=" << sourcRevision << ", " << filePath << "\n"; diff --git a/src/plugins/cpptools/cppcodemodelinspectordumper.h b/src/plugins/cpptools/cppcodemodelinspectordumper.h index 41d294e817..c7769315c1 100644 --- a/src/plugins/cpptools/cppcodemodelinspectordumper.h +++ b/src/plugins/cpptools/cppcodemodelinspectordumper.h @@ -42,6 +42,7 @@ namespace CppCodeModelInspector { struct CPPTOOLS_EXPORT Utils { static QString toString(bool value); + static QString toString(int value); static QString toString(unsigned value); static QString toString(const QDateTime &dateTime); static QString toString(CPlusPlus::Document::CheckMode checkMode); @@ -49,8 +50,8 @@ struct CPPTOOLS_EXPORT Utils static QString toString(ProjectExplorer::HeaderPathType type); static QString toString(::Utils::LanguageVersion languageVersion); static QString toString(::Utils::LanguageExtensions languageExtension); - static QString toString(CppTools::ProjectPart::QtVersion qtVersion); - static QString toString(CppTools::ProjectPart::BuildTargetType buildTargetType); + static QString toString(::Utils::QtVersion qtVersion); + static QString toString(ProjectExplorer::BuildTargetType buildTargetType); static QString toString(const QVector<CppTools::ProjectFile> &projectFiles); static QString toString(CppTools::ProjectFile::Kind kind); static QString toString(CPlusPlus::Kind kind); diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.cpp b/src/plugins/cpptools/cppcodemodelsettingspage.cpp index af5f6b1fd2..0cd52a5228 100644 --- a/src/plugins/cpptools/cppcodemodelsettingspage.cpp +++ b/src/plugins/cpptools/cppcodemodelsettingspage.cpp @@ -41,9 +41,8 @@ using namespace CppTools; using namespace CppTools::Internal; -CppCodeModelSettingsWidget::CppCodeModelSettingsWidget(QWidget *parent) - : QWidget(parent) - , m_ui(new Ui::CppCodeModelSettingsPage) +CppCodeModelSettingsWidget::CppCodeModelSettingsWidget() + : m_ui(new Ui::CppCodeModelSettingsPage) { m_ui->setupUi(this); m_ui->expensiveChecksHintIcon->setPixmap(Utils::Icons::WARNING.pixmap()); @@ -184,17 +183,16 @@ bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const return settingsChanged; } -CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings, - QObject *parent) - : Core::IOptionsPage(parent) - , m_settings(settings) +CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings) + : m_settings(settings) { setId(Constants::CPP_CODE_MODEL_SETTINGS_ID); setDisplayName(QCoreApplication::translate("CppTools",Constants::CPP_CODE_MODEL_SETTINGS_NAME)); setCategory(Constants::CPP_SETTINGS_CATEGORY); setDisplayCategory(QCoreApplication::translate("CppTools", "C++")); - setCategoryIcon(Utils::Icon({{":/cpptools/images/settingscategory_cpp.png", - Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint)); + setCategoryIcon(Utils::Icon({{":/projectexplorer/images/settingscategory_cpp.png", + Utils::Theme::PanelTextColorDark}}, + Utils::Icon::Tint)); } QWidget *CppCodeModelSettingsPage::widget() diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.h b/src/plugins/cpptools/cppcodemodelsettingspage.h index 5ccb5fb37f..4f0722a805 100644 --- a/src/plugins/cpptools/cppcodemodelsettingspage.h +++ b/src/plugins/cpptools/cppcodemodelsettingspage.h @@ -46,7 +46,7 @@ class CppCodeModelSettingsWidget: public QWidget Q_OBJECT public: - explicit CppCodeModelSettingsWidget(QWidget *parent = nullptr); + CppCodeModelSettingsWidget(); ~CppCodeModelSettingsWidget() override; void setSettings(const QSharedPointer<CppCodeModelSettings> &s); @@ -67,8 +67,7 @@ private: class CppCodeModelSettingsPage: public Core::IOptionsPage { public: - explicit CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings, - QObject *parent = nullptr); + explicit CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings); QWidget *widget() override; void apply() override; diff --git a/src/plugins/cpptools/cppcodestylepreferencesfactory.cpp b/src/plugins/cpptools/cppcodestylepreferencesfactory.cpp index 4c0ca8d9a5..0146af8336 100644 --- a/src/plugins/cpptools/cppcodestylepreferencesfactory.cpp +++ b/src/plugins/cpptools/cppcodestylepreferencesfactory.cpp @@ -106,7 +106,7 @@ QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePref if (!cppPreferences) return nullptr; auto widget = new Internal::CppCodeStylePreferencesWidget(parent); - widget->layout()->setMargin(0); + widget->layout()->setContentsMargins(0, 0, 0, 0); widget->setCodeStyle(cppPreferences); return widget; } diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index b51f833afe..0a7624576a 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -1203,7 +1203,7 @@ void InternalCppCompletionAssistProcessor::completeObjCMsgSend(ClassOrNamespace } foreach (Scope *scope, memberScopes) { - for (unsigned i = 0; i < scope->memberCount(); ++i) { + for (int i = 0; i < scope->memberCount(); ++i) { Symbol *symbol = scope->memberAt(i); if (ObjCMethod *method = symbol->type()->asObjCMethodType()) { @@ -1214,7 +1214,7 @@ void InternalCppCompletionAssistProcessor::completeObjCMsgSend(ClassOrNamespace QString text; QString data; if (selectorName->hasArguments()) { - for (unsigned i = 0; i < selectorName->nameCount(); ++i) { + for (int i = 0; i < selectorName->nameCount(); ++i) { if (i > 0) text += QLatin1Char(' '); Symbol *arg = method->argumentAt(i); @@ -1320,8 +1320,8 @@ bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const } int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString &fileName, - unsigned line, - unsigned positionInBlock, + int line, + int positionInBlock, const QString &expr, int endOfExpression) { @@ -1467,7 +1467,7 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope) for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) { if (Block *block = scope->asBlock()) { if (ClassOrNamespace *binding = context.lookupType(scope)) { - for (unsigned i = 0; i < scope->memberCount(); ++i) { + for (int i = 0; i < scope->memberCount(); ++i) { Symbol *member = scope->memberAt(i); if (member->isEnum()) { if (ClassOrNamespace *b = binding->findBlock(block)) @@ -1494,13 +1494,13 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope) for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) { if (scope->isBlock()) { - for (unsigned i = 0; i < scope->memberCount(); ++i) + for (int i = 0; i < scope->memberCount(); ++i) addCompletionItem(scope->memberAt(i), FunctionLocalsOrder); } else if (Function *fun = scope->asFunction()) { - for (unsigned i = 0, argc = fun->argumentCount(); i < argc; ++i) + for (int i = 0, argc = fun->argumentCount(); i < argc; ++i) addCompletionItem(fun->argumentAt(i), FunctionArgumentsOrder); } else if (Template *templ = scope->asTemplate()) { - for (unsigned i = 0, argc = templ->templateParameterCount(); i < argc; ++i) + for (int i = 0, argc = templ->templateParameterCount(); i < argc; ++i) addCompletionItem(templ->templateParameterAt(i), FunctionArgumentsOrder); break; } @@ -1799,7 +1799,7 @@ bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupIt if (!klass) continue; - for (unsigned i = 0; i < scope->memberCount(); ++i) { + for (int i = 0; i < scope->memberCount(); ++i) { Symbol *member = scope->memberAt(i); Function *fun = member->type()->asFunctionType(); if (!fun || fun->isGenerated()) @@ -1809,7 +1809,7 @@ bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupIt else if (!wantSignals && type == CompleteQt4Slots && !fun->isSlot()) continue; - unsigned count = fun->argumentCount(); + int count = fun->argumentCount(); while (true) { const QString completionText = wantQt5SignalOrSlot ? createQt5SignalOrSlot(fun, o) @@ -1937,7 +1937,7 @@ bool InternalCppCompletionAssistProcessor::completeConstructorOrFunction(const Q if (!className) continue; // nothing to do for anonymous classes. - for (unsigned i = 0; i < klass->memberCount(); ++i) { + for (int i = 0; i < klass->memberCount(); ++i) { Symbol *member = klass->memberAt(i); const Name *memberName = member->name(); diff --git a/src/plugins/cpptools/cppcompletionassist.h b/src/plugins/cpptools/cppcompletionassist.h index 7213271263..5afdc43593 100644 --- a/src/plugins/cpptools/cppcompletionassist.h +++ b/src/plugins/cpptools/cppcompletionassist.h @@ -111,7 +111,7 @@ private: bool tryObjCCompletion(); bool objcKeywordsWanted() const; int startCompletionInternal(const QString &fileName, - unsigned line, unsigned positionInBlock, + int line, int positionInBlock, const QString &expression, int endOfExpression); diff --git a/src/plugins/cpptools/cppcursorinfo.h b/src/plugins/cpptools/cppcursorinfo.h index d9da2541d3..233fdeac26 100644 --- a/src/plugins/cpptools/cppcursorinfo.h +++ b/src/plugins/cpptools/cppcursorinfo.h @@ -46,16 +46,16 @@ class CPPTOOLS_EXPORT CursorInfo public: struct Range { Range() = default; - Range(unsigned line, unsigned column, unsigned length) + Range(int line, int column, int length) : line(line) , column(column) , length(length) { } - unsigned line = 0; // 1-based - unsigned column = 0; // 1-based - unsigned length = 0; + int line = 0; // 1-based + int column = 0; // 1-based + int length = 0; }; using Ranges = QVector<Range>; diff --git a/src/plugins/cpptools/cppelementevaluator.cpp b/src/plugins/cpptools/cppelementevaluator.cpp index 88ffc3c075..b59bf3380d 100644 --- a/src/plugins/cpptools/cppelementevaluator.cpp +++ b/src/plugins/cpptools/cppelementevaluator.cpp @@ -397,7 +397,7 @@ void CppElementEvaluator::checkDiagnosticMessage(int pos) } } -bool CppElementEvaluator::matchIncludeFile(const Document::Ptr &document, unsigned line) +bool CppElementEvaluator::matchIncludeFile(const Document::Ptr &document, int line) { foreach (const Document::Include &includeFile, document->resolvedIncludes()) { if (includeFile.line() == line) { @@ -408,11 +408,11 @@ bool CppElementEvaluator::matchIncludeFile(const Document::Ptr &document, unsign return false; } -bool CppElementEvaluator::matchMacroInUse(const Document::Ptr &document, unsigned pos) +bool CppElementEvaluator::matchMacroInUse(const Document::Ptr &document, int pos) { foreach (const Document::MacroUse &use, document->macroUses()) { if (use.containsUtf16charOffset(pos)) { - const unsigned begin = use.utf16charsBegin(); + const int begin = use.utf16charsBegin(); if (pos < begin + use.macro().nameToQString().size()) { m_element = QSharedPointer<CppElement>(new CppMacro(use.macro())); return true; diff --git a/src/plugins/cpptools/cppelementevaluator.h b/src/plugins/cpptools/cppelementevaluator.h index 13950a09cc..6ce518a2e1 100644 --- a/src/plugins/cpptools/cppelementevaluator.h +++ b/src/plugins/cpptools/cppelementevaluator.h @@ -65,8 +65,8 @@ public: private: void clear(); void checkDiagnosticMessage(int pos); - bool matchIncludeFile(const CPlusPlus::Document::Ptr &document, unsigned line); - bool matchMacroInUse(const CPlusPlus::Document::Ptr &document, unsigned pos); + bool matchIncludeFile(const CPlusPlus::Document::Ptr &document, int line); + bool matchMacroInUse(const CPlusPlus::Document::Ptr &document, int pos); void handleLookupItemMatch(const CPlusPlus::Snapshot &snapshot, const CPlusPlus::LookupItem &lookupItem, const CPlusPlus::LookupContext &lookupContext, diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp index 5ee5ef22cf..b6f7fb5720 100644 --- a/src/plugins/cpptools/cppfilesettingspage.cpp +++ b/src/plugins/cpptools/cppfilesettingspage.cpp @@ -252,8 +252,7 @@ QString CppFileSettings::licenseTemplate() // ------------------ CppFileSettingsWidget -CppFileSettingsWidget::CppFileSettingsWidget(QWidget *parent) : - QWidget(parent), +CppFileSettingsWidget::CppFileSettingsWidget() : m_ui(new Internal::Ui::CppFileSettingsPage) { m_ui->setupUi(this); @@ -351,9 +350,7 @@ void CppFileSettingsWidget::slotEdit() } // --------------- CppFileSettingsPage -CppFileSettingsPage::CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings, - QObject *parent) : - Core::IOptionsPage(parent), +CppFileSettingsPage::CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings) : m_settings(settings) { setId(Constants::CPP_FILE_SETTINGS_ID); @@ -363,7 +360,6 @@ CppFileSettingsPage::CppFileSettingsPage(QSharedPointer<CppFileSettings> &settin QWidget *CppFileSettingsPage::widget() { - if (!m_widget) { m_widget = new CppFileSettingsWidget; m_widget->setSettings(*m_settings); diff --git a/src/plugins/cpptools/cppfilesettingspage.h b/src/plugins/cpptools/cppfilesettingspage.h index 5375664828..4a88e5af5e 100644 --- a/src/plugins/cpptools/cppfilesettingspage.h +++ b/src/plugins/cpptools/cppfilesettingspage.h @@ -70,7 +70,7 @@ class CppFileSettingsWidget : public QWidget Q_OBJECT public: - explicit CppFileSettingsWidget(QWidget *parent = nullptr); + CppFileSettingsWidget(); ~CppFileSettingsWidget() override; CppFileSettings settings() const; @@ -87,8 +87,7 @@ private: class CppFileSettingsPage : public Core::IOptionsPage { public: - explicit CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings, - QObject *parent = nullptr); + explicit CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings); QWidget *widget() override; void apply() override; diff --git a/src/plugins/cpptools/cppfollowsymbolundercursor.cpp b/src/plugins/cpptools/cppfollowsymbolundercursor.cpp index 5ec6b572a2..9a66467951 100644 --- a/src/plugins/cpptools/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cpptools/cppfollowsymbolundercursor.cpp @@ -353,7 +353,7 @@ Link attemptFuncDeclDef(const QTextCursor &cursor, Snapshot snapshot, if (target) { result = target->toLink(); - unsigned startLine, startColumn, endLine, endColumn; + int startLine, startColumn, endLine, endColumn; document->translationUnit()->getTokenStartPosition(name->firstToken(), &startLine, &startColumn); document->translationUnit()->getTokenEndPosition(name->lastToken() - 1, &endLine, @@ -540,8 +540,7 @@ void FollowSymbolUnderCursor::findLink( for (int i = 0; i < tokens.size(); ++i) { const Token &tk = tokens.at(i); - if (static_cast<unsigned>(positionInBlock) >= tk.utf16charsBegin() - && static_cast<unsigned>(positionInBlock) < tk.utf16charsEnd()) { + if (positionInBlock >= tk.utf16charsBegin() && positionInBlock < tk.utf16charsEnd()) { int closingParenthesisPos = tokens.size(); if (i >= 2 && tokens.at(i).is(T_IDENTIFIER) && tokens.at(i - 1).is(T_LPAREN) && (tokens.at(i - 2).is(T_SIGNAL) || tokens.at(i - 2).is(T_SLOT))) { @@ -583,8 +582,7 @@ void FollowSymbolUnderCursor::findLink( // In this case we want to look at one token before the current position to recognize // an operator if the cursor is inside the actual operator: operator[$] - if (static_cast<unsigned>(positionInBlock) >= tk.utf16charsBegin() - && static_cast<unsigned>(positionInBlock) <= tk.utf16charsEnd()) { + if (positionInBlock >= tk.utf16charsBegin() && positionInBlock <= tk.utf16charsEnd()) { cursorRegionReached = true; if (tk.is(T_OPERATOR)) { link = attemptFuncDeclDef(cursor, theSnapshot, @@ -633,7 +631,7 @@ void FollowSymbolUnderCursor::findLink( // Handle include directives if (tk.is(T_STRING_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL)) { - const unsigned lineno = cursor.blockNumber() + 1; + const int lineno = cursor.blockNumber() + 1; foreach (const Document::Include &incl, doc->resolvedIncludes()) { if (incl.line() == lineno) { link.targetFileName = incl.resolvedFileName(); @@ -697,8 +695,7 @@ void FollowSymbolUnderCursor::findLink( if (d->isDeclaration() || d->isFunction()) { const QString fileName = QString::fromUtf8(d->fileName(), d->fileNameLength()); if (data.filePath().toString() == fileName) { - if (static_cast<unsigned>(line) == d->line() - && static_cast<unsigned>(positionInBlock) >= d->column()) { + if (line == d->line() && positionInBlock >= d->column()) { // TODO: check the end result = r; // take the symbol under cursor. break; @@ -709,9 +706,9 @@ void FollowSymbolUnderCursor::findLink( int tokenBeginColumnNumber = 0; Utils::Text::convertPosition(document, beginOfToken, &tokenBeginLineNumber, &tokenBeginColumnNumber); - if (static_cast<unsigned>(tokenBeginLineNumber) > d->line() - || (static_cast<unsigned>(tokenBeginLineNumber) == d->line() - && static_cast<unsigned>(tokenBeginColumnNumber) >= d->column())) { + if (tokenBeginLineNumber > d->line() + || (tokenBeginLineNumber == d->line() + && tokenBeginColumnNumber >= d->column())) { result = r; // take the symbol under cursor. break; } diff --git a/src/plugins/cpptools/cpphoverhandler.cpp b/src/plugins/cpptools/cpphoverhandler.cpp index 07617a411f..057a9de73f 100644 --- a/src/plugins/cpptools/cpphoverhandler.cpp +++ b/src/plugins/cpptools/cpphoverhandler.cpp @@ -62,7 +62,7 @@ void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, Rep const QSharedPointer<CppElement> &cppElement = evaluator.cppElement(); const QStringList candidates = cppElement->helpIdCandidates; const HelpItem helpItem(candidates + fallback, cppElement->helpMark, cppElement->helpCategory); - setLastHelpItemIdentified(helpItem); // tool tip appended by decorateToolTip + setLastHelpItemIdentified(helpItem); // tool tip appended by BaseHoverHandler::decorateToolTip if (!helpItem.isValid()) tip += cppElement->tooltip; } else { diff --git a/src/plugins/cpptools/cppincludesfilter.cpp b/src/plugins/cpptools/cppincludesfilter.cpp index 8a852fb7a5..f40763e052 100644 --- a/src/plugins/cpptools/cppincludesfilter.cpp +++ b/src/plugins/cpptools/cppincludesfilter.cpp @@ -37,9 +37,9 @@ #include <QTimer> using namespace Core; -using namespace CppTools; -using namespace CppTools::Internal; using namespace ProjectExplorer; +using namespace Utils; + namespace CppTools { namespace Internal { @@ -50,9 +50,8 @@ public: void toFront() override; bool hasNext() const override; - QString next() override; - QString filePath() const override; - QString fileName() const override; + Utils::FilePath next() override; + Utils::FilePath filePath() const override; private: void fetchMore(); @@ -62,13 +61,9 @@ private: QSet<QString> m_queuedPaths; QSet<QString> m_allResultPaths; QStringList m_resultQueue; - QString m_currentPath; + FilePath m_currentPath; }; -} // Internal -} // CppTools - - CppIncludesIterator::CppIncludesIterator(CPlusPlus::Snapshot snapshot, const QSet<QString> &seedPaths) : m_snapshot(snapshot), @@ -90,26 +85,21 @@ bool CppIncludesIterator::hasNext() const return !m_resultQueue.isEmpty(); } -QString CppIncludesIterator::next() +FilePath CppIncludesIterator::next() { if (m_resultQueue.isEmpty()) - return QString(); - m_currentPath = m_resultQueue.takeFirst(); + return {}; + m_currentPath = FilePath::fromString(m_resultQueue.takeFirst()); if (m_resultQueue.isEmpty()) fetchMore(); return m_currentPath; } -QString CppIncludesIterator::filePath() const +FilePath CppIncludesIterator::filePath() const { return m_currentPath; } -QString CppIncludesIterator::fileName() const -{ - return QFileInfo(m_currentPath).fileName(); -} - void CppIncludesIterator::fetchMore() { while (!m_queuedPaths.isEmpty() && m_resultQueue.isEmpty()) { @@ -160,7 +150,7 @@ void CppIncludesFilter::prepareSearch(const QString &entry) m_needsUpdate = false; QSet<QString> seedPaths; for (Project *project : SessionManager::projects()) { - const Utils::FilePathList allFiles = project->files(Project::AllFiles); + const Utils::FilePathList allFiles = project->files(Project::SourceFiles); for (const Utils::FilePath &filePath : allFiles ) seedPaths.insert(filePath.toString()); } @@ -186,3 +176,7 @@ void CppIncludesFilter::markOutdated() m_needsUpdate = true; setFileIterator(nullptr); // clean up } + +} // Internal +} // CppTools + diff --git a/src/plugins/cpptools/cppkitinfo.cpp b/src/plugins/cpptools/cppkitinfo.cpp deleted file mode 100644 index e57a4dbd73..0000000000 --- a/src/plugins/cpptools/cppkitinfo.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "cppkitinfo.h" - -#include <projectexplorer/kit.h> -#include <projectexplorer/kitinformation.h> -#include <projectexplorer/kitmanager.h> -#include <projectexplorer/project.h> -#include <projectexplorer/projectexplorerconstants.h> -#include <projectexplorer/target.h> - -#include <qtsupport/qtkitinformation.h> - -namespace CppTools { - -using namespace ProjectExplorer; - -KitInfo::KitInfo(Project *project) -{ - // Kit - if (Target *target = project->activeTarget()) - kit = target->kit(); - else - kit = KitManager::defaultKit(); - - // Toolchains - if (kit) { - cToolChain = ToolChainKitAspect::toolChain(kit, Constants::C_LANGUAGE_ID); - cxxToolChain = ToolChainKitAspect::toolChain(kit, Constants::CXX_LANGUAGE_ID); - } - - // Sysroot - sysRootPath = ProjectExplorer::SysRootKitAspect::sysRoot(kit).toString(); -} - -bool KitInfo::isValid() const -{ - return kit; -} - -} // namespace CppTools diff --git a/src/plugins/cpptools/cpplocalsymbols.cpp b/src/plugins/cpptools/cpplocalsymbols.cpp index feec5dc606..36ce87ce49 100644 --- a/src/plugins/cpptools/cpplocalsymbols.cpp +++ b/src/plugins/cpptools/cpplocalsymbols.cpp @@ -71,14 +71,14 @@ protected: { _scopeStack.append(scope); - for (unsigned i = 0; i < scope->memberCount(); ++i) { + for (int i = 0; i < scope->memberCount(); ++i) { if (Symbol *member = scope->memberAt(i)) { if (member->isTypedef()) continue; if (!member->isGenerated() && (member->isDeclaration() || member->isArgument())) { if (member->name() && member->name()->isNameId()) { const Token token = tokenAt(member->sourceLocation()); - unsigned line, column; + int line, column; getPosition(token.utf16charsBegin(), &line, &column); localUses[member].append( HighlightingResult(line, column, token.utf16chars(), @@ -89,7 +89,7 @@ protected: } } - bool checkLocalUse(NameAST *nameAst, unsigned firstToken) + bool checkLocalUse(NameAST *nameAst, int firstToken) { if (SimpleNameAST *simpleName = nameAst->asSimpleName()) { const Token token = tokenAt(simpleName->identifier_token); @@ -102,7 +102,7 @@ protected: continue; if (!member->isGenerated() && (member->sourceLocation() < firstToken || member->enclosingScope()->isFunction())) { - unsigned line, column; + int line, column; getTokenStartPosition(simpleName->identifier_token, &line, &column); localUses[member].append( HighlightingResult(line, column, token.utf16chars(), diff --git a/src/plugins/cpptools/cpplocalsymbols_test.cpp b/src/plugins/cpptools/cpplocalsymbols_test.cpp index 7ee8ad1723..7a21b1bc4d 100644 --- a/src/plugins/cpptools/cpplocalsymbols_test.cpp +++ b/src/plugins/cpptools/cpplocalsymbols_test.cpp @@ -93,9 +93,7 @@ struct Result { QList<Result> result; - CppTools::SemanticInfo::LocalUseIterator it(localUses); - while (it.hasNext()) { - it.next(); + for (auto it = localUses.cbegin(), end = localUses.cend(); it != end; ++it) { const CPlusPlus::Symbol *symbol = it.key(); const QList<CppTools::SemanticInfo::Use> &uses = it.value(); foreach (const CppTools::SemanticInfo::Use &use, uses) diff --git a/src/plugins/cpptools/cpplocatordata.cpp b/src/plugins/cpptools/cpplocatordata.cpp index d736736191..b1f0b22db8 100644 --- a/src/plugins/cpptools/cpplocatordata.cpp +++ b/src/plugins/cpptools/cpplocatordata.cpp @@ -44,16 +44,18 @@ void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document) { QMutexLocker locker(&m_pendingDocumentsMutex); - int i = 0, ei = m_pendingDocuments.size(); - for (; i < ei; ++i) { + bool isPending = false; + for (int i = 0, ei = m_pendingDocuments.size(); i < ei; ++i) { const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i); - if (doc->fileName() == document->fileName() && doc->revision() <= document->revision()) { - m_pendingDocuments[i] = document; + if (doc->fileName() == document->fileName()) { + isPending = true; + if (document->revision() >= doc->revision()) + m_pendingDocuments[i] = document; break; } } - if (i == ei && QFileInfo(document->fileName()).suffix() != "moc") + if (!isPending && QFileInfo(document->fileName()).suffix() != "moc") m_pendingDocuments.append(document); flushPendingDocument(false); @@ -101,10 +103,7 @@ QList<IndexItem::Ptr> CppLocatorData::allIndexItems( const QHash<QString, QList<IndexItem::Ptr>> &items) const { QList<IndexItem::Ptr> result; - QHashIterator<QString, QList<IndexItem::Ptr> > it(items); - while (it.hasNext()) { - it.next(); - result.append(it.value()); - } + for (const QList<IndexItem::Ptr> &subItems : items) + result.append(subItems); return result; } diff --git a/src/plugins/cpptools/cpplocatorfilter.cpp b/src/plugins/cpptools/cpplocatorfilter.cpp index 39965d3120..000091bde4 100644 --- a/src/plugins/cpptools/cpplocatorfilter.cpp +++ b/src/plugins/cpptools/cpplocatorfilter.cpp @@ -33,6 +33,7 @@ #include <QRegularExpression> #include <algorithm> +#include <numeric> using namespace CppTools; using namespace CppTools::Internal; @@ -68,16 +69,13 @@ void CppLocatorFilter::refresh(QFutureInterface<void> &future) QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor( QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) { - QList<Core::LocatorFilterEntry> normalEntries; - QList<Core::LocatorFilterEntry> goodEntries; - QList<Core::LocatorFilterEntry> betterEntries; - QList<Core::LocatorFilterEntry> bestEntries; + QList<Core::LocatorFilterEntry> entries[int(MatchLevel::Count)]; const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); const IndexItem::ItemType wanted = matchTypes(); const QRegularExpression regexp = createRegExp(entry); if (!regexp.isValid()) - return goodEntries; + return {}; const bool hasColonColon = entry.contains("::"); const QRegularExpression shortRegexp = hasColonColon ? createRegExp(entry.mid(entry.lastIndexOf("::") + 2)) : regexp; @@ -119,13 +117,13 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor( } if (matchInParameterList) - normalEntries.append(filterEntry); + entries[int(MatchLevel::Normal)].append(filterEntry); else if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix)) - bestEntries.append(filterEntry); + entries[int(MatchLevel::Best)].append(filterEntry); else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix)) - betterEntries.append(filterEntry); + entries[int(MatchLevel::Better)].append(filterEntry); else - goodEntries.append(filterEntry); + entries[int(MatchLevel::Good)].append(filterEntry); } } @@ -135,19 +133,12 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor( return IndexItem::Recurse; }); - if (normalEntries.size() < 1000) - Utils::sort(normalEntries, Core::LocatorFilterEntry::compareLexigraphically); - if (goodEntries.size() < 1000) - Utils::sort(goodEntries, Core::LocatorFilterEntry::compareLexigraphically); - if (betterEntries.size() < 1000) - Utils::sort(betterEntries, Core::LocatorFilterEntry::compareLexigraphically); - if (bestEntries.size() < 1000) - Utils::sort(bestEntries, Core::LocatorFilterEntry::compareLexigraphically); - - bestEntries += betterEntries; - bestEntries += goodEntries; - bestEntries += normalEntries; - return bestEntries; + for (auto &entry : entries) { + if (entry.size() < 1000) + Utils::sort(entry, Core::LocatorFilterEntry::compareLexigraphically); + } + + return std::accumulate(std::begin(entries), std::end(entries), QList<Core::LocatorFilterEntry>()); } void CppLocatorFilter::accept(Core::LocatorFilterEntry selection, diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp index 482c89b5b1..1b5e64feca 100644 --- a/src/plugins/cpptools/cpplocatorfilter_test.cpp +++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp @@ -54,8 +54,6 @@ const bool debug = qEnvironmentVariable("QTC_DEBUG_CPPLOCATORFILTERTESTCASE") == QTC_DECLARE_MYTESTDATADIR("../../../tests/cpplocators/") -inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } - class CppLocatorFilterTestCase : public BasicLocatorFilterTest , public CppTools::Tests::TestCase @@ -95,14 +93,15 @@ class CppCurrentDocumentFilterTestCase { public: CppCurrentDocumentFilterTestCase(const QString &fileName, - const ResultDataList &expectedResults) + const ResultDataList &expectedResults, + const QString &searchText = QString()) : BasicLocatorFilterTest(CppTools::CppModelManager::instance()->currentDocumentFilter()) , m_fileName(fileName) { QVERIFY(succeededSoFar()); QVERIFY(!m_fileName.isEmpty()); - ResultDataList results = ResultData::fromFilterEntryList(matchesFor()); + ResultDataList results = ResultData::fromFilterEntryList(matchesFor(searchText)); if (debug) { ResultData::printFilterEntries(expectedResults, "Expected:"); ResultData::printFilterEntries(results, "Results:"); @@ -172,153 +171,153 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() QTest::newRow("CppFunctionsFilter") << testFile << cppFunctionsFilter - << _("function") - << (QList<ResultData>() - << ResultData(_("functionDefinedInClass(bool, int)"), _("MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("<anonymous namespace>::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), - _("<anonymous namespace>::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("myFunction(bool, int)"), testFileShort) - << ResultData(_("myFunction(bool, int)"), _("MyNamespace (file1.cpp)")) - << ResultData(_("myFunction(bool, int)"), _("<anonymous namespace> (file1.cpp)")) - ); + << "function" + << ResultDataList{ + ResultData("functionDefinedInClass(bool, int)", "MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "<anonymous namespace>::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", "MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", + "<anonymous namespace>::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClassAndNamespace(float)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("myFunction(bool, int)", testFileShort), + ResultData("myFunction(bool, int)", "MyNamespace (file1.cpp)"), + ResultData("myFunction(bool, int)", "<anonymous namespace> (file1.cpp)") + }; QTest::newRow("CppFunctionsFilter-Sorting") << testFile << cppFunctionsFilter - << _("pos") - << (QList<ResultData>() - << ResultData(_("positiveNumber()"), testFileShort) - << ResultData(_("somePositionWithin()"), testFileShort) - << ResultData(_("pointOfService()"), testFileShort) - << ResultData(_("matchArgument(Pos)"), testFileShort) - ); + << "pos" + << ResultDataList{ + ResultData("positiveNumber()", testFileShort), + ResultData("somePositionWithin()", testFileShort), + ResultData("pointOfService()", testFileShort), + ResultData("matchArgument(Pos)", testFileShort) + }; QTest::newRow("CppFunctionsFilter-arguments") - << testFile - << cppFunctionsFilter - << _("function*bool") - << (QList<ResultData>() - << ResultData(_("functionDefinedInClass(bool, int)"), - _("MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("<anonymous namespace>::MyClass (file1.cpp)")) - << ResultData(_("myFunction(bool, int)"), testFileShort) - << ResultData(_("myFunction(bool, int)"), _("MyNamespace (file1.cpp)")) - << ResultData(_("myFunction(bool, int)"), _("<anonymous namespace> (file1.cpp)")) - ); + << testFile + << cppFunctionsFilter + << "function*bool" + << ResultDataList{ + ResultData("functionDefinedInClass(bool, int)", + "MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "<anonymous namespace>::MyClass (file1.cpp)"), + ResultData("myFunction(bool, int)", testFileShort), + ResultData("myFunction(bool, int)", "MyNamespace (file1.cpp)"), + ResultData("myFunction(bool, int)", "<anonymous namespace> (file1.cpp)") + }; QTest::newRow("CppFunctionsFilter-WithNamespacePrefix") << testFile << cppFunctionsFilter - << _("mynamespace::") - << (QList<ResultData>() - << ResultData(_("MyClass()"), _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("myFunction(bool, int)"), _("MyNamespace (file1.cpp)")) - ); + << "mynamespace::" + << ResultDataList{ + ResultData("MyClass()", "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClassAndNamespace(float)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("myFunction(bool, int)", "MyNamespace (file1.cpp)"), + }; QTest::newRow("CppFunctionsFilter-WithClassPrefix") - << testFile - << cppFunctionsFilter - << _("MyClass::func") - << (QList<ResultData>() - << ResultData(_("functionDefinedInClass(bool, int)"), - _("MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedInClass(bool, int)"), - _("<anonymous namespace>::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), - _("MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), - _("MyNamespace::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClass(char)"), - _("<anonymous namespace>::MyClass (file1.cpp)")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), - _("MyNamespace::MyClass (file1.cpp)")) - ); + << testFile + << cppFunctionsFilter + << "MyClass::func" + << ResultDataList{ + ResultData("functionDefinedInClass(bool, int)", + "MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedInClass(bool, int)", + "<anonymous namespace>::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", + "MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", + "MyNamespace::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClass(char)", + "<anonymous namespace>::MyClass (file1.cpp)"), + ResultData("functionDefinedOutSideClassAndNamespace(float)", + "MyNamespace::MyClass (file1.cpp)"), + }; QTest::newRow("CppClassesFilter") << testFile << cppClassesFilter - << _("myclass") - << (QList<ResultData>() - << ResultData(_("MyClass"), testFileShort) - << ResultData(_("MyClass"), _("MyNamespace")) - << ResultData(_("MyClass"), _("<anonymous namespace>")) - ); + << "myclass" + << ResultDataList{ + ResultData("MyClass", testFileShort), + ResultData("MyClass", "MyNamespace"), + ResultData("MyClass", "<anonymous namespace>") + }; QTest::newRow("CppClassesFilter-WithNamespacePrefix") << testFile << cppClassesFilter - << _("mynamespace::") - << (QList<ResultData>() - << ResultData(_("MyClass"), _("MyNamespace")) - ); + << "mynamespace::" + << ResultDataList{ + ResultData("MyClass", "MyNamespace") + }; // all symbols in the left column are expected to be fully qualified. QTest::newRow("CppLocatorFilter-filtered") << testFile << cppLocatorFilter - << _("my") - << (QList<ResultData>() - << ResultData(_("MyClass"), testFileShort) - << ResultData(_("MyClass::MyClass"), _("()")) - << ResultData(_("MyClass::functionDefinedOutSideClass"), _("(char)")) - << ResultData(_("MyEnum"), testFileShort) - << ResultData(_("MyNamespace::MyClass"), testFileShort) - << ResultData(_("MyNamespace::MyClass::MyClass"), _("()")) - << ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClass"), - _("(char)")) - << ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClassAndNamespace"), - _("(float)")) - << ResultData(_("MyNamespace::MyEnum"), testFileShort) - << ResultData(_("MyNamespace::myFunction"), _("(bool, int)")) - << ResultData(_("myFunction"), _("(bool, int)")) - << ResultData(_("<anonymous namespace>::MyClass"), testFileShort) - << ResultData(_("<anonymous namespace>::MyClass::MyClass"), _("()")) - << ResultData(_("<anonymous namespace>::MyClass::functionDefinedOutSideClass"), - _("(char)")) - << ResultData(_("<anonymous namespace>::MyEnum"), testFileShort) - << ResultData(_("<anonymous namespace>::myFunction"), _("(bool, int)")) - ); + << "my" + << ResultDataList{ + ResultData("MyClass", testFileShort), + ResultData("MyClass::MyClass", "()"), + ResultData("MyClass::functionDefinedOutSideClass", "(char)"), + ResultData("MyEnum", testFileShort), + ResultData("MyNamespace::MyClass", testFileShort), + ResultData("MyNamespace::MyClass::MyClass", "()"), + ResultData("MyNamespace::MyClass::functionDefinedOutSideClass", + "(char)"), + ResultData("MyNamespace::MyClass::functionDefinedOutSideClassAndNamespace", + "(float)"), + ResultData("MyNamespace::MyEnum", testFileShort), + ResultData("MyNamespace::myFunction", "(bool, int)"), + ResultData("myFunction", "(bool, int)"), + ResultData("<anonymous namespace>::MyClass", testFileShort), + ResultData("<anonymous namespace>::MyClass::MyClass", "()"), + ResultData("<anonymous namespace>::MyClass::functionDefinedOutSideClass", + "(char)"), + ResultData("<anonymous namespace>::MyEnum", testFileShort), + ResultData("<anonymous namespace>::myFunction", "(bool, int)") + }; QTest::newRow("CppClassesFilter-ObjC") - << objTestFile - << cppClassesFilter - << _("M") - << (QList<ResultData>() - << ResultData(_("MyClass"), objTestFileShort) - << ResultData(_("MyClass"), objTestFileShort) - << ResultData(_("MyClass"), objTestFileShort) - << ResultData(_("MyProtocol"), objTestFileShort) - ); + << objTestFile + << cppClassesFilter + << "M" + << ResultDataList{ + ResultData("MyClass", objTestFileShort), + ResultData("MyClass", objTestFileShort), + ResultData("MyClass", objTestFileShort), + ResultData("MyProtocol", objTestFileShort), + }; QTest::newRow("CppFunctionsFilter-ObjC") << objTestFile << cppFunctionsFilter - << _("M") - << (QList<ResultData>() - << ResultData(_("anotherMethod"), _("MyClass (file1.mm)")) - << ResultData(_("anotherMethod:"), _("MyClass (file1.mm)")) - << ResultData(_("someMethod"), _("MyClass (file1.mm)")) - ); + << "M" + << ResultDataList{ + ResultData("anotherMethod", "MyClass (file1.mm)"), + ResultData("anotherMethod:", "MyClass (file1.mm)"), + ResultData("someMethod", "MyClass (file1.mm)") + }; } void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter() @@ -326,51 +325,101 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter() MyTestDataDir testDirectory("testdata_basic"); const QString testFile = testDirectory.file("file1.cpp"); - QList<ResultData> expectedResults = QList<ResultData>() - << ResultData(_("int myVariable"), _("")) - << ResultData(_("myFunction(bool, int)"), _("")) - << ResultData(_("Pos"), _("")) - << ResultData(_("somePositionWithin()"), _("")) - << ResultData(_("pointOfService()"), _("")) - << ResultData(_("matchArgument(Pos)"), _("")) - << ResultData(_("positiveNumber()"), _("")) - << ResultData(_("MyEnum"), _("")) - << ResultData(_("int V1"), _("MyEnum")) - << ResultData(_("int V2"), _("MyEnum")) - << ResultData(_("MyClass"), _("")) - << ResultData(_("MyClass()"), _("MyClass")) - << ResultData(_("functionDeclaredOnly()"), _("MyClass")) - << ResultData(_("functionDefinedInClass(bool, int)"), _("MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass")) - << ResultData(_("int myVariable"), _("MyNamespace")) - << ResultData(_("myFunction(bool, int)"), _("MyNamespace")) - << ResultData(_("MyEnum"), _("MyNamespace")) - << ResultData(_("int V1"), _("MyNamespace::MyEnum")) - << ResultData(_("int V2"), _("MyNamespace::MyEnum")) - << ResultData(_("MyClass"), _("MyNamespace")) - << ResultData(_("MyClass()"), _("MyNamespace::MyClass")) - << ResultData(_("functionDeclaredOnly()"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedInClass(bool, int)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), - _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), - _("MyNamespace::MyClass")) - << ResultData(_("int myVariable"), _("<anonymous namespace>")) - << ResultData(_("myFunction(bool, int)"), _("<anonymous namespace>")) - << ResultData(_("MyEnum"), _("<anonymous namespace>")) - << ResultData(_("int V1"), _("<anonymous namespace>::MyEnum")) - << ResultData(_("int V2"), _("<anonymous namespace>::MyEnum")) - << ResultData(_("MyClass"), _("<anonymous namespace>")) - << ResultData(_("MyClass()"), _("<anonymous namespace>::MyClass")) - << ResultData(_("functionDeclaredOnly()"), _("<anonymous namespace>::MyClass")) - << ResultData(_("functionDefinedInClass(bool, int)"), _("<anonymous namespace>::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("<anonymous namespace>::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("<anonymous namespace>::MyClass")) - << ResultData(_("main()"), _("")) - ; + auto expectedResults = ResultDataList{ + ResultData("int myVariable", ""), + ResultData("myFunction(bool, int)", ""), + ResultData("Pos", ""), + ResultData("somePositionWithin()", ""), + ResultData("pointOfService()", ""), + ResultData("matchArgument(Pos)", ""), + ResultData("positiveNumber()", ""), + ResultData("MyEnum", ""), + ResultData("int V1", "MyEnum"), + ResultData("int V2", "MyEnum"), + ResultData("MyClass", ""), + ResultData("MyClass()", "MyClass"), + ResultData("functionDeclaredOnly()", "MyClass"), + ResultData("functionDefinedInClass(bool, int)", "MyClass"), + ResultData("functionDefinedOutSideClass(char)", "MyClass"), + ResultData("functionDefinedOutSideClass(char)", "MyClass"), + ResultData("int myVariable", "MyNamespace"), + ResultData("myFunction(bool, int)", "MyNamespace"), + ResultData("MyEnum", "MyNamespace"), + ResultData("int V1", "MyNamespace::MyEnum"), + ResultData("int V2", "MyNamespace::MyEnum"), + ResultData("MyClass", "MyNamespace"), + ResultData("MyClass()", "MyNamespace::MyClass"), + ResultData("functionDeclaredOnly()", "MyNamespace::MyClass"), + ResultData("functionDefinedInClass(bool, int)", "MyNamespace::MyClass"), + ResultData("functionDefinedOutSideClass(char)", "MyNamespace::MyClass"), + ResultData("functionDefinedOutSideClassAndNamespace(float)", + "MyNamespace::MyClass"), + ResultData("functionDefinedOutSideClass(char)", "MyNamespace::MyClass"), + ResultData("functionDefinedOutSideClassAndNamespace(float)", + "MyNamespace::MyClass"), + ResultData("int myVariable", "<anonymous namespace>"), + ResultData("myFunction(bool, int)", "<anonymous namespace>"), + ResultData("MyEnum", "<anonymous namespace>"), + ResultData("int V1", "<anonymous namespace>::MyEnum"), + ResultData("int V2", "<anonymous namespace>::MyEnum"), + ResultData("MyClass", "<anonymous namespace>"), + ResultData("MyClass()", "<anonymous namespace>::MyClass"), + ResultData("functionDeclaredOnly()", "<anonymous namespace>::MyClass"), + ResultData("functionDefinedInClass(bool, int)", "<anonymous namespace>::MyClass"), + ResultData("functionDefinedOutSideClass(char)", "<anonymous namespace>::MyClass"), + ResultData("functionDefinedOutSideClass(char)", "<anonymous namespace>::MyClass"), + ResultData("main()", ""), + }; CppCurrentDocumentFilterTestCase(testFile, expectedResults); } + +void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentHighlighting() +{ + MyTestDataDir testDirectory("testdata_basic"); + const QString testFile = testDirectory.file("file1.cpp"); + + const QString searchText = "pos"; + const ResultDataList expectedResults{ + ResultData("Pos", "", + "~~~"), + ResultData("pointOfService()", "", + "~ ~ ~ "), + ResultData("positiveNumber()", "", + "~~~ "), + ResultData("somePositionWithin()", "", + " ~~~ "), + ResultData("matchArgument(Pos)", "", + " ~~~ ") + }; + + Tests::VerifyCleanCppModelManager verify; + + CppCurrentDocumentFilterTestCase(testFile, expectedResults, searchText); +} + +void CppToolsPlugin::test_cpplocatorfilters_CppFunctionsFilterHighlighting() +{ + MyTestDataDir testDirectory("testdata_basic"); + const QString testFile = testDirectory.file("file1.cpp"); + const QString testFileShort = FilePath::fromString(testFile).shortNativePath(); + + const QString searchText = "pos"; + const ResultDataList expectedResults{ + ResultData("positiveNumber()", testFileShort, + "~~~ "), + ResultData("somePositionWithin()", testFileShort, + " ~~~ "), + ResultData("pointOfService()", testFileShort, + "~ ~ ~ "), + ResultData("matchArgument(Pos)", testFileShort, + " ~~~ ") + }; + + CppModelManager *cppModelManager = CppModelManager::instance(); + ILocatorFilter *filter = cppModelManager->functionsFilter(); + + Tests::VerifyCleanCppModelManager verify; + + CppLocatorFilterTestCase(filter, testFile, searchText, expectedResults); +} diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index ea083c8eb6..47c7df5bf9 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -52,15 +52,16 @@ #include "followsymbolinterface.h" #include <coreplugin/documentmanager.h> +#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/icore.h> -#include <coreplugin/vcsmanager.h> #include <coreplugin/progressmanager/progressmanager.h> -#include <coreplugin/editormanager/editormanager.h> -#include <texteditor/textdocument.h> +#include <coreplugin/vcsmanager.h> +#include <extensionsystem/pluginmanager.h> #include <projectexplorer/project.h> #include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectmacro.h> #include <projectexplorer/session.h> +#include <texteditor/textdocument.h> #include <utils/fileutils.h> #include <utils/hostosinfo.h> #include <utils/qtcassert.h> @@ -511,6 +512,10 @@ CppModelManager::CppModelManager() : CppModelManagerBase(nullptr) , d(new CppModelManagerPrivate) { + // Used for weak dependency in VcsBaseSubmitEditor + setObjectName("CppModelManager"); + ExtensionSystem::PluginManager::addObject(this); + d->m_indexingSupporter = nullptr; d->m_enableGC = true; @@ -561,6 +566,8 @@ CppModelManager::CppModelManager() CppModelManager::~CppModelManager() { + ExtensionSystem::PluginManager::removeObject(this); + delete d->m_internalIndexingSupport; delete d; } @@ -608,10 +615,7 @@ void CppModelManager::ensureUpdated() QStringList CppModelManager::internalProjectFiles() const { QStringList files; - QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(d->m_projectToProjectsInfo); - while (it.hasNext()) { - it.next(); - const ProjectInfo pinfo = it.value(); + for (const ProjectInfo &pinfo : d->m_projectToProjectsInfo) { foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) { foreach (const ProjectFile &file, part->files) files += file.path; @@ -624,10 +628,7 @@ QStringList CppModelManager::internalProjectFiles() const ProjectExplorer::HeaderPaths CppModelManager::internalHeaderPaths() const { ProjectExplorer::HeaderPaths headerPaths; - QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(d->m_projectToProjectsInfo); - while (it.hasNext()) { - it.next(); - const ProjectInfo pinfo = it.value(); + for (const ProjectInfo &pinfo : d->m_projectToProjectsInfo) { foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) { foreach (const ProjectExplorer::HeaderPath &path, part->headerPaths) { ProjectExplorer::HeaderPath hp(QDir::cleanPath(path.path), path.type); @@ -655,10 +656,7 @@ ProjectExplorer::Macros CppModelManager::internalDefinedMacros() const { ProjectExplorer::Macros macros; QSet<ProjectExplorer::Macro> alreadyIn; - QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(d->m_projectToProjectsInfo); - while (it.hasNext()) { - it.next(); - const ProjectInfo pinfo = it.value(); + for (const ProjectInfo &pinfo : d->m_projectToProjectsInfo) { for (const ProjectPart::Ptr &part : pinfo.projectParts()) { addUnique(part->toolChainMacros, macros, alreadyIn); addUnique(part->projectMacros, macros, alreadyIn); @@ -783,11 +781,8 @@ WorkingCopy CppModelManager::buildWorkingCopyList() cppEditorDocument->revision()); } - QSetIterator<AbstractEditorSupport *> it(d->m_extraEditorSupports); - while (it.hasNext()) { - AbstractEditorSupport *es = it.next(); + for (AbstractEditorSupport *es : qAsConst(d->m_extraEditorSupports)) workingCopy.insert(es->fileName(), es->contents(), es->revision()); - } // Add the project configuration file QByteArray conf = codeModelConfiguration(); @@ -815,9 +810,7 @@ static QSet<QString> tooBigFilesRemoved(const QSet<QString> &files, int fileSize QSet<QString> result; QFileInfo fileInfo; - QSetIterator<QString> i(files); - while (i.hasNext()) { - const QString filePath = i.next(); + for (const QString &filePath : files) { fileInfo.setFile(filePath); if (fileSizeExceedsLimit(fileInfo, fileSizeLimitInMb)) continue; @@ -887,9 +880,8 @@ QList<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() const void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove) { QMutexLocker snapshotLocker(&d->m_snapshotMutex); - QSetIterator<QString> i(filesToRemove); - while (i.hasNext()) - d->m_snapshot.remove(i.next()); + for (const QString &file : filesToRemove) + d->m_snapshot.remove(file); } class ProjectInfoComparer @@ -935,9 +927,7 @@ public: commonSourceFiles.intersect(m_oldSourceFiles); QList<Document::Ptr> documentsToCheck; - QSetIterator<QString> i(commonSourceFiles); - while (i.hasNext()) { - const QString file = i.next(); + for (const QString &file : commonSourceFiles) { if (Document::Ptr document = snapshot.document(file)) documentsToCheck << document; } @@ -1169,7 +1159,7 @@ ProjectPart::Ptr CppModelManager::fallbackProjectPart() part->languageExtensions &= ~Utils::LanguageExtensions( Utils::LanguageExtension::ObjectiveC); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->updateLanguageFeatures(); return part; @@ -1322,6 +1312,60 @@ void CppModelManager::renameIncludes(const QString &oldFileName, const QString & } } +// Return the class name which function belongs to +static const char *belongingClassName(const Function *function) +{ + if (!function) + return nullptr; + + if (auto funcName = function->name()) { + if (auto qualifiedNameId = funcName->asQualifiedNameId()) { + if (const Name *funcBaseName = qualifiedNameId->base()) { + if (auto identifier = funcBaseName->identifier()) + return identifier->chars(); + } + } + } + + return nullptr; +} + +QSet<QString> CppModelManager::symbolsInFiles(const QSet<Utils::FilePath> &files) const +{ + QSet<QString> uniqueSymbols; + const Snapshot cppSnapShot = snapshot(); + + // Iterate over the files and get interesting symbols + for (const Utils::FilePath &file : files) { + // Add symbols from the C++ code model + const CPlusPlus::Document::Ptr doc = cppSnapShot.document(file); + if (!doc.isNull() && doc->control()) { + const CPlusPlus::Control *ctrl = doc->control(); + CPlusPlus::Symbol **symPtr = ctrl->firstSymbol(); // Read-only + while (symPtr != ctrl->lastSymbol()) { + const CPlusPlus::Symbol *sym = *symPtr; + + const CPlusPlus::Identifier *symId = sym->identifier(); + // Add any class, function or namespace identifiers + if ((sym->isClass() || sym->isFunction() || sym->isNamespace()) && symId + && symId->chars()) { + uniqueSymbols.insert(QString::fromUtf8(symId->chars())); + } + + // Handle specific case : get "Foo" in "void Foo::function() {}" + if (sym->isFunction() && !sym->asFunction()->isDeclaration()) { + const char *className = belongingClassName(sym->asFunction()); + if (className) + uniqueSymbols.insert(QString::fromUtf8(className)); + } + + ++symPtr; + } + } + } + return uniqueSymbols; +} + void CppModelManager::onCoreAboutToClose() { Core::ProgressManager::cancelTasks(CppTools::Constants::TASK_INDEX); diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 9deaa2e392..8567de9c30 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -230,6 +230,9 @@ public: void renameIncludes(const QString &oldFileName, const QString &newFileName); + // for VcsBaseSubmitEditor + Q_INVOKABLE QSet<QString> symbolsInFiles(const QSet<Utils::FilePath> &files) const; + signals: /// Project data might be locked while this is emitted. void aboutToRemoveFiles(const QStringList &files); diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index 02586943da..73da04531f 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -108,7 +108,7 @@ public: projectInfo = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; foreach (const QString &file, projectFiles) { ProjectFile projectFile(file, ProjectFile::classify(file)); part->files.append(projectFile); @@ -184,7 +184,7 @@ void CppToolsPlugin::test_modelmanager_paths_are_clean() ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->projectMacros = {ProjectExplorer::Macro("OH_BEHAVE", "-1")}; part->headerPaths = {{testDataDir.includeDir(false), HeaderPathType::User}, {testDataDir.frameworksDir(false), HeaderPathType::Framework}}; @@ -214,7 +214,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers() ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->projectMacros = {{"OH_BEHAVE", "-1"}}; part->headerPaths = {{testDataDir.includeDir(false), HeaderPathType::User}, {testDataDir.frameworksDir(false), HeaderPathType::Framework}}; @@ -262,7 +262,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files() ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->projectMacros = {{"OH_BEHAVE", "-1"}}; part->headerPaths = {{testDataDir.includeDir(false), HeaderPathType::User}}; part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); @@ -318,7 +318,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times() ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); @@ -337,7 +337,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times() // Simulate project configuration change by having different defines each time. macros += {"ANOTHER_DEFINE"}; part->projectMacros = macros; - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); @@ -381,7 +381,7 @@ void CppToolsPlugin::test_modelmanager_refresh_test_for_changes() ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); pi.appendProjectPart(part); @@ -417,7 +417,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed() ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader)); pi.appendProjectPart(part); @@ -438,7 +438,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed() // Now add testHeader2 and remove testHeader1 pi = ProjectInfo(project); ProjectPart::Ptr newPart(new ProjectPart); - newPart->qtVersion = ProjectPart::Qt5; + newPart->qtVersion = Utils::QtVersion::Qt5; newPart->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); newPart->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader)); pi.appendProjectPart(newPart); @@ -477,7 +477,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ ProjectInfo pi = ProjectInfo(project); ProjectPart::Ptr part(new ProjectPart); - part->qtVersion = ProjectPart::Qt5; + part->qtVersion = Utils::QtVersion::Qt5; foreach (const QString &file, initialProjectFiles) part->files.append(ProjectFile(file, ProjectFile::CXXSource)); pi = ProjectInfo(project); @@ -498,7 +498,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ document = snapshot.document(fileToChange); const QDateTime lastModifiedBefore = document->lastModified(); - QCOMPARE(document->globalSymbolCount(), 1U); + QCOMPARE(document->globalSymbolCount(), 1); QCOMPARE(document->globalSymbolAt(0)->name()->identifier()->chars(), "someGlobal"); // Modify the file @@ -527,7 +527,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ document = snapshot.document(fileToChange); const QDateTime lastModifiedAfter = document->lastModified(); QVERIFY(lastModifiedAfter > lastModifiedBefore); - QCOMPARE(document->globalSymbolCount(), 2U); + QCOMPARE(document->globalSymbolCount(), 2); QCOMPARE(document->globalSymbolAt(0)->name()->identifier()->chars(), "someGlobal"); QCOMPARE(document->globalSymbolAt(1)->name()->identifier()->chars(), "addedOtherGlobal"); } @@ -618,11 +618,10 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles() QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h" QStringList fileNamesInWorkinCopy; - QHashIterator<Utils::FilePath, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); - while (it.hasNext()) { - it.next(); + const WorkingCopy::Table &elements = workingCopy.elements(); + for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) fileNamesInWorkinCopy << Utils::FilePath::fromString(it.key().toString()).fileName(); - } + fileNamesInWorkinCopy.sort(); const QString expectedUiHeaderFileName = _("ui_mainwindow.h"); QCOMPARE(fileNamesInWorkinCopy.at(0), mm->configurationFileName()); @@ -756,7 +755,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project() part1->projectFile = QLatin1String("project1.projectfile"); part1->files.append(ProjectFile(main1File, ProjectFile::CXXSource)); part1->files.append(ProjectFile(header, ProjectFile::CXXHeader)); - part1->qtVersion = ProjectPart::NoQt; + part1->qtVersion = Utils::QtVersion::None; part1->projectMacros = {{"SUB1"}}; part1->headerPaths = {{testDataDirectory.includeDir(false), HeaderPathType::User}}; @@ -764,7 +763,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project() part2->projectFile = QLatin1String("project1.projectfile"); part2->files.append(ProjectFile(main2File, ProjectFile::CXXSource)); part2->files.append(ProjectFile(header, ProjectFile::CXXHeader)); - part2->qtVersion = ProjectPart::NoQt; + part2->qtVersion = Utils::QtVersion::None; part2->projectMacros = {{"SUB2"}}; part2->headerPaths = {{testDataDirectory.includeDir(false), HeaderPathType::User}}; @@ -820,7 +819,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers() part1->projectFile = QLatin1String("project1.projectfile"); part1->files.append(ProjectFile(main1File, ProjectFile::CXXSource)); part1->files.append(ProjectFile(header, ProjectFile::CXXHeader)); - part1->qtVersion = ProjectPart::NoQt; + part1->qtVersion = Utils::QtVersion::None; part1->precompiledHeaders.append(pch1File); part1->headerPaths = {{testDataDirectory.includeDir(false), HeaderPathType::User}}; part1->updateLanguageFeatures(); @@ -829,7 +828,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers() part2->projectFile = QLatin1String("project2.projectfile"); part2->files.append(ProjectFile(main2File, ProjectFile::CXXSource)); part2->files.append(ProjectFile(header, ProjectFile::CXXHeader)); - part2->qtVersion = ProjectPart::NoQt; + part2->qtVersion = Utils::QtVersion::None; part2->precompiledHeaders.append(pch2File); part2->headerPaths = {{testDataDirectory.includeDir(false), HeaderPathType::User}}; part2->updateLanguageFeatures(); @@ -901,13 +900,13 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor() ProjectPart::Ptr part1(new ProjectPart); part1->files.append(ProjectFile(main1File, ProjectFile::CXXSource)); part1->files.append(ProjectFile(header, ProjectFile::CXXHeader)); - part1->qtVersion = ProjectPart::NoQt; + part1->qtVersion = Utils::QtVersion::None; part1->headerPaths = {{testDataDirectory.includeDir(false), HeaderPathType::User}}; ProjectPart::Ptr part2(new ProjectPart); part2->files.append(ProjectFile(main2File, ProjectFile::CXXSource)); part2->files.append(ProjectFile(header, ProjectFile::CXXHeader)); - part2->qtVersion = ProjectPart::NoQt; + part2->qtVersion = Utils::QtVersion::None; part2->headerPaths = {{testDataDirectory.includeDir(false), HeaderPathType::User}}; ProjectInfo pi = ProjectInfo(project); @@ -986,7 +985,7 @@ void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate() part->project = project; part->files.append(ProjectFile(fileA, ProjectFile::CXXSource)); part->files.append(ProjectFile(fileB, ProjectFile::CXXSource)); - part->qtVersion = ProjectPart::NoQt; + part->qtVersion = Utils::QtVersion::None; ProjectInfo pi = ProjectInfo(project); pi.appendProjectPart(part); @@ -1009,7 +1008,7 @@ void CppToolsPlugin::test_modelmanager_renameIncludes() struct ModelManagerGCHelper { ~ModelManagerGCHelper() { CppModelManager::instance()->GC(); } } GCHelper; - Q_UNUSED(GCHelper); // do not warn about being unused + Q_UNUSED(GCHelper) // do not warn about being unused TemporaryDir tmpDir; QVERIFY(tmpDir.isValid()); @@ -1055,7 +1054,7 @@ void CppToolsPlugin::test_modelmanager_renameIncludesInEditor() struct ModelManagerGCHelper { ~ModelManagerGCHelper() { CppModelManager::instance()->GC(); } } GCHelper; - Q_UNUSED(GCHelper); // do not warn about being unused + Q_UNUSED(GCHelper) // do not warn about being unused TemporaryDir tmpDir; QVERIFY(tmpDir.isValid()); diff --git a/src/plugins/cpptools/cppoverviewmodel.cpp b/src/plugins/cpptools/cppoverviewmodel.cpp index e0fc805698..6fd9b161dc 100644 --- a/src/plugins/cpptools/cppoverviewmodel.cpp +++ b/src/plugins/cpptools/cppoverviewmodel.cpp @@ -82,8 +82,8 @@ QVariant SymbolItem::data(int /*column*/, int role) const if (Template *t = symbl->asTemplate()) if (Symbol *templateDeclaration = t->declaration()) { QStringList parameters; - parameters.reserve(static_cast<int>(t->templateParameterCount())); - for (unsigned i = 0; i < t->templateParameterCount(); ++i) { + parameters.reserve(t->templateParameterCount()); + for (int i = 0; i < t->templateParameterCount(); ++i) { parameters.append(overviewModel->_overview.prettyName( t->templateParameterAt(i)->name())); } @@ -119,7 +119,7 @@ QVariant SymbolItem::data(int /*column*/, int role) const return Icons::iconForSymbol(symbol); case AbstractOverviewModel::FileNameRole: - return QString::fromUtf8(symbol->fileName(), static_cast<int>(symbol->fileNameLength())); + return QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()); case AbstractOverviewModel::LineNumberRole: return symbol->line(); @@ -135,15 +135,15 @@ bool OverviewModel::hasDocument() const return _cppDocument; } -unsigned OverviewModel::globalSymbolCount() const +int OverviewModel::globalSymbolCount() const { - unsigned count = 0; + int count = 0; if (_cppDocument) count += _cppDocument->globalSymbolCount(); return count; } -Symbol *OverviewModel::globalSymbolAt(unsigned index) const +Symbol *OverviewModel::globalSymbolAt(int index) const { return _cppDocument->globalSymbolAt(index); } Symbol *OverviewModel::symbolFromIndex(const QModelIndex &index) const @@ -185,8 +185,8 @@ Utils::LineColumn OverviewModel::lineColumnFromIndex(const QModelIndex &sourceIn CPlusPlus::Symbol *symbol = symbolFromIndex(sourceIndex); if (!symbol) return lineColumn; - lineColumn.line = static_cast<int>(symbol->line()); - lineColumn.column = static_cast<int>(symbol->column()); + lineColumn.line = symbol->line(); + lineColumn.column = symbol->column(); return lineColumn; } @@ -202,8 +202,8 @@ void OverviewModel::buildTree(SymbolItem *root, bool isRoot) return; if (isRoot) { - unsigned rows = globalSymbolCount(); - for (unsigned row = 0; row < rows; ++row) { + int rows = globalSymbolCount(); + for (int row = 0; row < rows; ++row) { Symbol *symbol = globalSymbolAt(row); auto currentItem = new SymbolItem(symbol); buildTree(currentItem, false); diff --git a/src/plugins/cpptools/cppoverviewmodel.h b/src/plugins/cpptools/cppoverviewmodel.h index 44a45ace36..4d06427395 100644 --- a/src/plugins/cpptools/cppoverviewmodel.h +++ b/src/plugins/cpptools/cppoverviewmodel.h @@ -59,8 +59,8 @@ public: private: CPlusPlus::Symbol *symbolFromIndex(const QModelIndex &index) const; bool hasDocument() const; - unsigned globalSymbolCount() const; - CPlusPlus::Symbol *globalSymbolAt(unsigned index) const; + int globalSymbolCount() const; + CPlusPlus::Symbol *globalSymbolAt(int index) const; void buildTree(SymbolItem *root, bool isRoot); private: diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter.cpp index 853e563424..82df823af1 100644 --- a/src/plugins/cpptools/cpppointerdeclarationformatter.cpp +++ b/src/plugins/cpptools/cpppointerdeclarationformatter.cpp @@ -377,7 +377,7 @@ void PointerDeclarationFormatter::checkAndRewrite(DeclaratorAST *declarator, CHECK_R(symbol, "No symbol"); // Check for expanded tokens - for (unsigned token = tokenRange.start; token <= tokenRange.end; ++token) + for (int token = tokenRange.start; token <= tokenRange.end; ++token) CHECK_R(!tokenAt(token).expanded(), "Token is expanded"); Utils::ChangeSet::Range range(m_cppRefactoringFile->startOf(tokenRange.start), @@ -455,7 +455,7 @@ void PointerDeclarationFormatter::printCandidate(AST *ast) { #if DEBUG_OUTPUT QString tokens; - for (unsigned token = ast->firstToken(); token < ast->lastToken(); token++) + for (int token = ast->firstToken(); token < ast->lastToken(); token++) tokens += QString::fromLatin1(tokenAt(token).spell()) + QLatin1Char(' '); # ifdef __GNUC__ diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter.h b/src/plugins/cpptools/cpppointerdeclarationformatter.h index 20ed9557bc..e965d89774 100644 --- a/src/plugins/cpptools/cpppointerdeclarationformatter.h +++ b/src/plugins/cpptools/cpppointerdeclarationformatter.h @@ -101,9 +101,9 @@ private: class TokenRange { public: TokenRange() = default; - TokenRange(unsigned start, unsigned end) : start(start), end(end) {} - unsigned start = 0; - unsigned end = 0; + TokenRange(int start, int end) : start(start), end(end) {} + int start = 0; + int end = 0; }; void processIfWhileForStatement(ExpressionAST *expression, Symbol *symbol); diff --git a/src/plugins/cpptools/cppprojectfile.cpp b/src/plugins/cpptools/cppprojectfile.cpp index 52c599d10b..3f1e590619 100644 --- a/src/plugins/cpptools/cppprojectfile.cpp +++ b/src/plugins/cpptools/cppprojectfile.cpp @@ -47,32 +47,38 @@ bool ProjectFile::operator==(const ProjectFile &other) const && path == other.path; } -ProjectFile::Kind ProjectFile::classify(const QString &filePath) +ProjectFile::Kind ProjectFile::classifyByMimeType(const QString &mt) { - if (isAmbiguousHeader(filePath)) - return AmbiguousHeader; - - const Utils::MimeType mimeType = Utils::mimeTypeForFile(filePath); - const QString mt = mimeType.name(); - if (mt == QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)) + if (mt == CppTools::Constants::C_SOURCE_MIMETYPE) return CSource; - if (mt == QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)) + if (mt == CppTools::Constants::C_HEADER_MIMETYPE) return CHeader; - if (mt == QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)) + if (mt == CppTools::Constants::CPP_SOURCE_MIMETYPE) return CXXSource; - if (mt == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE)) + if (mt == CppTools::Constants::CPP_HEADER_MIMETYPE) return CXXHeader; - if (mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)) + if (mt == CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE) return ObjCSource; - if (mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)) + if (mt == CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE) return ObjCXXSource; - if (mt == QLatin1String(CppTools::Constants::QDOC_MIMETYPE)) + if (mt == CppTools::Constants::QDOC_MIMETYPE) return CXXSource; - if (mt == QLatin1String(CppTools::Constants::MOC_MIMETYPE)) + if (mt == CppTools::Constants::MOC_MIMETYPE) return CXXSource; + if (mt == CppTools::Constants::AMBIGUOUS_HEADER_MIMETYPE) + return AmbiguousHeader; return Unsupported; } +ProjectFile::Kind ProjectFile::classify(const QString &filePath) +{ + if (isAmbiguousHeader(filePath)) + return AmbiguousHeader; + + const Utils::MimeType mimeType = Utils::mimeTypeForFile(filePath); + return classifyByMimeType(mimeType.name()); +} + bool ProjectFile::isAmbiguousHeader(const QString &filePath) { return filePath.endsWith(".h"); diff --git a/src/plugins/cpptools/cppprojectfile.h b/src/plugins/cpptools/cppprojectfile.h index 4cfda1be49..942cf66f3b 100644 --- a/src/plugins/cpptools/cppprojectfile.h +++ b/src/plugins/cpptools/cppprojectfile.h @@ -50,6 +50,7 @@ public: OpenCLSource, }; + static Kind classifyByMimeType(const QString &mt); static Kind classify(const QString &filePath); static bool isSource(Kind kind); diff --git a/src/plugins/cpptools/cppprojectfilecategorizer.cpp b/src/plugins/cpptools/cppprojectfilecategorizer.cpp index 35ec2d9263..036022bb43 100644 --- a/src/plugins/cpptools/cppprojectfilecategorizer.cpp +++ b/src/plugins/cpptools/cppprojectfilecategorizer.cpp @@ -31,10 +31,11 @@ namespace CppTools { ProjectFileCategorizer::ProjectFileCategorizer(const QString &projectPartName, const QStringList &filePaths, - const FileClassifier &fileClassifier) + const FileIsActive &fileIsActive, + const GetMimeType &getMimeType) : m_partName(projectPartName) { - const ProjectFiles ambiguousHeaders = classifyFiles(filePaths, fileClassifier); + const ProjectFiles ambiguousHeaders = classifyFiles(filePaths, fileIsActive, getMimeType); expandSourcesWithAmbiguousHeaders(ambiguousHeaders); m_partCount = (m_cSources.isEmpty() ? 0 : 1) @@ -53,14 +54,17 @@ QString ProjectFileCategorizer::partName(const QString &languageName) const } ProjectFiles ProjectFileCategorizer::classifyFiles(const QStringList &filePaths, - const FileClassifier &fileClassifier) + const FileIsActive &fileIsActive, + const GetMimeType &getMimeType) { ProjectFiles ambiguousHeaders; foreach (const QString &filePath, filePaths) { - const ProjectFile projectFile = fileClassifier - ? fileClassifier(filePath) - : ProjectFile(filePath, ProjectFile::classify(filePath)); + const ProjectFile projectFile(filePath, + getMimeType + ? ProjectFile::classifyByMimeType(getMimeType(filePath)) + : ProjectFile::classify(filePath), + fileIsActive ? fileIsActive(filePath) : true); switch (projectFile.kind) { case ProjectFile::AmbiguousHeader: diff --git a/src/plugins/cpptools/cppprojectfilecategorizer.h b/src/plugins/cpptools/cppprojectfilecategorizer.h index 48cd2438c6..bd82ee2ca0 100644 --- a/src/plugins/cpptools/cppprojectfilecategorizer.h +++ b/src/plugins/cpptools/cppprojectfilecategorizer.h @@ -26,7 +26,8 @@ #pragma once #include "cppprojectfile.h" -#include "cpprawprojectpart.h" + +#include <projectexplorer/rawprojectpart.h> #include <QString> #include <QVector> @@ -36,12 +37,14 @@ namespace CppTools { class ProjectFileCategorizer { public: - using FileClassifier = RawProjectPart::FileClassifier; + using FileIsActive = ProjectExplorer::RawProjectPart::FileIsActive; + using GetMimeType = ProjectExplorer::RawProjectPart::GetMimeType; public: ProjectFileCategorizer(const QString &projectPartName, const QStringList &filePaths, - const FileClassifier &fileClassifier = FileClassifier()); + const FileIsActive &fileIsActive = {}, + const GetMimeType &getMimeType = {}); bool hasCSources() const { return !m_cSources.isEmpty(); } bool hasCxxSources() const { return !m_cxxSources.isEmpty(); } @@ -59,7 +62,9 @@ public: QString partName(const QString &languageName) const; private: - ProjectFiles classifyFiles(const QStringList &filePaths, const FileClassifier &fileClassifier); + ProjectFiles classifyFiles(const QStringList &filePaths, + const FileIsActive &fileIsActive, + const GetMimeType &getMimeType); void expandSourcesWithAmbiguousHeaders(const ProjectFiles &ambiguousHeaders); private: diff --git a/src/plugins/cpptools/cppprojectinfogenerator.cpp b/src/plugins/cpptools/cppprojectinfogenerator.cpp index 18c7d4fb76..c013e62566 100644 --- a/src/plugins/cpptools/cppprojectinfogenerator.cpp +++ b/src/plugins/cpptools/cppprojectinfogenerator.cpp @@ -35,8 +35,9 @@ namespace CppTools { namespace Internal { -ProjectInfoGenerator::ProjectInfoGenerator(const QFutureInterface<void> &futureInterface, - const ProjectUpdateInfo &projectUpdateInfo) +ProjectInfoGenerator::ProjectInfoGenerator( + const QFutureInterface<void> &futureInterface, + const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo) : m_futureInterface(futureInterface) , m_projectUpdateInfo(projectUpdateInfo) { @@ -46,7 +47,7 @@ ProjectInfo ProjectInfoGenerator::generate() { ProjectInfo projectInfo(m_projectUpdateInfo.project); - for (const RawProjectPart &rpp : m_projectUpdateInfo.rawProjectParts) { + for (const ProjectExplorer::RawProjectPart &rpp : m_projectUpdateInfo.rawProjectParts) { if (m_futureInterface.isCanceled()) return ProjectInfo(); @@ -57,8 +58,8 @@ ProjectInfo ProjectInfoGenerator::generate() return projectInfo; } -static ProjectPart::Ptr projectPartFromRawProjectPart(const RawProjectPart &rawProjectPart, - ProjectExplorer::Project *project) +static ProjectPart::Ptr projectPartFromRawProjectPart( + const ProjectExplorer::RawProjectPart &rawProjectPart, ProjectExplorer::Project *project) { ProjectPart::Ptr part(new ProjectPart); part->project = project; @@ -80,14 +81,15 @@ static ProjectPart::Ptr projectPartFromRawProjectPart(const RawProjectPart &rawP return part; } -QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(const RawProjectPart &rawProjectPart) +QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts( + const ProjectExplorer::RawProjectPart &rawProjectPart) { using Utils::LanguageExtension; QVector<ProjectPart::Ptr> result; ProjectFileCategorizer cat(rawProjectPart.displayName, rawProjectPart.files, - rawProjectPart.fileClassifier); + rawProjectPart.fileIsActive); if (!cat.hasParts()) return result; @@ -138,15 +140,15 @@ QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(const RawProj } ProjectPart::Ptr ProjectInfoGenerator::createProjectPart( - const RawProjectPart &rawProjectPart, + const ProjectExplorer::RawProjectPart &rawProjectPart, const ProjectPart::Ptr &templateProjectPart, const ProjectFiles &projectFiles, const QString &partName, Language language, Utils::LanguageExtensions languageExtensions) { - RawProjectPartFlags flags; - ToolChainInfo tcInfo; + ProjectExplorer::RawProjectPartFlags flags; + ProjectExplorer::ToolChainInfo tcInfo; if (language == Language::C) { flags = rawProjectPart.flagsForC; tcInfo = m_projectUpdateInfo.cToolChainInfo; diff --git a/src/plugins/cpptools/cppprojectinfogenerator.h b/src/plugins/cpptools/cppprojectinfogenerator.h index bb73fdd0e0..2dbc4cd2fa 100644 --- a/src/plugins/cpptools/cppprojectinfogenerator.h +++ b/src/plugins/cpptools/cppprojectinfogenerator.h @@ -37,13 +37,14 @@ class ProjectInfoGenerator { public: ProjectInfoGenerator(const QFutureInterface<void> &futureInterface, - const ProjectUpdateInfo &projectUpdateInfo); + const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo); ProjectInfo generate(); private: - QVector<ProjectPart::Ptr> createProjectParts(const RawProjectPart &rawProjectPart); - ProjectPart::Ptr createProjectPart(const RawProjectPart &rawProjectPart, + QVector<ProjectPart::Ptr> createProjectParts( + const ProjectExplorer::RawProjectPart &rawProjectPart); + ProjectPart::Ptr createProjectPart(const ProjectExplorer::RawProjectPart &rawProjectPart, const ProjectPart::Ptr &templateProjectPart, const ProjectFiles &projectFiles, const QString &partName, @@ -52,7 +53,7 @@ private: private: const QFutureInterface<void> m_futureInterface; - const ProjectUpdateInfo &m_projectUpdateInfo; + const ProjectExplorer::ProjectUpdateInfo &m_projectUpdateInfo; }; } // namespace Internal } // namespace CppTools diff --git a/src/plugins/cpptools/cppprojectupdater.cpp b/src/plugins/cpptools/cppprojectupdater.cpp index 23842f15f3..f89f8e9fc8 100644 --- a/src/plugins/cpptools/cppprojectupdater.cpp +++ b/src/plugins/cpptools/cppprojectupdater.cpp @@ -46,7 +46,7 @@ CppProjectUpdater::~CppProjectUpdater() cancelAndWaitForFinished(); } -void CppProjectUpdater::update(const ProjectUpdateInfo &projectUpdateInfo) +void CppProjectUpdater::update(const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo) { // Stop previous update. cancelAndWaitForFinished(); @@ -101,4 +101,14 @@ void CppProjectUpdater::onProjectInfoGenerated() QTC_CHECK(future != QFuture<void>()); } +CppProjectUpdaterFactory::CppProjectUpdaterFactory() +{ + setObjectName("CppProjectUpdaterFactory"); +} + +CppProjectUpdaterInterface *CppProjectUpdaterFactory::create() +{ + return new CppProjectUpdater; +} + } // namespace CppTools diff --git a/src/plugins/cpptools/cppprojectupdater.h b/src/plugins/cpptools/cppprojectupdater.h index 65eb1522a1..5d95fa087c 100644 --- a/src/plugins/cpptools/cppprojectupdater.h +++ b/src/plugins/cpptools/cppprojectupdater.h @@ -25,6 +25,7 @@ #pragma once +#include "cppprojectupdaterinterface.h" #include "cpptools_global.h" #include "projectinfo.h" @@ -34,9 +35,19 @@ namespace CppTools { class ProjectInfo; -class ProjectUpdateInfo; -class CPPTOOLS_EXPORT CppProjectUpdater : public QObject +// registered in extensionsystem's object pool for plugins with weak dependency to CppTools +class CPPTOOLS_EXPORT CppProjectUpdaterFactory : public QObject +{ + Q_OBJECT +public: + CppProjectUpdaterFactory(); + + // keep the namespace, for the type name in the invokeMethod call + Q_INVOKABLE CppTools::CppProjectUpdaterInterface *create(); +}; + +class CPPTOOLS_EXPORT CppProjectUpdater : public QObject, public CppProjectUpdaterInterface { Q_OBJECT @@ -44,8 +55,8 @@ public: CppProjectUpdater(); ~CppProjectUpdater() override; - void update(const ProjectUpdateInfo &projectUpdateInfo); - void cancel(); + void update(const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo) override; + void cancel() override; private: void cancelAndWaitForFinished(); @@ -54,7 +65,7 @@ private: void onProjectInfoGenerated(); private: - ProjectUpdateInfo m_projectUpdateInfo; + ProjectExplorer::ProjectUpdateInfo m_projectUpdateInfo; QFutureInterface<void> m_futureInterface; QFutureWatcher<ProjectInfo> m_generateFutureWatcher; diff --git a/src/plugins/cpptools/cppkitinfo.h b/src/plugins/cpptools/cppprojectupdaterinterface.h index d2f9a871bd..2a9f44db48 100644 --- a/src/plugins/cpptools/cppkitinfo.h +++ b/src/plugins/cpptools/cppprojectupdaterinterface.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -25,32 +25,17 @@ #pragma once -#include "projectpart.h" - -#include "cpptools_global.h" - -namespace ProjectExplorer { -class Kit; -class Project; -class ToolChain; -} // namespace ProjectExplorer +#include <projectexplorer/rawprojectpart.h> namespace CppTools { -class CPPTOOLS_EXPORT KitInfo +class CppProjectUpdaterInterface { public: - explicit KitInfo(ProjectExplorer::Project *project); - - bool isValid() const; - - ProjectExplorer::Kit *kit = nullptr; - ProjectExplorer::ToolChain *cToolChain = nullptr; - ProjectExplorer::ToolChain *cxxToolChain = nullptr; - - ProjectPart::QtVersion projectPartQtVersion = ProjectPart::NoQt; + virtual ~CppProjectUpdaterInterface() = default; - QString sysRootPath; + virtual void update(const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo) = 0; + virtual void cancel() = 0; }; } // namespace CppTools diff --git a/src/plugins/cpptools/cpprawprojectpart.cpp b/src/plugins/cpptools/cpprawprojectpart.cpp deleted file mode 100644 index ee18166c05..0000000000 --- a/src/plugins/cpptools/cpprawprojectpart.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "cpprawprojectpart.h" - -#include <projectexplorer/abi.h> -#include <projectexplorer/projectexplorerconstants.h> -#include <projectexplorer/kitinformation.h> - -namespace CppTools { - -RawProjectPartFlags::RawProjectPartFlags(const ProjectExplorer::ToolChain *toolChain, - const QStringList &commandLineFlags) -{ - // Keep the following cheap/non-blocking for the ui thread. Expensive - // operations are encapsulated in ToolChainInfo as "runners". - this->commandLineFlags = commandLineFlags; - if (toolChain) { - warningFlags = toolChain->warningFlags(commandLineFlags); - languageExtensions = toolChain->languageExtensions(commandLineFlags); - } -} - -void RawProjectPart::setDisplayName(const QString &displayName) -{ - this->displayName = displayName; -} - -void RawProjectPart::setFiles(const QStringList &files, const FileClassifier &fileClassifier) -{ - this->files = files; - this->fileClassifier = fileClassifier; -} - -void RawProjectPart::setProjectFileLocation(const QString &projectFile, int line, int column) -{ - this->projectFile = projectFile; - projectFileLine = line; - projectFileColumn = column; -} - -void RawProjectPart::setConfigFileName(const QString &configFileName) -{ - this->projectConfigFile = configFileName; -} - -void RawProjectPart::setBuildSystemTarget(const QString &target) -{ - buildSystemTarget = target; -} - -void RawProjectPart::setCallGroupId(const QString &id) -{ - callGroupId = id; -} - -void RawProjectPart::setQtVersion(ProjectPart::QtVersion qtVersion) -{ - this->qtVersion = qtVersion; -} - -void RawProjectPart::setMacros(const ProjectExplorer::Macros ¯os) -{ - this->projectMacros = macros; -} - -void RawProjectPart::setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths) -{ - this->headerPaths = headerPaths; -} - -void RawProjectPart::setIncludePaths(const QStringList &includePaths) -{ - headerPaths.clear(); - - foreach (const QString &includeFile, includePaths) { - ProjectExplorer::HeaderPath hp(includeFile, ProjectExplorer::HeaderPathType::User); - - // The simple project managers are utterly ignorant of frameworks on macOS, and won't report - // framework paths. The work-around is to check if the include path ends in ".framework", - // and if so, add the parent directory as framework path. - if (includeFile.endsWith(QLatin1String(".framework"))) { - const int slashIdx = includeFile.lastIndexOf(QLatin1Char('/')); - if (slashIdx != -1) { - hp = {includeFile.left(slashIdx), ProjectExplorer::HeaderPathType::Framework}; - } - } - - headerPaths.push_back(std::move(hp)); - } -} - -void RawProjectPart::setPreCompiledHeaders(const QStringList &preCompiledHeaders) -{ - this->precompiledHeaders = preCompiledHeaders; -} - -void RawProjectPart::setSelectedForBuilding(bool yesno) -{ - this->selectedForBuilding = yesno; -} - -void RawProjectPart::setFlagsForC(const RawProjectPartFlags &flags) -{ - flagsForC = flags; -} - -void RawProjectPart::setFlagsForCxx(const RawProjectPartFlags &flags) -{ - flagsForCxx = flags; -} - -void RawProjectPart::setBuildTargetType(ProjectPart::BuildTargetType type) -{ - buildTargetType = type; -} - -} // namespace CppTools diff --git a/src/plugins/cpptools/cpprawprojectpart.h b/src/plugins/cpptools/cpprawprojectpart.h deleted file mode 100644 index 43e3067753..0000000000 --- a/src/plugins/cpptools/cpprawprojectpart.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "cpptools_global.h" -#include "projectpart.h" - -#include <projectexplorer/toolchain.h> -#include <utils/cpplanguage_details.h> - -#include <functional> - -namespace CppTools { - -class CPPTOOLS_EXPORT RawProjectPartFlags -{ -public: - RawProjectPartFlags() = default; - RawProjectPartFlags(const ProjectExplorer::ToolChain *toolChain, - const QStringList &commandLineFlags); - -public: - QStringList commandLineFlags; - // The following are deduced from commandLineFlags. - ProjectExplorer::WarningFlags warningFlags = ProjectExplorer::WarningFlags::Default; - Utils::LanguageExtensions languageExtensions = Utils::LanguageExtension::None; -}; - -class CPPTOOLS_EXPORT RawProjectPart -{ -public: - void setDisplayName(const QString &displayName); - - void setProjectFileLocation(const QString &projectFile, int line = -1, int column = -1); - void setConfigFileName(const QString &configFileName); - void setCallGroupId(const QString &id); - - // FileClassifier must be thread-safe. - using FileClassifier = std::function<ProjectFile(const QString &filePath)>; - void setFiles(const QStringList &files, const FileClassifier &fileClassifier = FileClassifier()); - void setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths); - void setIncludePaths(const QStringList &includePaths); - void setPreCompiledHeaders(const QStringList &preCompiledHeaders); - - void setBuildSystemTarget(const QString &target); - void setBuildTargetType(ProjectPart::BuildTargetType type); - void setSelectedForBuilding(bool yesno); - - void setFlagsForC(const RawProjectPartFlags &flags); - void setFlagsForCxx(const RawProjectPartFlags &flags); - - void setMacros(const ProjectExplorer::Macros ¯os); - void setQtVersion(ProjectPart::QtVersion qtVersion); - -public: - QString displayName; - - QString projectFile; - int projectFileLine = -1; - int projectFileColumn = -1; - QString callGroupId; - - // Files - QStringList files; - FileClassifier fileClassifier; - QStringList precompiledHeaders; - ProjectExplorer::HeaderPaths headerPaths; - QString projectConfigFile; // Generic Project Manager only - - // Build system - QString buildSystemTarget; - ProjectPart::BuildTargetType buildTargetType = ProjectPart::BuildTargetType::Unknown; - bool selectedForBuilding = true; - - // Flags - RawProjectPartFlags flagsForC; - RawProjectPartFlags flagsForCxx; - - // Misc - ProjectExplorer::Macros projectMacros; - ProjectPart::QtVersion qtVersion = ProjectPart::UnknownQt; -}; - -using RawProjectParts = QVector<RawProjectPart>; - -} // namespace CppTools diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index f3c27073a9..4d16dd4813 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -159,7 +159,7 @@ void CppRefactoringFile::setCppDocument(Document::Ptr document) Scope *CppRefactoringFile::scopeAt(unsigned index) const { - unsigned line, column; + int line, column; cppDocument()->translationUnit()->getTokenStartPosition(index, &line, &column); return cppDocument()->scopeAt(line, column); } @@ -195,10 +195,10 @@ bool CppRefactoringFile::isCursorOn(const AST *ast) const Utils::ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const { const Token &token = tokenAt(tokenIndex); - unsigned line, column; + int line, column; cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column); const int start = document()->findBlockByNumber(line - 1).position() + column - 1; - return {start, static_cast<int>(start + token.utf16chars())}; + return {start, start + token.utf16chars()}; } Utils::ChangeSet::Range CppRefactoringFile::range(AST *ast) const @@ -208,7 +208,7 @@ Utils::ChangeSet::Range CppRefactoringFile::range(AST *ast) const int CppRefactoringFile::startOf(unsigned index) const { - unsigned line, column; + int line, column; cppDocument()->translationUnit()->getPosition(tokenAt(index).utf16charsBegin(), &line, &column); return document()->findBlockByNumber(line - 1).position() + column - 1; } @@ -220,21 +220,21 @@ int CppRefactoringFile::startOf(const AST *ast) const int CppRefactoringFile::endOf(unsigned index) const { - unsigned line, column; + int line, column; cppDocument()->translationUnit()->getPosition(tokenAt(index).utf16charsEnd(), &line, &column); return document()->findBlockByNumber(line - 1).position() + column - 1; } int CppRefactoringFile::endOf(const AST *ast) const { - unsigned end = ast->lastToken(); + int end = ast->lastToken(); QTC_ASSERT(end > 0, return -1); return endOf(end - 1); } void CppRefactoringFile::startAndEndOf(unsigned index, int *start, int *end) const { - unsigned line, column; + int line, column; Token token(tokenAt(index)); cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column); *start = document()->findBlockByNumber(line - 1).position() + column - 1; diff --git a/src/plugins/cpptools/cppselectionchanger.cpp b/src/plugins/cpptools/cppselectionchanger.cpp index 98437c1ced..3159f16eb3 100644 --- a/src/plugins/cpptools/cppselectionchanger.cpp +++ b/src/plugins/cpptools/cppselectionchanger.cpp @@ -136,13 +136,12 @@ int CppSelectionChanger::getTokenStartCursorPosition( unsigned tokenIndex, const QTextCursor &cursor) const { - unsigned startLine, startColumn; + int startLine, startColumn; m_unit->getTokenStartPosition(tokenIndex, &startLine, &startColumn); const QTextDocument *document = cursor.document(); - const int startPosition = - document->findBlockByNumber(static_cast<int>(startLine) - 1).position() - + static_cast<int>(startColumn) - 1; + const int startPosition = document->findBlockByNumber(startLine - 1).position() + + startColumn - 1; return startPosition; } @@ -151,13 +150,12 @@ int CppSelectionChanger::getTokenEndCursorPosition( unsigned tokenIndex, const QTextCursor &cursor) const { - unsigned endLine, endColumn; + int endLine, endColumn; m_unit->getTokenEndPosition(tokenIndex, &endLine, &endColumn); const QTextDocument *document = cursor.document(); - const int endPosition = - document->findBlockByNumber(static_cast<int>(endLine) - 1).position() - + static_cast<int>(endColumn) - 1; + const int endPosition = document->findBlockByNumber(endLine - 1).position() + + endColumn - 1; return endPosition; } @@ -167,7 +165,7 @@ void CppSelectionChanger::printTokenDebugInfo( const QTextCursor &cursor, QString prefix) const { - unsigned line, column; + int line, column; const Token token = m_unit->tokenAt(tokenIndex); m_unit->getTokenStartPosition(tokenIndex, &line, &column); const int startPos = getTokenStartCursorPosition(tokenIndex, cursor); @@ -571,7 +569,7 @@ void CppSelectionChanger::fineTuneASTNodePositions(ASTNodePositions &positions) // Start position will be the end position minus the size of the actual contents of the // literal. - int newPosStart = newPosEnd - static_cast<int>(firstToken.string->size()); + int newPosStart = newPosEnd - firstToken.string->size(); // Skip raw literal parentheses. if (isRawLiteral) @@ -591,7 +589,7 @@ void CppSelectionChanger::fineTuneASTNodePositions(ASTNodePositions &positions) qDebug() << "Selecting inner contents of char literal."; positions.astPosEnd = positions.astPosEnd - 1; - positions.astPosStart = positions.astPosEnd - int(firstToken.literal->size()); + positions.astPosStart = positions.astPosEnd - firstToken.literal->size(); } } } else if (ForStatementAST *forStatementAST = ast->asForStatement()) { diff --git a/src/plugins/cpptools/cppsemanticinfo.h b/src/plugins/cpptools/cppsemanticinfo.h index 57e67eaf72..1c61592655 100644 --- a/src/plugins/cpptools/cppsemanticinfo.h +++ b/src/plugins/cpptools/cppsemanticinfo.h @@ -62,7 +62,6 @@ public: public: using Use = TextEditor::HighlightingResult; using LocalUseMap = QHash<CPlusPlus::Symbol *, QList<Use>>; - using LocalUseIterator = QHashIterator<CPlusPlus::Symbol *, QList<Use>>; // Document specific unsigned revision = 0; diff --git a/src/plugins/cpptools/cppsourceprocessor.cpp b/src/plugins/cpptools/cppsourceprocessor.cpp index 35a0ccf529..7f232c1ad7 100644 --- a/src/plugins/cpptools/cppsourceprocessor.cpp +++ b/src/plugins/cpptools/cppsourceprocessor.cpp @@ -324,8 +324,8 @@ void CppSourceProcessor::macroAdded(const CPlusPlus::Macro ¯o) m_currentDoc->appendMacro(macro); } -void CppSourceProcessor::passedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset, - unsigned line, const CPlusPlus::Macro ¯o) +void CppSourceProcessor::passedMacroDefinitionCheck(int bytesOffset, int utf16charsOffset, + int line, const CPlusPlus::Macro ¯o) { if (!m_currentDoc) return; @@ -336,7 +336,7 @@ void CppSourceProcessor::passedMacroDefinitionCheck(unsigned bytesOffset, unsign line, QVector<MacroArgumentReference>()); } -void CppSourceProcessor::failedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charOffset, +void CppSourceProcessor::failedMacroDefinitionCheck(int bytesOffset, int utf16charOffset, const ByteArrayRef &name) { if (!m_currentDoc) @@ -346,8 +346,8 @@ void CppSourceProcessor::failedMacroDefinitionCheck(unsigned bytesOffset, unsign bytesOffset, utf16charOffset); } -void CppSourceProcessor::notifyMacroReference(unsigned bytesOffset, unsigned utf16charOffset, - unsigned line, const CPlusPlus::Macro ¯o) +void CppSourceProcessor::notifyMacroReference(int bytesOffset, int utf16charOffset, + int line, const CPlusPlus::Macro ¯o) { if (!m_currentDoc) return; @@ -358,8 +358,8 @@ void CppSourceProcessor::notifyMacroReference(unsigned bytesOffset, unsigned utf line, QVector<MacroArgumentReference>()); } -void CppSourceProcessor::startExpandingMacro(unsigned bytesOffset, unsigned utf16charOffset, - unsigned line, const CPlusPlus::Macro ¯o, +void CppSourceProcessor::startExpandingMacro(int bytesOffset, int utf16charOffset, + int line, const CPlusPlus::Macro ¯o, const QVector<MacroArgumentReference> &actuals) { if (!m_currentDoc) @@ -371,7 +371,7 @@ void CppSourceProcessor::startExpandingMacro(unsigned bytesOffset, unsigned utf1 line, actuals); } -void CppSourceProcessor::stopExpandingMacro(unsigned, const CPlusPlus::Macro &) +void CppSourceProcessor::stopExpandingMacro(int, const CPlusPlus::Macro &) { if (!m_currentDoc) return; @@ -409,19 +409,19 @@ void CppSourceProcessor::mergeEnvironment(Document::Ptr doc) m_env.addMacros(doc->definedMacros()); } -void CppSourceProcessor::startSkippingBlocks(unsigned utf16charsOffset) +void CppSourceProcessor::startSkippingBlocks(int utf16charsOffset) { if (m_currentDoc) m_currentDoc->startSkippingBlocks(utf16charsOffset); } -void CppSourceProcessor::stopSkippingBlocks(unsigned utf16charsOffset) +void CppSourceProcessor::stopSkippingBlocks(int utf16charsOffset) { if (m_currentDoc) m_currentDoc->stopSkippingBlocks(utf16charsOffset); } -void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, IncludeType type, +void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, IncludeType type, const QStringList &initialIncludes) { if (fileName.isEmpty()) diff --git a/src/plugins/cpptools/cppsourceprocessor.h b/src/plugins/cpptools/cppsourceprocessor.h index de6ea7928a..faa5a266c8 100644 --- a/src/plugins/cpptools/cppsourceprocessor.h +++ b/src/plugins/cpptools/cppsourceprocessor.h @@ -93,20 +93,20 @@ private: // Client interface void macroAdded(const CPlusPlus::Macro ¯o) override; - void passedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset, - unsigned line, const CPlusPlus::Macro ¯o) override; - void failedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charOffset, + void passedMacroDefinitionCheck(int bytesOffset, int utf16charsOffset, + int line, const CPlusPlus::Macro ¯o) override; + void failedMacroDefinitionCheck(int bytesOffset, int utf16charOffset, const CPlusPlus::ByteArrayRef &name) override; - void notifyMacroReference(unsigned bytesOffset, unsigned utf16charOffset, - unsigned line, const CPlusPlus::Macro ¯o) override; - void startExpandingMacro(unsigned bytesOffset, unsigned utf16charOffset, - unsigned line, const CPlusPlus::Macro ¯o, + void notifyMacroReference(int bytesOffset, int utf16charOffset, + int line, const CPlusPlus::Macro ¯o) override; + void startExpandingMacro(int bytesOffset, int utf16charOffset, + int line, const CPlusPlus::Macro ¯o, const QVector<CPlusPlus::MacroArgumentReference> &actuals) override; - void stopExpandingMacro(unsigned bytesOffset, const CPlusPlus::Macro ¯o) override; + void stopExpandingMacro(int bytesOffset, const CPlusPlus::Macro ¯o) override; void markAsIncludeGuard(const QByteArray ¯oName) override; - void startSkippingBlocks(unsigned utf16charsOffset) override; - void stopSkippingBlocks(unsigned utf16charsOffset) override; - void sourceNeeded(unsigned line, const QString &fileName, IncludeType type, + void startSkippingBlocks(int utf16charsOffset) override; + void stopSkippingBlocks(int utf16charsOffset) override; + void sourceNeeded(int line, const QString &fileName, IncludeType type, const QStringList &initialIncludes) override; private: diff --git a/src/plugins/cpptools/cppsourceprocessor_test.cpp b/src/plugins/cpptools/cppsourceprocessor_test.cpp index 009264cc3c..67a1b9f702 100644 --- a/src/plugins/cpptools/cppsourceprocessor_test.cpp +++ b/src/plugins/cpptools/cppsourceprocessor_test.cpp @@ -179,11 +179,11 @@ void CppToolsPlugin::test_cppsourceprocessor_macroUses() const QList<Document::MacroUse> macroUses = document->macroUses(); QCOMPARE(macroUses.size(), 1); const Document::MacroUse macroUse = macroUses.at(0); - QCOMPARE(macroUse.bytesBegin(), 25U); - QCOMPARE(macroUse.bytesEnd(), 35U); - QCOMPARE(macroUse.utf16charsBegin(), 25U); - QCOMPARE(macroUse.utf16charsEnd(), 35U); - QCOMPARE(macroUse.beginLine(), 2U); + QCOMPARE(macroUse.bytesBegin(), 25); + QCOMPARE(macroUse.bytesEnd(), 35); + QCOMPARE(macroUse.utf16charsBegin(), 25); + QCOMPARE(macroUse.utf16charsEnd(), 35); + QCOMPARE(macroUse.beginLine(), 2); } static bool isMacroDefinedInDocument(const QByteArray ¯oName, const Document::Ptr &document) diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 04b7ce1adc..970c8fdbd7 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -53,8 +53,8 @@ HEADERS += \ cpppointerdeclarationformatter.h \ cppprojectfile.h \ cppprojectupdater.h \ + cppprojectupdaterinterface.h \ cppqtstyleindenter.h \ - cpprawprojectpart.h \ cpprefactoringchanges.h \ cpprefactoringengine.h \ cppselectionchanger.h \ @@ -104,7 +104,6 @@ HEADERS += \ cppmodelmanagerinterface.h \ cppbuiltinmodelmanagersupport.h \ headerpathfilter.h \ - cppkitinfo.h \ cpptools_clazychecks.h SOURCES += \ @@ -155,7 +154,6 @@ SOURCES += \ cppprojectfile.cpp \ cppprojectupdater.cpp \ cppqtstyleindenter.cpp \ - cpprawprojectpart.cpp \ cpprefactoringchanges.cpp \ cpprefactoringengine.cpp \ cppselectionchanger.cpp \ @@ -192,8 +190,7 @@ SOURCES += \ cppprojectpartchooser.cpp \ wrappablelineedit.cpp \ cppbuiltinmodelmanagersupport.cpp \ - headerpathfilter.cpp \ - cppkitinfo.cpp + headerpathfilter.cpp FORMS += \ clangdiagnosticconfigswidget.ui \ @@ -227,6 +224,3 @@ equals(TEST, 1) { DEFINES += SRCDIR=\\\"$$PWD\\\" } - -RESOURCES += \ - cpptools.qrc diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index 85e086ddf9..8446281281 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -116,8 +116,6 @@ Project { "cppincludesfilter.h", "cppindexingsupport.cpp", "cppindexingsupport.h", - "cppkitinfo.cpp", - "cppkitinfo.h", "cpplocalsymbols.cpp", "cpplocalsymbols.h", "cpplocatordata.cpp", @@ -142,10 +140,9 @@ Project { "cppprojectpartchooser.h", "cppprojectupdater.cpp", "cppprojectupdater.h", + "cppprojectupdaterinterface.h", "cppqtstyleindenter.cpp", "cppqtstyleindenter.h", - "cpprawprojectpart.cpp", - "cpprawprojectpart.h", "cpprefactoringchanges.cpp", "cpprefactoringchanges.h", "cpprefactoringengine.cpp", @@ -157,7 +154,6 @@ Project { "cppsemanticinfoupdater.h", "cppsourceprocessor.cpp", "cppsourceprocessor.h", - "cpptools.qrc", "cpptools_clangtidychecks.h", "cpptools_clazychecks.h", "cpptools_global.h", diff --git a/src/plugins/cpptools/cpptools.qrc b/src/plugins/cpptools/cpptools.qrc deleted file mode 100644 index 7ba7243975..0000000000 --- a/src/plugins/cpptools/cpptools.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/cpptools"> - <file>images/settingscategory_cpp.png</file> - <file>images/settingscategory_cpp@2x.png</file> - </qresource> -</RCC> diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h index 8490f2ccf5..f62a06dee2 100644 --- a/src/plugins/cpptools/cpptoolsconstants.h +++ b/src/plugins/cpptools/cpptoolsconstants.h @@ -43,6 +43,7 @@ const char OBJECTIVE_CPP_SOURCE_MIMETYPE[] = "text/x-objc++src"; const char CPP_HEADER_MIMETYPE[] = "text/x-c++hdr"; const char QDOC_MIMETYPE[] = "text/x-qdoc"; const char MOC_MIMETYPE[] = "text/x-moc"; +const char AMBIGUOUS_HEADER_MIMETYPE[] = "application/vnd.qtc.ambiguousheader"; // not a real MIME type // QSettings keys for use by the "New Class" wizards. const char CPPTOOLS_SETTINGSGROUP[] = "CppTools"; diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index be52ced3f1..d0d486e201 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -23,31 +23,33 @@ ** ****************************************************************************/ -#include "cpptoolsconstants.h" #include "cpptoolsplugin.h" -#include "cppfilesettingspage.h" #include "cppcodemodelsettingspage.h" #include "cppcodestylesettingspage.h" +#include "cppfilesettingspage.h" #include "cppmodelmanager.h" -#include "cpptoolsjsextension.h" -#include "cpptoolssettings.h" -#include "cpptoolsreuse.h" #include "cppprojectfile.h" +#include "cppprojectupdater.h" #include "cpptoolsbridge.h" +#include "cpptoolsbridgeqtcreatorimplementation.h" +#include "cpptoolsconstants.h" +#include "cpptoolsjsextension.h" +#include "cpptoolsreuse.h" +#include "cpptoolssettings.h" #include "projectinfo.h" #include "stringtable.h" -#include "cpptoolsbridgeqtcreatorimplementation.h" #include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actionmanager.h> -#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/coreconstants.h> #include <coreplugin/documentmanager.h> +#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/icore.h> #include <coreplugin/idocument.h> #include <coreplugin/jsexpander.h> #include <coreplugin/vcsmanager.h> #include <cppeditor/cppeditorconstants.h> +#include <extensionsystem/pluginmanager.h> #include <projectexplorer/project.h> #include <projectexplorer/projecttree.h> @@ -97,6 +99,7 @@ public: delete m_cppCodeModelSettingsPage; if (m_cppCodeStyleSettingsPage) delete m_cppCodeStyleSettingsPage; + ExtensionSystem::PluginManager::removeObject(&m_cppProjectUpdaterFactory); } QSharedPointer<CppCodeModelSettings> m_codeModelSettings; @@ -104,6 +107,7 @@ public: CppFileSettingsPage *m_cppFileSettingsPage = nullptr; CppCodeModelSettingsPage *m_cppCodeModelSettingsPage = nullptr; QPointer<CppCodeStyleSettingsPage> m_cppCodeStyleSettingsPage = nullptr; + CppProjectUpdaterFactory m_cppProjectUpdaterFactory; }; CppToolsPlugin::CppToolsPlugin() @@ -173,6 +177,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) d = new CppToolsPluginPrivate; JsExpander::registerGlobalObject<CppToolsJsExtension>("Cpp"); + ExtensionSystem::PluginManager::addObject(&d->m_cppProjectUpdaterFactory); // Menus ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS); diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index d319c9eb1e..8035c08785 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -159,6 +159,8 @@ private slots: void test_cpplocatorfilters_CppLocatorFilter(); void test_cpplocatorfilters_CppLocatorFilter_data(); void test_cpplocatorfilters_CppCurrentDocumentFilter(); + void test_cpplocatorfilters_CppCurrentDocumentHighlighting(); + void test_cpplocatorfilters_CppFunctionsFilterHighlighting(); void test_builtinsymbolsearcher(); void test_builtinsymbolsearcher_data(); diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp index 22e2567b44..b9ba701aeb 100644 --- a/src/plugins/cpptools/cpptoolstestcase.cpp +++ b/src/plugins/cpptools/cpptoolstestcase.cpp @@ -291,7 +291,7 @@ ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool config Project *project = result.project(); if (configureAsExampleProject) - project->configureAsExampleProject({ }); + project->configureAsExampleProject(); if (TestCase::waitUntilCppModelManagerIsAwareOf(project)) { m_openProjects.append(project); diff --git a/src/plugins/cpptools/cppworkingcopy.h b/src/plugins/cpptools/cppworkingcopy.h index 1477720553..1dd1c719d2 100644 --- a/src/plugins/cpptools/cppworkingcopy.h +++ b/src/plugins/cpptools/cppworkingcopy.h @@ -70,14 +70,14 @@ public: QPair<QByteArray, unsigned> get(const Utils::FilePath &fileName) const { return _elements.value(fileName); } - QHashIterator<Utils::FilePath, QPair<QByteArray, unsigned> > iterator() const - { return QHashIterator<Utils::FilePath, QPair<QByteArray, unsigned> >(_elements); } + using Table = QHash<Utils::FilePath, QPair<QByteArray, unsigned> >; + const Table &elements() const + { return _elements; } int size() const { return _elements.size(); } private: - using Table = QHash<Utils::FilePath, QPair<QByteArray, unsigned> >; Table _elements; }; diff --git a/src/plugins/cpptools/doxygengenerator.cpp b/src/plugins/cpptools/doxygengenerator.cpp index c11cb4d7cb..702f92e524 100644 --- a/src/plugins/cpptools/doxygengenerator.cpp +++ b/src/plugins/cpptools/doxygengenerator.cpp @@ -108,6 +108,10 @@ QString DoxygenGenerator::generate(QTextCursor cursor, return QString(); QString declCandidate = cursor.selectedText(); + + if (declCandidate.startsWith(QLatin1String("Q_INVOKABLE"))) + declCandidate = declCandidate.mid(11); + declCandidate.replace(QChar::ParagraphSeparator, QLatin1Char('\n')); // Let's append a closing brace in the case we got content like 'class MyType {' diff --git a/src/plugins/cpptools/headerpathfilter.cpp b/src/plugins/cpptools/headerpathfilter.cpp index e2d1e6a4ca..d401f547f5 100644 --- a/src/plugins/cpptools/headerpathfilter.cpp +++ b/src/plugins/cpptools/headerpathfilter.cpp @@ -86,8 +86,8 @@ QString clangIncludeDirectory(const QString &clangVersion, const QString &clangR #ifndef UNIT_TESTS return Core::ICore::clangIncludeDirectory(clangVersion, clangResourceDirectory); #else - Q_UNUSED(clangVersion); - Q_UNUSED(clangResourceDirectory); + Q_UNUSED(clangVersion) + Q_UNUSED(clangResourceDirectory) return CLANG_RESOURCE_DIR; #endif } diff --git a/src/plugins/cpptools/images/settingscategory_cpp.png b/src/plugins/cpptools/images/settingscategory_cpp.png Binary files differdeleted file mode 100644 index fe39d2663c..0000000000 --- a/src/plugins/cpptools/images/settingscategory_cpp.png +++ /dev/null diff --git a/src/plugins/cpptools/images/settingscategory_cpp@2x.png b/src/plugins/cpptools/images/settingscategory_cpp@2x.png Binary files differdeleted file mode 100644 index 92078c4281..0000000000 --- a/src/plugins/cpptools/images/settingscategory_cpp@2x.png +++ /dev/null diff --git a/src/plugins/cpptools/includeutils.cpp b/src/plugins/cpptools/includeutils.cpp index c57366332c..c42b104acf 100644 --- a/src/plugins/cpptools/includeutils.cpp +++ b/src/plugins/cpptools/includeutils.cpp @@ -319,7 +319,7 @@ QList<IncludeGroup> IncludeGroup::detectIncludeGroupsByNewLines(QList<Document:: { // Create groups QList<IncludeGroup> result; - unsigned lastLine = 0; + int lastLine = 0; QList<Include> currentIncludes; bool isFirst = true; foreach (const Include &include, includes) { diff --git a/src/plugins/cpptools/insertionpointlocator.cpp b/src/plugins/cpptools/insertionpointlocator.cpp index e6db241d79..c92d8bbca8 100644 --- a/src/plugins/cpptools/insertionpointlocator.cpp +++ b/src/plugins/cpptools/insertionpointlocator.cpp @@ -58,7 +58,7 @@ static int ordering(InsertionPointLocator::AccessSpec xsSpec) struct AccessRange { - unsigned start = 0; + int start = 0; unsigned end = 0; InsertionPointLocator::AccessSpec xsSpec = InsertionPointLocator::Invalid; unsigned colonToken = 0; @@ -119,7 +119,7 @@ protected: bool needsSuffix = false; findMatch(ranges, _xsSpec, beforeToken, needsLeadingEmptyLine, needsPrefix, needsSuffix); - unsigned line = 0, column = 0; + int line = 0, column = 0; getTokenStartPosition(beforeToken, &line, &column); QString prefix; @@ -253,7 +253,7 @@ InsertionLocation::InsertionLocation() = default; InsertionLocation::InsertionLocation(const QString &fileName, const QString &prefix, const QString &suffix, - unsigned line, unsigned column) + int line, int column) : m_fileName(fileName) , m_prefix(prefix) , m_suffix(suffix) @@ -350,7 +350,7 @@ public: : ASTVisitor(translationUnit) {} - void operator()(Symbol *decl, unsigned *line, unsigned *column) + void operator()(Symbol *decl, int *line, int *column) { // default to end of file const unsigned lastToken = translationUnit()->ast()->lastToken(); @@ -408,15 +408,15 @@ protected: class FindFunctionDefinition : protected ASTVisitor { FunctionDefinitionAST *_result = nullptr; - unsigned _line = 0; - unsigned _column = 0; + int _line = 0; + int _column = 0; public: explicit FindFunctionDefinition(TranslationUnit *translationUnit) : ASTVisitor(translationUnit) { } - FunctionDefinitionAST *operator()(unsigned line, unsigned column) + FunctionDefinitionAST *operator()(int line, int column) { _result = nullptr; _line = line; @@ -430,7 +430,7 @@ protected: { if (_result) return false; - unsigned line, column; + int line, column; translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column); if (line > _line || (line == _line && column > _column)) return false; @@ -473,7 +473,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, // find the index of declaration int declIndex = -1; - for (unsigned i = 0; i < klass->memberCount(); ++i) { + for (int i = 0; i < klass->memberCount(); ++i) { Symbol *s = klass->memberAt(i); if (s == declaration) { declIndex = i; @@ -505,7 +505,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, } if (!definitionFunction) { // try to find one below - for (unsigned i = declIndex + 1; i < klass->memberCount(); ++i) { + for (int i = declIndex + 1; i < klass->memberCount(); ++i) { Symbol *s = klass->memberAt(i); surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s); if (!surroundingFunctionDecl) @@ -526,7 +526,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, if (!definitionFunction) return noResult; - unsigned line, column; + int line, column; if (suffix.isEmpty()) { Document::Ptr targetDoc = changes.snapshot().document(QString::fromUtf8(definitionFunction->fileName())); if (!targetDoc) @@ -586,7 +586,7 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(Symbol *declara if (doc.isNull()) return result; - unsigned line = 0, column = 0; + int line = 0, column = 0; FindMethodDefinitionInsertPoint finder(doc->translationUnit()); finder(declaration, &line, &column); diff --git a/src/plugins/cpptools/insertionpointlocator.h b/src/plugins/cpptools/insertionpointlocator.h index c05bc0f6ff..a54f988241 100644 --- a/src/plugins/cpptools/insertionpointlocator.h +++ b/src/plugins/cpptools/insertionpointlocator.h @@ -35,7 +35,7 @@ class CPPTOOLS_EXPORT InsertionLocation public: InsertionLocation(); InsertionLocation(const QString &fileName, const QString &prefix, - const QString &suffix, unsigned line, unsigned column); + const QString &suffix, int line, int column); QString fileName() const { return m_fileName; } @@ -49,11 +49,11 @@ public: { return m_suffix; } /// \returns The line where to insert. The line number is 1-based. - unsigned line() const + int line() const { return m_line; } /// \returns The column where to insert. The column number is 1-based. - unsigned column() const + int column() const { return m_column; } bool isValid() const @@ -63,8 +63,8 @@ private: QString m_fileName; QString m_prefix; QString m_suffix; - unsigned m_line = 0; - unsigned m_column = 0; + int m_line = 0; + int m_column = 0; }; class CPPTOOLS_EXPORT InsertionPointLocator diff --git a/src/plugins/cpptools/projectinfo.cpp b/src/plugins/cpptools/projectinfo.cpp index 1cc5515eb9..a7047dc972 100644 --- a/src/plugins/cpptools/projectinfo.cpp +++ b/src/plugins/cpptools/projectinfo.cpp @@ -25,47 +25,14 @@ #include "projectinfo.h" -#include "cppkitinfo.h" - #include <projectexplorer/abi.h> -#include <projectexplorer/toolchain.h> #include <projectexplorer/kitinformation.h> #include <projectexplorer/projectexplorerconstants.h> +#include <projectexplorer/rawprojectpart.h> +#include <projectexplorer/toolchain.h> namespace CppTools { -ToolChainInfo::ToolChainInfo(const ProjectExplorer::ToolChain *toolChain, - const QString &sysRootPath) -{ - if (toolChain) { - // Keep the following cheap/non-blocking for the ui thread... - type = toolChain->typeId(); - isMsvc2015ToolChain - = toolChain->targetAbi().osFlavor() == ProjectExplorer::Abi::WindowsMsvc2015Flavor; - wordWidth = toolChain->targetAbi().wordWidth(); - targetTriple = toolChain->originalTargetTriple(); - extraCodeModelFlags = toolChain->extraCodeModelFlags(); - - // ...and save the potentially expensive operations for later so that - // they can be run from a worker thread. - this->sysRootPath = sysRootPath; - headerPathsRunner = toolChain->createBuiltInHeaderPathsRunner(); - macroInspectionRunner = toolChain->createMacroInspectionRunner(); - } -} - -ProjectUpdateInfo::ProjectUpdateInfo(ProjectExplorer::Project *project, - const KitInfo &kitInfo, - const RawProjectParts &rawProjectParts) - : project(project) - , rawProjectParts(rawProjectParts) - , cToolChain(kitInfo.cToolChain) - , cxxToolChain(kitInfo.cxxToolChain) - , cToolChainInfo(ToolChainInfo(cToolChain, kitInfo.sysRootPath)) - , cxxToolChainInfo(ToolChainInfo(cxxToolChain, kitInfo.sysRootPath)) -{ -} - ProjectInfo::ProjectInfo(QPointer<ProjectExplorer::Project> project) : m_project(project) { diff --git a/src/plugins/cpptools/projectinfo.h b/src/plugins/cpptools/projectinfo.h index c934bda2d5..347e72f477 100644 --- a/src/plugins/cpptools/projectinfo.h +++ b/src/plugins/cpptools/projectinfo.h @@ -27,10 +27,10 @@ #include "cpptools_global.h" -#include "cpprawprojectpart.h" #include "projectpart.h" #include <projectexplorer/project.h> +#include <projectexplorer/rawprojectpart.h> #include <projectexplorer/toolchain.h> #include <QHash> @@ -40,49 +40,6 @@ namespace CppTools { -class KitInfo; - -class ToolChainInfo -{ -public: - ToolChainInfo() = default; - ToolChainInfo(const ProjectExplorer::ToolChain *toolChain, - const QString &sysRootPath); - - bool isValid() const { return type.isValid(); } - -public: - Core::Id type; - bool isMsvc2015ToolChain = false; - unsigned wordWidth = 0; - QString targetTriple; - QStringList extraCodeModelFlags; - - QString sysRootPath; // For headerPathsRunner. - ProjectExplorer::ToolChain::BuiltInHeaderPathsRunner headerPathsRunner; - ProjectExplorer::ToolChain::MacroInspectionRunner macroInspectionRunner; -}; - -class CPPTOOLS_EXPORT ProjectUpdateInfo -{ -public: - ProjectUpdateInfo() = default; - ProjectUpdateInfo(ProjectExplorer::Project *project, - const KitInfo &kitInfo, - const RawProjectParts &rawProjectParts); - bool isValid() const { return project && !rawProjectParts.isEmpty(); } - -public: - QPointer<ProjectExplorer::Project> project; - QVector<RawProjectPart> rawProjectParts; - - const ProjectExplorer::ToolChain *cToolChain = nullptr; - const ProjectExplorer::ToolChain *cxxToolChain = nullptr; - - ToolChainInfo cToolChainInfo; - ToolChainInfo cxxToolChainInfo; -}; - class CPPTOOLS_EXPORT ProjectInfo { public: diff --git a/src/plugins/cpptools/projectpart.cpp b/src/plugins/cpptools/projectpart.cpp index 4569f231d1..f88fefac82 100644 --- a/src/plugins/cpptools/projectpart.cpp +++ b/src/plugins/cpptools/projectpart.cpp @@ -36,8 +36,9 @@ namespace CppTools { void ProjectPart::updateLanguageFeatures() { const bool hasCxx = languageVersion >= Utils::LanguageVersion::CXX98; - const bool hasQt = hasCxx && qtVersion != NoQt; + const bool hasQt = hasCxx && qtVersion != Utils::QtVersion::None; languageFeatures.cxx11Enabled = languageVersion >= Utils::LanguageVersion::CXX11; + languageFeatures.cxx14Enabled = languageVersion >= Utils::LanguageVersion::CXX14; languageFeatures.cxxEnabled = hasCxx; languageFeatures.c99Enabled = languageVersion >= Utils::LanguageVersion::C99; languageFeatures.objCEnabled = languageExtensions.testFlag(Utils::LanguageExtension::ObjectiveC); diff --git a/src/plugins/cpptools/projectpart.h b/src/plugins/cpptools/projectpart.h index 71df5e1ee5..f7a872e2a1 100644 --- a/src/plugins/cpptools/projectpart.h +++ b/src/plugins/cpptools/projectpart.h @@ -29,9 +29,11 @@ #include "cppprojectfile.h" +#include <projectexplorer/buildtargettype.h> #include <projectexplorer/headerpath.h> #include <projectexplorer/projectexplorer_global.h> #include <projectexplorer/projectmacro.h> +#include <projectexplorer/rawprojectpart.h> #include <coreplugin/id.h> @@ -53,24 +55,11 @@ namespace CppTools { class CPPTOOLS_EXPORT ProjectPart { public: - enum QtVersion { - UnknownQt = -1, - NoQt, - Qt4, - Qt5 - }; - enum ToolChainWordWidth { WordWidth32Bit, WordWidth64Bit, }; - enum BuildTargetType { - Unknown, - Executable, - Library - }; - using Ptr = QSharedPointer<ProjectPart>; public: @@ -97,7 +86,7 @@ public: ::Utils::LanguageVersion languageVersion = ::Utils::LanguageVersion::LatestCxx; ::Utils::LanguageExtensions languageExtensions = ::Utils::LanguageExtension::None; CPlusPlus::LanguageFeatures languageFeatures; - QtVersion qtVersion = UnknownQt; + ::Utils::QtVersion qtVersion = ::Utils::QtVersion::Unknown; // Files ProjectFiles files; @@ -111,7 +100,7 @@ public: // Build system QString buildSystemTarget; - BuildTargetType buildTargetType = Unknown; + ProjectExplorer::BuildTargetType buildTargetType = ProjectExplorer::BuildTargetType::Unknown; bool selectedForBuilding = true; // ToolChain diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp index 6adb437bf8..05080fdb87 100644 --- a/src/plugins/cpptools/searchsymbols.cpp +++ b/src/plugins/cpptools/searchsymbols.cpp @@ -70,7 +70,7 @@ IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->fileName()), return IndexItem::Ptr()); - for (unsigned i = 0, ei = doc->globalSymbolCount(); i != ei; ++i) + for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i) accept(doc->globalSymbolAt(i)); Internal::StringTable::scheduleGC(); @@ -95,7 +95,7 @@ bool SearchSymbols::visit(Enum *symbol) QString newScope = scopedSymbolName(name, symbol); ScopedScope scopeRaii(_scope, newScope); - for (unsigned i = 0, ei = symbol->memberCount(); i != ei; ++i) + for (int i = 0, ei = symbol->memberCount(); i != ei; ++i) accept(symbol->memberAt(i)); return false; @@ -112,7 +112,7 @@ bool SearchSymbols::visit(Namespace *symbol) QString name = scopedSymbolName(symbol); QString newScope = name; ScopedScope raii(_scope, newScope); - for (unsigned i = 0; i < symbol->memberCount(); ++i) { + for (int i = 0; i < symbol->memberCount(); ++i) { accept(symbol->memberAt(i)); } return false; @@ -321,7 +321,7 @@ void SearchSymbols::processClass(T *clazz) QString newScope = scopedSymbolName(name, clazz); ScopedScope scopeRaii(_scope, newScope); - for (unsigned i = 0, ei = clazz->memberCount(); i != ei; ++i) + for (int i = 0, ei = clazz->memberCount(); i != ei; ++i) accept(clazz->memberAt(i)); } diff --git a/src/plugins/cpptools/symbolsfindfilter.cpp b/src/plugins/cpptools/symbolsfindfilter.cpp index 404a4209a6..3cba030352 100644 --- a/src/plugins/cpptools/symbolsfindfilter.cpp +++ b/src/plugins/cpptools/symbolsfindfilter.cpp @@ -263,7 +263,7 @@ SymbolsFindFilterConfigWidget::SymbolsFindFilterConfigWidget(SymbolsFindFilter * auto layout = new QGridLayout(this); setLayout(layout); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); auto typeLabel = new QLabel(tr("Types:")); layout->addWidget(typeLabel, 0, 0); diff --git a/src/plugins/cpptools/typehierarchybuilder.cpp b/src/plugins/cpptools/typehierarchybuilder.cpp index aee41076d7..b0a31ad62a 100644 --- a/src/plugins/cpptools/typehierarchybuilder.cpp +++ b/src/plugins/cpptools/typehierarchybuilder.cpp @@ -71,13 +71,13 @@ void DerivedHierarchyVisitor::execute(const CPlusPlus::Document::Ptr &doc, _otherBases.clear(); _context = CPlusPlus::LookupContext(doc, snapshot); - for (unsigned i = 0; i < doc->globalSymbolCount(); ++i) + for (int i = 0; i < doc->globalSymbolCount(); ++i) accept(doc->globalSymbolAt(i)); } bool DerivedHierarchyVisitor::visit(CPlusPlus::Class *symbol) { - for (unsigned i = 0; i < symbol->baseClassCount(); ++i) { + for (int i = 0; i < symbol->baseClassCount(); ++i) { CPlusPlus::BaseClass *baseSymbol = symbol->baseClassAt(i); QString baseName = _actualBases.value(baseSymbol); diff --git a/src/plugins/cpptools/usages.h b/src/plugins/cpptools/usages.h index 1e0f502c5e..3248fc4e90 100644 --- a/src/plugins/cpptools/usages.h +++ b/src/plugins/cpptools/usages.h @@ -51,6 +51,12 @@ public: && first.path == second.path; } + friend bool operator<(const Usage &first, const Usage &second) + { + return std::tie(first.path, first.line, first.column) + < std::tie(second.path, second.line, second.column); + } + public: QString path; int line = 0; |