mirror of
https://github.com/zaaarf/lillero.git
synced 2024-11-10 01:29:22 +01:00
fix: added empty predicates edge case to find function, and single-instruction constructor to InsnSequence
This commit is contained in:
parent
3185d840c4
commit
c9ea715ba1
2 changed files with 23 additions and 13 deletions
|
@ -19,6 +19,16 @@ public class InsnSequence extends InsnList {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Public constructor.
|
||||||
* Must be given two non-null, connected nodes.
|
* Must be given two non-null, connected nodes.
|
||||||
|
|
|
@ -85,25 +85,25 @@ public class PatternMatcher {
|
||||||
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).test(cur)) {
|
if(predicates.get(match) != null) {
|
||||||
match++;
|
if(predicates.get(match).test(cur)) {
|
||||||
if(first == null)
|
match++;
|
||||||
first = cur;
|
if (first == null)
|
||||||
} else { //reset
|
first = cur;
|
||||||
first = null;
|
} else { //reset
|
||||||
match = 0;
|
first = null;
|
||||||
|
match = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//check if we found the last one
|
//check if we found the last one
|
||||||
if(match == predicates.size()) {
|
if(match == predicates.size()) {
|
||||||
|
if(match == 0)
|
||||||
|
return new InsnSequence(cur); //match whatever
|
||||||
last = cur;
|
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!");
|
throw new PatternNotFoundException("Failed to find pattern!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue