Clang: Add Declaration highlighting

We are adding declaration detection for function to the highligher on
user request. Other declaration will follow in separate patches.

Task-number: QTCREATORBUG-15564
Change-Id: I54e97c26425f8d6e9854547d50a9ac8fa076b4e8
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Marco Bubke
2016-03-03 13:02:29 +01:00
parent 2349b13ae5
commit f8e64a87bb
18 changed files with 413 additions and 230 deletions

View File

@@ -5,6 +5,7 @@ QtcLibrary {
Depends { name: "Qt.network" }
Depends { name: "Sqlite" }
Depends { name: "Utils" }
cpp.defines: base.concat("CLANGBACKENDIPC_BUILD_LIB")
cpp.includePaths: base.concat(".")
@@ -18,6 +19,7 @@ QtcLibrary {
Export {
Depends { name: "Sqlite" }
Depends { name: "Utils" }
Depends { name: "Qt.network" }
cpp.includePaths: [
"."

View File

@@ -1,3 +1,3 @@
QTC_LIB_NAME = Clangbackendipc
QTC_LIB_DEPENDS += sqlite
QTC_LIB_DEPENDS += sqlite utils
INCLUDEPATH *= $$IDE_SOURCE_TREE/src/libs/clangbackendipc

View File

@@ -26,6 +26,8 @@
#ifndef CLANGBACKENDIPC_GLOBAL_H
#define CLANGBACKENDIPC_GLOBAL_H
#include <utils/sizedarray.h>
#include <QtCore/qglobal.h>
#if defined(CLANGBACKENDIPC_BUILD_LIB)
@@ -51,7 +53,7 @@ enum class DiagnosticSeverity // one to one mapping of the clang enum numbers
Fatal = 4
};
enum class HighlightingType
enum class HighlightingType : quint8
{
Invalid,
Keyword,
@@ -70,7 +72,8 @@ enum class HighlightingType
PreprocessorDefinition,
PreprocessorExpansion,
Label,
OutputArgument
OutputArgument,
Declaration
};
enum class CompletionCorrection
@@ -123,5 +126,12 @@ struct MessageTrait<Message> \
static const MessageType enumeration = MessageType::Message; \
};
using MixinHighlightingTypes = Utils::SizedArray<HighlightingType, 6>;
struct HighlightingTypes {
HighlightingType mainHighlightingType;
MixinHighlightingTypes mixinHighlightingTypes;
};
}
#endif // CLANGBACKENDIPC_GLOBAL_H

View File

@@ -35,14 +35,25 @@ namespace ClangBackEnd {
HighlightingMarkContainer::HighlightingMarkContainer(uint line,
uint column,
uint length,
HighlightingType type)
HighlightingTypes types)
: line_(line),
column_(column),
length_(length),
type_(type)
types_(types)
{
}
HighlightingMarkContainer::HighlightingMarkContainer(uint line,
uint column,
uint length,
HighlightingType type)
: line_(line),
column_(column),
length_(length)
{
types_.mainHighlightingType = type;
}
uint HighlightingMarkContainer::line() const
{
return line_;
@@ -58,14 +69,21 @@ uint HighlightingMarkContainer::length() const
return length_;
}
HighlightingType HighlightingMarkContainer::type() const
HighlightingTypes HighlightingMarkContainer::types() const
{
return type_;
return types_;
}
quint32 &HighlightingMarkContainer::typeAsInt()
QDataStream &operator<<(QDataStream &out, HighlightingTypes highlightingTypes)
{
return reinterpret_cast<quint32&>(type_);
out << reinterpret_cast<const quint8&>(highlightingTypes.mainHighlightingType);
out << highlightingTypes.mixinHighlightingTypes.size();
for (HighlightingType type : highlightingTypes.mixinHighlightingTypes)
out << reinterpret_cast<const quint8&>(type);
return out;
}
QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container)
@@ -73,27 +91,55 @@ QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &conta
out << container.line_;
out << container.column_;
out << container.length_;
out << quint32(container.type_);
out << container.types_;
return out;
}
QDataStream &operator>>(QDataStream &in, HighlightingTypes &highlightingTypes)
{
in >> reinterpret_cast<quint8&>(highlightingTypes.mainHighlightingType);
quint8 size;
in >> size;
for (int counter = 0; counter < size; ++counter) {
HighlightingType type;
in >> reinterpret_cast<quint8&>(type);
highlightingTypes.mixinHighlightingTypes.push_back(type);
}
return in;
}
QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container)
{
in >> container.line_;
in >> container.column_;
in >> container.length_;
in >> container.typeAsInt();
in >> container.types_;
return in;
}
bool operator==(const MixinHighlightingTypes &first, const MixinHighlightingTypes &second)
{
return first.size() == second.size()
&& std::equal(first.begin(), first.end(), second.begin());
}
bool operator==(const HighlightingTypes &first, const HighlightingTypes &second)
{
return first.mainHighlightingType == second.mainHighlightingType
&& first.mixinHighlightingTypes == second.mixinHighlightingTypes;
}
bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second)
{
return first.line_ == second.line_
&& first.column_ == second.column_
&& first.length_ == second.length_
&& first.type_ == second.type_;
&& first.types_ == second.types_;
}
#define RETURN_TEXT_FOR_CASE(enumValue) case HighlightingType::enumValue: return #enumValue
@@ -129,7 +175,7 @@ QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container)
<< container.line() << ", "
<< container.column() << ", "
<< container.length() << ", "
<< highlightingTypeToCStringLiteral(container.type()) << ", "
<< highlightingTypeToCStringLiteral(container.types().mainHighlightingType) << ", "
<< ")";
return debug;
@@ -140,13 +186,25 @@ void PrintTo(HighlightingType highlightingType, std::ostream *os)
*os << highlightingTypeToCStringLiteral(highlightingType);
}
void PrintTo(const HighlightingTypes &types, std::ostream *os)
{
PrintTo(types.mainHighlightingType, os);
*os << "[";
for (HighlightingType type : types.mixinHighlightingTypes)
PrintTo(type, os);
*os << "]";
}
void PrintTo(const HighlightingMarkContainer& container, ::std::ostream *os)
{
*os << "HighlightingMarkContainer("
<< container.line() << ", "
<< container.column() << ", "
<< container.length() << ", ";
PrintTo(container.type(), os);
PrintTo(container.types(), os);
*os << ")";
}

View File

@@ -36,29 +36,29 @@ class CMBIPC_EXPORT HighlightingMarkContainer
friend CMBIPC_EXPORT bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second);
public:
HighlightingMarkContainer() = default;
HighlightingMarkContainer(uint line, uint column, uint length, HighlightingTypes types);
HighlightingMarkContainer(uint line, uint column, uint length, HighlightingType type);
uint line() const;
uint column() const;
uint length() const;
HighlightingType type() const;
private:
quint32 &typeAsInt();
HighlightingTypes types() const;
private:
uint line_;
uint column_;
uint length_;
HighlightingType type_;
HighlightingTypes types_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container);
CMBIPC_EXPORT bool operator==(const HighlightingTypes &first, const HighlightingTypes &second);
CMBIPC_EXPORT bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container);
CMBIPC_EXPORT void PrintTo(HighlightingType highlightingType, ::std::ostream *os);
CMBIPC_EXPORT void PrintTo(const HighlightingTypes &types, ::std::ostream *os);
void PrintTo(const HighlightingMarkContainer &container, ::std::ostream *os);
} // namespace ClangBackEnd