Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic] Use migrated code as $method_base #2558

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions clang/lib/DPCT/RuleInfra/CallExprRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define CALL_EXPR_REWRITER_H

#include "Diagnostics/Diagnostics.h"
#include "RuleInfra/ExprAnalysis.h"

namespace clang {
namespace dpct {
Expand Down Expand Up @@ -1676,26 +1677,14 @@ class UserDefinedRewriter : public CallExprRewriter {
case (OutputBuilder::Kind::MethodBase): {
if (auto *MCE = llvm::dyn_cast<CXXMemberCallExpr>(Call)) {
if (auto *Callee = llvm::dyn_cast<MemberExpr>(MCE->getCallee())) {
auto &SM = DpctGlobalInfo::getSourceManager();
auto &Context = DpctGlobalInfo::getContext();
auto CallRange =
getDefinitionRange(Call->getBeginLoc(), Call->getEndLoc());
auto LastTokenLength = Lexer::MeasureTokenLength(
CallRange.getEnd(), SM, Context.getLangOpts());
auto Base = Callee->getBase();
std::string BaseStr;
if (isa<CXXThisExpr>(Callee->getBase())) {
BaseStr = "this";
} else {
BaseStr = getStringInRange(
Base->getSourceRange(), CallRange.getBegin(),
CallRange.getEnd().getLocWithOffset(LastTokenLength));
}
OS << BaseStr;
if (Callee->isArrow()) {
OS << "->";
} else {
OS << ".";
const Expr *Base = Callee->getBase();
if (!isa<CXXThisExpr>(Base)) {
ExprAnalysis EA(Base);
OS << EA.getReplacedString();
if (Callee->isArrow())
OS << "->";
else
OS << ".";
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions clang/test/dpct/user_defined_rule.cu
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public:
int fieldC;
int methodA(int i, int j){return 0;};
};
ClassA getClassA() { return ClassA(); };
class ClassB{
public:
int fieldB;
int methodB(int i){return 0;};
};
ClassB getClassB() { return ClassB(); };

enum Fruit{
apple,
Expand All @@ -80,12 +82,14 @@ void foo2(){
//CHECK: ClassB a;
//CHECK-NEXT: a.fieldD = 3;
//CHECK-NEXT: a.methodB(2);
//CHECK-NEXT: getClassB().methodB(2);
//CHECK-NEXT: a.set_a(3);
//CHECK-NEXT: int k = a.get_a();
//CHECK-NEXT: Fruit f = pineapple;
ClassA a;
a.fieldC = 3;
a.methodA(1,2);
getClassA().methodA(1,2);
a.fieldA = 3;
int k = a.fieldA;
Fruit f = Fruit::apple;
Expand Down
5 changes: 5 additions & 0 deletions clang/test/dpct/user_defined_rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
Out: $method_base methodB($2)
- In: methodC
Out: methodD
- Rule: rule_getClassA
Kind: API
Priority: Takeover
In: getClassA
Out: getClassB()
- Rule: rule_Fruit
Kind: Enum
Priority: Takeover
Expand Down