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

Jimple to JavaObjects to change minimaltestsuite #1162

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

sahilagichani14
Copy link
Collaborator

No description provided.

@sahilagichani14 sahilagichani14 linked an issue Jan 20, 2025 that may be closed by this pull request
3 tasks
@sahilagichani14 sahilagichani14 marked this pull request as draft January 20, 2025 05:13
Copy link
Collaborator

@swissiety swissiety left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear we are on the same page: the goal is to transform a StmtGraph to a String containing Java Sourcecode. And if we run that Javacode we should get the equivalent StmtGraph (again)

@sahilagichani14
Copy link
Collaborator Author

Just to be clear we are on the same page: the goal is to transform a StmtGraph to a String containing Java Sourcecode. And if we run that Javacode we should get the equivalent StmtGraph (again)

So the starting point is StmtGraph and not Jimple String?

@swissiety
Copy link
Collaborator

yes and please make use/implement a StmtVisitor to print the details of the respective Stmts. And in those methods of the StmtVisitor you could make use of that JavaPoet library if it helps you to keep track of the different Java variables of the generated source code. Maybe a Map<Value, JavaVariableNameString> of already generated Jimple objects would suffice as well, so you could generate each Stmt and initialize its Operands or reuse the already created ones.

Comment on lines +97 to +114
if (stmt.getRightOp() instanceof IntConstant) {
typeString =
String.format(
"IntConstant.getInstance(%s)", ((IntConstant) stmt.getRightOp()).getValue());
} else if (stmt.getRightOp() instanceof Local) {
typeString =
String.format(
"JavaJimple.newLocal(\"%s\", factory.getClassType(\"%s\"))",
((Local) stmt.getRightOp()).getName(), stmt.getRightOp().getType());
}
javaCodeObjects.add(
String.format(
"Stmt %s = JavaJimple.newAssignment(JavaJimple.newLocal(\"%s\", factory.classType(\"%s\")), %s , noStmtPositionInfo)",
stmt.getLeftOp().toString(),
stmt.getLeftOp().toString(),
stmt.getType().toString(),
typeString));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget we have more of those visitors like the ValueVisitor e.g. for Operands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: JimpleJavaObjectPrinter
2 participants