forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/4.6'
Conflicts: src/plugins/coreplugin/locator/locator.cpp src/plugins/imageviewer/imageviewerplugin.cpp src/plugins/remotelinux/remotelinuxplugin.cpp src/tools/clangbackend/source/tokeninfo.cpp tests/unit/unittest/data/highlightingmarks.cpp Change-Id: I74cc3ba3a2836cb9d0e65d3380d8c4f88d720c67
This commit is contained in:
@@ -41,4 +41,9 @@ enum class PreferredTranslationUnit
|
||||
# define IS_PRETTY_DECL_SUPPORTED
|
||||
#endif
|
||||
|
||||
// CLANG-UPGRADE-CHECK: Remove IS_INVALIDDECL_SUPPORTED once we require clang >= 7.0
|
||||
#if defined(CINDEX_VERSION_HAS_ISINVALIDECL_BACKPORTED) || CINDEX_VERSION_MINOR >= 46
|
||||
# define IS_INVALIDDECL_SUPPORTED
|
||||
#endif
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -28,30 +28,74 @@
|
||||
#include "clangfilepath.h"
|
||||
|
||||
#include <utf8string.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static QList<QByteArray> splitArgs(QString &argsString)
|
||||
{
|
||||
QList<QByteArray> result;
|
||||
Utils::QtcProcess::ArgIterator it(&argsString);
|
||||
while (it.next())
|
||||
result.append(it.value().toUtf8());
|
||||
return result;
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
static QList<QByteArray> extraOptions(const char(&environment)[Size])
|
||||
{
|
||||
if (!qEnvironmentVariableIsSet(environment))
|
||||
return QList<QByteArray>();
|
||||
QString arguments = QString::fromLocal8Bit(qgetenv(environment));
|
||||
return splitArgs(arguments);
|
||||
}
|
||||
|
||||
static QList<QByteArray> extraClangCodeModelPrependOptions() {
|
||||
constexpr char ccmPrependOptions[] = "QTC_CLANG_CCM_CMD_PREPEND";
|
||||
static const QList<QByteArray> options = extraOptions(ccmPrependOptions);
|
||||
if (!options.isEmpty())
|
||||
qWarning() << "ClangCodeModel options are prepended with " << options;
|
||||
return options;
|
||||
}
|
||||
|
||||
static QList<QByteArray> extraClangCodeModelAppendOptions() {
|
||||
constexpr char ccmAppendOptions[] = "QTC_CLANG_CCM_CMD_APPEND";
|
||||
static const QList<QByteArray> options = extraOptions(ccmAppendOptions);
|
||||
if (!options.isEmpty())
|
||||
qWarning() << "ClangCodeModel options are appended with " << options;
|
||||
return options;
|
||||
}
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
CommandLineArguments::CommandLineArguments(const char *filePath,
|
||||
const Utf8StringVector &projectPartArguments,
|
||||
const Utf8StringVector &fileArguments,
|
||||
bool addVerboseOption)
|
||||
: m_prependArgs(extraClangCodeModelPrependOptions()),
|
||||
m_appendArgs(extraClangCodeModelAppendOptions())
|
||||
{
|
||||
const auto elementsToReserve = projectPartArguments.size()
|
||||
+ uint(fileArguments.size())
|
||||
+ (addVerboseOption ? 1 : 0);
|
||||
m_arguments.reserve(elementsToReserve);
|
||||
const int elementsToReserve = m_prependArgs.size()
|
||||
+ projectPartArguments.size()
|
||||
+ fileArguments.size()
|
||||
+ (addVerboseOption ? 1 : 0)
|
||||
+ m_appendArgs.size();
|
||||
m_arguments.reserve(static_cast<size_t>(elementsToReserve));
|
||||
|
||||
for (const auto &argument : m_prependArgs)
|
||||
m_arguments.push_back(argument.constData());
|
||||
for (const auto &argument : projectPartArguments)
|
||||
m_arguments.push_back(argument.constData());
|
||||
for (const auto &argument : fileArguments)
|
||||
m_arguments.push_back(argument.constData());
|
||||
if (addVerboseOption)
|
||||
m_arguments.push_back("-v");
|
||||
for (const auto &argument : m_appendArgs)
|
||||
m_arguments.push_back(argument.constData());
|
||||
m_nativeFilePath = FilePath::toNativeSeparators(Utf8String::fromUtf8(filePath));
|
||||
m_arguments.push_back(m_nativeFilePath.constData());
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
|
||||
private:
|
||||
Utf8String m_nativeFilePath;
|
||||
const QList<QByteArray> m_prependArgs;
|
||||
const QList<QByteArray> m_appendArgs;
|
||||
std::vector<const char *> m_arguments;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "sourcelocation.h"
|
||||
#include "sourcerange.h"
|
||||
|
||||
#include "clangbackend_global.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
@@ -103,6 +105,15 @@ bool Cursor::isDeclaration() const
|
||||
return clang_isDeclaration(kind());
|
||||
}
|
||||
|
||||
bool Cursor::isInvalidDeclaration() const
|
||||
{
|
||||
#ifdef IS_INVALIDDECL_SUPPORTED
|
||||
return clang_isInvalidDeclaration(cxCursor);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Cursor::isLocalVariable() const
|
||||
{
|
||||
switch (semanticParent().kind()) {
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
bool isStaticMethod() const;
|
||||
bool isCompoundType() const;
|
||||
bool isDeclaration() const;
|
||||
bool isInvalidDeclaration() const;
|
||||
bool isLocalVariable() const;
|
||||
bool isReference() const;
|
||||
bool isExpression() const;
|
||||
|
||||
@@ -100,6 +100,9 @@ SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit,
|
||||
const char *contents = clang_getFileContents(cxTranslationUnit, cxFile, nullptr);
|
||||
if (!contents)
|
||||
return;
|
||||
// (1) column in SourceLocation is the actual column shown by CppEditor.
|
||||
// (2) column in Clang is the utf8 byte offset from the beginning of the line.
|
||||
// Here we convert column from (2) to (1).
|
||||
column_ = static_cast<uint>(QString::fromUtf8(&contents[lineStart],
|
||||
static_cast<int>(column_)).size());
|
||||
}
|
||||
|
||||
@@ -330,8 +330,10 @@ void TokenInfo::typeKind(const Cursor &cursor)
|
||||
|
||||
void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion)
|
||||
{
|
||||
const CXCursorKind kind = cursor.kind();
|
||||
if (cursor.isInvalidDeclaration())
|
||||
return;
|
||||
|
||||
const CXCursorKind kind = cursor.kind();
|
||||
switch (kind) {
|
||||
case CXCursor_Destructor:
|
||||
case CXCursor_Constructor:
|
||||
|
||||
Reference in New Issue
Block a user