Implement AST merging for Objective-C properties.

llvm-svn: 96483
This commit is contained in:
Douglas Gregor 2010-02-17 18:02:10 +00:00
parent 231461f88f
commit a11c45866e
5 changed files with 99 additions and 1 deletions

View File

@ -74,5 +74,8 @@ def err_odr_objc_method_variadic_inconsistent : Error<
"and not variadic in another">;
def note_odr_objc_method_here : Note<
"%select{class|instance}0 method %1 also declared here">;
def err_odr_objc_property_type_inconsistent : Error<
"property %0 declared with incompatible types in different "
"translation units (%1 vs. %2)">;
def err_unsupported_ast_node: Error<"cannot import unsupported AST node %0">;
}

View File

@ -96,7 +96,8 @@ namespace {
Decl *VisitObjCMethodDecl(ObjCMethodDecl *D);
Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
// Importing statements
Stmt *VisitStmt(Stmt *S);
@ -2315,6 +2316,66 @@ Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
return ToIface;
}
Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
// Import the major distinguishing characteristics of an @property.
DeclContext *DC, *LexicalDC;
DeclarationName Name;
SourceLocation Loc;
if (ImportDeclParts(D, DC, LexicalDC, Name, Loc))
return 0;
// Check whether we have already imported this property.
for (DeclContext::lookup_result Lookup = DC->lookup(Name);
Lookup.first != Lookup.second;
++Lookup.first) {
if (ObjCPropertyDecl *FoundProp
= dyn_cast<ObjCPropertyDecl>(*Lookup.first)) {
// Check property types.
if (!Importer.IsStructurallyEquivalent(D->getType(),
FoundProp->getType())) {
Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent)
<< Name << D->getType() << FoundProp->getType();
Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
<< FoundProp->getType();
return 0;
}
// FIXME: Check property attributes, getters, setters, etc.?
// Consider these properties to be equivalent.
Importer.Imported(D, FoundProp);
return FoundProp;
}
}
// Import the type.
QualType T = Importer.Import(D->getType());
if (T.isNull())
return 0;
// Create the new property.
ObjCPropertyDecl *ToProperty
= ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc,
Name.getAsIdentifierInfo(),
Importer.Import(D->getAtLoc()),
T,
D->getPropertyImplementation());
Importer.Imported(D, ToProperty);
ToProperty->setLexicalDeclContext(LexicalDC);
LexicalDC->addDecl(ToProperty);
ToProperty->setPropertyAttributes(D->getPropertyAttributes());
ToProperty->setGetterName(Importer.Import(D->getGetterName()));
ToProperty->setSetterName(Importer.Import(D->getSetterName()));
ToProperty->setGetterMethodDecl(
cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl())));
ToProperty->setSetterMethodDecl(
cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl())));
ToProperty->setPropertyIvarDecl(
cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl())));
return ToProperty;
}
//----------------------------------------------------------------------------
// Import Statements
//----------------------------------------------------------------------------

View File

@ -0,0 +1,12 @@
// Matching properties
@interface I1 {
}
- (int)getProp2;
- (void)setProp2:(int)value;
@end
// Mismatched property
@interface I2
@property (readonly) float Prop1;
@end

View File

@ -0,0 +1,13 @@
// Matching properties
@interface I1 {
}
- (int)getProp2;
- (void)setProp2:(int)value;
@property (readonly) int Prop1;
@property (getter = getProp2, setter = setProp2:) int Prop2;
@end
// Mismatched property
@interface I2
@property (readonly) int Prop1;
@end

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/property1.m
// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/property2.m
// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
// CHECK: property2.m:12:26: error: property 'Prop1' declared with incompatible types in different translation units ('int' vs. 'float')
// CHECK: property1.m:10:28: note: declared here with type 'float'
// CHECK: property2.m:12:26: error: instance method 'Prop1' has incompatible result types in different translation units ('int' vs. 'float')
// CHECK: property1.m:10:28: note: instance method 'Prop1' also declared here
// CHECK: 4 diagnostics generated.