Commit [c79177] refactoring Maximize Restore History

Time for a commit to separate the refactoring and master branches. Not

yet done.

Theodore Theodore 2014-05-13

removed src/main/java/com/tbodt/declassify/classfile/bytecode/BytecodeIndexArgument.java
removed src/main/java/com/tbodt/declassify/classfile/bytecode/ConstantPoolIndexArgument.java
removed src/main/java/com/tbodt/declassify/classfile/bytecode/LocalVariableIndexArgument.java
removed src/main/java/com/tbodt/declassify/classfile/bytecode/ShortArgument.java
removed src/main/java/com/tbodt/declassify/classfile/bytecode/TableSwitchArgument.java
removed src/main/java/com/tbodt/declassify/classfile/bytecode/WideBytecodeIndexArgument.java
removed src/main/java/com/tbodt/declassify/classfile/bytecode/ZeroArgument.java
changed src/main/java/com/tbodt/declassify/classfile/bytecode/Bytecode.java
changed src/main/java/com/tbodt/declassify/classfile/bytecode/Opcode.java
changed src/main/java/com/tbodt/declassify/classfile/ClassInfo.java
changed src/main/java/com/tbodt/declassify/classfile/ConstantPool.java
copied src/main/java/com/tbodt/declassify/classfile/bytecode/Argument.java -> src/main/java/com/tbodt/declassify/classfile/bytecode/NopBytecode.java
copied src/main/java/com/tbodt/declassify/classfile/bytecode/ByteArgument.java -> src/main/java/com/tbodt/declassify/classfile/bytecode/ConstBytecode.java
src/main/java/com/tbodt/declassify/classfile/bytecode/Bytecode.java Diff Switch to side-by-side view
Loading...
src/main/java/com/tbodt/declassify/classfile/bytecode/Opcode.java Diff Switch to side-by-side view
Loading...
src/main/java/com/tbodt/declassify/classfile/ClassInfo.java Diff Switch to side-by-side view
Loading...
src/main/java/com/tbodt/declassify/classfile/ConstantPool.java Diff Switch to side-by-side view
Loading...
src/main/java/com/tbodt/declassify/classfile/bytecode/Argument.java to src/main/java/com/tbodt/declassify/classfile/bytecode/NopBytecode.java
--- a/src/main/java/com/tbodt/declassify/classfile/bytecode/Argument.java
+++ b/src/main/java/com/tbodt/declassify/classfile/bytecode/NopBytecode.java
@@ -1,18 +1,7 @@
 /*
- * Copyright (C) 2013 Theodore Dubois
- *
- * This program 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 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
  */
 
 package com.tbodt.declassify.classfile.bytecode;
@@ -25,19 +14,15 @@
  *
  * @author Theodore Dubois
  */
-public abstract class Argument {
-    public static Argument read(Class<? extends Argument> aType, DataInput in, ConstantPool cpool) throws IOException {
-        Argument a = null;
-        try {
-            a = aType.newInstance();
-        } catch (InstantiationException ex) {
-            throw new RuntimeException(ex);
-        } catch (IllegalAccessException ex) {
-            throw new RuntimeException(ex);
-        }
-        a.read(in, cpool);
-        return a;
+public final class NopBytecode extends Bytecode {
+    @Override
+    protected void readHelper(ConstantPool cpool, DataInput in) throws IOException {
+        // nop has no arguments
     }
 
-    protected abstract void read(DataInput in, ConstantPool cpool) throws IOException;
+    @Override
+    public boolean equals(Object obj) {
+        return obj instanceof NopBytecode; // all NopBytecodes are equal
+    }
+
 }
src/main/java/com/tbodt/declassify/classfile/bytecode/ByteArgument.java to src/main/java/com/tbodt/declassify/classfile/bytecode/ConstBytecode.java
--- a/src/main/java/com/tbodt/declassify/classfile/bytecode/ByteArgument.java
+++ b/src/main/java/com/tbodt/declassify/classfile/bytecode/ConstBytecode.java
@@ -1,23 +1,14 @@
 /*
- * Copyright (C) 2013 Theodore Dubois
- *
- * This program 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 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
  */
-
 package com.tbodt.declassify.classfile.bytecode;
 
+import com.tbodt.declassify.classfile.ClassFormatException;
 import com.tbodt.declassify.classfile.ConstantPool;
+import com.tbodt.declassify.source.LiteralExpression;
+import com.tbodt.declassify.source.SourceType;
 import java.io.DataInput;
 import java.io.IOException;
 
@@ -25,41 +16,74 @@
  *
  * @author Theodore Dubois
  */
-public class ByteArgument extends Argument {
-
-    private byte b;
-
-    /**
-     * Get the value of b
-     *
-     * @return the value of b
-     */
-    public byte getB() {
-        return b;
+public final class ConstBytecode extends Bytecode {
+    private LiteralExpression value;
+    
+    @Override
+    protected void readHelper(ConstantPool cpool, DataInput in) throws IOException, ClassFormatException {
+        switch (opcode) {
+            case ACONST_NULL:
+                value = new LiteralExpression(null, new SourceType(Object.class));
+                break;
+            case ICONST_M1:
+                value = new LiteralExpression(-1);
+                break;
+            case ICONST_0:
+                value = new LiteralExpression(0);
+                break;
+            case ICONST_1:
+                value = new LiteralExpression(1);
+                break;
+            case ICONST_2:
+                value = new LiteralExpression(2);
+                break;
+            case ICONST_3:
+                value = new LiteralExpression(3);
+                break;
+            case ICONST_4:
+                value = new LiteralExpression(4);
+                break;
+            case ICONST_5:
+                value = new LiteralExpression(5);
+                break;
+            case LCONST_0:
+                value = new LiteralExpression(0L);
+                break;
+            case LCONST_1:
+                value = new LiteralExpression(1L);
+                break;
+            case FCONST_0:
+                value = new LiteralExpression(0.0F);
+                break;
+            case FCONST_1:
+                value = new LiteralExpression(1.0F);
+                break;
+            case FCONST_2:
+                value = new LiteralExpression(2.0F);
+                break;
+            case DCONST_0:
+                value = new LiteralExpression(0.0);
+                break;
+            case DCONST_1:
+                value = new LiteralExpression(1.0);
+                break;
+            case BIPUSH:
+                value = new LiteralExpression(in.readByte());
+                break;
+            case SIPUSH:
+                value = new LiteralExpression(in.readShort());
+                break;
+            case LDC:
+                int index = in.readUnsignedShort();
+                value = new LiteralExpression(cpool.get(index), null);
+                break;
+            default:
+                throw new AssertionError();
+        }
     }
-
-    @Override
-    protected void read(DataInput in, ConstantPool cpool) throws IOException {
-        b = in.readByte();
+    
+    public LiteralExpression getValue() {
+        return value;
     }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final ByteArgument other = (ByteArgument) obj;
-        if (this.b != other.b)
-            return false;
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        int hash = 5;
-        hash = 17 * hash + this.b;
-        return hash;
-    }
-
+    
 }