forked from JavaTX/JavaCompilerCore
Nicht lauffähig. ASPFactory neu implementieren
This commit is contained in:
parent
ab37e1a607
commit
284af1246b
@ -2,16 +2,39 @@ package de.dhbwstuttgart.sat.asp;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ASPStringConverter {
|
||||
private static final Map<String, String> replacements = new HashMap<>();
|
||||
static{
|
||||
replacements.put(".", "_DOT_");
|
||||
replacements.put("$", "_DOLLAR_");
|
||||
}
|
||||
|
||||
public static String toConstant(JavaClassName name){
|
||||
return toConstant(name.toString().replace(".", "_"));
|
||||
return toConstant(name.toString());
|
||||
}
|
||||
|
||||
public static String toConstant(String name){
|
||||
return "c" + name.toString().replace(".", "_");
|
||||
return "c" + replace(name);
|
||||
}
|
||||
|
||||
public static String fromConstant(String s){
|
||||
return s.replace("_", ".").substring(1);
|
||||
return unReplace(s).substring(1);
|
||||
}
|
||||
|
||||
private static String replace(String input){
|
||||
for(String toReplace : replacements.keySet()){
|
||||
input = input.replace(toReplace, replacements.get(toReplace));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
private static String unReplace(String input){
|
||||
for(String toReplace : replacements.keySet()){
|
||||
input = input.replace(replacements.get(toReplace), toReplace);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class Clingo {
|
||||
commands.add(file.getPath());
|
||||
}
|
||||
commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList()));
|
||||
|
||||
Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start();
|
||||
InputStream output = clingo.getInputStream();
|
||||
clingo.waitFor();
|
||||
|
16
src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java
Normal file
16
src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java
Normal file
@ -0,0 +1,16 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ASPFactory {
|
||||
public static String convertFC(Collection<ClassOrInterface> classes){
|
||||
return null; //TODO
|
||||
}
|
||||
|
||||
public static String convert(RefType t){
|
||||
return null; //TODO
|
||||
}
|
||||
}
|
@ -36,11 +36,10 @@ public class ASPGenerator {
|
||||
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
|
||||
ASPPairSmaller fcEntry = (ASPPairSmaller) convert(fcp);
|
||||
writer.add(new ASPStatement(fcEntry.toASP()));
|
||||
convert(fcp);
|
||||
}
|
||||
for(Pair cons : constraintSet){
|
||||
writer.add(new ASPStatement(convert(cons).toASP()));
|
||||
convert(cons);
|
||||
}
|
||||
|
||||
return writer.getASPFile();
|
||||
@ -88,7 +87,7 @@ public class ASPGenerator {
|
||||
|
||||
@Override
|
||||
public ASPType visit(TypePlaceholder typePlaceholder) {
|
||||
return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()));
|
||||
return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()),writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -13,9 +14,8 @@ public class ASPGenericType implements ASPType{
|
||||
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
private String toASP() {
|
||||
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,11 +9,10 @@ public abstract class ASPPair {
|
||||
public ASPPair(ASPType ls, ASPType rs, ASPWriter writer){
|
||||
this.leftSide = ls;
|
||||
this.rightSide = rs;
|
||||
writer.add(new ASPStatement(ls.toASP()));
|
||||
writer.add(new ASPStatement(rs.toASP()));
|
||||
writer.add(new ASPStatement(toASP()));
|
||||
}
|
||||
|
||||
public String toASP(){
|
||||
private String toASP(){
|
||||
return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")";
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ASPParameterList {
|
||||
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 + "," + paramNum + ")"));
|
||||
writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," + t.getPointer() + "," + paramNum + ")"));
|
||||
paramNum++;
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,6 @@ public class ASPRefType implements ASPType {
|
||||
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
public interface ASPType {
|
||||
String toASP();
|
||||
|
||||
String getPointer();
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
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){
|
||||
public ASPTypeVar(String name, ASPWriter writer){
|
||||
this.name = name;
|
||||
writer.add(new ASPStatement(this.toASP()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ASPRule.ASP_TYPE_VAR+"("+ name +")";
|
||||
return toASP();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
private String toASP() {
|
||||
return ASPRule.ASP_TYPE_VAR+"("+ name +")";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,12 +49,10 @@ public class ASTFactory {
|
||||
parameterSuperClass = (ParameterizedType) tempSuperClass;
|
||||
java.lang.Class superjreClass = jreClass.getSuperclass();
|
||||
RefType superClass;
|
||||
if(superjreClass != null){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(TypeVariable tv : superjreClass.getTypeParameters()){
|
||||
params.add(new GenericRefType(tv.getName(), new NullToken()));
|
||||
}
|
||||
superClass = new RefType(new JavaClassName(superjreClass.getName()), params, new NullToken());
|
||||
if(parameterSuperClass != null){
|
||||
superClass = (RefType) convertType(parameterSuperClass);
|
||||
}else if(superjreClass != null){
|
||||
superClass = (RefType) convertType(superjreClass);
|
||||
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
|
||||
superClass = (RefType) createType(java.lang.Object.class, name, "");
|
||||
}
|
||||
@ -70,19 +68,24 @@ public class ASTFactory {
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convertType(Type type){
|
||||
JavaClassName name = null;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
if(type instanceof ParameterizedType){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(Type paramType : ((ParameterizedType)type).getActualTypeArguments()){
|
||||
params.add(convertType(paramType));
|
||||
}
|
||||
JavaClassName name = new JavaClassName(((ParameterizedType) type).getRawType().getTypeName());
|
||||
return new RefType(name, params, new NullToken());
|
||||
}else if(type instanceof TypeVariable){
|
||||
|
||||
return new GenericRefType(((TypeVariable) type).getName(), new NullToken());
|
||||
}else if(type instanceof Class){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
Class paramClass = (Class) type;
|
||||
//params.add(new RefType(paramClass.getName())
|
||||
for(TypeVariable tv : paramClass.getTypeParameters()){
|
||||
params.add(new GenericRefType(tv.getName(), new NullToken()));
|
||||
}
|
||||
JavaClassName name = new JavaClassName(paramClass.getName());
|
||||
return new RefType(name, params, new NullToken());
|
||||
}else throw new NotImplementedException();
|
||||
return new RefType(name, params, new NullToken());
|
||||
}
|
||||
|
||||
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
|
||||
|
@ -28,10 +28,11 @@ public class UnifyWithoutWildcards {
|
||||
public void adapt() throws InterruptedException, IOException, ClassNotFoundException {
|
||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||
RefType t1 = new RefType(new JavaClassName("Matrix"), new NullToken());
|
||||
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("Vector"), list, new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
run(testSet);
|
||||
ResultSet resultSet = run(testSet);
|
||||
System.out.println(resultSet);
|
||||
}
|
||||
|
||||
public ResultSet run(ConstraintSet<Pair> toTest) throws IOException, InterruptedException, ClassNotFoundException {
|
||||
|
@ -1,3 +1,6 @@
|
||||
import java.lang.Runnable;
|
||||
import java.lang.String;
|
||||
import java.lang.System;
|
||||
|
||||
public class LamRunnable{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user