ResultSetOutputGenerator
This commit is contained in:
parent
83aaff140c
commit
dff72b0c97
@ -130,6 +130,7 @@ public class ASPParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void parseParameter(String statement){
|
private void parseParameter(String statement){
|
||||||
|
//param(pointer, typ, nextPointer
|
||||||
Pattern p = Pattern.compile(ASPRule.ASP_PARAMLIST_NAME+"\\(([^,]+),([^,]+),([^,]+)\\)");
|
Pattern p = Pattern.compile(ASPRule.ASP_PARAMLIST_NAME+"\\(([^,]+),([^,]+),([^,]+)\\)");
|
||||||
Matcher m = p.matcher(statement);
|
Matcher m = p.matcher(statement);
|
||||||
boolean b = m.matches();
|
boolean b = m.matches();
|
||||||
@ -137,7 +138,7 @@ public class ASPParser {
|
|||||||
if(m.groupCount()<3)throw new DebugException("Fehler in Regex");
|
if(m.groupCount()<3)throw new DebugException("Fehler in Regex");
|
||||||
String pointer = m.group(1);
|
String pointer = m.group(1);
|
||||||
String type = m.group(2);
|
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(next.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))next = null;
|
||||||
if(this.parameterLists.containsKey(pointer)){
|
if(this.parameterLists.containsKey(pointer)){
|
||||||
throw new DebugException("Fehler in Ergebnisparsen");
|
throw new DebugException("Fehler in Ergebnisparsen");
|
||||||
@ -158,20 +159,18 @@ public class ASPParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void parseType(String statement){
|
private void parseType(String statement){
|
||||||
//TODO: Diese Regel muss 3 Parameter parsen (TypPointer, TypName, ParameterlistenPointer)
|
//Diese Regel muss 3 Parameter parsen (TypPointer, TypName, ParameterlistenPointer)
|
||||||
throw new NotImplementedException();
|
Pattern p = Pattern.compile(ASPRule.ASP_TYPE+"\\(([^,]+),([^,]+),([^,]+)\\)");
|
||||||
/*
|
|
||||||
Pattern p = Pattern.compile(ASPRule.ASP_TYPE+"\\(([^,]+),([^,]+)\\)");
|
|
||||||
Matcher m = p.matcher(statement);
|
Matcher m = p.matcher(statement);
|
||||||
boolean b = m.matches();
|
boolean b = m.matches();
|
||||||
if(b){
|
if(b){
|
||||||
if(m.groupCount()<2)throw new DebugException("Fehler in Regex");
|
if(m.groupCount()<3)throw new DebugException("Fehler in Regex");
|
||||||
String ls = m.group(1);
|
String pointer = m.group(1);
|
||||||
String rs = m.group(2);
|
String name = m.group(2);
|
||||||
List<String> params = this.getParams(rs);
|
String paraList = m.group(3);
|
||||||
this.types.put(ls,new ParsedType(ls, params));
|
List<String> params = this.getParams(paraList);
|
||||||
|
this.types.put(pointer,new ParsedType(name, params));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getParams(String pointer) {
|
private List<String> getParams(String pointer) {
|
||||||
|
@ -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(")");
|
||||||
|
}
|
||||||
|
}
|
20
src/de/dhbwstuttgart/syntaxtree/visual/ResultSetPrinter.java
Normal file
20
src/de/dhbwstuttgart/syntaxtree/visual/ResultSetPrinter.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,7 @@ import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
|||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
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());
|
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
|
||||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||||
ResultSet resultSet = run(testSet);
|
ResultSet resultSet = run(testSet);
|
||||||
System.out.println(resultSet.results);
|
System.out.println(ResultSetPrinter.print(resultSet));
|
||||||
assert resultSet.results.size() > 0;
|
assert resultSet.results.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user