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;
......
......@@ -270,7 +270,7 @@ protected:
} // end of anonymous namespace
static bool sortByLinePredicate(const CheckSymbols::Use &lhs, const CheckSymbols::Use &rhs)
static bool sortByLinePredicate(const CheckSymbols::Result &lhs, const CheckSymbols::Result &rhs)
{
if (lhs.line == rhs.line)
return lhs.column < rhs.column;
......@@ -294,25 +294,17 @@ static bool acceptName(NameAST *ast, unsigned *referenceToken)
&& !ast->asOperatorFunctionId();
}
CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Use> &macroUses)
CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Result> &macroUses)
{
QTC_ASSERT(doc, return Future());
return (new CheckSymbols(doc, context, macroUses))->start();
}
CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Use> &macroUses)
CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Result> &macroUses)
: ASTVisitor(doc->translationUnit()), _doc(doc), _context(context)
, _lineOfLastUsage(0), _macroUses(macroUses)
{
CollectSymbols collectTypes(doc, context.snapshot());
_fileName = doc->fileName();
_potentialTypes = collectTypes.types();
_potentialFields = collectTypes.fields();
_potentialFunctions = collectTypes.functions();
_potentialStatics = collectTypes.statics();
unsigned line = 0;
getTokenEndPosition(translationUnit()->ast()->lastToken(), &line, 0);
_chunkSize = qMax(50U, line / 200);
......@@ -330,13 +322,21 @@ CheckSymbols::~CheckSymbols()
void CheckSymbols::run()
{
CollectSymbols collectTypes(_doc, _context.snapshot());
_fileName = _doc->fileName();
_potentialTypes = collectTypes.types();
_potentialFields = collectTypes.fields();
_potentialFunctions = collectTypes.functions();
_potentialStatics = collectTypes.statics();
qSort(_macroUses.begin(), _macroUses.end(), sortByLinePredicate);
_doc->clearDiagnosticMessages();
if (! isCanceled()) {
if (_doc->translationUnit()) {
accept(_doc->translationUnit()->ast());
_usages << QVector<Use>::fromList(_macroUses);
_usages << QVector<Result>::fromList(_macroUses);
flush();
}
}
......@@ -468,7 +468,7 @@ bool CheckSymbols::visit(NamespaceAST *ast)
if (! tok.generated()) {
unsigned line, column;
getTokenStartPosition(ast->identifier_token, &line, &column);
Use use(line, column, tok.length(), SemanticInfo::TypeUse);
Result use(line, column, tok.length(), CppHighlightingSupport::TypeUse);
addUse(use);
}
}
......@@ -483,7 +483,7 @@ bool CheckSymbols::visit(UsingDirectiveAST *)
bool CheckSymbols::visit(EnumeratorAST *ast)
{
addUse(ast->identifier_token, SemanticInfo::EnumerationUse);
addUse(ast->identifier_token, CppHighlightingSupport::EnumerationUse);
return true;
}
......@@ -498,7 +498,7 @@ bool CheckSymbols::visit(SimpleDeclarationAST *ast)
if (funTy->isVirtual()
|| (nameAST->asDestructorName()
&& hasVirtualDestructor(_context.lookupType(funTy->enclosingScope())))) {
addUse(nameAST, SemanticInfo::VirtualMethodUse);
addUse(nameAST, CppHighlightingSupport::VirtualMethodUse);
declrIdNameAST = nameAST;
} else if (maybeAddFunction(_context.lookup(decl->name(),
decl->enclosingScope()),
......@@ -506,7 +506,7 @@ bool CheckSymbols::visit(SimpleDeclarationAST *ast)
declrIdNameAST = nameAST;
// Add a diagnostic message if non-virtual function has override/final marker
if ((_usages.back().kind != SemanticInfo::VirtualMethodUse)) {
if ((_usages.back().kind != CppHighlightingSupport::VirtualMethodUse)) {
if (funTy->isOverride())
warning(declrIdNameAST, QCoreApplication::translate(
"CPlusplus::CheckSymbols", "Only virtual methods can be marked 'override'"));
......@@ -544,7 +544,7 @@ bool CheckSymbols::visit(ElaboratedTypeSpecifierAST *ast)
{
accept(ast->attribute_list);
accept(ast->name);
addUse(ast->name, SemanticInfo::TypeUse);
addUse(ast->name, CppHighlightingSupport::TypeUse);
return false;
}
......@@ -777,14 +777,14 @@ void CheckSymbols::checkName(NameAST *ast, Scope *scope)
if (klass) {
if (hasVirtualDestructor(_context.lookupType(klass))) {
addUse(ast, SemanticInfo::VirtualMethodUse);
addUse(ast, CppHighlightingSupport::VirtualMethodUse);
} else {
bool added = false;
if (highlightCtorDtorAsType && maybeType(ast->name))
added = maybeAddTypeOrStatic(_context.lookup(ast->name, klass), ast);
if (!added)
addUse(ast, SemanticInfo::FunctionUse);
addUse(ast, CppHighlightingSupport::FunctionUse);
}
}
} else if (maybeType(ast->name) || maybeStatic(ast->name)) {
......@@ -834,14 +834,14 @@ bool CheckSymbols::visit(QualifiedNameAST *ast)
if (binding && ast->unqualified_name) {
if (ast->unqualified_name->asDestructorName() != 0) {
if (hasVirtualDestructor(binding)) {
addUse(ast->unqualified_name, SemanticInfo::VirtualMethodUse);
addUse(ast->unqualified_name, CppHighlightingSupport::VirtualMethodUse);
} else {
bool added = false;
if (highlightCtorDtorAsType && maybeType(ast->name))
added = maybeAddTypeOrStatic(binding->find(ast->unqualified_name->name),
ast->unqualified_name);
if (!added)
addUse(ast->unqualified_name, SemanticInfo::FunctionUse);
addUse(ast->unqualified_name, CppHighlightingSupport::FunctionUse);
}
} else {
maybeAddTypeOrStatic(binding->find(ast->unqualified_name->name), ast->unqualified_name);
......@@ -877,7 +877,7 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast)
if (NameAST *class_or_namespace_name = nested_name_specifier->class_or_namespace_name) {
if (TemplateIdAST *template_id = class_or_namespace_name->asTemplateId()) {
if (template_id->template_token) {
addUse(template_id, SemanticInfo::TypeUse);
addUse(template_id, CppHighlightingSupport::TypeUse);
binding = 0; // there's no way we can find a binding.
}
......@@ -901,7 +901,7 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast)
bool CheckSymbols::visit(TypenameTypeParameterAST *ast)
{
addUse(ast->name, SemanticInfo::TypeUse);
addUse(ast->name, CppHighlightingSupport::TypeUse);
accept(ast->type_id);
return false;
}
......@@ -909,7 +909,7 @@ bool CheckSymbols::visit(TypenameTypeParameterAST *ast)
bool CheckSymbols::visit(TemplateTypeParameterAST *ast)
{
accept(ast->template_parameter_list);
addUse(ast->name, SemanticInfo::TypeUse);
addUse(ast->name, CppHighlightingSupport::TypeUse);
accept(ast->type_id);
return false;
}
......@@ -961,7 +961,7 @@ bool CheckSymbols::visit(MemInitializerAST *ast)
bool CheckSymbols::visit(GotoStatementAST *ast)
{
if (ast->identifier_token)
addUse(ast->identifier_token, SemanticInfo::LabelUse);
addUse(ast->identifier_token, CppHighlightingSupport::LabelUse);
return false;
}
......@@ -969,7 +969,7 @@ bool CheckSymbols::visit(GotoStatementAST *ast)
bool CheckSymbols::visit(LabeledStatementAST *ast)
{
if (ast->label_token && !tokenAt(ast->label_token).isKeyword())
addUse(ast->label_token, SemanticInfo::LabelUse);
addUse(ast->label_token, CppHighlightingSupport::LabelUse);
accept(ast->statement);
return false;
......@@ -990,7 +990,7 @@ bool CheckSymbols::visit(SimpleSpecifierAST *ast)
if (id.equalTo(_doc->control()->cpp11Override())
|| id.equalTo(_doc->control()->cpp11Final()))
{
addUse(ast->specifier_token, SemanticInfo::PseudoKeywordUse);
addUse(ast->specifier_token, CppHighlightingSupport::PseudoKeywordUse);
}
}
}
......@@ -1001,7 +1001,7 @@ bool CheckSymbols::visit(SimpleSpecifierAST *ast)
bool CheckSymbols::visit(ClassSpecifierAST *ast)
{
if (ast->final_token)
addUse(ast->final_token, SemanticInfo::PseudoKeywordUse);
addUse(ast->final_token, CppHighlightingSupport::PseudoKeywordUse);
return true;
}
......@@ -1026,7 +1026,7 @@ bool CheckSymbols::visit(FunctionDefinitionAST *ast)
if (fun->isVirtual()
|| (declId->asDestructorName()
&& hasVirtualDestructor(_context.lookupType(fun->enclosingScope())))) {
addUse(declId, SemanticInfo::VirtualMethodUse);
addUse(declId, CppHighlightingSupport::VirtualMethodUse);
} else if (!maybeAddFunction(_context.lookup(fun->name(),
fun->enclosingScope()),
declId, fun->argumentCount())) {
......@@ -1050,8 +1050,8 @@ bool CheckSymbols::visit(FunctionDefinitionAST *ast)
accept(ast->function_body);
const LocalSymbols locals(_doc, ast);
foreach (const QList<SemanticInfo::Use> &uses, locals.uses) {
foreach (const SemanticInfo::Use &u, uses)
foreach (const QList<Result> &uses, locals.uses) {
foreach (const Result &u, uses)
addUse(u);
}
......@@ -1062,7 +1062,7 @@ bool CheckSymbols::visit(FunctionDefinitionAST *ast)
return false;
}
void CheckSymbols::addUse(NameAST *ast, UseKind kind)
void CheckSymbols::addUse(NameAST *ast, Kind kind)
{
if (! ast)
return;
......@@ -1085,7 +1085,7 @@ void CheckSymbols::addUse(NameAST *ast, UseKind kind)
addUse(startToken, kind);
}
void CheckSymbols::addUse(unsigned tokenIndex, UseKind kind)
void CheckSymbols::addUse(unsigned tokenIndex, Kind kind)
{
if (! tokenIndex)
return;
......@@ -1098,11 +1098,11 @@ void CheckSymbols::addUse(unsigned tokenIndex, UseKind kind)
getTokenStartPosition(tokenIndex, &line, &column);
const unsigned length = tok.length();
const Use use(line, column, length, kind);
const Result use(line, column, length, kind);
addUse(use);
}
void CheckSymbols::addUse(const Use &use)
void CheckSymbols::addUse(const Result &use)
{
if (use.isInvalid())
return;
......@@ -1134,7 +1134,7 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast)
unsigned line, column;
getTokenStartPosition(startToken, &line, &column);
const unsigned length = tok.length();
const Use use(line, column, length, SemanticInfo::TypeUse);
const Result use(line, column, length, CppHighlightingSupport::TypeUse);
addUse(use);
}
......@@ -1176,14 +1176,14 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam
getTokenStartPosition(startToken, &line, &column);
const unsigned length = tok.length();
UseKind kind = SemanticInfo::TypeUse;
Kind kind = CppHighlightingSupport::TypeUse;
if (c->enclosingEnum() != 0)
kind = SemanticInfo::EnumerationUse;
kind = CppHighlightingSupport::EnumerationUse;
else if (c->isStatic())
// treat static variable as a field(highlighting)
kind = SemanticInfo::FieldUse;
kind = CppHighlightingSupport::FieldUse;
const Use use(line, column, length, kind);
const Result use(line, column, length, kind);
addUse(use);
return true;
......@@ -1218,7 +1218,7 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a
getTokenStartPosition(startToken, &line, &column);
const unsigned length = tok.length();
const Use use(line, column, length, SemanticInfo::FieldUse);
const Result use(line, column, length, CppHighlightingSupport::FieldUse);
addUse(use);
return true;
......@@ -1243,7 +1243,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
return false;
enum { Match_None, Match_TooManyArgs, Match_TooFewArgs, Match_Ok } matchType = Match_None;
SemanticInfo::UseKind kind = SemanticInfo::FunctionUse;
Kind kind = CppHighlightingSupport::FunctionUse;
foreach (const LookupItem &r, candidates) {
Symbol *c = r.declaration();
......@@ -1270,21 +1270,21 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
if (argumentCount < funTy->minimumArgumentCount()) {
if (matchType != Match_Ok) {
kind = funTy->isVirtual() ? SemanticInfo::VirtualMethodUse : SemanticInfo::FunctionUse;
kind = funTy->isVirtual() ? CppHighlightingSupport::VirtualMethodUse : CppHighlightingSupport::FunctionUse;
matchType = Match_TooFewArgs;
}
} else if (argumentCount > funTy->argumentCount() && ! funTy->isVariadic()) {
if (matchType != Match_Ok) {
matchType = Match_TooManyArgs;
kind = funTy->isVirtual() ? SemanticInfo::VirtualMethodUse : SemanticInfo::FunctionUse;
kind = funTy->isVirtual() ? CppHighlightingSupport::VirtualMethodUse : CppHighlightingSupport::FunctionUse;
}
} else if (!funTy->isVirtual()) {
matchType = Match_Ok;
kind = SemanticInfo::FunctionUse;
kind = CppHighlightingSupport::FunctionUse;
//continue, to check if there is a matching candidate which is virtual
} else {
matchType = Match_Ok;
kind = SemanticInfo::VirtualMethodUse;
kind = CppHighlightingSupport::VirtualMethodUse;
break;
}
}
......@@ -1294,7 +1294,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
if (highlightCtorDtorAsType
&& (isConstructor || isDestructor)
&& maybeType(ast->name)
&& kind == SemanticInfo::FunctionUse) {
&& kind == CppHighlightingSupport::FunctionUse) {
return false;
}
......@@ -1308,7 +1308,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
else if (matchType == Match_TooManyArgs)
warning(line, column, QCoreApplication::translate("CPlusPlus::CheckSymbols", "Too many arguments"), length);
const Use use(line, column, length, kind);
const Result use(line, column, length, kind);
addUse(use);
return true;
......
......@@ -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.