/**
 * 
 */
package dspl.intermediate.instructions;

import java.util.ArrayList;

import dspl.intermediate.Comparison;
import dspl.intermediate.variable.Variable;

/**
 * LoopInstruction is used to represent for and while loops.<br>
 * Note that in DSPL a while loop is a subclass of for-loop internally.
 * meaning "for(x=0; x<10; x++) { ... }"   ==   "x=0; while(x<10) { ... x++; }"
 * <p>
 * A note on terminology:<br>
 * Assume a for loop of structure "for (x=0, y=7, z=10; x<10; x++) { a = 5+x; ... }
 * The first portion ("x=0, y=7, z=10") is referred to as the Assignment Instruction(s)
 * The second portion ("x<10;") is referred to as the Condition Instruction(s)
 * The third portion ("x++") is referred to as the Arithmatic Instruction(s)
 * The fourth portion ("a = 5+x") is referred to as the Loop Instruction(s)
 * @author David
 */
public class LoopInstruction extends Instruction {
	/**
	 * Contains the instruction(s) to be evaluated before entering the loop
	 * is allowed to be empty
	 */
	public Instruction assignmentInstr;
	
	/**
	 * Contains the single comparison instruction which if false, terminates the loop
	 */
	public Comparison comp; 
	
	/**
	 * Contains the instruction(s) to be evaluated directly before evaluating the conditionInstr instruction(s)
	 */
	public Instruction arithmaticInstr;
	
	/**
	 * Contains the instructions to be evaluated wtihin the body fo the loop
	 */
	public Instruction loopInstr;
	
	/**
	 * 
	 * @param assignmentInstr Assignment Instruction(s)
	 * @param conditionInstr  Condition Instruction(s)
	 * @param arithmaticInstr Arithmatic Instruction(s)
	 * @param loopInstr		  Loop Instruction(s)
	 */
	public LoopInstruction(Instruction assignmentInstr, Comparison comp, Instruction arithmaticInstr, Instruction loopInstr) {
		this.assignmentInstr = assignmentInstr; 
		this.comp = comp; 
		this.arithmaticInstr = arithmaticInstr;
		this.loopInstr = loopInstr;
	}
	
	/* (non-Javadoc)
	 * @see dspl.intermediate.instructions.Instruction#usesVariable(dspl.intermediate.variable.Variable)
	 */
	public boolean usesVariable(Variable v) {
		// TODO Auto-generated method stub
		return false;
	}

	public int getInstType() {
		return Instruction.INST_TYPE_FORLOOP;
	}
}
