private static int selectStrOpcode(final int strLength, final boolean ignoreCase) { int op; if (ignoreCase) { switch(strLength) { case 1: op = OPCode.EXACT1_IC; break; default:op = OPCode.EXACTN_IC; break; } // switch } else { switch (strLength) { case 1: op = OPCode.EXACT1; break; case 2: op = OPCode.EXACT2; break; case 3: op = OPCode.EXACT3; break; case 4: op = OPCode.EXACT4; break; case 5: op = OPCode.EXACT5; break; default:op = OPCode.EXACTN; break; } // inner switch } return op; }
@Override protected void compileBackrefNode(final BackRefNode node) { if (isIgnoreCase(regex.options)) { addOpcode(OPCode.BACKREFN_IC); addMemNum(node.backRef); } else { switch (node.backRef) { case 1: addOpcode(OPCode.BACKREF1); break; case 2: addOpcode(OPCode.BACKREF2); break; default: addOpcode(OPCode.BACKREFN); addOpcode(node.backRef); break; } // switch } }
private void compileRangeRepeatNode(final QuantifierNode qn, final int targetLen, final int emptyInfo) { final int numRepeat = regex.numRepeat; addOpcode(qn.greedy ? OPCode.REPEAT : OPCode.REPEAT_NG); addMemNum(numRepeat); /* OP_REPEAT ID */ regex.numRepeat++; addRelAddr(targetLen + OPSize.REPEAT_INC); entryRepeatRange(numRepeat, qn.lower, qn.upper); compileTreeEmptyCheck(qn.target, emptyInfo); if (qn.isInRepeat()) { addOpcode(qn.greedy ? OPCode.REPEAT_INC_SG : OPCode.REPEAT_INC_NG_SG); } else { addOpcode(qn.greedy ? OPCode.REPEAT_INC : OPCode.REPEAT_INC_NG); } addMemNum(numRepeat); /* OP_REPEAT ID */ }
@Override protected void compileOptionNode(final EncloseNode node) { final int prev = regex.options; if (isDynamic(prev ^ node.option)) { addOpcodeOption(OPCode.SET_OPTION_PUSH, node.option); addOpcodeOption(OPCode.SET_OPTION, prev); addOpcode(OPCode.FAIL); } regex.options = node.option; compileTree(node.target); regex.options = prev; if (isDynamic(prev ^ node.option)) { addOpcodeOption(OPCode.SET_OPTION, prev); } }
private void nullCheckFound() { // null_check_found: /* empty loop founded, skip next instruction */ switch(code[ip++]) { case OPCode.JUMP: case OPCode.PUSH: ip++; // p += SIZE_RELADDR; break; case OPCode.REPEAT_INC: case OPCode.REPEAT_INC_NG: case OPCode.REPEAT_INC_SG: case OPCode.REPEAT_INC_NG_SG: ip++; // p += SIZE_MEMNUM; break; default: throw new InternalException(ErrorMessages.ERR_UNEXPECTED_BYTECODE); } // switch }
private void compileTreeEmptyCheck(final Node node, final int emptyInfo) { final int savedNumNullCheck = regex.numNullCheck; if (emptyInfo != 0) { addOpcode(OPCode.NULL_CHECK_START); addMemNum(regex.numNullCheck); /* NULL CHECK ID */ regex.numNullCheck++; } compileTree(node); if (emptyInfo != 0) { switch (emptyInfo) { case TargetInfo.IS_EMPTY: addOpcode(OPCode.NULL_CHECK_END); break; case TargetInfo.IS_EMPTY_MEM: addOpcode(OPCode.NULL_CHECK_END_MEMST); break; default: break; } // switch addMemNum(savedNumNullCheck); /* NULL CHECK ID */ } }