From: jzhou Date: Sat, 12 Mar 2011 00:40:03 +0000 (+0000) Subject: Fix bug in Class Library X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a8b478aad142a517835b99b8ff981af3588fe340;p=IRC.git Fix bug in Class Library --- diff --git a/Robust/src/ClassLibrary/Character.java b/Robust/src/ClassLibrary/Character.java index 85406ad8..ab3f3b6a 100644 --- a/Robust/src/ClassLibrary/Character.java +++ b/Robust/src/ClassLibrary/Character.java @@ -54,4 +54,20 @@ public class Character { } return returnValue; } + + public static final int MIN_RADIX = 2; + public static final int MAX_RADIX = 36; + + public static char forDigit(int digit, int radix) { + if ((digit >= radix) || (digit < 0)) { + return '\0'; + } + if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) { + return '\0'; + } + if (digit < 10) { + return (char)('0' + digit); + } + return (char)('a' - 10 + digit); +} } diff --git a/Robust/src/ClassLibrary/MGC/gnu/BigDecimal.java b/Robust/src/ClassLibrary/MGC/gnu/BigDecimal.java index 4e169ba1..e5d87c5b 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/BigDecimal.java +++ b/Robust/src/ClassLibrary/MGC/gnu/BigDecimal.java @@ -1061,7 +1061,7 @@ public class BigDecimal //extends Number implements Comparable * as inserted after the first digit, the character 'E' is appended * and adjExp is appended. */ - /*public String toString() + public String toString() { // bigStr is the String representation of the unscaled value. If // scale is zero we simply return this. @@ -1072,7 +1072,7 @@ public class BigDecimal //extends Number implements Comparable boolean negative = (bigStr.charAt(0) == '-'); int point = bigStr.length() - scale - (negative ? 1 : 0); - CPStringBuilder val = new CPStringBuilder(); + /*CP*/StringBuilder val = new /*CP*/StringBuilder(); if (scale >= 0 && (point - 1) >= -6) { @@ -1115,7 +1115,7 @@ public class BigDecimal //extends Number implements Comparable val.append( point - 1 ); } return val.toString(); - }*/ + } /** * Returns the String representation of this BigDecimal, using engineering diff --git a/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java b/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java index c61d4895..03fab683 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java +++ b/Robust/src/ClassLibrary/MGC/gnu/BigInteger.java @@ -1759,12 +1759,12 @@ public class BigInteger //extends Number implements Comparable return shift(this, -n); } - /*private void format(int radix, CPStringBuilder buffer) + private void format(int radix, /*CP*/StringBuilder buffer) { if (words == null) - buffer.append(Integer.toString(ival, radix)); + buffer.append(Integer.toString(ival/*, radix*/)); else if (ival <= 2) - buffer.append(Long.toString(longValue(), radix)); + buffer.append(Long.toString(longValue()/*, radix*/)); else { boolean neg = isNegative(); @@ -1819,27 +1819,27 @@ public class BigInteger //extends Number implements Comparable } } } - }*/ + } - /*public String toString() + public String toString() { return toString(10); - }*/ + } - /*public String toString(int radix) + public String toString(int radix) { - if (USING_NATIVE) - return mpz.toString(radix); + /*if (USING_NATIVE) + return mpz.toString(radix);*/ if (words == null) - return Integer.toString(ival, radix); + return Integer.toString(ival/*, radix*/); if (ival <= 2) - return Long.toString(longValue(), radix); + return Long.toString(longValue()/*, radix*/); int buf_size = ival * (MPN.chars_per_word(radix) + 1); - CPStringBuilder buffer = new CPStringBuilder(buf_size); + /*CP*/StringBuilder buffer = new /*CP*/StringBuilder(buf_size); format(radix, buffer); return buffer.toString(); - }*/ + } public int intValue() { diff --git a/Robust/src/ClassLibrary/MGC/gnu/Float.java b/Robust/src/ClassLibrary/MGC/gnu/Float.java index 21d7e4d9..12515b7f 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Float.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Float.java @@ -355,8 +355,7 @@ public final class Float public static float parseFloat(String str) { //return VMFloat.parseFloat(str); - System.println("Float.parseFloat(String) invoked"); - return 1.0f; + return (float)Double.parseDouble(str); } /** diff --git a/Robust/src/ClassLibrary/MGC/gnu/StringBuilder.java b/Robust/src/ClassLibrary/MGC/gnu/StringBuilder.java index 799551c3..a5f4da9c 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/StringBuilder.java +++ b/Robust/src/ClassLibrary/MGC/gnu/StringBuilder.java @@ -376,5 +376,56 @@ public final class StringBuilder { return new String(this.value, 0, this.count); } + + /** + * Get the character at the specified index. + * + * @param index the index of the character to get, starting at 0 + * @return the character at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * (while unspecified, this is a StringIndexOutOfBoundsException) + */ + public char charAt(int index) + { + if (index < 0 || index >= count) + throw new /*StringIndexOutOfBounds*/Exception("StringIndexOutOfBounds " + index); + return value[index]; + } + + /** + * Set the character at the specified index. + * + * @param index the index of the character to set starting at 0 + * @param ch the value to set that character to + * @throws IndexOutOfBoundsException if index is negative or >= length() + * (while unspecified, this is a StringIndexOutOfBoundsException) + */ + public void setCharAt(int index, char ch) + { + if (index < 0 || index >= count) + throw new /*StringIndexOutOfBounds*/Exception("StringIndexOutOfBounds " + index); + // Call ensureCapacity to enforce copy-on-write. + ensureCapacity_unsynchronized(count); + value[index] = ch; + } + + /** + * Insert the char argument into this StringBuffer. + * + * @param offset the place to insert in this buffer + * @param ch the char to insert + * @return this StringBuffer + * @throws StringIndexOutOfBoundsException if offset is out of bounds + */ + public StringBuffer insert(int offset, char ch) + { + if (offset < 0 || offset > count) + throw new /*StringIndexOutOfBounds*/Exception("StringIndexOutOfBounds " + offset); + ensureCapacity_unsynchronized(count + 1); + System.arraycopy(value, offset, value, offset + 1, count - offset); + value[offset] = ch; + count++; + return this; + } } diff --git a/Robust/src/ClassLibrary/gnu/Double.java b/Robust/src/ClassLibrary/gnu/Double.java index ea5c9334..7f2feac1 100644 --- a/Robust/src/ClassLibrary/gnu/Double.java +++ b/Robust/src/ClassLibrary/gnu/Double.java @@ -475,7 +475,7 @@ public final class Double extends Number //implements Comparable if (isNaN(value)) return 0x7ff8000000000000L; else - return 0; //VMDouble.doubleToRawLongBits(value); + return /*VMDouble.*/doubleToRawLongBits(value); } /** @@ -492,10 +492,11 @@ public final class Double extends Number //implements Comparable * @return the bits of the double * @see #longBitsToDouble(long) */ - public static long doubleToRawLongBits(double value) + /*public static long doubleToRawLongBits(double value) { - return 0; //VMDouble.doubleToRawLongBits(value); - } + return VMDouble.doubleToRawLongBits(value); + }*/ + public static native long doubleToRawLongBits(double value); /** * Convert the argument in IEEE 754 floating-point "double format" bit @@ -510,10 +511,11 @@ public final class Double extends Number //implements Comparable * @see #doubleToLongBits(double) * @see #doubleToRawLongBits(double) */ - public static double longBitsToDouble(long bits) + /*public static double longBitsToDouble(long bits) { - return 0.0; //VMDouble.longBitsToDouble(bits); - } + return VMDouble.longBitsToDouble(bits); + }*/ + public static native double longBitsToDouble(long bits); /** * Compare two Doubles numerically by comparing their double diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index d12cc8ad..9f683f77 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1738,7 +1738,7 @@ public class BuildCode { generateMethodParam(cn, md, output); - if(md.isInvokedByStatic()) { + if(md.isInvokedByStatic() && !md.isStaticBlock() && !md.getModifiers().isNative()) { // generate the staticinit version String mdstring = md.getSafeMethodDescriptor() + "staticinit"; @@ -1919,7 +1919,7 @@ public class BuildCode { ClassDescriptor cn=md!=null ? md.getClassDesc() : null; ParamsObject objectparams=(ParamsObject)paramstable.get(md!=null ? md : task); - if((md != null) && md.isInvokedByStatic() && !md.isStaticBlock()) { + if((md != null) && md.isInvokedByStatic() && !md.isStaticBlock() && !md.getModifiers().isNative()) { // generate a special static init version mgcstaticinit = true; String mdstring = md.getSafeMethodDescriptor() + "staticinit"; @@ -2416,7 +2416,7 @@ public class BuildCode { ParamsObject objectparams=(ParamsObject)paramstable.get(md); ClassDescriptor cn=md.getClassDesc(); String mdstring = md.getSafeMethodDescriptor(); - if(mgcstaticinit && !md.getModifiers().isNative()) { + if(mgcstaticinit && !md.isStaticBlock() && !md.getModifiers().isNative()) { mdstring += "staticinit"; } @@ -2659,7 +2659,7 @@ public class BuildCode { if(fsfn.getField().isStatic()) { // static field - if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic()/* && mgcstaticinit*/)) { + if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { // is a static block or is invoked in some static block ClassDescriptor cd = fm.getMethod().getClassDesc(); ClassDescriptor cn = fsfn.getDst().getType().getClassDesc(); @@ -2896,7 +2896,7 @@ public class BuildCode { //catch the constructor case output.print("void "); if (md!=null) { - if(mgcstaticinit) { + if(mgcstaticinit && !md.isStaticBlock() && !md.getModifiers().isNative()) { mdstring += "staticinit"; } output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+mdstring+"("); diff --git a/Robust/src/Runtime/bamboo/multicoreruntime.c b/Robust/src/Runtime/bamboo/multicoreruntime.c index d1ee9875..359cad91 100644 --- a/Robust/src/Runtime/bamboo/multicoreruntime.c +++ b/Robust/src/Runtime/bamboo/multicoreruntime.c @@ -116,6 +116,52 @@ double CALL23(___Double______nativeparsedouble_____AR_B_I_I, int start, int leng } #endif +typedef union jvalue +{ + bool z; + char c; + short s; + int i; + long long j; + float f; + double d; +} jvalue; + +#ifdef D___Double______doubleToRawLongBits____D +long long CALL11(___Double______doubleToRawLongBits____D, double dval, double dval) { + jvalue val; + val.d = dval; + +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) + /* On little endian ARM processors when using FPA, word order of + doubles is still big endian. So take that into account here. When + using VFP, word order of doubles follows byte order. */ + +#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff)) + + val.j = SWAP_DOUBLE(val.j); +#endif + + return val.j; +} +#endif + +#ifdef D___Double______longBitsToDouble____J +double CALL11(___Double______longBitsToDouble____J, long long lval, long long lval) { + jvalue val; + val.j = lval; + +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) +#ifndef SWAP_DOUBLE +#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff)) +#endif + val.j = SWAP_DOUBLE(val.j); +#endif + + return val.d; +} +#endif + #ifdef D___String______convertdoubletochar____D__AR_C int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject * ___chararray___) { int length=VAR(___chararray___)->___length___; diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 8cf71847..e0129f85 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -173,6 +173,52 @@ double CALL23(___Double______nativeparsedouble_____AR_B_I_I, int start, int leng } #endif +#ifdef D___Double______doubleToRawLongBits____D +typedef union jvalue +{ + bool z; + char c; + short s; + int i; + long long j; + float f; + double d; +} jvalue; + +long long CALL11(___Double______doubleToRawLongBits____D, double dval, double dval) { + jvalue val; + val.d = dval; + +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) + /* On little endian ARM processors when using FPA, word order of + doubles is still big endian. So take that into account here. When + using VFP, word order of doubles follows byte order. */ + +#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff)) + + val.j = SWAP_DOUBLE(val.j); +#endif + + return val.j; +} +#endif + +#ifdef D___Double______longBitsToDouble____J +double CALL11(___Double______longBitsToDouble____J, long long lval, long long lval) { + jvalue val; + val.j = lval; + +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) +#ifndef SWAP_DOUBLE +#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff)) +#endif + val.j = SWAP_DOUBLE(val.j); +#endif + + return val.d; +} +#endif + #ifdef D___String______convertdoubletochar____D__AR_C int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) { int length=VAR(___chararray___)->___length___;