package fr.lifl.stc.stan.implicitFlow.data; /** * * @author dorina * */ public class BooleanVariable implements Comparable{ static public int VARIABLE_TYPE = 1, SWITCH_TYPE = 2, CONSTANT_TYPE = 3; static public int TRUE_TYPE = -1; static public int FALSE_TYPE = -2; public static BooleanVariable condition_true = new BooleanVariable(TRUE_TYPE, CONSTANT_TYPE); public static BooleanVariable condition_false = new BooleanVariable(FALSE_TYPE, CONSTANT_TYPE); private int line; /** * for SWITCH_TYPE, specifies the indice of tested variable. Has the values 0, 1, 2, etc. */ private int switch_indice; /** * can be VARIABLE_TYPE, SWITCH_TYPE, CONSTANT_TYPE */ private int type; /* * can be TRUE_TYPE or FALSE_TYPE , to specify if it represents a negation or no */ private int bool_type; BooleanVariable negation; /* public BooleanVariable(int line){ this.line = line; this.type = VARIABLE_TYPE; } */ public BooleanVariable(int line, int type){ this(line, type, -1); } public BooleanVariable(int line, int type, int switch_ind){ this.switch_indice = switch_ind; this.line = line; this.type = type; //this.switch_indice = this.bool_type = TRUE_TYPE; if(type!=CONSTANT_TYPE) this.negation = new BooleanVariable(line, type, switch_indice, this); else { //FIXME check if it works if(line == TRUE_TYPE) negation = condition_false; else negation = condition_true; } } private BooleanVariable(int line, int type, int switch_indice, BooleanVariable negation){ this.line = line; this.type = type; this.bool_type = FALSE_TYPE; this.switch_indice = switch_indice; this.negation = negation; } /** * method for Comparable interface * @param o * @return */ public int compareTo(Object o){ if(! (o instanceof BooleanVariable)) return 1; BooleanVariable b = (BooleanVariable)o; if(this.getLine() > b.getLine()) return 1; if(this.getLine() < b.getLine()) return -1; if(this.getSwitchInd() > b.getSwitchInd()) return 1; if(this.getSwitchInd() < b.getSwitchInd()) return -1; return 0; } public int getLine(){ return this.line; } public int getType(){ return this.type; } public boolean isNegation(){ return this.bool_type == FALSE_TYPE; } public BooleanVariable getAfirmation() { if(this.isNegation()) return this.getNegation(); return this; } public BooleanVariable getNegation(){ return negation; } public int getSwitchInd(){ return this.switch_indice; } public String toString(){ if (this == condition_true) return "(TRUE)"; if (this == condition_false) return "(FALSE)"; String s = "("; if(isNegation()) s += "not "; s += line+", "+this.switch_indice+")"; return s; } }