aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-21 19:39:06 +0000
committerChris Lattner <sabre@nondot.org>2008-06-21 19:39:06 +0000
commit5a6ddbf295d2ea1c28cfb67d82db22f3893ede6f (patch)
treec7568aa7f57f05d9e0744bff2440f663c0566f34 /lib/Sema/SemaDecl.cpp
parent63e9d5673791096589c601528e857e00a13050ff (diff)
add parser and sema support for the funny ObjC '@defs' thing.
Patch by David Chisnall! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52586 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7af557b1a8..ee1aad54ed 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1731,6 +1731,35 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
return New;
}
+/// Collect the instance variables declared in an Objective-C object. Used in
+/// the creation of structures from objects using the @defs directive.
+static void CollectIvars(ObjCInterfaceDecl *Class,
+ llvm::SmallVector<Sema::DeclTy*, 16> &ivars) {
+ if (Class->getSuperClass())
+ CollectIvars(Class->getSuperClass(), ivars);
+ ivars.append(Class->ivar_begin(), Class->ivar_end());
+}
+
+/// Called whenever @defs(ClassName) is encountered in the source. Inserts the
+/// instance variables of ClassName into Decls.
+void Sema::ActOnDefs(Scope *S, SourceLocation DeclStart,
+ IdentifierInfo *ClassName,
+ llvm::SmallVector<DeclTy*, 16> &Decls) {
+ // Check that ClassName is a valid class
+ ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName);
+ if (!Class) {
+ Diag(DeclStart, diag::err_undef_interface, ClassName->getName());
+ return;
+ }
+ // Add the isa pointer
+ Decls.push_back(FieldDecl::Create(Context, SourceLocation(),
+ &Context.Idents.get("isa"),
+ Context.getObjCClassType()));
+ // Collect the instance variables
+ CollectIvars(Class, Decls);
+}
+
+
static bool CalcFakeICEVal(const Expr* Expr,
llvm::APSInt& Result,
ASTContext& Context) {