MCPcopy Create free account
hub / github.com/LFYSec/MScan / IRBuildHelper

Class IRBuildHelper

src/main/java/pascal/taie/ir/IRBuildHelper.java:42–157  ·  view source on GitHub ↗

Helper for building IR for a method from scratch. Given a JMethod, this helper automatically creates this variable (for instance method), parameters, and return variable (if method return type is not void) for the method.

Source from the content-addressed store, hash-verified

40 * return type is not {@code void}) for the method.
41 */
42public class IRBuildHelper {
43
44 private static final String THIS = "%this";
45
46 private static final String PARAM = "%param";
47
48 private static final String TEMP = "%temp";
49
50 private static final String RETURN = "%return";
51
52 private final JMethod method;
53
54 private final Var thisVar;
55
56 private final List<Var> params;
57
58 private final Var returnVar;
59
60 private final Set<Var> returnVars;
61
62 private final List<Var> vars;
63
64 /**
65 * Counter for indexing all variables.
66 */
67 private int varCounter = 0;
68
69 /**
70 * Counter for naming temporary variables.
71 */
72 private int tempCounter = 0;
73
74 public IRBuildHelper(JMethod method) {
75 this.method = method;
76 // build this variable
77 vars = new ArrayList<>();
78 thisVar = method.isStatic() ? null :
79 newVar(THIS, method.getDeclaringClass().getType());
80 // build parameters
81 params = new ArrayList<>(method.getParamCount());
82 for (int i = 0; i < method.getParamCount(); ++i) {
83 params.add(newVar(PARAM + i, method.getParamType(i)));
84 }
85 // build return variable
86 Type retType = method.getReturnType();
87 if (!retType.equals(VoidType.VOID)) {
88 returnVar = newVar(RETURN, retType);
89 returnVars = Set.of(returnVar);
90 } else {
91 returnVar = null;
92 returnVars = Set.of();
93 }
94 }
95
96 /**
97 * @return {@code this} variable of the IR being built.
98 * @throws AssertionError if the method is not an instance method.
99 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected