]> granicus.if.org Git - clang/commitdiff
Added ASTContext::setObjcIdType/getObjcIdType(), set by Sema.
authorSteve Naroff <snaroff@apple.com>
Mon, 15 Oct 2007 14:41:52 +0000 (14:41 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 15 Oct 2007 14:41:52 +0000 (14:41 +0000)
Also noticed ASTContext::BuiltinVaListType wasn't being initialized to the null type (so I set it).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42983 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTContext.cpp
AST/Type.cpp
Sema/Sema.cpp
Sema/Sema.h
include/clang/AST/ASTContext.h

index f26105f55a98c006c8142d969c8db257ef6eb0f0..93446824b1eda75dc70aaa478ea3fee187ebd097 100644 (file)
@@ -146,6 +146,10 @@ void ASTContext::InitBuiltinTypes() {
   FloatComplexTy      = getComplexType(FloatTy);
   DoubleComplexTy     = getComplexType(DoubleTy);
   LongDoubleComplexTy = getComplexType(LongDoubleTy);
+  
+  BuiltinVaListType = QualType();
+  ObjcIdType = QualType();
+  IdStructType = 0;
 }
 
 //===----------------------------------------------------------------------===//
@@ -837,3 +841,17 @@ void ASTContext::setBuiltinVaListType(QualType T)
   BuiltinVaListType = T;
 }
 
+void ASTContext::setObjcIdType(TypedefDecl *TD)
+{
+  assert(ObjcIdType.isNull() && "'id' type already set!");
+    
+  ObjcIdType = getTypedefType(TD);
+
+  // typedef struct objc_object *id;
+  const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType();
+  assert(ptr && "'id' incorrectly typed");
+  const RecordType *rec = ptr->getPointeeType()->getAsStructureType();
+  assert(rec && "'id' incorrectly typed");
+  IdStructType = rec;
+}
+
index 87090978b45eae5274a895b1e4d205b145713caa..70dce2c4958de6d035c13f872b199d167f431254 100644 (file)
@@ -268,6 +268,8 @@ bool Type::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
 }
 
 // FIXME: Devise a way to do this without using strcmp.
+// Would like to say..."return getAsStructureType() == IdStructType;", but
+// we don't have a pointer to ASTContext.
 bool Type::isObjcIdType() const {
   if (const RecordType *RT = getAsStructureType())
     return !strcmp(RT->getDecl()->getName(), "objc_object");
index 9487ed01ac2c01fbeb6486cdce60b82316b05c98..330d9dce741ac2f4dc6226f4c41d668106e275bd 100644 (file)
@@ -31,17 +31,18 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
 /// For now, we will *not* install id as a built-in. FIXME: reconsider this.
 QualType Sema::GetObjcIdType(SourceLocation Loc) {
   assert(TUScope && "GetObjcIdType(): Top-level scope is null");
-  if (!ObjcIdTypedef) {
+  if (Context.getObjcIdType().isNull()) {
     IdentifierInfo *IdIdent = &Context.Idents.get("id");
     ScopedDecl *IdDecl = LookupScopedDecl(IdIdent, Decl::IDNS_Ordinary, 
                                           SourceLocation(), TUScope);
-    ObjcIdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
+    TypedefDecl *ObjcIdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
     if (!ObjcIdTypedef) {
       Diag(Loc, diag::err_missing_id_definition);
       return QualType();
     }
+    Context.setObjcIdType(ObjcIdTypedef);
   }
-  return Context.getTypedefType(ObjcIdTypedef);
+  return Context.getObjcIdType();
 }
 
 
@@ -64,7 +65,6 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
   KnownFunctionIDs[ id_vprintf ] = &IT.get("vprintf");
   
   TUScope = 0;
-  ObjcIdTypedef = 0;
 }
 
 void Sema::DeleteExpr(ExprTy *E) {
index 94d22f074211b4169ea143948f7a2456f9ad79a0..a7db5b9d2ab0aac9802386ef8b32d577ae672fbd 100644 (file)
@@ -118,9 +118,6 @@ class Sema : public Action {
   /// For example, user-defined classes, built-in "id" type, etc.
   Scope *TUScope;
   
-  /// ObjcIdTypedef - built-in typedef for "id".
-  TypedefDecl *ObjcIdTypedef;
-
   /// ObjCMethodList - a linked list of methods with different signatures.
   struct ObjcMethodList {
     ObjcMethodDecl *Method;
index b554fcf20c642e6bfdfbbf3af5cbde45e32682d0..dfe503627992d51fc661af917872f1d4bd73f724 100644 (file)
@@ -46,6 +46,10 @@ class ASTContext {
   /// This is initially null and set by Sema::LazilyCreateBuiltin when
   /// a builtin that takes a valist is encountered.
   QualType BuiltinVaListType;
+  
+  /// ObjcIdType - a psuedo built-in typedef type (set by Sema).
+  QualType ObjcIdType;
+  const RecordType *IdStructType;
 public:
   
   SourceManager &SourceMgr;
@@ -150,6 +154,9 @@ public:
   // getCFConstantStringType - Return the type used for constant CFStrings. 
   QualType getCFConstantStringType(); 
   
+  void setObjcIdType(TypedefDecl *Decl);
+  QualType getObjcIdType() const { return ObjcIdType; }
+  
   void setBuiltinVaListType(QualType T);
   QualType getBuiltinVaListType() const { return BuiltinVaListType; }