[cfe-commits] r51968 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/RecordLayout.h lib/AST/ASTContext.cpp test/Sema/objc-interface-layout.m
Devang Patel
dpatel at apple.com
Wed Jun 4 14:54:37 PDT 2008
Author: dpatel
Date: Wed Jun 4 16:54:36 2008
New Revision: 51968
URL: http://llvm.org/viewvc/llvm-project?rev=51968&view=rev
Log:
Add ObjCInterface layout support.
Reuse RecordLayout.
Added:
cfe/trunk/test/Sema/objc-interface-layout.m
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/RecordLayout.h
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=51968&r1=51967&r2=51968&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Jun 4 16:54:36 2008
@@ -49,6 +49,8 @@
/// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts.
/// This is lazily created. This is intentionally not serialized.
llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts;
+ llvm::DenseMap<const ObjCInterfaceDecl*,
+ const ASTRecordLayout*> ASTObjCInterfaces;
llvm::SmallVector<const RecordType *, 8> EncodingRecordTypes;
@@ -304,6 +306,7 @@
/// position information.
const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
+ const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
//===--------------------------------------------------------------------===//
// Type Operators
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=51968&r1=51967&r2=51968&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Wed Jun 4 16:54:36 2008
@@ -20,9 +20,13 @@
class ASTContext;
class RecordDecl;
-/// ASTRecordLayout - This class contains layout information for one RecordDecl,
+/// ASTRecordLayout -
+/// This class contains layout information for one RecordDecl,
/// which is a struct/union/class. The decl represented must be a definition,
-/// not a forward declaration. These objects are managed by ASTContext.
+/// not a forward declaration.
+/// This class is also used to contain layout informaiton for one
+/// ObjCInterfaceDecl. FIXME - Find appropriate name.
+/// These objects are managed by ASTContext.
class ASTRecordLayout {
uint64_t Size; // Size of record in bits.
unsigned Alignment; // Alignment of record in bits.
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=51968&r1=51967&r2=51968&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jun 4 16:54:36 2008
@@ -295,6 +295,13 @@
Align = EltInfo.second;
break;
}
+ case Type::ObjCInterface: {
+ ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T);
+ const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl());
+ Width = Layout.getSize();
+ Align = Layout.getAlignment();
+ break;
+ }
case Type::Tagged: {
if (EnumType *ET = dyn_cast<EnumType>(cast<TagType>(T)))
return getTypeInfo(ET->getDecl()->getIntegerType());
@@ -386,6 +393,42 @@
Alignment = std::max(Alignment, FieldAlign);
}
+
+/// getASTObjcInterfaceLayout - Get or compute information about the layout of the
+/// specified Objective C, which indicates its size and ivar
+/// position information.
+const ASTRecordLayout &
+ASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) {
+ // Look up this layout, if already laid out, return what we have.
+ const ASTRecordLayout *&Entry = ASTObjCInterfaces[D];
+ if (Entry) return *Entry;
+
+ // Allocate and assign into ASTRecordLayouts here. The "Entry" reference can
+ // be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into.
+ ASTRecordLayout *NewEntry = new ASTRecordLayout();
+ Entry = NewEntry;
+
+ NewEntry->InitializeLayout(D->ivar_size());
+ bool IsPacked = D->getAttr<PackedAttr>();
+
+ if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
+ NewEntry->SetAlignment(std::max(NewEntry->getAlignment(),
+ AA->getAlignment()));
+
+ // Layout each ivar sequentially.
+ unsigned i = 0;
+ for (ObjCInterfaceDecl::ivar_iterator IVI = D->ivar_begin(),
+ IVE = D->ivar_end(); IVI != IVE; ++IVI) {
+ const ObjCIvarDecl* Ivar = (*IVI);
+ NewEntry->LayoutField(Ivar, i++, false, IsPacked, *this);
+ }
+
+ // Finally, round the size of the total struct up to the alignment of the
+ // struct itself.
+ NewEntry->FinalizeLayout();
+ return *NewEntry;
+}
+
/// getASTRecordLayout - Get or compute information about the layout of the
/// specified record (struct/union/class), which indicates its size and field
/// position information.
Added: cfe/trunk/test/Sema/objc-interface-layout.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-interface-layout.m?rev=51968&view=auto
==============================================================================
--- cfe/trunk/test/Sema/objc-interface-layout.m (added)
+++ cfe/trunk/test/Sema/objc-interface-layout.m Wed Jun 4 16:54:36 2008
@@ -0,0 +1,27 @@
+// RUN: clang %s -fsyntax-only -verify
+typedef struct objc_object {} *id;
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+
+ at protocol NSObject
+- (BOOL) isEqual:(id) object;
+ at end
+
+ at protocol NSCopying
+- (id) copyWithZone:(NSZone *) zone;
+ at end
+
+ at interface NSObject < NSObject > {}
+ at end
+
+extern id NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone * zone);
+
+ at interface MyClassBase : NSObject < NSCopying > {}
+ at end
+
+ at interface MyClassDirectNode : MyClassBase < NSCopying >
+{
+ @public NSUInteger attributeRuns[((1024 - 16 - sizeof (MyClassBase)) / (sizeof (NSUInteger) + sizeof (void *)))];
+}
+ at end
More information about the cfe-commits
mailing list