new Operator funktioniert jetzt, TypeVars werden mit einem speziellen Constraint durchgeschleußt an construct vorbei, wahrscheinlich die beste lösung bis jetzt

This commit is contained in:
sebastian 2017-04-22 03:39:14 +02:00
parent bd8cf2959f
commit 7fb439e65d
24 changed files with 1603 additions and 625 deletions

1220
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@ -5,13 +5,23 @@ package de.dhbwstuttgart.strucTypes5.algo;
*/
import com.google.common.collect.Constraint;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintField;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintMethod;
import de.dhbwstuttgart.strucTypes5.typeVars.GenericNames;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typecheck.JavaClassName;
import java.util.*;
@ -35,9 +45,8 @@ public class Construct {
// Generate a Interface for every StructuralType
for (TypeVar typeVar : constraintSet.keySet()) {
interfaceList.add(generateInterface(constraintSet.get(typeVar)));
interfaceList.add(generateInterface(typeVar , constraintSet.get(typeVar)));
}
}
@ -57,6 +66,7 @@ public class Construct {
Map<TypeVar, Set<ConstraintAbstract>> sortetConstraints = new HashMap<>();
for (ConstraintAbstract constraint : constraints) {
if (constraint instanceof ConstraintMethod) {
ConstraintMethod constraintMethod = (ConstraintMethod) constraint;
@ -65,10 +75,26 @@ public class Construct {
}
else {
Set<ConstraintAbstract> constraintSet = new HashSet<>();
constraintSet.add(constraint);
sortetConstraints.put(constraintMethod.getReceiver() , constraintSet);
}
}
else if (constraint instanceof ConstraintField ) {
ConstraintField constraintField = (ConstraintField) constraint;
if (sortetConstraints.containsKey(constraintField.getReceiver())) {
sortetConstraints.get(constraintField.getReceiver()).add(constraintField);
}
else {
Set<ConstraintAbstract> constraintSet = new HashSet<>();
constraintSet.add(constraint);
sortetConstraints.put(constraintField.getReceiver() , constraintSet);
}
}
else {
remainingConstraints.add(constraint);
}
@ -79,15 +105,72 @@ public class Construct {
/**
* Method Generates Interfaces for the Structural Type.
* The Method also adds the new Constraints to the remainung Constraints List.
* The Method also adds the new Constraints to the remaining Constraints List.
*
*/
private ClassOrInterface generateInterface(Set<ConstraintAbstract> constraintSet) {
private ClassOrInterface generateInterface(TypeVar receiver , Set<ConstraintAbstract> constraintSet) {
List<Field> fields = new ArrayList<>();
List<Method> methods = new ArrayList<>();
List<GenericTypeVar> genericRefTypes = new ArrayList<>();
GenericDeclarationList generics = new GenericDeclarationList(genericRefTypes , new NullToken());
for (ConstraintAbstract constraint : constraintSet) {
if (constraint instanceof ConstraintField) {
ConstraintField cf = (ConstraintField) constraint;
// Field(String name, RefTypeOrTPHOrWildcardOrGeneric type, int modifier, Token offset)
RefType refType = new RefType(new JavaClassName( cf.getReceiver().toString()), new NullToken());
Field newField = new Field(cf.getNameOfField() ,refType , 0, new NullToken() );
fields.add(newField);
}
else if (constraint instanceof ConstraintMethod) {
ConstraintMethod cm = (ConstraintMethod) constraint;
// public Method(String name, RefTypeOrTPHOrWildcardOrGeneric returnType, int modifiers, ParameterList parameterList, Block block,
//GenericDeclarationList gtvDeclarations, Token offset)
String name = cm.getMethodName();
RefType returnType = new RefType(new JavaClassName(GenericNames.makeNewGenericName()) , new NullToken() );
int modifers = 0;
List<FormalParameter> formalParameters = new ArrayList<>();
ParameterList parameterList = new ParameterList(formalParameters, new NullToken());
Block block = null;
GenericDeclarationList genericDeclarationList = null;
Method m = new Method(name, returnType, modifers, parameterList, block , genericDeclarationList, new NullToken());
methods.add(m);
}
}
//Konstruktor:
// public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, GenericDeclarationList genericClassParameters,
// RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildca
int modifers = 0;
JavaClassName name = new JavaClassName(receiver.toString());
// Fields and Methos from List
GenericDeclarationList genericClassParameters = null;
RefTypeOrTPHOrWildcardOrGeneric superClass = null;
Boolean isInterface = true;
List<RefTypeOrTPHOrWildcardOrGeneric> implementetInterfaces = new ArrayList<>();
ClassOrInterface newInterface = new ClassOrInterface(modifers, name, fields,methods, genericClassParameters, superClass , isInterface, implementetInterfaces ,new NullToken());
return newInterface;
}

View File

@ -0,0 +1,170 @@
package de.dhbwstuttgart.strucTypes5.algo;
/**
* Created by sebastian on 21.04.17.
*/
import de.dhbwstuttgart.strucTypes5.constraints.*;
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.FieldInterface;
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface;
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.MethodInterface;
import de.dhbwstuttgart.strucTypes5.typeVars.*;
import de.dhbwstuttgart.syntaxtree.*;
import java.util.*;
/**
* Takes a Typled Class and a Constraint Set for construct the Interfaces
* => typed class = cl + typVarStore + List with Constraints
*/
public class ConstructInterfaceTemplates {
List<Interface> interfaceList = new ArrayList<>();
List<ConstraintAbstract> remainingConstraints = new ArrayList<>();
public ConstructInterfaceTemplates(ClassOrInterface classOrInterface, TypeVarStore typeVarStore , List<ConstraintAbstract> constraints, MappingAltNeu mappingAltNeu) {
// Sort the Constriants
Map<TypeVar, Set<ConstraintAbstract>> constraintSet = sortConstriants(constraints, mappingAltNeu);
// Generate a Interface for every StructuralType
for (TypeVar typeVar : constraintSet.keySet()) {
interfaceList.add(generateInterface(typeVar , constraintSet.get(typeVar) , typeVarStore , mappingAltNeu));
}
}
/**
*
* @param constraints
* @return
*
* Method sortet Constraints for ReceiverType for the Structural Type.
* Other Constraints as the Field or MethodsConstraints are copied to the global List remainungConstraints
*
*/
private Map<TypeVar,Set<ConstraintAbstract>> sortConstriants(List<ConstraintAbstract> constraints , MappingAltNeu mappingAltNeu) {
Map<TypeVar, Set<ConstraintAbstract>> sortetConstraints = new HashMap<>();
for (ConstraintAbstract constraint : constraints) {
if (constraint instanceof ConstraintMethod) {
ConstraintMethod constraintMethod = (ConstraintMethod) constraint;
if (sortetConstraints.containsKey(constraintMethod.getReceiver())) {
sortetConstraints.get(constraintMethod.getReceiver()).add(constraintMethod);
}
else {
Set<ConstraintAbstract> constraintSet = new HashSet<>();
constraintSet.add(constraint);
sortetConstraints.put(constraintMethod.getReceiver() , constraintSet);
}
}
else if (constraint instanceof ConstraintField ) {
ConstraintField constraintField = (ConstraintField) constraint;
if (sortetConstraints.containsKey(constraintField.getReceiver())) {
sortetConstraints.get(constraintField.getReceiver()).add(constraintField);
}
else {
Set<ConstraintAbstract> constraintSet = new HashSet<>();
constraintSet.add(constraint);
sortetConstraints.put(constraintField.getReceiver() , constraintSet);
}
}
else if (constraint instanceof ConstraintSubType) {
ConstraintSubType constraintSubType = (ConstraintSubType) constraint;
TypeVar lower = (TypeVar) mappingAltNeu.getNeu(constraintSubType.getSubtype());
TypeVar higher = (TypeVar) mappingAltNeu.getNeu(constraintSubType.getSuperType());
remainingConstraints.add(new ConstraintSubType(lower , higher));
}
else {
System.out.println(constraint.getClass());
remainingConstraints.add(constraint);
}
}
return sortetConstraints;
}
/**
* Method Generates Interfaces for the Structural Type.
* The Method also adds the new Constraints to the remaining Constraints List.
*
*/
private Interface generateInterface(TypeVar receiver , Set<ConstraintAbstract> constraintSet , TypeVarStore typeVarStore , MappingAltNeu mappingAltNeu) {
List<FieldInterface> fields = new ArrayList<>();
List<MethodInterface> methods = new ArrayList<>();
List<TypeVarAbstract> generics = new ArrayList<>();
List<TypeVarAbstract> genericsForConstraint = new ArrayList<>();
for (ConstraintAbstract constraint : constraintSet) {
if (constraint instanceof ConstraintField) {
ConstraintField cf = (ConstraintField) constraint;
fields.add(new FieldInterface( typeVarStore.makeFreshTypeVar(), cf.getNameOfField() ));
// ToDo make constraint
}
else if (constraint instanceof ConstraintMethod) {
ConstraintMethod cm = (ConstraintMethod) constraint;
// Erstelle Generics für Constraint
genericsForConstraint.add(mappingAltNeu.getNeu(cm.getReturnType()));
for (TypeVar tv : cm.getArgumentTypesBeta()) {
genericsForConstraint.add(mappingAltNeu.getNeu(tv));
}
// Erstelle Generic für neuen Typvariablen für das Interface
List<TypeVarAbstract> args = new ArrayList<>();
for (TypeVar tv : cm.getArgumentTypes()) {
TypeVar generic = typeVarStore.makeFreshTypeVar();
args.add(generic);
}
TypeVar rtype = typeVarStore.makeFreshTypeVar();
MethodInterface methodInterface = new MethodInterface(cm.getMethodName(), rtype , args );
// Erstelle Generics für das Interface
generics.add(rtype);
generics.addAll(args);
methods.add(methodInterface);
}
}
TypeVar neuerTypeReveiver = (TypeVar) mappingAltNeu.getNeu(receiver);
InterfaceForConstraint interfaceForConstraint = new InterfaceForConstraint(receiver, genericsForConstraint);
remainingConstraints.add(new ConstraintSubTypeGeneric<>(neuerTypeReveiver , interfaceForConstraint ));
Interface newInterface = new Interface(receiver, fields, methods , generics);
return newInterface;
}
}

View File

@ -1,14 +1,26 @@
package de.dhbwstuttgart.strucTypes5.algo;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionClass;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class TI {
public AssumptionMap assresult;
// Start TypeInference Algorithm, need Assumptions and a Class
public TI(AssumptionMap ass , ClassOrInterface cl) {
@ -17,17 +29,41 @@ public class TI {
Type type = new Type(ass , cl, typeVarStore);
// Neue TypVariablen
ResultTuple tp = typeVarStore.freshVariableAndMapping();
// Construct soll die Interfaces erstellen
// Construct
// Solve
// Einfache Implementierung -> Es werden die erforderlichen Daten für die Constraits und Interface zusammengetragen
ConstructInterfaceTemplates constructInterfaceTemplates = new ConstructInterfaceTemplates(cl, tp.getTypeVarStore(), type.constraintList , tp.getMappingAltNeu());
System.out.println(constructInterfaceTemplates.interfaceList);
System.out.println(constructInterfaceTemplates.remainingConstraints);
// Generiere Generics für die Klasse
List<TypeVarAbstract> generics = new ArrayList<>();
for (Method m : cl.getMethods()) {
generics.add(tp.getTypeVarStore().getTypeVarByTPH(m.getType()));
for (FormalParameter fp : m.getParameterList().getFormalparalist()) {
generics.add(tp.getTypeVarStore().getTypeVarByTPH(fp.getType()));
}
}
// Assumption Map für weitere Anwendungen
AssumptionClass assumptionClass = new AssumptionClass(cl,tp.getTypeVarStore(),ass, constructInterfaceTemplates.remainingConstraints , constructInterfaceTemplates.interfaceList, generics);
AssumptionMap assumptionMapNew = new AssumptionMap();
assumptionMapNew.addAssumption(assumptionClass);
assresult = assumptionMapNew;
System.out.println(tp.getTypeVarStore());
}
}

View File

@ -1,11 +1,12 @@
package de.dhbwstuttgart.strucTypes5.algo;
import de.dhbwstuttgart.strucTypes3.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionClass;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintFactory;
import de.dhbwstuttgart.strucTypes5.constraints.*;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
@ -13,6 +14,8 @@ import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import java.util.ArrayList;
@ -85,6 +88,31 @@ public class TypeExpr {
for (Expression arg : methodCall.get_ArgList().getArguments()) {
result.addAll(typeExpression(arg));
}
// zuordnen der Variablen zu den ermittelten typen
AssumptionClass assumptionClass = assumptionMap.getClassAssumption(methodCall.get_Receiver().getType().toString());
if (assumptionClass != null) {
Method m = assumptionClass.getCl().getMethods().get(0);
for (int i = 0; i < methodCall.get_ArgList().getArguments().size() ; i++) {
// Verknüpfen von typeVar und typeVar
RefTypeOrTPHOrWildcardOrGeneric tmold = m.getParameterList().getFormalparalist().get(i).getType();
RefTypeOrTPHOrWildcardOrGeneric takt = methodCall.get_ArgList().getArguments().get(i).getType();
System.out.println(assumptionClass.getTypeVarStore().getTypeVarByTPH(tmold) + "<" + typeVarStore.getTypeVarByTPH(takt));
TypeVar x = (TypeVar) assumptionClass.getTypeVarStore().getTypeVarByTPH(tmold);
TypeVar y = (TypeVar) typeVarStore.getTypeVarByTPH(takt);
List<ConstraintAbstract> foroldConstraints = new ArrayList<>();
foroldConstraints.add(new ConstraintSubType(y,x));
OldConstraints oldConstraints = new OldConstraints(foroldConstraints);
result.add(oldConstraints);
}
}
return result;
}
else {
@ -94,13 +122,10 @@ public class TypeExpr {
for (Expression arg : methodCall.get_ArgList().getArguments()) {
result.addAll(typeExpression(arg));
}
result.addAll(ConstraintFactory.generateConstraintMethod(methodCall, typeVarStore));
return result;
}
}
else if (expression instanceof Receiver) {
Receiver receiver = (Receiver) expression;
@ -118,11 +143,21 @@ public class TypeExpr {
result.addAll(typeExpression(arg));
}
//typeVarStore.addTuple(TypeVarFactory.makeTypeVar() , newClass.getType());
System.out.println(newClass.getType());
System.out.println(newClass.getType().getClass());
//Versuche Informationen zu laden
AssumptionClass assumptionClass = assumptionMap.getClassAssumption(newClass.getType().toString());
if (assumptionClass != null) {
System.out.println("assumption gefunden");
OldConstraints oldConstraints= new OldConstraints(assumptionClass.getConstraints());
result.add(oldConstraints);
}
typeVarStore.addTuple(TypeVarFactory.makeTypeVar() , newClass.getType());
//
return result;
}
else {

View File

@ -1,7 +1,10 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes2.Assumptions_Map;
import de.dhbwstuttgart.strucTypes3.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
@ -10,26 +13,29 @@ import java.util.List;
/**
* Created by sebastian on 21.04.17.
*/
public class AssumptionClass extends AssumptionAbstract {
public class AssumptionClass extends AssumptionAbstract {
// Die Angaben entspreichen einer clT Klasse
private ClassOrInterface cl;
private TypeVarStore typeVarStore;
private Assumptions_Map assumptions_map;
private AssumptionMap assumptionMap;
private List<ConstraintAbstract> constraints;
private List<ClassOrInterface> generatedinterfaces;
private List<Interface> generatedinterfaces;
private List<TypeVarAbstract> genericsForClass;
public AssumptionClass(ClassOrInterface cl, TypeVarStore typeVarStore, Assumptions_Map assumptions_map, List<ConstraintAbstract> constraints, List<ClassOrInterface> generatedinterfaces) {
public AssumptionClass() {
}
public AssumptionClass(ClassOrInterface cl, TypeVarStore typeVarStore, AssumptionMap assumptionMap, List<ConstraintAbstract> constraints, List<Interface> generatedinterfaces, List<TypeVarAbstract> genericsForClass) {
this.cl = cl;
this.typeVarStore = typeVarStore;
this.assumptions_map = assumptions_map;
this.assumptionMap = assumptionMap;
this.constraints = constraints;
this.generatedinterfaces = generatedinterfaces;
this.genericsForClass = genericsForClass;
}
public AssumptionClass () {
}
public ClassOrInterface getCl() {
return cl;
@ -47,12 +53,12 @@ public class AssumptionClass extends AssumptionAbstract {
this.typeVarStore = typeVarStore;
}
public Assumptions_Map getAssumptions_map() {
return assumptions_map;
public AssumptionMap getAssumptionMap() {
return assumptionMap;
}
public void setAssumptions_map(Assumptions_Map assumptions_map) {
this.assumptions_map = assumptions_map;
public void setAssumptionMap(AssumptionMap assumptionMap) {
this.assumptionMap = assumptionMap;
}
public List<ConstraintAbstract> getConstraints() {
@ -63,12 +69,21 @@ public class AssumptionClass extends AssumptionAbstract {
this.constraints = constraints;
}
public List<ClassOrInterface> getGeneratedinterfaces() {
public List<Interface> getGeneratedinterfaces() {
return generatedinterfaces;
}
public void setGeneratedinterfaces(List<ClassOrInterface> generatedinterfaces) {
public void setGeneratedinterfaces(List<Interface> generatedinterfaces) {
this.generatedinterfaces = generatedinterfaces;
}
public List<TypeVarAbstract> getGenericsForClass() {
return genericsForClass;
}
public void setGenericsForClass(List<TypeVarAbstract> genericsForClass) {
this.genericsForClass = genericsForClass;
}
}

View File

@ -41,7 +41,8 @@ public class ConstraintFactory {
neueTypeVars.add(newVar);
typeVarsArg.add(oldVar);
ConstraintSubTypeGeneric<TypeVar,TypeVar> subTypeGeneric = new ConstraintSubTypeGeneric<>(newVar,oldVar);
//ConstraintSubTypeGeneric<TypeVar,TypeVar> subTypeGeneric = new ConstraintSubTypeGeneric<>(newVar,oldVar);
ConstraintSubType subTypeGeneric = new ConstraintSubType(oldVar, newVar);
resultConstraints.add(subTypeGeneric);
}
resultConstraints.add(new ConstraintMethod(receiver, methodCall.get_Name(), typeVarsArg, caller , neueTypeVars ));

View File

@ -15,6 +15,11 @@ public class ConstraintSubType extends ConstraintAbstract{
private TypeVar subtype;
private TypeVar superType;
public ConstraintSubType(TypeVar subtype, TypeVar superType) {
this.subtype = subtype;
this.superType = superType;
}
public TypeVar getSubtype() {
return subtype;
}

View File

@ -0,0 +1,42 @@
package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import java.util.List;
/**
* Created by sebastian on 21.04.17.
*/
public class InterfaceForConstraint {
private TypeVarAbstract strucType;
private List<TypeVarAbstract> generics;
public InterfaceForConstraint(TypeVarAbstract strucType, List<TypeVarAbstract> generics) {
this.strucType = strucType;
this.generics = generics;
}
public TypeVarAbstract getStrucType() {
return strucType;
}
public void setStrucType(TypeVarAbstract strucType) {
this.strucType = strucType;
}
public List<TypeVarAbstract> getGenerics() {
return generics;
}
public void setGenerics(List<TypeVarAbstract> generics) {
this.generics = generics;
}
@Override
public String toString() {
return String.format("sT %s <%s> " , strucType , generics);
}
}

View File

@ -0,0 +1,24 @@
package de.dhbwstuttgart.strucTypes5.constraints;
import java.util.List;
/**
* Created by sebastian on 22.04.17.
*/
/*
Soll Constraints durch die Construct methode schleusen
*/
public class OldConstraints extends ConstraintAbstract{
public List<ConstraintAbstract> constraintAbstractList;
public OldConstraints(List<ConstraintAbstract> constraintAbstractList) {
this.constraintAbstractList = constraintAbstractList;
}
@Override
public String toString() {
return constraintAbstractList.toString();
}
}

View File

@ -0,0 +1,44 @@
package de.dhbwstuttgart.strucTypes5.factoryForSyntaxtree;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
import de.dhbwstuttgart.syntaxtree.Generic;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typecheck.GenericTypeName;
import de.dhbwstuttgart.typecheck.JavaClassName;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 21.04.17.
*/
public class FactoryForElementes {
public static GenericTypeVar createGeneric(String nameOfGeneric) {
// Code der benötigt wird um ein Generic zu erstellen.
List<RefTypeOrTPHOrWildcardOrGeneric> list = new ArrayList<>();
GenericContext genericContext = new GenericContext(new JavaClassName("") , new String(""));
GenericTypeName genericTypeName = new GenericTypeName(genericContext,nameOfGeneric);
GenericTypeVar genericTypeVar = new GenericTypeVar( genericTypeName, list , new NullToken() , new NullToken());
return genericTypeVar;
}
public static GenericRefType createGenericRefType(String nameOfGeneric) {
GenericContext genericContext = new GenericContext(new JavaClassName("") , new String(""));
GenericTypeName genericTypeName = new GenericTypeName(genericContext,nameOfGeneric);
GenericRefType genericRefType = new GenericRefType( genericTypeName , new NullToken());
return genericRefType;
}
}

View File

@ -0,0 +1,40 @@
package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
/**
* Created by sebastian on 09.04.17.
*/
public class FieldInterface {
TypeVarAbstract type;
String name;
public FieldInterface(TypeVarAbstract type, String name) {
this.type = type;
this.name = name;
}
public TypeVarAbstract getType() {
return type;
}
public void setType(TypeVarAbstract type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return String.format("%s %s " , type , name );
}
}

View File

@ -0,0 +1,60 @@
package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import java.util.List;
/**
* Created by sebastian on 09.04.17.
*/
public class Interface {
TypeVarAbstract strucType;
List<FieldInterface> fields;
List<MethodInterface> methods;
List<TypeVarAbstract> generics;
public Interface(TypeVarAbstract strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<TypeVarAbstract> generics) {
this.strucType = strucType;
this.fields = fields;
this.methods = methods;
this.generics = generics;
}
public List<FieldInterface> getFields() {
return fields;
}
public void setFields(List<FieldInterface> fields) {
this.fields = fields;
}
public List<MethodInterface> getMethods() {
return methods;
}
public void setMethods(List<MethodInterface> methods) {
this.methods = methods;
}
public List<TypeVarAbstract> getGenerics() {
return generics;
}
public void setGenerics(List<TypeVarAbstract> generics) {
this.generics = generics;
}
@Override
public String toString() {
return String.format("interface %s < %s > { \n %s \n %s } \n \n " , strucType , generics, fields.toString() , methods.toString());
}
}

View File

@ -0,0 +1,54 @@
package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import java.util.List;
/**
* Created by sebastian on 09.04.17.
*/
public class MethodInterface {
String name;
TypeVarAbstract rtType;
List<TypeVarAbstract> argsTypes;
public MethodInterface(String name, TypeVarAbstract rtType, List<TypeVarAbstract> argsTypes) {
this.name = name;
this.rtType = rtType;
this.argsTypes = argsTypes;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public TypeVarAbstract getRtType() {
return rtType;
}
public void setRtType(TypeVarAbstract rtType) {
this.rtType = rtType;
}
public List<TypeVarAbstract> getArgsTypes() {
return argsTypes;
}
public void setArgsTypes(List<TypeVarAbstract> argsTypes) {
this.argsTypes = argsTypes;
}
@Override
public String toString() {
return String.format(" %s %s ( %s ); " , rtType, name, argsTypes.toString());
}
}

View File

@ -0,0 +1,21 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
/**
* Created by sebastian on 21.04.17.
*/
public class GenericNames {
private static Integer counter = new Integer(1);
public static String makeNewGenericName() {
return new String("G" + counter.toString());
}
}

View File

@ -0,0 +1,45 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 15.04.17.
*/
public class MappingAltNeu {
List<TypeVarAbstract> altList = new ArrayList<>();
List<TypeVarAbstract> neuList = new ArrayList<>();
public void addTypeVar(TypeVarAbstract alt, TypeVarAbstract neu) {
altList.add(alt);
// Versuch bereits bekannte Typen mitzunehmen
// geht nur wenn dies auch dem TypeVarStore bekannt ist
if (alt.getClass().equals(TypeVarType.class)) {
neuList.add(alt);
}
else {
neuList.add(neu);
}
}
public TypeVarAbstract getNeu (TypeVarAbstract altTypeVar) {
// Wenn typ bereits bekannt ist
//if (altTypeVar.getClass().equals(TypeVarType.class)) {
// return altTypeVar;
//}
// Typvariable nicht bekannt
//if ( ! neuList.contains(altTypeVar)) {
// return altTypeVar;
//}
//System.out.println(altTypeVar);
return neuList.get(altList.indexOf(altTypeVar));
}
}

View File

@ -0,0 +1,36 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
/**
* Created by sebastian on 15.04.17.
*/
public class ResultTuple {
public MappingAltNeu mappingAltNeu;
public TypeVarStore typeVarStore;
public ResultTuple(MappingAltNeu mappingAltNeu, TypeVarStore typeVarStore) {
this.mappingAltNeu = mappingAltNeu;
this.typeVarStore = typeVarStore;
}
public MappingAltNeu getMappingAltNeu() {
return mappingAltNeu;
}
public void setMappingAltNeu(MappingAltNeu mappingAltNeu) {
this.mappingAltNeu = mappingAltNeu;
}
public TypeVarStore getTypeVarStore() {
return typeVarStore;
}
public void setTypeVarStore(TypeVarStore typeVarStore) {
this.typeVarStore = typeVarStore;
}
}

View File

@ -14,7 +14,7 @@ public class TypeVar extends TypeVarAbstract {
@Override
public String toString() {
return String.format("TVar: %s" , id);
return String.format("TVar_%s" , id);
}
@Override

View File

@ -95,7 +95,7 @@ public class TypeVarStore {
}
/*
public ResultTuple freshVariableAndMapping() {
MappingAltNeu mappingAltNeu = new MappingAltNeu();
@ -135,7 +135,7 @@ public class TypeVarStore {
}
}
*/

View File

@ -0,0 +1,13 @@
class A {
Integer i;
mt(x,y,z) { return x.sub(y).add(z); }
}

View File

@ -0,0 +1,101 @@
package strucTypes5;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
import de.dhbwstuttgart.strucTypes5.algo.TI;
import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.algo.TypeExpr;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerGlobal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typecheck.GenericTypeName;
import de.dhbwstuttgart.typecheck.JavaClassName;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class ConstructTest {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("ConstructTest.jav");
JavaTXParser parser = new JavaTXParser();
try {
for (String filename : filenames) {
System.out.println("Teste: " + filename);
SourceFile sf = parser.parse(new File(rootDirectory + filename));
/*
// Test of the Global Assumption Maker who make mass und fass;
TypeVarStore typeVarStore = new TypeVarStore();
AssumptionMakerGlobal makerGlobal = new AssumptionMakerGlobal(sf.getClasses().get(0), typeVarStore );
System.out.println(typeVarStore.toString());
System.out.println(makerGlobal.getAssumptionAbstractList().toString()) ;
// Test of the Local AssumptionMaker who only makes the Assumption for an Local Method;
AssumptionMakerLocal assumptionMakerLocal = new AssumptionMakerLocal(sf.getClasses().get(0).getMethods().get(0) , typeVarStore);
System.out.println(assumptionMakerLocal.getResultAssumptionList());
List<AssumptionAbstract> assAll = new ArrayList<>();
assAll.addAll(assumptionMakerLocal.getResultAssumptionList());
assAll.addAll(makerGlobal.getAssumptionAbstractList());
AssumptionMap assumptionMap = new AssumptionMap();
assumptionMap.addAll(assAll);
*/
ClassOrInterface clA = sf.getClasses().get(0);
AssumptionMap map = new AssumptionMap();
TI ti = new TI(map , clA);
// Code der benötigt wird um ein Generic zu erstellen.
List<RefTypeOrTPHOrWildcardOrGeneric> list = new ArrayList<>();
GenericContext genericContext = new GenericContext(new JavaClassName("") , new String(""));
GenericTypeName genericTypeName = new GenericTypeName(genericContext,"nameOfGeneric");
GenericTypeVar genericTypeVar = new GenericTypeVar( genericTypeName, list , new NullToken() , new NullToken());
System.out.println(genericTypeVar);
//
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}

View File

@ -6,7 +6,9 @@ main () { return new A().mt(new Main() , new A() , new A() ); }
}
class A {
class A{
}

View File

@ -0,0 +1,20 @@
class Main {
main () { return new A().mt( new MyInteger() , new MyInteger() , new MyInteger() ); }
}
class A{
mt(x,y,z) { return x.sub(y).add(z); }
}
class MyInteger {
}

View File

@ -0,0 +1,83 @@
package strucTypes5;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.strucTypes5.algo.TI;
import de.dhbwstuttgart.strucTypes5.algo.TypeExpr;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerGlobal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.strucTypes5.ausgabe.Class2String;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class NewOperatorTest2 {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("NewOperatorTest2.jav");
JavaTXParser parser = new JavaTXParser();
try {
for (String filename : filenames) {
System.out.println("Teste: " + filename);
SourceFile sf = parser.parse(new File(rootDirectory + filename));
SourceFile sfdebug = sf;
ClassOrInterface mainClass = sf.getClasses().get(0);
ClassOrInterface aClass = sf.getClasses().get(1);
AssumptionMap assumptionMap = new AssumptionMap();
TI ti = new TI(assumptionMap, aClass);
TI ti1 = new TI(ti.assresult, mainClass);
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}