]> granicus.if.org Git - clang/commitdiff
Change the type of ObjCStringLiteral from "struct __builtin_CFString *" to "NSConstan...
authorSteve Naroff <snaroff@apple.com>
Mon, 15 Oct 2007 23:35:17 +0000 (23:35 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 15 Oct 2007 23:35:17 +0000 (23:35 +0000)
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

AST/ASTContext.cpp
Sema/SemaExpr.cpp
include/clang/AST/ASTContext.h

index 86cf13c4f6e1236ee1c9ce9cc558cb845b2afeb5..366966fec3c7dfb04babc6ec1f39c55743fffa5d 100644 (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();
index c7d74e99ad78c34fb4ada185953fb9d63c287aba..29a3b667be8caec084b927a05e56ec3b7ab8a82c 100644 (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);
 }
 
index e84c423d5e7f528f8f22b9815cae45f8ab45a28b..090cc52c6720dfa30caf953efddae684d16af1a0 100644 (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; }