Commit 4b0f70f4 authored by Erik Verbruggen's avatar Erik Verbruggen

C++: highlighter clean-ups

- Moved TextEditor::SemanticHighlighter::Result to
  TextEditor::HighlightingResult
- Moved SemanticInfo::UseKind to CppHighlightingSupport::Kind

Change-Id: I14faab1891ca691a0691cfd9243edf19fcd3d3df
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 6a4310a4
......@@ -1949,23 +1949,24 @@ void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
m_occurrencesUnusedFormat.clearForeground();
m_occurrencesUnusedFormat.setToolTip(tr("Unused variable"));
m_occurrenceRenameFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_RENAME);
m_semanticHighlightFormatMap[SemanticInfo::TypeUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::TypeUse] =
fs.toTextCharFormat(TextEditor::C_TYPE);
m_semanticHighlightFormatMap[SemanticInfo::LocalUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::LocalUse] =
fs.toTextCharFormat(TextEditor::C_LOCAL);
m_semanticHighlightFormatMap[SemanticInfo::FieldUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::FieldUse] =
fs.toTextCharFormat(TextEditor::C_FIELD);
m_semanticHighlightFormatMap[SemanticInfo::EnumerationUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::EnumerationUse] =
fs.toTextCharFormat(TextEditor::C_ENUMERATION);
m_semanticHighlightFormatMap[SemanticInfo::VirtualMethodUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::VirtualMethodUse] =
fs.toTextCharFormat(TextEditor::C_VIRTUAL_METHOD);
m_semanticHighlightFormatMap[SemanticInfo::LabelUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::LabelUse] =
fs.toTextCharFormat(TextEditor::C_LABEL);
m_semanticHighlightFormatMap[SemanticInfo::MacroUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::MacroUse] =
fs.toTextCharFormat(TextEditor::C_PREPROCESSOR);
m_semanticHighlightFormatMap[SemanticInfo::FunctionUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::FunctionUse] =
fs.toTextCharFormat(TextEditor::C_FUNCTION);
m_semanticHighlightFormatMap[SemanticInfo::PseudoKeywordUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::PseudoKeywordUse] =
fs.toTextCharFormat(TextEditor::C_KEYWORD);
m_keywordFormat = fs.toTextCharFormat(TextEditor::C_KEYWORD);
......
......@@ -260,7 +260,7 @@ private:
SemanticHighlighter::Source currentSource(bool force = false);
void highlightUses(const QList<TextEditor::SemanticHighlighter::Result> &uses,
void highlightUses(const QList<TextEditor::HighlightingResult> &uses,
QList<QTextEdit::ExtraSelection> *selections);
void createToolBar(CPPEditor *editable);
......@@ -316,8 +316,8 @@ private:
bool m_objcEnabled;
bool m_initialized;
QFuture<TextEditor::SemanticHighlighter::Result> m_highlighter;
QFutureWatcher<TextEditor::SemanticHighlighter::Result> m_highlightWatcher;
QFuture<TextEditor::HighlightingResult> m_highlighter;
QFutureWatcher<TextEditor::HighlightingResult> m_highlightWatcher;
unsigned m_highlightRevision; // the editor revision that requested the highlight
QFuture<QList<int> > m_references;
......
This diff is collapsed.
......@@ -31,6 +31,7 @@
#define CPLUSPLUSCHECKSYMBOLS_H
#include "cpptools_global.h"
#include "cpphighlightingsupport.h"
#include "cppsemanticinfo.h"
#include <cplusplus/TypeOfExpression.h>
......@@ -44,17 +45,17 @@ namespace CppTools {
class CPPTOOLS_EXPORT CheckSymbols:
protected CPlusPlus::ASTVisitor,
public QRunnable,
public QFutureInterface<TextEditor::SemanticHighlighter::Result>
public QFutureInterface<TextEditor::HighlightingResult>
{
public:
virtual ~CheckSymbols();
typedef TextEditor::SemanticHighlighter::Result Use;
typedef CppTools::SemanticInfo::UseKind UseKind;
typedef TextEditor::HighlightingResult Result;
typedef CppHighlightingSupport::Kind Kind;
virtual void run();
typedef QFuture<Use> Future;
typedef QFuture<Result> Future;
Future start()
{
......@@ -67,14 +68,14 @@ public:
static Future go(CPlusPlus::Document::Ptr doc,
const CPlusPlus::LookupContext &context,
const QList<Use> &macroUses);
const QList<Result> &macroUses);
static QMap<int, QVector<Use> > chunks(const QFuture<Use> &future, int from, int to)
static QMap<int, QVector<Result> > chunks(const QFuture<Result> &future, int from, int to)
{
QMap<int, QVector<Use> > chunks;
QMap<int, QVector<Result> > chunks;
for (int i = from; i < to; ++i) {
const Use use = future.resultAt(i);
const Result use = future.resultAt(i);
if (use.isInvalid())
continue;
......@@ -91,7 +92,7 @@ protected:
CheckSymbols(CPlusPlus::Document::Ptr doc,
const CPlusPlus::LookupContext &context,
const QList<Use> &macroUses);
const QList<Result> &otherUses);
bool hasVirtualDestructor(CPlusPlus::Class *klass) const;
bool hasVirtualDestructor(CPlusPlus::ClassOrNamespace *binding) const;
......@@ -110,9 +111,9 @@ protected:
void checkName(CPlusPlus::NameAST *ast, CPlusPlus::Scope *scope = 0);
CPlusPlus::ClassOrNamespace *checkNestedName(CPlusPlus::QualifiedNameAST *ast);
void addUse(const Use &use);
void addUse(unsigned tokenIndex, UseKind kind);
void addUse(CPlusPlus::NameAST *name, UseKind kind);
void addUse(const Result &use);
void addUse(unsigned tokenIndex, Kind kind);
void addUse(CPlusPlus::NameAST *name, Kind kind);
void addType(CPlusPlus::ClassOrNamespace *b, CPlusPlus::NameAST *ast);
......@@ -177,10 +178,10 @@ private:
QSet<QByteArray> _potentialFunctions;
QSet<QByteArray> _potentialStatics;
QList<CPlusPlus::AST *> _astStack;
QVector<Use> _usages;
QVector<Result> _usages;
int _chunkSize;
unsigned _lineOfLastUsage;
QList<Use> _macroUses;
QList<Result> _macroUses;
};
} // namespace CppTools
......
......@@ -47,14 +47,26 @@ namespace CppTools {
class CPPTOOLS_EXPORT CppHighlightingSupport
{
public:
typedef TextEditor::SemanticHighlighter::Result Use;
enum Kind {
Unknown = 0,
TypeUse,
LocalUse,
FieldUse,
EnumerationUse,
VirtualMethodUse,
LabelUse,
MacroUse,
FunctionUse,
PseudoKeywordUse
};
public:
CppHighlightingSupport(TextEditor::ITextEditor *editor);
virtual ~CppHighlightingSupport() = 0;
virtual QFuture<Use> highlightingFuture(const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const = 0;
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const = 0;
protected:
TextEditor::ITextEditor *editor() const
......
......@@ -49,22 +49,23 @@ CppHighlightingSupportInternal::~CppHighlightingSupportInternal()
{
}
QFuture<CppHighlightingSupport::Use> CppHighlightingSupportInternal::highlightingFuture(
QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highlightingFuture(
const Document::Ptr &doc,
const Snapshot &snapshot) const
{
QList<CheckSymbols::Use> macroUses;
typedef TextEditor::HighlightingResult Result;
QList<Result> macroUses;
//Get macro definitions
// Get macro definitions
foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
int line, column;
editor()->convertPosition(macro.offset(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
CheckSymbols::Use use(line, column, macro.name().size(), SemanticInfo::MacroUse);
Result use(line, column, macro.name().size(), MacroUse);
macroUses.append(use);
}
//Get macro uses
// Get macro uses
foreach (const Document::MacroUse &macro, doc->macroUses()) {
const QString name = QString::fromUtf8(macro.macro().name());
......@@ -84,7 +85,7 @@ QFuture<CppHighlightingSupport::Use> CppHighlightingSupportInternal::highlightin
int line, column;
editor()->convertPosition(macro.begin(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
CheckSymbols::Use use(line, column, name.size(), SemanticInfo::MacroUse);
Result use(line, column, name.size(), MacroUse);
macroUses.append(use);
}
......
......@@ -39,15 +39,13 @@ namespace Internal {
class CppHighlightingSupportInternal: public CppHighlightingSupport
{
public:
typedef TextEditor::SemanticHighlighter::Result Use;
public:
CppHighlightingSupportInternal(TextEditor::ITextEditor *editor);
virtual ~CppHighlightingSupportInternal();
virtual QFuture<Use> highlightingFuture(const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const;
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const;
};
class CppHighlightingSupportInternalFactory: public CppHighlightingSupportFactory
......
......@@ -27,6 +27,7 @@
**
****************************************************************************/
#include "cpphighlightingsupport.h"
#include "cpplocalsymbols.h"
#include "cppsemanticinfo.h"
......@@ -73,6 +74,8 @@ protected:
using ASTVisitor::visit;
using ASTVisitor::endVisit;
typedef TextEditor::HighlightingResult HighlightingResult;
void enterScope(Scope *scope)
{
_scopeStack.append(scope);
......@@ -86,7 +89,9 @@ protected:
const Identifier *id = member->identifier();
unsigned line, column;
getTokenStartPosition(member->sourceLocation(), &line, &column);
localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::LocalUse));
localUses[member].append(
HighlightingResult(line, column, id->size(),
CppHighlightingSupport::LocalUse));
}
}
}
......@@ -107,7 +112,9 @@ protected:
else if (!member->isGenerated() && (member->sourceLocation() < firstToken || member->enclosingScope()->isFunction())) {
unsigned line, column;
getTokenStartPosition(simpleName->identifier_token, &line, &column);
localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::LocalUse));
localUses[member].append(
HighlightingResult(line, column, id->size(),
CppHighlightingSupport::LocalUse));
return false;
}
}
......
......@@ -43,19 +43,7 @@ namespace CppTools {
class CPPTOOLS_EXPORT SemanticInfo
{
public:
enum UseKind {
Unknown = 0,
TypeUse,
LocalUse,
FieldUse,
EnumerationUse,
VirtualMethodUse,
LabelUse,
MacroUse,
FunctionUse,
PseudoKeywordUse
};
typedef TextEditor::SemanticHighlighter::Result Use;
typedef TextEditor::HighlightingResult Use;
typedef QHash<CPlusPlus::Symbol *, QList<Use> > LocalUseMap;
typedef QHashIterator<CPlusPlus::Symbol *, QList<Use> > LocalUseIterator;
......
......@@ -78,7 +78,7 @@ public:
Max // number of the last used value (to generate the warning formats)
};
typedef TextEditor::SemanticHighlighter::Result Use;
typedef TextEditor::HighlightingResult Use;
SemanticHighlighter(QmlJSTextEditorWidget *editor);
......
......@@ -41,7 +41,7 @@ using namespace TextEditor::SemanticHighlighter;
void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
SyntaxHighlighter *highlighter,
const QFuture<Result> &future,
const QFuture<HighlightingResult> &future,
int from, int to,
const QHash<int, QTextCharFormat> &kindToFormat)
{
......@@ -54,7 +54,7 @@ void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
// be cleaned of additional extra formats if they have no results
int currentBlockNumber = 0;
for (int i = from - 1; i >= 0; --i) {
const Result &result = future.resultAt(i);
const HighlightingResult &result = future.resultAt(i);
const int blockNumber = result.line - 1;
if (blockNumber < firstResultBlockNumber) {
// stop! found where last format stopped
......@@ -69,7 +69,7 @@ void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
QTC_ASSERT(currentBlockNumber < doc->blockCount(), return);
QTextBlock b = doc->findBlockByNumber(currentBlockNumber);
Result result = future.resultAt(from);
HighlightingResult result = future.resultAt(from);
for (int i = from; i < to && b.isValid(); ) {
const int blockNumber = result.line - 1;
QTC_ASSERT(blockNumber < doc->blockCount(), return);
......@@ -111,12 +111,12 @@ void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
void TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
SyntaxHighlighter *highlighter,
const QFuture<Result> &future)
const QFuture<HighlightingResult> &future)
{
// find block number of last result
int lastBlockNumber = 0;
for (int i = future.resultCount() - 1; i >= 0; --i) {
const Result &result = future.resultAt(i);
const HighlightingResult &result = future.resultAt(i);
if (result.line) {
lastBlockNumber = result.line - 1;
break;
......
......@@ -44,14 +44,12 @@ namespace TextEditor {
class SyntaxHighlighter;
namespace SemanticHighlighter {
class TEXTEDITOR_EXPORT Result {
class TEXTEDITOR_EXPORT HighlightingResult {
public:
unsigned line; // 1-based
unsigned column; // 1-based
unsigned length;
int kind;
int kind; /// The various highlighters can define their own kind of results.
bool isValid() const
{ return line != 0; }
......@@ -59,21 +57,25 @@ public:
bool isInvalid() const
{ return line == 0; }
Result()
: line(0), column(0), length(0), kind(-1) {}
Result(unsigned line, unsigned column, unsigned length, int kind)
: line(line), column(column), length(length), kind(kind) {}
HighlightingResult()
: line(0), column(0), length(0), kind(0)
{}
HighlightingResult(unsigned line, unsigned column, unsigned length, int kind)
: line(line), column(column), length(length), kind(kind)
{}
bool operator==(const Result& other) const
bool operator==(const HighlightingResult& other) const
{
return
line == other.line &&
column == other.column &&
length == other.length &&
kind == other.kind;
return line == other.line
&& column == other.column
&& length == other.length
&& kind == other.kind;
}
};
namespace SemanticHighlighter {
// Applies the future results [from, to) and applies the extra formats
// indicated by Result::kind and kindToFormat to the correct location using
// SyntaxHighlighter::setExtraAdditionalFormats.
......@@ -83,7 +85,7 @@ public:
// Requires that results of the Future are ordered by line.
void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats(
SyntaxHighlighter *highlighter,
const QFuture<Result> &future,
const QFuture<HighlightingResult> &future,
int from, int to,
const QHash<int, QTextCharFormat> &kindToFormat);
......@@ -92,7 +94,7 @@ void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats(
// Requires that results of the Future are ordered by line.
void TEXTEDITOR_EXPORT clearExtraAdditionalFormatsUntilEnd(
SyntaxHighlighter *highlighter,
const QFuture<Result> &future);
const QFuture<HighlightingResult> &future);
} // namespace SemanticHighlighter
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment