Fixes for highlighting locals in Objective-C methods.

This commit is contained in:
Erik Verbruggen
2009-12-29 18:19:35 +01:00
parent 7c0f4e8f50
commit 5723682b21
3 changed files with 33 additions and 1 deletions

View File

@@ -155,6 +155,9 @@ private:
virtual bool visit(Function *function) virtual bool visit(Function *function)
{ return processScope(function->members()); } { return processScope(function->members()); }
virtual bool visit(ObjCMethod *method)
{ return processScope(method->members()); }
bool processScope(Scope *scope) bool processScope(Scope *scope)
{ {
if (_scope || ! scope) if (_scope || ! scope)
@@ -258,9 +261,15 @@ protected:
} }
virtual bool visit(SimpleNameAST *ast) virtual bool visit(SimpleNameAST *ast)
{ return findMemberForToken(ast->firstToken(), ast); }
virtual bool visit(ObjCMessageArgumentDeclarationAST *ast)
{ return findMemberForToken(ast->param_name_token, ast); }
bool findMemberForToken(unsigned tokenIdx, NameAST *ast)
{ {
unsigned line, column; unsigned line, column;
getTokenStartPosition(ast->firstToken(), &line, &column); getTokenStartPosition(tokenIdx, &line, &column);
Scope *scope = findScope(line, column, Scope *scope = findScope(line, column,
_functionScope->owner(), _functionScope->owner(),
@@ -273,6 +282,12 @@ protected:
return false; return false;
else if (findMember(fun->arguments(), ast, line, column)) else if (findMember(fun->arguments(), ast, line, column))
return false; return false;
} else if (scope->isObjCMethodScope()) {
ObjCMethod *method = scope->owner()->asObjCMethod();
if (findMember(method->members(), ast, line, column))
return false;
else if (findMember(method->arguments(), ast, line, column))
return false;
} else if (scope->isBlockScope()) { } else if (scope->isBlockScope()) {
if (findMember(scope, ast, line, column)) if (findMember(scope, ast, line, column))
return false; return false;
@@ -395,6 +410,12 @@ protected:
return false; return false;
} }
virtual bool visit(ObjCMethodPrototypeAST *ast)
{
accept(ast->argument_list);
return false;
}
}; };

View File

@@ -187,6 +187,14 @@ bool Scope::isFunctionScope() const
return false; return false;
} }
bool Scope::isObjCMethodScope() const
{
ObjCMethod *m = 0;
if (_owner && 0 != (m = _owner->asObjCMethod()))
return m->arguments() != this;
return false;
}
void Scope::enterSymbol(Symbol *symbol) void Scope::enterSymbol(Symbol *symbol)
{ {
if (++_symbolCount == _allocatedSymbols) { if (++_symbolCount == _allocatedSymbols) {

View File

@@ -114,6 +114,9 @@ public:
/// Returns true if this scope's owner is an ObjCClass Symbol. /// Returns true if this scope's owner is an ObjCClass Symbol.
bool isObjCClassScope() const; bool isObjCClassScope() const;
/// Returns true if this scope's owner is an ObjCMethod symbol.
bool isObjCMethodScope() const;
/// Adds a Symbol to this Scope. /// Adds a Symbol to this Scope.
void enterSymbol(Symbol *symbol); void enterSymbol(Symbol *symbol);