Commit e0f55073 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Simplified SemanticInfo::Use.

parent 8c64c97c
......@@ -215,7 +215,7 @@ protected:
if (member->identifier() != id)
continue;
else if (member->line() < line || (member->line() == line && member->column() <= column)) {
localUses[member].append(SemanticInfo::Use(ast, line, column, id->size()));
localUses[member].append(SemanticInfo::Use(line, column, id->size()));
return true;
}
}
......@@ -251,7 +251,7 @@ protected:
}
Identifier *id = identifier(ast->identifier_token);
externalUses[id].append(SemanticInfo::Use(ast, line, column, id->size()));
externalUses[id].append(SemanticInfo::Use(line, column, id->size()));
return false;
}
......@@ -283,7 +283,7 @@ protected:
}
Identifier *id = identifier(ast->identifier_token);
externalUses[id].append(SemanticInfo::Use(ast, line, column, id->size()));
externalUses[id].append(SemanticInfo::Use(line, column, id->size()));
for (TemplateArgumentListAST *arg = ast->template_arguments; arg; arg = arg->next)
accept(arg);
......@@ -902,7 +902,6 @@ void CPPEditor::updateMethodBoxIndex()
static void highlightUses(QTextDocument *doc,
const QTextCharFormat &format,
TranslationUnit *translationUnit,
const QList<SemanticInfo::Use> &uses,
QList<QTextEdit::ExtraSelection> *selections)
{
......@@ -910,34 +909,18 @@ static void highlightUses(QTextDocument *doc,
return;
foreach (const SemanticInfo::Use &use, uses) {
NameAST *name = use.name;
bool generated = false;
QTextEdit::ExtraSelection sel;
for (unsigned tk = name->firstToken(), end = name->lastToken(); tk != end; ++tk) {
if (translationUnit->tokenAt(tk).generated) {
generated = true;
break;
}
}
if (! generated) {
unsigned startLine, startColumn;
unsigned endLine, endColumn;
unsigned identifier_token = name->firstToken();
sel.format = format;
sel.cursor = QTextCursor(doc);
translationUnit->getTokenStartPosition(identifier_token, &startLine, &startColumn);
translationUnit->getTokenEndPosition(identifier_token, &endLine, &endColumn);
const int anchor = doc->findBlockByNumber(use.line - 1).position() + use.column - 1;
const int position = anchor + use.length;
QTextEdit::ExtraSelection sel;
sel.cursor = QTextCursor(doc);
sel.cursor.setPosition(doc->findBlockByNumber(startLine - 1).position() + startColumn - 1);
sel.cursor.setPosition(doc->findBlockByNumber(endLine - 1).position() + endColumn - 1,
QTextCursor::KeepAnchor);
sel.format = format;
sel.cursor.setPosition(anchor);
sel.cursor.setPosition(position, QTextCursor::KeepAnchor);
selections->append(sel);
}
selections->append(sel);
}
}
......@@ -1641,8 +1624,6 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
QList<QTextEdit::ExtraSelection> selections;
TranslationUnit *translationUnit = semanticInfo.doc->translationUnit();
SemanticInfo::LocalUseIterator it(semanticInfo.localUses);
while (it.hasNext()) {
it.next();
......@@ -1661,36 +1642,11 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
if (! good)
continue;
highlightUses(document(), format, translationUnit, uses, &selections);
break; // done
}
#if 0
SemanticInfo::ExternalUseIterator it2(semanticInfo.externalUses);
while (it2.hasNext()) {
it2.next();
const QList<Use> &uses = it2.value();
bool good = false;
foreach (const Use &use, uses) {
unsigned l = line;
unsigned c = column + 1; // convertCursorPosition() returns a 0-based column number.
if (l == use.line && c >= use.column && c <= (use.column + use.length)) {
good = true;
break;
}
}
if (! good)
continue;
highlightUses(document(), format, translationUnit, uses, &selections);
highlightUses(document(), format, uses, &selections);
break; // done
}
#endif
setExtraSelections(CodeSemanticsSelection, selections);
}
SemanticHighlighter::Source CPPEditor::currentSource()
......
......@@ -31,7 +31,6 @@
#define CPPEDITOR_H
#include "cppeditorenums.h"
#include <ASTfwd.h>
#include <cplusplus/CppDocument.h>
#include <texteditor/basetexteditor.h>
......@@ -67,15 +66,15 @@ class SemanticInfo
{
public:
struct Use {
CPlusPlus::NameAST *name;
unsigned line;
unsigned column;
unsigned length;
Use() {}
Use()
: line(0), column(0), length(0) {}
Use(CPlusPlus::NameAST *name, unsigned line, unsigned column, unsigned length)
: name(name), line(line), column(column), length(length) {}
Use(unsigned line, unsigned column, unsigned length)
: line(line), column(column), length(length) {}
};
typedef QHash<CPlusPlus::Symbol *, QList<Use> > LocalUseMap;
......
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