Commit 17f70f88 authored by Allan MILHOMME's avatar Allan MILHOMME

n

parent 69272ec8
void main(Array<String> args)
{
Int i = Math:.random().toInt();
if (i.inf(2).not())
test2(i);
Int i = 0;
while (i.inf(10)) {
i = i.add(1);
}
System:.out.println(i);
test3(i);
}
void test2(Int m)
void test3(Int i)
[
m.inf(1).not();
i.inf(3).not();
]
{
......
......@@ -16,6 +16,7 @@ import language.parser.tokens.MethodDeclaration;
import language.parser.tokens.MyType;
import language.parser.tokens.ObjectInstanciation;
import language.parser.tokens.Reference;
import main.Logger;
import namingSpace.ClassNamingSpace;
import namingSpace.NamingSpace;
......@@ -80,6 +81,7 @@ public class ExpressionCompiler {
r.toOperationList().getInfos(currentSpace.getCurrentInfo(), false).copyTo(r.toOperationList()));
currentSpace.addInfo(assignation.secondExp.toOperationList().knowing(
r.toOperationList().getInfos(currentSpace.getCurrentInfo(), false), currentSpace.getCurrentInfo()));
currentSpace.removeInfosOn(r.toOperationList());
}
if (!isTypeParentOf(assignation.ref.getLastType(), t))
......
......@@ -28,11 +28,6 @@ public class MethodCompiler {
return;
}
if (dec.classArgs != null) {
dec.classArgs.compile(this.unit, dec.getNamingSpace());
for (VariableDeclaration d : dec.classArgs.vars)
this.unit.statementCompiler.compile(d, dec.getNamingSpace());
}
dec.compileTypes(this.unit);
if (dec.cons != null) {
......
......@@ -2,7 +2,17 @@ package compiler;
import java.util.Arrays;
import language.parser.tokens.*;
import language.parser.tokens.ClassDeclaration;
import language.parser.tokens.ConstructorCall;
import language.parser.tokens.ConstructorDeclaration;
import language.parser.tokens.Expression;
import language.parser.tokens.GenericArgs;
import language.parser.tokens.MethodDeclaration;
import language.parser.tokens.MyType;
import language.parser.tokens.ReturnStatement;
import language.parser.tokens.Statement;
import language.parser.tokens.VariableDeclaration;
import main.Logger;
import namingSpace.ClassNamingSpace;
import namingSpace.MethodNamingSpace;
import namingSpace.NamingSpace;
......
......@@ -68,7 +68,7 @@ public class StructureCompiler {
whi.space = new NamingSpace(space, false);
MethodNamingSpace methodSpace = space.getFirstUpperNamingSpace(MethodNamingSpace.class);
methodSpace.inflow.newLoopInflow();
methodSpace.inflow.newLoopInflow(whi.condition);
MyType t = this.unit.expressionCompiler.compile(space, whi.condition);
if (!t.isType(Access.booleanAccess))
......@@ -82,7 +82,7 @@ public class StructureCompiler {
fo.space = new NamingSpace(space, false);
MethodNamingSpace methodSpace = space.getFirstUpperNamingSpace(MethodNamingSpace.class);
methodSpace.inflow.newLoopInflow();
methodSpace.inflow.newLoopInflow(fo.exp2);
if (fo.exp1 != null)
this.unit.expressionCompiler.compile(fo.space, fo.exp1);
......
......@@ -9,7 +9,6 @@ import inflow.Inflow;
import inflow.VariableValue;
import language.parser.tokens.MyType;
import language.parser.tokens.VariableDeclaration;
import main.Logger;
import namingSpace.MethodNamingSpace;
public class Variable {
......@@ -22,6 +21,8 @@ public class Variable {
}
public VariableValue getValue() {
if (this.dec.values == null)
return new VariableValue(this);
return this.dec.values[this.index];
}
......
package inflow;
import language.parser.tokens.Expression;
import language.parser.tokens.IfElseStructure;
public class BasicInflow extends Inflow {
......@@ -22,8 +23,8 @@ public class BasicInflow extends Inflow {
this.childInflow = new IfInflow(this, ifElse, conditions);
}
public void newLoopInflow() {
this.childInflow = new LoopInflow(this);
public void newLoopInflow(Expression e) {
this.childInflow = new LoopInflow(this, e);
}
public void newNullInflow() {
......@@ -44,6 +45,8 @@ public class BasicInflow extends Inflow {
this.currentInfos = ((IfInflow) this.childInflow).updateInfos();
if (this.childInflow instanceof NullInflow)
this.currentInfos = ((NullInflow) this.childInflow).updateInfos();
if (this.childInflow instanceof LoopInflow)
this.currentInfos = ((LoopInflow) this.childInflow).updateInfos();
this.childInflow = null;
}
......@@ -61,7 +64,7 @@ public class BasicInflow extends Inflow {
public HigherInfo getAllInfos() {
if (this.childInflow != null)
return this.childInflow.getAllInfos();
return this.currentInfos;
return this.currentInfos.normalize();
}
@Override
......
package inflow;
import language.parser.tokens.Expression;
import main.Logger;
public class LoopInflow extends BasicInflow {
public final LoopValue value = new LoopValue(this);
public final Expression condition;
public LoopInflow(BasicInflow p) {
public LoopInflow(BasicInflow p, Expression e) {
super(p);
this.condition = e;
}
public Expression getConditionExp() {return null;}
public Expression getConditionExp() {return this.condition;}
public HigherInfo updateInfos() {
HigherInfo loopedInfos = this.currentInfos.toLoop(value);
HigherInfo loopedInfos = this.currentInfos.normalize().toLoop(value).normalize();
Logger.debug(""+loopedInfos);
HigherInfo deduced = this.getConditionExp().toOperationList().knowing(false, loopedInfos);
HigherInfo newInfos = new AndInfo(loopedInfos, deduced);
return newInfos.removeInfosOn(new OperationList(value), newInfos);
Logger.debug("" + newInfos.removeInfosOn(new OperationList(value), newInfos).normalize());
return newInfos.removeInfosOn(new OperationList(value), newInfos).normalize();
}
}
......@@ -6,7 +6,15 @@ import java.util.LinkedList;
import compiler.UnitCompiler;
import compiler.Variable;
import inflow.Value;
import language.parser.parser.*;
import language.parser.parser.ArraySearch;
import language.parser.parser.OptionalSearch;
import language.parser.parser.ParserString;
import language.parser.parser.Result;
import language.parser.parser.Search;
import language.parser.parser.Token;
import language.parser.parser.TokenBuilder;
import language.parser.parser.TokenSearch;
import main.Logger;
import namingSpace.NamingSpace;
public class Arguments extends Token {
......@@ -61,6 +69,7 @@ public class Arguments extends Token {
public void compile(UnitCompiler unit, NamingSpace nameSpace) {
for (VariableDeclaration dec : this.vars) {
dec.initValues();
dec.setNamingSpace(nameSpace);
dec.associatedArguments = this;
nameSpace.addVariableDeclaration(dec);
......
......@@ -8,6 +8,7 @@ import org.objectweb.asm.Opcodes;
import converter.MyClassWriter;
import converter.TypeConverter;
import language.parser.parser.*;
import main.Logger;
import namingSpace.NamingSpace;
public class IfElseStructure extends Token {
......@@ -67,6 +68,6 @@ public class IfElseStructure extends Token {
}
public boolean canEscape() {
return Arrays.stream(this.ifs).anyMatch(i -> i.canEscape()) || this.scope.canEscape();
return Arrays.stream(this.ifs).anyMatch(i -> i.canEscape()) || (this.scope != null && this.scope.canEscape());
}
}
\ No newline at end of file
......@@ -38,7 +38,6 @@ public class MethodDeclaration extends Token {
/********** Do not modify or remove **********/
public Asserts asserts = Asserts.noAssert();
public Arguments classArgs = Arguments.generate(new VariableDeclaration[0]);
public MethodSignature signature;
public GenericsDeclaration typeArgs = GenericsDeclaration.generate(new String[0]);
public boolean hasBeenCompiled = false, triedToBeResolved = false;
......@@ -77,7 +76,6 @@ public class MethodDeclaration extends Token {
this.namingSpace = new MethodNamingSpace(superSpace, this);
this.namingSpace.addGenericsDeclaration(this.typeArgs);
this.classArgs.isClassArguments = true;
this.isStatic = superSpace instanceof UnitNamingSpace;
}
......@@ -187,9 +185,6 @@ public class MethodDeclaration extends Token {
this.returnType = MyType.voidType;
else
this.returnType = this.returType;
if (this.classArgs == null)
this.classArgs = Arguments.generate(new VariableDeclaration[0]);
}
public String getDescription(boolean signature) {
......@@ -200,9 +195,6 @@ public class MethodDeclaration extends Token {
for (MyType t : this.cons.classDeclaration.classArgs.getArgumentsType())
b.append(TypeConverter.getDescription(t, signature));
for (MyType t : this.classArgs.getArgumentsType())
b.append(TypeConverter.getDescription(t, signature));
for (MyType t : this.getArgumentsType())
b.append(TypeConverter.getDescription(t, signature));
......
......@@ -189,7 +189,7 @@ public class Reference extends ExpressionPart {
list = this.exp.toOperationList();
else if (this.isFirstField())
list = new OperationList(VariableValue.thisValue);
else if (this.variables[0] == null)
else if (this.variables[0] == null || this.variables[0].dec.values == null)
return new OperationList();
else
list = new OperationList(this.variables[0].getValue());
......
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