mirror of
https://github.com/zaaarf/lillero.git
synced 2024-11-21 23:14:51 +01:00
fix: failure to restart matcher after failing to find pattern once
This commit is contained in:
parent
592e38066f
commit
30f7660ded
2 changed files with 14 additions and 20 deletions
|
@ -78,30 +78,24 @@ public class PatternMatcher {
|
||||||
*/
|
*/
|
||||||
public InsnSequence find(AbstractInsnNode node) {
|
public InsnSequence find(AbstractInsnNode node) {
|
||||||
if(node != null) {
|
if(node != null) {
|
||||||
int match = 0;
|
AbstractInsnNode first;
|
||||||
AbstractInsnNode first = null;
|
AbstractInsnNode last;
|
||||||
AbstractInsnNode last = null;
|
|
||||||
for(AbstractInsnNode cur = node; cur != null; cur = reverse ? cur.getPrevious() : cur.getNext()) {
|
for(AbstractInsnNode cur = node; cur != null; cur = reverse ? cur.getPrevious() : cur.getNext()) {
|
||||||
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue;
|
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue;
|
||||||
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue;
|
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue;
|
||||||
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue;
|
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue;
|
||||||
if(predicates.get(match) != null) {
|
if(predicates.size() == 0)
|
||||||
if(predicates.get(match).test(cur)) {
|
return new InsnSequence(cur); //match whatever
|
||||||
match++;
|
first = cur;
|
||||||
if (first == null)
|
last = cur;
|
||||||
first = cur;
|
for(int match = 0; match < predicates.size(); match++) {
|
||||||
} else { //reset
|
if(last == null) break;
|
||||||
first = null;
|
if(!predicates.get(match).test(last)) break;
|
||||||
match = 0;
|
if(match == predicates.size() - 1) {
|
||||||
|
if(reverse) return new InsnSequence(last, first); //we are matching backwards
|
||||||
|
else return new InsnSequence(first, last);
|
||||||
}
|
}
|
||||||
}
|
last = reverse ? last.getPrevious() : last.getNext();
|
||||||
//check if we found the last one
|
|
||||||
if(match == predicates.size()) {
|
|
||||||
if(match == 0)
|
|
||||||
return new InsnSequence(cur); //match whatever
|
|
||||||
last = cur;
|
|
||||||
if(reverse) return new InsnSequence(last, first); //we are matching backwards
|
|
||||||
else return new InsnSequence(first, last);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class StackTools implements Opcodes {
|
||||||
public static InsnList instantiate(String name, String desc, InsnList args) {
|
public static InsnList instantiate(String name, String desc, InsnList args) {
|
||||||
InsnSequence list = new InsnSequence();
|
InsnSequence list = new InsnSequence();
|
||||||
list.add(new TypeInsnNode(NEW, name), new InsnNode(DUP));
|
list.add(new TypeInsnNode(NEW, name), new InsnNode(DUP));
|
||||||
if (args != null) list.add(args);
|
if(args != null) list.add(args);
|
||||||
list.add(new MethodInsnNode(INVOKESPECIAL, name, "<init>", desc, false));
|
list.add(new MethodInsnNode(INVOKESPECIAL, name, "<init>", desc, false));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue