Fixes some bugs

This commit is contained in:
konsoletyper 2014-06-28 00:03:12 +04:00
parent b21e1b4dd5
commit 084de3374e
5 changed files with 42 additions and 40 deletions

View File

@ -99,6 +99,7 @@
<argument>java.lang.annotation</argument> <argument>java.lang.annotation</argument>
<argument>java.lang.reflect</argument> <argument>java.lang.reflect</argument>
<argument>java.io</argument> <argument>java.io</argument>
<argument>java.math</argument>
<argument>java.net</argument> <argument>java.net</argument>
<argument>java.text</argument> <argument>java.text</argument>
<argument>java.util</argument> <argument>java.util</argument>

View File

@ -26,48 +26,41 @@ import java.util.Random;
class TPrimality { class TPrimality {
/** Just to denote that this class can't be instantiated. */ /** Just to denote that this class can't be instantiated. */
private TPrimality() {} private TPrimality() {
}
/** All prime numbers with bit length lesser than 10 bits. */ /** All prime numbers with bit length lesser than 10 bits. */
private static final int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, private static final int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571,
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853,
479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,
571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 1009, 1013, 1019, 1021 };
647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,
827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009,
1013, 1019, 1021 };
/** All {@code BigInteger} prime numbers with bit length lesser than 8 bits. */ /** All {@code BigInteger} prime numbers with bit length lesser than 8 bits. */
private static final TBigInteger BIprimes[] = new TBigInteger[primes.length]; private static final TBigInteger BIprimes[] = new TBigInteger[primes.length];
/** /**
* It encodes how many iterations of Miller-Rabin test are need to get an * It encodes how many iterations of Miller-Rabin test are need to get an
* error bound not greater than {@code 2<sup>(-100)</sup>}. For example: * error bound not greater than {@code 2<sup>(-100)</sup>}. For example: for
* for a {@code 1000}-bit number we need {@code 4} iterations, since * a {@code 1000}-bit number we need {@code 4} iterations, since
* {@code BITS[3] < 1000 <= BITS[4]}. * {@code BITS[3] < 1000 <= BITS[4]}.
*/ */
private static final int[] BITS = { 0, 0, 1854, 1233, 927, 747, 627, 543, private static final int[] BITS = { 0, 0, 1854, 1233, 927, 747, 627, 543, 480, 431, 393, 361, 335, 314, 295, 279,
480, 431, 393, 361, 335, 314, 295, 279, 265, 253, 242, 232, 223, 265, 253, 242, 232, 223, 216, 181, 169, 158, 150, 145, 140, 136, 132, 127, 123, 119, 114, 110, 105, 101,
216, 181, 169, 158, 150, 145, 140, 136, 132, 127, 123, 119, 114, 96, 92, 87, 83, 78, 73, 69, 64, 59, 54, 49, 44, 38, 32, 26, 1 };
110, 105, 101, 96, 92, 87, 83, 78, 73, 69, 64, 59, 54, 49, 44, 38,
32, 26, 1 };
/** /**
* It encodes how many i-bit primes there are in the table for * It encodes how many i-bit primes there are in the table for
* {@code i=2,...,10}. For example {@code offsetPrimes[6]} says that from * {@code i=2,...,10}. For example {@code offsetPrimes[6]} says that from
* index {@code 11} exists {@code 7} consecutive {@code 6}-bit prime * index {@code 11} exists {@code 7} consecutive {@code 6}-bit prime numbers
* numbers in the array. * in the array.
*/ */
private static final int[][] offsetPrimes = { null, null, { 0, 2 }, private static final int[][] offsetPrimes = { null, null, { 0, 2 }, { 2, 2 }, { 4, 2 }, { 6, 5 }, { 11, 7 },
{ 2, 2 }, { 4, 2 }, { 6, 5 }, { 11, 7 }, { 18, 13 }, { 31, 23 }, { 18, 13 }, { 31, 23 }, { 54, 43 }, { 97, 75 } };
{ 54, 43 }, { 97, 75 } };
static {// To initialize the dual table of BigInteger primes static {// To initialize the dual table of BigInteger primes
for (int i = 0; i < primes.length; i++) { for (int i = 0; i < primes.length; i++) {
@ -94,19 +87,17 @@ class TPrimality {
TBigInteger startPoint; TBigInteger startPoint;
TBigInteger probPrime; TBigInteger probPrime;
// If n < "last prime of table" searches next prime in the table // If n < "last prime of table" searches next prime in the table
if ((n.numberLength == 1) && (n.digits[0] >= 0) if ((n.numberLength == 1) && (n.digits[0] >= 0) && (n.digits[0] < primes[primes.length - 1])) {
&& (n.digits[0] < primes[primes.length - 1])) {
for (i = 0; n.digits[0] >= primes[i]; i++) { for (i = 0; n.digits[0] >= primes[i]; i++) {
// do nothing // do nothing
} }
return BIprimes[i]; return BIprimes[i];
} }
/* /*
* Creates a "N" enough big to hold the next probable prime Note that: N < * Creates a "N" enough big to hold the next probable prime Note that: N
* "next prime" < 2*N * < "next prime" < 2*N
*/ */
startPoint = new TBigInteger(1, n.numberLength, startPoint = new TBigInteger(1, n.numberLength, new int[n.numberLength + 1]);
new int[n.numberLength + 1]);
System.arraycopy(n.digits, 0, startPoint.digits, 0, n.numberLength); System.arraycopy(n.digits, 0, startPoint.digits, 0, n.numberLength);
// To fix N to the "next odd number" // To fix N to the "next odd number"
if (n.testBit(0)) { if (n.testBit(0)) {
@ -204,8 +195,7 @@ class TPrimality {
} }
// To check if 'n' is divisible by some prime of the table // To check if 'n' is divisible by some prime of the table
for (int i = 1; i < primes.length; i++) { for (int i = 1; i < primes.length; i++) {
if (TDivision.remainderArrayByInt(n.digits, n.numberLength, if (TDivision.remainderArrayByInt(n.digits, n.numberLength, primes[i]) == 0) {
primes[i]) == 0) {
return false; return false;
} }
} }
@ -224,8 +214,10 @@ class TPrimality {
/** /**
* The Miller-Rabin primality test. * The Miller-Rabin primality test.
* *
* @param n the input number to be tested. * @param n
* @param t the number of trials. * the input number to be tested.
* @param t
* the number of trials.
* @return {@code false} if the number is definitely compose, otherwise * @return {@code false} if the number is definitely compose, otherwise
* {@code true} with probability {@code 1 - 4<sup>(-t)</sup>}. * {@code true} with probability {@code 1 - 4<sup>(-t)</sup>}.
* @ar.org.fitc.ref "D. Knuth, The Art of Computer Programming Vo.2, Section * @ar.org.fitc.ref "D. Knuth, The Art of Computer Programming Vo.2, Section
@ -253,8 +245,7 @@ class TPrimality {
*/ */
do { do {
x = new TBigInteger(bitLength, rnd); x = new TBigInteger(bitLength, rnd);
} while ((x.compareTo(n) >= TBigInteger.EQUALS) || (x.sign == 0) } while ((x.compareTo(n) >= TBigInteger.EQUALS) || (x.sign == 0) || x.isOne());
|| x.isOne());
} }
y = x.modPow(q, n); y = x.modPow(q, n);
if (y.isOne() || y.equals(n_minus_1)) { if (y.isOne() || y.equals(n_minus_1)) {

View File

@ -35,7 +35,7 @@ public class TRandom extends TObject implements TSerializable {
} }
protected int next(int bits) { protected int next(int bits) {
return (int)(random() * (1 << TMath.min(32, bits))); return (int)(random() * (1L << TMath.min(32, bits)));
} }
public void nextBytes(byte[] bytes) { public void nextBytes(byte[] bytes) {

View File

@ -37,6 +37,9 @@ class BreakToContinueReplacer implements StatementVisitor {
} }
public void visitSequence(List<Statement> statements) { public void visitSequence(List<Statement> statements) {
if (statements == null) {
return;
}
for (int i = 0; i < statements.size(); ++i) { for (int i = 0; i < statements.size(); ++i) {
Statement stmt = statements.get(i); Statement stmt = statements.get(i);
stmt.acceptVisitor(this); stmt.acceptVisitor(this);

View File

@ -199,8 +199,15 @@ public class Decompiler {
for (int i = 0; i < this.graph.size(); ++i) { for (int i = 0; i < this.graph.size(); ++i) {
Block block = stack.peek(); Block block = stack.peek();
while (block.end == i) { while (block.end == i) {
Block oldBlock = block;
stack.pop(); stack.pop();
block = stack.peek(); block = stack.peek();
if (block.start >= 0) {
int mappedStart = indexer.nodeAt(block.start);
if (blockMap[mappedStart] == oldBlock) {
blockMap[mappedStart] = block;
}
}
} }
while (parentNode.getEnd() == i) { while (parentNode.getEnd() == i) {
currentNode = parentNode.getNext(); currentNode = parentNode.getNext();