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 de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ASPStringConverter {
|
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){
|
public static String toConstant(JavaClassName name){
|
||||||
return toConstant(name.toString().replace(".", "_"));
|
return toConstant(name.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toConstant(String name){
|
public static String toConstant(String name){
|
||||||
return "c" + name.toString().replace(".", "_");
|
return "c" + replace(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String fromConstant(String s){
|
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.add(file.getPath());
|
||||||
}
|
}
|
||||||
commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList()));
|
commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList()));
|
||||||
|
|
||||||
Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start();
|
Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start();
|
||||||
InputStream output = clingo.getInputStream();
|
InputStream output = clingo.getInputStream();
|
||||||
clingo.waitFor();
|
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();
|
TypeConverter converter = new TypeConverter();
|
||||||
for(Pair fcp : fc){
|
for(Pair fcp : fc){
|
||||||
//Wenn dieser Cast fehlschlägt stimmt etwas nicht. Alle Paare in der FC müssen smaller Operatoren haen
|
//Wenn dieser Cast fehlschlägt stimmt etwas nicht. Alle Paare in der FC müssen smaller Operatoren haen
|
||||||
ASPPairSmaller fcEntry = (ASPPairSmaller) convert(fcp);
|
convert(fcp);
|
||||||
writer.add(new ASPStatement(fcEntry.toASP()));
|
|
||||||
}
|
}
|
||||||
for(Pair cons : constraintSet){
|
for(Pair cons : constraintSet){
|
||||||
writer.add(new ASPStatement(convert(cons).toASP()));
|
convert(cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
return writer.getASPFile();
|
return writer.getASPFile();
|
||||||
@ -88,7 +87,7 @@ public class ASPGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ASPType visit(TypePlaceholder typePlaceholder) {
|
public ASPType visit(TypePlaceholder typePlaceholder) {
|
||||||
return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()));
|
return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()),writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||||
|
|
||||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||||
|
|
||||||
public class ASPGenericType implements ASPType{
|
public class ASPGenericType implements ASPType{
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -13,9 +14,8 @@ public class ASPGenericType implements ASPType{
|
|||||||
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String toASP() {
|
||||||
public String toASP() {
|
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||||
return toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,11 +9,10 @@ public abstract class ASPPair {
|
|||||||
public ASPPair(ASPType ls, ASPType rs, ASPWriter writer){
|
public ASPPair(ASPType ls, ASPType rs, ASPWriter writer){
|
||||||
this.leftSide = ls;
|
this.leftSide = ls;
|
||||||
this.rightSide = rs;
|
this.rightSide = rs;
|
||||||
writer.add(new ASPStatement(ls.toASP()));
|
writer.add(new ASPStatement(toASP()));
|
||||||
writer.add(new ASPStatement(rs.toASP()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toASP(){
|
private String toASP(){
|
||||||
return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")";
|
return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class ASPParameterList {
|
|||||||
if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||||
param += nextPointer;
|
param += nextPointer;
|
||||||
writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")"));
|
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++;
|
paramNum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,6 @@ public class ASPRefType implements ASPType {
|
|||||||
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
|
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toASP() {
|
|
||||||
return toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPointer() {
|
public String getPointer() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||||
|
|
||||||
public interface ASPType {
|
public interface ASPType {
|
||||||
String toASP();
|
|
||||||
|
|
||||||
String getPointer();
|
String getPointer();
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||||
|
|
||||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||||
|
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||||
|
|
||||||
public class ASPTypeVar implements ASPType{
|
public class ASPTypeVar implements ASPType{
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public ASPTypeVar(String name){
|
public ASPTypeVar(String name, ASPWriter writer){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
writer.add(new ASPStatement(this.toASP()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ASPRule.ASP_TYPE_VAR+"("+ name +")";
|
return toASP();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String toASP() {
|
||||||
public String toASP() {
|
return ASPRule.ASP_TYPE_VAR+"("+ name +")";
|
||||||
return toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,12 +49,10 @@ public class ASTFactory {
|
|||||||
parameterSuperClass = (ParameterizedType) tempSuperClass;
|
parameterSuperClass = (ParameterizedType) tempSuperClass;
|
||||||
java.lang.Class superjreClass = jreClass.getSuperclass();
|
java.lang.Class superjreClass = jreClass.getSuperclass();
|
||||||
RefType superClass;
|
RefType superClass;
|
||||||
if(superjreClass != null){
|
if(parameterSuperClass != null){
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
superClass = (RefType) convertType(parameterSuperClass);
|
||||||
for(TypeVariable tv : superjreClass.getTypeParameters()){
|
}else if(superjreClass != null){
|
||||||
params.add(new GenericRefType(tv.getName(), new NullToken()));
|
superClass = (RefType) convertType(superjreClass);
|
||||||
}
|
|
||||||
superClass = new RefType(new JavaClassName(superjreClass.getName()), params, new NullToken());
|
|
||||||
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
|
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
|
||||||
superClass = (RefType) createType(java.lang.Object.class, name, "");
|
superClass = (RefType) createType(java.lang.Object.class, name, "");
|
||||||
}
|
}
|
||||||
@ -70,19 +68,24 @@ public class ASTFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RefTypeOrTPHOrWildcardOrGeneric convertType(Type type){
|
private static RefTypeOrTPHOrWildcardOrGeneric convertType(Type type){
|
||||||
JavaClassName name = null;
|
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
|
||||||
if(type instanceof ParameterizedType){
|
if(type instanceof ParameterizedType){
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
for(Type paramType : ((ParameterizedType)type).getActualTypeArguments()){
|
for(Type paramType : ((ParameterizedType)type).getActualTypeArguments()){
|
||||||
params.add(convertType(paramType));
|
params.add(convertType(paramType));
|
||||||
}
|
}
|
||||||
|
JavaClassName name = new JavaClassName(((ParameterizedType) type).getRawType().getTypeName());
|
||||||
|
return new RefType(name, params, new NullToken());
|
||||||
}else if(type instanceof TypeVariable){
|
}else if(type instanceof TypeVariable){
|
||||||
|
return new GenericRefType(((TypeVariable) type).getName(), new NullToken());
|
||||||
}else if(type instanceof Class){
|
}else if(type instanceof Class){
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
Class paramClass = (Class) type;
|
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();
|
}else throw new NotImplementedException();
|
||||||
return new RefType(name, params, new NullToken());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
|
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 {
|
public void adapt() throws InterruptedException, IOException, ClassNotFoundException {
|
||||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> list = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
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());
|
RefType t2 = new RefType(new JavaClassName("Vector"), list, new NullToken());
|
||||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
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 {
|
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{
|
public class LamRunnable{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user