[PATCH] D57204: [AST] Add a method to get a call type from an ObjCMessageExpr
George Karpenkov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 24 17:24:51 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rC352147: [AST] Add a method to get a call type from an ObjCMessageExpr (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.
Changed prior to commit:
https://reviews.llvm.org/D57204?vs=183439&id=183453#toc
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57204/new/
https://reviews.llvm.org/D57204
Files:
include/clang/AST/ExprObjC.h
lib/AST/ExprObjC.cpp
Index: include/clang/AST/ExprObjC.h
===================================================================
--- include/clang/AST/ExprObjC.h
+++ include/clang/AST/ExprObjC.h
@@ -1180,6 +1180,13 @@
/// sent to.
ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
+ /// \return the return type of the message being sent.
+ /// This is not always the type of the message expression itself because
+ /// of references (the expression would not have a reference type).
+ /// It is also not always the declared return type of the method because
+ /// of `instancetype` (in that case it's an expression type).
+ QualType getCallReturnType(ASTContext &Ctx) const;
+
/// Source range of the receiver.
SourceRange getReceiverRange() const;
Index: lib/AST/ExprObjC.cpp
===================================================================
--- lib/AST/ExprObjC.cpp
+++ lib/AST/ExprObjC.cpp
@@ -292,6 +292,31 @@
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57204.183453.patch
Type: text/x-patch
Size: 1844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190125/0ebb3378/attachment.bin>
More information about the cfe-commits
mailing list