Skip to content

Commit bed0423

Browse files
committed
Improved Deducing this
1 parent 6857df5 commit bed0423

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

clang/lib/Frontend/OvdlPrinter.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "clang/AST/DeclCXX.h"
12
#include "clang/Basic/SourceLocation.h"
23
#include "clang/Basic/Specifiers.h"
34
#include "clang/Frontend/CompilerInstance.h"
@@ -7,6 +8,7 @@
78
#include "clang/Sema/OverloadCallback.h"
89
#include "clang/Sema/Sema.h"
910
#include "llvm/ADT/SmallString.h"
11+
#include "llvm/Support/Casting.h"
1012
#include "llvm/Support/YAMLTraits.h"
1113
#include "llvm/Support/raw_ostream.h"
1214
#include <algorithm>
@@ -70,7 +72,7 @@ struct OvInsCandEntry {
7072
std::string name;
7173
std::string usingLocation;
7274
clang::SourceLocation usingLoc;
73-
OverloadCandidateRewriteKind rewriteKind;
75+
OverloadCandidateRewriteKind rewriteKind=clang::CRK_None;
7476
std::deque<std::string> paramTypes;
7577
OvInsSource src;
7678
std::vector<OvInsTemplateSpec> templateSpecs;
@@ -1102,20 +1104,26 @@ class DefaultOverloadInstCallback : public OverloadCallback {
11021104
const auto callKinds = getCallKinds();
11031105
const SetArgs &setArg = getSetArgs();
11041106
bool isStaticCall = setArg.ObjectExpr == nullptr && C.IgnoreObjectArgument;
1107+
//if (C.Function && C.Function){isStaticCall=true;}
11051108
for (size_t i = 0; i < C.Conversions.size(); ++i) {
11061109
const ExprValueKind fromKind =
11071110
(callKinds.size() > i - isStaticCall)
11081111
? ((i >= isStaticCall) ? callKinds[i - isStaticCall] : VK_LValue)
11091112
: VK_LValue;
11101113
const auto &conv = C.Conversions[i];
11111114
OvInsConvEntry &actual = res[i];
1115+
bool isDeduceThis=false;
11121116
{
11131117
int inArgsIdx = i;
1114-
if ((C.Function && isa<CXXMethodDecl>(C.Function) &&
1115-
!isa<CXXConstructorDecl>(C.Function) && setArg.ObjectExpr) ||
1116-
C.IsSurrogate)
1117-
--inArgsIdx;
1118-
actual.src = getConversionSource(setArg, inArgsIdx);
1118+
if (auto* fp=llvm::dyn_cast_or_null<CXXMethodDecl>(C.Function)){
1119+
isDeduceThis = fp->isExplicitObjectMemberFunction();
1120+
}
1121+
if (!isDeduceThis)
1122+
if ((C.Function && isa<CXXMethodDecl>(C.Function) &&
1123+
!isa<CXXConstructorDecl>(C.Function) && setArg.ObjectExpr) ||
1124+
C.IsSurrogate)
1125+
--inArgsIdx;
1126+
actual.src = getConversionSource(setArg, inArgsIdx-isDeduceThis);
11191127
}
11201128
if (!conv.isInitialized()) {
11211129
actual.kind = "Uninitialized";
@@ -1124,6 +1132,7 @@ class DefaultOverloadInstCallback : public OverloadCallback {
11241132
int idx = i;
11251133
if (C.isReversed())
11261134
idx = 1 - idx;
1135+
//if (!isDeduceThis)
11271136
if ((C.Function && isa<CXXMethodDecl>(C.Function) &&
11281137
!isa<CXXConstructorDecl>(C.Function)) ||
11291138
C.IsSurrogate)
@@ -1138,7 +1147,7 @@ class DefaultOverloadInstCallback : public OverloadCallback {
11381147
if (C.Function && idx != -1 &&
11391148
!isa<clang::InitListExpr>(setArg.inArgs[idx]))
11401149
path << " -> "
1141-
<< C.Function->parameters()[idx]
1150+
<< C.Function->parameters()[idx+isDeduceThis]
11421151
->getType()
11431152
.getCanonicalType()
11441153
.getAsString();
@@ -1204,6 +1213,7 @@ class DefaultOverloadInstCallback : public OverloadCallback {
12041213
if (temp != "")
12051214
path << " = " << temp;
12061215
}
1216+
//path << i<<" "<<idx;
12071217
}
12081218

12091219
return res;
@@ -1284,8 +1294,6 @@ class DefaultOverloadInstCallback : public OverloadCallback {
12841294
res.usingLoc.print(usingLoc, S->SourceMgr);
12851295
}
12861296
res.rewriteKind = C.getRewriteKind();
1287-
if (!C.Function && !C.IsSurrogate)
1288-
res.rewriteKind = OverloadCandidateRewriteKind::CRK_None;
12891297
res.name = C.FoundDecl.getDecl()->getQualifiedNameAsString();
12901298
if (C.Function) {
12911299
res.paramTypes = getParamTypes(C);

0 commit comments

Comments
 (0)