Aufräumen

This commit is contained in:
JanUlrich 2018-03-07 22:42:05 +01:00
parent 095f9a7956
commit e8388e2748
14 changed files with 1 additions and 326 deletions

View File

@ -4,18 +4,12 @@ import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import java.util.*;

View File

@ -1,104 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.writer.model.*;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class ASPGenerator {
ASPWriter writer = new ASPWriter();
/*
public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException {
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
List<Pair> constraintPairs = new ArrayList<>();
for(Constraint<Pair> constraint : constraints1){
constraintPairs.addAll(constraint);
}
asp = toASP(constraintPairs, FCGenerator.toFC(fcClasses));
}
*/
public String getASP(){
return "";
}
private String toASP(List<Pair> constraintSet, Collection<Pair> fc){
TypeConverter converter = new TypeConverter();
for(Pair fcp : fc){
//Wenn dieser Cast fehlschlägt stimmt etwas nicht. Alle Paare in der FC müssen smaller Operatoren haen
convert(fcp);
}
for(Pair cons : constraintSet){
convert(cons);
}
return writer.getASPFile();
}
private ASPPair convert(Pair pair){
TypeConverter converter = new TypeConverter();
ASPType ls = pair.TA1.acceptTV(converter);
ASPType rs = pair.TA2.acceptTV(converter);
if(pair.OperatorEqual()){
return new ASPPairEquals(ls, rs,writer);
}else if(pair.OperatorSmallerDot()){
return new ASPPairSmallerDot(ls, rs, writer);
}else if(pair.OperatorSmaller()){
//Diese Cast müssen auch immer funktionieren, da in smaller Constraints nur RefTypes vorkommen
return new ASPPairSmaller(new ASPFCType((ASPRefType) ls), new ASPFCType((ASPRefType) rs), writer);
}else throw new NotImplementedException();
}
private ASPRefType convert(ClassOrInterface cl){
List<ASPType> paramList = new ArrayList<>();
for(GenericTypeVar gtv : cl.getGenerics()){
paramList.add(new ASPGenericType(ASPStringConverter.toConstant(gtv.getName())));
}
ASPParameterList params = new ASPParameterList(paramList, writer);
return new ASPRefType(ASPStringConverter.toConstant(cl.getClassName()), params);
}
private class TypeConverter implements TypeVisitor<ASPType>{
@Override
public ASPType visit(RefType type) {
List<ASPType> paramList = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric gtv : type.getParaList()){
paramList.add(gtv.acceptTV(this));
}
ASPParameterList params = new ASPParameterList(paramList, writer);
return new ASPRefType(ASPStringConverter.toConstant(type.getName()), params);
}
@Override
public ASPType visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public ASPType visit(TypePlaceholder typePlaceholder) {
return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()),writer);
}
@Override
public ASPType visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public ASPType visit(GenericRefType genericRefType) {
return new ASPRefType(ASPStringConverter.toConstant(genericRefType.getParsedName()),
new ASPParameterList(new ArrayList<>(), writer));
}
}
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.sat.asp.writer.model;
package de.dhbwstuttgart.sat.asp.writer;
public class ASPStatement {
private final String stmt;

View File

@ -1,7 +1,5 @@
package de.dhbwstuttgart.sat.asp.writer;
import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement;
import java.util.HashSet;
public class ASPWriter {

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
public class ASPFCType extends ASPRefType {
public ASPFCType(ASPRefType refType){
super(refType.name, refType.params);
}
public String toString(){
return ASPRule.ASP_FCTYPE + "(" + name +"," + params.name + ")";
}
}

View File

@ -1,25 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
public class ASPGenericType implements ASPType{
private final String name;
public ASPGenericType(String name){
this.name = name;
}
public String toString(){
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
}
private String toASP() {
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
}
@Override
public String getPointer() {
return name;
}
}

View File

@ -1,24 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
public abstract class ASPPair {
public final ASPType leftSide;
public final ASPType rightSide;
public ASPPair(ASPType ls, ASPType rs, ASPWriter writer){
this.leftSide = ls;
this.rightSide = rs;
writer.add(new ASPStatement(toASP()));
}
private String toASP(){
return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")";
}
public String toString(){
return toASP();
}
protected abstract String getRuleName();
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
public class ASPPairEquals extends ASPPair{
public ASPPairEquals(ASPType ls, ASPType rs, ASPWriter writer){
super(ls, rs, writer);
}
@Override
protected String getRuleName() {
return ASPRule.ASP_PAIR_EQUALS_NAME.toString();
}
}

View File

@ -1,17 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
import java.util.Map;
public class ASPPairSmaller extends ASPPair{
public ASPPairSmaller(ASPFCType ls, ASPFCType rs, ASPWriter writer){
super(ls, rs, writer);
}
@Override
protected String getRuleName() {
return ASPRule.ASP_PAIR_SMALLER_NAME.toString();
}
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
public class ASPPairSmallerDot extends ASPPair{
public ASPPairSmallerDot(ASPType ls, ASPType rs, ASPWriter writer){
super(ls, rs, writer);
}
@Override
protected String getRuleName() {
return ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString();
}
}

View File

@ -1,45 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import java.util.Iterator;
import java.util.List;
public class ASPParameterList {
public final String name;
private final List<ASPType> types;
public ASPParameterList(List<ASPType> types, ASPWriter writer){
int paramNum = 0;
this.types = types;
if(types.size() == 0){
name = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
}else{
name = newName();
String nextPointer = name;
Iterator<ASPType> it = types.iterator();
while(it.hasNext()){
ASPType t = it.next();
String param = nextPointer + "," + t.toString() + ",";
nextPointer = newName();
if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
param += nextPointer;
writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")"));
writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," + t.getPointer() + "," + paramNum + ")"));
paramNum++;
}
}
}
private String newName() {
return ASPStringConverter.toConstant(NameGenerator.makeNewName());
}
public String toString(){
return name;
}
}

View File

@ -1,26 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
public class ASPRefType implements ASPType {
protected final ASPParameterList params;
protected final String name;
public ASPRefType(String name, ASPParameterList params){
this.name = name;
this.params = params;
}
public ASPParameterList getParams() {
return params;
}
public String toString(){
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
}
@Override
public String getPointer() {
return name;
}
}

View File

@ -1,5 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
public interface ASPType {
String getPointer();
}

View File

@ -1,27 +0,0 @@
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
public class ASPTypeVar implements ASPType{
private final String name;
public ASPTypeVar(String name, ASPWriter writer){
this.name = name;
writer.add(new ASPStatement(this.toASP()));
}
@Override
public String toString() {
return toASP();
}
private String toASP() {
return ASPRule.ASP_TYPE_VAR+"("+ name +")";
}
@Override
public String getPointer() {
return name;
}
}