Added ASTContext::setObjcIdType/getObjcIdType(), set by Sema.

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
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index f26105f..9344682 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -146,6 +146,10 @@
   FloatComplexTy      = getComplexType(FloatTy);
   DoubleComplexTy     = getComplexType(DoubleTy);
   LongDoubleComplexTy = getComplexType(LongDoubleTy);
+  
+  BuiltinVaListType = QualType();
+  ObjcIdType = QualType();
+  IdStructType = 0;
 }
 
 //===----------------------------------------------------------------------===//
@@ -837,3 +841,17 @@
   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;
+}
+
diff --git a/AST/Type.cpp b/AST/Type.cpp
index 8709097..70dce2c 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -268,6 +268,8 @@
 }
 
 // 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");
diff --git a/Sema/Sema.cpp b/Sema/Sema.cpp
index 9487ed0..330d9dc 100644
--- a/Sema/Sema.cpp
+++ b/Sema/Sema.cpp
@@ -31,17 +31,18 @@
 /// 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 @@
   KnownFunctionIDs[ id_vprintf ] = &IT.get("vprintf");
   
   TUScope = 0;
-  ObjcIdTypedef = 0;
 }
 
 void Sema::DeleteExpr(ExprTy *E) {
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 94d22f0..a7db5b9 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -118,9 +118,6 @@
   /// 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;
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index b554fcf..dfe5036 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -46,6 +46,10 @@
   /// 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 @@
   // 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; }