C++: highlighter clean-ups

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

Change-Id: I14faab1891ca691a0691cfd9243edf19fcd3d3df
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Erik Verbruggen
2013-04-16 16:48:10 +02:00
parent 6a4310a44a
commit 4b0f70f4c9
13 changed files with 797 additions and 785 deletions

View File

@@ -1949,23 +1949,24 @@ void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
m_occurrencesUnusedFormat.clearForeground(); m_occurrencesUnusedFormat.clearForeground();
m_occurrencesUnusedFormat.setToolTip(tr("Unused variable")); m_occurrencesUnusedFormat.setToolTip(tr("Unused variable"));
m_occurrenceRenameFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_RENAME); m_occurrenceRenameFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_RENAME);
m_semanticHighlightFormatMap[SemanticInfo::TypeUse] =
m_semanticHighlightFormatMap[CppHighlightingSupport::TypeUse] =
fs.toTextCharFormat(TextEditor::C_TYPE); fs.toTextCharFormat(TextEditor::C_TYPE);
m_semanticHighlightFormatMap[SemanticInfo::LocalUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::LocalUse] =
fs.toTextCharFormat(TextEditor::C_LOCAL); fs.toTextCharFormat(TextEditor::C_LOCAL);
m_semanticHighlightFormatMap[SemanticInfo::FieldUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::FieldUse] =
fs.toTextCharFormat(TextEditor::C_FIELD); fs.toTextCharFormat(TextEditor::C_FIELD);
m_semanticHighlightFormatMap[SemanticInfo::EnumerationUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::EnumerationUse] =
fs.toTextCharFormat(TextEditor::C_ENUMERATION); fs.toTextCharFormat(TextEditor::C_ENUMERATION);
m_semanticHighlightFormatMap[SemanticInfo::VirtualMethodUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::VirtualMethodUse] =
fs.toTextCharFormat(TextEditor::C_VIRTUAL_METHOD); fs.toTextCharFormat(TextEditor::C_VIRTUAL_METHOD);
m_semanticHighlightFormatMap[SemanticInfo::LabelUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::LabelUse] =
fs.toTextCharFormat(TextEditor::C_LABEL); fs.toTextCharFormat(TextEditor::C_LABEL);
m_semanticHighlightFormatMap[SemanticInfo::MacroUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::MacroUse] =
fs.toTextCharFormat(TextEditor::C_PREPROCESSOR); fs.toTextCharFormat(TextEditor::C_PREPROCESSOR);
m_semanticHighlightFormatMap[SemanticInfo::FunctionUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::FunctionUse] =
fs.toTextCharFormat(TextEditor::C_FUNCTION); fs.toTextCharFormat(TextEditor::C_FUNCTION);
m_semanticHighlightFormatMap[SemanticInfo::PseudoKeywordUse] = m_semanticHighlightFormatMap[CppHighlightingSupport::PseudoKeywordUse] =
fs.toTextCharFormat(TextEditor::C_KEYWORD); fs.toTextCharFormat(TextEditor::C_KEYWORD);
m_keywordFormat = fs.toTextCharFormat(TextEditor::C_KEYWORD); m_keywordFormat = fs.toTextCharFormat(TextEditor::C_KEYWORD);

View File

@@ -260,7 +260,7 @@ private:
SemanticHighlighter::Source currentSource(bool force = false); 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); QList<QTextEdit::ExtraSelection> *selections);
void createToolBar(CPPEditor *editable); void createToolBar(CPPEditor *editable);
@@ -316,8 +316,8 @@ private:
bool m_objcEnabled; bool m_objcEnabled;
bool m_initialized; bool m_initialized;
QFuture<TextEditor::SemanticHighlighter::Result> m_highlighter; QFuture<TextEditor::HighlightingResult> m_highlighter;
QFutureWatcher<TextEditor::SemanticHighlighter::Result> m_highlightWatcher; QFutureWatcher<TextEditor::HighlightingResult> m_highlightWatcher;
unsigned m_highlightRevision; // the editor revision that requested the highlight unsigned m_highlightRevision; // the editor revision that requested the highlight
QFuture<QList<int> > m_references; QFuture<QList<int> > m_references;

View File

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

View File

@@ -31,6 +31,7 @@
#define CPLUSPLUSCHECKSYMBOLS_H #define CPLUSPLUSCHECKSYMBOLS_H
#include "cpptools_global.h" #include "cpptools_global.h"
#include "cpphighlightingsupport.h"
#include "cppsemanticinfo.h" #include "cppsemanticinfo.h"
#include <cplusplus/TypeOfExpression.h> #include <cplusplus/TypeOfExpression.h>
@@ -44,17 +45,17 @@ namespace CppTools {
class CPPTOOLS_EXPORT CheckSymbols: class CPPTOOLS_EXPORT CheckSymbols:
protected CPlusPlus::ASTVisitor, protected CPlusPlus::ASTVisitor,
public QRunnable, public QRunnable,
public QFutureInterface<TextEditor::SemanticHighlighter::Result> public QFutureInterface<TextEditor::HighlightingResult>
{ {
public: public:
virtual ~CheckSymbols(); virtual ~CheckSymbols();
typedef TextEditor::SemanticHighlighter::Result Use; typedef TextEditor::HighlightingResult Result;
typedef CppTools::SemanticInfo::UseKind UseKind; typedef CppHighlightingSupport::Kind Kind;
virtual void run(); virtual void run();
typedef QFuture<Use> Future; typedef QFuture<Result> Future;
Future start() Future start()
{ {
@@ -67,14 +68,14 @@ public:
static Future go(CPlusPlus::Document::Ptr doc, static Future go(CPlusPlus::Document::Ptr doc,
const CPlusPlus::LookupContext &context, 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) { for (int i = from; i < to; ++i) {
const Use use = future.resultAt(i); const Result use = future.resultAt(i);
if (use.isInvalid()) if (use.isInvalid())
continue; continue;
@@ -91,7 +92,7 @@ protected:
CheckSymbols(CPlusPlus::Document::Ptr doc, CheckSymbols(CPlusPlus::Document::Ptr doc,
const CPlusPlus::LookupContext &context, const CPlusPlus::LookupContext &context,
const QList<Use> &macroUses); const QList<Result> &otherUses);
bool hasVirtualDestructor(CPlusPlus::Class *klass) const; bool hasVirtualDestructor(CPlusPlus::Class *klass) const;
bool hasVirtualDestructor(CPlusPlus::ClassOrNamespace *binding) const; bool hasVirtualDestructor(CPlusPlus::ClassOrNamespace *binding) const;
@@ -110,9 +111,9 @@ protected:
void checkName(CPlusPlus::NameAST *ast, CPlusPlus::Scope *scope = 0); void checkName(CPlusPlus::NameAST *ast, CPlusPlus::Scope *scope = 0);
CPlusPlus::ClassOrNamespace *checkNestedName(CPlusPlus::QualifiedNameAST *ast); CPlusPlus::ClassOrNamespace *checkNestedName(CPlusPlus::QualifiedNameAST *ast);
void addUse(const Use &use); void addUse(const Result &use);
void addUse(unsigned tokenIndex, UseKind kind); void addUse(unsigned tokenIndex, Kind kind);
void addUse(CPlusPlus::NameAST *name, UseKind kind); void addUse(CPlusPlus::NameAST *name, Kind kind);
void addType(CPlusPlus::ClassOrNamespace *b, CPlusPlus::NameAST *ast); void addType(CPlusPlus::ClassOrNamespace *b, CPlusPlus::NameAST *ast);
@@ -177,10 +178,10 @@ private:
QSet<QByteArray> _potentialFunctions; QSet<QByteArray> _potentialFunctions;
QSet<QByteArray> _potentialStatics; QSet<QByteArray> _potentialStatics;
QList<CPlusPlus::AST *> _astStack; QList<CPlusPlus::AST *> _astStack;
QVector<Use> _usages; QVector<Result> _usages;
int _chunkSize; int _chunkSize;
unsigned _lineOfLastUsage; unsigned _lineOfLastUsage;
QList<Use> _macroUses; QList<Result> _macroUses;
}; };
} // namespace CppTools } // namespace CppTools

View File

@@ -47,14 +47,26 @@ namespace CppTools {
class CPPTOOLS_EXPORT CppHighlightingSupport class CPPTOOLS_EXPORT CppHighlightingSupport
{ {
public: public:
typedef TextEditor::SemanticHighlighter::Result Use; enum Kind {
Unknown = 0,
TypeUse,
LocalUse,
FieldUse,
EnumerationUse,
VirtualMethodUse,
LabelUse,
MacroUse,
FunctionUse,
PseudoKeywordUse
};
public: public:
CppHighlightingSupport(TextEditor::ITextEditor *editor); CppHighlightingSupport(TextEditor::ITextEditor *editor);
virtual ~CppHighlightingSupport() = 0; virtual ~CppHighlightingSupport() = 0;
virtual QFuture<Use> highlightingFuture(const CPlusPlus::Document::Ptr &doc, virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
const CPlusPlus::Snapshot &snapshot) const = 0; const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const = 0;
protected: protected:
TextEditor::ITextEditor *editor() const TextEditor::ITextEditor *editor() const

View File

@@ -49,22 +49,23 @@ CppHighlightingSupportInternal::~CppHighlightingSupportInternal()
{ {
} }
QFuture<CppHighlightingSupport::Use> CppHighlightingSupportInternal::highlightingFuture( QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highlightingFuture(
const Document::Ptr &doc, const Document::Ptr &doc,
const Snapshot &snapshot) const 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()) { foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
int line, column; int line, column;
editor()->convertPosition(macro.offset(), &line, &column); editor()->convertPosition(macro.offset(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here ++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); macroUses.append(use);
} }
//Get macro uses // Get macro uses
foreach (const Document::MacroUse &macro, doc->macroUses()) { foreach (const Document::MacroUse &macro, doc->macroUses()) {
const QString name = QString::fromUtf8(macro.macro().name()); const QString name = QString::fromUtf8(macro.macro().name());
@@ -84,7 +85,7 @@ QFuture<CppHighlightingSupport::Use> CppHighlightingSupportInternal::highlightin
int line, column; int line, column;
editor()->convertPosition(macro.begin(), &line, &column); editor()->convertPosition(macro.begin(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here ++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); macroUses.append(use);
} }

View File

@@ -39,15 +39,13 @@ namespace Internal {
class CppHighlightingSupportInternal: public CppHighlightingSupport class CppHighlightingSupportInternal: public CppHighlightingSupport
{ {
public:
typedef TextEditor::SemanticHighlighter::Result Use;
public: public:
CppHighlightingSupportInternal(TextEditor::ITextEditor *editor); CppHighlightingSupportInternal(TextEditor::ITextEditor *editor);
virtual ~CppHighlightingSupportInternal(); virtual ~CppHighlightingSupportInternal();
virtual QFuture<Use> highlightingFuture(const CPlusPlus::Document::Ptr &doc, virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
const CPlusPlus::Snapshot &snapshot) const; const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const;
}; };
class CppHighlightingSupportInternalFactory: public CppHighlightingSupportFactory class CppHighlightingSupportInternalFactory: public CppHighlightingSupportFactory

View File

@@ -27,6 +27,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "cpphighlightingsupport.h"
#include "cpplocalsymbols.h" #include "cpplocalsymbols.h"
#include "cppsemanticinfo.h" #include "cppsemanticinfo.h"
@@ -73,6 +74,8 @@ protected:
using ASTVisitor::visit; using ASTVisitor::visit;
using ASTVisitor::endVisit; using ASTVisitor::endVisit;
typedef TextEditor::HighlightingResult HighlightingResult;
void enterScope(Scope *scope) void enterScope(Scope *scope)
{ {
_scopeStack.append(scope); _scopeStack.append(scope);
@@ -86,7 +89,9 @@ protected:
const Identifier *id = member->identifier(); const Identifier *id = member->identifier();
unsigned line, column; unsigned line, column;
getTokenStartPosition(member->sourceLocation(), &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())) { else if (!member->isGenerated() && (member->sourceLocation() < firstToken || member->enclosingScope()->isFunction())) {
unsigned line, column; unsigned line, column;
getTokenStartPosition(simpleName->identifier_token, &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; return false;
} }
} }

View File

@@ -43,19 +43,7 @@ namespace CppTools {
class CPPTOOLS_EXPORT SemanticInfo class CPPTOOLS_EXPORT SemanticInfo
{ {
public: public:
enum UseKind { typedef TextEditor::HighlightingResult Use;
Unknown = 0,
TypeUse,
LocalUse,
FieldUse,
EnumerationUse,
VirtualMethodUse,
LabelUse,
MacroUse,
FunctionUse,
PseudoKeywordUse
};
typedef TextEditor::SemanticHighlighter::Result Use;
typedef QHash<CPlusPlus::Symbol *, QList<Use> > LocalUseMap; typedef QHash<CPlusPlus::Symbol *, QList<Use> > LocalUseMap;
typedef QHashIterator<CPlusPlus::Symbol *, QList<Use> > LocalUseIterator; typedef QHashIterator<CPlusPlus::Symbol *, QList<Use> > LocalUseIterator;

View File

@@ -78,7 +78,7 @@ public:
Max // number of the last used value (to generate the warning formats) Max // number of the last used value (to generate the warning formats)
}; };
typedef TextEditor::SemanticHighlighter::Result Use; typedef TextEditor::HighlightingResult Use;
SemanticHighlighter(QmlJSTextEditorWidget *editor); SemanticHighlighter(QmlJSTextEditorWidget *editor);

View File

@@ -41,7 +41,7 @@ using namespace TextEditor::SemanticHighlighter;
void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats( void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
SyntaxHighlighter *highlighter, SyntaxHighlighter *highlighter,
const QFuture<Result> &future, const QFuture<HighlightingResult> &future,
int from, int to, int from, int to,
const QHash<int, QTextCharFormat> &kindToFormat) const QHash<int, QTextCharFormat> &kindToFormat)
{ {
@@ -54,7 +54,7 @@ void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
// be cleaned of additional extra formats if they have no results // be cleaned of additional extra formats if they have no results
int currentBlockNumber = 0; int currentBlockNumber = 0;
for (int i = from - 1; i >= 0; --i) { 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; const int blockNumber = result.line - 1;
if (blockNumber < firstResultBlockNumber) { if (blockNumber < firstResultBlockNumber) {
// stop! found where last format stopped // stop! found where last format stopped
@@ -69,7 +69,7 @@ void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
QTC_ASSERT(currentBlockNumber < doc->blockCount(), return); QTC_ASSERT(currentBlockNumber < doc->blockCount(), return);
QTextBlock b = doc->findBlockByNumber(currentBlockNumber); QTextBlock b = doc->findBlockByNumber(currentBlockNumber);
Result result = future.resultAt(from); HighlightingResult result = future.resultAt(from);
for (int i = from; i < to && b.isValid(); ) { for (int i = from; i < to && b.isValid(); ) {
const int blockNumber = result.line - 1; const int blockNumber = result.line - 1;
QTC_ASSERT(blockNumber < doc->blockCount(), return); QTC_ASSERT(blockNumber < doc->blockCount(), return);
@@ -111,12 +111,12 @@ void TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
void TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd( void TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
SyntaxHighlighter *highlighter, SyntaxHighlighter *highlighter,
const QFuture<Result> &future) const QFuture<HighlightingResult> &future)
{ {
// find block number of last result // find block number of last result
int lastBlockNumber = 0; int lastBlockNumber = 0;
for (int i = future.resultCount() - 1; i >= 0; --i) { for (int i = future.resultCount() - 1; i >= 0; --i) {
const Result &result = future.resultAt(i); const HighlightingResult &result = future.resultAt(i);
if (result.line) { if (result.line) {
lastBlockNumber = result.line - 1; lastBlockNumber = result.line - 1;
break; break;

View File

@@ -44,14 +44,12 @@ namespace TextEditor {
class SyntaxHighlighter; class SyntaxHighlighter;
namespace SemanticHighlighter { class TEXTEDITOR_EXPORT HighlightingResult {
class TEXTEDITOR_EXPORT Result {
public: public:
unsigned line; // 1-based unsigned line; // 1-based
unsigned column; // 1-based unsigned column; // 1-based
unsigned length; unsigned length;
int kind; int kind; /// The various highlighters can define their own kind of results.
bool isValid() const bool isValid() const
{ return line != 0; } { return line != 0; }
@@ -59,21 +57,25 @@ public:
bool isInvalid() const bool isInvalid() const
{ return line == 0; } { return line == 0; }
Result() HighlightingResult()
: line(0), column(0), length(0), kind(-1) {} : line(0), column(0), length(0), kind(0)
Result(unsigned line, unsigned column, unsigned length, int kind) {}
: line(line), column(column), length(length), kind(kind) {}
bool operator==(const Result& other) const HighlightingResult(unsigned line, unsigned column, unsigned length, int kind)
: line(line), column(column), length(length), kind(kind)
{}
bool operator==(const HighlightingResult& other) const
{ {
return return line == other.line
line == other.line && && column == other.column
column == other.column && && length == other.length
length == other.length && && kind == other.kind;
kind == other.kind;
} }
}; };
namespace SemanticHighlighter {
// Applies the future results [from, to) and applies the extra formats // Applies the future results [from, to) and applies the extra formats
// indicated by Result::kind and kindToFormat to the correct location using // indicated by Result::kind and kindToFormat to the correct location using
// SyntaxHighlighter::setExtraAdditionalFormats. // SyntaxHighlighter::setExtraAdditionalFormats.
@@ -83,7 +85,7 @@ public:
// Requires that results of the Future are ordered by line. // Requires that results of the Future are ordered by line.
void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats( void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats(
SyntaxHighlighter *highlighter, SyntaxHighlighter *highlighter,
const QFuture<Result> &future, const QFuture<HighlightingResult> &future,
int from, int to, int from, int to,
const QHash<int, QTextCharFormat> &kindToFormat); const QHash<int, QTextCharFormat> &kindToFormat);
@@ -92,7 +94,7 @@ void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats(
// Requires that results of the Future are ordered by line. // Requires that results of the Future are ordered by line.
void TEXTEDITOR_EXPORT clearExtraAdditionalFormatsUntilEnd( void TEXTEDITOR_EXPORT clearExtraAdditionalFormatsUntilEnd(
SyntaxHighlighter *highlighter, SyntaxHighlighter *highlighter,
const QFuture<Result> &future); const QFuture<HighlightingResult> &future);
} // namespace SemanticHighlighter } // namespace SemanticHighlighter

File diff suppressed because it is too large Load Diff