forked from JavaTX/JavaCompilerCore
Erste Version von ASPFactory implementieren
This commit is contained in:
parent
284af1246b
commit
c4aec8379e
@ -1,16 +1,125 @@
|
||||
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.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
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.Collection;
|
||||
import java.util.*;
|
||||
|
||||
public class ASPFactory {
|
||||
public static String convertFC(Collection<ClassOrInterface> classes){
|
||||
return null; //TODO
|
||||
public class ASPFactory implements TypeVisitor<String>{
|
||||
|
||||
public String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException{
|
||||
ASPFactory factory = new ASPFactory();
|
||||
convertFC(fcClasses);
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
for(Pair p : constraint){
|
||||
convertPair(p);
|
||||
}
|
||||
}
|
||||
|
||||
return writer.getASPFile();
|
||||
}
|
||||
|
||||
public static String convert(RefType t){
|
||||
return null; //TODO
|
||||
ASPWriter writer = new ASPWriter();
|
||||
|
||||
private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
|
||||
Set<Pair> fc = FCGenerator.toFC(classes);
|
||||
for(Pair fcp : fc){
|
||||
convertPair(fcp);
|
||||
}
|
||||
}
|
||||
|
||||
private void convertPair(Pair p){
|
||||
String ls = p.TA1.acceptTV(this);
|
||||
String rs = p.TA2.acceptTV(this);
|
||||
ASPStatement pairStmt = null;
|
||||
if(p.GetOperator().equals(PairOperator.SMALLERDOT)){
|
||||
pairStmt = makeStatement(ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)){
|
||||
pairStmt = makeStatement(ASPRule.ASP_PAIR_EQUALS_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
|
||||
pairStmt = makeStatement(ASPRule.ASP_PAIR_SMALLER_NAME.toString(), ls, rs);
|
||||
}else throw new NotImplementedException();
|
||||
writer.add(pairStmt);
|
||||
}
|
||||
|
||||
private ASPStatement makeStatement(String rule, String... params){
|
||||
String stmt = rule + "(";
|
||||
for(String param : params){
|
||||
stmt += param + ",";
|
||||
}
|
||||
stmt = stmt.substring(0,stmt.length()-1);
|
||||
stmt += ")";
|
||||
return new ASPStatement(stmt);
|
||||
}
|
||||
|
||||
private String convertParameterlist(List<String> pointers){
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
Iterator<String> it = pointers.iterator();
|
||||
String p = pointer;
|
||||
while (it.hasNext()){
|
||||
ASPStatement stmt;
|
||||
String type = it.next();
|
||||
String nextP = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
if(it.hasNext()){
|
||||
stmt = makeStatement(ASPRule.ASP_PARAMLIST_NAME.toString(), p, type, nextP);
|
||||
}else{
|
||||
stmt = makeStatement(ASPRule.ASP_PARAMLIST_NAME.toString(), p, type,
|
||||
ASPRule.ASP_PARAMLIST_END_POINTER.toString());
|
||||
}
|
||||
p = nextP;
|
||||
writer.add(stmt);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
List<String> params = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||
params.add(param.acceptTV(this));
|
||||
}
|
||||
String typeName = ASPStringConverter.toConstant(refType.getName());
|
||||
ASPStatement stmt = makeStatement(ASPRule.ASP_TYPE.toString(), pointer, typeName, convertParameterlist(params));
|
||||
writer.add(stmt);
|
||||
return pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
String name = ASPStringConverter.toConstant(typePlaceholder.getName());
|
||||
ASPStatement stmt = makeStatement(ASPRule.ASP_TYPE_VAR.toString(), name);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user