Skip to content

Commit

Permalink
[SYCLomatic] Use migrated code as $method_base (#2558)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiang, Zhiwei <[email protected]>
  • Loading branch information
zhiweij1 authored Dec 12, 2024
1 parent d91470e commit 4932f9c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
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

0 comments on commit 4932f9c

Please sign in to comment.