[cfe-commits] r42983 - in /cfe/trunk: AST/ASTContext.cpp AST/Type.cpp Sema/Sema.cpp Sema/Sema.h include/clang/AST/ASTContext.h
Steve Naroff
snaroff at apple.com
Mon Oct 15 07:41:53 PDT 2007
Author: snaroff
Date: Mon Oct 15 09:41:52 2007
New Revision: 42983
URL: http://llvm.org/viewvc/llvm-project?rev=42983&view=rev
Log:
Added ASTContext::setObjcIdType/getObjcIdType(), set by Sema.
Also noticed ASTContext::BuiltinVaListType wasn't being initialized to the null type (so I set it).
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/AST/Type.cpp
cfe/trunk/Sema/Sema.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/include/clang/AST/ASTContext.h
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=42983&r1=42982&r2=42983&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Mon Oct 15 09:41:52 2007
@@ -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;
+}
+
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=42983&r1=42982&r2=42983&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Mon Oct 15 09:41:52 2007
@@ -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");
Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=42983&r1=42982&r2=42983&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Mon Oct 15 09:41:52 2007
@@ -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) {
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42983&r1=42982&r2=42983&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Mon Oct 15 09:41:52 2007
@@ -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;
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=42983&r1=42982&r2=42983&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Oct 15 09:41:52 2007
@@ -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; }
More information about the cfe-commits
mailing list