Bugfix #4 (FunVoidN Typen)

This commit is contained in:
JanUlrich 2016-11-15 23:00:07 +01:00
parent 642394c25b
commit 388685d3b2
6 changed files with 29 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.NullSyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.FunN;
import de.dhbwstuttgart.syntaxtree.type.FunVoidN;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
@ -108,7 +109,7 @@ public class UnifyTypeFactory {
params.add(UnifyTypeFactory.convert(pT));
}
}
ret = FunNType.getFunNType(new TypeParams(params));
ret = FunNType.getFunNType(t.getName().toString(), new TypeParams(params));
return ret;
}

View File

@ -215,16 +215,6 @@ public class LambdaExpression extends Expr{
return ret;
}
/*
private List<LocalOrFieldVarOrClassname> crawlVariables(SyntaxTreeNode inStatements){
List<LocalOrFieldVarOrClassname> ret = new ArrayList<>();
for(SyntaxTreeNode child : inStatements.getChildren()){
ret.addAll(crawlVariables(child));
}
return ret;
}
*/
@Override
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
DHBWConstantPoolGen cp = cg.getConstantPool();

View File

@ -17,6 +17,7 @@ import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
/**
@ -157,7 +158,7 @@ public class FunN extends RefType {
}
public FunNInterface getCorrespondingInterface(){
return null;
throw new NotImplementedException();
}
/*

View File

@ -1,12 +1,16 @@
package de.dhbwstuttgart.syntaxtree.type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -29,7 +33,7 @@ public class FunVoidN extends FunN {
* @param T
* @return
*/
public FunVoidN(Menge<Type> T) {
public FunVoidN(List<Type> T) {
super(T.size());
this.setR(new Void(this, -1));
this.setT(T);
@ -56,5 +60,17 @@ public class FunVoidN extends FunN {
if(T!=null)t.addAll(T);
this.set_ParaList(t);
}
@Override
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
//FunN Typen müssen nicht geprüft werden. Sie werden schließlich nur von unserem Typinferenzalgorithmus erstellt:
List<Type> paraList = new ArrayList<>();
if(this.T != null && this.T.size() > 0)for(Type t : this.T){
Type toAdd = t.TYPE(ass, parent);
//if(toAdd == null)throw new TypeinferenceException("Typ "+toAdd+" ist in den Assumptions nicht vorhanden",this);
paraList.add(toAdd);
}
FunVoidN ret = new FunVoidN(paraList);
return ret;
}
}

View File

@ -13,8 +13,8 @@ public class FunNType extends UnifyType {
/**
* Creates a FunN-Type with the specified TypeParameters.
*/
protected FunNType(TypeParams p) {
super("Fun"+(p.size()-1), p);
protected FunNType(String name, TypeParams p) {
super(name, p);
}
/**
@ -23,13 +23,13 @@ public class FunNType extends UnifyType {
* @return A FunNType.
* @throws IllegalArgumentException is thrown when there are to few type parameters or there are wildcard-types.
*/
public static FunNType getFunNType(TypeParams tp) throws IllegalArgumentException {
public static FunNType getFunNType(String name, TypeParams tp) throws IllegalArgumentException {
if(tp.size() == 0)
throw new IllegalArgumentException("FunNTypes need at least one type parameter");
for(UnifyType t : tp)
if(t instanceof WildcardType)
throw new IllegalArgumentException("Invalid TypeParams for a FunNType: " + tp);
return new FunNType(tp);
return new FunNType(name,tp);
}
/**
@ -43,7 +43,7 @@ public class FunNType extends UnifyType {
public UnifyType setTypeParams(TypeParams newTp) {
if(newTp.hashCode() == typeParams.hashCode() && newTp.equals(typeParams))
return this;
return getFunNType(newTp);
return getFunNType(this.getName(), newTp);
}
@Override
@ -64,7 +64,7 @@ public class FunNType extends UnifyType {
if(newParams.hashCode() == typeParams.hashCode() && newParams.equals(typeParams))
return this;
return new FunNType(newParams);
return new FunNType(this.getName(), newParams);
}
@Override

View File

@ -12,7 +12,7 @@ public class FunVoid {
@Test
public void run(){
Menge<String> mustContain = new Menge<String>();
//mustContain.add("TestIfStmt var");
mustContain.add("FunVoid");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
ArrayList l = new ArrayList();
}