summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/cplusplus')
-rw-r--r--src/shared/cplusplus/AST.cpp310
-rw-r--r--src/shared/cplusplus/AST.h321
-rw-r--r--src/shared/cplusplus/ASTClone.cpp159
-rw-r--r--src/shared/cplusplus/ASTVisit.cpp186
-rw-r--r--src/shared/cplusplus/ASTVisitor.h30
-rw-r--r--src/shared/cplusplus/ASTfwd.h15
-rw-r--r--src/shared/cplusplus/Parser.cpp315
-rw-r--r--src/shared/cplusplus/Parser.h16
8 files changed, 1228 insertions, 124 deletions
diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 946ecf5cb5..e8ecfa07cd 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -1981,6 +1981,8 @@ unsigned ObjCClassInterfaceDeclarationAST::firstToken() const
unsigned ObjCClassInterfaceDeclarationAST::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;
@@ -2003,6 +2005,9 @@ unsigned ObjCCategoryInterfaceDeclarationAST::lastToken() const
if (end_token)
return end_token + 1;
+ if (member_declarations)
+ return member_declarations->lastToken();
+
if (rparen_token) return rparen_token + 1;
if (category_identifier_token) return category_identifier_token + 1;
if (lparen_token) return lparen_token + 1;
@@ -2022,6 +2027,12 @@ unsigned ObjCProtocolDefinitionAST::lastToken() const
if (end_token)
return end_token + 1;
+ if (member_declarations)
+ return member_declarations->lastToken();
+
+ if (protocol_refs)
+ return protocol_refs->lastToken();
+
if (identifier_token)
return identifier_token + 1;
@@ -2155,4 +2166,303 @@ unsigned ObjCEncodeExpressionAST::lastToken() const
return encode_token + 1;
}
+unsigned ObjCInstanceVariablesDeclarationAST::firstToken() const
+{
+ return lbrace_token;
+}
+
+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();
+
+ return lbrace_token + 1;
+}
+
+unsigned ObjCVisibilityDeclarationAST::firstToken() const
+{
+ return visibility_token;
+}
+
+unsigned ObjCVisibilityDeclarationAST::lastToken() const
+{
+ return visibility_token + 1;
+}
+
+unsigned ObjcPropertyAttributeAST::firstToken() const
+{
+ return attribute_identifier_token;
+}
+
+unsigned ObjcPropertyAttributeAST::lastToken() const
+{
+ if (colon_token)
+ return colon_token + 1;
+ if (method_selector_identifier_token)
+ return method_selector_identifier_token + 1;
+ if (equals_token)
+ return equals_token + 1;
+
+ return attribute_identifier_token + 1;
+}
+
+unsigned ObjcPropertyAttributeListAST::firstToken() const
+{
+ if (attr)
+ return attr->firstToken();
+ else if (comma_token)
+ return comma_token;
+ else if (next)
+ return next->lastToken();
+ else
+ // ### Assert?
+ return 0;
+}
+
+unsigned ObjcPropertyAttributeListAST::lastToken() const
+{
+ for (const ObjcPropertyAttributeListAST *it = this; it; it = it->next) {
+ if (! it->next && (comma_token || it->attr)) {
+ if (comma_token)
+ return comma_token + 1;
+ else
+ return it->attr->lastToken();
+ }
+ }
+ // ### assert?
+ return 0;
+}
+
+unsigned ObjCPropertyDeclarationAST::firstToken() const
+{
+ if (attributes)
+ return attributes->firstToken();
+
+ return property_token;
+}
+
+unsigned ObjCPropertyDeclarationAST::lastToken() const
+{
+ if (simple_declaration)
+ return simple_declaration->lastToken();
+ else if (rparen_token)
+ return rparen_token + 1;
+ else if (property_attributes)
+ return property_attributes->lastToken();
+ else if (lparen_token)
+ return lparen_token + 1;
+ else
+ return property_token + 1;
+}
+
+unsigned ObjCMessageArgumentDeclarationAST::firstToken() const
+{
+ return param_selector_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;
+}
+
+unsigned ObjCMessageArgumentDeclarationListAST::firstToken() const
+{
+ if (argument_declaration)
+ return argument_declaration->firstToken();
+ else if (next)
+ return next->firstToken();
+ else
+ // ### Assert?
+ return 0;
+}
+
+unsigned ObjCMessageArgumentDeclarationListAST::lastToken() const
+{
+ for (const ObjCMessageArgumentDeclarationListAST *it = this; it; it = it->next) {
+ if (! it->next && it->argument_declaration) {
+ return it->argument_declaration->lastToken();
+ }
+ }
+ // ### assert?
+ return 0;
+}
+
+unsigned ObjCMethodPrototypeAST::firstToken() const
+{
+ return method_type_token;
+}
+
+unsigned ObjCMethodPrototypeAST::lastToken() const
+{
+ if (attributes)
+ return attributes->lastToken();
+ else if (arguments)
+ return arguments->lastToken();
+ else if (type_name)
+ return type_name->lastToken();
+ else
+ 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
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index 290a84324b..f6ab2626eb 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -2491,6 +2491,8 @@ public:
unsigned colon_token;
unsigned superclass_identifier_token;
ObjCProtocolRefsAST *protocol_refs;
+ ObjCInstanceVariablesDeclarationAST *inst_vars_decl;
+ DeclarationListAST *member_declarations;
unsigned end_token;
public:
@@ -2515,6 +2517,7 @@ public:
unsigned category_identifier_token;
unsigned rparen_token;
ObjCProtocolRefsAST *protocol_refs;
+ DeclarationListAST *member_declarations;
unsigned end_token;
public:
@@ -2558,6 +2561,7 @@ public:
unsigned protocol_token;
unsigned identifier_token;
ObjCProtocolRefsAST *protocol_refs;
+ DeclarationListAST *member_declarations;
unsigned end_token;
public:
@@ -2714,6 +2718,323 @@ 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:
+ virtual ObjCInstanceVariablesDeclarationAST *asObjCInstanceVariablesDeclaration()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjCInstanceVariablesDeclarationAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjCVisibilityDeclarationAST: public DeclarationAST
+{
+public:
+ unsigned visibility_token;
+
+public:
+ virtual ObjCVisibilityDeclarationAST *asObjCVisibilityDeclaration()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjCVisibilityDeclarationAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjcPropertyAttributeAST: public AST
+{
+public:
+ unsigned attribute_identifier_token;
+ unsigned equals_token;
+ unsigned method_selector_identifier_token;
+ unsigned colon_token;
+
+public:
+ virtual ObjcPropertyAttributeAST *asObjcPropertyAttribute()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjcPropertyAttributeAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjcPropertyAttributeListAST: public AST
+{
+public:
+ ObjcPropertyAttributeAST *attr;
+ unsigned comma_token;
+ ObjcPropertyAttributeListAST *next;
+
+public:
+ virtual ObjcPropertyAttributeListAST *asObjcPropertyAttributeList()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjcPropertyAttributeListAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjCPropertyDeclarationAST: public DeclarationAST
+{
+public:
+ SpecifierAST *attributes;
+ unsigned property_token;
+ unsigned lparen_token;
+ ObjcPropertyAttributeListAST *property_attributes;
+ unsigned rparen_token;
+ DeclarationAST *simple_declaration;
+
+public:
+ virtual ObjCPropertyDeclarationAST *asObjCPropertyDeclaration()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjCPropertyDeclarationAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public AST
+{
+public:
+ unsigned param_selector_token;
+ unsigned colon_token;
+ ObjCTypeNameAST* type_name;
+ SpecifierAST *attributes;
+ unsigned param_name_token;
+
+public:
+ virtual ObjCMessageArgumentDeclarationAST *asObjCMessageArgumentDeclaration()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjCMessageArgumentDeclarationAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationListAST: public AST
+{
+public:
+ ObjCMessageArgumentDeclarationAST *argument_declaration;
+ ObjCMessageArgumentDeclarationListAST *next;
+
+public:
+ virtual ObjCMessageArgumentDeclarationListAST *asObjCMessageArgumentDeclarationList()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjCMessageArgumentDeclarationListAST *clone(MemoryPool *pool) const;
+
+protected:
+ virtual void accept0(ASTVisitor *visitor);
+};
+
+class CPLUSPLUS_EXPORT ObjCMethodPrototypeAST: public DeclarationAST
+{
+public:
+ unsigned method_type_token;
+ ObjCTypeNameAST *type_name;
+ ObjCMessageArgumentDeclarationListAST *arguments;
+ SpecifierAST *attributes;
+
+public:
+ virtual ObjCMethodPrototypeAST *asObjCMethodPrototype()
+ { return this; }
+
+ virtual unsigned firstToken() const;
+ virtual unsigned lastToken() const;
+
+ virtual ObjCMethodPrototypeAST *clone(MemoryPool *pool) const;
+
+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
diff --git a/src/shared/cplusplus/ASTClone.cpp b/src/shared/cplusplus/ASTClone.cpp
index abc89510a5..1e160ae274 100644
--- a/src/shared/cplusplus/ASTClone.cpp
+++ b/src/shared/cplusplus/ASTClone.cpp
@@ -1235,6 +1235,8 @@ ObjCClassInterfaceDeclarationAST *ObjCClassInterfaceDeclarationAST::clone(Memory
ast->colon_token = colon_token;
ast->superclass_identifier_token = superclass_identifier_token;
if (protocol_refs) ast->protocol_refs = protocol_refs->clone(pool);
+ if (inst_vars_decl) ast->inst_vars_decl = inst_vars_decl->clone(pool);
+ if (member_declarations) ast->member_declarations = member_declarations->clone(pool);
ast->end_token = end_token;
return ast;
}
@@ -1250,6 +1252,7 @@ ObjCCategoryInterfaceDeclarationAST *ObjCCategoryInterfaceDeclarationAST::clone(
ast->lparen_token = lparen_token;
ast->category_identifier_token = category_identifier_token;
ast->rparen_token = rparen_token;
+ if (member_declarations) ast->member_declarations = member_declarations->clone(pool);
ast->end_token = end_token;
return ast;
}
@@ -1271,6 +1274,7 @@ ObjCProtocolDefinitionAST *ObjCProtocolDefinitionAST::clone(MemoryPool *pool) co
ast->protocol_token = protocol_token;
ast->identifier_token = identifier_token;
if (protocol_refs) ast->protocol_refs = protocol_refs->clone(pool);
+ if (member_declarations) ast->member_declarations = member_declarations->clone(pool);
ast->end_token = end_token;
return ast;
}
@@ -1339,4 +1343,159 @@ ObjCEncodeExpressionAST *ObjCEncodeExpressionAST::clone(MemoryPool *pool) const
return ast;
}
+ObjCInstanceVariablesDeclarationAST *ObjCInstanceVariablesDeclarationAST::clone(MemoryPool *pool) const
+{
+ ObjCInstanceVariablesDeclarationAST *ast = new (pool) ObjCInstanceVariablesDeclarationAST;
+ ast->lbrace_token = lbrace_token;
+ if (instance_variables) ast->instance_variables = instance_variables->clone(pool);
+ if (member_declarations) ast->member_declarations = member_declarations->clone(pool);
+ ast->rbrace_token = rbrace_token;
+ return ast;
+}
+
+ObjCVisibilityDeclarationAST *ObjCVisibilityDeclarationAST::clone(MemoryPool *pool) const
+{
+ ObjCVisibilityDeclarationAST *ast = new (pool) ObjCVisibilityDeclarationAST;
+ ast->visibility_token = visibility_token;
+ return ast;
+}
+
+ObjcPropertyAttributeAST *ObjcPropertyAttributeAST::clone(MemoryPool *pool) const
+{
+ ObjcPropertyAttributeAST *ast = new (pool) ObjcPropertyAttributeAST;
+ ast->attribute_identifier_token = attribute_identifier_token;
+ ast->equals_token = equals_token;
+ ast->method_selector_identifier_token = method_selector_identifier_token;
+ ast->colon_token = colon_token;
+ return ast;
+}
+
+ObjcPropertyAttributeListAST *ObjcPropertyAttributeListAST::clone(MemoryPool *pool) const
+{
+ ObjcPropertyAttributeListAST *ast = new (pool) ObjcPropertyAttributeListAST;
+ if (attr) ast->attr = attr->clone(pool);
+ ast->comma_token = comma_token;
+ if (next) ast->next = next->clone(pool);
+ return ast;
+}
+
+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);
+ ast->rparen_token = rparen_token;
+ if (simple_declaration) ast->simple_declaration = simple_declaration->clone(pool);
+ return ast;
+}
+
+ObjCMessageArgumentDeclarationAST *ObjCMessageArgumentDeclarationAST::clone(MemoryPool *pool) const
+{
+ ObjCMessageArgumentDeclarationAST *ast = new (pool) ObjCMessageArgumentDeclarationAST;
+ ast->param_selector_token = param_selector_token;
+ ast->colon_token = colon_token;
+ if (type_name) ast->type_name = type_name->clone(pool);
+ if (attributes) ast->attributes = attributes->clone(pool);
+ ast->param_name_token = param_name_token;
+ return ast;
+}
+
+ObjCMessageArgumentDeclarationListAST *ObjCMessageArgumentDeclarationListAST::clone(MemoryPool *pool) const
+{
+ ObjCMessageArgumentDeclarationListAST *ast = new (pool) ObjCMessageArgumentDeclarationListAST;
+ if (argument_declaration) ast->argument_declaration = argument_declaration->clone(pool);
+ if (next) ast->next = next->clone(pool);
+ return ast;
+}
+
+ObjCMethodPrototypeAST *ObjCMethodPrototypeAST::clone(MemoryPool *pool) const
+{
+ ObjCMethodPrototypeAST *ast = new (pool) ObjCMethodPrototypeAST;
+ ast->method_type_token = method_type_token;
+ if (type_name) ast->type_name = type_name->clone(pool);
+ if (arguments) ast->arguments = arguments->clone(pool);
+ if (attributes) ast->attributes = attributes->clone(pool);
+ 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
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 02f1218afe..98fe8a84ad 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -1146,6 +1146,10 @@ void ObjCClassInterfaceDeclarationAST::accept0(ASTVisitor *visitor)
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
accept(protocol_refs, visitor);
+ if (inst_vars_decl)
+ accept(inst_vars_decl, visitor);
+ if (member_declarations)
+ accept(member_declarations, visitor);
// visit DeclarationAST
}
visitor->endVisit(this);
@@ -1180,7 +1184,10 @@ void ObjCProtocolDefinitionAST::accept0(ASTVisitor *visitor)
// visit ObjCProtocolDefinitionAST
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
- accept(protocol_refs, visitor);
+ if (protocol_refs)
+ accept(protocol_refs, visitor);
+ if (member_declarations)
+ accept(member_declarations, visitor);
// visit DeclarationAST
}
visitor->endVisit(this);
@@ -1265,4 +1272,181 @@ void ObjCEncodeExpressionAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
+void ObjCInstanceVariablesDeclarationAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjCInstanceVariablesDeclarationAST
+ if (instance_variables)
+ accept(instance_variables, visitor);
+ if (member_declarations)
+ accept(member_declarations, visitor);
+ // visit AST
+ }
+ visitor->endVisit(this);
+}
+
+void ObjCVisibilityDeclarationAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjCVisibilityDeclarationAST
+ // visit DeclarationAST
+ }
+ visitor->endVisit(this);
+}
+
+void ObjcPropertyAttributeAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjcPropertyAttributeAST
+ // visit AST
+ }
+ visitor->endVisit(this);
+}
+
+void ObjcPropertyAttributeListAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjcPropertyAttributeListAST
+ if (attr)
+ accept(attr, visitor);
+ // visit AST
+ }
+ visitor->endVisit(this);
+}
+
+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)
+ accept(simple_declaration, visitor);
+ // visit DeclarationAST:
+ }
+ visitor->endVisit(this);
+}
+
+void ObjCMessageArgumentDeclarationAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjCMessageArgumentDeclarationAST
+ if (type_name)
+ accept(type_name, visitor);
+ if (attributes)
+ accept(attributes, visitor);
+ // visit AST
+ }
+ visitor->endVisit(this);
+}
+
+void ObjCMessageArgumentDeclarationListAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjCMessageArgumentDeclarationListAST
+ if (argument_declaration)
+ accept(argument_declaration, visitor);
+ // visit AST
+ }
+ visitor->endVisit(this);
+}
+
+void ObjCMethodPrototypeAST::accept0(ASTVisitor *visitor)
+{
+ if (visitor->visit(this)) {
+ // visit ObjCMethodPrototypeAST
+ if (type_name)
+ accept(type_name, visitor);
+ for (ObjCMessageArgumentDeclarationListAST *it = arguments; it; it = it->next)
+ accept(it, visitor);
+ if (attributes)
+ accept(attributes, visitor);
+ // visit AST
+ }
+ 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
diff --git a/src/shared/cplusplus/ASTVisitor.h b/src/shared/cplusplus/ASTVisitor.h
index 130c666262..5279d290f5 100644
--- a/src/shared/cplusplus/ASTVisitor.h
+++ b/src/shared/cplusplus/ASTVisitor.h
@@ -209,6 +209,21 @@ public:
virtual bool visit(ObjCProtocolExpressionAST *) { return true; }
virtual bool visit(ObjCTypeNameAST *) { return true; }
virtual bool visit(ObjCEncodeExpressionAST *) { return true; }
+ virtual bool visit(ObjCInstanceVariablesDeclarationAST *) { return true; }
+ virtual bool visit(ObjCVisibilityDeclarationAST *) { return true; }
+ virtual bool visit(ObjcPropertyAttributeAST *) { return true; }
+ virtual bool visit(ObjcPropertyAttributeListAST *) { return true; }
+ virtual bool visit(ObjCPropertyDeclarationAST *) { return true; }
+ 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 *) { }
@@ -329,6 +344,21 @@ public:
virtual void endVisit(ObjCProtocolExpressionAST *) { }
virtual void endVisit(ObjCTypeNameAST *) { }
virtual void endVisit(ObjCEncodeExpressionAST *) { }
+ virtual void endVisit(ObjCInstanceVariablesDeclarationAST *) { }
+ virtual void endVisit(ObjCVisibilityDeclarationAST *) { }
+ virtual void endVisit(ObjcPropertyAttributeAST *) { }
+ virtual void endVisit(ObjcPropertyAttributeListAST *) { }
+ virtual void endVisit(ObjCPropertyDeclarationAST *) { }
+ 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;
diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h
index f25e293282..5416856614 100644
--- a/src/shared/cplusplus/ASTfwd.h
+++ b/src/shared/cplusplus/ASTfwd.h
@@ -182,6 +182,21 @@ class ObjCMessageArgumentAST;
class ObjCProtocolExpressionAST;
class ObjCTypeNameAST;
class ObjCEncodeExpressionAST;
+class ObjCInstanceVariablesDeclarationAST;
+class ObjCVisibilityDeclarationAST;
+class ObjCPropertyDeclarationAST;
+class ObjcPropertyAttributeListAST;
+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
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index 571ceaa074..2856e07622 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -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();
- match(T_LPAREN, &ast->lparen_token);
- parseForInitStatement(ast->initializer);
+
+ ast->for_token = for_token;
+ ast->lparen_token = lparen_token;
+ ast->initializer = initializer;
parseExpression(ast->condition);
match(T_SEMICOLON, &ast->semicolon_token);
parseExpression(ast->expression);
match(T_RPAREN, &ast->rparen_token);
parseStatement(ast->statement);
+
node = ast;
- return true;
}
- return false;
+
+ return true;
}
bool Parser::parseForInitStatement(StatementAST *&node)
@@ -3951,7 +3978,7 @@ bool Parser::parseObjCInterface(DeclarationAST *&node,
"invalid attributes for category interface declaration");
ObjCCategoryInterfaceDeclarationAST *ast = new (_pool) ObjCCategoryInterfaceDeclarationAST;
- // XXX: Should the attributes get stored anyway? (for fixing/refactoring purposes maybe...)
+ // TODO: Should the attributes get stored anyway? (for fixing/refactoring purposes maybe...)
ast->interface_token = objc_interface_token;
ast->class_identifier_token = identifier_token;
@@ -3962,8 +3989,15 @@ bool Parser::parseObjCInterface(DeclarationAST *&node,
match(T_RPAREN, &(ast->rparen_token));
parseObjCProtocolRefs(ast->protocol_refs);
- while (parseObjCInterfaceMemberDeclaration()) {
+
+ DeclarationListAST **nextMembers = &(ast->member_declarations);
+ DeclarationAST *declaration = 0;
+ while (parseObjCInterfaceMemberDeclaration(declaration)) {
+ *nextMembers = new (_pool) DeclarationListAST;
+ (*nextMembers)->declaration = declaration;
+ nextMembers = &((*nextMembers)->next);
}
+
match(T_AT_END, &(ast->end_token));
node = ast;
@@ -3981,10 +4015,18 @@ bool Parser::parseObjCInterface(DeclarationAST *&node,
}
parseObjCProtocolRefs(ast->protocol_refs);
- parseObjClassInstanceVariables();
- while (parseObjCInterfaceMemberDeclaration()) {
+ parseObjClassInstanceVariables(ast->inst_vars_decl);
+
+ DeclarationListAST **nextMembers = &(ast->member_declarations);
+ DeclarationAST *declaration = 0;
+ while (parseObjCInterfaceMemberDeclaration(declaration)) {
+ *nextMembers = new (_pool) DeclarationListAST;
+ (*nextMembers)->declaration = declaration;
+ nextMembers = &((*nextMembers)->next);
}
+
match(T_AT_END, &(ast->end_token));
+
node = ast;
return true;
}
@@ -4040,7 +4082,12 @@ bool Parser::parseObjCProtocol(DeclarationAST *&node,
parseObjCProtocolRefs(ast->protocol_refs);
- while (parseObjCInterfaceMemberDeclaration()) {
+ DeclarationListAST **nextMembers = &(ast->member_declarations);
+ DeclarationAST *declaration = 0;
+ while (parseObjCInterfaceMemberDeclaration(declaration)) {
+ *nextMembers = new (_pool) DeclarationListAST;
+ (*nextMembers)->declaration = declaration;
+ nextMembers = &((*nextMembers)->next);
}
match(T_AT_END, &(ast->end_token));
@@ -4054,47 +4101,62 @@ bool Parser::parseObjCProtocol(DeclarationAST *&node,
// objc-class-instance-variables-opt
// objc-implementation ::= T_AT_IMPLEMENTAION T_IDENTIFIER T_LPAREN T_IDENTIFIER T_RPAREN
//
-bool Parser::parseObjCImplementation(DeclarationAST *&)
+bool Parser::parseObjCImplementation(DeclarationAST *&node)
{
if (LA() != T_AT_IMPLEMENTATION)
return false;
- consumeToken();
-
+ unsigned implementation_token = consumeToken();
unsigned identifier_token = 0;
match(T_IDENTIFIER, &identifier_token);
if (LA() == T_LPAREN) {
// a category implementation
- unsigned lparen_token = 0, rparen_token = 0;
- unsigned category_name_token = 0;
- match(T_LPAREN, &lparen_token);
- match(T_IDENTIFIER, &category_name_token);
- match(T_RPAREN, &rparen_token);
- return true;
- }
+ ObjCCategoryImplementationAST *ast = new (_pool) ObjCCategoryImplementationAST;
+ ast->implementation_token = implementation_token;
+ ast->class_identifier = identifier_token;
- // a class implementation
- if (LA() == T_COLON) {
- consumeToken();
- unsigned super_class_name_token = 0;
- match(T_IDENTIFIER, &super_class_name_token);
+ match(T_LPAREN, &(ast->lparen_token));
+ match(T_IDENTIFIER, &(ast->category_name_token));
+ match(T_RPAREN, &(ast->rparen_token));
+
+ parseObjCMethodDefinitionList(ast->declarations);
+ match(T_AT_END, &(ast->end_token));
+
+ node = ast;
+ } else {
+ // a class implementation
+ ObjCClassImplementationAST *ast = new (_pool) ObjCClassImplementationAST;
+ ast->implementation_token = implementation_token;
+ ast->class_identifier = identifier_token;
+
+ if (LA() == T_COLON) {
+ ast->colon_token = consumeToken();
+ match(T_IDENTIFIER, &(ast->super_class_identifier));
+ }
+
+ parseObjClassInstanceVariables(ast->inst_vars_decl);
+ parseObjCMethodDefinitionList(ast->declarations);
+ match(T_AT_END, &(ast->end_token));
+
+ node = ast;
}
- parseObjClassInstanceVariables();
- parseObjCMethodDefinitionList();
return true;
}
-bool Parser::parseObjCMethodDefinitionList()
+bool Parser::parseObjCMethodDefinitionList(DeclarationListAST *&node)
{
+ DeclarationListAST **next = &node;
+
while (LA() && LA() != T_AT_END) {
unsigned start = cursor();
+ DeclarationAST *declaration = 0;
switch (LA()) {
case T_PLUS:
case T_MINUS:
- parseObjCMethodDefinition();
+ parseObjCMethodDefinition(declaration);
if (start == cursor())
consumeToken();
@@ -4105,7 +4167,9 @@ bool Parser::parseObjCMethodDefinitionList()
break;
case T_AT_SYNTHESIZE: {
- consumeToken();
+ ObjCSynthesizedPropertiesDeclarationAST *ast = new (_pool) ObjCSynthesizedPropertiesDeclarationAST;
+ ast->synthesized_token = consumeToken();
+ // TODO EV
unsigned identifier_token = 0;
match(T_IDENTIFIER, &identifier_token);
@@ -4129,34 +4193,36 @@ bool Parser::parseObjCMethodDefinitionList()
}
}
- unsigned semicolon_token = 0;
- match(T_SEMICOLON, &semicolon_token);
+ match(T_SEMICOLON, &(ast->semicolon_token));
+ declaration = ast;
break;
}
case T_AT_DYNAMIC: {
- consumeToken();
- unsigned identifier_token = 0;
- match(T_IDENTIFIER, &identifier_token);
+ ObjCDynamicPropertiesDeclarationAST *ast = new (_pool) ObjCDynamicPropertiesDeclarationAST;
+ ast->dynamic_token = consumeToken();
+ ast->property_identifiers = new (_pool) IdentifierListAST;
+ match(T_IDENTIFIER, &(ast->property_identifiers->identifier_token));
+ IdentifierListAST *last = ast->property_identifiers;
while (LA() == T_COMMA) {
- consumeToken();
- match(T_IDENTIFIER, &identifier_token);
+ last->comma_token = consumeToken();
+ last->next = new (_pool) IdentifierListAST;
+ last = last->next;
+ match(T_IDENTIFIER, &(last->identifier_token));
}
- unsigned semicolon_token = 0;
- match(T_SEMICOLON, &semicolon_token);
+ match(T_SEMICOLON, &(ast->semicolon_token));
+ declaration = ast;
break;
}
default:
if (LA() == T_EXTERN && LA(2) == T_STRING_LITERAL) {
- DeclarationAST *declaration = 0;
parseDeclaration(declaration);
} else {
- DeclarationAST *declaration = 0;
if (! parseBlockDeclaration(declaration)) {
rewind(start);
_translationUnit->error(cursor(),
@@ -4167,14 +4233,22 @@ bool Parser::parseObjCMethodDefinitionList()
}
break;
} // switch
+
+ if (declaration) {
+ *next = new (_pool) DeclarationListAST;
+ (*next)->declaration = declaration;
+ next = &((*next)->next);
+ }
}
return true;
}
-bool Parser::parseObjCMethodDefinition()
+bool Parser::parseObjCMethodDefinition(DeclarationAST *&node)
{
- if (! parseObjCMethodPrototype())
+ // TODO EV:
+ DeclarationAST *ast = 0;
+ if (! parseObjCMethodPrototype(ast))
return false;
if (LA() == T_SEMICOLON)
@@ -4221,22 +4295,22 @@ bool Parser::parseObjCProtocolRefs(ObjCProtocolRefsAST *&node)
// objc-instance-variable-decl-list-opt
// T_RBRACE
//
-bool Parser::parseObjClassInstanceVariables()
+bool Parser::parseObjClassInstanceVariables(ObjCInstanceVariablesDeclarationAST *&node)
{
if (LA() != T_LBRACE)
return false;
- unsigned lbrace_token = 0, rbrace_token = 0;
+ ObjCInstanceVariablesDeclarationAST *ast = new (_pool) ObjCInstanceVariablesDeclarationAST;
+ match(T_LBRACE, &(ast->lbrace_token));
- match(T_LBRACE, &lbrace_token);
- while (LA()) {
+ for (DeclarationListAST **next = &(ast->instance_variables); LA(); next = &((*next)->next)) {
if (LA() == T_RBRACE)
break;
const unsigned start = cursor();
- DeclarationAST *declaration = 0;
- parseObjCInstanceVariableDeclaration(declaration);
+ *next = new (_pool) DeclarationListAST;
+ parseObjCInstanceVariableDeclaration((*next)->declaration);
if (start == cursor()) {
// skip stray token.
@@ -4245,7 +4319,9 @@ bool Parser::parseObjClassInstanceVariables()
}
}
- match(T_RBRACE, &rbrace_token);
+ match(T_RBRACE, &(ast->rbrace_token));
+
+ node = ast;
return true;
}
@@ -4254,7 +4330,7 @@ bool Parser::parseObjClassInstanceVariables()
// objc-interface-declaration ::= T_SEMICOLON
// objc-interface-declaration ::= objc-property-declaration
// objc-interface-declaration ::= objc-method-prototype
-bool Parser::parseObjCInterfaceMemberDeclaration()
+bool Parser::parseObjCInterfaceMemberDeclaration(DeclarationAST *&node)
{
switch (LA()) {
case T_AT_END:
@@ -4270,25 +4346,22 @@ bool Parser::parseObjCInterfaceMemberDeclaration()
return true;
case T_AT_PROPERTY: {
- DeclarationAST *declaration = 0;
- return parseObjCPropertyDeclaration(declaration);
+ return parseObjCPropertyDeclaration(node);
}
case T_PLUS:
case T_MINUS:
- return parseObjCMethodPrototype();
+ return parseObjCMethodPrototype(node);
case T_ENUM:
case T_CLASS:
case T_STRUCT:
case T_UNION: {
- DeclarationAST *declaration = 0;
- return parseSimpleDeclaration(declaration, /*accept struct declarators */ true);
+ return parseSimpleDeclaration(node, /*accept struct declarators */ true);
}
default: {
- DeclarationAST *declaration = 0;
- return parseSimpleDeclaration(declaration, /*accept struct declarators */ true);
+ return parseSimpleDeclaration(node, /*accept struct declarators */ true);
} // default
} // switch
@@ -4300,42 +4373,56 @@ bool Parser::parseObjCInterfaceMemberDeclaration()
bool Parser::parseObjCInstanceVariableDeclaration(DeclarationAST *&node)
{
switch (LA()) {
- case T_AT_PRIVATE:
- case T_AT_PROTECTED:
- case T_AT_PUBLIC:
- case T_AT_PACKAGE:
- consumeToken();
- return true;
+ case T_AT_PRIVATE:
+ case T_AT_PROTECTED:
+ case T_AT_PUBLIC:
+ case T_AT_PACKAGE: {
+ ObjCVisibilityDeclarationAST *ast = new (_pool) ObjCVisibilityDeclarationAST;
+ ast->visibility_token = consumeToken();
+ node = ast;
+ return true;
+ }
- default:
- return parseSimpleDeclaration(node, true);
+ default:
+ return parseSimpleDeclaration(node, true);
}
}
// objc-property-declaration ::=
// T_AT_PROPERTY T_LPAREN (property-attribute @ T_COMMA) T_RPAREN simple-declaration
//
-bool Parser::parseObjCPropertyDeclaration(DeclarationAST *&, SpecifierAST *)
+bool Parser::parseObjCPropertyDeclaration(DeclarationAST *&node, SpecifierAST *attributes)
{
if (LA() != T_AT_PROPERTY)
return false;
- /*unsigned objc_property_token = */ consumeToken();
+ ObjCPropertyDeclarationAST *ast = new (_pool) ObjCPropertyDeclarationAST;
+ ast->attributes = attributes;
+ ast->property_token = consumeToken();
if (LA() == T_LPAREN) {
- unsigned lparen_token = 0, rparen_token = 0;
- match(T_LPAREN, &lparen_token);
- if (parseObjCPropertyAttribute()) {
+ match(T_LPAREN, &(ast->lparen_token));
+
+ ObjcPropertyAttributeAST *property_attribute = 0;
+ if (parseObjCPropertyAttribute(property_attribute)) {
+ ast->property_attributes = new (_pool) ObjcPropertyAttributeListAST;
+ ast->property_attributes->attr = property_attribute;
+ ObjcPropertyAttributeListAST *last = ast->property_attributes;
+
while (LA() == T_COMMA) {
- consumeToken();
- parseObjCPropertyAttribute();
+ last->comma_token = consumeToken();
+ last->next = new (_pool) ObjcPropertyAttributeListAST;
+ last = last->next;
+ parseObjCPropertyAttribute(last->attr);
}
}
- match(T_RPAREN, &rparen_token);
+
+ match(T_RPAREN, &(ast->rparen_token));
}
- DeclarationAST *simple_declaration = 0;
- parseSimpleDeclaration(simple_declaration, /*accept-struct-declarators = */ true);
+ parseSimpleDeclaration(ast->simple_declaration, /*accept-struct-declarators = */ true);
+
+ node = ast;
return true;
}
@@ -4344,22 +4431,31 @@ bool Parser::parseObjCPropertyDeclaration(DeclarationAST *&, SpecifierAST *)
// objc-method-decl ::= objc-type-name? objc-selector
// objc-method-decl ::= objc-type-name? objc-keyword-decl-list objc-parmlist-opt
//
-bool Parser::parseObjCMethodPrototype()
+bool Parser::parseObjCMethodPrototype(DeclarationAST *&node)
{
if (LA() != T_PLUS && LA() != T_MINUS)
return false;
- /*unsigned method_type_token = */ consumeToken();
-
- ObjCTypeNameAST *type_name = 0;
- parseObjCTypeName(type_name);
+ ObjCMethodPrototypeAST *ast = new (_pool) ObjCMethodPrototypeAST;
+ ast->method_type_token = consumeToken();
- unsigned selector_token = 0;
+ parseObjCTypeName(ast->type_name);
if ((lookAtObjCSelector() && LA(2) == T_COLON) || LA() == T_COLON) {
- while (parseObjCKeywordDeclaration()) {
+ ObjCMessageArgumentDeclarationAST *declaration = 0;
+ parseObjCKeywordDeclaration(declaration);
+
+ ast->arguments = new (_pool) ObjCMessageArgumentDeclarationListAST;
+ ast->arguments->argument_declaration = declaration;
+ ObjCMessageArgumentDeclarationListAST **last = &(ast->arguments);
+
+ while (parseObjCKeywordDeclaration(declaration)) {
+ (*last)->next = new (_pool) ObjCMessageArgumentDeclarationListAST;
+ last = &((*last)->next);
+ (*last)->argument_declaration = declaration;
}
+ // TODO: err, what does this parse?
while (LA() == T_COMMA) {
consumeToken();
@@ -4372,15 +4468,18 @@ bool Parser::parseObjCMethodPrototype()
parseParameterDeclaration(parameter_declaration);
}
} else if (lookAtObjCSelector()) {
- parseObjCSelector(selector_token);
+ ast->arguments = new (_pool) ObjCMessageArgumentDeclarationListAST;
+ ast->arguments->argument_declaration = new (_pool) ObjCMessageArgumentDeclarationAST;
+ parseObjCSelector(ast->arguments->argument_declaration->param_selector_token);
} else {
_translationUnit->error(cursor(), "expected a selector");
}
- SpecifierAST *attributes = 0, **attr = &attributes;
+ SpecifierAST **attr = &(ast->attributes);
while (parseAttributeSpecifier(*attr))
attr = &(*attr)->next;
+ node = ast;
return true;
}
@@ -4392,18 +4491,18 @@ bool Parser::parseObjCMethodPrototype()
// objc-property-attribute ::= retain
// objc-property-attribute ::= copy
// objc-property-attribute ::= nonatomic
-bool Parser::parseObjCPropertyAttribute()
+bool Parser::parseObjCPropertyAttribute(ObjcPropertyAttributeAST *&node)
{
if (LA() != T_IDENTIFIER)
return false;
- unsigned identifier_token = 0;
- match(T_IDENTIFIER, &identifier_token);
+ node = new (_pool) ObjcPropertyAttributeAST;
+ match(T_IDENTIFIER, &(node->attribute_identifier_token));
if (LA() == T_EQUAL) {
- consumeToken();
- match(T_IDENTIFIER, &identifier_token);
+ node->equals_token = consumeToken();
+ match(T_IDENTIFIER, &(node->method_selector_identifier_token));
if (LA() == T_COLON)
- consumeToken();
+ node->colon_token = consumeToken();
}
return true;
@@ -4438,27 +4537,24 @@ bool Parser::parseObjCSelector(unsigned &selector_token)
// objc-keyword-decl ::= objc-selector? T_COLON objc-type-name? objc-keyword-attributes-opt T_IDENTIFIER
//
-bool Parser::parseObjCKeywordDeclaration()
+bool Parser::parseObjCKeywordDeclaration(ObjCMessageArgumentDeclarationAST *&node)
{
if (! (LA() == T_COLON || (lookAtObjCSelector() && LA(2) == T_COLON)))
return false;
- unsigned selector_token = 0;
- parseObjCSelector(selector_token);
+ ObjCMessageArgumentDeclarationAST *ast = new (_pool) ObjCMessageArgumentDeclarationAST;
- unsigned colon_token = 0;
- match(T_COLON, &colon_token);
-
- ObjCTypeNameAST *type_name = 0;
- parseObjCTypeName(type_name);
+ parseObjCSelector(ast->param_selector_token);
+ match(T_COLON, &(ast->colon_token));
+ parseObjCTypeName(ast->type_name);
- SpecifierAST *attributes = 0, **attr = &attributes;
+ SpecifierAST **attr = &(ast->attributes);
while (parseAttributeSpecifier(*attr))
attr = &(*attr)->next;
- unsigned identifier_token = 0;
- match(T_IDENTIFIER, &identifier_token);
+ match(T_IDENTIFIER, &(ast->param_name_token));
+ node = ast;
return true;
}
@@ -4475,15 +4571,4 @@ bool Parser::parseObjCTypeQualifiers(unsigned &type_qualifier)
return true;
}
-// objc-end: T_AT_END
-bool Parser::parseObjCEnd(DeclarationAST *&)
-{
- if (LA() != T_AT_END)
- return false;
-
- consumeToken();
- return true;
-}
-
-
CPLUSPLUS_END_NAMESPACE
diff --git a/src/shared/cplusplus/Parser.h b/src/shared/cplusplus/Parser.h
index 2de07f1bea..df017209e1 100644
--- a/src/shared/cplusplus/Parser.h
+++ b/src/shared/cplusplus/Parser.h
@@ -228,23 +228,22 @@ public:
bool parseObjCMessageReceiver(ExpressionAST *&node);
bool parseObjCMessageArguments(ObjCMessageArgumentListAST *&node);
bool parseObjCSelectorArg(ObjCMessageArgumentAST *&node);
- bool parseObjCMethodDefinitionList();
- bool parseObjCMethodDefinition();
+ bool parseObjCMethodDefinitionList(DeclarationListAST *&node);
+ bool parseObjCMethodDefinition(DeclarationAST *&node);
bool parseObjCProtocolRefs(ObjCProtocolRefsAST *&node);
- bool parseObjClassInstanceVariables();
- bool parseObjCInterfaceMemberDeclaration();
+ bool parseObjClassInstanceVariables(ObjCInstanceVariablesDeclarationAST *&node);
+ bool parseObjCInterfaceMemberDeclaration(DeclarationAST *&node);
bool parseObjCInstanceVariableDeclaration(DeclarationAST *&node);
bool parseObjCPropertyDeclaration(DeclarationAST *&node,
SpecifierAST *attributes = 0);
bool parseObjCImplementation(DeclarationAST *&node);
- bool parseObjCMethodPrototype();
- bool parseObjCPropertyAttribute();
+ bool parseObjCMethodPrototype(DeclarationAST *&node);
+ bool parseObjCPropertyAttribute(ObjcPropertyAttributeAST *&node);
bool parseObjCTypeName(ObjCTypeNameAST *&node);
bool parseObjCSelector(unsigned &selector_token);
- bool parseObjCKeywordDeclaration();
+ bool parseObjCKeywordDeclaration(ObjCMessageArgumentDeclarationAST *&node);
bool parseObjCTypeQualifiers(unsigned &type_qualifier);
- bool parseObjCEnd(DeclarationAST *&node);
bool lookAtObjCSelector() const;
@@ -288,6 +287,7 @@ private:
TranslationUnit *_translationUnit;
Control *_control;
MemoryPool *_pool;
+ Identifier *_objcInContextKeyword;
unsigned _tokenIndex;
bool _templateArguments: 1;
bool _qtMocRunEnabled: 1;