[cfe-commits] r96483 - in /cfe/trunk: include/clang/Basic/DiagnosticASTKinds.td lib/AST/ASTImporter.cpp test/ASTMerge/Inputs/property1.m test/ASTMerge/Inputs/property2.m test/ASTMerge/property.m
Douglas Gregor
dgregor at apple.com
Wed Feb 17 10:02:11 PST 2010
Author: dgregor
Date: Wed Feb 17 12:02:10 2010
New Revision: 96483
URL: http://llvm.org/viewvc/llvm-project?rev=96483&view=rev
Log:
Implement AST merging for Objective-C properties.
Added:
cfe/trunk/test/ASTMerge/Inputs/property1.m
cfe/trunk/test/ASTMerge/Inputs/property2.m
cfe/trunk/test/ASTMerge/property.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ASTImporter.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=96483&r1=96482&r2=96483&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Wed Feb 17 12:02:10 2010
@@ -74,5 +74,8 @@
"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">;
}
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=96483&r1=96482&r2=96483&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Feb 17 12:02:10 2010
@@ -96,7 +96,8 @@
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 @@
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
//----------------------------------------------------------------------------
Added: cfe/trunk/test/ASTMerge/Inputs/property1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/property1.m?rev=96483&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/property1.m (added)
+++ cfe/trunk/test/ASTMerge/Inputs/property1.m Wed Feb 17 12:02:10 2010
@@ -0,0 +1,12 @@
+// Matching properties
+ at interface I1 {
+}
+- (int)getProp2;
+- (void)setProp2:(int)value;
+ at end
+
+// Mismatched property
+ at interface I2
+ at property (readonly) float Prop1;
+ at end
+
Added: cfe/trunk/test/ASTMerge/Inputs/property2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/property2.m?rev=96483&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/property2.m (added)
+++ cfe/trunk/test/ASTMerge/Inputs/property2.m Wed Feb 17 12:02:10 2010
@@ -0,0 +1,13 @@
+// Matching properties
+ at interface I1 {
+}
+- (int)getProp2;
+- (void)setProp2:(int)value;
+ at property (readonly) int Prop1;
+ at property (getter = getProp2, setter = setProp2:) int Prop2;
+ at end
+
+// Mismatched property
+ at interface I2
+ at property (readonly) int Prop1;
+ at end
Added: cfe/trunk/test/ASTMerge/property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/property.m?rev=96483&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/property.m (added)
+++ cfe/trunk/test/ASTMerge/property.m Wed Feb 17 12:02:10 2010
@@ -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.
More information about the cfe-commits
mailing list