aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AST/ASTContext.cpp18
-rw-r--r--AST/Type.cpp2
-rw-r--r--Sema/Sema.cpp8
-rw-r--r--Sema/Sema.h3
-rw-r--r--include/clang/AST/ASTContext.h7
5 files changed, 31 insertions, 7 deletions
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index f26105f55a..93446824b1 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -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;
+}
+
diff --git a/AST/Type.cpp b/AST/Type.cpp
index 87090978b4..70dce2c495 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -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");
diff --git a/Sema/Sema.cpp b/Sema/Sema.cpp
index 9487ed01ac..330d9dce74 100644
--- a/Sema/Sema.cpp
+++ b/Sema/Sema.cpp
@@ -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) {
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 94d22f0742..a7db5b9d2a 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -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;
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index b554fcf20c..dfe5036279 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -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; }