diff --git a/src/de/dhbwstuttgart/sat/asp/Clingo.java b/src/de/dhbwstuttgart/sat/asp/Clingo.java index 9f529bbe..771da890 100644 --- a/src/de/dhbwstuttgart/sat/asp/Clingo.java +++ b/src/de/dhbwstuttgart/sat/asp/Clingo.java @@ -21,6 +21,7 @@ public class Clingo { programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/subst.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/unify.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/result.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/adapt.lp")); } @@ -37,7 +38,8 @@ public class Clingo { List commands = new ArrayList<>(); commands.add(pathToClingo); //commands.add("--outf=2"); //use JSON-Output - commands.add("--outf=1"); //use JSON-Output + commands.add("--outf=1"); //use Text-Output + commands.add("-n 0"); //Compute all models for(File file : input){ commands.add(file.getPath()); } @@ -47,6 +49,7 @@ public class Clingo { InputStream output = clingo.getInputStream(); clingo.waitFor(); String result = IOUtils.toString(output, StandardCharsets.UTF_8); + System.out.println(result); return result; } } diff --git a/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java b/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java index 80ebfc38..551d689b 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java @@ -16,13 +16,7 @@ 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; -import javax.json.JsonObject; -import java.io.StringReader; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -39,7 +33,7 @@ public class ASPParser extends UnifyResultBaseListener { private Map types = new HashMap<>(); private Set tphs = new HashSet<>(); private Map parameterLists = new HashMap<>(); - private Set equalsRelations = new HashSet<>(); + private Set unifierRelations = new HashSet<>(); private Set smallerRelations = new HashSet<>(); /** @@ -88,12 +82,12 @@ public class ASPParser extends UnifyResultBaseListener { } @Override - public void enterEquals(UnifyResultParser.EqualsContext ctx) { + public void enterUnifier(UnifyResultParser.UnifierContext ctx) { List parameterList = parseParameterList(ctx.parameterList()); - if(parameterList.size()<2)throw new DebugException("Fehler in Equals-Regel"); + if(parameterList.size()<2)throw new DebugException("Fehler in Unifier-Regel"); String ls = parameterList.get(0); String rs = parameterList.get(1); - equalsRelations.add(new Relation(ls, rs)); + unifierRelations.add(new Relation(ls, rs)); } @@ -172,7 +166,7 @@ public class ASPParser extends UnifyResultBaseListener { //for(String paramPointer : types.values().stream().map(parsedType -> parsedType.params).collect(Collectors.toList())){ } //Dann die Equalsdot Statements - for(Relation eq : equalsRelations){ + for(Relation eq : unifierRelations){ RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(eq.left); RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(eq.right); if(lsType instanceof TypePlaceholder && rsType instanceof RefType) diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4 b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4 index 98b6a5fb..c00e2bd6 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4 +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4 @@ -8,6 +8,7 @@ resultSetRule : | smaller | typeVar | type + | unifier | otherRule ; @@ -17,6 +18,7 @@ value : NAME parameter : PARAMLIST_NAME parameterList; equals : EQUALS_NAME parameterList; +unifier : UNIFIER_NAME parameterList; smaller : SMALLER_NAME parameterList; typeVar : TYPEVAR_NAME parameterList; type : TYPE_NAME parameterList; @@ -24,6 +26,7 @@ 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'; +UNIFIER_NAME : 'unifier'; EQUALS_NAME : 'equals'; SMALLER_NAME : 'smaller'; TYPEVAR_NAME : 'typeVar'; diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens index 8f9c0e0a..23aea6a8 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens @@ -4,20 +4,22 @@ 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 +UNIFIER_NAME=7 +EQUALS_NAME=8 +SMALLER_NAME=9 +TYPEVAR_NAME=10 +TYPE_NAME=11 +NAME=12 +WS=13 +LINE_COMMENT=14 'ANSWER'=1 '.'=2 '('=3 ','=4 ')'=5 'param'=6 -'equals'=7 -'smaller'=8 -'typeVar'=9 -'type'=10 +'unifier'=7 +'equals'=8 +'smaller'=9 +'typeVar'=10 +'type'=11 diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultBaseListener.java b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultBaseListener.java index f33525d7..eafb4c42 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultBaseListener.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultBaseListener.java @@ -83,6 +83,18 @@ public class UnifyResultBaseListener implements UnifyResultListener { *

The default implementation does nothing.

*/ @Override public void exitEquals(UnifyResultParser.EqualsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterUnifier(UnifyResultParser.UnifierContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitUnifier(UnifyResultParser.UnifierContext ctx) { } /** * {@inheritDoc} * diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java index b8660eba..67b90e8e 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java @@ -17,8 +17,9 @@ public class UnifyResultLexer extends Lexer { 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; + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, UNIFIER_NAME=7, + EQUALS_NAME=8, SMALLER_NAME=9, TYPEVAR_NAME=10, TYPE_NAME=11, NAME=12, + WS=13, LINE_COMMENT=14; public static String[] channelNames = { "DEFAULT_TOKEN_CHANNEL", "HIDDEN" }; @@ -28,17 +29,19 @@ public class UnifyResultLexer extends Lexer { }; 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" + "T__0", "T__1", "T__2", "T__3", "T__4", "PARAMLIST_NAME", "UNIFIER_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'" + null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'unifier'", + "'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" + null, null, null, null, null, null, "PARAMLIST_NAME", "UNIFIER_NAME", + "EQUALS_NAME", "SMALLER_NAME", "TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", + "LINE_COMMENT" }; public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); @@ -98,31 +101,33 @@ public class UnifyResultLexer extends Lexer { 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\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\20m\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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\3\2\2\2\37 \7C\2\2 !\7P\2\2!\"\7U\2\2\"#\7Y\2\2#"+ + "$\7G\2\2$%\7T\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/\60\7c\2\2\60\61\7"+ + "t\2\2\61\62\7c\2\2\62\63\7o\2\2\63\16\3\2\2\2\64\65\7w\2\2\65\66\7p\2"+ + "\2\66\67\7k\2\2\678\7h\2\289\7k\2\29:\7g\2\2:;\7t\2\2;\20\3\2\2\2<=\7"+ + "g\2\2=>\7s\2\2>?\7w\2\2?@\7c\2\2@A\7n\2\2AB\7u\2\2B\22\3\2\2\2CD\7u\2"+ + "\2DE\7o\2\2EF\7c\2\2FG\7n\2\2GH\7n\2\2HI\7g\2\2IJ\7t\2\2J\24\3\2\2\2K"+ + "L\7v\2\2LM\7{\2\2MN\7r\2\2NO\7g\2\2OP\7X\2\2PQ\7c\2\2QR\7t\2\2R\26\3\2"+ + "\2\2ST\7v\2\2TU\7{\2\2UV\7r\2\2VW\7g\2\2W\30\3\2\2\2XZ\t\2\2\2YX\3\2\2"+ + "\2Z[\3\2\2\2[Y\3\2\2\2[\\\3\2\2\2\\\32\3\2\2\2]_\t\3\2\2^]\3\2\2\2_`\3"+ + "\2\2\2`^\3\2\2\2`a\3\2\2\2ab\3\2\2\2bc\b\16\2\2c\34\3\2\2\2dh\7\'\2\2"+ + "eg\n\4\2\2fe\3\2\2\2gj\3\2\2\2hf\3\2\2\2hi\3\2\2\2ik\3\2\2\2jh\3\2\2\2"+ + "kl\b\17\2\2l\36\3\2\2\2\6\2[`h\3\b\2\2"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.tokens b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.tokens index 8f9c0e0a..23aea6a8 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.tokens +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.tokens @@ -4,20 +4,22 @@ 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 +UNIFIER_NAME=7 +EQUALS_NAME=8 +SMALLER_NAME=9 +TYPEVAR_NAME=10 +TYPE_NAME=11 +NAME=12 +WS=13 +LINE_COMMENT=14 'ANSWER'=1 '.'=2 '('=3 ','=4 ')'=5 'param'=6 -'equals'=7 -'smaller'=8 -'typeVar'=9 -'type'=10 +'unifier'=7 +'equals'=8 +'smaller'=9 +'typeVar'=10 +'type'=11 diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultListener.java b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultListener.java index 6158b123..f760ceb7 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultListener.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultListener.java @@ -67,6 +67,16 @@ public interface UnifyResultListener extends ParseTreeListener { * @param ctx the parse tree */ void exitEquals(UnifyResultParser.EqualsContext ctx); + /** + * Enter a parse tree produced by {@link UnifyResultParser#unifier}. + * @param ctx the parse tree + */ + void enterUnifier(UnifyResultParser.UnifierContext ctx); + /** + * Exit a parse tree produced by {@link UnifyResultParser#unifier}. + * @param ctx the parse tree + */ + void exitUnifier(UnifyResultParser.UnifierContext ctx); /** * Enter a parse tree produced by {@link UnifyResultParser#smaller}. * @param ctx the parse tree diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java index bf0789f1..18c78dd7 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java @@ -17,24 +17,26 @@ public class UnifyResultParser extends Parser { 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; + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, UNIFIER_NAME=7, + EQUALS_NAME=8, SMALLER_NAME=9, TYPEVAR_NAME=10, TYPE_NAME=11, NAME=12, + WS=13, LINE_COMMENT=14; 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; + RULE_parameter = 4, RULE_equals = 5, RULE_unifier = 6, RULE_smaller = 7, + RULE_typeVar = 8, RULE_type = 9, RULE_otherRule = 10; public static final String[] ruleNames = { "answer", "resultSetRule", "parameterList", "value", "parameter", "equals", - "smaller", "typeVar", "type", "otherRule" + "unifier", "smaller", "typeVar", "type", "otherRule" }; private static final String[] _LITERAL_NAMES = { - null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'equals'", "'smaller'", - "'typeVar'", "'type'" + null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'unifier'", + "'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" + null, null, null, null, null, null, "PARAMLIST_NAME", "UNIFIER_NAME", + "EQUALS_NAME", "SMALLER_NAME", "TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", + "LINE_COMMENT" }; public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); @@ -113,21 +115,21 @@ public class UnifyResultParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(20); + setState(22); match(T__0); - setState(26); + setState(28); _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)) { + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PARAMLIST_NAME) | (1L << UNIFIER_NAME) | (1L << EQUALS_NAME) | (1L << SMALLER_NAME) | (1L << TYPEVAR_NAME) | (1L << TYPE_NAME) | (1L << NAME))) != 0)) { { { - setState(21); + setState(23); resultSetRule(); - setState(22); + setState(24); match(T__1); } } - setState(28); + setState(30); _errHandler.sync(this); _la = _input.LA(1); } @@ -160,6 +162,9 @@ public class UnifyResultParser extends Parser { public TypeContext type() { return getRuleContext(TypeContext.class,0); } + public UnifierContext unifier() { + return getRuleContext(UnifierContext.class,0); + } public OtherRuleContext otherRule() { return getRuleContext(OtherRuleContext.class,0); } @@ -181,48 +186,55 @@ public class UnifyResultParser extends Parser { ResultSetRuleContext _localctx = new ResultSetRuleContext(_ctx, getState()); enterRule(_localctx, 2, RULE_resultSetRule); try { - setState(35); + setState(38); _errHandler.sync(this); switch (_input.LA(1)) { case PARAMLIST_NAME: enterOuterAlt(_localctx, 1); { - setState(29); + setState(31); parameter(); } break; case EQUALS_NAME: enterOuterAlt(_localctx, 2); { - setState(30); + setState(32); equals(); } break; case SMALLER_NAME: enterOuterAlt(_localctx, 3); { - setState(31); + setState(33); smaller(); } break; case TYPEVAR_NAME: enterOuterAlt(_localctx, 4); { - setState(32); + setState(34); typeVar(); } break; case TYPE_NAME: enterOuterAlt(_localctx, 5); { - setState(33); + setState(35); type(); } break; - case NAME: + case UNIFIER_NAME: enterOuterAlt(_localctx, 6); { - setState(34); + setState(36); + unifier(); + } + break; + case NAME: + enterOuterAlt(_localctx, 7); + { + setState(37); otherRule(); } break; @@ -269,27 +281,27 @@ public class UnifyResultParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(37); + setState(40); match(T__2); - setState(38); + setState(41); value(); - setState(43); + setState(46); _errHandler.sync(this); _la = _input.LA(1); while (_la==T__3) { { { - setState(39); + setState(42); match(T__3); - setState(40); + setState(43); value(); } } - setState(45); + setState(48); _errHandler.sync(this); _la = _input.LA(1); } - setState(46); + setState(49); match(T__4); } } @@ -327,20 +339,20 @@ public class UnifyResultParser extends Parser { ValueContext _localctx = new ValueContext(_ctx, getState()); enterRule(_localctx, 6, RULE_value); try { - setState(50); + setState(53); _errHandler.sync(this); switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) { case 1: enterOuterAlt(_localctx, 1); { - setState(48); + setState(51); match(NAME); } break; case 2: enterOuterAlt(_localctx, 2); { - setState(49); + setState(52); resultSetRule(); } break; @@ -382,9 +394,9 @@ public class UnifyResultParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(52); + setState(55); match(PARAMLIST_NAME); - setState(53); + setState(56); parameterList(); } } @@ -424,9 +436,51 @@ public class UnifyResultParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(55); + setState(58); match(EQUALS_NAME); - setState(56); + setState(59); + parameterList(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class UnifierContext extends ParserRuleContext { + public TerminalNode UNIFIER_NAME() { return getToken(UnifyResultParser.UNIFIER_NAME, 0); } + public ParameterListContext parameterList() { + return getRuleContext(ParameterListContext.class,0); + } + public UnifierContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_unifier; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterUnifier(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitUnifier(this); + } + } + + public final UnifierContext unifier() throws RecognitionException { + UnifierContext _localctx = new UnifierContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_unifier); + try { + enterOuterAlt(_localctx, 1); + { + setState(61); + match(UNIFIER_NAME); + setState(62); parameterList(); } } @@ -462,13 +516,13 @@ public class UnifyResultParser extends Parser { public final SmallerContext smaller() throws RecognitionException { SmallerContext _localctx = new SmallerContext(_ctx, getState()); - enterRule(_localctx, 12, RULE_smaller); + enterRule(_localctx, 14, RULE_smaller); try { enterOuterAlt(_localctx, 1); { - setState(58); + setState(64); match(SMALLER_NAME); - setState(59); + setState(65); parameterList(); } } @@ -504,13 +558,13 @@ public class UnifyResultParser extends Parser { public final TypeVarContext typeVar() throws RecognitionException { TypeVarContext _localctx = new TypeVarContext(_ctx, getState()); - enterRule(_localctx, 14, RULE_typeVar); + enterRule(_localctx, 16, RULE_typeVar); try { enterOuterAlt(_localctx, 1); { - setState(61); + setState(67); match(TYPEVAR_NAME); - setState(62); + setState(68); parameterList(); } } @@ -546,13 +600,13 @@ public class UnifyResultParser extends Parser { public final TypeContext type() throws RecognitionException { TypeContext _localctx = new TypeContext(_ctx, getState()); - enterRule(_localctx, 16, RULE_type); + enterRule(_localctx, 18, RULE_type); try { enterOuterAlt(_localctx, 1); { - setState(64); + setState(70); match(TYPE_NAME); - setState(65); + setState(71); parameterList(); } } @@ -588,13 +642,13 @@ public class UnifyResultParser extends Parser { public final OtherRuleContext otherRule() throws RecognitionException { OtherRuleContext _localctx = new OtherRuleContext(_ctx, getState()); - enterRule(_localctx, 18, RULE_otherRule); + enterRule(_localctx, 20, RULE_otherRule); try { enterOuterAlt(_localctx, 1); { - setState(67); + setState(73); match(NAME); - setState(68); + setState(74); parameterList(); } } @@ -610,24 +664,25 @@ public class UnifyResultParser extends Parser { } public static final String _serializedATN = - "\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\2*+\7\5\2\2+\60\5\b\5\2,-\7\6\2\2-/\5\b\5\2.,\3\2\2\2/\62"+ + "\3\2\2\2\60.\3\2\2\2\60\61\3\2\2\2\61\63\3\2\2\2\62\60\3\2\2\2\63\64\7"+ + "\7\2\2\64\7\3\2\2\2\658\7\16\2\2\668\5\4\3\2\67\65\3\2\2\2\67\66\3\2\2"+ + "\28\t\3\2\2\29:\7\b\2\2:;\5\6\4\2;\13\3\2\2\2<=\7\n\2\2=>\5\6\4\2>\r\3"+ + "\2\2\2?@\7\t\2\2@A\5\6\4\2A\17\3\2\2\2BC\7\13\2\2CD\5\6\4\2D\21\3\2\2"+ + "\2EF\7\f\2\2FG\5\6\4\2G\23\3\2\2\2HI\7\r\2\2IJ\5\6\4\2J\25\3\2\2\2KL\7"+ + "\16\2\2LM\5\6\4\2M\27\3\2\2\2\6\36(\60\67"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { diff --git a/test/asp/UnifyWithoutWildcards.java b/test/asp/UnifyWithoutWildcards.java index 6f69d639..40ea0bc7 100644 --- a/test/asp/UnifyWithoutWildcards.java +++ b/test/asp/UnifyWithoutWildcards.java @@ -11,6 +11,7 @@ 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.ResolvedType; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import org.junit.Test; @@ -34,8 +35,33 @@ public class UnifyWithoutWildcards { RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken()); testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); ResultSet resultSet = run(testSet); - System.out.println(ResultSetPrinter.print(resultSet)); + //System.out.println(ResultSetPrinter.print(resultSet)); assert resultSet.results.size() > 0; + ResolvedType rsType = resultSet.resolveType(list2.get(1)); + assert ((RefType)rsType.resolvedType).getName().equals("java.util.Map"); + } + + @Test + public void adaptNewParaListTest1() throws InterruptedException, IOException, ClassNotFoundException { + ConstraintSet testSet = new ConstraintSet<>(); + List list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); + RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test1"), list1, new NullToken()); + RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); + testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); + ResultSet resultSet = run(testSet); + //System.out.println(ResultSetPrinter.print(resultSet)); + assert resultSet.results.size() == 0; //Hier gibt es keine Lösung. + //TODO: Kann in zukünfigen Fällen eine Lösung geben + } + + @Test + public void step1() throws InterruptedException, IOException, ClassNotFoundException { + ConstraintSet testSet = new ConstraintSet<>(); + TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); + RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); + testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); + ResultSet resultSet = run(testSet); + System.out.println(resultSet.results.size()); } public ResultSet run(ConstraintSet toTest) throws IOException, InterruptedException, ClassNotFoundException { @@ -95,9 +121,12 @@ public class UnifyWithoutWildcards { private Collection getFC() { Set ret = new HashSet<>(); ret.add(ASTFactory.createClass(Matrix.class)); + ret.add(ASTFactory.createClass(Test1.class)); //ret.add(ASTFactory.createObjectClass()); //ret.add(ASTFactory.createClass(java.util.List.class)); return ret; } private class Matrix extends HashMap>{} + + private class Test1 extends Object{} }