Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypesNew
This commit is contained in:
commit
ebacb72dcb
15
pom.xml
15
pom.xml
@ -76,7 +76,22 @@
|
||||
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>aspParser</id>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/de/dhbwstuttgart/sat/asp/parser/antlr/</sourceDirectory>
|
||||
<outputDirectory>src/de/dhbwstuttgart/sat/asp/parser/antlr/</outputDirectory>
|
||||
<arguments>
|
||||
<argument>-package</argument>
|
||||
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -43,16 +43,25 @@ public class FCGenerator {
|
||||
return getSuperTypes(forType, availableClasses, new HashMap<>());
|
||||
}
|
||||
|
||||
//TODO: implements Interface auch als superklassen beachten
|
||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) throws ClassNotFoundException {
|
||||
/**
|
||||
*
|
||||
* @param forType
|
||||
* @param availableClasses
|
||||
* @param gtvs
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) throws ClassNotFoundException {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
//Die GTVs, die in forType hinzukommen:
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> newGTVs = new HashMap<>();
|
||||
//Generics mit gleichem Namen müssen den selben TPH bekommen
|
||||
for(GenericTypeVar gtv : forType.getGenerics()){
|
||||
if(!gtvs.containsKey(gtv.getName())){
|
||||
gtvs.put(gtv.getName(), TypePlaceholder.fresh(new NullToken()));
|
||||
newGTVs.put(gtv.getName(), TypePlaceholder.fresh(new NullToken()));
|
||||
TypePlaceholder replacePlaceholder = TypePlaceholder.fresh(new NullToken());
|
||||
gtvs.put(gtv.getName(), replacePlaceholder);
|
||||
newGTVs.put(gtv.getName(), replacePlaceholder);
|
||||
}
|
||||
params.add(gtvs.get(gtv.getName()));
|
||||
}
|
||||
@ -78,7 +87,7 @@ public class FCGenerator {
|
||||
Beispie: Matrix<A> extends Vector<Vector<A>>
|
||||
Den ersten Parameter mit Vector<A> austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen
|
||||
*/
|
||||
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
||||
//Hier vermerken, welche Typen in der Superklasse ausgetauscht werden müssen
|
||||
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = superType.getParaList().iterator();
|
||||
while(itSetParams.hasNext()){
|
||||
@ -88,7 +97,9 @@ public class FCGenerator {
|
||||
newGTVs.put(itGenParams.next().getName(), setSetType);
|
||||
}
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric superRefType = superType.acceptTV(new TypeExchanger(newGTVs));
|
||||
//Für den superType kann man nun zum Austauschen der Generics wieder die gtvs nehmen:
|
||||
//Die newGTVs sind nur für den superClass ClassOrInterface welches möglicherweise per reflection geladen wurde abgestimmt
|
||||
RefTypeOrTPHOrWildcardOrGeneric superRefType = superType.acceptTV(new TypeExchanger(gtvs));
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric t1 = new RefType(forType.getClassName(), params, new NullToken());
|
||||
RefTypeOrTPHOrWildcardOrGeneric t2 = superRefType;
|
||||
@ -150,8 +161,6 @@ public class FCGenerator {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
|
||||
if(! gtvs.containsKey(genericRefType.getParsedName()))
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
//TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf.
|
||||
//return UnifyTypeFactory.convert(ASTFactory.createObjectType());
|
||||
return gtvs.get(genericRefType.getParsedName());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,13 @@ public class Clingo {
|
||||
"/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo";
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add(pathToClingo);
|
||||
commands.add("--outf=2"); //use JSON-Output
|
||||
//commands.add("--outf=2"); //use JSON-Output
|
||||
commands.add("--outf=1"); //use JSON-Output
|
||||
for(File file : input){
|
||||
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();
|
||||
|
26
src/de/dhbwstuttgart/sat/asp/model/ASPGencayRule.java
Normal file
26
src/de/dhbwstuttgart/sat/asp/model/ASPGencayRule.java
Normal file
@ -0,0 +1,26 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public enum ASPGencayRule {
|
||||
ASP_PAIR_EQUALS_NAME("equals"),
|
||||
ASP_PAIR_SMALLER_NAME("sub"),
|
||||
ASP_PAIR_SMALLER_DOT_NAME("subEq"),
|
||||
ASP_PARAMLIST_NAME("paramEq"),
|
||||
ASP_FC_PARAMLIST_NAME("param"),
|
||||
ASP_PARAMLIST_END_POINTER("null"),
|
||||
ASP_TYPE("typeEq"),
|
||||
ASP_FCTYPE("type"),
|
||||
ASP_TYPE_VAR("var"),
|
||||
ASP_GENERIC_VAR("pph"),
|
||||
ASP_PARAMLIST_ORDER("paramOrder");
|
||||
|
||||
private final String text;
|
||||
|
||||
private ASPGencayRule(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public enum ASPRule {
|
||||
ASP_GENERIC_TYPE_NAME("genericType"),
|
||||
ASP_PAIR_EQUALS_NAME("equals"),
|
||||
ASP_PAIR_SMALLER_NAME("smaller"),
|
||||
ASP_PAIR_SMALLER_DOT_NAME("smallerDot"),
|
||||
ASP_PARAMLIST_NAME("param"),
|
||||
ASP_PARAMLISTNUMERATION_NAME("paramNum"),
|
||||
ASP_PARAMLIST_END_POINTER("null"),
|
||||
ASP_TYPE("type"),
|
||||
ASP_FCTYPE("typeFC"),
|
||||
|
@ -1,17 +1,20 @@
|
||||
package de.dhbwstuttgart.sat.asp.parser;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultBaseListener;
|
||||
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultLexer;
|
||||
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultParser;
|
||||
import de.dhbwstuttgart.sat.asp.parser.model.ParsedType;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.writer.model.ASPParameterList;
|
||||
import de.dhbwstuttgart.sat.asp.writer.model.ASPRefType;
|
||||
import de.dhbwstuttgart.sat.asp.writer.model.ASPType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.result.*;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
@ -20,6 +23,7 @@ import java.io.StringReader;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Ablauf:
|
||||
@ -29,12 +33,14 @@ import java.util.regex.Pattern;
|
||||
* TODO: Überlegen welche Informationen noch nach der Unifizierung gebraucht werden
|
||||
* -> Eigentlich nur die korrekten Namen der Typen und TPHs
|
||||
*/
|
||||
public class ASPParser {
|
||||
private final Collection<TypePlaceholder> originalTPHs;
|
||||
public class ASPParser extends UnifyResultBaseListener {
|
||||
private Collection<TypePlaceholder> originalTPHs;
|
||||
private ResultSet resultSet;
|
||||
private Map<String, ParsedType> types = new HashMap<>();
|
||||
private Set<String> tphs = new HashSet<>();
|
||||
private Map<String, ParameterListNode> parameterLists = new HashMap<>();
|
||||
private Set<Relation> equalsRelations = new HashSet<>();
|
||||
private Set<Relation> smallerRelations = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Parst clingo output welcher als JSON (option --outf=2) ausgibt
|
||||
@ -45,61 +51,137 @@ public class ASPParser {
|
||||
return new ASPParser(toParse, oldPlaceholders).resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterParameter(UnifyResultParser.ParameterContext ctx) {
|
||||
//Linked List (pointer, Type, nextPointer)
|
||||
List<String> params = parseParameterList(ctx.parameterList());
|
||||
parameterLists.put(params.get(0), new ParameterListNode(params.get(1), params.get(2)));
|
||||
}
|
||||
|
||||
private static class Relation {
|
||||
public final String right;
|
||||
public final String left;
|
||||
|
||||
Relation(String leftType, String rightType){
|
||||
this.left = leftType;
|
||||
this.right = rightType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (left+right).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Relation)
|
||||
return (right+left).equals(((Relation) obj).left+((Relation) obj).right);
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> parseParameterList(UnifyResultParser.ParameterListContext ctx){
|
||||
return ctx.value().stream().map(v ->
|
||||
//ASPStringConverter.fromConstant(v.getText())
|
||||
v.getText()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterEquals(UnifyResultParser.EqualsContext ctx) {
|
||||
List<String> parameterList = parseParameterList(ctx.parameterList());
|
||||
if(parameterList.size()<2)throw new DebugException("Fehler in Equals-Regel");
|
||||
String ls = parameterList.get(0);
|
||||
String rs = parameterList.get(1);
|
||||
equalsRelations.add(new Relation(ls, rs));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterSmaller(UnifyResultParser.SmallerContext ctx) {
|
||||
List<String> parameterList = parseParameterList(ctx.parameterList());
|
||||
if(parameterList.size()<2)throw new DebugException("Fehler in Smaller-Regel");
|
||||
String ls = parameterList.get(0);
|
||||
String rs = parameterList.get(1);
|
||||
smallerRelations.add(new Relation(ls, rs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterTypeVar(UnifyResultParser.TypeVarContext ctx) {
|
||||
List<String> parameterList = parseParameterList(ctx.parameterList());
|
||||
if(parameterList.size()<1)throw new DebugException("Fehler in typeVar-Regel");
|
||||
tphs.add(parameterList.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterType(UnifyResultParser.TypeContext ctx){
|
||||
List<String> parameterList = parseParameterList(ctx.parameterList());
|
||||
if(parameterList.size()<3)throw new DebugException("Fehler in Type-Regel");
|
||||
String name = parameterList.get(0);
|
||||
String typeName = parameterList.get(1);
|
||||
String paramPointer = parameterList.get(2);
|
||||
types.put(name, new ParsedType(typeName, paramPointer));
|
||||
}
|
||||
|
||||
/*
|
||||
private List<String> parsedRule;
|
||||
private List<String> parseRule(String rule){
|
||||
UnifyResultLexer lexer = new UnifyResultLexer(CharStreams.fromString(rule));
|
||||
UnifyResultParser.AspruleContext parseTree = new UnifyResultParser(new CommonTokenStream(lexer)).asprule();
|
||||
parsedRule = new ArrayList<>();
|
||||
new ParseTreeWalker().walk(this, parseTree);
|
||||
return parsedRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterAsprule(UnifyResultParser.AspruleContext ctx) {
|
||||
super.enterAsprule(ctx);
|
||||
for(int i = 0; i< ctx.getChildCount();i++){
|
||||
parsedRule.add(ctx.getChild(i).getText());
|
||||
}
|
||||
}
|
||||
*/
|
||||
private ASPParser(String toParse, Collection<TypePlaceholder> oldPlaceholders){
|
||||
//System.out.println(toParse);
|
||||
this.originalTPHs = oldPlaceholders;
|
||||
|
||||
/*
|
||||
JsonObject jsonResult = Json.createReader(new StringReader(toParse)).readObject();
|
||||
JsonArray results = jsonResult.getJsonArray("Call").getJsonObject(0).
|
||||
getJsonArray("Witnesses").getJsonObject(0).
|
||||
getJsonArray("Value");
|
||||
|
||||
//Im ersten Schritt werden alle Regeln geparst
|
||||
String completeResult = "";
|
||||
for(int i = 0; i<results.size();i++){
|
||||
String aspStatement = results.getString(i);
|
||||
completeResult += aspStatement + " ";
|
||||
}
|
||||
System.out.println(completeResult);
|
||||
*/
|
||||
UnifyResultLexer lexer = new UnifyResultLexer(CharStreams.fromString(toParse));
|
||||
UnifyResultParser.AnswerContext parseTree = new UnifyResultParser(new CommonTokenStream(lexer)).answer();
|
||||
new ParseTreeWalker().walk(this, parseTree);
|
||||
|
||||
/*
|
||||
Diese Funktion läuft im folgenden mehrmals über das Result aus dem ASP Programm.
|
||||
Dabei werden Schritt für Schritt die Felder dieser Klasse befüllt die am Schluss das ResultSet ergeben
|
||||
*/
|
||||
*/
|
||||
Set<ResultPair> ret = new HashSet<>();
|
||||
//Zuerst die params und typeVars:
|
||||
for(int i = 0; i<results.size();i++){
|
||||
String aspStatement = results.getString(i);
|
||||
parseParameter(aspStatement);
|
||||
parseTypeVar(aspStatement);
|
||||
}
|
||||
//Dann die Typen, das ist wichtig, da die Typen auf die Parameter referenzieren:
|
||||
for(int i = 0; i<results.size();i++){
|
||||
String aspStatement = results.getString(i);
|
||||
parseType(aspStatement);
|
||||
}
|
||||
//for(String paramPointer : types.values().stream().map(parsedType -> parsedType.params).collect(Collectors.toList())){ }
|
||||
|
||||
//Dann die Equalsdot Statements
|
||||
for(int i = 0; i<results.size();i++){
|
||||
String aspStatement = results.getString(i);
|
||||
ResultPair p = parseEqualsDot(aspStatement);
|
||||
if(p != null)ret.add(p);
|
||||
p = parseSmallerDot(aspStatement);
|
||||
if(p != null)ret.add(p);
|
||||
}
|
||||
|
||||
this.resultSet = new ResultSet(ret);
|
||||
}
|
||||
|
||||
private ResultPair parseSmallerDot(String statement) {
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
private ResultPair parseEqualsDot(String statement){
|
||||
Pattern p = Pattern.compile(ASPRule.ASP_PAIR_EQUALS_NAME+"\\(([^,]+),([^,]+)\\)");
|
||||
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);
|
||||
RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(ls);
|
||||
RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(rs);
|
||||
for(Relation eq : equalsRelations){
|
||||
RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(eq.left);
|
||||
RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(eq.right);
|
||||
if(lsType instanceof TypePlaceholder && rsType instanceof RefType)
|
||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) lsType, rsType);
|
||||
ret.add(new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) lsType, rsType));
|
||||
else if(lsType instanceof TypePlaceholder && rsType instanceof TypePlaceholder)
|
||||
ret.add(new PairTPHEqualTPH((TypePlaceholder)lsType, (TypePlaceholder)rsType));
|
||||
else throw new NotImplementedException();
|
||||
}
|
||||
return null;
|
||||
this.resultSet = new ResultSet(ret);
|
||||
}
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric getType(String name) {
|
||||
@ -113,7 +195,8 @@ public class ASPParser {
|
||||
if(types.containsKey(name)){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
ParsedType t = types.get(name);
|
||||
for(String param : t.params){
|
||||
|
||||
for(String param : getParams(t.params)){
|
||||
params.add(this.getType(param));
|
||||
}
|
||||
return new RefType(new JavaClassName(ASPStringConverter.fromConstant(t.name)), params, new NullToken());
|
||||
@ -129,53 +212,14 @@ public class ASPParser {
|
||||
this.nextNode = next;
|
||||
}
|
||||
}
|
||||
private void parseParameter(String statement){
|
||||
Pattern p = Pattern.compile(ASPRule.ASP_PARAMLIST_NAME+"\\(([^,]+),([^,]+),([^,]+)\\)");
|
||||
Matcher m = p.matcher(statement);
|
||||
boolean b = m.matches();
|
||||
if(b){
|
||||
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);
|
||||
if(next.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))next = null;
|
||||
if(this.parameterLists.containsKey(pointer)){
|
||||
throw new DebugException("Fehler in Ergebnisparsen");
|
||||
}
|
||||
this.parameterLists.put(pointer,new ParameterListNode(type, next));
|
||||
}
|
||||
}
|
||||
|
||||
private void parseTypeVar(String statement){
|
||||
Pattern p = Pattern.compile(ASPRule.ASP_TYPE_VAR+"\\(([^,]+)\\)");
|
||||
Matcher m = p.matcher(statement);
|
||||
boolean b = m.matches();
|
||||
if(b){
|
||||
if(m.groupCount()<1)throw new DebugException("Fehler in Regex");
|
||||
String name = m.group(1);
|
||||
this.tphs.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseType(String statement){
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getParams(String pointer) {
|
||||
List<String> params = new ArrayList<>();
|
||||
if(pointer.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))return params;
|
||||
while(pointer != null){
|
||||
if(pointer.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))return params;
|
||||
if(!parameterLists.containsKey(pointer))
|
||||
throw new DebugException("Fehler in Ergebnisparsen");
|
||||
//TODO: Fehler in ASP. Die adapt Regel muss erkennen, wenn die Parameterliste auf der linken Seite kürzer ist und diese Rechtzeitig beenden
|
||||
ParameterListNode param = parameterLists.get(pointer);
|
||||
pointer = param.nextNode;
|
||||
params.add(param.type);
|
||||
|
37
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4
Normal file
37
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4
Normal file
@ -0,0 +1,37 @@
|
||||
grammar UnifyResult;
|
||||
|
||||
answer : 'ANSWER' (resultSetRule '.')*;
|
||||
|
||||
resultSetRule :
|
||||
parameter
|
||||
| equals
|
||||
| smaller
|
||||
| typeVar
|
||||
| type
|
||||
| otherRule
|
||||
;
|
||||
|
||||
parameterList : '(' value (',' value)* ')';
|
||||
value : NAME
|
||||
| resultSetRule ;
|
||||
|
||||
parameter : PARAMLIST_NAME parameterList;
|
||||
equals : EQUALS_NAME parameterList;
|
||||
smaller : SMALLER_NAME parameterList;
|
||||
typeVar : TYPEVAR_NAME parameterList;
|
||||
type : TYPE_NAME parameterList;
|
||||
otherRule : NAME parameterList;
|
||||
|
||||
//TODO: Es sollte Regeln für das Result set geben, welche sich nicht mit den anderen überdecken, dann auch nur diese im Result ausgeben
|
||||
PARAMLIST_NAME : 'param';
|
||||
EQUALS_NAME : 'equals';
|
||||
SMALLER_NAME : 'smaller';
|
||||
TYPEVAR_NAME : 'typeVar';
|
||||
TYPE_NAME : 'type';
|
||||
NAME : [a-zA-Z0-9_]+;
|
||||
|
||||
WS : [ \t\r\n\u000C]+ -> skip
|
||||
;
|
||||
LINE_COMMENT
|
||||
: '%' ~[\r\n]* -> skip
|
||||
;
|
23
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens
Normal file
23
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens
Normal file
@ -0,0 +1,23 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
PARAMLIST_NAME=6
|
||||
EQUALS_NAME=7
|
||||
SMALLER_NAME=8
|
||||
TYPEVAR_NAME=9
|
||||
TYPE_NAME=10
|
||||
NAME=11
|
||||
WS=12
|
||||
LINE_COMMENT=13
|
||||
'ANSWER'=1
|
||||
'.'=2
|
||||
'('=3
|
||||
','=4
|
||||
')'=5
|
||||
'param'=6
|
||||
'equals'=7
|
||||
'smaller'=8
|
||||
'typeVar'=9
|
||||
'type'=10
|
@ -0,0 +1,159 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.tree.ErrorNode;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
/**
|
||||
* This class provides an empty implementation of {@link UnifyResultListener},
|
||||
* which can be extended to create a listener which only needs to handle a subset
|
||||
* of the available methods.
|
||||
*/
|
||||
public class UnifyResultBaseListener implements UnifyResultListener {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterAnswer(UnifyResultParser.AnswerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitAnswer(UnifyResultParser.AnswerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterResultSetRule(UnifyResultParser.ResultSetRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitResultSetRule(UnifyResultParser.ResultSetRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterParameterList(UnifyResultParser.ParameterListContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitParameterList(UnifyResultParser.ParameterListContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterValue(UnifyResultParser.ValueContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitValue(UnifyResultParser.ValueContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterParameter(UnifyResultParser.ParameterContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitParameter(UnifyResultParser.ParameterContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterEquals(UnifyResultParser.EqualsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitEquals(UnifyResultParser.EqualsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterSmaller(UnifyResultParser.SmallerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitSmaller(UnifyResultParser.SmallerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterTypeVar(UnifyResultParser.TypeVarContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitTypeVar(UnifyResultParser.TypeVarContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterType(UnifyResultParser.TypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitType(UnifyResultParser.TypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterOtherRule(UnifyResultParser.OtherRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitOtherRule(UnifyResultParser.OtherRuleContext ctx) { }
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterEveryRule(ParserRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitEveryRule(ParserRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void visitTerminal(TerminalNode node) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void visitErrorNode(ErrorNode node) { }
|
||||
}
|
134
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java
Normal file
134
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java
Normal file
@ -0,0 +1,134 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
||||
public class UnifyResultLexer extends Lexer {
|
||||
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
|
||||
|
||||
protected static final DFA[] _decisionToDFA;
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
new PredictionContextCache();
|
||||
public static final int
|
||||
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, EQUALS_NAME=7,
|
||||
SMALLER_NAME=8, TYPEVAR_NAME=9, TYPE_NAME=10, NAME=11, WS=12, LINE_COMMENT=13;
|
||||
public static String[] channelNames = {
|
||||
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||
};
|
||||
|
||||
public static String[] modeNames = {
|
||||
"DEFAULT_MODE"
|
||||
};
|
||||
|
||||
public static final String[] ruleNames = {
|
||||
"T__0", "T__1", "T__2", "T__3", "T__4", "PARAMLIST_NAME", "EQUALS_NAME",
|
||||
"SMALLER_NAME", "TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'equals'", "'smaller'",
|
||||
"'typeVar'", "'type'"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, null, null, null, null, null, "PARAMLIST_NAME", "EQUALS_NAME", "SMALLER_NAME",
|
||||
"TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
|
||||
};
|
||||
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #VOCABULARY} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String[] tokenNames;
|
||||
static {
|
||||
tokenNames = new String[_SYMBOLIC_NAMES.length];
|
||||
for (int i = 0; i < tokenNames.length; i++) {
|
||||
tokenNames[i] = VOCABULARY.getLiteralName(i);
|
||||
if (tokenNames[i] == null) {
|
||||
tokenNames[i] = VOCABULARY.getSymbolicName(i);
|
||||
}
|
||||
|
||||
if (tokenNames[i] == null) {
|
||||
tokenNames[i] = "<INVALID>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getTokenNames() {
|
||||
return tokenNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Vocabulary getVocabulary() {
|
||||
return VOCABULARY;
|
||||
}
|
||||
|
||||
|
||||
public UnifyResultLexer(CharStream input) {
|
||||
super(input);
|
||||
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "UnifyResult.g4"; }
|
||||
|
||||
@Override
|
||||
public String[] getRuleNames() { return ruleNames; }
|
||||
|
||||
@Override
|
||||
public String getSerializedATN() { return _serializedATN; }
|
||||
|
||||
@Override
|
||||
public String[] getChannelNames() { return channelNames; }
|
||||
|
||||
@Override
|
||||
public String[] getModeNames() { return modeNames; }
|
||||
|
||||
@Override
|
||||
public ATN getATN() { return _ATN; }
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\17c\b\1\4\2\t\2\4"+
|
||||
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
|
||||
"\13\4\f\t\f\4\r\t\r\4\16\t\16\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\4"+
|
||||
"\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3"+
|
||||
"\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13"+
|
||||
"\3\13\3\13\3\13\3\13\3\f\6\fP\n\f\r\f\16\fQ\3\r\6\rU\n\r\r\r\16\rV\3\r"+
|
||||
"\3\r\3\16\3\16\7\16]\n\16\f\16\16\16`\13\16\3\16\3\16\2\2\17\3\3\5\4\7"+
|
||||
"\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\3\2\5\6\2\62;C\\"+
|
||||
"aac|\5\2\13\f\16\17\"\"\4\2\f\f\17\17\2e\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3"+
|
||||
"\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2"+
|
||||
"\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\3\35"+
|
||||
"\3\2\2\2\5$\3\2\2\2\7&\3\2\2\2\t(\3\2\2\2\13*\3\2\2\2\r,\3\2\2\2\17\62"+
|
||||
"\3\2\2\2\219\3\2\2\2\23A\3\2\2\2\25I\3\2\2\2\27O\3\2\2\2\31T\3\2\2\2\33"+
|
||||
"Z\3\2\2\2\35\36\7C\2\2\36\37\7P\2\2\37 \7U\2\2 !\7Y\2\2!\"\7G\2\2\"#\7"+
|
||||
"T\2\2#\4\3\2\2\2$%\7\60\2\2%\6\3\2\2\2&\'\7*\2\2\'\b\3\2\2\2()\7.\2\2"+
|
||||
")\n\3\2\2\2*+\7+\2\2+\f\3\2\2\2,-\7r\2\2-.\7c\2\2./\7t\2\2/\60\7c\2\2"+
|
||||
"\60\61\7o\2\2\61\16\3\2\2\2\62\63\7g\2\2\63\64\7s\2\2\64\65\7w\2\2\65"+
|
||||
"\66\7c\2\2\66\67\7n\2\2\678\7u\2\28\20\3\2\2\29:\7u\2\2:;\7o\2\2;<\7c"+
|
||||
"\2\2<=\7n\2\2=>\7n\2\2>?\7g\2\2?@\7t\2\2@\22\3\2\2\2AB\7v\2\2BC\7{\2\2"+
|
||||
"CD\7r\2\2DE\7g\2\2EF\7X\2\2FG\7c\2\2GH\7t\2\2H\24\3\2\2\2IJ\7v\2\2JK\7"+
|
||||
"{\2\2KL\7r\2\2LM\7g\2\2M\26\3\2\2\2NP\t\2\2\2ON\3\2\2\2PQ\3\2\2\2QO\3"+
|
||||
"\2\2\2QR\3\2\2\2R\30\3\2\2\2SU\t\3\2\2TS\3\2\2\2UV\3\2\2\2VT\3\2\2\2V"+
|
||||
"W\3\2\2\2WX\3\2\2\2XY\b\r\2\2Y\32\3\2\2\2Z^\7\'\2\2[]\n\4\2\2\\[\3\2\2"+
|
||||
"\2]`\3\2\2\2^\\\3\2\2\2^_\3\2\2\2_a\3\2\2\2`^\3\2\2\2ab\b\16\2\2b\34\3"+
|
||||
"\2\2\2\6\2QV^\3\b\2\2";
|
||||
public static final ATN _ATN =
|
||||
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
|
||||
static {
|
||||
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
|
||||
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
|
||||
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
PARAMLIST_NAME=6
|
||||
EQUALS_NAME=7
|
||||
SMALLER_NAME=8
|
||||
TYPEVAR_NAME=9
|
||||
TYPE_NAME=10
|
||||
NAME=11
|
||||
WS=12
|
||||
LINE_COMMENT=13
|
||||
'ANSWER'=1
|
||||
'.'=2
|
||||
'('=3
|
||||
','=4
|
||||
')'=5
|
||||
'param'=6
|
||||
'equals'=7
|
||||
'smaller'=8
|
||||
'typeVar'=9
|
||||
'type'=10
|
@ -0,0 +1,110 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
/**
|
||||
* This interface defines a complete listener for a parse tree produced by
|
||||
* {@link UnifyResultParser}.
|
||||
*/
|
||||
public interface UnifyResultListener extends ParseTreeListener {
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#answer}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterAnswer(UnifyResultParser.AnswerContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#answer}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitAnswer(UnifyResultParser.AnswerContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#resultSetRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterResultSetRule(UnifyResultParser.ResultSetRuleContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#resultSetRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitResultSetRule(UnifyResultParser.ResultSetRuleContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#parameterList}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterParameterList(UnifyResultParser.ParameterListContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#parameterList}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitParameterList(UnifyResultParser.ParameterListContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#value}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterValue(UnifyResultParser.ValueContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#value}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitValue(UnifyResultParser.ValueContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#parameter}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterParameter(UnifyResultParser.ParameterContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#parameter}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitParameter(UnifyResultParser.ParameterContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#equals}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterEquals(UnifyResultParser.EqualsContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#equals}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitEquals(UnifyResultParser.EqualsContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#smaller}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterSmaller(UnifyResultParser.SmallerContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#smaller}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitSmaller(UnifyResultParser.SmallerContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#typeVar}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterTypeVar(UnifyResultParser.TypeVarContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#typeVar}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitTypeVar(UnifyResultParser.TypeVarContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#type}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterType(UnifyResultParser.TypeContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#type}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitType(UnifyResultParser.TypeContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#otherRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterOtherRule(UnifyResultParser.OtherRuleContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#otherRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitOtherRule(UnifyResultParser.OtherRuleContext ctx);
|
||||
}
|
639
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java
Normal file
639
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java
Normal file
@ -0,0 +1,639 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
import org.antlr.v4.runtime.tree.*;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
||||
public class UnifyResultParser extends Parser {
|
||||
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
|
||||
|
||||
protected static final DFA[] _decisionToDFA;
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
new PredictionContextCache();
|
||||
public static final int
|
||||
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, EQUALS_NAME=7,
|
||||
SMALLER_NAME=8, TYPEVAR_NAME=9, TYPE_NAME=10, NAME=11, WS=12, LINE_COMMENT=13;
|
||||
public static final int
|
||||
RULE_answer = 0, RULE_resultSetRule = 1, RULE_parameterList = 2, RULE_value = 3,
|
||||
RULE_parameter = 4, RULE_equals = 5, RULE_smaller = 6, RULE_typeVar = 7,
|
||||
RULE_type = 8, RULE_otherRule = 9;
|
||||
public static final String[] ruleNames = {
|
||||
"answer", "resultSetRule", "parameterList", "value", "parameter", "equals",
|
||||
"smaller", "typeVar", "type", "otherRule"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'equals'", "'smaller'",
|
||||
"'typeVar'", "'type'"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, null, null, null, null, null, "PARAMLIST_NAME", "EQUALS_NAME", "SMALLER_NAME",
|
||||
"TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
|
||||
};
|
||||
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #VOCABULARY} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String[] tokenNames;
|
||||
static {
|
||||
tokenNames = new String[_SYMBOLIC_NAMES.length];
|
||||
for (int i = 0; i < tokenNames.length; i++) {
|
||||
tokenNames[i] = VOCABULARY.getLiteralName(i);
|
||||
if (tokenNames[i] == null) {
|
||||
tokenNames[i] = VOCABULARY.getSymbolicName(i);
|
||||
}
|
||||
|
||||
if (tokenNames[i] == null) {
|
||||
tokenNames[i] = "<INVALID>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getTokenNames() {
|
||||
return tokenNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Vocabulary getVocabulary() {
|
||||
return VOCABULARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "UnifyResult.g4"; }
|
||||
|
||||
@Override
|
||||
public String[] getRuleNames() { return ruleNames; }
|
||||
|
||||
@Override
|
||||
public String getSerializedATN() { return _serializedATN; }
|
||||
|
||||
@Override
|
||||
public ATN getATN() { return _ATN; }
|
||||
|
||||
public UnifyResultParser(TokenStream input) {
|
||||
super(input);
|
||||
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
public static class AnswerContext extends ParserRuleContext {
|
||||
public List<ResultSetRuleContext> resultSetRule() {
|
||||
return getRuleContexts(ResultSetRuleContext.class);
|
||||
}
|
||||
public ResultSetRuleContext resultSetRule(int i) {
|
||||
return getRuleContext(ResultSetRuleContext.class,i);
|
||||
}
|
||||
public AnswerContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_answer; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterAnswer(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitAnswer(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final AnswerContext answer() throws RecognitionException {
|
||||
AnswerContext _localctx = new AnswerContext(_ctx, getState());
|
||||
enterRule(_localctx, 0, RULE_answer);
|
||||
int _la;
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(20);
|
||||
match(T__0);
|
||||
setState(26);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PARAMLIST_NAME) | (1L << EQUALS_NAME) | (1L << SMALLER_NAME) | (1L << TYPEVAR_NAME) | (1L << TYPE_NAME) | (1L << NAME))) != 0)) {
|
||||
{
|
||||
{
|
||||
setState(21);
|
||||
resultSetRule();
|
||||
setState(22);
|
||||
match(T__1);
|
||||
}
|
||||
}
|
||||
setState(28);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class ResultSetRuleContext extends ParserRuleContext {
|
||||
public ParameterContext parameter() {
|
||||
return getRuleContext(ParameterContext.class,0);
|
||||
}
|
||||
public EqualsContext equals() {
|
||||
return getRuleContext(EqualsContext.class,0);
|
||||
}
|
||||
public SmallerContext smaller() {
|
||||
return getRuleContext(SmallerContext.class,0);
|
||||
}
|
||||
public TypeVarContext typeVar() {
|
||||
return getRuleContext(TypeVarContext.class,0);
|
||||
}
|
||||
public TypeContext type() {
|
||||
return getRuleContext(TypeContext.class,0);
|
||||
}
|
||||
public OtherRuleContext otherRule() {
|
||||
return getRuleContext(OtherRuleContext.class,0);
|
||||
}
|
||||
public ResultSetRuleContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_resultSetRule; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterResultSetRule(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitResultSetRule(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final ResultSetRuleContext resultSetRule() throws RecognitionException {
|
||||
ResultSetRuleContext _localctx = new ResultSetRuleContext(_ctx, getState());
|
||||
enterRule(_localctx, 2, RULE_resultSetRule);
|
||||
try {
|
||||
setState(35);
|
||||
_errHandler.sync(this);
|
||||
switch (_input.LA(1)) {
|
||||
case PARAMLIST_NAME:
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(29);
|
||||
parameter();
|
||||
}
|
||||
break;
|
||||
case EQUALS_NAME:
|
||||
enterOuterAlt(_localctx, 2);
|
||||
{
|
||||
setState(30);
|
||||
equals();
|
||||
}
|
||||
break;
|
||||
case SMALLER_NAME:
|
||||
enterOuterAlt(_localctx, 3);
|
||||
{
|
||||
setState(31);
|
||||
smaller();
|
||||
}
|
||||
break;
|
||||
case TYPEVAR_NAME:
|
||||
enterOuterAlt(_localctx, 4);
|
||||
{
|
||||
setState(32);
|
||||
typeVar();
|
||||
}
|
||||
break;
|
||||
case TYPE_NAME:
|
||||
enterOuterAlt(_localctx, 5);
|
||||
{
|
||||
setState(33);
|
||||
type();
|
||||
}
|
||||
break;
|
||||
case NAME:
|
||||
enterOuterAlt(_localctx, 6);
|
||||
{
|
||||
setState(34);
|
||||
otherRule();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NoViableAltException(this);
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class ParameterListContext extends ParserRuleContext {
|
||||
public List<ValueContext> value() {
|
||||
return getRuleContexts(ValueContext.class);
|
||||
}
|
||||
public ValueContext value(int i) {
|
||||
return getRuleContext(ValueContext.class,i);
|
||||
}
|
||||
public ParameterListContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_parameterList; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterParameterList(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitParameterList(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final ParameterListContext parameterList() throws RecognitionException {
|
||||
ParameterListContext _localctx = new ParameterListContext(_ctx, getState());
|
||||
enterRule(_localctx, 4, RULE_parameterList);
|
||||
int _la;
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(37);
|
||||
match(T__2);
|
||||
setState(38);
|
||||
value();
|
||||
setState(43);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
while (_la==T__3) {
|
||||
{
|
||||
{
|
||||
setState(39);
|
||||
match(T__3);
|
||||
setState(40);
|
||||
value();
|
||||
}
|
||||
}
|
||||
setState(45);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
}
|
||||
setState(46);
|
||||
match(T__4);
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class ValueContext extends ParserRuleContext {
|
||||
public TerminalNode NAME() { return getToken(UnifyResultParser.NAME, 0); }
|
||||
public ResultSetRuleContext resultSetRule() {
|
||||
return getRuleContext(ResultSetRuleContext.class,0);
|
||||
}
|
||||
public ValueContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_value; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterValue(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitValue(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final ValueContext value() throws RecognitionException {
|
||||
ValueContext _localctx = new ValueContext(_ctx, getState());
|
||||
enterRule(_localctx, 6, RULE_value);
|
||||
try {
|
||||
setState(50);
|
||||
_errHandler.sync(this);
|
||||
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
|
||||
case 1:
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(48);
|
||||
match(NAME);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
enterOuterAlt(_localctx, 2);
|
||||
{
|
||||
setState(49);
|
||||
resultSetRule();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class ParameterContext extends ParserRuleContext {
|
||||
public TerminalNode PARAMLIST_NAME() { return getToken(UnifyResultParser.PARAMLIST_NAME, 0); }
|
||||
public ParameterListContext parameterList() {
|
||||
return getRuleContext(ParameterListContext.class,0);
|
||||
}
|
||||
public ParameterContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_parameter; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterParameter(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitParameter(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final ParameterContext parameter() throws RecognitionException {
|
||||
ParameterContext _localctx = new ParameterContext(_ctx, getState());
|
||||
enterRule(_localctx, 8, RULE_parameter);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(52);
|
||||
match(PARAMLIST_NAME);
|
||||
setState(53);
|
||||
parameterList();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class EqualsContext extends ParserRuleContext {
|
||||
public TerminalNode EQUALS_NAME() { return getToken(UnifyResultParser.EQUALS_NAME, 0); }
|
||||
public ParameterListContext parameterList() {
|
||||
return getRuleContext(ParameterListContext.class,0);
|
||||
}
|
||||
public EqualsContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_equals; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterEquals(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitEquals(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final EqualsContext equals() throws RecognitionException {
|
||||
EqualsContext _localctx = new EqualsContext(_ctx, getState());
|
||||
enterRule(_localctx, 10, RULE_equals);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(55);
|
||||
match(EQUALS_NAME);
|
||||
setState(56);
|
||||
parameterList();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class SmallerContext extends ParserRuleContext {
|
||||
public TerminalNode SMALLER_NAME() { return getToken(UnifyResultParser.SMALLER_NAME, 0); }
|
||||
public ParameterListContext parameterList() {
|
||||
return getRuleContext(ParameterListContext.class,0);
|
||||
}
|
||||
public SmallerContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_smaller; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterSmaller(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitSmaller(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final SmallerContext smaller() throws RecognitionException {
|
||||
SmallerContext _localctx = new SmallerContext(_ctx, getState());
|
||||
enterRule(_localctx, 12, RULE_smaller);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(58);
|
||||
match(SMALLER_NAME);
|
||||
setState(59);
|
||||
parameterList();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class TypeVarContext extends ParserRuleContext {
|
||||
public TerminalNode TYPEVAR_NAME() { return getToken(UnifyResultParser.TYPEVAR_NAME, 0); }
|
||||
public ParameterListContext parameterList() {
|
||||
return getRuleContext(ParameterListContext.class,0);
|
||||
}
|
||||
public TypeVarContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_typeVar; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterTypeVar(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitTypeVar(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final TypeVarContext typeVar() throws RecognitionException {
|
||||
TypeVarContext _localctx = new TypeVarContext(_ctx, getState());
|
||||
enterRule(_localctx, 14, RULE_typeVar);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(61);
|
||||
match(TYPEVAR_NAME);
|
||||
setState(62);
|
||||
parameterList();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class TypeContext extends ParserRuleContext {
|
||||
public TerminalNode TYPE_NAME() { return getToken(UnifyResultParser.TYPE_NAME, 0); }
|
||||
public ParameterListContext parameterList() {
|
||||
return getRuleContext(ParameterListContext.class,0);
|
||||
}
|
||||
public TypeContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_type; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterType(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitType(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final TypeContext type() throws RecognitionException {
|
||||
TypeContext _localctx = new TypeContext(_ctx, getState());
|
||||
enterRule(_localctx, 16, RULE_type);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(64);
|
||||
match(TYPE_NAME);
|
||||
setState(65);
|
||||
parameterList();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class OtherRuleContext extends ParserRuleContext {
|
||||
public TerminalNode NAME() { return getToken(UnifyResultParser.NAME, 0); }
|
||||
public ParameterListContext parameterList() {
|
||||
return getRuleContext(ParameterListContext.class,0);
|
||||
}
|
||||
public OtherRuleContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_otherRule; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterOtherRule(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitOtherRule(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final OtherRuleContext otherRule() throws RecognitionException {
|
||||
OtherRuleContext _localctx = new OtherRuleContext(_ctx, getState());
|
||||
enterRule(_localctx, 18, RULE_otherRule);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(67);
|
||||
match(NAME);
|
||||
setState(68);
|
||||
parameterList();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\17I\4\2\t\2\4\3\t"+
|
||||
"\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\3"+
|
||||
"\2\3\2\3\2\3\2\7\2\33\n\2\f\2\16\2\36\13\2\3\3\3\3\3\3\3\3\3\3\3\3\5\3"+
|
||||
"&\n\3\3\4\3\4\3\4\3\4\7\4,\n\4\f\4\16\4/\13\4\3\4\3\4\3\5\3\5\5\5\65\n"+
|
||||
"\5\3\6\3\6\3\6\3\7\3\7\3\7\3\b\3\b\3\b\3\t\3\t\3\t\3\n\3\n\3\n\3\13\3"+
|
||||
"\13\3\13\3\13\2\2\f\2\4\6\b\n\f\16\20\22\24\2\2\2F\2\26\3\2\2\2\4%\3\2"+
|
||||
"\2\2\6\'\3\2\2\2\b\64\3\2\2\2\n\66\3\2\2\2\f9\3\2\2\2\16<\3\2\2\2\20?"+
|
||||
"\3\2\2\2\22B\3\2\2\2\24E\3\2\2\2\26\34\7\3\2\2\27\30\5\4\3\2\30\31\7\4"+
|
||||
"\2\2\31\33\3\2\2\2\32\27\3\2\2\2\33\36\3\2\2\2\34\32\3\2\2\2\34\35\3\2"+
|
||||
"\2\2\35\3\3\2\2\2\36\34\3\2\2\2\37&\5\n\6\2 &\5\f\7\2!&\5\16\b\2\"&\5"+
|
||||
"\20\t\2#&\5\22\n\2$&\5\24\13\2%\37\3\2\2\2% \3\2\2\2%!\3\2\2\2%\"\3\2"+
|
||||
"\2\2%#\3\2\2\2%$\3\2\2\2&\5\3\2\2\2\'(\7\5\2\2(-\5\b\5\2)*\7\6\2\2*,\5"+
|
||||
"\b\5\2+)\3\2\2\2,/\3\2\2\2-+\3\2\2\2-.\3\2\2\2.\60\3\2\2\2/-\3\2\2\2\60"+
|
||||
"\61\7\7\2\2\61\7\3\2\2\2\62\65\7\r\2\2\63\65\5\4\3\2\64\62\3\2\2\2\64"+
|
||||
"\63\3\2\2\2\65\t\3\2\2\2\66\67\7\b\2\2\678\5\6\4\28\13\3\2\2\29:\7\t\2"+
|
||||
"\2:;\5\6\4\2;\r\3\2\2\2<=\7\n\2\2=>\5\6\4\2>\17\3\2\2\2?@\7\13\2\2@A\5"+
|
||||
"\6\4\2A\21\3\2\2\2BC\7\f\2\2CD\5\6\4\2D\23\3\2\2\2EF\7\r\2\2FG\5\6\4\2"+
|
||||
"G\25\3\2\2\2\6\34%-\64";
|
||||
public static final ATN _ATN =
|
||||
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
|
||||
static {
|
||||
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
|
||||
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
|
||||
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,8 +4,8 @@ import java.util.List;
|
||||
|
||||
public class ParsedType {
|
||||
public final String name;
|
||||
public final List<String> params;
|
||||
public ParsedType(String name, List<String> params){
|
||||
public final String params;
|
||||
public ParsedType(String name, String params){
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
}
|
||||
|
127
src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java
Normal file
127
src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java
Normal file
@ -0,0 +1,127 @@
|
||||
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.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
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.unify.model.PairOperator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ASPFactory implements TypeVisitor<String>{
|
||||
|
||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException{
|
||||
ASPFactory factory = new ASPFactory();
|
||||
factory.convertFC(fcClasses);
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
for(Pair p : constraint){
|
||||
factory.convertPair(p);
|
||||
}
|
||||
}
|
||||
|
||||
return factory.writer.getASPFile();
|
||||
}
|
||||
|
||||
ASPWriter writer = new ASPWriter();
|
||||
boolean isFCType = false;
|
||||
|
||||
private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
|
||||
Set<Pair> fc = FCGenerator.toFC(classes);
|
||||
isFCType = true;
|
||||
for(Pair fcp : fc){
|
||||
convertPair(fcp);
|
||||
}
|
||||
isFCType = false;
|
||||
}
|
||||
|
||||
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;
|
||||
if(!it.hasNext()){
|
||||
return ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
}
|
||||
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());
|
||||
String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString();
|
||||
ASPStatement stmt = makeStatement(ruleName, 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);
|
||||
writer.add(stmt);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
264
src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java
Normal file
264
src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java
Normal file
@ -0,0 +1,264 @@
|
||||
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.ASPGencayRule;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
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.unify.model.PairOperator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
/* TODO:
|
||||
* Alle TPHs müssen als var(tph) definiert sein
|
||||
* Wenn es eine Variable ist, dann direkt in die type-Regel schreiben: type(p, type, tph)
|
||||
* Für die FCTypen eindeutige Namen für die pph-Regeln
|
||||
* (ergibt sich von selbst, weil man einfach den Namen der TPH in der FC verwenden kann)
|
||||
* paramOrder wird benötigt!
|
||||
* Nur bei parameterlisten > 1
|
||||
* paramOrder(paralistPointer, parameter, num)
|
||||
* (ähnlich meiner paramNum)
|
||||
* Trennung von FC und Eq:
|
||||
* sub -> type -> param
|
||||
* ...Eq -> typeEq -> paramEq
|
||||
* type..(_,_,_p): p kann sein:
|
||||
* 1. Variable
|
||||
* 2. ParameterPointer
|
||||
* 3. null
|
||||
*/
|
||||
ASPWriter writer = new ASPWriter();
|
||||
boolean isFCType = false;
|
||||
|
||||
private static List<ASPStatement> generateVar(ConstraintSet<Pair> constraints){
|
||||
List<ASPStatement> ret = new ArrayList<>();
|
||||
for(TypePlaceholder tph : getInvolvedTPHS(constraints)){
|
||||
ret.add(makeStatement(ASPGencayRule.ASP_TYPE_VAR.toString(),
|
||||
ASPStringConverter.toConstant(tph.getName())));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected static Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
|
||||
List<TypePlaceholder> ret = new ArrayList<>();
|
||||
toTest.map((Pair p)-> {
|
||||
ret.addAll(p.TA1.acceptTV(new TPHExtractor()));
|
||||
ret.addAll(p.TA2.acceptTV(new TPHExtractor()));
|
||||
return p;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException{
|
||||
ASPGencayFactory factory = new ASPGencayFactory();
|
||||
factory.convertFC(fcClasses);
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
for(Pair p : constraint){
|
||||
factory.convertPair(p);
|
||||
}
|
||||
}
|
||||
factory.writer.addAll(generateVar(constraints));
|
||||
|
||||
return factory.writer.getASPFile();
|
||||
}
|
||||
|
||||
private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
|
||||
Set<Pair> fc = FCGenerator.toFC(classes);
|
||||
isFCType = true;
|
||||
for(Pair fcp : fc){
|
||||
generateTheta((RefType) fcp.TA1);
|
||||
generateTheta((RefType) fcp.TA2);
|
||||
convertPair(fcp);
|
||||
}
|
||||
isFCType = false;
|
||||
}
|
||||
|
||||
private void generateTheta(RefType t){
|
||||
String rule = "theta"+t.getParaList().size() ;
|
||||
String name = ASPStringConverter.toConstant(t.getName());
|
||||
writer.add(makeStatement(rule, name));
|
||||
}
|
||||
|
||||
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(ASPGencayRule.ASP_PAIR_SMALLER_DOT_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)){
|
||||
pairStmt = makeStatement(ASPGencayRule.ASP_PAIR_EQUALS_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
|
||||
pairStmt = makeStatement(ASPGencayRule.ASP_PAIR_SMALLER_NAME.toString(), ls, rs);
|
||||
}else throw new NotImplementedException();
|
||||
writer.add(pairStmt);
|
||||
}
|
||||
|
||||
private static 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){
|
||||
//if(pointers.size()==1)return pointers.get(0);
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
Iterator<String> it = pointers.iterator();
|
||||
String p = pointer;
|
||||
String paramname = ASPGencayRule.ASP_PARAMLIST_NAME.toString();
|
||||
if(this.isFCType)paramname = ASPGencayRule.ASP_FC_PARAMLIST_NAME.toString();
|
||||
if(!it.hasNext()){
|
||||
return ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
}
|
||||
while (it.hasNext()){
|
||||
ASPStatement stmt;
|
||||
String type = it.next();
|
||||
String nextP = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
if(it.hasNext()){
|
||||
stmt = makeStatement(paramname, p, type, nextP);
|
||||
}else{
|
||||
stmt = makeStatement(paramname, p, type,
|
||||
ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString());
|
||||
}
|
||||
p = nextP;
|
||||
writer.add(stmt);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
//Wird zum erstellen der pph(..) Regeln gebraucht
|
||||
private String currentFCTypePointer = "";
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
currentFCTypePointer = pointer;
|
||||
String paramPointer = ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
if(refType.getParaList().size() == 1 ){
|
||||
if(refType.getParaList().get(0) instanceof TypePlaceholder){
|
||||
TypePlaceholder typePlaceholder = (TypePlaceholder) refType.getParaList().get(0);
|
||||
paramPointer = typePlaceholder.acceptTV(this);
|
||||
}
|
||||
}else{
|
||||
List<String> params = null;
|
||||
params = generateParameter(refType);
|
||||
params.remove(0);
|
||||
paramPointer = convertParameterlist(params);
|
||||
if(refType.getParaList().size()>1){
|
||||
//paramOrder generieren:
|
||||
for(String param : params) {
|
||||
ASPStatement pOstmt = makeStatement(ASPGencayRule.ASP_PARAMLIST_ORDER.toString(),
|
||||
paramPointer, param);
|
||||
writer.add(pOstmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
String typeName = ASPStringConverter.toConstant(refType.getName());
|
||||
String ruleName = isFCType? ASPGencayRule.ASP_FCTYPE.toString(): ASPGencayRule.ASP_TYPE.toString();
|
||||
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, paramPointer);
|
||||
writer.add(stmt);
|
||||
return pointer;
|
||||
/*
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
List<String> params = null;
|
||||
params = generateParameter(refType);
|
||||
params.remove(0); //Das erste ist der eigentliche Typ kein parameter
|
||||
String typeName = ASPStringConverter.toConstant(refType.getName());
|
||||
String ruleName = isFCType? ASPGencayRule.ASP_FCTYPE.toString(): ASPGencayRule.ASP_TYPE.toString();
|
||||
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, convertParameterlist(params));
|
||||
writer.add(stmt);
|
||||
return pointer;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt die Parameterliste, wobei type auch schon als Parameter betrachtet wird.
|
||||
* Die RefTypes werden nicht zu extra type-Regeln umgewandelt. Es wird nur ihr Name als Konstante benutzt
|
||||
* Das funktioniert, weil nacher das ParamOrder zuteilt, welche Typen zusammenhängen.
|
||||
* Diese funktion nur verwenden, wenn auch ein paramOrder generiert wird
|
||||
*/
|
||||
private List<String> generateParameter(RefType type){
|
||||
List<String> ret = new ArrayList<>();
|
||||
ret.add(ASPStringConverter.toConstant(type.getName()));
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : type.getParaList()){
|
||||
if(param instanceof RefType){
|
||||
ret.addAll(generateParameter((RefType) param));
|
||||
}else if(param instanceof TypePlaceholder){
|
||||
ret.add(param.acceptTV(this));
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
String name = ASPStringConverter.toConstant(typePlaceholder.getName());
|
||||
|
||||
ASPStatement stmt = null;
|
||||
if(isFCType){
|
||||
stmt = makeStatement(ASPGencayRule.ASP_GENERIC_VAR.toString(),
|
||||
currentFCTypePointer, name);
|
||||
} else {
|
||||
stmt = makeStatement(ASPGencayRule.ASP_TYPE_VAR.toString(), name);
|
||||
}
|
||||
|
||||
writer.add(stmt);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static class TPHExtractor implements TypeVisitor<List<TypePlaceholder>>{
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(RefType refType) {
|
||||
ArrayList<TypePlaceholder> ret = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||
ret.addAll(param.acceptTV(this));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(SuperWildcardType superWildcardType) {
|
||||
return superWildcardType.getInnerType().acceptTV(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(TypePlaceholder typePlaceholder) {
|
||||
return Arrays.asList(typePlaceholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(ExtendsWildcardType extendsWildcardType) {
|
||||
return extendsWildcardType.getInnerType().acceptTV(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(GenericRefType genericRefType) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
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.writer.model.*;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPGenerator {
|
||||
ASPWriter writer = new ASPWriter();
|
||||
private final String asp;
|
||||
|
||||
public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException {
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
List<Pair> constraintPairs = new ArrayList<>();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
constraintPairs.addAll(constraint);
|
||||
}
|
||||
asp = toASP(constraintPairs, FCGenerator.toFC(fcClasses));
|
||||
}
|
||||
|
||||
public String getASP(){
|
||||
return asp;
|
||||
}
|
||||
|
||||
private String toASP(List<Pair> constraintSet, Collection<Pair> fc){
|
||||
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()));
|
||||
}
|
||||
for(Pair cons : constraintSet){
|
||||
writer.add(new ASPStatement(convert(cons).toASP()));
|
||||
}
|
||||
|
||||
return writer.getASPFile();
|
||||
}
|
||||
|
||||
private ASPPair convert(Pair pair){
|
||||
TypeConverter converter = new TypeConverter();
|
||||
ASPType ls = pair.TA1.acceptTV(converter);
|
||||
ASPType rs = pair.TA2.acceptTV(converter);
|
||||
if(pair.OperatorEqual()){
|
||||
return new ASPPairEquals(ls, rs,writer);
|
||||
}else if(pair.OperatorSmallerDot()){
|
||||
return new ASPPairSmallerDot(ls, rs, writer);
|
||||
}else if(pair.OperatorSmaller()){
|
||||
//Diese Cast müssen auch immer funktionieren, da in smaller Constraints nur RefTypes vorkommen
|
||||
return new ASPPairSmaller(new ASPFCType((ASPRefType) ls), new ASPFCType((ASPRefType) rs), writer);
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ASPRefType convert(ClassOrInterface cl){
|
||||
List<ASPType> paramList = new ArrayList<>();
|
||||
for(GenericTypeVar gtv : cl.getGenerics()){
|
||||
paramList.add(new ASPGenericType(ASPStringConverter.toConstant(gtv.getName())));
|
||||
}
|
||||
ASPParameterList params = new ASPParameterList(paramList, writer);
|
||||
return new ASPRefType(ASPStringConverter.toConstant(cl.getClassName()), params);
|
||||
}
|
||||
|
||||
private class TypeConverter implements TypeVisitor<ASPType>{
|
||||
|
||||
@Override
|
||||
public ASPType visit(RefType type) {
|
||||
List<ASPType> paramList = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric gtv : type.getParaList()){
|
||||
paramList.add(gtv.acceptTV(this));
|
||||
}
|
||||
ASPParameterList params = new ASPParameterList(paramList, writer);
|
||||
return new ASPRefType(ASPStringConverter.toConstant(type.getName()), params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(TypePlaceholder typePlaceholder) {
|
||||
return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(GenericRefType genericRefType) {
|
||||
return new ASPRefType(ASPStringConverter.toConstant(genericRefType.getParsedName()),
|
||||
new ASPParameterList(new ArrayList<>(), writer));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
public class ASPStatement {
|
||||
private final String stmt;
|
@ -1,8 +1,8 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPWriter {
|
||||
|
||||
@ -19,4 +19,8 @@ public class ASPWriter {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void addAll(Collection<ASPStatement> aspStatements) {
|
||||
content.addAll(aspStatements);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public class ASPFCType extends ASPRefType {
|
||||
public ASPFCType(ASPRefType refType){
|
||||
super(refType.name, refType.params);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASPRule.ASP_FCTYPE + "(" + name +"," + params.name + ")";
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
|
||||
public class ASPGenericType implements ASPType{
|
||||
private final String name;
|
||||
|
||||
public ASPGenericType(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public abstract class ASPPair {
|
||||
public final ASPType leftSide;
|
||||
public final ASPType rightSide;
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
public String toASP(){
|
||||
return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")";
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return toASP();
|
||||
}
|
||||
|
||||
protected abstract String getRuleName();
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public class ASPPairEquals extends ASPPair{
|
||||
public ASPPairEquals(ASPType ls, ASPType rs, ASPWriter writer){
|
||||
super(ls, rs, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASPRule.ASP_PAIR_EQUALS_NAME.toString();
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ASPPairSmaller extends ASPPair{
|
||||
public ASPPairSmaller(ASPFCType ls, ASPFCType rs, ASPWriter writer){
|
||||
super(ls, rs, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASPRule.ASP_PAIR_SMALLER_NAME.toString();
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public class ASPPairSmallerDot extends ASPPair{
|
||||
public ASPPairSmallerDot(ASPType ls, ASPType rs, ASPWriter writer){
|
||||
super(ls, rs, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPParameterList {
|
||||
public final String name;
|
||||
private final List<ASPType> types;
|
||||
|
||||
public ASPParameterList(List<ASPType> types, ASPWriter writer){
|
||||
int paramNum = 0;
|
||||
this.types = types;
|
||||
if(types.size() == 0){
|
||||
name = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
}else{
|
||||
name = newName();
|
||||
String nextPointer = name;
|
||||
Iterator<ASPType> it = types.iterator();
|
||||
while(it.hasNext()){
|
||||
ASPType t = it.next();
|
||||
String param = nextPointer + "," + t.toString() + ",";
|
||||
nextPointer = newName();
|
||||
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 + ")"));
|
||||
paramNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String newName() {
|
||||
return ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
|
||||
public class ASPRefType implements ASPType {
|
||||
protected final ASPParameterList params;
|
||||
protected final String name;
|
||||
|
||||
public ASPRefType(String name, ASPParameterList params){
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public ASPParameterList getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
public interface ASPType {
|
||||
String toASP();
|
||||
|
||||
String getPointer();
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
|
||||
public class ASPTypeVar implements ASPType{
|
||||
private final String name;
|
||||
|
||||
public ASPTypeVar(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ASPRule.ASP_TYPE_VAR+"("+ name +")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@ package asp;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||
import de.dhbwstuttgart.sat.asp.Clingo;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
@ -25,7 +25,7 @@ public class ClingoTest {
|
||||
@Test
|
||||
public void test() throws IOException, InterruptedException, ClassNotFoundException {
|
||||
String content = "";
|
||||
content = new ASPGenerator(this.getPairs(), this.getFC()).getASP();
|
||||
content = ASPFactory.generateASP(this.getPairs(), this.getFC());
|
||||
|
||||
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
|
||||
writer.println(content);
|
||||
|
@ -4,10 +4,11 @@ import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.sat.asp.Clingo;
|
||||
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
|
||||
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;
|
||||
@ -27,16 +28,19 @@ public class UnifyWithoutWildcards {
|
||||
@Test
|
||||
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 t2 = new RefType(new JavaClassName("Vector"), list, new NullToken());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
|
||||
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
run(testSet);
|
||||
ResultSet resultSet = run(testSet);
|
||||
System.out.println(ResultSetPrinter.print(resultSet));
|
||||
assert resultSet.results.size() > 0;
|
||||
}
|
||||
|
||||
public ResultSet run(ConstraintSet<Pair> toTest) throws IOException, InterruptedException, ClassNotFoundException {
|
||||
String content = "";
|
||||
content = new ASPGenerator(toTest, this.getFC()).getASP();
|
||||
content = ASPFactory.generateASP(toTest, this.getFC());
|
||||
|
||||
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
|
||||
writer.println(content);
|
||||
@ -77,7 +81,8 @@ public class UnifyWithoutWildcards {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
private Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
|
||||
|
||||
protected Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
|
||||
List<TypePlaceholder> ret = new ArrayList<>();
|
||||
toTest.map((Pair p)-> {
|
||||
ret.addAll(p.TA1.acceptTV(new TPHExtractor()));
|
||||
|
63
test/asp/gencay/GeneratorTest.java
Normal file
63
test/asp/gencay/GeneratorTest.java
Normal file
@ -0,0 +1,63 @@
|
||||
package asp.gencay;
|
||||
|
||||
import asp.UnifyWithoutWildcards;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.sat.asp.Clingo;
|
||||
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGencayFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
||||
public class GeneratorTest extends UnifyWithoutWildcards{
|
||||
@Test
|
||||
public void simple() throws ClassNotFoundException {
|
||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||
RefType t1 = new RefType(new JavaClassName("java.util.List"), list1, new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.util.List"), list2, new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
String resultSet = ASPGencayFactory.generateASP(testSet,
|
||||
new HashSet<>(Arrays.asList(ASTFactory.createClass(List.class))));
|
||||
System.out.println(resultSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrix() throws ClassNotFoundException {
|
||||
ConstraintSet<Pair> testSet = new ConstraintSet<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
|
||||
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
|
||||
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
|
||||
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
|
||||
String resultSet = ASPGencayFactory.generateASP(testSet, this.getFC());
|
||||
System.out.println(resultSet);
|
||||
}
|
||||
|
||||
private Collection<ClassOrInterface> getFC() {
|
||||
Set<ClassOrInterface> ret = new HashSet<>();
|
||||
ret.add(ASTFactory.createClass(Matrix.class));
|
||||
//ret.add(ASTFactory.createObjectClass());
|
||||
//ret.add(ASTFactory.createClass(java.util.List.class));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
class Matrix extends Vector<Vector<Integer>> {}
|
@ -1,7 +1,7 @@
|
||||
package asp.typeinference;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -55,8 +55,8 @@ public class ASPTest {
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = compiler.getConstraints();
|
||||
ASPGenerator generator = new ASPGenerator(cons, allClasses);
|
||||
System.out.println(generator.getASP());
|
||||
String asp = ASPFactory.generateASP(cons, allClasses);
|
||||
System.out.println(asp);
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
|
Loading…
Reference in New Issue
Block a user