package sds.decompile;

import java.util.Stack;

/**
 * This adapter class is for
 * {@link LocalStack <code>LocalStack</code>}
 * and
 * {@link OperandStack <code>OperandStack</code>}.
 */
public abstract class SimpleStack {
	Stack<String> stack;
	Stack<String> type;

	/**
	 * constructor.
	 */
	public SimpleStack() {
		this.stack = new Stack<>();
		this.type = new Stack<>();
	}

	/**
	 * push element and type onto each stack.
	 * @param element
	 * @param type 
	 */
	public void push(String element, String type) {
		if(element == null) {
			throw new IllegalArgumentException("argument is null.");
		}
		if(type == null) {
			throw new IllegalArgumentException("type is null");
		}
		stack.push(element);
		this.type.push(type);
	}

	/**
	 * returns top element of type stack.
	 * @return top element
	 */
	public String popType() {
		if(type.empty()) {
			throw new IllegalStateException("type stack is empty.");
		}
		return type.pop();
	}

	/**
	 * return top element of stack.
	 * @param popType whether pop type stack
	 * @return top element
	 */
	public String pop(boolean popType) {
		if(popType) {
			type.pop();
		}
		return pop();
	}

	/**
	 * returns top element of stack.
	 * @return top element
	 */
	public String pop() {
		if(stack.empty()) {
			throw new IllegalStateException("stack is empty.");
		}
		String element = stack.pop();
		return element;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("stack: ").append(stack).append("\n")
			.append("type : ").append(type);
		return sb.toString();
	}
}
@@ -1324,54 +1324,26 @@
 %7D%0A%09%09
-String element = stack.pop();%0A%09%09return element
+return stack.pop()
 ;%0A%09%7D
@@ -1426,29 +1426,121 @@
 der(
+%22%5B%22
 );%0A%09%09
-sb.append(%22stack
+if(stack.size() %3E 0) %7B%0A%09%09%09for(int i = 0; i %3C stack.size() - 1; i++) %7B%0A%09%09%09%09sb.append(type.get(i)).append(%22
 : %22)
@@ -1552,16 +1552,23 @@
 nd(stack
+.get(i)
 ).append
@@ -1573,24 +1573,32 @@
 nd(%22
-%5Cn
+, 
 %22)
+;
 %0A%09%09%09
+%7D%0A%09%09%09sb
 .append(
 %22typ
@@ -1597,33 +1597,89 @@
 end(
-%22
 type
- : %22).append(type
+.get(type.size() - 1)).append(%22: %22).append(stack.get(stack.size() - 1)
 );%0A
+%09%09%7D%0A
 %09%09re
@@ -1686,16 +1686,28 @@
 turn sb.
+append(%22%5D%22).
 toString

delete unnecessary storing to val, and modify toString.