forked from qt-creator/qt-creator
Highlight namespaces.
This commit is contained in:
@@ -273,10 +273,24 @@ bool CheckUndefinedSymbols::warning(AST *ast, const QString &text)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckUndefinedSymbols::visit(UsingDirectiveAST *ast)
|
bool CheckUndefinedSymbols::visit(NamespaceAST *ast)
|
||||||
{
|
{
|
||||||
checkNamespace(ast->name);
|
if (ast->identifier_token) {
|
||||||
return false;
|
const Token &tok = tokenAt(ast->identifier_token);
|
||||||
|
if (! tok.generated()) {
|
||||||
|
unsigned line, column;
|
||||||
|
getTokenStartPosition(ast->identifier_token, &line, &column);
|
||||||
|
Use use(line, column, tok.length());
|
||||||
|
_typeUsages.append(use);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckUndefinedSymbols::visit(UsingDirectiveAST *)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckUndefinedSymbols::visit(SimpleDeclarationAST *)
|
bool CheckUndefinedSymbols::visit(SimpleDeclarationAST *)
|
||||||
@@ -284,29 +298,8 @@ bool CheckUndefinedSymbols::visit(SimpleDeclarationAST *)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckUndefinedSymbols::visit(NamedTypeSpecifierAST *ast)
|
bool CheckUndefinedSymbols::visit(NamedTypeSpecifierAST *)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
if (ast->name) {
|
|
||||||
unsigned line, column;
|
|
||||||
getTokenStartPosition(ast->name->firstToken(), &line, &column);
|
|
||||||
|
|
||||||
// ### use the potential types.
|
|
||||||
Scope *enclosingScope = _context.thisDocument()->scopeAt(line, column);
|
|
||||||
const QList<Symbol *> candidates = _context.lookup(ast->name->name, enclosingScope);
|
|
||||||
|
|
||||||
Symbol *ty = 0;
|
|
||||||
foreach (Symbol *c, candidates) {
|
|
||||||
if (c->isTypedef() || c->isClass() || c->isEnum()
|
|
||||||
|| c->isForwardClassDeclaration() || c->isTypenameArgument())
|
|
||||||
ty = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! ty)
|
|
||||||
warning(ast->name, QCoreApplication::translate("CheckUndefinedSymbols", "Expected a type-name"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +323,7 @@ void CheckUndefinedSymbols::checkNamespace(NameAST *name)
|
|||||||
warning(line, column, QCoreApplication::translate("CheckUndefinedSymbols", "Expected a namespace-name"), length);
|
warning(line, column, QCoreApplication::translate("CheckUndefinedSymbols", "Expected a namespace-name"), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckUndefinedSymbols::visit(SimpleNameAST *ast)
|
void CheckUndefinedSymbols::checkName(NameAST *ast)
|
||||||
{
|
{
|
||||||
if (ast->name) {
|
if (ast->name) {
|
||||||
const QByteArray id = QByteArray::fromRawData(ast->name->identifier()->chars(), // ### move
|
const QByteArray id = QByteArray::fromRawData(ast->name->identifier()->chars(), // ### move
|
||||||
@@ -345,25 +338,17 @@ bool CheckUndefinedSymbols::visit(SimpleNameAST *ast)
|
|||||||
addTypeUsage(candidates, ast);
|
addTypeUsage(candidates, ast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckUndefinedSymbols::visit(SimpleNameAST *ast)
|
||||||
|
{
|
||||||
|
checkName(ast);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckUndefinedSymbols::visit(TemplateIdAST *ast)
|
bool CheckUndefinedSymbols::visit(TemplateIdAST *ast)
|
||||||
{
|
{
|
||||||
if (ast->name) {
|
checkName(ast);
|
||||||
const QByteArray id = QByteArray::fromRawData(ast->name->identifier()->chars(), // ### move
|
|
||||||
ast->name->identifier()->size());
|
|
||||||
if (_potentialTypes.contains(id)) {
|
|
||||||
Scope *scope = CollectTypes::findScope(tokenAt(ast->firstToken()).offset, _scopes); // ### move
|
|
||||||
if (! scope)
|
|
||||||
scope = _context.thisDocument()->globalSymbols();
|
|
||||||
|
|
||||||
ClassOrNamespace *b = _context.lookupType(ast->name, scope);
|
|
||||||
addTypeUsage(b, ast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +431,13 @@ void CheckUndefinedSymbols::addTypeUsage(const QList<Symbol *> &candidates, Name
|
|||||||
const unsigned length = tok.length();
|
const unsigned length = tok.length();
|
||||||
|
|
||||||
foreach (Symbol *c, candidates) {
|
foreach (Symbol *c, candidates) {
|
||||||
if (c->isTypedef() || c->isClass() || c->isEnum() || c->isForwardClassDeclaration() || c->isTypenameArgument()) {
|
if (c->isUsingDeclaration()) // skip using declarations...
|
||||||
|
continue;
|
||||||
|
else if (c->isUsingNamespaceDirective()) // ... and using namespace directives.
|
||||||
|
continue;
|
||||||
|
else if (c->isTypedef() || c->isNamespace() ||
|
||||||
|
c->isClass() || c->isEnum() ||
|
||||||
|
c->isForwardClassDeclaration() || c->isTypenameArgument()) {
|
||||||
Use use(line, column, length);
|
Use use(line, column, length);
|
||||||
_typeUsages.append(use);
|
_typeUsages.append(use);
|
||||||
//qDebug() << "added use" << oo(ast->name) << line << column << length;
|
//qDebug() << "added use" << oo(ast->name) << line << column << length;
|
||||||
|
|||||||
@@ -62,10 +62,12 @@ protected:
|
|||||||
bool warning(unsigned line, unsigned column, const QString &text, unsigned length = 0);
|
bool warning(unsigned line, unsigned column, const QString &text, unsigned length = 0);
|
||||||
bool warning(AST *ast, const QString &text);
|
bool warning(AST *ast, const QString &text);
|
||||||
|
|
||||||
|
void checkName(NameAST *ast);
|
||||||
void checkNamespace(NameAST *name);
|
void checkNamespace(NameAST *name);
|
||||||
void addTypeUsage(ClassOrNamespace *b, NameAST *ast);
|
void addTypeUsage(ClassOrNamespace *b, NameAST *ast);
|
||||||
void addTypeUsage(const QList<Symbol *> &candidates, NameAST *ast);
|
void addTypeUsage(const QList<Symbol *> &candidates, NameAST *ast);
|
||||||
|
|
||||||
|
virtual bool visit(NamespaceAST *);
|
||||||
virtual bool visit(UsingDirectiveAST *);
|
virtual bool visit(UsingDirectiveAST *);
|
||||||
virtual bool visit(SimpleDeclarationAST *);
|
virtual bool visit(SimpleDeclarationAST *);
|
||||||
virtual bool visit(NamedTypeSpecifierAST *);
|
virtual bool visit(NamedTypeSpecifierAST *);
|
||||||
|
|||||||
Reference in New Issue
Block a user