[cfe-commits] r43021 - in /cfe/trunk: AST/ASTContext.cpp Sema/SemaExpr.cpp include/clang/AST/ASTContext.h
Steve Naroff
snaroff at apple.com
Mon Oct 15 16:35:18 PDT 2007
Author: snaroff
Date: Mon Oct 15 18:35:17 2007
New Revision: 43021
URL: http://llvm.org/viewvc/llvm-project?rev=43021&view=rev
Log:
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).
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/Sema/SemaExpr.cpp
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=43021&r1=43020&r2=43021&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Mon Oct 15 18:35:17 2007
@@ -150,6 +150,7 @@
BuiltinVaListType = QualType();
ObjcIdType = QualType();
IdStructType = 0;
+ ObjcConstantStringType = QualType();
}
//===----------------------------------------------------------------------===//
@@ -855,6 +856,13 @@
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();
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=43021&r1=43020&r2=43021&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Oct 15 18:35:17 2007
@@ -1890,10 +1890,18 @@
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);
}
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=43021&r1=43020&r2=43021&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Oct 15 18:35:17 2007
@@ -40,7 +40,6 @@
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 @@
/// 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 @@
/// 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; }
More information about the cfe-commits
mailing list