aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-18 06:06:56 +0000
committerChris Lattner <sabre@nondot.org>2009-02-18 06:06:56 +0000
commita0af1fe67da29343cd182c51cd48d91b740ecef2 (patch)
treef639daa78dc080c903aeeeefda1d14dfaee35e56
parent690398188ea5b428f06aa13c7d4ce6eb741ad4f9 (diff)
simplify the code used to compute the type of an objc string. This makes
it faster in the common case when NSConstantString is around. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64895 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExprObjC.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 1da74b9c32..5dba6846a3 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -51,36 +51,38 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
// Verify that this composite string is acceptable for ObjC strings.
if (CheckObjCString(S))
return true;
-
- 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");
- NamedDecl *IFace = LookupName(TUScope, NSIdent, LookupOrdinaryName);
- ObjCInterfaceDecl *strIFace = dyn_cast_or_null<ObjCInterfaceDecl>(IFace);
- if (strIFace)
- Context.setObjCConstantStringInterface(strIFace);
- }
- QualType t = Context.getObjCConstantStringInterface();
- // If there is no NSConstantString interface defined then treat constant
- // strings as untyped objects and let the runtime figure it out later.
- if (t == QualType()) {
- t = Context.getObjCIdType();
+
+ // Initialize the constant string interface lazily. This assumes
+ // the NSConstantString interface is seen in this translation unit.
+ QualType Ty = Context.getObjCConstantStringInterface();
+ if (!Ty.isNull()) {
+ Ty = Context.getPointerType(Ty);
} else {
- t = Context.getPointerType(t);
+ IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
+ NamedDecl *IF = LookupName(TUScope, NSIdent, LookupOrdinaryName);
+ if (ObjCInterfaceDecl *StrIF = dyn_cast_or_null<ObjCInterfaceDecl>(IF)) {
+ Context.setObjCConstantStringInterface(StrIF);
+ Ty = Context.getObjCConstantStringInterface();
+ Ty = Context.getPointerType(Ty);
+ } else {
+ // If there is no NSConstantString interface defined then treat constant
+ // strings as untyped objects and let the runtime figure it out later.
+ Ty = Context.getObjCIdType();
+ }
}
- return new (Context) ObjCStringLiteral(S, t, AtLoc);
+
+ return new (Context) ObjCStringLiteral(S, Ty, AtLoc);
}
Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
SourceLocation EncodeLoc,
SourceLocation LParenLoc,
- TypeTy *Ty,
+ TypeTy *ty,
SourceLocation RParenLoc) {
- QualType EncodedType = QualType::getFromOpaquePtr(Ty);
+ QualType EncodedType = QualType::getFromOpaquePtr(ty);
- QualType t = Context.getPointerType(Context.CharTy);
- return new (Context) ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
+ QualType Ty = Context.getPointerType(Context.CharTy);
+ return new (Context) ObjCEncodeExpr(Ty, EncodedType, AtLoc, RParenLoc);
}
Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
@@ -88,8 +90,8 @@ Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
SourceLocation SelLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc) {
- QualType t = Context.getObjCSelType();
- return new (Context) ObjCSelectorExpr(t, Sel, AtLoc, RParenLoc);
+ QualType Ty = Context.getObjCSelType();
+ return new (Context) ObjCSelectorExpr(Ty, Sel, AtLoc, RParenLoc);
}
Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
@@ -103,11 +105,11 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
return true;
}
- QualType t = Context.getObjCProtoType();
- if (t.isNull())
+ QualType Ty = Context.getObjCProtoType();
+ if (Ty.isNull())
return true;
- t = Context.getPointerType(t);
- return new (Context) ObjCProtocolExpr(t, PDecl, AtLoc, RParenLoc);
+ Ty = Context.getPointerType(Ty);
+ return new (Context) ObjCProtocolExpr(Ty, PDecl, AtLoc, RParenLoc);
}
bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,