Commit 3560dc42 authored by Custom2043's avatar Custom2043

gne.

parent 8394a577
......@@ -85,6 +85,7 @@ public class ExpressionCompiler
{
currentSpace.removeInfosOn(r.toOperationList());
currentSpace.addInfo(r.toOperationList().getInfos(currentSpace.getCurrentInfo(), false).copyTo(r.toOperationList()));
currentSpace.addInfo(assignation.secondExp.toOperationList().knowing(r.toOperationList().getInfos(currentSpace.getCurrentInfo(), false), currentSpace.getCurrentInfo()));
}
if (!isTypeParentOf(assignation.ref.getLastType(), t))
......
......@@ -69,8 +69,10 @@ public class StatementCompiler
return ;
}
ret.refInfos = space.getCurrentInfo();
if (ret.exp != null)
{
ret.resultInfo = ret.exp.toOperationList().getInfos(space.getCurrentInfo(), false);
ret.returnType = this.unit.expressionCompiler.compile(space, ret.exp);
if (met.returnType.equals(MyType.voidType))
UnitCompiler.report("Le return ne devrait pas avoir de type");
......
......@@ -115,4 +115,10 @@ public class AndInfo extends HigherInfo
public HigherInfo accessArray(OperationList index, HigherInfo refInfos) {
return new AndInfo(this.info1.accessArray(index, null), this.info2.accessArray(index, null));
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return new AndInfo(this.info1.replaceAndRemoveOther(toReplace, replacement),this.info2.replaceAndRemoveOther(toReplace, replacement));
}
}
......@@ -126,4 +126,10 @@ public class ArrayInfo extends HigherInfo
{
return new ArrayInfo(this.index, this.info.removeInfo(inf));
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return new ArrayInfo(index,this.info.replaceAndRemoveOther(toReplace, replacement));
}
}
\ No newline at end of file
......@@ -106,4 +106,10 @@ public class FieldInfo extends HigherInfo
}
return this;
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return new FieldInfo(var,this.info.replaceAndRemoveOther(toReplace, replacement));
}
}
......@@ -42,4 +42,6 @@ public abstract class HigherInfo {
return NoInfo.instance;
}
public abstract HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement);
}
\ No newline at end of file
......@@ -134,4 +134,10 @@ public class IfInfo extends HigherInfo
public HigherInfo accessArray(OperationList index, HigherInfo refInfos) {
return new IfInfo(this.condition, this.then.accessArray(index, null), this.els.accessArray(index, null));
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return new IfInfo(this.condition, this.then.replaceAndRemoveOther(toReplace, replacement),this.els.replaceAndRemoveOther(toReplace, replacement));
}
}
......@@ -3,25 +3,46 @@ package inflow;
import java.util.Arrays;
import language.parser.tokens.MethodCall;
import language.parser.tokens.MethodDeclaration;
public class MethodUse implements Operation
{
public final OperationEnum opType;
public final OperationList[] args;
public final MethodDeclaration dec;
public MethodUse(OperationEnum o, OperationList... a)
public MethodUse(MethodDeclaration d, OperationEnum o, OperationList... a)
{
this.opType = o;
this.args = a;
this.dec = d;
}
public MethodUse(OperationEnum o, OperationList... a)
{
this(null, o, a);
}
public MethodUse(OperationEnum o, MethodCall call)
{
this(o, Arrays.stream(call.exp).map(e -> e.toOperationList()).toArray(OperationList[]::new));
}
public MethodUse(MethodDeclaration d, MethodCall call)
{
this(d, null, Arrays.stream(call.exp).map(e -> e.toOperationList()).toArray(OperationList[]::new));
}
@Override
public HigherInfo apply(HigherInfo onInfo, OperationList on, HigherInfo refInfos) {
if (dec != null) {
return this.dec.apply().replaceAndRemoveOther(
this.dec.args.originalValues,
this.args
);
}
if (this.args.length == 0)
return onInfo.apply(on, null, this.opType, null, refInfos);
return onInfo.apply(on, this.args[0], this.opType, this.args[0].getInfos(refInfos, false), refInfos);
......@@ -29,6 +50,10 @@ public class MethodUse implements Operation
@Override
public AndInfo knowing(HigherInfo resultInfo, OperationList resultList, OperationList callerList, HigherInfo refInfos) {
if (dec != null)
return (AndInfo)dec.knowing(resultInfo);
if (this.args.length == 0)
return new AndInfo(
resultInfo.knowing(resultList, callerList, null, this.opType, refInfos),
......
......@@ -89,4 +89,10 @@ public class NoInfo extends HigherInfo {
public HigherInfo accessArray(OperationList index, HigherInfo refInfos) {
return this;
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return this;
}
}
......@@ -115,4 +115,10 @@ public class OrInfo extends HigherInfo
public HigherInfo accessArray(OperationList index, HigherInfo refInfos) {
return new OrInfo(this.info1.accessArray(index, null), this.info2.accessArray(index, null));
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return new OrInfo(this.info1.replaceAndRemoveOther(toReplace, replacement),this.info2.replaceAndRemoveOther(toReplace, replacement));
}
}
......@@ -134,4 +134,10 @@ public class ValueInfo extends HigherInfo
public HigherInfo accessArray(OperationList index, HigherInfo refInfos) {
return NoInfo.instance;
}
@Override
public HigherInfo replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return new ValueInfo(value, this.info.replaceAndRemoveOther(toReplace, replacement));
}
}
......@@ -131,4 +131,10 @@ public class BooleanValueInfo extends Info
public boolean use(VariableValue value) {
return false;
}
@Override
public Info replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
return this;
}
}
......@@ -6,11 +6,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import inflow.ConstantValue;
import inflow.MethodUse;
import inflow.OperationEnum;
import inflow.OperationList;
import inflow.VariableValue;
import inflow.*;
public class Calcul
{
......@@ -57,6 +53,17 @@ public class Calcul
return new Calcul(this.calc1.mul(other.calc2), this.calc2.mul(other.calc1)).normalize();
}
public Calcul replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
Ligne l1 = this.calc1.replaceAndRemoveOther(toReplace, replacement);
Ligne l2 = this.calc1.replaceAndRemoveOther(toReplace, replacement);
if (l1 == null || l2 == null)
return null;
return new Calcul(l1, l2);
}
public Calcul not()
{
return new Calcul(this.calc1.not(), this.calc2).normalize();
......@@ -148,6 +155,25 @@ class Ligne
return this.add(c.not());
}
public Calcul replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
for (Element e : this.elements)
{
Element ee = new Element(e.multiplicateur);
for (VariableValue v : e.var)
{
for (Value vv : toReplace)
if (vv == v)
{
}
else
return null;
}
}
}
public Ligne mul(Ligne c) {
LinkedList<Element> newList = new LinkedList<>();
for (Element e : this.elements)
......
package info;
import inflow.HigherInfo;
import inflow.OperationEnum;
import inflow.OperationList;
import inflow.VariableValue;
import inflow.*;
public abstract class Info {
......@@ -29,4 +26,5 @@ public abstract class Info {
public abstract HigherInfo inverse();
public abstract boolean use(VariableValue value);
public abstract Info replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement);
}
package info;
import compiler.UnitCompiler;
import inflow.AndInfo;
import inflow.ConstantValue;
import inflow.HigherInfo;
import inflow.IfInfo;
import inflow.MethodUse;
import inflow.NoInfo;
import inflow.OperationEnum;
import inflow.OperationList;
import inflow.OrInfo;
import inflow.ValueInfo;
import inflow.VariableValue;
import inflow.*;
public class IntRangeInfo extends Info
{
......@@ -315,4 +305,17 @@ public class IntRangeInfo extends Info
return this.min.getValues().stream().anyMatch(v -> v.possessedBy.equals(value.possessedBy)) ||
this.max.getValues().stream().anyMatch(v -> v.possessedBy.equals(value.possessedBy));
}
@Override
public Info replaceAndRemoveOther(Value[] toReplace, OperationList[] replacement)
{
Calcul min2 = this.min.replaceAndRemoveOther(toReplace, replacement);
Calcul max2 = this.max.replaceAndRemoveOther(toReplace, replacement);
if (min2 == null || max2 == null)
return null;
return new IntRangeInfo(min2, max2);
}
}
......@@ -5,14 +5,8 @@ import java.util.LinkedList;
import compiler.UnitCompiler;
import compiler.Variable;
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 inflow.Value;
import language.parser.parser.*;
import namingSpace.NamingSpace;
public class Arguments extends Token
......@@ -39,6 +33,8 @@ public class Arguments extends Token
public boolean isClassArguments = false;
public Value[] originalValues;
public static Arguments arrayClassArgs = generate(new VariableDeclaration[] {
VariableDeclaration.generate(MyType.fromAccess(Access.intAccess), "length")
});
......@@ -85,6 +81,7 @@ public class Arguments extends Token
nameSpace.addVariableDeclaration(dec);
dec.compileTypes(unit, nameSpace);
}
this.originalValues = Arrays.stream(this.getVariableList()).map(v -> v.getValue()).toArray(Value[]::new);
this.checkClassArgsTypes();
}
......
......@@ -6,14 +6,10 @@ import compiler.ExpressionCompiler;
import compiler.UnitCompiler;
import converter.MyClassWriter;
import converter.TypeConverter;
import language.parser.parser.OptionalSearch;
import language.parser.parser.OrSearch;
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 inflow.AndInfo;
import inflow.HigherInfo;
import inflow.NoInfo;
import language.parser.parser.*;
import namingSpace.ClassNamingSpace;
import namingSpace.MethodNamingSpace;
import namingSpace.NamingSpace;
......@@ -364,4 +360,24 @@ public class MethodDeclaration extends Token
{
return this.namingSpace.getFirstUpperNamingSpace(ClassNamingSpace.class).getClassDeclaration();
}
public HigherInfo apply()
{
HigherInfo info = NoInfo.instance;
for (ReturnStatement st : this.getTokensIn(ReturnStatement.class))
info = new AndInfo(info, st.resultInfo);
return info;
}
public HigherInfo knowing(HigherInfo resultInfo)
{
HigherInfo info = NoInfo.instance;
for (ReturnStatement st : this.getTokensIn(ReturnStatement.class))
info = new AndInfo(info, st.exp.toOperationList().knowing(resultInfo, st.refInfos));
return info;
}
}
\ No newline at end of file
package language.parser.tokens;
import converter.MyClassWriter;
import converter.TypeConverter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
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 converter.MyClassWriter;
import converter.TypeConverter;
import inflow.HigherInfo;
import language.parser.parser.*;
public class ReturnStatement extends Token
{
......@@ -30,6 +26,8 @@ public class ReturnStatement extends Token
/********** Do not modify or remove **********/
public MyType returnType;
public HigherInfo resultInfo;
public HigherInfo refInfos;
@Override
public void writeBytecode(MyClassWriter writer)
......
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