Commit 761fcb3d authored by Allan MILHOMME's avatar Allan MILHOMME

m

parent 70a503a3
void main(Array<String> args)
{
Int i = 0;
Int j = i.add(3);
if (j.inf(6))
test3(i);
i = 0;
i = i.add(1);
while (i.inf(10)) {
i = i.add(1);
}
System:.out.println(i);
test3(i);
}
void test3(Int i)
[
i.inf(3);
i.inf(3).not();
]
{
......
......@@ -107,7 +107,7 @@ public class ExpressionCompiler {
currentSpace.removeInfosDependingOn(r.toOperationList());
currentSpace.removeInfosOn((VariableValue)r.toOperationList().getLastValue());
currentSpace.addInfo(addedInfo.normalize());
Logger.debug("Out : "+currentSpace.getCurrentInfo().normalize());
//Logger.debug("Out : "+currentSpace.getCurrentInfo().normalize());
}
if (!isTypeParentOf(assignation.ref.getLastType(), t))
......
......@@ -16,4 +16,8 @@ public class ConstantValue implements Value {
public ConstantValue() {
this.value = NoInfo.instance;
}
public String toString() {
return this.value.toString();
}
}
......@@ -17,9 +17,9 @@ public class LoopInflow extends BasicInflow {
public HigherInfo updateInfos() {
HigherInfo deduced = this.getConditionExp().toOperationList().knowing(true, this.currentInfos);
Logger.debug("Deduced : "+deduced+" from "+this.currentInfos);
//Logger.debug("Deduced : "+deduced+" from "+this.currentInfos);
HigherInfo newInfos = new AndInfo(this.currentInfos, deduced);
Logger.debug("" + newInfos.removeInfosDependingOn(new OperationList(value), newInfos).normalize());
//Logger.debug("" + newInfos.removeInfosDependingOn(new OperationList(value), newInfos).normalize());
return newInfos.removeInfosDependingOn(new OperationList(value), newInfos).normalize();
}
......
......@@ -4,20 +4,17 @@ import language.parser.tokens.Access;
import language.parser.tokens.Reference;
public enum OperationEnum {
INT_ADD("add", Access.intAccess, Access.intAccess), INT_SUB("sub", Access.intAccess, Access.intAccess), INT_MUL(
"mul", Access.intAccess, Access.intAccess), INT_DIV("div", Access.intAccess, Access.intAccess), INT_EQ("eq",
Access.intAccess, Access.intAccess), INT_INF("inf", Access.intAccess,
Access.intAccess), INT_NOT("not", Access.intAccess), BOOL_AND("and", Access.booleanAccess,
Access.booleanAccess), BOOL_OR("or", Access.booleanAccess,
Access.booleanAccess), BOOL_EQ("eq", Access.booleanAccess,
Access.booleanAccess), BOOL_NOT("not", Access.booleanAccess),
INT_ADD("add", Access.intAccess, Access.intAccess), INT_SUB("sub", Access.intAccess, Access.intAccess),
INT_MUL("mul", Access.intAccess, Access.intAccess), INT_DIV("div", Access.intAccess, Access.intAccess),
INT_EQ("eq", Access.intAccess, Access.intAccess), INT_INF("inf", Access.intAccess, Access.intAccess),
INT_NOT("not", Access.intAccess), BOOL_AND("and", Access.booleanAccess, Access.booleanAccess),
BOOL_OR("or", Access.booleanAccess, Access.booleanAccess),
BOOL_EQ("eq", Access.booleanAccess, Access.booleanAccess), BOOL_NOT("not", Access.booleanAccess),
// Method that doesn't actually exists
INT_UP_TO("up_to", Access.intAccess), INT_DOWN_TO("up_to", Access.intAccess), INT_UP_TO_1("up_to_1",
Access.intAccess), INT_DOWN_TO_1("up_to_1",
Access.intAccess), INT_EXPAND("expand", Access.intAccess, Access.intAccess), // Badly named
ARRAY_SET("set", Access.arrayAccess, Access.intAccess, Access.objectAccess), ARRAY_GET("get", Access.arrayAccess,
Access.intAccess);
INT_UP_TO("up_to", Access.intAccess), INT_DOWN_TO("up_to", Access.intAccess),
INT_UP_TO_1("up_to_1", Access.intAccess, Access.intAccess), INT_DOWN_TO_1("up_to_1", Access.intAccess),
INT_EXPAND("expand", Access.intAccess, Access.intAccess), // Badly named
;
public final String methodName;
public final Access callerAccess;
......
......@@ -5,6 +5,7 @@ import java.util.LinkedList;
import info.BooleanValueInfo;
import info.IntRangeInfo;
import main.Logger;
public class OperationList {
public final Value baseValue;
......@@ -59,6 +60,9 @@ public class OperationList {
public HigherInfo getFirstValueInfo(HigherInfo refInfos) {
if (this.baseValue instanceof VariableValue)
return ((VariableValue) this.baseValue).getInfos(refInfos);
if (this.baseValue instanceof LoopValue)
return ((LoopValue) this.baseValue).getInfos(refInfos);
return ((ConstantValue) this.baseValue).value;
}
......@@ -72,8 +76,10 @@ public class OperationList {
HigherInfo toAdd = NoInfo.instance;
for (int i = this.operationList.size() - 1;; i--) {
if (i == -1) {
if (this.baseValue instanceof VariableValue)
if (this.baseValue instanceof VariableValue || this.baseValue instanceof LoopValue) {
//Logger.debug("Knowing return : "+new AndInfo(toAdd, resultInfo).setValue(this.baseValue).normalize());
return new AndInfo(toAdd, resultInfo).setValue(this.baseValue).normalize();
}
return NoInfo.instance;
}
......
......@@ -75,7 +75,7 @@ public class BooleanValueInfo extends Info {
else if (opType == OperationEnum.INT_INF) {
if (this.value) {
return new AndInfo(
argExp.getInfos(refInfos, true).apply(argExp, null, OperationEnum.INT_UP_TO_1, null, refInfos)
argExp.getInfos(refInfos, true).apply(argExp, refExp, OperationEnum.INT_UP_TO_1, refExp.getInfos(refInfos, false), refInfos)
.setValue(refExp.getLastValue()),
refExp.getInfos(refInfos, true).apply(refExp, null, OperationEnum.INT_DOWN_TO_1, null, refInfos)
.setValue(argExp.getLastValue()));
......
......@@ -229,7 +229,7 @@ class Ligne {
public OperationList toOperationList() {
OperationList list = this.elements.get(0).toOperationList();
for (int i = 1; i < this.elements.size(); i++)
list.apply(new MethodUse(OperationEnum.INT_ADD, this.elements.get(i).toOperationList()));
list = list.apply(new MethodUse(OperationEnum.INT_ADD, this.elements.get(i).toOperationList()));
return list;
}
......@@ -322,7 +322,7 @@ class Element {
OperationList list = new OperationList(new ConstantValue(new IntRangeInfo(this.multiplicateur)));
for (Value v : this.var)
list.apply(new MethodUse(OperationEnum.INT_MUL, new OperationList(v)));
list = list.apply(new MethodUse(OperationEnum.INT_MUL, new OperationList(v)));
return list;
}
......
......@@ -36,8 +36,6 @@ public class IntRangeInfo extends Info {
return new ValueInfo(new IntRangeInfo(new Calcul(Integer.MIN_VALUE), this.min));
else if (opType == OperationEnum.INT_DOWN_TO)
return new ValueInfo(new IntRangeInfo(this.max, new Calcul(Integer.MAX_VALUE)));
else if (opType == OperationEnum.INT_UP_TO_1)
return new ValueInfo(new IntRangeInfo(new Calcul(Integer.MIN_VALUE), this.min.sub(new Calcul(1))));
else if (opType == OperationEnum.INT_DOWN_TO_1)
return new ValueInfo(new IntRangeInfo(this.max.add(new Calcul(1)), new Calcul(Integer.MAX_VALUE)));
throw new IllegalArgumentException("Unknown method for Int : " + opType);
......@@ -86,6 +84,12 @@ public class IntRangeInfo extends Info {
return NoInfo.instance;
}
else if (opType == OperationEnum.INT_UP_TO_1) {
//Logger.debug("This "+this+", other : "+range);
HigherInfo info2 = range.min.toOperationList().knowing(new ValueInfo(this), refInfos);
//Logger.debug("Info 2 : "+info2);
return new ValueInfo(new IntRangeInfo(new Calcul(Integer.MIN_VALUE), this.min.sub(new Calcul(1))));
}
throw new UnsupportedOperationException("Unknown method for Int : " + opType);
}
......@@ -208,6 +212,8 @@ public class IntRangeInfo extends Info {
}
public HigherInfo div(OperationList thisExp, OperationList otherExp, IntRangeInfo range, HigherInfo refInfos) {
Logger.debug("This exp : "+thisExp+", other : "+otherExp);
if (!otherExp
.apply(new MethodUse(OperationEnum.INT_EQ, new OperationList(new ConstantValue(new IntRangeInfo(0)))))
.getInfos(refInfos, false).isFalse())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment