modified: ../../../main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java

modified:   ../../../main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
	deleted:    ../../../main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java
	modified:   ../../../main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java
	modified:   ../../../main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java
	modified:   ../../../main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java
Es wird jetzt FunN-Type FunN$$ geparst
Der Typ FunN wurde entfernt
Der Name des Typs FunNType wurde um $$ am Ende ergänzt
This commit is contained in:
Martin Plümicke 2019-02-27 16:04:55 +01:00
parent fcad60996c
commit 88ec8823fd
11 changed files with 39 additions and 78 deletions

View File

@ -18,6 +18,8 @@ import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TypeGenerator {
@ -139,12 +141,17 @@ public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(
String name, Java8Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein
if(!reg.contains(name)){ //Dann könnte es ein generischer Type oder ein FunN$$-Type sein
if(generics.contains(name)){
return new GenericRefType(name, offset);
}else{
Pattern p = Pattern.compile("Fun(\\d+)[$][$]");
Matcher m = p.matcher(name);
if (m.matches()) {//es ist FunN$$-Type
return new RefType(new JavaClassName(name), convert(typeArguments, reg, generics), offset);
} else {
throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",offset);
}
}}
}
if(typeArguments == null){
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();

View File

@ -68,9 +68,6 @@ public class UnifyTypeFactory {
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){
if(t instanceof GenericRefType){
return UnifyTypeFactory.convert((GenericRefType)t, innerType);
}else
if(t instanceof FunN){
return UnifyTypeFactory.convert((FunN)t, innerType);
}else if(t instanceof TypePlaceholder){
return UnifyTypeFactory.convert((TypePlaceholder)t, innerType);
}else if(t instanceof ExtendsWildcardType){
@ -86,13 +83,13 @@ public class UnifyTypeFactory {
public static UnifyType convert(RefType t, Boolean innerType){
//Check if it is a FunN Type:
Pattern p = Pattern.compile("Fun(\\d+)");
Pattern p = Pattern.compile("Fun(\\d+)[$][$]");
Matcher m = p.matcher(t.getName().toString());
boolean b = m.matches();
if(b){
Integer N = Integer.valueOf(m.group(1));
if((N + 1) == t.getParaList().size()){
return convert(new FunN(t.getParaList()), false);
return convertFunN(t.getParaList(), false);
}
}
UnifyType ret;
@ -108,11 +105,11 @@ public class UnifyTypeFactory {
return ret;
}
public static UnifyType convert(FunN t, Boolean innerType){
public static UnifyType convertFunN(List<RefTypeOrTPHOrWildcardOrGeneric> paraList, Boolean innerType){
UnifyType ret;
List<UnifyType> params = new ArrayList<>();
if(t.getParaList() != null && t.getParaList().size() > 0){
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
if(paraList != null && paraList.size() > 0){
for(RefTypeOrTPHOrWildcardOrGeneric pT : paraList){
params.add(UnifyTypeFactory.convert(pT, false));
}
}
@ -236,7 +233,7 @@ public class UnifyTypeFactory {
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map<String,TypePlaceholder> tphs) {
RefType ret = new RefType(new JavaClassName(t.getName()+"$$"), convert(t.getTypeParams(), tphs), new NullToken());
RefType ret = new RefType(new JavaClassName(t.getName()), convert(t.getTypeParams(), tphs), new NullToken());
return ret;
}

View File

@ -1,41 +0,0 @@
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import java.util.List;
/**
* @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke
* "interface FunN<R,T1, T2, ... ,TN> { R apply(T1 arg1, T2 arg2, ... , TN argN); }"
* @author A10023 - Andreas Stadelmeier
*
* Bemerkung:
* FunN ist ein RefType. Der RefType ist nicht mit einem FunNInterface verbunden.
*
*/
public class FunN extends RefType {
/**
* @author Andreas Stadelmeier, a10023
* BenÃtigt ¼r den Typinferenzalgorithmus ¼r Java 8
* Generiert einen RefType auf eine FunN<R,T1,...,TN> - Klasse.
* @param params
* @return
*/
public FunN(List<RefTypeOrTPHOrWildcardOrGeneric> params) {
super(new JavaClassName("Fun"+(params.size()-1)), params, new NullToken());
}
/**
* Spezieller Konstruktor um eine FunN ohne Returntype zu generieren
protected FunN(List<? extends Type> list){
super("",0);
if(list==null)throw new NullPointerException();
setT(list);
this.name = new JavaClassName("Fun"+list.size());//getName();
}
*/
}

View File

@ -21,7 +21,7 @@ import java.util.Optional;
public class FunNClass extends ClassOrInterface {
public FunNClass(List<GenericRefType> funNParams) {
super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */,
super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */,
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());

View File

@ -1,10 +1,10 @@
package de.dhbwstuttgart.typeinference.assumptions;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.TypeScope;
import de.dhbwstuttgart.syntaxtree.type.FunN;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
@ -63,7 +63,7 @@ public class MethodAssumption extends Assumption{
}
RefTypeOrTPHOrWildcardOrGeneric receiverType;
if(receiver instanceof FunNClass){
receiverType = new FunN(params);
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params);
}else{
receiverType = new RefType(receiver.getClassName(), params, new NullToken());
}

View File

@ -65,7 +65,9 @@ public class TYPEStmt implements StatementVisitor{
//lambdaParams.add(0,tphRetType);
constraintsSet.addUndConstraint(
new Pair(lambdaExpression.getType(),
new FunN(lambdaParams),PairOperator.EQUALSDOT));
new RefType(new JavaClassName("Fun"+(lambdaParams.size()-1)+"$$"), lambdaParams, new NullToken()),
//new FunN(lambdaParams),
PairOperator.EQUALSDOT));
constraintsSet.addUndConstraint(
new Pair(lambdaExpression.getReturnType(),
tphRetType,PairOperator.EQUALSDOT));

View File

@ -22,7 +22,7 @@ public class FunNType extends UnifyType {
* Creates a FunN-Type with the specified TypeParameters.
*/
protected FunNType(TypeParams p) {
super("Fun"+(p.size()-1), p);
super("Fun"+(p.size()-1)+"$$", p);
}
/**

View File

@ -3,7 +3,7 @@ import java.lang.Integer;
//import java.lang.Byte;
import java.lang.Boolean;
public class MatrixOP extends Vector<Vector<Integer>> {
public class MatrixOP extends Vector<Vector<Integer>> {
MatrixOP () {
}
@ -18,10 +18,10 @@ public class MatrixOP extends Vector<Vector<Integer>> {
}
}
mul = (m1, m2) -> {
Fun2$$<java.util.Vector<java.util.Vector<java.lang.Integer>>, java.util.Vector<java.util.Vector<java.lang.Integer>>, MatrixOP> mul = (m1, m2) -> {
var ret = new MatrixOP();
var i = 0;
while(i < size()) {
while(i < m1.size()) {
var v1 = m1.elementAt(i);
var v2 = new Vector<Integer>();
var j = 0;

View File

@ -14,10 +14,10 @@ sort(in){
return merge(sort(firstHalf), sort(secondHalf));
}
*/
/*
void sort(ArrayList<String> a){
void sort(a){
a = merge(a,a);
}
*/
}

View File

@ -1,13 +1,14 @@
import java.lang.Integer;
class Faculty {
Integer mul(Integer x, Integer y) {
//fact;
Integer mul(Integer x, Integer y) {
return x;
}
m () {
var fact = (Integer x) -> {
var fact = (Integer x) -> {
return mul(x, fact.apply(x));
};
return fact;

View File

@ -1,13 +1,8 @@
class MathStruc <A> {
class mathStruc<A> {
A model;
innerOp = o -> ms -> new MathStruc<A>(o.apply(this.model, ms.model));
mathStruc(A a) { }
A model(){ A a; return a; }
methode(){
var innerOp = o -> ms ->
new mathStruc<A>(o.apply(this.model(),ms.model()));
return innerOp;
}
}
MathStruc(A m) { model=m; }
}