From b58cb740e5e08f7a11a7b176a97351bf49b0d52a Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Mon, 8 Feb 2010 09:34:51 +0100
Subject: [PATCH] Changed ObjC message arguments to have SimpleName for the
 name part.

---
 src/libs/cplusplus/FindUsages.cpp         | 27 ++++++++
 src/libs/cplusplus/FindUsages.h           |  2 +
 src/plugins/cppeditor/cppeditor.cpp       | 82 ++++++++++++-----------
 src/shared/cplusplus/AST.cpp              |  6 +-
 src/shared/cplusplus/AST.h                |  4 +-
 src/shared/cplusplus/ASTClone.cpp         |  3 +-
 src/shared/cplusplus/ASTMatcher.cpp       |  5 +-
 src/shared/cplusplus/ASTVisit.cpp         |  1 +
 src/shared/cplusplus/CheckDeclaration.cpp | 24 +++----
 src/shared/cplusplus/CheckDeclarator.cpp  |  2 +-
 src/shared/cplusplus/CheckName.cpp        |  9 ++-
 src/shared/cplusplus/Parser.cpp           |  3 +-
 12 files changed, 104 insertions(+), 64 deletions(-)

diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp
index 31d75c346f7..7b79b0ac16d 100644
--- a/src/libs/cplusplus/FindUsages.cpp
+++ b/src/libs/cplusplus/FindUsages.cpp
@@ -458,3 +458,30 @@ bool FindUsages::visit(SimpleDeclarationAST *)
 
 void FindUsages::endVisit(SimpleDeclarationAST *)
 { --_inSimpleDeclaration; }
+
+bool FindUsages::visit(ObjCSelectorWithoutArgumentsAST *ast)
+{
+    const Identifier *id = identifier(ast->name_token);
+    if (id == _id) {
+        LookupContext context = currentContext(ast);
+        const QList<Symbol *> candidates = context.resolve(ast->selector_name);
+        reportResult(ast->name_token, candidates);
+    }
+
+    return false;
+}
+
+bool FindUsages::visit(ObjCSelectorWithArgumentsAST *ast)
+{
+    for (ObjCSelectorArgumentListAST *iter = ast->selector_argument_list; iter;
+         iter = iter->next) {
+        const Identifier *id = identifier(iter->value->name_token);
+        if (id == _id) {
+            LookupContext context = currentContext(iter->value);
+            const QList<Symbol *> candidates = context.resolve(ast->selector_name);
+            reportResult(iter->value->name_token, candidates);
+        }
+    }
+
+    return false;
+}
diff --git a/src/libs/cplusplus/FindUsages.h b/src/libs/cplusplus/FindUsages.h
index 1a61cca4e6c..2b066fa2fa5 100644
--- a/src/libs/cplusplus/FindUsages.h
+++ b/src/libs/cplusplus/FindUsages.h
@@ -100,6 +100,8 @@ protected:
     virtual bool visit(FunctionDeclaratorAST *ast);
     virtual bool visit(SimpleDeclarationAST *);
     virtual void endVisit(SimpleDeclarationAST *);
+    virtual bool visit(ObjCSelectorWithoutArgumentsAST *ast);
+    virtual bool visit(ObjCSelectorWithArgumentsAST *ast);
 
 private:
     const Identifier *_id;
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 86976b03400..c4fdf3518e9 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -261,9 +261,6 @@ 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;
@@ -1276,6 +1273,49 @@ void CPPEditor::switchDeclarationDefinition()
     }
 }
 
+static inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolvedSymbols)
+{
+    QList<LookupItem> candidates = resolvedSymbols;
+
+    LookupItem result = candidates.first();
+    const FullySpecifiedType ty = result.type().simplified();
+
+    if (ty->isForwardClassDeclarationType()) {
+        while (! candidates.isEmpty()) {
+            LookupItem r = candidates.takeFirst();
+
+            if (! r.type()->isForwardClassDeclarationType()) {
+                result = r;
+                break;
+            }
+        }
+    }
+
+    if (ty->isObjCForwardClassDeclarationType()) {
+        while (! candidates.isEmpty()) {
+            LookupItem r = candidates.takeFirst();
+
+            if (! r.type()->isObjCForwardClassDeclarationType()) {
+                result = r;
+                break;
+            }
+        }
+    }
+
+    if (ty->isObjCForwardProtocolDeclarationType()) {
+        while (! candidates.isEmpty()) {
+            LookupItem r = candidates.takeFirst();
+
+            if (! r.type()->isObjCForwardProtocolDeclarationType()) {
+                result = r;
+                break;
+            }
+        }
+    }
+
+    return result;
+}
+
 CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
                                       bool resolveTarget)
 {
@@ -1340,41 +1380,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
             typeOfExpression(expression, doc, lastSymbol);
 
     if (!resolvedSymbols.isEmpty()) {
-        LookupItem result = resolvedSymbols.first();
-        const FullySpecifiedType ty = result.type().simplified();
-
-        if (ty->isForwardClassDeclarationType()) {
-            while (! resolvedSymbols.isEmpty()) {
-                LookupItem r = resolvedSymbols.takeFirst();
-
-                if (! r.type()->isForwardClassDeclarationType()) {
-                    result = r;
-                    break;
-                }
-            }
-        }
-
-        if (ty->isObjCForwardClassDeclarationType()) {
-            while (! resolvedSymbols.isEmpty()) {
-                LookupItem r = resolvedSymbols.takeFirst();
-
-                if (! r.type()->isObjCForwardClassDeclarationType()) {
-                    result = r;
-                    break;
-                }
-            }
-        }
-
-        if (ty->isObjCForwardProtocolDeclarationType()) {
-            while (! resolvedSymbols.isEmpty()) {
-                LookupItem r = resolvedSymbols.takeFirst();
-
-                if (! r.type()->isObjCForwardProtocolDeclarationType()) {
-                    result = r;
-                    break;
-                }
-            }
-        }
+        LookupItem result = skipForwardDeclarations(resolvedSymbols);
 
         if (Symbol *symbol = result.lastVisibleSymbol()) {
             Symbol *def = 0;
diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 348f9cddd72..4504d9eadc1 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -2250,13 +2250,13 @@ unsigned ObjCMessageArgumentDeclarationAST::firstToken() const
     if (type_name)
         return type_name->firstToken();
     else
-        return param_name_token;
+        return param_name->firstToken();
 }
 
 unsigned ObjCMessageArgumentDeclarationAST::lastToken() const
 {
-    if (param_name_token)
-        return param_name_token + 1;
+    if (param_name)
+        return param_name->lastToken();
     else if (type_name)
         return type_name->lastToken();
 
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index eef6ec7528b..11bcaf0f1c0 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -2996,12 +2996,12 @@ protected:
     virtual bool match0(AST *, ASTMatcher *);
 };
 
-class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public NameAST
+class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public AST
 {
 public:
     ObjCTypeNameAST* type_name;
     SpecifierListAST *attribute_list;
-    unsigned param_name_token;
+    SimpleNameAST *param_name;
 
 public: // annotations
     Argument *argument;
diff --git a/src/shared/cplusplus/ASTClone.cpp b/src/shared/cplusplus/ASTClone.cpp
index 183cce037a6..805e7837b7a 100644
--- a/src/shared/cplusplus/ASTClone.cpp
+++ b/src/shared/cplusplus/ASTClone.cpp
@@ -1466,7 +1466,8 @@ ObjCMessageArgumentDeclarationAST *ObjCMessageArgumentDeclarationAST::clone(Memo
     for (SpecifierListAST *iter = attribute_list, **ast_iter = &ast->attribute_list;
          iter; iter = iter->next, ast_iter = &(*ast_iter)->next)
         *ast_iter = new (pool) SpecifierListAST((iter->value) ? iter->value->clone(pool) : 0);
-    ast->param_name_token = param_name_token;
+    if (param_name)
+        ast->param_name = param_name->clone(pool);
     return ast;
 }
 
diff --git a/src/shared/cplusplus/ASTMatcher.cpp b/src/shared/cplusplus/ASTMatcher.cpp
index 6992a1d1cc2..7f86349551c 100644
--- a/src/shared/cplusplus/ASTMatcher.cpp
+++ b/src/shared/cplusplus/ASTMatcher.cpp
@@ -2459,7 +2459,10 @@ bool ASTMatcher::match(ObjCMessageArgumentDeclarationAST *node, ObjCMessageArgum
     else if (! AST::match(node->attribute_list, pattern->attribute_list, this))
         return false;
 
-    pattern->param_name_token = node->param_name_token;
+    if (! pattern->param_name)
+        pattern->param_name = node->param_name;
+    else if (! AST::match(node->param_name, pattern->param_name, this))
+        return false;
 
     return true;
 }
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 22d9bd20ded..1b9f50df58d 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -1087,6 +1087,7 @@ void ObjCMessageArgumentDeclarationAST::accept0(ASTVisitor *visitor)
     if (visitor->visit(this)) {
         accept(type_name, visitor);
         accept(attribute_list, visitor);
+        accept(param_name, visitor);
     }
     visitor->endVisit(this);
 }
diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp
index faeac37e106..7ad7662af31 100644
--- a/src/shared/cplusplus/CheckDeclaration.cpp
+++ b/src/shared/cplusplus/CheckDeclaration.cpp
@@ -319,18 +319,14 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
 
     const bool isQ_SLOT   = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_SLOT;
     const bool isQ_SIGNAL = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_SIGNAL;
-#ifdef ICHECK_BUILD
-    const bool isQ_INVOKABLE = (ast->invoke_token > 0);
-#endif
+    const bool isQ_INVOKABLE = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_INVOKABLE;
 
     if (isQ_SIGNAL)
         fun->setMethodKey(Function::SignalMethod);
     else if (isQ_SLOT)
         fun->setMethodKey(Function::SlotMethod);
-#ifdef ICHECK_BUILD
     else if (isQ_INVOKABLE)
-        fun->setInvokable(true);
-#endif
+        fun->setMethodKey(Function::InvokableMethod);
 
     checkFunctionArguments(fun);
 
@@ -672,10 +668,14 @@ bool CheckDeclaration::visit(ObjCClassDeclarationAST *ast)
 
 bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast)
 {
-    if (!ast->method_prototype)
+    ObjCMethodPrototypeAST *methodProto = ast->method_prototype;
+    if (!methodProto)
+        return false;
+    ObjCSelectorAST *selector = methodProto->selector;
+    if (!selector)
         return false;
 
-    FullySpecifiedType ty = semantic()->check(ast->method_prototype, _scope);
+    FullySpecifiedType ty = semantic()->check(methodProto, _scope);
     ObjCMethod *methodTy = ty.type()->asObjCMethodType();
     if (!methodTy)
         return false;
@@ -688,15 +688,15 @@ bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast)
 
         symbol = methodTy;
     } else {
-        Declaration *decl = control()->newDeclaration(ast->firstToken(), methodTy->name());
+        Declaration *decl = control()->newDeclaration(selector->firstToken(), methodTy->name());
         decl->setType(methodTy);
         symbol = decl;
         symbol->setStorage(methodTy->storage());
     }
 
-    symbol->setStartOffset(tokenAt(ast->firstToken()).offset);
-    symbol->setEndOffset(tokenAt(ast->lastToken()).offset);
-    symbol->setVisibility(semantic()->currentVisibility());
+    symbol->setStartOffset(tokenAt(selector->firstToken()).offset);
+    symbol->setEndOffset(tokenAt(selector->lastToken()).offset);
+    symbol->setVisibility(semantic()->currentObjCVisibility());
 
     _scope->enterSymbol(symbol);
 
diff --git a/src/shared/cplusplus/CheckDeclarator.cpp b/src/shared/cplusplus/CheckDeclarator.cpp
index afee09023b4..b1680613936 100644
--- a/src/shared/cplusplus/CheckDeclarator.cpp
+++ b/src/shared/cplusplus/CheckDeclarator.cpp
@@ -259,7 +259,7 @@ bool CheckDeclarator::visit(ObjCMethodPrototypeAST *ast)
 
     FullySpecifiedType returnType = semantic()->check(ast->type_name, _scope);
 
-    unsigned location = ast->firstToken();
+    unsigned location = ast->selector->firstToken();
 
     semantic()->check(ast->selector, _scope);
 
diff --git a/src/shared/cplusplus/CheckName.cpp b/src/shared/cplusplus/CheckName.cpp
index 26fa9c21ee1..98b5adea253 100644
--- a/src/shared/cplusplus/CheckName.cpp
+++ b/src/shared/cplusplus/CheckName.cpp
@@ -418,12 +418,11 @@ bool CheckName::visit(ObjCMessageArgumentDeclarationAST *ast)
     if (ast->type_name)
         type = semantic()->check(ast->type_name, _scope);
 
-    if (ast->param_name_token) {
-        const Identifier *id = identifier(ast->param_name_token);
-        _name = control()->nameId(id);
-        ast->name = _name;
+    if (ast->param_name) {
+        accept(ast->param_name);
 
-        Argument *arg = control()->newArgument(ast->param_name_token, _name);
+        Argument *arg = control()->newArgument(ast->param_name->firstToken(),
+                                               ast->param_name->name);
         ast->argument = arg;
         arg->setType(type);
         arg->setInitializer(0);
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index 60828aa6fe5..86fb18dd2c3 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -5269,7 +5269,8 @@ bool Parser::parseObjCKeywordDeclaration(ObjCSelectorArgumentAST *&argument, Obj
     while (parseAttributeSpecifier(*attr))
         attr = &(*attr)->next;
 
-    match(T_IDENTIFIER, &node->param_name_token);
+    node->param_name = new (_pool) SimpleNameAST;
+    match(T_IDENTIFIER, &node->param_name->identifier_token);
 
     return true;
 }
-- 
GitLab