Change the type of ObjCStringLiteral from "struct __builtin_CFString *" to "NSConstantString *".

This makes the typecheck much happier. Without this change, the type checker would have to special case "struct __builtin_CFString *". This change does assume the interface for NSConstantString is declared in the translation unit.

I left ASTContext::getCFConstantStringType() around for now (with a comment that says it is currently unused).

llvm-svn: 43021
This commit is contained in:
Steve Naroff 2007-10-15 23:35:17 +00:00
parent 9aa4fc5cd6
commit f73b784a5e
3 changed files with 31 additions and 6 deletions

View File

@ -150,6 +150,7 @@ void ASTContext::InitBuiltinTypes() {
BuiltinVaListType = QualType();
ObjcIdType = QualType();
IdStructType = 0;
ObjcConstantStringType = QualType();
}
//===----------------------------------------------------------------------===//
@ -855,6 +856,13 @@ void ASTContext::setObjcIdType(TypedefDecl *TD)
IdStructType = rec;
}
void ASTContext::setObjcConstantStringInterface(ObjcInterfaceDecl *Decl) {
assert(ObjcConstantStringType.isNull() &&
"'NSConstantString' type already set!");
ObjcConstantStringType = getObjcInterfaceType(Decl);
}
bool ASTContext::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
const BuiltinType *lBuiltin = lhs->getAsBuiltinType();
const BuiltinType *rBuiltin = rhs->getAsBuiltinType();

View File

@ -1890,10 +1890,18 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string) {
if (CheckBuiltinCFStringArgument(S))
return true;
QualType t = Context.getCFConstantStringType();
t = t.getQualifiedType(QualType::Const);
if (Context.getObjcConstantStringInterface().isNull()) {
// Initialize the constant string interface lazily. This assumes
// the NSConstantString interface is seen in this translation unit.
IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
ScopedDecl *IFace = LookupScopedDecl(NSIdent, Decl::IDNS_Ordinary,
SourceLocation(), TUScope);
ObjcInterfaceDecl *stringInterface = cast<ObjcInterfaceDecl>(IFace);
assert(stringInterface && "missing '@interface NSConstantString'");
Context.setObjcConstantStringInterface(stringInterface);
}
QualType t = Context.getObjcConstantStringInterface();
t = Context.getPointerType(t);
return new ObjCStringLiteral(S, t);
}

View File

@ -40,7 +40,6 @@ class ASTContext {
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::FoldingSet<ObjcQualifiedInterfaceType> ObjcQualifiedInterfaceTypes;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
RecordDecl *CFConstantStringTypeDecl;
/// BuiltinVaListType - built-in va list type.
/// This is initially null and set by Sema::LazilyCreateBuiltin when
@ -50,6 +49,9 @@ class ASTContext {
/// ObjcIdType - a psuedo built-in typedef type (set by Sema).
QualType ObjcIdType;
const RecordType *IdStructType;
QualType ObjcConstantStringType;
RecordDecl *CFConstantStringTypeDecl;
public:
SourceManager &SourceMgr;
@ -151,12 +153,19 @@ public:
/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
QualType getPointerDiffType() const;
// getCFConstantStringType - Return the type used for constant CFStrings.
// getCFConstantStringType - Return the type used for constant CFStrings.
// CURRENTLY UNUSED (10/15/07). ObjCStringLiteral now uses the hook below.
QualType getCFConstantStringType();
// This setter/getter represents the actual ObjC type for an NSConstantString.
void setObjcConstantStringInterface(ObjcInterfaceDecl *Decl);
QualType getObjcConstantStringInterface() const {
return ObjcConstantStringType;
}
void setObjcIdType(TypedefDecl *Decl);
QualType getObjcIdType() const { return ObjcIdType; }
void setBuiltinVaListType(QualType T);
QualType getBuiltinVaListType() const { return BuiltinVaListType; }