ResultSetOutputGenerator

This commit is contained in:
JanUlrich 2018-03-12 00:38:02 +01:00
parent 83aaff140c
commit dff72b0c97
4 changed files with 66 additions and 12 deletions

View File

@ -130,6 +130,7 @@ public class ASPParser {
}
}
private void parseParameter(String statement){
//param(pointer, typ, nextPointer
Pattern p = Pattern.compile(ASPRule.ASP_PARAMLIST_NAME+"\\(([^,]+),([^,]+),([^,]+)\\)");
Matcher m = p.matcher(statement);
boolean b = m.matches();
@ -137,7 +138,7 @@ public class ASPParser {
if(m.groupCount()<3)throw new DebugException("Fehler in Regex");
String pointer = m.group(1);
String type = m.group(2);
String next = m.group(2);
String next = m.group(3);
if(next.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))next = null;
if(this.parameterLists.containsKey(pointer)){
throw new DebugException("Fehler in Ergebnisparsen");
@ -158,20 +159,18 @@ public class ASPParser {
}
private void parseType(String statement){
//TODO: Diese Regel muss 3 Parameter parsen (TypPointer, TypName, ParameterlistenPointer)
throw new NotImplementedException();
/*
Pattern p = Pattern.compile(ASPRule.ASP_TYPE+"\\(([^,]+),([^,]+)\\)");
//Diese Regel muss 3 Parameter parsen (TypPointer, TypName, ParameterlistenPointer)
Pattern p = Pattern.compile(ASPRule.ASP_TYPE+"\\(([^,]+),([^,]+),([^,]+)\\)");
Matcher m = p.matcher(statement);
boolean b = m.matches();
if(b){
if(m.groupCount()<2)throw new DebugException("Fehler in Regex");
String ls = m.group(1);
String rs = m.group(2);
List<String> params = this.getParams(rs);
this.types.put(ls,new ParsedType(ls, params));
if(m.groupCount()<3)throw new DebugException("Fehler in Regex");
String pointer = m.group(1);
String name = m.group(2);
String paraList = m.group(3);
List<String> params = this.getParams(paraList);
this.types.put(pointer,new ParsedType(name, params));
}
*/
}
private List<String> getParams(String pointer) {

View File

@ -0,0 +1,34 @@
package de.dhbwstuttgart.syntaxtree.visual;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.result.*;
public class ResultSetOutputGenerator extends OutputGenerator implements ResultSetVisitor{
public ResultSetOutputGenerator(StringBuilder out) {
super(out);
}
@Override
public void visit(PairTPHsmallerTPH p) {
print(p, "<");
}
@Override
public void visit(PairTPHequalRefTypeOrWildcardType p) {
print(p, "=.");
}
@Override
public void visit(PairTPHEqualTPH p) {
print(p, "=.");
}
private void print(ResultPair p , String operator){
out.append("(");
p.getLeft().accept((ResultSetVisitor) this);
out.append(" "+operator+" ");
p.getRight().accept((ResultSetVisitor) this);
out.append(")");
}
}

View File

@ -0,0 +1,20 @@
package de.dhbwstuttgart.syntaxtree.visual;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import java.util.Set;
public class ResultSetPrinter {
public static String print(ResultSet toPrint){
StringBuilder output = new StringBuilder();
for(ResultPair p : toPrint.results){
p.accept(new ResultSetOutputGenerator(output));
output.append("\n");
}
return output.toString();
}
}

View File

@ -8,6 +8,7 @@ import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
@ -33,7 +34,7 @@ public class UnifyWithoutWildcards {
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
ResultSet resultSet = run(testSet);
System.out.println(resultSet.results);
System.out.println(ResultSetPrinter.print(resultSet));
assert resultSet.results.size() > 0;
}