diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2019-01-25 01:23:37 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2019-01-25 01:23:37 +0000 |
commit | 6b6d467fc080468077e4ae623138118c9d365cc1 (patch) | |
tree | e83e77d89f998d3a11fe23a8fd898a6a00dbdd77 /lib/AST/ExprObjC.cpp | |
parent | e217acab66a45cb61e1e22b7dc3d1470fb18e62c (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352147 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprObjC.cpp')
-rw-r--r-- | lib/AST/ExprObjC.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/AST/ExprObjC.cpp b/lib/AST/ExprObjC.cpp index c31b5de2a5..584aa8c1fb 100644 --- a/lib/AST/ExprObjC.cpp +++ b/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: |