summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprObjC.cpp
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2019-01-25 01:23:37 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2019-01-25 01:23:37 +0000
commit42c9473edeef02b0e31f39dad8621c5f3eb99379 (patch)
treefbf1670c1885fbaef2c3b5acacf6cb89c9f7f06f /clang/lib/AST/ExprObjC.cpp
parent0b247d1865dc0c973f5a4482ad69eed3b460edaa (diff)
downloadbcm5719-llvm-42c9473edeef02b0e31f39dad8621c5f3eb99379.tar.gz
bcm5719-llvm-42c9473edeef02b0e31f39dad8621c5f3eb99379.zip
[AST] Add a method to get a call type from an ObjCMessageExpr
Due to references, expression type does not always correspond to an expected method return type (e.g. for a method returning int & the expression type of the call would still be int). We have a helper method for getting the expected type on CallExpr, but not on ObjCMessageExpr. Differential Revision: https://reviews.llvm.org/D57204 llvm-svn: 352147
Diffstat (limited to 'clang/lib/AST/ExprObjC.cpp')
-rw-r--r--clang/lib/AST/ExprObjC.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprObjC.cpp b/clang/lib/AST/ExprObjC.cpp
index c31b5de2a5b..584aa8c1fbe 100644
--- a/clang/lib/AST/ExprObjC.cpp
+++ b/clang/lib/AST/ExprObjC.cpp
@@ -292,6 +292,31 @@ void ObjCMessageExpr::getSelectorLocs(
SelLocs.push_back(getSelectorLoc(i));
}
+
+QualType ObjCMessageExpr::getCallReturnType(ASTContext &Ctx) const {
+ if (const ObjCMethodDecl *MD = getMethodDecl()) {
+ QualType QT = MD->getReturnType();
+ if (QT == Ctx.getObjCInstanceType()) {
+ // instancetype corresponds to expression types.
+ return getType();
+ }
+ return QT;
+ }
+
+ // Expression type might be different from an expected call return type,
+ // as expression type would never be a reference even if call returns a
+ // reference. Reconstruct the original expression type.
+ QualType QT = getType();
+ switch (getValueKind()) {
+ case VK_LValue:
+ return Ctx.getLValueReferenceType(QT);
+ case VK_XValue:
+ return Ctx.getRValueReferenceType(QT);
+ case VK_RValue:
+ return QT;
+ }
+}
+
SourceRange ObjCMessageExpr::getReceiverRange() const {
switch (getReceiverKind()) {
case Instance:
OpenPOWER on IntegriCloud