From: jzhou Date: Sat, 12 Feb 2011 00:40:45 +0000 (+0000) Subject: Make special MGC versions of some library class like HashMap and Vector etc. to avoid... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7dd95dce931810ddaf14f3ad1e64c4d0d18974e6;p=IRC.git Make special MGC versions of some library class like HashMap and Vector etc. to avoid braking compilation of non-MGC build --- diff --git a/Robust/src/ClassLibrary/HashMap.java b/Robust/src/ClassLibrary/HashMap.java index 780159d9..158bb253 100644 --- a/Robust/src/ClassLibrary/HashMap.java +++ b/Robust/src/ClassLibrary/HashMap.java @@ -1,4 +1,4 @@ -public class HashMap implements Map { +public class HashMap{ HashEntry[] table; float loadFactor; int numItems; @@ -56,8 +56,8 @@ public class HashMap implements Map { } /* 0=keys, 1=values */ - public Iterator iterator(int type) { - return (Iterator)(new HashMapIterator(this, type)); + public HashMapIterator iterator(int type) { + return (new HashMapIterator(this, type)); } Object remove(Object key) { diff --git a/Robust/src/ClassLibrary/MGC/HashMap.java b/Robust/src/ClassLibrary/MGC/HashMap.java new file mode 100644 index 00000000..780159d9 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/HashMap.java @@ -0,0 +1,132 @@ +public class HashMap implements Map { + HashEntry[] table; + float loadFactor; + int numItems; + + public HashMap() { + init(16, 0.75f); + } + + public HashMap(int initialCapacity) { + init(initialCapacity, 0.75f); + } + + public HashMap(int initialCapacity, float loadFactor) { + init(initialCapacity, loadFactor); + } + + private void init(int initialCapacity, float loadFactor) { + table=new HashEntry[initialCapacity]; + this.loadFactor=loadFactor; + this.numItems=0; + } + + private static int hash(Object o, int length) { + if (o==null) + return 0; + int value=o.hashCode()%length; + if (value<0) + return -value; + return value; + } + + void resize() { + int newCapacity=2*table.length+1; + HashEntry[] oldtable=table; + this.table=new HashEntry[newCapacity]; + + for(int i=0; i(loadFactor*table.length)) { + //Resize the table + resize(); + } + int bin=hash(key, table.length); + HashEntry ptr=table[bin]; + while(ptr!=null) { + if (ptr.key.equals(key)) { + Object oldvalue=ptr.value; + ptr.value=value; + return oldvalue; + } + ptr=ptr.next; + } + HashEntry he=new HashEntry(); + he.value=value; + he.key=key; + he.next=table[bin]; + table[bin]=he; + return null; + } +} diff --git a/Robust/src/ClassLibrary/MGC/Map.java b/Robust/src/ClassLibrary/MGC/Map.java new file mode 100644 index 00000000..1156a956 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/Map.java @@ -0,0 +1,249 @@ +/* Map.java: interface Map -- An object that maps keys to values + interface Map.Entry -- an Entry in a Map + Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.util; + +/** + * An object that maps keys onto values. Keys cannot be duplicated. This + * interface replaces the obsolete {@link Dictionary} abstract class. + *

+ * + * The map has three collection views, which are backed by the map + * (modifications on one show up on the other): a set of keys, a collection + * of values, and a set of key-value mappings. Some maps have a guaranteed + * order, but not all do. + *

+ * + * Note: Be careful about using mutable keys. Behavior is unspecified if + * a key's comparison behavior is changed after the fact. As a corollary + * to this rule, don't use a Map as one of its own keys or values, as it makes + * hashCode and equals have undefined behavior. + *

+ * + * All maps are recommended to provide a no argument constructor, which builds + * an empty map, and one that accepts a Map parameter and copies the mappings + * (usually by putAll), to create an equivalent map. Unfortunately, Java + * cannot enforce these suggestions. + *

+ * + * The map may be unmodifiable, in which case unsupported operations will + * throw an UnsupportedOperationException. Note that some operations may be + * safe, such as putAll(m) where m is empty, even if the operation would + * normally fail with a non-empty argument. + * + * @author Original author unknown + * @author Eric Blake (ebb9@email.byu.edu) + * @see HashMap + * @see TreeMap + * @see Hashtable + * @see SortedMap + * @see Collection + * @see Set + * @since 1.2 + * @status updated to 1.4 + */ +public interface Map// +{ + /** + * Remove all entries from this Map (optional operation). + * + * @throws UnsupportedOperationException if clear is not supported + */ + //void clear(); + + /** + * Returns true if this contains a mapping for the given key. + * + * @param key the key to search for + * @return true if the map contains the key + * @throws ClassCastException if the key is of an inappropriate type + * @throws NullPointerException if key is null but the map + * does not permit null keys + */ + boolean containsKey(Object key); + + /** + * Returns true if this contains at least one mapping with the given value. + * In other words, returns true if a value v exists where + * (value == null ? v == null : value.equals(v)). This usually + * requires linear time. + * + * @param value the value to search for + * @return true if the map contains the value + * @throws ClassCastException if the type of the value is not a valid type + * for this map. + * @throws NullPointerException if the value is null and the map doesn't + * support null values. + */ + //boolean containsValue(Object value); + + /** + * Returns a set view of the mappings in this Map. Each element in the + * set is a Map.Entry. The set is backed by the map, so that changes in + * one show up in the other. Modifications made while an iterator is + * in progress cause undefined behavior. If the set supports removal, + * these methods remove the underlying mapping from the map: + * Iterator.remove, Set.remove, + * removeAll, retainAll, and clear. + * Element addition, via add or addAll, is + * not supported via this set. + * + * @return the set view of all mapping entries + * @see Map.Entry + */ + //Set> entrySet(); + + /** + * Compares the specified object with this map for equality. Returns + * true if the other object is a Map with the same mappings, + * that is,
+ * o instanceof Map && entrySet().equals(((Map) o).entrySet(); + * This allows comparison of maps, regardless of implementation. + * + * @param o the object to be compared + * @return true if the object equals this map + * @see Set#equals(Object) + */ + //boolean equals(Object o); + + /** + * Returns the value mapped by the given key. Returns null if + * there is no mapping. However, in Maps that accept null values, you + * must rely on containsKey to determine if a mapping exists. + * + * @param key the key to look up + * @return the value associated with the key, or null if key not in map + * @throws ClassCastException if the key is an inappropriate type + * @throws NullPointerException if this map does not accept null keys + * @see #containsKey(Object) + */ + Object get(Object key); + + /** + * Associates the given key to the given value (optional operation). If the + * map already contains the key, its value is replaced. Be aware that in + * a map that permits null values, a null return does not + * always imply that the mapping was created. + * + * @param key the key to map + * @param value the value to be mapped + * @return the previous value of the key, or null if there was no mapping + * @throws UnsupportedOperationException if the operation is not supported + * @throws ClassCastException if the key or value is of the wrong type + * @throws IllegalArgumentException if something about this key or value + * prevents it from existing in this map + * @throws NullPointerException if either the key or the value is null, + * and the map forbids null keys or values + * @see #containsKey(Object) + */ + Object put(Object key, Object value); + + /** + * Returns the hash code for this map. This is the sum of all hashcodes + * for each Map.Entry object in entrySet. This allows comparison of maps, + * regardless of implementation, and satisfies the contract of + * Object.hashCode. + * + * @return the hash code + * @see Map.Entry#hashCode() + */ + //int hashCode(); + + /** + * Returns true if the map contains no mappings. + * + * @return true if the map is empty + */ + boolean isEmpty(); + + /* 0=keys, 1=values */ + public Iterator iterator(int type); + + /** + * Returns a set view of the keys in this Map. The set is backed by the + * map, so that changes in one show up in the other. Modifications made + * while an iterator is in progress cause undefined behavior. If the set + * supports removal, these methods remove the underlying mapping from + * the map: Iterator.remove, Set.remove, + * removeAll, retainAll, and clear. + * Element addition, via add or addAll, is + * not supported via this set. + * + * @return the set view of all keys + */ + //Set keySet(); + + /** + * Copies all entries of the given map to this one (optional operation). If + * the map already contains a key, its value is replaced. + * + * @param m the mapping to load into this map + * @throws UnsupportedOperationException if the operation is not supported + * @throws ClassCastException if a key or value is of the wrong type + * @throws IllegalArgumentException if something about a key or value + * prevents it from existing in this map + * @throws NullPointerException if the map forbids null keys or values, or + * if m is null. + * @see #put(Object, Object) + */ + //void putAll(Map m); + + /** + * Removes the mapping for this key if present (optional operation). If + * the key is not present, this returns null. Note that maps which permit + * null values may also return null if the key was removed. + * + * @param key the key to remove + * @return the value the key mapped to, or null if not present. + * @throws UnsupportedOperationException if deletion is unsupported + * @throws NullPointerException if the key is null and this map doesn't + * support null keys. + * @throws ClassCastException if the type of the key is not a valid type + * for this map. + */ + Object remove(Object o); + + /** + * Returns the number of key-value mappings in the map. If there are more + * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. + * + * @return the number of mappings + */ + int size(); +} diff --git a/Robust/src/ClassLibrary/MGC/Math.java b/Robust/src/ClassLibrary/MGC/Math.java new file mode 100644 index 00000000..878eb0b2 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/Math.java @@ -0,0 +1,138 @@ +public class Math { + + public static double setPI() { + double PI = 3.14159265358979323846; + return PI; + } + + // an alias for setPI() + public static double PI() { + double PI = 3.14159265358979323846; + return PI; + } + + public static int abs(int x) { + if (x < 0) { + return -x; + } else { + return x; + } + } + + public static double fabs(double x) { + if (x < 0) { + return -x; + } else { + return x; + } + } + + public static double abs(double x) { + if (x < 0) { + return -x; + } else { + return x; + } + } + + public static float abs(float a) { + if (a<0) + return -a; + else return a; + } + + public static double max(double a, double b) { + if(a == b) + return a; + if(a > b) { + return a; + } else { + return b; + } + } + + public static int max(int a, int b) { + if(a == b) + return a; + if(a > b) { + return a; + } else { + return b; + } + } + + public static int imax(int a, int b) { + if(a == b) + return a; + if(a > b) { + return a; + } else { + return b; + } + } + + public static int imin(int a, int b) { + if(a == b) + return a; + if(a > b) { + return b; + } else { + return a; + } + } + + /** sqrt(a^2 + b^2) without under/overflow. **/ + public static double hypot(double a, double b) { + double r; + if (fabs(a) > fabs(b)) { + r = b/a; + r = fabs(a)*sqrt(1+r*r); + } else if (b != 0) { + r = a/b; + r = fabs(b)*sqrt(1+r*r); + } else { + r = 0.0; + } + return r; + } + + public static double rint(double x) { + double y = ceil(x); + double d = y - x; + if( d == 0.5 ) { + if( ((int)y)%2 == 0 ) { + return y; + } else { + return y - 1.0; + } + } else if( d < 0.5 ) { + return y; + } + return y - 1.0; + } + + public static native double sin(double a); + public static native double cos(double a); + public static native double asin(double a); + public static native double acos(double a); + public static native double tan(double a); + public static native double atan(double a); + public static native double atan2(double a, double b); + public static native double exp(double a); + public static native double sqrt(double a); + public static native double log(double a); + public static native double pow(double a, double b); + + public static native double ceil(double a); + public static native double floor(double a); + + public static native float sinf(float a); + public static native float cosf(float a); + public static native float expf(float a); + public static native float sqrtf(float a); + public static native float logf(float a); + public static native float powf(float a, float b); + public static native float ceilf(float a); + + public static native float IEEEremainder(float f1, float f2); +} diff --git a/Robust/src/ClassLibrary/MGC/Set.java b/Robust/src/ClassLibrary/MGC/Set.java new file mode 100644 index 00000000..8e59b91f --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/Set.java @@ -0,0 +1,265 @@ +/* Set.java -- A collection that prohibits duplicates + Copyright (C) 1998, 2001, 2004, 2005 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.util; + +/** + * A collection that contains no duplicates. In other words, for two set + * elements e1 and e2, e1.equals(e2) returns false. There + * are additional stipulations on add, equals + * and hashCode, as well as the requirements that constructors + * do not permit duplicate elements. The Set interface is incompatible with + * List; you cannot implement both simultaneously. + *

+ * + * Note: Be careful about using mutable objects in sets. In particular, + * if a mutable object changes to become equal to another set element, you + * have violated the contract. As a special case of this, a Set is not + * allowed to be an element of itself, without risking undefined behavior. + * + * @author Original author unknown + * @author Eric Blake (ebb9@email.byu.edu) + * @see Collection + * @see List + * @see SortedSet + * @see HashSet + * @see TreeSet + * @see LinkedHashSet + * @see AbstractSet + * @see Collections#singleton(Object) + * @see Collections#EMPTY_SET + * @since 1.2 + * @status updated to 1.4 + */ +public interface Set// extends Collection +{ + /** + * Adds the specified element to the set if it is not already present + * (optional operation). In particular, the comparison algorithm is + * o == null ? e == null : o.equals(e). Sets need not permit + * all values, and may document what exceptions will be thrown if + * a value is not permitted. + * + * @param o the object to add + * @return true if the object was not previously in the set + * @throws UnsupportedOperationException if this operation is not allowed + * @throws ClassCastException if the class of o prevents it from being added + * @throws IllegalArgumentException if some aspect of o prevents it from + * being added + * @throws NullPointerException if null is not permitted in this set + */ + boolean add(Object/*E*/ o); + + /** + * Adds all of the elements of the given collection to this set (optional + * operation). If the argument is also a Set, this returns the mathematical + * union of the two. The behavior is unspecified if the set is + * modified while this is taking place. + * + * @param c the collection to add + * @return true if the set changed as a result + * @throws UnsupportedOperationException if this operation is not allowed + * @throws ClassCastException if the class of an element prevents it from + * being added + * @throws IllegalArgumentException if something about an element prevents + * it from being added + * @throws NullPointerException if null is not permitted in this set, or + * if the argument c is null + * @see #add(Object) + */ + //boolean addAll(Collection c); + + /** + * Removes all elements from this set (optional operation). This set will + * be empty afterwords, unless an exception occurs. + * + * @throws UnsupportedOperationException if this operation is not allowed + */ + void clear(); + + /** + * Returns true if the set contains the specified element. In other words, + * this looks for o == null ? e == null : o.equals(e). + * + * @param o the object to look for + * @return true if it is found in the set + * @throws ClassCastException if the type of o is not a valid type + * for this set. + * @throws NullPointerException if o is null and this set doesn't + * support null values. + */ + boolean contains(Object o); + + /** + * Returns true if this set contains all elements in the specified + * collection. If the argument is also a set, this is the subset + * relationship. + * + * @param c the collection to check membership in + * @return true if all elements in this set are in c + * @throws NullPointerException if c is null + * @throws ClassCastException if the type of any element in c is not + * a valid type for this set. + * @throws NullPointerException if some element of c is null and this + * set doesn't support null values. + * @see #contains(Object) + */ + //boolean containsAll(Collection c); + + /** + * Compares the specified object to this for equality. For sets, the object + * must be a set, the two must have the same size, and every element in + * one must be in the other. + * + * @param o the object to compare to + * @return true if it is an equal set + */ + //boolean equals(Object o); + + /** + * Returns the hash code for this set. In order to satisfy the contract of + * equals, this is the sum of the hashcode of all elements in the set. + * + * @return the sum of the hashcodes of all set elements + * @see #equals(Object) + */ + //int hashCode(); + + /** + * Returns true if the set contains no elements. + * + * @return true if the set is empty + */ + boolean isEmpty(); + + /** + * Returns an iterator over the set. The iterator has no specific order, + * unless further specified. + * + * @return a set iterator + */ + //Iterator iterator(); + + /** + * Removes the specified element from this set (optional operation). If + * an element e exists, o == null ? e == null : o.equals(e), + * it is removed from the set. + * + * @param o the object to remove + * @return true if the set changed (an object was removed) + * @throws UnsupportedOperationException if this operation is not allowed + * @throws ClassCastException if the type of o is not a valid type + * for this set. + * @throws NullPointerException if o is null and this set doesn't allow + * the removal of a null value. + */ + boolean remove(Object o); + + /** + * Removes from this set all elements contained in the specified collection + * (optional operation). If the argument is a set, this returns the + * asymmetric set difference of the two sets. + * + * @param c the collection to remove from this set + * @return true if this set changed as a result + * @throws UnsupportedOperationException if this operation is not allowed + * @throws NullPointerException if c is null + * @throws ClassCastException if the type of any element in c is not + * a valid type for this set. + * @throws NullPointerException if some element of c is null and this + * set doesn't support removing null values. + * @see #remove(Object) + */ + //boolean removeAll(Collection c); + + /** + * Retains only the elements in this set that are also in the specified + * collection (optional operation). If the argument is also a set, this + * performs the intersection of the two sets. + * + * @param c the collection to keep + * @return true if this set was modified + * @throws UnsupportedOperationException if this operation is not allowed + * @throws NullPointerException if c is null + * @throws ClassCastException if the type of any element in c is not + * a valid type for this set. + * @throws NullPointerException if some element of c is null and this + * set doesn't support retaining null values. + * @see #remove(Object) + */ + //boolean retainAll(Collection c); + + /** + * Returns the number of elements in the set. If there are more + * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is + * the cardinality of the set. + * + * @return the number of elements + */ + int size(); + + /** + * Returns an array containing the elements of this set. If the set + * makes a guarantee about iteration order, the array has the same + * order. The array is distinct from the set; modifying one does not + * affect the other. + * + * @return an array of this set's elements + * @see #toArray(Object[]) + */ + Object[] toArray(); + + /** + * Returns an array containing the elements of this set, of the same runtime + * type of the argument. If the given set is large enough, it is reused, + * and null is inserted in the first unused slot. Otherwise, reflection + * is used to build a new array. If the set makes a guarantee about iteration + * order, the array has the same order. The array is distinct from the set; + * modifying one does not affect the other. + * + * @param a the array to determine the return type; if it is big enough + * it is used and returned + * @return an array holding the elements of the set + * @throws ArrayStoreException if the runtime type of a is not a supertype + * of all elements in the set + * @throws NullPointerException if a is null + * @see #toArray() + */ + // T[] toArray(T[] a); +} diff --git a/Robust/src/ClassLibrary/MGC/System.java b/Robust/src/ClassLibrary/MGC/System.java new file mode 100644 index 00000000..74a6c66f --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/System.java @@ -0,0 +1,104 @@ +import java.util.Properties; + +public class System { + PrintStream out; + + public System() { + out = new PrintStream("System.out"); + } + + public static void printInt(int x) { + String s=String.valueOf(x); + printString(s); + } + + public static native long currentTimeMillis(); + + public static native long microTimes(); + + public static native long getticks(); + + public static native void printString(String s); + + public static void println(String s) { + System.printString(s+"\n"); + } + + public static void println(Object o) { + System.printString(""+o+"\n"); + } + + public static void println(int o) { + System.printString(""+o+"\n"); + } + + public static void println(double o) { + System.printString(""+o+"\n"); + } + + public static void println(long o) { + System.printString(""+o+"\n"); + } + + public static void println() { + System.printString("\n"); + } + + public static void print(String s) { + System.printString(s); + } + + public static void print(Object o) { + System.printString(""+o); + } + + public static void print(int o) { + System.printString(""+o); + } + + public static void print(double o) { + System.printString(""+o); + } + + public static void print(long o) { + System.printString(""+o); + } + + public static void error() { + System.printString("Error (Use Breakpoint on ___System______error method for more information!)\n"); + } + + public static native void exit(int status); + + public static native void printI(int status); + + public static native void clearPrefetchCache(); + + public static native void rangePrefetch(Object o, short[] offsets); + + public static native void deepArrayCopy(Object dst, Object src); + + public static native void Assert(boolean status); + + /* Only used for microbenchmark testing of SingleTM version */ + public static native void logevent(int event); + public static native void logevent(); + + /* Only used for microbenchmark testing of SingleTM version */ + public static native void initLog(); + + public static native void flushToFile(int threadid); + /* Only used for microbenchmark testing of SingleTM version */ + + public static native void arraycopy(Object src, int srcPos, Object dst, int destPos, int length); + + // for disjoint reachability analysis + public static void genReach(); + + private static Properties props; + private static native Properties initProperties(Properties props); + + public static Properties getProperties() { + return props; + } +} diff --git a/Robust/src/ClassLibrary/MGC/Vector.java b/Robust/src/ClassLibrary/MGC/Vector.java new file mode 100644 index 00000000..5f506edf --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/Vector.java @@ -0,0 +1,157 @@ +public class Vector implements Set { + Object[] array; + int size; + int capacityIncrement; + + public Vector() { + capacityIncrement=0; + size=0; + array=new Object[10]; + } + + public Vector(int size) { + capacityIncrement=0; + this.size=0; + array=new Object[size]; + } + + public boolean isEmpty() { + return size==0; + } + + public void clear() { + size=0; + array=new Object[10]; + } + + public int indexOf(Object elem) { + return indexOf(elem, 0); + } + + public int indexOf(Object elem, int index) { + for(int i=index; i=size) { + System.printString("Illegal Vector.elementAt\n"); + System.exit(-1); + return null; + } + return array[index]; + } + + public void setElementAt(Object obj, int index) { + if (index array.length) { + int newsize; + if (capacityIncrement<=0) + newsize=array.length*2; + else + newsize=array.length+capacityIncrement; + if (newsizesize) { + System.printString("Illegal Vector.insertElementAt\n"); + System.exit(-1); + } + + if (size==array.length) { + ensureCapacity(size+1); + } + size++; + for(int i=size-1; i>index; --i) { + array[i] = array[i-1]; + } + array[index] = obj; + } + + public void removeElementAt(int index) { + if (index<0||index>=size) { + System.printString("Illegal Vector.removeElementAt\n"); + System.exit(-1); + } + removeElement(array, index, size); + size--; + array[size]=null; + } + + public static native void removeElement(Object[] array, int index, int size); + + public void removeAllElements() { + int s = size; + for(int i = 0; i - * - * The map has three collection views, which are backed by the map - * (modifications on one show up on the other): a set of keys, a collection - * of values, and a set of key-value mappings. Some maps have a guaranteed - * order, but not all do. - *

- * - * Note: Be careful about using mutable keys. Behavior is unspecified if - * a key's comparison behavior is changed after the fact. As a corollary - * to this rule, don't use a Map as one of its own keys or values, as it makes - * hashCode and equals have undefined behavior. - *

- * - * All maps are recommended to provide a no argument constructor, which builds - * an empty map, and one that accepts a Map parameter and copies the mappings - * (usually by putAll), to create an equivalent map. Unfortunately, Java - * cannot enforce these suggestions. - *

- * - * The map may be unmodifiable, in which case unsupported operations will - * throw an UnsupportedOperationException. Note that some operations may be - * safe, such as putAll(m) where m is empty, even if the operation would - * normally fail with a non-empty argument. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see HashMap - * @see TreeMap - * @see Hashtable - * @see SortedMap - * @see Collection - * @see Set - * @since 1.2 - * @status updated to 1.4 - */ -public interface Map// -{ - /** - * Remove all entries from this Map (optional operation). - * - * @throws UnsupportedOperationException if clear is not supported - */ - //void clear(); - - /** - * Returns true if this contains a mapping for the given key. - * - * @param key the key to search for - * @return true if the map contains the key - * @throws ClassCastException if the key is of an inappropriate type - * @throws NullPointerException if key is null but the map - * does not permit null keys - */ - boolean containsKey(Object key); - - /** - * Returns true if this contains at least one mapping with the given value. - * In other words, returns true if a value v exists where - * (value == null ? v == null : value.equals(v)). This usually - * requires linear time. - * - * @param value the value to search for - * @return true if the map contains the value - * @throws ClassCastException if the type of the value is not a valid type - * for this map. - * @throws NullPointerException if the value is null and the map doesn't - * support null values. - */ - //boolean containsValue(Object value); - - /** - * Returns a set view of the mappings in this Map. Each element in the - * set is a Map.Entry. The set is backed by the map, so that changes in - * one show up in the other. Modifications made while an iterator is - * in progress cause undefined behavior. If the set supports removal, - * these methods remove the underlying mapping from the map: - * Iterator.remove, Set.remove, - * removeAll, retainAll, and clear. - * Element addition, via add or addAll, is - * not supported via this set. - * - * @return the set view of all mapping entries - * @see Map.Entry - */ - //Set> entrySet(); - - /** - * Compares the specified object with this map for equality. Returns - * true if the other object is a Map with the same mappings, - * that is,
- * o instanceof Map && entrySet().equals(((Map) o).entrySet(); - * This allows comparison of maps, regardless of implementation. - * - * @param o the object to be compared - * @return true if the object equals this map - * @see Set#equals(Object) - */ - //boolean equals(Object o); - - /** - * Returns the value mapped by the given key. Returns null if - * there is no mapping. However, in Maps that accept null values, you - * must rely on containsKey to determine if a mapping exists. - * - * @param key the key to look up - * @return the value associated with the key, or null if key not in map - * @throws ClassCastException if the key is an inappropriate type - * @throws NullPointerException if this map does not accept null keys - * @see #containsKey(Object) - */ - Object get(Object key); - - /** - * Associates the given key to the given value (optional operation). If the - * map already contains the key, its value is replaced. Be aware that in - * a map that permits null values, a null return does not - * always imply that the mapping was created. - * - * @param key the key to map - * @param value the value to be mapped - * @return the previous value of the key, or null if there was no mapping - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if the key or value is of the wrong type - * @throws IllegalArgumentException if something about this key or value - * prevents it from existing in this map - * @throws NullPointerException if either the key or the value is null, - * and the map forbids null keys or values - * @see #containsKey(Object) - */ - Object put(Object key, Object value); - - /** - * Returns the hash code for this map. This is the sum of all hashcodes - * for each Map.Entry object in entrySet. This allows comparison of maps, - * regardless of implementation, and satisfies the contract of - * Object.hashCode. - * - * @return the hash code - * @see Map.Entry#hashCode() - */ - //int hashCode(); - - /** - * Returns true if the map contains no mappings. - * - * @return true if the map is empty - */ - boolean isEmpty(); - - /* 0=keys, 1=values */ - public Iterator iterator(int type); - - /** - * Returns a set view of the keys in this Map. The set is backed by the - * map, so that changes in one show up in the other. Modifications made - * while an iterator is in progress cause undefined behavior. If the set - * supports removal, these methods remove the underlying mapping from - * the map: Iterator.remove, Set.remove, - * removeAll, retainAll, and clear. - * Element addition, via add or addAll, is - * not supported via this set. - * - * @return the set view of all keys - */ - //Set keySet(); - - /** - * Copies all entries of the given map to this one (optional operation). If - * the map already contains a key, its value is replaced. - * - * @param m the mapping to load into this map - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if a key or value is of the wrong type - * @throws IllegalArgumentException if something about a key or value - * prevents it from existing in this map - * @throws NullPointerException if the map forbids null keys or values, or - * if m is null. - * @see #put(Object, Object) - */ - //void putAll(Map m); - - /** - * Removes the mapping for this key if present (optional operation). If - * the key is not present, this returns null. Note that maps which permit - * null values may also return null if the key was removed. - * - * @param key the key to remove - * @return the value the key mapped to, or null if not present. - * @throws UnsupportedOperationException if deletion is unsupported - * @throws NullPointerException if the key is null and this map doesn't - * support null keys. - * @throws ClassCastException if the type of the key is not a valid type - * for this map. - */ - Object remove(Object o); - - /** - * Returns the number of key-value mappings in the map. If there are more - * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. - * - * @return the number of mappings - */ - int size(); -} diff --git a/Robust/src/ClassLibrary/Math.java b/Robust/src/ClassLibrary/Math.java index 878eb0b2..7e6a59f6 100644 --- a/Robust/src/ClassLibrary/Math.java +++ b/Robust/src/ClassLibrary/Math.java @@ -133,6 +133,4 @@ public class Math { public static native float logf(float a); public static native float powf(float a, float b); public static native float ceilf(float a); - - public static native float IEEEremainder(float f1, float f2); } diff --git a/Robust/src/ClassLibrary/Set.java b/Robust/src/ClassLibrary/Set.java deleted file mode 100644 index 8e59b91f..00000000 --- a/Robust/src/ClassLibrary/Set.java +++ /dev/null @@ -1,265 +0,0 @@ -/* Set.java -- A collection that prohibits duplicates - Copyright (C) 1998, 2001, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A collection that contains no duplicates. In other words, for two set - * elements e1 and e2, e1.equals(e2) returns false. There - * are additional stipulations on add, equals - * and hashCode, as well as the requirements that constructors - * do not permit duplicate elements. The Set interface is incompatible with - * List; you cannot implement both simultaneously. - *

- * - * Note: Be careful about using mutable objects in sets. In particular, - * if a mutable object changes to become equal to another set element, you - * have violated the contract. As a special case of this, a Set is not - * allowed to be an element of itself, without risking undefined behavior. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see SortedSet - * @see HashSet - * @see TreeSet - * @see LinkedHashSet - * @see AbstractSet - * @see Collections#singleton(Object) - * @see Collections#EMPTY_SET - * @since 1.2 - * @status updated to 1.4 - */ -public interface Set// extends Collection -{ - /** - * Adds the specified element to the set if it is not already present - * (optional operation). In particular, the comparison algorithm is - * o == null ? e == null : o.equals(e). Sets need not permit - * all values, and may document what exceptions will be thrown if - * a value is not permitted. - * - * @param o the object to add - * @return true if the object was not previously in the set - * @throws UnsupportedOperationException if this operation is not allowed - * @throws ClassCastException if the class of o prevents it from being added - * @throws IllegalArgumentException if some aspect of o prevents it from - * being added - * @throws NullPointerException if null is not permitted in this set - */ - boolean add(Object/*E*/ o); - - /** - * Adds all of the elements of the given collection to this set (optional - * operation). If the argument is also a Set, this returns the mathematical - * union of the two. The behavior is unspecified if the set is - * modified while this is taking place. - * - * @param c the collection to add - * @return true if the set changed as a result - * @throws UnsupportedOperationException if this operation is not allowed - * @throws ClassCastException if the class of an element prevents it from - * being added - * @throws IllegalArgumentException if something about an element prevents - * it from being added - * @throws NullPointerException if null is not permitted in this set, or - * if the argument c is null - * @see #add(Object) - */ - //boolean addAll(Collection c); - - /** - * Removes all elements from this set (optional operation). This set will - * be empty afterwords, unless an exception occurs. - * - * @throws UnsupportedOperationException if this operation is not allowed - */ - void clear(); - - /** - * Returns true if the set contains the specified element. In other words, - * this looks for o == null ? e == null : o.equals(e). - * - * @param o the object to look for - * @return true if it is found in the set - * @throws ClassCastException if the type of o is not a valid type - * for this set. - * @throws NullPointerException if o is null and this set doesn't - * support null values. - */ - boolean contains(Object o); - - /** - * Returns true if this set contains all elements in the specified - * collection. If the argument is also a set, this is the subset - * relationship. - * - * @param c the collection to check membership in - * @return true if all elements in this set are in c - * @throws NullPointerException if c is null - * @throws ClassCastException if the type of any element in c is not - * a valid type for this set. - * @throws NullPointerException if some element of c is null and this - * set doesn't support null values. - * @see #contains(Object) - */ - //boolean containsAll(Collection c); - - /** - * Compares the specified object to this for equality. For sets, the object - * must be a set, the two must have the same size, and every element in - * one must be in the other. - * - * @param o the object to compare to - * @return true if it is an equal set - */ - //boolean equals(Object o); - - /** - * Returns the hash code for this set. In order to satisfy the contract of - * equals, this is the sum of the hashcode of all elements in the set. - * - * @return the sum of the hashcodes of all set elements - * @see #equals(Object) - */ - //int hashCode(); - - /** - * Returns true if the set contains no elements. - * - * @return true if the set is empty - */ - boolean isEmpty(); - - /** - * Returns an iterator over the set. The iterator has no specific order, - * unless further specified. - * - * @return a set iterator - */ - //Iterator iterator(); - - /** - * Removes the specified element from this set (optional operation). If - * an element e exists, o == null ? e == null : o.equals(e), - * it is removed from the set. - * - * @param o the object to remove - * @return true if the set changed (an object was removed) - * @throws UnsupportedOperationException if this operation is not allowed - * @throws ClassCastException if the type of o is not a valid type - * for this set. - * @throws NullPointerException if o is null and this set doesn't allow - * the removal of a null value. - */ - boolean remove(Object o); - - /** - * Removes from this set all elements contained in the specified collection - * (optional operation). If the argument is a set, this returns the - * asymmetric set difference of the two sets. - * - * @param c the collection to remove from this set - * @return true if this set changed as a result - * @throws UnsupportedOperationException if this operation is not allowed - * @throws NullPointerException if c is null - * @throws ClassCastException if the type of any element in c is not - * a valid type for this set. - * @throws NullPointerException if some element of c is null and this - * set doesn't support removing null values. - * @see #remove(Object) - */ - //boolean removeAll(Collection c); - - /** - * Retains only the elements in this set that are also in the specified - * collection (optional operation). If the argument is also a set, this - * performs the intersection of the two sets. - * - * @param c the collection to keep - * @return true if this set was modified - * @throws UnsupportedOperationException if this operation is not allowed - * @throws NullPointerException if c is null - * @throws ClassCastException if the type of any element in c is not - * a valid type for this set. - * @throws NullPointerException if some element of c is null and this - * set doesn't support retaining null values. - * @see #remove(Object) - */ - //boolean retainAll(Collection c); - - /** - * Returns the number of elements in the set. If there are more - * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is - * the cardinality of the set. - * - * @return the number of elements - */ - int size(); - - /** - * Returns an array containing the elements of this set. If the set - * makes a guarantee about iteration order, the array has the same - * order. The array is distinct from the set; modifying one does not - * affect the other. - * - * @return an array of this set's elements - * @see #toArray(Object[]) - */ - Object[] toArray(); - - /** - * Returns an array containing the elements of this set, of the same runtime - * type of the argument. If the given set is large enough, it is reused, - * and null is inserted in the first unused slot. Otherwise, reflection - * is used to build a new array. If the set makes a guarantee about iteration - * order, the array has the same order. The array is distinct from the set; - * modifying one does not affect the other. - * - * @param a the array to determine the return type; if it is big enough - * it is used and returned - * @return an array holding the elements of the set - * @throws ArrayStoreException if the runtime type of a is not a supertype - * of all elements in the set - * @throws NullPointerException if a is null - * @see #toArray() - */ - // T[] toArray(T[] a); -} diff --git a/Robust/src/ClassLibrary/System.java b/Robust/src/ClassLibrary/System.java index 74a6c66f..e36beaee 100644 --- a/Robust/src/ClassLibrary/System.java +++ b/Robust/src/ClassLibrary/System.java @@ -1,12 +1,4 @@ -import java.util.Properties; - -public class System { - PrintStream out; - - public System() { - out = new PrintStream("System.out"); - } - +public class System { public static void printInt(int x) { String s=String.valueOf(x); printString(s); @@ -94,11 +86,4 @@ public class System { // for disjoint reachability analysis public static void genReach(); - - private static Properties props; - private static native Properties initProperties(Properties props); - - public static Properties getProperties() { - return props; - } } diff --git a/Robust/src/ClassLibrary/Vector.java b/Robust/src/ClassLibrary/Vector.java index 5f506edf..42ab24f9 100644 --- a/Robust/src/ClassLibrary/Vector.java +++ b/Robust/src/ClassLibrary/Vector.java @@ -1,4 +1,4 @@ -public class Vector implements Set { +public class Vector { Object[] array; int size; int capacityIncrement; @@ -95,14 +95,6 @@ public class Vector implements Set { } array[size++]=obj; } - - public boolean add(Object obj) { - if (size==array.length) { - ensureCapacity(size+1); - } - array[size++]=obj; - return true; - } public void insertElementAt(Object obj, int index) { if (index<0||index>size) { @@ -138,20 +130,4 @@ public class Vector implements Set { removeElementAt(0); } } - - public Object[] toArray() { - Object[] tarray = new Object[this.size]; - for(int i = 0; i < this.size; i++) { - tarray[i] = this.array[i]; - } - return tarray; - } - - public Vector(Set s) { - Object[] sarray = s.toArray(); - capacityIncrement=0; - this.size=sarray.length; - array=sarray; - } - }