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

Simplified ObjC selectors in the AST.

parent 69dfa356
......@@ -463,29 +463,26 @@ bool FindUsages::visit(SimpleDeclarationAST *ast)
return false;
}
bool FindUsages::visit(ObjCSelectorWithoutArgumentsAST *ast)
bool FindUsages::visit(ObjCSelectorAST *ast)
{
const Identifier *id = identifier(ast->name_token);
#if 1
const Identifier *id = ast->name->identifier();
if (id == _id) {
LookupContext context = currentContext(ast);
const QList<Symbol *> candidates = context.resolve(ast->selector_name);
reportResult(ast->name_token, candidates);
const QList<Symbol *> candidates = context.resolve(ast->name);
reportResult(ast->firstToken(), candidates);
}
return false;
}
bool FindUsages::visit(ObjCSelectorWithArgumentsAST *ast)
{
#else
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);
const QList<Symbol *> candidates = context.resolve(ast->name);
reportResult(iter->value->name_token, candidates);
}
}
#endif
return false;
}
......@@ -99,8 +99,7 @@ protected:
virtual bool visit(ExpressionOrDeclarationStatementAST *ast);
virtual bool visit(FunctionDeclaratorAST *ast);
virtual bool visit(SimpleDeclarationAST *);
virtual bool visit(ObjCSelectorWithoutArgumentsAST *ast);
virtual bool visit(ObjCSelectorWithArgumentsAST *ast);
virtual bool visit(ObjCSelectorAST *ast);
private:
const Identifier *_id;
......
......@@ -803,12 +803,12 @@ bool ResolveExpression::visit(ObjCMessageExpressionAST *ast)
}
}
if (klassName&&ast->selector && ast->selector->selector_name) {
if (klassName&&ast->selector && ast->selector->name) {
ResolveObjCClass resolveObjCClass;
QList<Symbol *> resolvedSymbols = resolveObjCClass(klassName, result, _context);
foreach (Symbol *resolvedSymbol, resolvedSymbols)
if (ObjCClass *klass = resolvedSymbol->asObjCClass())
_results.append(resolveMember(ast->selector->selector_name, klass));
_results.append(resolveMember(ast->selector->name, klass));
}
}
......
......@@ -1498,6 +1498,15 @@ unsigned SimpleNameAST::lastToken() const
return identifier_token + 1;
}
unsigned ObjCSelectorAST::firstToken() const
{
return selector_argument_list->firstToken();
}
unsigned ObjCSelectorAST::lastToken() const
{
return selector_argument_list->lastToken();
}
unsigned SimpleSpecifierAST::firstToken() const
{
......@@ -2089,16 +2098,6 @@ unsigned ObjCEncodeExpressionAST::lastToken() const
return encode_token + 1;
}
unsigned ObjCSelectorWithoutArgumentsAST::firstToken() const
{
return name_token;
}
unsigned ObjCSelectorWithoutArgumentsAST::lastToken() const
{
return name_token + 1;
}
unsigned ObjCSelectorArgumentAST::firstToken() const
{
return name_token;
......@@ -2112,16 +2111,6 @@ unsigned ObjCSelectorArgumentAST::lastToken() const
return name_token + 1;
}
unsigned ObjCSelectorWithArgumentsAST::firstToken() const
{
return selector_argument_list->firstToken();
}
unsigned ObjCSelectorWithArgumentsAST::lastToken() const
{
return selector_argument_list->lastToken();
}
unsigned ObjCSelectorExpressionAST::firstToken() const
{
return selector_token;
......
......@@ -238,8 +238,6 @@ public:
virtual ObjCSelectorAST *asObjCSelector() { return 0; }
virtual ObjCSelectorArgumentAST *asObjCSelectorArgument() { return 0; }
virtual ObjCSelectorExpressionAST *asObjCSelectorExpression() { return 0; }
virtual ObjCSelectorWithArgumentsAST *asObjCSelectorWithArguments() { return 0; }
virtual ObjCSelectorWithoutArgumentsAST *asObjCSelectorWithoutArguments() { return 0; }
virtual ObjCSynchronizedStatementAST *asObjCSynchronizedStatement() { return 0; }
virtual ObjCSynthesizedPropertiesDeclarationAST *asObjCSynthesizedPropertiesDeclaration() { return 0; }
virtual ObjCSynthesizedPropertyAST *asObjCSynthesizedProperty() { return 0; }
......@@ -371,15 +369,41 @@ public:
virtual PostfixDeclaratorAST *clone(MemoryPool *pool) const = 0;
};
class CPLUSPLUS_EXPORT ObjCSelectorAST: public AST
class CPLUSPLUS_EXPORT ObjCSelectorArgumentAST: public AST
{
public: // annotation
const Name *selector_name;
public:
unsigned name_token;
unsigned colon_token;
public:
virtual ObjCSelectorArgumentAST *asObjCSelectorArgument() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorArgumentAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT ObjCSelectorAST: public NameAST
{
public:
ObjCSelectorArgumentListAST *selector_argument_list;
public:
virtual ObjCSelectorAST *asObjCSelector() { return this; }
virtual ObjCSelectorAST *clone(MemoryPool *pool) const = 0;
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT SimpleSpecifierAST: public SpecifierAST
......@@ -2766,61 +2790,6 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT ObjCSelectorWithoutArgumentsAST: public ObjCSelectorAST
{
public:
unsigned name_token;
public:
virtual ObjCSelectorWithoutArgumentsAST *asObjCSelectorWithoutArguments() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorWithoutArgumentsAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT ObjCSelectorArgumentAST: public AST
{
public:
unsigned name_token;
unsigned colon_token;
public:
virtual ObjCSelectorArgumentAST *asObjCSelectorArgument() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorArgumentAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT ObjCSelectorWithArgumentsAST: public ObjCSelectorAST
{
public:
ObjCSelectorArgumentListAST *selector_argument_list;
public:
virtual ObjCSelectorWithArgumentsAST *asObjCSelectorWithArguments() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorWithArgumentsAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT ObjCSelectorExpressionAST: public ExpressionAST
{
public:
......
......@@ -40,6 +40,23 @@
using namespace CPlusPlus;
ObjCSelectorArgumentAST *ObjCSelectorArgumentAST::clone(MemoryPool *pool) const
{
ObjCSelectorArgumentAST *ast = new (pool) ObjCSelectorArgumentAST;
ast->name_token = name_token;
ast->colon_token = colon_token;
return ast;
}
ObjCSelectorAST *ObjCSelectorAST::clone(MemoryPool *pool) const
{
ObjCSelectorAST *ast = new (pool) ObjCSelectorAST;
for (ObjCSelectorArgumentListAST *iter = selector_argument_list, **ast_iter = &ast->selector_argument_list;
iter; iter = iter->next, ast_iter = &(*ast_iter)->next)
*ast_iter = new (pool) ObjCSelectorArgumentListAST((iter->value) ? iter->value->clone(pool) : 0);
return ast;
}
SimpleSpecifierAST *SimpleSpecifierAST::clone(MemoryPool *pool) const
{
SimpleSpecifierAST *ast = new (pool) SimpleSpecifierAST;
......@@ -1351,30 +1368,6 @@ ObjCEncodeExpressionAST *ObjCEncodeExpressionAST::clone(MemoryPool *pool) const
return ast;
}
ObjCSelectorWithoutArgumentsAST *ObjCSelectorWithoutArgumentsAST::clone(MemoryPool *pool) const
{
ObjCSelectorWithoutArgumentsAST *ast = new (pool) ObjCSelectorWithoutArgumentsAST;
ast->name_token = name_token;
return ast;
}
ObjCSelectorArgumentAST *ObjCSelectorArgumentAST::clone(MemoryPool *pool) const
{
ObjCSelectorArgumentAST *ast = new (pool) ObjCSelectorArgumentAST;
ast->name_token = name_token;
ast->colon_token = colon_token;
return ast;
}
ObjCSelectorWithArgumentsAST *ObjCSelectorWithArgumentsAST::clone(MemoryPool *pool) const
{
ObjCSelectorWithArgumentsAST *ast = new (pool) ObjCSelectorWithArgumentsAST;
for (ObjCSelectorArgumentListAST *iter = selector_argument_list, **ast_iter = &ast->selector_argument_list;
iter; iter = iter->next, ast_iter = &(*ast_iter)->next)
*ast_iter = new (pool) ObjCSelectorArgumentListAST((iter->value) ? iter->value->clone(pool) : 0);
return ast;
}
ObjCSelectorExpressionAST *ObjCSelectorExpressionAST::clone(MemoryPool *pool) const
{
ObjCSelectorExpressionAST *ast = new (pool) ObjCSelectorExpressionAST;
......
......@@ -41,6 +41,22 @@
using namespace CPlusPlus;
bool ObjCSelectorArgumentAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ObjCSelectorArgumentAST *_other = pattern->asObjCSelectorArgument())
return matcher->match(this, _other);
return false;
}
bool ObjCSelectorAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ObjCSelectorAST *_other = pattern->asObjCSelector())
return matcher->match(this, _other);
return false;
}
bool SimpleSpecifierAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (SimpleSpecifierAST *_other = pattern->asSimpleSpecifier())
......@@ -937,30 +953,6 @@ bool ObjCEncodeExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool ObjCSelectorWithoutArgumentsAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ObjCSelectorWithoutArgumentsAST *_other = pattern->asObjCSelectorWithoutArguments())
return matcher->match(this, _other);
return false;
}
bool ObjCSelectorArgumentAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ObjCSelectorArgumentAST *_other = pattern->asObjCSelectorArgument())
return matcher->match(this, _other);
return false;
}
bool ObjCSelectorWithArgumentsAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ObjCSelectorWithArgumentsAST *_other = pattern->asObjCSelectorWithArguments())
return matcher->match(this, _other);
return false;
}
bool ObjCSelectorExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ObjCSelectorExpressionAST *_other = pattern->asObjCSelectorExpression())
......
......@@ -47,6 +47,31 @@ ASTMatcher::ASTMatcher()
ASTMatcher::~ASTMatcher()
{ }
bool ASTMatcher::match(ObjCSelectorArgumentAST *node, ObjCSelectorArgumentAST *pattern)
{
(void) node;
(void) pattern;
pattern->name_token = node->name_token;
pattern->colon_token = node->colon_token;
return true;
}
bool ASTMatcher::match(ObjCSelectorAST *node, ObjCSelectorAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->selector_argument_list)
pattern->selector_argument_list = node->selector_argument_list;
else if (! AST::match(node->selector_argument_list, pattern->selector_argument_list, this))
return false;
return true;
}
bool ASTMatcher::match(SimpleSpecifierAST *node, SimpleSpecifierAST *pattern)
{
(void) node;
......@@ -2272,41 +2297,6 @@ bool ASTMatcher::match(ObjCEncodeExpressionAST *node, ObjCEncodeExpressionAST *p
return true;
}
bool ASTMatcher::match(ObjCSelectorWithoutArgumentsAST *node, ObjCSelectorWithoutArgumentsAST *pattern)
{
(void) node;
(void) pattern;
pattern->name_token = node->name_token;
return true;
}
bool ASTMatcher::match(ObjCSelectorArgumentAST *node, ObjCSelectorArgumentAST *pattern)
{
(void) node;
(void) pattern;
pattern->name_token = node->name_token;
pattern->colon_token = node->colon_token;
return true;
}
bool ASTMatcher::match(ObjCSelectorWithArgumentsAST *node, ObjCSelectorWithArgumentsAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->selector_argument_list)
pattern->selector_argument_list = node->selector_argument_list;
else if (! AST::match(node->selector_argument_list, pattern->selector_argument_list, this))
return false;
return true;
}
bool ASTMatcher::match(ObjCSelectorExpressionAST *node, ObjCSelectorExpressionAST *pattern)
{
(void) node;
......
......@@ -146,14 +146,13 @@ public:
virtual bool match(ObjCProtocolDeclarationAST *node, ObjCProtocolDeclarationAST *pattern);
virtual bool match(ObjCProtocolForwardDeclarationAST *node, ObjCProtocolForwardDeclarationAST *pattern);
virtual bool match(ObjCProtocolRefsAST *node, ObjCProtocolRefsAST *pattern);
virtual bool match(ObjCSelectorAST *node, ObjCSelectorAST *pattern);
virtual bool match(ObjCMessageExpressionAST *node, ObjCMessageExpressionAST *pattern);
virtual bool match(ObjCMessageArgumentAST *node, ObjCMessageArgumentAST *pattern);
virtual bool match(ObjCProtocolExpressionAST *node, ObjCProtocolExpressionAST *pattern);
virtual bool match(ObjCTypeNameAST *node, ObjCTypeNameAST *pattern);
virtual bool match(ObjCEncodeExpressionAST *node, ObjCEncodeExpressionAST *pattern);
virtual bool match(ObjCSelectorWithoutArgumentsAST *node, ObjCSelectorWithoutArgumentsAST *pattern);
virtual bool match(ObjCSelectorArgumentAST *node, ObjCSelectorArgumentAST *pattern);
virtual bool match(ObjCSelectorWithArgumentsAST *node, ObjCSelectorWithArgumentsAST *pattern);
virtual bool match(ObjCSelectorExpressionAST *node, ObjCSelectorExpressionAST *pattern);
virtual bool match(ObjCInstanceVariablesDeclarationAST *node, ObjCInstanceVariablesDeclarationAST *pattern);
virtual bool match(ObjCVisibilityDeclarationAST *node, ObjCVisibilityDeclarationAST *pattern);
......
......@@ -788,24 +788,12 @@ public:
return __ast;
}
ObjCSelectorWithoutArgumentsAST *ObjCSelectorWithoutArguments()
{
ObjCSelectorWithoutArgumentsAST *__ast = new (&pool) ObjCSelectorWithoutArgumentsAST;
return __ast;
}
ObjCSelectorArgumentAST *ObjCSelectorArgument()
{
ObjCSelectorArgumentAST *__ast = new (&pool) ObjCSelectorArgumentAST;
return __ast;
}
ObjCSelectorWithArgumentsAST *ObjCSelectorWithArguments()
{
ObjCSelectorWithArgumentsAST *__ast = new (&pool) ObjCSelectorWithArgumentsAST;
return __ast;
}
ObjCSelectorExpressionAST *ObjCSelectorExpression(ObjCSelectorAST *selector = 0)
{
ObjCSelectorExpressionAST *__ast = new (&pool) ObjCSelectorExpressionAST;
......
......@@ -41,6 +41,21 @@
using namespace CPlusPlus;
void ObjCSelectorArgumentAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void ObjCSelectorAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(selector_argument_list, visitor);
}
visitor->endVisit(this);
}
void SimpleSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -995,28 +1010,6 @@ void ObjCEncodeExpressionAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void ObjCSelectorWithoutArgumentsAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void ObjCSelectorArgumentAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void ObjCSelectorWithArgumentsAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(selector_argument_list, visitor);
}
visitor->endVisit(this);
}
void ObjCSelectorExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......
......@@ -211,14 +211,13 @@ public:
virtual bool visit(ObjCProtocolDeclarationAST *) { return true; }
virtual bool visit(ObjCProtocolForwardDeclarationAST *) { return true; }
virtual bool visit(ObjCProtocolRefsAST *) { return true; }
virtual bool visit(ObjCSelectorAST *) { return true; }
virtual bool visit(ObjCMessageExpressionAST *) { return true; }
virtual bool visit(ObjCMessageArgumentAST *) { return true; }
virtual bool visit(ObjCProtocolExpressionAST *) { return true; }
virtual bool visit(ObjCTypeNameAST *) { return true; }
virtual bool visit(ObjCEncodeExpressionAST *) { return true; }
virtual bool visit(ObjCSelectorWithoutArgumentsAST *) { return true; }
virtual bool visit(ObjCSelectorArgumentAST *) { return true; }
virtual bool visit(ObjCSelectorWithArgumentsAST *) { return true; }
virtual bool visit(ObjCSelectorExpressionAST *) { return true; }
virtual bool visit(ObjCInstanceVariablesDeclarationAST *) { return true; }
virtual bool visit(ObjCVisibilityDeclarationAST *) { return true; }
......@@ -342,14 +341,13 @@ public:
virtual void endVisit(ObjCProtocolDeclarationAST *) { }
virtual void endVisit(ObjCProtocolForwardDeclarationAST *) { }
virtual void endVisit(ObjCProtocolRefsAST *) { }
virtual void endVisit(ObjCSelectorAST *) { }
virtual void endVisit(ObjCMessageExpressionAST *) { }
virtual void endVisit(ObjCMessageArgumentAST *) { }
virtual void endVisit(ObjCProtocolExpressionAST *) { }
virtual void endVisit(ObjCTypeNameAST *) { }
virtual void endVisit(ObjCEncodeExpressionAST *) { }
virtual void endVisit(ObjCSelectorWithoutArgumentsAST *) { }
virtual void endVisit(ObjCSelectorArgumentAST *) { }
virtual void endVisit(ObjCSelectorWithArgumentsAST *) { }
virtual void endVisit(ObjCSelectorExpressionAST *) { }
virtual void endVisit(ObjCInstanceVariablesDeclarationAST *) { }
virtual void endVisit(ObjCVisibilityDeclarationAST *) { }
......
......@@ -145,8 +145,6 @@ class ObjCProtocolRefsAST;
class ObjCSelectorAST;
class ObjCSelectorArgumentAST;
class ObjCSelectorExpressionAST;
class ObjCSelectorWithArgumentsAST;
class ObjCSelectorWithoutArgumentsAST;
class ObjCSynchronizedStatementAST;
class ObjCSynthesizedPropertiesDeclarationAST;
class ObjCSynthesizedPropertyAST;
......
......@@ -263,7 +263,7 @@ bool CheckDeclarator::visit(ObjCMethodPrototypeAST *ast)
semantic()->check(ast->selector, _scope);
ObjCMethod *method = control()->newObjCMethod(location, ast->selector->selector_name);
ObjCMethod *method = control()->newObjCMethod(location, ast->selector->name);
ast->symbol = method;
method->setScope(_scope);
method->setVisibility(semantic()->currentVisibility());
......@@ -271,17 +271,15 @@ bool CheckDeclarator::visit(ObjCMethodPrototypeAST *ast)
if (semantic()->isObjCClassMethod(tokenKind(ast->method_type_token)))
method->setStorage(Symbol::Static);
if (ast->selector->asObjCSelectorWithArguments()) {
for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
ObjCMessageArgumentDeclarationAST *argDecl = it->value;
for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
ObjCMessageArgumentDeclarationAST *argDecl = it->value;
semantic()->check(argDecl, method->arguments());
}
if (ast->dot_dot_dot_token)
method->setVariadic(true);
semantic()->check(argDecl, method->arguments());
}
if (ast->dot_dot_dot_token)
method->setVariadic(true);
_fullySpecifiedType = FullySpecifiedType(method);
return false;
......
......@@ -100,17 +100,6 @@ const Name *CheckName::check(NestedNameSpecifierListAST *nested_name_specifier_l
return switchName(previousName);
}
const Name *CheckName::check(ObjCSelectorAST *args, Scope *scope)
{
const Name *previousName = switchName(0);
Scope *previousScope = switchScope(scope);
accept(args);