Commit 26267c03 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Improved ObjC parsing, and added semantic checks.

parent a9b521f8
......@@ -154,6 +154,14 @@ void CheckUndefinedSymbols::buildTypeMap(NamespaceBinding *binding, QSet<Namespa
} else if (Declaration *decl = member->asDeclaration()) {
if (decl->isTypedef())
addType(decl->name());
} else if (ObjCForwardClassDeclaration *fKlass = member->asObjCForwardClassDeclaration()) {
addType(fKlass->name());
} else if (ObjCClass *klass = member->asObjCClass()) {
addType(klass->name());
} else if (ObjCForwardProtocolDeclaration *fProto = member->asObjCForwardProtocolDeclaration()) {
addType(fProto->name());
} else if (ObjCProtocol *proto = member->asObjCProtocol()) {
addType(proto->name());
}
}
}
......
......@@ -98,6 +98,10 @@ QIcon Icons::iconForSymbol(const Symbol *symbol) const
return _enumIcon;
} else if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
return _classIcon;
} else if (symbol->isObjCClass() || symbol->isObjCForwardClassDeclaration()) {
return _classIcon;
} else if (symbol->isObjCProtocol() || symbol->isObjCForwardProtocolDeclaration()) {
return _classIcon;
} else if (symbol->isNamespace()) {
return _namespaceIcon;
} else if (symbol->isUsingNamespaceDirective() ||
......
......@@ -1906,14 +1906,17 @@ unsigned WhileStatementAST::lastToken() const
// ObjC++
unsigned IdentifierListAST::firstToken() const
{
return identifier_token;
if (name)
return name->firstToken();
else
return comma_token;
}
unsigned IdentifierListAST::lastToken() const
{
for (const IdentifierListAST *it = this; it; it = it->next) {
if (! it->next && it->identifier_token) {
return it->identifier_token + 1;
if (! it->next && it->name) {
return it->name->lastToken();
}
}
// ### assert?
......@@ -1934,8 +1937,8 @@ unsigned ObjCClassDeclarationAST::lastToken() const
return semicolon_token + 1;
for (IdentifierListAST *it = identifier_list; it; it = it->next) {
if (! it->next && it->identifier_token)
return it->identifier_token + 1;
if (! it->next && it->name)
return it->name->lastToken();
}
for (SpecifierAST *it = attributes; it; it = it->next) {
......@@ -1959,8 +1962,8 @@ unsigned ObjCProtocolDeclarationAST::lastToken() const
return semicolon_token + 1;
for (IdentifierListAST *it = identifier_list; it; it = it->next) {
if (! it->next && it->identifier_token)
return it->identifier_token + 1;
if (! it->next && it->name)
return it->name->lastToken();
}
for (SpecifierAST *it = attributes; it; it = it->next) {
......@@ -1971,21 +1974,21 @@ unsigned ObjCProtocolDeclarationAST::lastToken() const
return protocol_token + 1;
}
unsigned ObjCClassInterfaceDeclarationAST::firstToken() const
unsigned ObjCClassInterfaceDefinitionAST::firstToken() const
{
if (attributes)
return attributes->firstToken();
return interface_token;
}
unsigned ObjCClassInterfaceDeclarationAST::lastToken() const
unsigned ObjCClassInterfaceDefinitionAST::lastToken() const
{
if (end_token) return end_token + 1;
if (member_declarations) return member_declarations->lastToken();
if (inst_vars_decl) return inst_vars_decl->lastToken();
if (superclass_identifier_token) return superclass_identifier_token + 1;
if (colon_token) return colon_token + 1;
if (class_identifier_token) return class_identifier_token + 1;
if (class_name) return class_name->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
......@@ -2036,8 +2039,8 @@ unsigned ObjCProtocolDefinitionAST::lastToken() const
if (protocol_refs)
return protocol_refs->lastToken();
if (identifier_token)
return identifier_token + 1;
if (name)
return name->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
......@@ -2057,8 +2060,8 @@ unsigned ObjCProtocolRefsAST::lastToken() const
if (greater_token) return greater_token + 1;
for (IdentifierListAST *it = identifier_list; it; it = it->next) {
if (! it->next && it->identifier_token)
return it->identifier_token + 1;
if (! it->next && it->name)
return it->name->lastToken();
}
return less_token + 1;
......@@ -2169,6 +2172,74 @@ 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;
}
unsigned ObjCSelectorArgumentAST::lastToken() const
{
if (colon_token)
return colon_token + 1;
else
return name_token + 1;
}
unsigned ObjCSelectorArgumentListAST::firstToken() const
{
if (argument)
return argument->firstToken();
// ### assert?
return 0;
}
unsigned ObjCSelectorArgumentListAST::lastToken() const
{
for (const ObjCSelectorArgumentListAST *it = this; it; it = it->next)
if (!it->next && it->argument)
return it->argument->lastToken();
// ### assert?
return 0;
}
unsigned ObjCSelectorWithArgumentsAST::firstToken() const
{
return selector_arguments->firstToken();
}
unsigned ObjCSelectorWithArgumentsAST::lastToken() const
{
return selector_arguments->lastToken();
}
unsigned ObjCSelectorExpressionAST::firstToken() const
{
return selector_token;
}
unsigned ObjCSelectorExpressionAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
if (selector)
return selector->lastToken();
if (lparen_token)
return rparen_token + 1;
return selector_token + 1;
}
unsigned ObjCInstanceVariablesDeclarationAST::firstToken() const
{
return lbrace_token;
......@@ -2179,9 +2250,6 @@ unsigned ObjCInstanceVariablesDeclarationAST::lastToken() const
if (rbrace_token)
return rbrace_token + 1;
if (member_declarations)
return member_declarations->lastToken();
if (instance_variables)
return instance_variables->lastToken();
......@@ -2198,24 +2266,22 @@ unsigned ObjCVisibilityDeclarationAST::lastToken() const
return visibility_token + 1;
}
unsigned ObjcPropertyAttributeAST::firstToken() const
unsigned ObjCPropertyAttributeAST::firstToken() const
{
return attribute_identifier_token;
}
unsigned ObjcPropertyAttributeAST::lastToken() const
unsigned ObjCPropertyAttributeAST::lastToken() const
{
if (colon_token)
return colon_token + 1;
if (method_selector_identifier_token)
return method_selector_identifier_token + 1;
if (method_selector)
return method_selector->lastToken();
if (equals_token)
return equals_token + 1;
return attribute_identifier_token + 1;
}
unsigned ObjcPropertyAttributeListAST::firstToken() const
unsigned ObjCPropertyAttributeListAST::firstToken() const
{
if (attr)
return attr->firstToken();
......@@ -2228,9 +2294,9 @@ unsigned ObjcPropertyAttributeListAST::firstToken() const
return 0;
}
unsigned ObjcPropertyAttributeListAST::lastToken() const
unsigned ObjCPropertyAttributeListAST::lastToken() const
{
for (const ObjcPropertyAttributeListAST *it = this; it; it = it->next) {
for (const ObjCPropertyAttributeListAST *it = this; it; it = it->next) {
if (! it->next && (comma_token || it->attr)) {
if (comma_token)
return comma_token + 1;
......@@ -2266,21 +2332,21 @@ unsigned ObjCPropertyDeclarationAST::lastToken() const
unsigned ObjCMessageArgumentDeclarationAST::firstToken() const
{
return param_selector_token;
if (type_name)
return type_name->firstToken();
else
return param_name_token;
}
unsigned ObjCMessageArgumentDeclarationAST::lastToken() const
{
if (param_name_token)
return param_name_token + 1;
else if (colon_token)
return colon_token + 1;
else if (type_name)
return type_name->lastToken();
else if (attributes)
return attributes->lastToken();
else
return param_name_token + 1;
// ### assert?
return 0;
}
unsigned ObjCMessageArgumentDeclarationListAST::firstToken() const
......
......@@ -196,9 +196,40 @@ public:
virtual UsingDirectiveAST *asUsingDirective() { return 0; }
virtual WhileStatementAST *asWhileStatement() { return 0; }
virtual IdentifierListAST *asIdentifierList() { return 0; }
virtual ObjCClassDeclarationAST *asObjCClassDeclaration() { return 0; }
virtual ObjCProtocolDeclarationAST *asObjCProtocolDeclaration() { return 0; }
virtual ObjCProtocolDefinitionAST *asObjCProtocolDefinition() { return 0; }
virtual ObjCProtocolRefsAST *asObjCProtocolRefs() { return 0; }
virtual ObjCMessageArgumentAST *asObjCMessageArgument() { return 0; }
virtual ObjCMessageArgumentListAST *asObjCMessageArgumentList() { return 0; }
virtual ObjCMessageExpressionAST *asObjCMessageExpression() { return 0; }
virtual ObjCProtocolExpressionAST *asObjCProtocolExpression() { return 0; }
virtual ObjCTypeNameAST *asObjCTypeName() { return 0; }
virtual ObjCEncodeExpressionAST *asObjCEncodeExpression() { return 0; }
virtual ObjCSelectorAST *asObjCSelector() { return 0; }
virtual ObjCSelectorWithoutArgumentsAST *asObjCSelectorWithoutArguments() { return 0; }
virtual ObjCSelectorArgumentAST *asObjCSelectorArgument() { return 0; }
virtual ObjCSelectorArgumentListAST *asObjCSelectorArgumentList() { return 0; }
virtual ObjCSelectorWithArgumentsAST *asObjCSelectorWithArguments() { return 0; }
virtual ObjCSelectorExpressionAST *asObjCSelectorExpression() { return 0; }
virtual ObjCInstanceVariablesDeclarationAST *asObjCInstanceVariablesDeclaration() { return 0; }
virtual ObjCVisibilityDeclarationAST *asObjCVisibilityDeclaration() { return 0; }
virtual ObjCPropertyAttributeAST *asObjCPropertyAttribute() { return 0; }
virtual ObjCPropertyAttributeListAST *asObjCPropertyAttributeList() { return 0; }
virtual ObjCPropertyDeclarationAST *asObjCPropertyDeclaration() { return 0; }
virtual ObjCMessageArgumentDeclarationAST *asObjCMessageArgumentDeclaration() { return 0; }
virtual ObjCMessageArgumentDeclarationListAST *asObjCMessageArgumentDeclarationList() { return 0; }
virtual ObjCMethodPrototypeAST *asObjCMethodPrototype() { return 0; }
virtual ObjCMethodDeclarationAST *asObjCMethodDeclaration() { return 0; }
virtual ObjCMethodDefinitionAST *asObjCMethodDefinition() { return 0; }
virtual ObjCClassImplementationAST *asObjCClassImplementation() { return 0; }
virtual ObjCCategoryImplementationAST *asObjCCategoryImplementation() { return 0; }
virtual ObjCSynthesizedPropertyAST *asObjCSynthesizedProperty() { return 0; }
virtual ObjCSynthesizedPropertyListAST *asObjCSynthesizedPropertyList() { return 0; }
virtual ObjCSynthesizedPropertiesDeclarationAST *asObjCSynthesizedPropertiesDeclaration() { return 0; }
virtual ObjCDynamicPropertiesDeclarationAST *asObjCDynamicPropertiesDeclaration() { return 0; }
virtual ObjCFastEnumerationAST *asObjCFastEnumeration() { return 0; }
virtual AST *clone(MemoryPool *pool) const = 0;
......@@ -2444,7 +2475,7 @@ protected:
class CPLUSPLUS_EXPORT IdentifierListAST: public AST
{
public:
unsigned identifier_token;
SimpleNameAST *name;
unsigned comma_token;
IdentifierListAST *next;
......@@ -2469,6 +2500,9 @@ public:
IdentifierListAST *identifier_list;
unsigned semicolon_token;
public: // annotations
List<ObjCForwardClassDeclaration *> *symbols;
public:
virtual ObjCClassDeclarationAST *asObjCClassDeclaration()
{ return this; }
......@@ -2482,12 +2516,12 @@ protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCClassInterfaceDeclarationAST: public DeclarationAST
class CPLUSPLUS_EXPORT ObjCClassInterfaceDefinitionAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
unsigned interface_token;
unsigned class_identifier_token;
SimpleNameAST *class_name;
unsigned colon_token;
unsigned superclass_identifier_token;
ObjCProtocolRefsAST *protocol_refs;
......@@ -2495,14 +2529,17 @@ public:
DeclarationListAST *member_declarations;
unsigned end_token;
public: // annotations
ObjCClass *symbol;
public:
virtual ObjCClassInterfaceDeclarationAST *asObjCClassInterfaceDeclaration()
virtual ObjCClassInterfaceDefinitionAST *asObjCClassInterfaceDefinition()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCClassInterfaceDeclarationAST *clone(MemoryPool *pool) const;
virtual ObjCClassInterfaceDefinitionAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
......@@ -2542,6 +2579,9 @@ public:
IdentifierListAST *identifier_list;
unsigned semicolon_token;
public: // annotations
List<ObjCForwardProtocolDeclaration *> *symbols;
public:
virtual ObjCProtocolDeclarationAST *asObjCProtocolDeclaration()
{ return this; }
......@@ -2560,11 +2600,14 @@ class CPLUSPLUS_EXPORT ObjCProtocolDefinitionAST: public DeclarationAST
public:
SpecifierAST *attributes;
unsigned protocol_token;
unsigned identifier_token;
SimpleNameAST *name;
ObjCProtocolRefsAST *protocol_refs;
DeclarationListAST *member_declarations;
unsigned end_token;
public: // annotations
ObjCProtocol *symbol;
public:
virtual ObjCProtocolDefinitionAST *asObjCProtocolDefinition()
{ return this; }
......@@ -2719,12 +2762,118 @@ protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCSelectorAST: public AST
{
public: // annotation
Name *selector_name;
public:
virtual ObjCSelectorAST *asObjCSelector()
{ return this; }
virtual ObjCSelectorAST *clone(MemoryPool *pool) const = 0;
};
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);
};
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);
};
class CPLUSPLUS_EXPORT ObjCSelectorArgumentListAST: public AST
{
public:
ObjCSelectorArgumentAST *argument;
ObjCSelectorArgumentListAST *next;
public:
virtual ObjCSelectorArgumentListAST *asObjCSelectorArgumentList()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorArgumentListAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCSelectorWithArgumentsAST: public ObjCSelectorAST
{
public:
ObjCSelectorArgumentListAST *selector_arguments;
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);
};
class CPLUSPLUS_EXPORT ObjCSelectorExpressionAST: public ExpressionAST
{
public:
unsigned selector_token;
unsigned lparen_token;
ObjCSelectorAST *selector;
unsigned rparen_token;
public:
virtual ObjCSelectorExpressionAST *asObjCSelectorExpression()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSelectorExpressionAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCInstanceVariablesDeclarationAST: public AST
{
public:
unsigned lbrace_token;
DeclarationListAST *instance_variables;
DeclarationListAST *member_declarations;
unsigned rbrace_token;
public:
......@@ -2758,42 +2907,41 @@ protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjcPropertyAttributeAST: public AST
class CPLUSPLUS_EXPORT ObjCPropertyAttributeAST: public AST
{
public:
unsigned attribute_identifier_token;
unsigned equals_token;
unsigned method_selector_identifier_token;
unsigned colon_token;
ObjCSelectorAST *method_selector;
public:
virtual ObjcPropertyAttributeAST *asObjcPropertyAttribute()
virtual ObjCPropertyAttributeAST *asObjCPropertyAttribute()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjcPropertyAttributeAST *clone(MemoryPool *pool) const;
virtual ObjCPropertyAttributeAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjcPropertyAttributeListAST: public AST
class CPLUSPLUS_EXPORT ObjCPropertyAttributeListAST: public AST
{
public:
ObjcPropertyAttributeAST *attr;
ObjCPropertyAttributeAST *attr;
unsigned comma_token;
ObjcPropertyAttributeListAST *next;
ObjCPropertyAttributeListAST *next;
public:
virtual ObjcPropertyAttributeListAST *asObjcPropertyAttributeList()
virtual ObjCPropertyAttributeListAST *asObjCPropertyAttributeList()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjcPropertyAttributeListAST *clone(MemoryPool *pool) const;
virtual ObjCPropertyAttributeListAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
......@@ -2805,7 +2953,7 @@ public:
SpecifierAST *attributes;
unsigned property_token;
unsigned lparen_token;
ObjcPropertyAttributeListAST *property_attributes;
ObjCPropertyAttributeListAST *property_attributes;
unsigned rparen_token;
DeclarationAST *simple_declaration;
......@@ -2825,12 +2973,13 @@ protected:
class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public AST
{
public:
unsigned param_selector_token;
unsigned colon_token;
ObjCTypeNameAST* type_name;
SpecifierAST *attributes;
unsigned param_name_token;
public: // annotations
Name *param_name;
public:
virtual ObjCMessageArgumentDeclarationAST *asObjCMessageArgumentDeclaration()
{ return this; }
......@@ -2868,9 +3017,13 @@ class CPLUSPLUS_EXPORT ObjCMethodPrototypeAST: public AST
public:
unsigned method_type_token;
ObjCTypeNameAST *type_name;
ObjCSelectorAST *selector;
ObjCMessageArgumentDeclarationListAST *arguments;
SpecifierAST *attributes;
public: // annotations
Function *symbol;
public:
virtual ObjCMethodPrototypeAST *asObjCMethodPrototype()
{ return this; }
......
......@@ -1207,7 +1207,8 @@ IdentifierListAST *IdentifierListAST::clone(MemoryPool *pool) const
{
IdentifierListAST *ast = new (pool) IdentifierListAST;
// copy IdentifierListAST
ast->identifier_token = identifier_token;
if (ast->name) ast->name = name->clone(pool);
ast->comma_token = comma_token;
if (next) ast->next = next->clone(pool);
return ast;
}
......@@ -1224,14 +1225,14 @@ ObjCClassDeclarationAST *ObjCClassDeclarationAST::clone(MemoryPool *pool) const
return ast;