Commit 34987cc1 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added more AST for ObjC.

parent a3d12952
......@@ -2241,6 +2241,9 @@ unsigned ObjcPropertyAttributeListAST::lastToken() const
unsigned ObjCPropertyDeclarationAST::firstToken() const
{
if (attributes)
return attributes->firstToken();
return property_token;
}
......@@ -2316,4 +2319,150 @@ unsigned ObjCMethodPrototypeAST::lastToken() const
return method_type_token + 1;
}
unsigned ObjCClassImplementationAST::firstToken() const
{
return implementation_token;
}
unsigned ObjCClassImplementationAST::lastToken() const
{
if (end_token)
return end_token + 1;
for (DeclarationListAST *it = declarations; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
if (inst_vars_decl)
return inst_vars_decl->lastToken();
if (super_class_identifier)
return super_class_identifier + 1;
if (colon_token)
return colon_token + 1;
if (class_identifier)
return class_identifier + 1;
return implementation_token + 1;
}
unsigned ObjCCategoryImplementationAST::firstToken() const
{
return implementation_token;
}
unsigned ObjCCategoryImplementationAST::lastToken() const
{
if (end_token)
return end_token + 1;
for (DeclarationListAST *it = declarations; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
if (rparen_token)
return rparen_token + 1;
if (category_name_token)
return category_name_token + 1;
if (lparen_token)
return lparen_token + 1;
if (class_identifier)
return class_identifier + 1;
return implementation_token + 1;
}
unsigned ObjCSynthesizedPropertyAST::firstToken() const
{
if (property_identifier)
return property_identifier;
else if (equals_token)
return equals_token;
else
return property_alias_identifier;
}
unsigned ObjCSynthesizedPropertyAST::lastToken() const
{
if (property_alias_identifier)
return property_alias_identifier + 1;
else if (equals_token)
return equals_token + 1;
else
return property_identifier + 1;
}
unsigned ObjCSynthesizedPropertyListAST::firstToken() const
{
if (synthesized_property)
return synthesized_property->firstToken();
else
return comma_token;
}
unsigned ObjCSynthesizedPropertyListAST::lastToken() const
{
for (const ObjCSynthesizedPropertyListAST *it = this; it; it = it->next) {
if (! it->next && it->synthesized_property) {
return it->synthesized_property->lastToken();
}
}
// ### assert?
return 0;
}
unsigned ObjCSynthesizedPropertiesDeclarationAST::firstToken() const
{
return synthesized_token;
}
unsigned ObjCSynthesizedPropertiesDeclarationAST::lastToken() const
{
if (semicolon_token)
return semicolon_token + 1;
else if (property_identifiers)
return property_identifiers->lastToken();
else
return synthesized_token + 1;
}
unsigned ObjCDynamicPropertiesDeclarationAST::firstToken() const
{
return dynamic_token;
}
unsigned ObjCDynamicPropertiesDeclarationAST::lastToken() const
{
if (semicolon_token)
return semicolon_token + 1;
else if (property_identifiers)
return property_identifiers->lastToken();
else
return dynamic_token + 1;
}
unsigned ObjCFastEnumerationAST::firstToken() const
{
return for_token;
}
unsigned ObjCFastEnumerationAST::lastToken() const
{
if (body_statement)
return body_statement->lastToken();
else if (rparen_token)
return rparen_token + 1;
else if (fast_enumeratable_expression)
return fast_enumeratable_expression->lastToken();
else if (in_token)
return in_token + 1;
else if (initializer)
return initializer->lastToken();
else if (lparen_token)
return lparen_token + 1;
else
return for_token + 1;
}
CPLUSPLUS_END_NAMESPACE
......@@ -2801,6 +2801,7 @@ protected:
class CPLUSPLUS_EXPORT ObjCPropertyDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
unsigned property_token;
unsigned lparen_token;
ObjcPropertyAttributeListAST *property_attributes;
......@@ -2882,6 +2883,158 @@ protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCClassImplementationAST: public DeclarationAST
{
public:
unsigned implementation_token;
unsigned class_identifier;
unsigned colon_token;
unsigned super_class_identifier;
ObjCInstanceVariablesDeclarationAST *inst_vars_decl;
DeclarationListAST *declarations;
unsigned end_token;
public:
virtual ObjCClassImplementationAST *asObjCClassImplementation()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCClassImplementationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCCategoryImplementationAST: public DeclarationAST
{
public:
unsigned implementation_token;
unsigned class_identifier;
unsigned lparen_token;
unsigned category_name_token;
unsigned rparen_token;
DeclarationListAST *declarations;
unsigned end_token;
public:
virtual ObjCCategoryImplementationAST *asObjCCategoryImplementation()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCCategoryImplementationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCSynthesizedPropertyAST: public AST
{
public:
unsigned property_identifier;
unsigned equals_token;
unsigned property_alias_identifier;
public:
virtual ObjCSynthesizedPropertyAST *asObjCSynthesizedProperty()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSynthesizedPropertyAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCSynthesizedPropertyListAST: public AST
{
public:
ObjCSynthesizedPropertyAST *synthesized_property;
unsigned comma_token;
ObjCSynthesizedPropertyListAST *next;
public:
virtual ObjCSynthesizedPropertyListAST *asObjCSynthesizedPropertyList()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSynthesizedPropertyListAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCSynthesizedPropertiesDeclarationAST: public DeclarationAST
{
public:
unsigned synthesized_token;
ObjCSynthesizedPropertyListAST *property_identifiers;
unsigned semicolon_token;
public:
virtual ObjCSynthesizedPropertiesDeclarationAST *asObjCSynthesizedPropertiesDeclaration()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCSynthesizedPropertiesDeclarationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCDynamicPropertiesDeclarationAST: public DeclarationAST
{
public:
unsigned dynamic_token;
IdentifierListAST *property_identifiers;
unsigned semicolon_token;
public:
virtual ObjCDynamicPropertiesDeclarationAST *asObjCDynamicPropertiesDeclaration()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCDynamicPropertiesDeclarationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCFastEnumerationAST: public StatementAST
{
public:
unsigned for_token;
unsigned lparen_token;
StatementAST *initializer;
unsigned in_token;
ExpressionAST *fast_enumeratable_expression;
unsigned rparen_token;
StatementAST *body_statement;
public:
virtual ObjCFastEnumerationAST *asObjCFastEnumeration()
{ return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ObjCFastEnumerationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
......
......@@ -1382,6 +1382,7 @@ ObjcPropertyAttributeListAST *ObjcPropertyAttributeListAST::clone(MemoryPool *po
ObjCPropertyDeclarationAST *ObjCPropertyDeclarationAST::clone(MemoryPool *pool) const
{
ObjCPropertyDeclarationAST *ast = new (pool) ObjCPropertyDeclarationAST;
if (attributes) ast->attributes = attributes->clone(pool);
ast->property_token = property_token;
ast->lparen_token = lparen_token;
if (property_attributes) ast->property_attributes = property_attributes->clone(pool);
......@@ -1419,4 +1420,82 @@ ObjCMethodPrototypeAST *ObjCMethodPrototypeAST::clone(MemoryPool *pool) const
return ast;
}
ObjCClassImplementationAST *ObjCClassImplementationAST::clone(MemoryPool *pool) const
{
ObjCClassImplementationAST *ast = new (pool) ObjCClassImplementationAST;
ast->implementation_token = implementation_token;
ast->class_identifier = class_identifier;
ast->colon_token = colon_token;
ast->super_class_identifier = super_class_identifier;
if (inst_vars_decl) ast->inst_vars_decl = inst_vars_decl->clone(pool);
if (declarations) ast->declarations = declarations->clone(pool);
ast->end_token = end_token;
return ast;
}
ObjCCategoryImplementationAST *ObjCCategoryImplementationAST::clone(MemoryPool *pool) const
{
ObjCCategoryImplementationAST *ast = new (pool) ObjCCategoryImplementationAST;
ast->implementation_token = implementation_token;
ast->class_identifier = class_identifier;
ast->lparen_token = lparen_token;
ast->category_name_token = category_name_token;
ast->rparen_token = rparen_token;
if (declarations) ast->declarations = declarations->clone(pool);
ast->end_token = end_token;
return ast;
}
ObjCSynthesizedPropertyAST *ObjCSynthesizedPropertyAST::clone(MemoryPool *pool) const
{
ObjCSynthesizedPropertyAST *ast = new (pool) ObjCSynthesizedPropertyAST;
ast->property_identifier = property_identifier;
ast->equals_token = equals_token;
ast->property_alias_identifier = property_alias_identifier;
return ast;
}
ObjCSynthesizedPropertyListAST *ObjCSynthesizedPropertyListAST::clone(MemoryPool *pool) const
{
ObjCSynthesizedPropertyListAST *ast = new (pool) ObjCSynthesizedPropertyListAST;
if (synthesized_property) ast->synthesized_property = synthesized_property->clone(pool);
ast->comma_token = comma_token;
if (next) ast->next = next->clone(pool);
return ast;
}
ObjCSynthesizedPropertiesDeclarationAST *ObjCSynthesizedPropertiesDeclarationAST::clone(MemoryPool *pool) const
{
ObjCSynthesizedPropertiesDeclarationAST *ast = new (pool) ObjCSynthesizedPropertiesDeclarationAST;
ast->synthesized_token = synthesized_token;
if (property_identifiers) ast->property_identifiers = property_identifiers->clone(pool);
ast->semicolon_token = semicolon_token;
return ast;
}
ObjCDynamicPropertiesDeclarationAST *ObjCDynamicPropertiesDeclarationAST::clone(MemoryPool *pool) const
{
ObjCDynamicPropertiesDeclarationAST *ast = new (pool) ObjCDynamicPropertiesDeclarationAST;
ast->dynamic_token = dynamic_token;
if (property_identifiers) ast->property_identifiers = property_identifiers->clone(pool);
ast->semicolon_token = semicolon_token;
return ast;
}
ObjCFastEnumerationAST *ObjCFastEnumerationAST::clone(MemoryPool *pool) const
{
ObjCFastEnumerationAST *ast = new (pool) ObjCFastEnumerationAST;
ast->for_token = for_token;
ast->lparen_token = lparen_token;
if (initializer)
ast->initializer = initializer->clone(pool);
ast->in_token = in_token;
if (fast_enumeratable_expression)
ast->fast_enumeratable_expression = fast_enumeratable_expression->clone(pool);
ast->rparen_token = rparen_token;
if (body_statement)
ast->body_statement = body_statement->clone(pool);
return ast;
}
CPLUSPLUS_END_NAMESPACE
......@@ -1318,6 +1318,8 @@ void ObjCPropertyDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCPropertyDeclarationAST:
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
for (ObjcPropertyAttributeListAST *it = property_attributes; it; it = it->next)
accept(it, visitor);
if (simple_declaration)
......@@ -1366,4 +1368,85 @@ void ObjCMethodPrototypeAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void ObjCClassImplementationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCClassImplementationAST
if (inst_vars_decl)
accept(inst_vars_decl, visitor);
for (DeclarationListAST *it = declarations; it; it = it->next)
accept(it, visitor);
// visit DeclarationAST
}
visitor->endVisit(this);
}
void ObjCCategoryImplementationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCCategoryImplementationAST
for (DeclarationListAST *it = declarations; it; it = it->next)
accept(it, visitor);
// visit DeclarationAST
}
visitor->endVisit(this);
}
void ObjCSynthesizedPropertyAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCSynthesizedPropertyAST
// visit AST
}
visitor->endVisit(this);
}
void ObjCSynthesizedPropertyListAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCSynthesizedPropertyListAST
if (synthesized_property)
accept(synthesized_property, visitor);
// visit AST
}
visitor->endVisit(this);
}
void ObjCSynthesizedPropertiesDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCSynthesizedPropertiesDeclarationAST
for (ObjCSynthesizedPropertyListAST *it = property_identifiers; it; it = it->next)
accept(it, visitor);
// visit DeclarationAST
}
visitor->endVisit(this);
}
void ObjCDynamicPropertiesDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCDynamicPropertiesDeclarationAST
for (IdentifierListAST *it = property_identifiers; it; it = it->next)
accept(it, visitor);
// visit DeclarationAST
}
visitor->endVisit(this);
}
void ObjCFastEnumerationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit ObjCFastEnumerationAST
if (initializer)
accept(initializer, visitor);
if (fast_enumeratable_expression)
accept(fast_enumeratable_expression, visitor);
if (body_statement)
accept(body_statement, visitor);
// visit StatementAST
}
visitor->endVisit(this);
}
CPLUSPLUS_END_NAMESPACE
......@@ -217,6 +217,13 @@ public:
virtual bool visit(ObjCMethodPrototypeAST *) { return true; }
virtual bool visit(ObjCMessageArgumentDeclarationListAST *) { return true; }
virtual bool visit(ObjCMessageArgumentDeclarationAST *) { return true; }
virtual bool visit(ObjCClassImplementationAST *) { return true; }
virtual bool visit(ObjCCategoryImplementationAST *) { return true; }
virtual bool visit(ObjCSynthesizedPropertyAST *) { return true; }
virtual bool visit(ObjCSynthesizedPropertyListAST *) { return true; }
virtual bool visit(ObjCSynthesizedPropertiesDeclarationAST *) { return true; }
virtual bool visit(ObjCDynamicPropertiesDeclarationAST *) { return true; }
virtual bool visit(ObjCFastEnumerationAST *) { return true; }
virtual bool visit(DeclarationListAST *) { return true; }
virtual void endVisit(DeclarationListAST *) { }
......@@ -345,6 +352,13 @@ public:
virtual void endVisit(ObjCMethodPrototypeAST *) { }
virtual void endVisit(ObjCMessageArgumentDeclarationListAST *) { }
virtual void endVisit(ObjCMessageArgumentDeclarationAST *) { }
virtual void endVisit(ObjCClassImplementationAST *) { }
virtual void endVisit(ObjCCategoryImplementationAST *) { }
virtual void endVisit(ObjCSynthesizedPropertyAST *) { }
virtual void endVisit(ObjCSynthesizedPropertyListAST *) { }
virtual void endVisit(ObjCSynthesizedPropertiesDeclarationAST *) { }
virtual void endVisit(ObjCDynamicPropertiesDeclarationAST *) { }
virtual void endVisit(ObjCFastEnumerationAST *) { }
private:
Control *_control;
......
......@@ -190,6 +190,13 @@ class ObjcPropertyAttributeAST;
class ObjCMethodPrototypeAST;
class ObjCMessageArgumentDeclarationListAST;
class ObjCMessageArgumentDeclarationAST;
class ObjCCategoryImplementationAST;
class ObjCClassImplementationAST;
class ObjCSynthesizedPropertyAST;
class ObjCSynthesizedPropertyListAST;
class ObjCSynthesizedPropertiesDeclarationAST;
class ObjCDynamicPropertiesDeclarationAST;
class ObjCFastEnumerationAST;
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
......
......@@ -63,6 +63,7 @@ Parser::Parser(TranslationUnit *unit)
: _translationUnit(unit),
_control(_translationUnit->control()),
_pool(_translationUnit->memoryPool()),
_objcInContextKeyword(_control->findOrInsertIdentifier("in")),
_tokenIndex(1),
_templateArguments(0),
_qtMocRunEnabled(false),
......@@ -422,7 +423,10 @@ bool Parser::parseDeclaration(DeclarationAST *&node)
return parseObjCImplementation(node);
case T_AT_END:
return parseObjCEnd(node);
// TODO: should this be done here, or higher-up?
_translationUnit->error(cursor(), "skip stray token `%s'", tok().spell());
consumeToken();
break;
default: {
if (_objCEnabled && LA() == T___ATTRIBUTE__) {
......@@ -2168,20 +2172,43 @@ bool Parser::parseForeachStatement(StatementAST *&node)
bool Parser::parseForStatement(StatementAST *&node)
{
if (LA() == T_FOR) {
if (LA() != T_FOR)
return false;
unsigned for_token = consumeToken();
unsigned lparen_token = 0;
match(T_LPAREN, &lparen_token);
StatementAST *initializer = 0;
parseForInitStatement(initializer);
if (LA() == T_IDENTIFIER && tok().identifier == _objcInContextKeyword) {
ObjCFastEnumerationAST *ast = new (_pool) ObjCFastEnumerationAST;
ast->for_token = for_token;
ast->lparen_token = lparen_token;
ast->initializer = initializer;
ast->in_token = consumeToken();
parseExpression(ast->fast_enumeratable_expression);
match(T_RPAREN, &ast->rparen_token);
parseStatement(ast->body_statement);
node = ast;
} else {
ForStatementAST *ast = new (_pool) ForStatementAST;
ast->for_token = consumeToken();