forked from qt-creator/qt-creator
Initial work on smart highlight of local symbols. For-statements and symbols genarated from a macro expansion are not yet highlighted.
This commit is contained in:
@@ -122,6 +122,18 @@ void CheckDeclaration::checkFunctionArguments(Function *fun)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned CheckDeclaration::locationOfDeclaratorId(DeclaratorAST *declarator) const
|
||||
{
|
||||
if (declarator && declarator->core_declarator) {
|
||||
if (DeclaratorIdAST *declaratorId = declarator->core_declarator->asDeclaratorId())
|
||||
return declaratorId->firstToken();
|
||||
else if (NestedDeclaratorAST *nested = declarator->core_declarator->asNestedDeclarator())
|
||||
return locationOfDeclaratorId(nested->declarator);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
|
||||
{
|
||||
FullySpecifiedType ty = semantic()->check(ast->decl_specifier_seq, _scope);
|
||||
@@ -164,11 +176,13 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
|
||||
FullySpecifiedType declTy = semantic()->check(it->declarator, qualTy,
|
||||
_scope, &name);
|
||||
|
||||
unsigned location = 0;
|
||||
if (it->declarator)
|
||||
location = it->declarator->firstToken();
|
||||
else
|
||||
location = ast->firstToken();
|
||||
unsigned location = locationOfDeclaratorId(it->declarator);
|
||||
if (! location) {
|
||||
if (it->declarator)
|
||||
location = it->declarator->firstToken();
|
||||
else
|
||||
location = ast->firstToken();
|
||||
}
|
||||
|
||||
Function *fun = 0;
|
||||
if (declTy && 0 != (fun = declTy->asFunctionType())) {
|
||||
@@ -355,10 +369,13 @@ bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *)
|
||||
|
||||
bool CheckDeclaration::visit(ParameterDeclarationAST *ast)
|
||||
{
|
||||
unsigned sourceLocation = 0;
|
||||
|
||||
if (ast->declarator)
|
||||
sourceLocation = ast->declarator->firstToken();
|
||||
unsigned sourceLocation = locationOfDeclaratorId(ast->declarator);
|
||||
if (! sourceLocation) {
|
||||
if (ast->declarator)
|
||||
sourceLocation = ast->declarator->firstToken();
|
||||
else
|
||||
sourceLocation = ast->firstToken();
|
||||
}
|
||||
|
||||
Name *argName = 0;
|
||||
FullySpecifiedType ty = semantic()->check(ast->type_specifier, _scope);
|
||||
|
||||
@@ -72,6 +72,8 @@ protected:
|
||||
|
||||
using ASTVisitor::visit;
|
||||
|
||||
unsigned locationOfDeclaratorId(DeclaratorAST *declarator) const;
|
||||
|
||||
virtual bool visit(SimpleDeclarationAST *ast);
|
||||
virtual bool visit(EmptyDeclarationAST *ast);
|
||||
virtual bool visit(AccessDeclarationAST *ast);
|
||||
|
||||
@@ -144,6 +144,8 @@ bool CheckStatement::visit(ExpressionStatementAST *ast)
|
||||
bool CheckStatement::visit(ForStatementAST *ast)
|
||||
{
|
||||
Block *block = control()->newBlock(ast->for_token);
|
||||
block->setStartOffset(tokenAt(ast->firstToken()).offset);
|
||||
block->setEndOffset(tokenAt(ast->lastToken()).offset);
|
||||
ast->symbol = block;
|
||||
_scope->enterSymbol(block);
|
||||
Scope *previousScope = switchScope(block->members());
|
||||
@@ -158,6 +160,8 @@ bool CheckStatement::visit(ForStatementAST *ast)
|
||||
bool CheckStatement::visit(IfStatementAST *ast)
|
||||
{
|
||||
Block *block = control()->newBlock(ast->if_token);
|
||||
block->setStartOffset(tokenAt(ast->firstToken()).offset);
|
||||
block->setEndOffset(tokenAt(ast->lastToken()).offset);
|
||||
ast->symbol = block;
|
||||
_scope->enterSymbol(block);
|
||||
Scope *previousScope = switchScope(block->members());
|
||||
@@ -198,6 +202,8 @@ bool CheckStatement::visit(ReturnStatementAST *ast)
|
||||
bool CheckStatement::visit(SwitchStatementAST *ast)
|
||||
{
|
||||
Block *block = control()->newBlock(ast->switch_token);
|
||||
block->setStartOffset(tokenAt(ast->firstToken()).offset);
|
||||
block->setEndOffset(tokenAt(ast->lastToken()).offset);
|
||||
ast->symbol = block;
|
||||
_scope->enterSymbol(block);
|
||||
Scope *previousScope = switchScope(block->members());
|
||||
@@ -219,6 +225,8 @@ bool CheckStatement::visit(TryBlockStatementAST *ast)
|
||||
bool CheckStatement::visit(CatchClauseAST *ast)
|
||||
{
|
||||
Block *block = control()->newBlock(ast->catch_token);
|
||||
block->setStartOffset(tokenAt(ast->firstToken()).offset);
|
||||
block->setEndOffset(tokenAt(ast->lastToken()).offset);
|
||||
ast->symbol = block;
|
||||
_scope->enterSymbol(block);
|
||||
Scope *previousScope = switchScope(block->members());
|
||||
@@ -231,6 +239,8 @@ bool CheckStatement::visit(CatchClauseAST *ast)
|
||||
bool CheckStatement::visit(WhileStatementAST *ast)
|
||||
{
|
||||
Block *block = control()->newBlock(ast->while_token);
|
||||
block->setStartOffset(tokenAt(ast->firstToken()).offset);
|
||||
block->setEndOffset(tokenAt(ast->lastToken()).offset);
|
||||
ast->symbol = block;
|
||||
_scope->enterSymbol(block);
|
||||
Scope *previousScope = switchScope(block->members());
|
||||
|
||||
@@ -328,7 +328,13 @@ FullySpecifiedType Block::type() const
|
||||
{ return FullySpecifiedType(); }
|
||||
|
||||
void Block::visitSymbol0(SymbolVisitor *visitor)
|
||||
{ visitor->visit(this); }
|
||||
{
|
||||
if (visitor->visit(this)) {
|
||||
for (unsigned i = 0; i < memberCount(); ++i) {
|
||||
visitSymbol(memberAt(i), visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
|
||||
: ScopedSymbol(translationUnit, sourceLocation, name)
|
||||
|
||||
Reference in New Issue
Block a user