[cfe-commits] r62607 - in /cfe/trunk: lib/AST/ASTContext.cpp test/CodeGenObjC/objc2-protocol-enc.m
Fariborz Jahanian
fjahanian at apple.com
Tue Jan 20 12:04:13 PST 2009
Author: fjahanian
Date: Tue Jan 20 14:04:12 2009
New Revision: 62607
URL: http://llvm.org/viewvc/llvm-project?rev=62607&view=rev
Log:
Detailed documentation for encoding of properties and a test
case.
Added:
cfe/trunk/test/CodeGenObjC/objc2-protocol-enc.m
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=62607&r1=62606&r2=62607&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jan 20 14:04:12 2009
@@ -1699,9 +1699,30 @@
}
/// getObjCEncodingForPropertyDecl - Return the encoded type for this
-/// method declaration. If non-NULL, Container must be either an
+/// property declaration. If non-NULL, Container must be either an
/// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be
/// NULL when getting encodings for protocol properties.
+/// Property attributes are stored as a comma-delimited C string. The simple
+/// attributes readonly and bycopy are encoded as single characters. The
+/// parametrized attributes, getter=name, setter=name, and ivar=name, are
+/// encoded as single characters, followed by an identifier. Property types
+/// are also encoded as a parametrized attribute. The characters used to encode
+/// these attributes are defined by the following enumeration:
+/// @code
+/// enum PropertyAttributes {
+/// kPropertyReadOnly = 'R', // property is read-only.
+/// kPropertyBycopy = 'C', // property is a copy of the value last assigned
+/// kPropertyByref = '&', // property is a reference to the value last assigned
+/// kPropertyDynamic = 'D', // property is dynamic
+/// kPropertyGetter = 'G', // followed by getter selector name
+/// kPropertySetter = 'S', // followed by setter selector name
+/// kPropertyInstanceVariable = 'V' // followed by instance variable name
+/// kPropertyType = 't' // followed by old-style type encoding.
+/// kPropertyWeak = 'W' // 'weak' property
+/// kPropertyStrong = 'P' // property GC'able
+/// kPropertyNonAtomic = 'N' // property non-atomic
+/// };
+/// @endcode
void ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
const Decl *Container,
std::string& S) {
Added: cfe/trunk/test/CodeGenObjC/objc2-protocol-enc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc2-protocol-enc.m?rev=62607&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc2-protocol-enc.m (added)
+++ cfe/trunk/test/CodeGenObjC/objc2-protocol-enc.m Tue Jan 20 14:04:12 2009
@@ -0,0 +1,43 @@
+// RUN: clang -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "T@\\\22<X>\\\22" %t &&
+// RUN: grep -e "T@\\\22<X><Y>\\\22" %t &&
+// RUN: grep -e "T@\\\22<X><Y><Z>\\\22" %t &&
+// RUN: grep -e "T@\\\22Foo<X><Y><Z>\\\22" %t
+
+ at protocol X, Y, Z;
+ at class Foo;
+
+ at protocol Proto
+ at property (copy) id <X> x;
+ at property (copy) id <X, Y> xy;
+ at property (copy) id <X, Y, Z> xyz;
+ at property(copy) Foo <X, Y, Z> *fooxyz;
+ at end
+
+ at interface Intf <Proto>
+{
+id <X> IVAR_x;
+id <X, Y> IVAR_xy;
+id <X, Y, Z> IVAR_xyz;
+Foo <X, Y, Z> *IVAR_Fooxyz;
+}
+ at end
+
+ at implementation Intf
+ at dynamic x, xy, xyz, fooxyz;
+ at end
+
+/**
+This protocol should generate the following metadata:
+struct objc_property_list __Protocol_Test_metadata = {
+ sizeof(struct objc_property), 4,
+ {
+ { "x", "T@\"<X>\"" },
+ { "xy", "T@\"<X><Y>\"" },
+ { "xyz", "T@\"<X><Y><Z>\"" },
+ { "fooxyz", "T@\"Foo<X><Y><Z>\"" }
+ }
+};
+
+"T@\"<X><Y><Z>\",D
+*/
More information about the cfe-commits
mailing list