From: Steve Naroff Date: Mon, 15 Oct 2007 23:35:17 +0000 (+0000) Subject: Change the type of ObjCStringLiteral from "struct __builtin_CFString *" to "NSConstan... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2198891824c38d45b2279de5d5e3ef9394eb457c;p=clang 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43021 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index 86cf13c4f6..366966fec3 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -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(); diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index c7d74e99ad..29a3b667be 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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(IFace); + assert(stringInterface && "missing '@interface NSConstantString'"); + Context.setObjcConstantStringInterface(stringInterface); + } + QualType t = Context.getObjcConstantStringInterface(); t = Context.getPointerType(t); - return new ObjCStringLiteral(S, t); } diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index e84c423d5e..090cc52c67 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -40,7 +40,6 @@ class ASTContext { llvm::FoldingSet FunctionTypeProtos; llvm::FoldingSet ObjcQualifiedInterfaceTypes; llvm::DenseMap 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 . 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; }