Commits

Ivan Vendrov committed 2078ed7

added dynamic I/O and fixed various bugs

Comments (0)

Files changed (7)

src/ca/usask/cs/giraffe/compiler/DictEnvironment.java

 	public DictEnvironment(Environment parent) {
 		this.parent = parent;
 		this.bindings = new LinkedHashMap<String,Value>();
-		this.types = new LinkedHashMap<String,Type>();
-		
-		// add endl as a global variable
-		this.bindings.put("endl", new CharValue('\n'));
-		this.types.put("endl", new Type(TypeTree.Primitive.CHAR));
+		this.types = new LinkedHashMap<String,Type>();		
 	}
 	
 	/**
 		this.parent = null;
 		this.bindings = new LinkedHashMap<String,Value>();
 		this.types = new LinkedHashMap<String,Type>();
+		
+		// add endl as a global variable
+		this.bindings.put("endl", new CharValue('\n'));
+		this.types.put("endl", new Type(TypeTree.Primitive.CHAR));
 	}
 	
 	@Override

src/ca/usask/cs/giraffe/compiler/anim/ConcreteAnimationStrip.java

 				animations.add(ad);
 				break;
 			case MULTI:
-				// get animations from all the deltaDescriptors
+				// get animations from all the deltaDescriptors				
 				for (DeltaDescriptor dd : del.multi_deltaList()) {
 					UpdateDescriptor ud = deltaToAnimation(dd);
 					animations.addAll(ud.animations());
 				}
+				break;
 			case INPUT:
+				IODescriptor io = new IODescriptor(true, true, del.input_str());
+				return new UpdateDescriptor(animations, highDescriptor,  io);
 			case OUTPUT:
-				break;
+				io = new IODescriptor(true, false, del.output_str());
+				return new UpdateDescriptor(animations, highDescriptor,  io);
 			default:
 				GiraffeLogger.error("Encountered unsupported delta type " +
 						del.deltaType());
 				}
 				break;
 			case INPUT:
+				IODescriptor io = new IODescriptor(false, true, del.input_str());
+				return new UpdateDescriptor(animations, highDescriptor,  io);
 			case OUTPUT:
+				io = new IODescriptor(false, false, del.output_str());
+				return new UpdateDescriptor(animations, highDescriptor,  io);
 			default:
 				GiraffeLogger.error("Encountered unsupported delta type " +
 						del.deltaType());

src/ca/usask/cs/giraffe/compiler/anim/DataDisplayManager.java

 	 * @param name
 	 *            the name of the data object
 	 */
-	public void removeDataObject(String name) {
+	public void removeDataObject(String name) {		
 		TypeTree type = boxes.get(name);
 		if (type == null) {
-			GiraffeLogger.error("Trying to remove object: " + name +
+			GiraffeLogger.error("Trying to remove nonexistent object: " + name +
 					" from DataDisplayManager");
+			return;
 		}
 		boxes.remove(name);
 		if (type.isPrimitive()) {

src/ca/usask/cs/giraffe/compiler/anim/IODescriptor.java

+package ca.usask.cs.giraffe.compiler.anim;
+
+/**
+ * Describes a change in IO state (adding or substracting an input/output string) 
+ * used by the UI to update the IO Display. 
+ * 
+ * @author isv452
+ *
+ */
+public class IODescriptor {
+	
+	/**
+	 * true if this describes an addition to the I/O state, false if it describes a subtraction
+	 */
+	private Boolean isAddition;
+	
+	/**
+	 * true if this describes an input string, false if it describes an output string
+	 */
+	private Boolean isInput;
+	
+	/**
+	 * the string to be added/substracted
+	 */
+	private String ioString;
+	
+	
+	/**
+	 * constructor
+	 */
+	public IODescriptor(boolean add, boolean input, String str){
+		isAddition = add;
+		isInput = input;
+		ioString = str;
+	}
+
+	// accessors
+	
+	public Boolean isAddition(){
+		return isAddition;
+	}
+	
+	public Boolean isInput(){
+		return isInput;
+	}
+	
+	public String getIOString(){
+		return ioString;
+	}
+}

src/ca/usask/cs/giraffe/compiler/anim/UpdateDescriptor.java

 	/**
 	 * Shows the new contents of the accumulator
 	 */
-	private String accumString;
+	private String accumString = "";
+	
+	/**
+	 * shows the IO update, if any
+	 */
+	private IODescriptor io = null;
 	
 	/**
 	 * Stores whether or not the UpdateDescriptor is empty either because we're
 	 */
 	private Boolean isProgramBoundary = false;
 	
+	
 	/**
-	 * Constructor
+	 * Constructor with i/o
+	 * 
+	 * @param ads
+	 *            description of the animations to perform simultaneously
+	 * @param hd
+	 *            description of the program substring to highlight while
+	 *            performing the animations
+	 * @param ioDesc
+	 * 			  the io changes
+	 */
+	public UpdateDescriptor(LinkedList<AnimationDescriptor> ads,
+			HighlightDescriptor hd, IODescriptor ioDesc) {
+		animations = ads;
+		highlight = hd;
+		io = ioDesc;
+	}
+	
+	/**
+	 * Constructor with accumulator change
 	 * 
 	 * @param ads
 	 *            description of the animations to perform simultaneously
 			HighlightDescriptor hd) {
 		animations = ads;
 		highlight = hd;
-		accumString = "";
 	}
 	
 	/**
 	public Boolean isEndOfProgram() {
 		return isProgramBoundary;
 	}
+	
+	/**
+	 * @return true if the descriptor has IO changes, false otherwise
+	 */
+	public Boolean hasIO(){
+		return null != io;
+	}
+	
+	/**
+	 * @precond hasIO()
+	 * @return the IO descriptor stored
+	 */
+	public IODescriptor getIO(){
+		if (!hasIO()) 
+			throw new RuntimeException("called getIO on an UpdateDescriptor with no I/O");
+		else 
+			return io;
+	}
 }

src/ca/usask/cs/giraffe/ui/UI.java

 import javax.swing.SwingUtilities;
 
 import ca.usask.cs.giraffe.UIController;
+import ca.usask.cs.giraffe.compiler.anim.IODescriptor;
 import ca.usask.cs.giraffe.compiler.anim.UpdateDescriptor;
 import ca.usask.cs.giraffe.core.GiraffeAction;
 import ca.usask.cs.giraffe.core.GiraffeLogger;
 		try {
 			SwingUtilities.invokeAndWait(new Runnable() {
 				public void run() {
+					if (ud.hasIO()){
+						IODescriptor io = ud.getIO();
+						System.out.println("New IO with str: " + io.getIOString() + " input: " + io.isInput());
+					}
 					window.getProgramPanel()
 							.getCodeTextArea()
 							.highlight(ud.highlight().startChar(),
 	} else {
 		cout << "No, x is not 1" << endl;
 	}
-
-	return 0;
 }