Bug fix
authorbdemsky <bdemsky>
Thu, 26 Oct 2006 20:51:41 +0000 (20:51 +0000)
committerbdemsky <bdemsky>
Thu, 26 Oct 2006 20:51:41 +0000 (20:51 +0000)
New test cases
FileLength functionality in File.java

13 files changed:
Robust/src/ClassLibrary/File.java [new file with mode: 0644]
Robust/src/ClassLibrary/FileInputStream.java
Robust/src/ClassLibrary/FileOutputStream.java
Robust/src/ClassLibrary/StringBuffer.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/Main/Main.java
Robust/src/Runtime/file.c
Robust/src/Tests/DoTests
Robust/src/Tests/FileLength.java [new file with mode: 0644]
Robust/src/Tests/WriteFile.java [new file with mode: 0644]
Robust/src/Tests/output/FileLength.output.goal [new file with mode: 0644]
Robust/src/Tests/output/ReadFile.output.goal [new file with mode: 0644]
Robust/src/Tests/output/WriteFile.output.goal [new file with mode: 0644]

diff --git a/Robust/src/ClassLibrary/File.java b/Robust/src/ClassLibrary/File.java
new file mode 100644 (file)
index 0000000..af9ce81
--- /dev/null
@@ -0,0 +1,17 @@
+public class File {
+    String path;
+
+    public File(String path) {
+       this.path=path;
+    }
+
+    String getPath() {
+       return path;
+    }
+
+    long length() {
+       return nativeLength(path.getBytes());
+    }
+
+    private static native long nativeLength(byte[] pathname);
+}
index 0a17f9989256a0e8b801f8428d91b5f3cd060359..2de45c83ef5bc1407d420f2fb3e171f50c8031cf 100644 (file)
@@ -5,6 +5,10 @@ public class FileInputStream {
        fd=nativeOpen(pathname.getBytes());
     }
 
+    public FileInputStream(File path) {
+       fd=nativeOpen(path.getPath().getBytes());
+    }
+
     private static native int nativeOpen(byte[] filename);
     private static native int nativeRead(int fd, byte[] array, int numBytes);
     private static native void nativeClose(int fd);
index eea7eef9bad11ce38fc2384620732b7a0de80689..04c589c3b74dd907e8b245c2b7c63369c9917ae0 100644 (file)
@@ -5,6 +5,10 @@ public class FileOutputStream {
        fd=nativeOpen(pathname.getBytes());
     }
 
+    public FileOutputStream(File path) {
+       fd=nativeOpen(path.getPath().getBytes());
+    }
+
     private static native int nativeOpen(byte[] filename);
     private static native void nativeWrite(int fd, byte[] array);
     private static native void nativeClose(int fd);
index e47a7e1e0bbd87496ae881b6a3d2c9d398997167..b06fd7066132cc2a4dbf6e210bcfe9bef1fd2a50 100644 (file)
@@ -5,7 +5,7 @@ public class StringBuffer {
     //    private static final int DEFAULTSIZE=16;
 
     public StringBuffer(String str) {
-       value=new char[str.value+16];//16 is DEFAULTSIZE
+       value=new char[str.count+16];//16 is DEFAULTSIZE
        count=str.count;
        offset=0;
        for(int i=0;i<count;i++)
index 4502d4c9bc0c6b35203fe7fc6bb1cfcfa44cf271..0ced5626f4f5458054e9d54bd4b6f67b728f45ef 100644 (file)
@@ -63,7 +63,7 @@ public class SemanticCheck {
     public void checkTypeDescriptor(TypeDescriptor td) {
        if (td.isPrimitive())
            return; /* Done */
-       if (td.isClass()) {
+       else if (td.isClass()) {
            String name=td.toString();
            ClassDescriptor field_cd=(ClassDescriptor)state.getClassSymbolTable().get(name);
            if (field_cd==null)
@@ -767,7 +767,7 @@ public class SemanticCheck {
        case Operation.MOD:
            // 5.6.2 Binary Numeric Promotion
            //TODO unboxing of reference objects
-           if (!ltd.isNumber()||!rtd.isNumber())
+           if (ltd.isArray()||rtd.isArray()||!ltd.isNumber()||!rtd.isNumber())
                throw new Error("Error in "+on.printNode(0));
 
            if (ltd.isDouble()||rtd.isDouble())
index 356c45c62c554213cf3a72ba1fe86ef317f2ef28..fbf54b89a8e9f9449bad258b739809b8500adb9b 100644 (file)
@@ -54,6 +54,7 @@ public class Main {
       readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java");
       readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
+      readSourceFile(state, ClassLibraryPrefix+"File.java");
       if (state.TASK) {
          readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
          readSourceFile(state, ClassLibraryPrefix+"Socket.java");
index a295465f19c45a577f6d821e16cf830341bee37c..bee9b96fe280eb8b89772e4a9d141bbb9e0ba257 100644 (file)
@@ -46,3 +46,11 @@ int ___FileInputStream______nativeRead____I__AR_B_I(int fd, struct ArrayObject *
   status=read(fd, string, toread);
   return status;
 }
+
+long long ___File______nativeLength_____AR_B(struct ArrayObject * ao) {
+  int length=ao->___length___;
+  char* filename= (((char *)& ao->___length___)+sizeof(int));
+  struct stat st;
+  stat(filename, &st);
+  return st.st_size;
+}
index 347206db0fc6a0c7699f9542bfa8eb1baec2462a..33233e51cf030342b9e89a6c1fc650a6400f4f31 100755 (executable)
@@ -12,3 +12,6 @@ dotest Test Test.java
 dotest virtualcalltest virtualcalltest.java
 dotest IncTest IncTest.java
 dotest CommandLineTest CommandLineTest.java hello hi
+dotest WriteFile WriteFile.java
+dotest ReadFile ReadFile.java
+dotest FileLength FileLength.java
diff --git a/Robust/src/Tests/FileLength.java b/Robust/src/Tests/FileLength.java
new file mode 100644 (file)
index 0000000..de258cd
--- /dev/null
@@ -0,0 +1,10 @@
+public class FileLength {
+    public static void main(String []str) {
+       String filename="testfile000";
+       File fi=new File(filename);
+       long length=fi.length();
+       String st=String.valueOf((int)length);
+       System.printString(st);
+    }
+
+}
diff --git a/Robust/src/Tests/WriteFile.java b/Robust/src/Tests/WriteFile.java
new file mode 100644 (file)
index 0000000..d31430b
--- /dev/null
@@ -0,0 +1,10 @@
+public class WriteFile {
+    public static void main(String []str) {
+       String filename="testfile000";
+       FileOutputStream fos=new FileOutputStream(filename);
+       String st=new String("adsasdasd");
+       fos.write(st.getBytes());
+       fos.close();
+    }
+
+}
diff --git a/Robust/src/Tests/output/FileLength.output.goal b/Robust/src/Tests/output/FileLength.output.goal
new file mode 100644 (file)
index 0000000..f11c82a
--- /dev/null
@@ -0,0 +1 @@
+9
\ No newline at end of file
diff --git a/Robust/src/Tests/output/ReadFile.output.goal b/Robust/src/Tests/output/ReadFile.output.goal
new file mode 100644 (file)
index 0000000..107d5f9
--- /dev/null
@@ -0,0 +1 @@
+adsasdasd
\ No newline at end of file
diff --git a/Robust/src/Tests/output/WriteFile.output.goal b/Robust/src/Tests/output/WriteFile.output.goal
new file mode 100644 (file)
index 0000000..e69de29