summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-04 11:52:40 +0100
committer zaaarf <zaaarf@proton.me>2023-03-04 11:52:40 +0100
commitc9ea715ba1caf0efb8b6ae0f805e0cff391e9b03 (patch)
tree0f691a32bd1f1247deb1862120474402956a240b
parent3185d840c456d76140d1f40b7a0c8818dba3b18f (diff)
fix: added empty predicates edge case to find function, and single-instruction constructor to InsnSequence
-rw-r--r--src/main/java/ftbsc/lll/tools/InsnSequence.java10
-rw-r--r--src/main/java/ftbsc/lll/tools/PatternMatcher.java26
2 files changed, 23 insertions, 13 deletions
diff --git a/src/main/java/ftbsc/lll/tools/InsnSequence.java b/src/main/java/ftbsc/lll/tools/InsnSequence.java
index 1a915ca..2038155 100644
--- a/src/main/java/ftbsc/lll/tools/InsnSequence.java
+++ b/src/main/java/ftbsc/lll/tools/InsnSequence.java
@@ -20,6 +20,16 @@ public class InsnSequence extends InsnList {
}
/**
+ * Public constructor for list with single item.
+ * Must be given a single non-null node.
+ * @param node the node in question
+ */
+ public InsnSequence(AbstractInsnNode node) {
+ super();
+ super.add(node);
+ }
+
+ /**
* Public constructor.
* Must be given two non-null, connected nodes.
* @param startNode the starting node of the pattern
diff --git a/src/main/java/ftbsc/lll/tools/PatternMatcher.java b/src/main/java/ftbsc/lll/tools/PatternMatcher.java
index 161a3fa..a941b72 100644
--- a/src/main/java/ftbsc/lll/tools/PatternMatcher.java
+++ b/src/main/java/ftbsc/lll/tools/PatternMatcher.java
@@ -85,25 +85,25 @@ public class PatternMatcher {
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue;
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue;
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue;
- if(predicates.get(match).test(cur)) {
- match++;
- if(first == null)
- first = cur;
- } else { //reset
- first = null;
- match = 0;
+ if(predicates.get(match) != null) {
+ if(predicates.get(match).test(cur)) {
+ match++;
+ if (first == null)
+ first = cur;
+ } else { //reset
+ first = null;
+ match = 0;
+ }
}
//check if we found the last one
if(match == predicates.size()) {
+ if(match == 0)
+ return new InsnSequence(cur); //match whatever
last = cur;
- break;
+ if(reverse) return new InsnSequence(last, first); //we are matching backwards
+ else return new InsnSequence(first, last);
}
}
- //only return value if we found both a start and an end
- if(first != null && last != null) {
- if(reverse) return new InsnSequence(last, first); //we are matching backwards
- else return new InsnSequence(first, last);
- }
}
throw new PatternNotFoundException("Failed to find pattern!");
}