MCPcopy Create free account
hub / github.com/FabricMC/Matcher / analyzeMethod

Method analyzeMethod

src/main/java/matcher/type/Analysis.java:55–750  ·  view source on GitHub ↗
(MethodInstance method, CommonClasses common)

Source from the content-addressed store, hash-verified

53
54class Analysis {
55 static void analyzeMethod(MethodInstance method, CommonClasses common) {
56 MethodNode asmNode = method.getAsmNode();
57 if (asmNode == null || (asmNode.access & Opcodes.ACC_ABSTRACT) != 0 || asmNode.instructions.size() == 0) return;
58
59 Matcher.LOGGER.debug(method.getDisplayName(NameType.MAPPED_PLAIN, true));
60 dump(asmNode);
61
62 StateRecorder rec = new StateRecorder(method, common);
63 InsnList il = asmNode.instructions;
64
65 Map<AbstractInsnNode, int[]> exitPoints = new IdentityHashMap<>();
66 exitPoints.put(null, new int[] { 0 });
67
68 Queue<QueueElement> queue = new ArrayDeque<>();
69 queue.add(new QueueElement(0, rec.getState()));
70 Set<QueueElement> queued = new HashSet<>();
71 queued.add(queue.peek());
72
73 boolean first = true;
74 QueueElement element;
75
76 while ((element = queue.poll()) != null || queueTryCatchBlocks(method, rec, queue, queued) && (element = queue.poll()) != null) {
77 if (!rec.jump(element.dstIndex, element.srcState) && !first) continue;
78 first = false;
79
80 insnLoop: for (int idx = element.dstIndex; idx < il.size(); idx++) {
81 assert rec.idx == idx;
82
83 AbstractInsnNode ain = il.get(idx);
84 int inType = ain.getType();
85
86 if (inType == AbstractInsnNode.LABEL || inType == AbstractInsnNode.FRAME || inType == AbstractInsnNode.LINE) {
87 if (!rec.next()) break;
88 continue;
89 }
90
91 int op = ain.getOpcode();
92
93 switch (op) {
94 // InsnNode
95 case Opcodes.NOP:
96 break;
97 case Opcodes.ACONST_NULL:
98 rec.push(common.NULL, rec.getNextVarId(VarSource.Constant));
99 break;
100 case Opcodes.ICONST_0:
101 case Opcodes.ICONST_1:
102 rec.push(common.BOOLEAN, rec.getNextVarId(VarSource.Constant));
103 break;
104 case Opcodes.ICONST_M1:
105 case Opcodes.ICONST_2:
106 case Opcodes.ICONST_3:
107 case Opcodes.ICONST_4:
108 case Opcodes.ICONST_5:
109 rec.push(common.BYTE, rec.getNextVarId(VarSource.Constant));
110 break;
111 case Opcodes.LCONST_0:
112 case Opcodes.LCONST_1:

Callers

nothing calls this directly

Calls 15

dumpMethod · 0.95
getStateMethod · 0.95
peekMethod · 0.95
queueTryCatchBlocksMethod · 0.95
jumpMethod · 0.95
getMethod · 0.95
getTypeMethod · 0.95
nextMethod · 0.95
pushMethod · 0.95
getNextVarIdMethod · 0.95
pop2Method · 0.95
popMethod · 0.95

Tested by

no test coverage detected