diff options
Diffstat (limited to 'lib/AST/ExprObjC.cpp')
-rw-r--r-- | lib/AST/ExprObjC.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/AST/ExprObjC.cpp b/lib/AST/ExprObjC.cpp index e1a23f5985..53d0e873f8 100644 --- a/lib/AST/ExprObjC.cpp +++ b/lib/AST/ExprObjC.cpp @@ -1,9 +1,8 @@ //===- ExprObjC.cpp - (ObjC) Expression AST Node Implementation -----------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -293,6 +292,32 @@ 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; + } + llvm_unreachable("Unsupported ExprValueKind"); +} + SourceRange ObjCMessageExpr::getReceiverRange() const { switch (getReceiverKind()) { case Instance: @@ -352,6 +377,11 @@ Stmt::child_range ObjCMessageExpr::children() { reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); } +Stmt::const_child_range ObjCMessageExpr::children() const { + auto Children = const_cast<ObjCMessageExpr *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); +} + StringRef ObjCBridgedCastExpr::getBridgeKindName() const { switch (getBridgeKind()) { case OBC_Bridge: |