Commit 07b3f65a authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: Remove unused code



Change-Id: I1fa597d1cd582f8eb4a37c3bbb963441696e9f4a
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent aa901845
......@@ -13,7 +13,6 @@ unix:QMAKE_LFLAGS += -Wl,-rpath,\'$$LLVM_LIBDIR\'
SOURCES += \
$$PWD/clangcodemodelplugin.cpp \
$$PWD/clangcompleter.cpp \
$$PWD/clangcompletioncontextanalyzer.cpp \
$$PWD/clangcompletion.cpp \
$$PWD/clangeditordocumentparser.cpp \
......@@ -24,7 +23,6 @@ SOURCES += \
$$PWD/clangutils.cpp \
$$PWD/clangbackendipcintegration.cpp \
$$PWD/completionchunkstotextconverter.cpp \
$$PWD/completionproposalsbuilder.cpp \
$$PWD/cppcreatemarkers.cpp \
$$PWD/cxprettyprinter.cpp \
$$PWD/diagnostic.cpp \
......@@ -43,7 +41,6 @@ SOURCES += \
HEADERS += \
$$PWD/clangcodemodelplugin.h \
$$PWD/clangcompleter.h \
$$PWD/clangcompletioncontextanalyzer.h \
$$PWD/clangcompletion.h \
$$PWD/clangeditordocumentparser.h \
......@@ -55,7 +52,6 @@ HEADERS += \
$$PWD/clangutils.h \
$$PWD/clangbackendipcintegration.h \
$$PWD/completionchunkstotextconverter.h \
$$PWD/completionproposalsbuilder.h \
$$PWD/constants.h \
$$PWD/cppcreatemarkers.h \
$$PWD/cxprettyprinter.h \
......@@ -96,14 +92,12 @@ equals(TEST, 1) {
HEADERS += \
$$PWD/test/clangcodecompletion_test.h \
$$PWD/test/clangcompletioncontextanalyzertest.h \
$$PWD/test/completiontesthelper.h
$$PWD/test/clangcompletioncontextanalyzertest.h
SOURCES += \
$$PWD/test/clangcodecompletion_test.cpp \
$$PWD/test/clangcompletioncontextanalyzertest.cpp \
$$PWD/test/clangcompletion_test.cpp \
$$PWD/test/completiontesthelper.cpp
$$PWD/test/clangcompletioncontextanalyzertest.cpp
DISTFILES += \
$$PWD/test/mysource.cpp \
......@@ -112,23 +106,7 @@ equals(TEST, 1) {
$$PWD/test/memberCompletion.cpp \
$$PWD/test/doxygenKeywordsCompletion.cpp \
$$PWD/test/preprocessorKeywordsCompletion.cpp \
$$PWD/test/includeDirectiveCompletion.cpp \
$$PWD/test/cxx_regression_1.cpp \
$$PWD/test/cxx_regression_2.cpp \
$$PWD/test/cxx_regression_3.cpp \
$$PWD/test/cxx_regression_4.cpp \
$$PWD/test/cxx_regression_5.cpp \
$$PWD/test/cxx_regression_6.cpp \
$$PWD/test/cxx_regression_7.cpp \
$$PWD/test/cxx_regression_8.cpp \
$$PWD/test/cxx_regression_9.cpp \
$$PWD/test/cxx_snippets_1.cpp \
$$PWD/test/cxx_snippets_2.cpp \
$$PWD/test/cxx_snippets_3.cpp \
$$PWD/test/cxx_snippets_4.cpp \
$$PWD/test/objc_messages_1.mm \
$$PWD/test/objc_messages_2.mm \
$$PWD/test/objc_messages_3.mm
$$PWD/test/includeDirectiveCompletion.cpp
}
macx {
......
......@@ -53,12 +53,8 @@ QtcPlugin {
name: "Completion support"
condition: product.clangCompletion
files: [
"clangcompleter.cpp",
"clangcompleter.h",
"clangcompletion.cpp",
"clangcompletion.h",
"completionproposalsbuilder.cpp",
"completionproposalsbuilder.h",
]
}
......@@ -92,9 +88,6 @@ QtcPlugin {
prefix: "test/"
files: [
"clang_tests_database.qrc",
"clangcompletion_test.cpp",
"completiontesthelper.cpp",
"completiontesthelper.h",
"clangcodecompletion_test.cpp",
"clangcodecompletion_test.h",
"clangcompletioncontextanalyzertest.cpp",
......@@ -114,19 +107,6 @@ QtcPlugin {
"doxygenKeywordsCompletion.cpp",
"preprocessorKeywordsCompletion.cpp",
"includeDirectiveCompletion.cpp",
"cxx_regression_1.cpp",
"cxx_regression_2.cpp",
"cxx_regression_3.cpp",
"cxx_regression_4.cpp",
"cxx_regression_5.cpp",
"cxx_regression_6.cpp",
"cxx_regression_7.cpp",
"cxx_regression_8.cpp",
"cxx_regression_9.cpp",
"cxx_snippets_1.cpp",
"cxx_snippets_2.cpp",
"cxx_snippets_3.cpp",
"cxx_snippets_4.cpp",
"objc_messages_1.mm",
"objc_messages_2.mm",
"objc_messages_3.mm",
......
......@@ -61,14 +61,6 @@ private:
#ifdef WITH_TESTS
QList<QObject *> createTestObjects() const;
private slots:
void test_CXX_regressions();
void test_CXX_regressions_data();
void test_CXX_snippets();
void test_CXX_snippets_data();
void test_ObjC_hints();
void test_ObjC_hints_data();
#endif
};
......
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clangcompleter.h"
#include "sourcemarker.h"
#include "unsavedfiledata.h"
#include "utils_p.h"
#include "completionproposalsbuilder.h"
#include "raii/scopedclangoptions.h"
#include "unit.h"
#include <QDebug>
#include <QFile>
#include <QMutex>
#include <QMutexLocker>
#include <QTime>
#include <clang-c/Index.h>
//#define TIME_COMPLETION
using namespace ClangCodeModel::Internal;
namespace ClangCodeModel {
class ClangCompleter::PrivateData
{
public:
PrivateData()
: m_mutex(QMutex::Recursive)
, m_unit(Unit::create())
, m_isSignalSlotCompletion(false)
{
}
~PrivateData()
{
}
bool parseFromFile(const UnsavedFiles &unsavedFiles)
{
Q_ASSERT(!m_unit->isLoaded());
if (m_unit->fileName().isEmpty())
return false;
unsigned opts = clang_defaultEditingTranslationUnitOptions();
#if defined(CINDEX_VERSION) && (CINDEX_VERSION > 5)
opts |= CXTranslationUnit_CacheCompletionResults;
opts |= CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
#endif
m_unit->setManagementOptions(opts);
m_unit->setUnsavedFiles(unsavedFiles);
m_unit->parse();
return m_unit->isLoaded();
}
public:
QMutex m_mutex;
Unit::Ptr m_unit;
bool m_isSignalSlotCompletion;
};
/**
* @brief Constructs with highest possible priority
*/
CodeCompletionResult::CodeCompletionResult()
: m_priority(SHRT_MAX)
, m_completionKind(Other)
, m_availability(Available)
, m_hasParameters(false)
{}
/**
* @brief Constructs with given priority
* @param priority Will be reversed, because clang's highest priority is 0,
* but inside QtCreator it is the lowest priority
*/
CodeCompletionResult::CodeCompletionResult(unsigned priority)
: m_priority(SHRT_MAX - priority)
, m_completionKind(Other)
, m_availability(Available)
, m_hasParameters(false)
{
}
ClangCompleter::ClangCompleter()
: d(new PrivateData)
{
}
ClangCompleter::~ClangCompleter()
{
}
QString ClangCompleter::fileName() const
{
return d->m_unit->fileName();
}
void ClangCompleter::setFileName(const QString &fileName)
{
if (d->m_unit->fileName() != fileName) {
d->m_unit = Unit::create(fileName);
}
}
QStringList ClangCompleter::options() const
{
return d->m_unit->compilationOptions();
}
void ClangCompleter::setOptions(const QStringList &options) const
{
if (d->m_unit->compilationOptions() != options) {
d->m_unit->setCompilationOptions(options);
d->m_unit->unload();
}
}
bool ClangCompleter::isSignalSlotCompletion() const
{
return d->m_isSignalSlotCompletion;
}
void ClangCompleter::setSignalSlotCompletion(bool isSignalSlot)
{
d->m_isSignalSlotCompletion = isSignalSlot;
}
bool ClangCompleter::reparse(const UnsavedFiles &unsavedFiles)
{
if (!d->m_unit->isLoaded())
return d->parseFromFile(unsavedFiles);
d->m_unit->setUnsavedFiles(unsavedFiles);
d->m_unit->reparse();
return d->m_unit->isLoaded();
}
QList<CodeCompletionResult> ClangCompleter::codeCompleteAt(unsigned line,
unsigned column,
const UnsavedFiles &unsavedFiles)
{
#ifdef TIME_COMPLETION
QTime t;t.start();
#endif // TIME_COMPLETION
if (!d->m_unit->isLoaded())
if (!d->parseFromFile(unsavedFiles))
return QList<CodeCompletionResult>();
ScopedCXCodeCompleteResults results;
d->m_unit->setUnsavedFiles(unsavedFiles);
d->m_unit->codeCompleteAt(line, column, results);
QList<CodeCompletionResult> completions;
if (results) {
const quint64 contexts = clang_codeCompleteGetContexts(results);
CompletionProposalsBuilder builder(completions, contexts, d->m_isSignalSlotCompletion);
for (unsigned i = 0; i < results.size(); ++i)
builder(results.completionAt(i));
}
#ifdef TIME_COMPLETION
qDebug() << "Completion timing:" << completions.size() << "results in" << t.elapsed() << "ms.";
#endif // TIME_COMPLETION
return completions;
}
bool ClangCompleter::objcEnabled() const
{
static const QString objcppOption = QLatin1String("-ObjC++");
static const QString objcOption = QLatin1String("-ObjC");
QStringList options = d->m_unit->compilationOptions();
return options.contains(objcOption) || options.contains(objcppOption);
}
QMutex *ClangCompleter::mutex() const
{
return &d->m_mutex;
}
} // namespace ClangCodeModel
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGCOMPLETER_H
#define CLANGCOMPLETER_H
#include "clang_global.h"
#include "diagnostic.h"
#include "sourcelocation.h"
#include "utils.h"
#include <QList>
#include <QMap>
#include <QMutex>
#include <QPair>
#include <QSharedPointer>
#include <QString>
#include <QStringList>
#include <QVariant>
namespace ClangCodeModel {
class SourceMarker;
class CLANG_EXPORT CodeCompletionResult
{
public:
enum Kind {
Other = 0,
FunctionCompletionKind,
ConstructorCompletionKind,
DestructorCompletionKind,
VariableCompletionKind,
ClassCompletionKind,
EnumCompletionKind,
EnumeratorCompletionKind,
NamespaceCompletionKind,
PreProcessorCompletionKind,
SignalCompletionKind,
SlotCompletionKind,
ObjCMessageCompletionKind,
KeywordCompletionKind,
ClangSnippetKind
};
enum Availability {
Available,
Deprecated,
NotAvailable,
NotAccessible
};
public:
CodeCompletionResult();
CodeCompletionResult(unsigned priority);
unsigned priority() const
{ return m_priority; }
bool isValid() const
{ return !m_text.isEmpty(); }
QString text() const
{ return m_text; }
void setText(const QString &text)
{ m_text = text; }
QString hint() const
{ return m_hint; }
void setHint(const QString &hint)
{ m_hint = hint; }
QString snippet() const
{ return m_snippet; }
void setSnippet(const QString &snippet)
{ m_snippet = snippet; }
Kind completionKind() const
{ return m_completionKind; }
void setCompletionKind(Kind type)
{ m_completionKind = type; }
int compare(const CodeCompletionResult &other) const
{
if (m_priority < other.m_priority)
return -1;
else if (m_priority > other.m_priority)
return 1;
if (m_completionKind < other.m_completionKind)
return -1;
else if (m_completionKind > other.m_completionKind)
return 1;
if (m_text < other.m_text)
return -1;
else if (m_text > other.m_text)
return 1;
if (m_hint < other.m_hint)
return -1;
else if (m_hint > other.m_hint)
return 1;
if (!m_hasParameters && other.m_hasParameters)
return -1;
else if (m_hasParameters && !other.m_hasParameters)
return 1;
if (m_availability < other.m_availability)
return -1;
else if (m_availability > other.m_availability)
return 1;
return 0;
}
bool hasParameters() const
{ return m_hasParameters; }
void setHasParameters(bool hasParameters)
{ m_hasParameters = hasParameters; }
Availability availability() const
{ return m_availability; }
void setAvailability(Availability availability)
{ m_availability = availability; }
private:
unsigned m_priority;
Kind m_completionKind;
QString m_text;
QString m_hint;
QString m_snippet;
Availability m_availability;
bool m_hasParameters;
};
inline CLANG_EXPORT uint qHash(const CodeCompletionResult &ccr)
{ return ccr.completionKind() ^ qHash(ccr.text()); }
inline CLANG_EXPORT bool operator==(const CodeCompletionResult &ccr1, const CodeCompletionResult &ccr2)
{ return ccr1.compare(ccr2) == 0; }
inline CLANG_EXPORT bool operator<(const CodeCompletionResult &ccr1, const CodeCompletionResult &ccr2)
{
return ccr1.compare(ccr2) < 0;
}
class CLANG_EXPORT ClangCompleter
{
Q_DISABLE_COPY(ClangCompleter)
class PrivateData;
public: // data structures
typedef QSharedPointer<ClangCompleter> Ptr;
public: // methods
ClangCompleter();
~ClangCompleter();
QString fileName() const;
void setFileName(const QString &fileName);
QStringList options() const;
void setOptions(const QStringList &options) const;
bool isSignalSlotCompletion() const;
void setSignalSlotCompletion(bool isSignalSlot);
bool reparse(const Internal::UnsavedFiles &unsavedFiles);
/**
* Do code-completion at the specified position.
*
* \param line The line number on which to do code-completion. The first
* line of a file has line number 1.
* \param column The column number where to do code-completion. Column
* numbers start with 1.
*/
QList<CodeCompletionResult> codeCompleteAt(unsigned line,
unsigned column,
const Internal::UnsavedFiles &unsavedFiles);
bool objcEnabled() const;
QMutex *mutex() const;
private: // instance fields
QScopedPointer<PrivateData> d;
};
} // namespace Clang
Q_DECLARE_METATYPE(ClangCodeModel::CodeCompletionResult)
#endif // CLANGCOMPLETER_H
......@@ -31,9 +31,11 @@
#ifndef CPPEDITOR_INTERNAL_CLANGCOMPLETION_H
#define CPPEDITOR_INTERNAL_CLANGCOMPLETION_H
#include "clangcompleter.h"
#include "clangbackendipcintegration.h"
#include "pchinfo.h"
#include "utils.h"
#include <cpptools/cppcompletionassistprocessor.h>
#include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cppmodelmanager.h>
......
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the