From 5723682b218b1de51a966df269c3ccefd9dfcb22 Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Tue, 29 Dec 2009 18:19:35 +0100
Subject: [PATCH] Fixes for highlighting locals in Objective-C methods.

---
 src/plugins/cppeditor/cppeditor.cpp | 23 ++++++++++++++++++++++-
 src/shared/cplusplus/Scope.cpp      |  8 ++++++++
 src/shared/cplusplus/Scope.h        |  3 +++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 7947f4c4b4a..ba09cff487d 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -155,6 +155,9 @@ private:
     virtual bool visit(Function *function)
     { return processScope(function->members()); }
 
+    virtual bool visit(ObjCMethod *method)
+    { return processScope(method->members()); }
+
     bool processScope(Scope *scope)
     {
         if (_scope || ! scope)
@@ -258,9 +261,15 @@ protected:
     }
 
     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;
-        getTokenStartPosition(ast->firstToken(), &line, &column);
+        getTokenStartPosition(tokenIdx, &line, &column);
 
         Scope *scope = findScope(line, column,
                                  _functionScope->owner(),
@@ -273,6 +282,12 @@ protected:
                     return false;
                 else if (findMember(fun->arguments(), ast, line, column))
                     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()) {
                 if (findMember(scope, ast, line, column))
                     return false;
@@ -395,6 +410,12 @@ protected:
 
         return false;
     }
+
+    virtual bool visit(ObjCMethodPrototypeAST *ast)
+    {
+        accept(ast->argument_list);
+        return false;
+    }
 };
 
 
diff --git a/src/shared/cplusplus/Scope.cpp b/src/shared/cplusplus/Scope.cpp
index 86503826d7f..9743e98e449 100644
--- a/src/shared/cplusplus/Scope.cpp
+++ b/src/shared/cplusplus/Scope.cpp
@@ -187,6 +187,14 @@ bool Scope::isFunctionScope() const
     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)
 {
     if (++_symbolCount == _allocatedSymbols) {
diff --git a/src/shared/cplusplus/Scope.h b/src/shared/cplusplus/Scope.h
index a31b6459be6..25df03a25e7 100644
--- a/src/shared/cplusplus/Scope.h
+++ b/src/shared/cplusplus/Scope.h
@@ -114,6 +114,9 @@ public:
     /// Returns true if this scope's owner is an ObjCClass Symbol.
     bool isObjCClassScope() const;
 
+    /// Returns true if this scope's owner is an ObjCMethod symbol.
+    bool isObjCMethodScope() const;
+
     /// Adds a Symbol to this Scope.
     void enterSymbol(Symbol *symbol);
 
-- 
GitLab