Commits

Alex Mair  committed e873b91 Merge

Merge remote-tracking branch 'origin/master_bugfix' into HEAD

  • Participants
  • Parent commits a5820e2, 12c7ef7

Comments (0)

Files changed (7)

File src/ca/usask/cs/giraffe/Giraffe.java

 	public static void main(String args[]) {
 		try {
 			GiraffeLogger.enableVerboseLogging(false);
-			GiraffeLogger.setLogLevel(GiraffeLogger.LEVEL.DEBUG);
+			GiraffeLogger.setLogLevel(GiraffeLogger.LEVEL.WARN);
 			
 			GiraffeLogger.info("Starting up...");
 			Controller c = new Controller();

File src/ca/usask/cs/giraffe/compiler/DefaultDelta.java

 	}
 	
 	@Override
+	public ValueTree setVar_oldVal() throws WrongSubclassException {
+		throw new WrongSubclassException(
+				"Invalid method access for Delta type " + this.deltaType());
+	}
+	
+	@Override
 	public LValue setVarToAccum_id() throws WrongSubclassException {
 		throw new WrongSubclassException(
 				"Invalid method access for Delta type " + this.deltaType());

File src/ca/usask/cs/giraffe/compiler/DeltaDescriptor.java

 package ca.usask.cs.giraffe.compiler;
 
 import ca.usask.cs.giraffe.exception.*;
+
 import java.util.AbstractList;
 import java.util.Map;
 
 	public ValueTree setVar_value() throws WrongSubclassException;
 	
 	/**
+	 * Treat this delta as setting a variable value to get the variable value
+	 * 
+	 * @return string representation of the old variable value
+	 * @throws WrongSubclassException
+	 *             if this delta isn't a variable setting
+	 */
+	public ValueTree setVar_oldVal() throws WrongSubclassException;
+	
+	/**
 	 * Treat this delta as setting a variable to the current expression value to
 	 * get its name
 	 * 
 	 */
 	public AbstractList<DeltaDescriptor> multi_deltaList()
 			throws WrongSubclassException;
+
+	
 	
 }

File src/ca/usask/cs/giraffe/compiler/NodeVisitor.java

 						cstart(node), cend(initDecl.getChild(0))));
 				this.interpreter.setVar(lvalue, initValue);
 				// Assignment char position is the entire init declarator
-				this.appendDelta(new SetVarDelta(lvalue, initValue,
+				this.appendDelta(new SetVarDelta(lvalue, initValue, new UnInitValue(),
 						cstart(initDecl), cend(initDecl)));
 			} catch (ClassCastException e) {
 				throw new ExecutionErrorException(
 					LValue lv = new LValue(varName);
 					deleteAndAdds.add(new DeclVarDelta(varType, lv,
 							cstart(node), cend(node)));
-					deleteAndAdds.add(new SetVarDelta(lv, interpreter
-							.getVar(lv), cstart(node), cend(node)));
-					//TODO too hackish
-					//Set array values individually
-					if (varType.isArray()){
-						Value arr = this.interpreter.getVar(lv);
-						for (int index = 0; index < arr.arrayLength(); index++)	{
-							LValue arrLv = new LValue(lv, index); 
-							deleteAndAdds.add(new SetVarDelta(arrLv,
-									interpreter.getVar(arrLv), cstart(node), cend(node)));
-						}
-					}
+					Value val = interpreter.getVar(lv);
+					deleteAndAdds.add(new SetVarDelta(lv, val, val, cstart(node), cend(node)));
 				}
 				// Bundle all the descriptors into a single delta
 				this.appendDelta(new MultiDelta(deleteAndAdds, cstart(node),
 							.debug("Doing ++ on variable " + id.toString());
 					Value newVal = current.plus(new IntValue(1));
 					this.interpreter.setVar(lv, newVal);
-					this.appendDelta(new SetVarDelta(lv, newVal,
+					this.appendDelta(new SetVarDelta(lv, newVal, current,
 							cstart(postfix), cend(postfix)));
 				}
 				
 					// Don't change old value of current, since postfix
 					Value newVal = current.minus(new IntValue(1));
 					this.interpreter.setVar(lv, newVal);
-					this.appendDelta(new SetVarDelta(lv, newVal,
+					this.appendDelta(new SetVarDelta(lv, newVal, current,
 							cstart(postfix), cend(postfix)));
 				} else {
 					throw new ExecutionErrorException(

File src/ca/usask/cs/giraffe/compiler/SetVarDelta.java

 	private ValueTree val;
 	
 	/**
+	 * Old var value
+	 */
+	private ValueTree oldVal;
+	
+	/**
 	 * @param id
 	 *            Name of the variable to set
 	 * @param val
 	 * @param charEnd
 	 *            end position of the declaration in the source code
 	 */
-	public SetVarDelta(LValue id, ValueTree val, int charStart, int charEnd) {
+	public SetVarDelta(LValue id, ValueTree val, ValueTree oldVal, int charStart, int charEnd) {
 		super(charStart,charEnd);
 		this.id = id;
 		this.val = val.copy();
+		this.oldVal = oldVal.copy();
 	}
 	
 	@Override
 	}
 	
 	@Override
+	public ValueTree setVar_oldVal() {
+		return this.oldVal;
+	}
+	
+	@Override
 	public String toString() {
 		return "" + this.deltaType() + "(" + this.setVar_id() + ", " +
 				this.setVar_value() + ")";

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

 						del.declVar_type());
 				animations.add(ad);
 				break;
-			case SET_VAR:
+			case SET_VAR:				
 				setVarHelper(animations, del.setVar_id(), del.setVar_value());
 				break;
 			case SET_ACCUM_VAR:
 				animations.addFirst(ad);
 				break;
 			case SET_VAR:
-				// no inverse, since only used for argument declaration
+				setVarHelper(animations, del.setVar_id(), del.setVar_oldVal());
 				break;
 			case SET_ACCUM_VAR:
 				accum = del.setAccumVar_oldVal();

File src/ca/usask/cs/giraffe/test/DeltaTests.java

 	public void setVarDelta() {
 		LValue lv = new LValue("foo");
 		Value val = new VoidValue();
-		DeltaDescriptor d = new SetVarDelta(lv, val, 0, 10);
+		DeltaDescriptor d = new SetVarDelta(lv, val, val, 0, 10);
 		assertEquals(0, d.charStart());
 		assertEquals(10, d.charEnd());