Commit b58cb740 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Changed ObjC message arguments to have SimpleName for the name part.

parent 4a652f6e
......@@ -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;
}
......@@ -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;
......
......@@ -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;
......
......@@ -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();
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment