This commit is contained in:
Fayez Abu Alia 2018-01-31 14:23:19 +01:00
commit 398c1992fa
75 changed files with 627 additions and 435 deletions

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.NegativeExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr</li>
</ul>
</li>
</ul>

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.NotExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr</li>
</ul>
</li>
</ul>

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.PositivExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr</li>
</ul>
</li>
</ul>

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.PostDecExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr</li>
</ul>
</li>
</ul>

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.PostIncExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr</li>
</ul>
</li>
</ul>

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.PreDecExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr</li>
</ul>
</li>
</ul>

View File

@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.UnaryExpr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.PreIncExpr</li>
<li>de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr</li>
</ul>
</li>
</ul>

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.NegativeExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.NegativeExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.NegativeExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.NegativeExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.NegativeExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.NotExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.NotExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.NotExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.NotExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.NotExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.PositivExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.PositivExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PositivExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PositivExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.PositivExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.PostDecExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.PostDecExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PostDecExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PostDecExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.PostDecExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.PostIncExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.PostIncExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PostIncExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PostIncExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.PostIncExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.PreDecExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.PreDecExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PreDecExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PreDecExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.PreDecExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.PreIncExpr</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,9 +70,9 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.PreIncExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PreIncExpr</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.PreIncExpr</h2>
</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.PreIncExpr</div>
<div class="classUseContainer">No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->

View File

@ -22,6 +22,11 @@
<artifactId>antlr4</artifactId>
<version>4.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.bytecode;
import java.util.HashMap;
import java.util.Iterator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
@ -371,12 +372,6 @@ public class BytecodeGen implements ASTVisitor {
}
@Override
public void visit(UnaryPlus unaryPlus) {
// TODO Auto-generated method stub
}
@Override
public void visit(WhileStmt whileStmt) {
// TODO Auto-generated method stub
@ -442,4 +437,9 @@ public class BytecodeGen implements ASTVisitor {
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
}

View File

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
@ -383,6 +384,11 @@ public class BytecodeGenMethod implements StatementVisitor{
receiver.expr.accept(this);
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
@Override
public void visit(Return aReturn) {
aReturn.retexpr.accept(this);
@ -412,11 +418,6 @@ public class BytecodeGenMethod implements StatementVisitor{
mv.visitVarInsn(Opcodes.ALOAD, 0);
}
@Override
public void visit(UnaryPlus unaryPlus) {
}
@Override
public void visit(WhileStmt whileStmt) {
// TODO Auto-generated method stub

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;
import java.util.ArrayList;
@ -126,6 +127,11 @@ public class KindOfLambda implements StatementVisitor{
receiver.expr.accept(this);
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
@Override
public void visit(Return aReturn) {
aReturn.retexpr.accept(this);
@ -155,12 +161,6 @@ public class KindOfLambda implements StatementVisitor{
this.argumentList.add(aThis.getType());
}
@Override
public void visit(UnaryPlus unaryPlus) {
// TODO Auto-generated method stub
}
@Override
public void visit(WhileStmt whileStmt) {
// TODO Auto-generated method stub

View File

@ -43,7 +43,7 @@ public class NormalMethod {
}
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return method.getType();
return method.getReturnType();
}
public boolean hasGen() {

View File

@ -89,6 +89,7 @@ public class JavaTXCompiler {
final ConstraintSet<Pair> cons = getConstraints();
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
System.out.println(finiteClosure);
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
TypeUnify unify = new TypeUnify();

View File

@ -0,0 +1,150 @@
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.*;
import java.util.*;
public class FCGenerator {
/**
* Baut die FiniteClosure aus availableClasses.
* Klassen welche nicht in availableClasses vorkommen werden im Java Classpath nachgeschlagen.
*
* @param availableClasses - Alle geparsten Klassen
*/
public static Set<UnifyPair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
HashSet<UnifyPair> pairs = new HashSet<>();
for(ClassOrInterface cly : availableClasses){
pairs.addAll(getSuperTypes(cly, availableClasses));
}
System.out.println(pairs);
return pairs;
}
/**
* Bildet eine Kette vom übergebenen Typ bis hin zum höchsten bekannten Typ
* Als Generics werden TPHs benutzt, welche der Unifikationsalgorithmus korrekt interpretieren muss.
* Die verwendeten TPHs werden in der Kette nach oben gereicht, so erhält der selbe GTV immer den selben TPH
* @param forType
* @return
*/
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
return getSuperTypes(forType, availableClasses, new HashMap<>());
}
//TODO: implements Interface auch als superklassen beachten
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, HashMap<String, UnifyType> gtvs) throws ClassNotFoundException {
List<UnifyType> params = new ArrayList<>();
//Die GTVs, die in forType hinzukommen:
HashMap<String, UnifyType> newGTVs = new HashMap<>();
//Generics mit gleichem Namen müssen den selben TPH bekommen
for(GenericTypeVar gtv : forType.getGenerics()){
if(!gtvs.containsKey(gtv.getParsedName())){
gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
newGTVs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
}
params.add(gtvs.get(gtv.getParsedName()));
}
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny();
ClassOrInterface superClass;
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
{
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString()));
}else{
superClass = hasSuperclass.get();
}
/*
Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse
modifiziert werden
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
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = forType.getSuperClass().getParaList().iterator();
while(itGenParams.hasNext()){
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
UnifyType setSetType = setType.acceptTV(new TypeExchanger(gtvs));
newGTVs.put(itGenParams.next().getParsedName(), setSetType);
}
UnifyType superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs));
TypeParams paramList = new TypeParams(params);
UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList);
UnifyType t2 = superType;
UnifyPair ret = UnifyTypeFactory.generateSmallerPair(t1, t2);
List<UnifyPair> superTypes;
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
superTypes = Arrays.asList(UnifyTypeFactory.generateSmallerPair(UnifyTypeFactory.convert(ASTFactory.createObjectType()), UnifyTypeFactory.convert(ASTFactory.createObjectType())));
}else{
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
}
List<UnifyPair> retList = new ArrayList<>();
retList.add(ret);
retList.addAll(superTypes);
return retList;
}
/**
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
*/
private static class TypeExchanger implements TypeVisitor<UnifyType>{
private final HashMap<String, UnifyType> gtvs;
TypeExchanger(HashMap<String, UnifyType> gtvs){
this.gtvs = gtvs;
}
@Override
public UnifyType visit(RefType refType) {
List<UnifyType> params = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
params.add(param.acceptTV(this));
}
TypeParams paramList = new TypeParams(params);
UnifyType ret = new ReferenceType(refType.getName().toString(), paramList);
return ret;
}
@Override
public UnifyType visit(SuperWildcardType superWildcardType) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public UnifyType visit(TypePlaceholder typePlaceholder) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public UnifyType visit(ExtendsWildcardType extendsWildcardType) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public UnifyType 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());
}
}
}

View File

@ -16,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.lang.reflect.Type;
import java.util.*;
public class StatementGenerator {
@ -95,7 +96,7 @@ public class StatementGenerator {
private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) {
if(stmt.block() != null){
return convert(stmt.block());
return convert(stmt.block(), false);
}else if(stmt.emptyStatement() != null){
return new EmptyStmt(stmt.getStart());
}else if(stmt.expressionStatement() != null){
@ -121,14 +122,14 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
public Block convert(Java8Parser.BlockContext block) {
public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) {
List<Statement> statements = new ArrayList<>();
if(block.blockStatements() != null)
for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){
List<Statement> stmt = convert(statementContext);
statements.addAll(stmt);
}
statements = SyntacticSugar.addTrailingReturn(statements);
if(addTrailingReturn)statements = SyntacticSugar.addTrailingReturn(statements);
return new Block(statements, block.getStart());
}
@ -289,8 +290,8 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
//TODO
throw new NotImplementedException();
return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
}
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
@ -316,8 +317,10 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.IfThenElseStatementContext stmt){
//TODO
throw new NotImplementedException();
Expression expr = convert(stmt.expression());
Statement thenBlock = convert(stmt.statementNoShortIf());
Statement elseBlock = convert(stmt.statement());
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()), expr, thenBlock, elseBlock, stmt.getStart());
}
private Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){
@ -591,7 +594,7 @@ public class StatementGenerator {
if(expression.relationalExpression() == null){
return convert(expression.shiftExpression());
}else{
throw new NotImplementedException();
return convert(expression.relationalExpression());
}
}
@ -604,7 +607,9 @@ public class StatementGenerator {
}
private Expression convert(Java8Parser.AdditiveExpressionContext expression) {
if(expression.additiveExpression() == null){
if(expression.additiveExpression() != null){
return convert(expression.additiveExpression());
}else if(expression.multiplicativeExpression() != null){
return convert(expression.multiplicativeExpression());
}else{
throw new NotImplementedException();
@ -627,9 +632,11 @@ public class StatementGenerator {
}else if(expression.unaryExpressionNotPlusMinus() != null){
return convert(expression.unaryExpressionNotPlusMinus());
}else if(expression.getText().startsWith("+")){
return new UnaryPlus(convert(expression.unaryExpression()));
return new UnaryExpr(UnaryExpr.Operation.PLUS, convert(expression.unaryExpression()),
TypePlaceholder.fresh(expression.getStart()), expression.getStart());
}else if(expression.getText().startsWith("-")){
return new UnaryMinus(convert(expression.unaryExpression()));
return new UnaryExpr(UnaryExpr.Operation.MINUS, convert(expression.unaryExpression()),
TypePlaceholder.fresh(expression.getStart()), expression.getStart());
}else{
//Diese Exceptions sollte nie geworfen werden.
//Der Code wurde nur noch nicht getestet. Sollte zur Sicherheit drin bleiben.
@ -672,10 +679,10 @@ public class StatementGenerator {
}
for(Java8Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){
expr = new PostIncExpr(expr);
expr = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, expr, TypePlaceholder.fresh(inc.getStart()), inc.getStart());
}
for(Java8Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){
expr = new PostDecExpr(expr);
expr = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, expr, TypePlaceholder.fresh(dec.getStart()), dec.getStart());
}
return expr;
@ -850,7 +857,7 @@ public class StatementGenerator {
expression.lambdaBody().expression().getStart()));
block = new Block(statements, expression.lambdaBody().getStart());
}else{
block = lambdaGenerator.convert(expression.lambdaBody().block());
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
}
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type

View File

@ -1,6 +1,9 @@
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.statement.*;
import java.util.List;
@ -10,22 +13,27 @@ public class SyntacticSugar {
public static List<Statement> addTrailingReturn(List<Statement> statements){
if(statements.size()!=0) {
Statement lastStmt = statements.get(statements.size() - 1);
if (lastStmt instanceof Return) return statements;
if (lastStmt instanceof WhileStmt) {
//TODO
//if (hasReturn(((WhileStmt) lastStmt).loopBlock)) return statements;
} else if (lastStmt instanceof IfStmt) {
if (hasReturn(((IfStmt) lastStmt).then_block)
&& hasReturn(((IfStmt) lastStmt).else_block)) return statements;
} else if (lastStmt instanceof ForStmt) {
if (hasReturn(((ForStmt) lastStmt).body_Loop_block)) return statements;
} else {
}
ReturnFinder hasReturn = new ReturnFinder();
lastStmt.accept(hasReturn);
if(hasReturn.hasReturn)return statements;
}
statements.add(new ReturnVoid(new NullToken()));
return statements;
}
private static class ReturnFinder extends AbstractASTWalker{
public boolean hasReturn = false;
@Override
public void visit(Return aReturn) {
hasReturn = true;
}
@Override
public void visit(ReturnVoid aReturn) {
hasReturn = true;
}
}
private static boolean hasReturn(Block block){
for(Statement s : block.getStatements())
if(s instanceof Return)return true;

View File

@ -136,12 +136,12 @@ public class SyntaxTreeGenerator{
//TODO: Error! Abstrakte Methode ohne abstrakt Keyword
}
}else{
block = stmtGen.convert(body.block());
block = stmtGen.convert(body.block(),true);
}
if(parentClass.equals(new JavaClassName(name))){
return new Constructor(modifiers, name, retType, modifiers, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations);
return new Constructor(modifiers, name, retType, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations);
}else{
return new Method(modifiers, name, retType, modifiers, parameterList,block, gtvDeclarations, header.getStart());
return new Method(modifiers, name, retType, parameterList,block, gtvDeclarations, header.getStart());
}
}
@ -221,10 +221,9 @@ public class SyntaxTreeGenerator{
*/
private Constructor generateStandardConstructor(String className, JavaClassName parentClass, RefType superClass, GenericDeclarationList classGenerics, Token offset){
RefType classType = ClassOrInterface.generateTypeOfClass(reg.getName(className), classGenerics, offset);
int modifiers = 0;
ParameterList params = new ParameterList(new ArrayList<>(), offset);
Block block = new Block(new ArrayList<>(), offset);
return new Constructor(Modifier.PUBLIC, className, classType, modifiers, params, block, classGenerics, offset, fieldInitializations);
return new Constructor(Modifier.PUBLIC, className, classType, params, block, classGenerics, offset, fieldInitializations);
}
private RefType convert(Java8Parser.SuperclassContext superclass) {

View File

@ -40,7 +40,12 @@ public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
if(unannTypeContext.unannPrimitiveType()!=null){
throw new NotImplementedException();
if(unannTypeContext.unannPrimitiveType().getText().equals("boolean")){
return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), unannTypeContext.getStart());
}else{
Java8Parser.NumericTypeContext numericType = unannTypeContext.unannPrimitiveType().numericType();
throw new NotImplementedException();
}
}else
if(unannTypeContext.unannReferenceType().unannArrayType()!=null){
//System.out.println(unannTypeContext.getText());

View File

@ -0,0 +1,46 @@
package de.dhbwstuttgart.sat.asp;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Clingo {
private final List<File> input;
private static final List<File> programFiles = new ArrayList<>();
static{
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/basis.lp"));
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/reduce1.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce2.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/unify.lp"));
}
public Clingo(List<File> inputFiles){
this.input = inputFiles;
}
public String runClingo() throws IOException, InterruptedException {
String pathToClingo =
"/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
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();
String result = IOUtils.toString(output, StandardCharsets.UTF_8);
return result;
}
}

View File

@ -0,0 +1,24 @@
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")
;
private final String text;
private ASPRule(final String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View File

@ -1,4 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
public interface ASPType {
}

View File

@ -0,0 +1,17 @@
package de.dhbwstuttgart.sat.asp.parser;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import java.util.HashSet;
import java.util.Set;
public class ASPParser {
ResultSet parse(String result){
Set<ResultPair> ret = new HashSet<>();
for(String pair : result.split(",")){
}
return new ResultSet(ret);
}
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.sat.asp.parser.model;
public class ParsedASPStatement {
public ParsedASPStatement(String statement){
}
}

View File

@ -1,9 +1,8 @@
package de.dhbwstuttgart.sat.asp;
package de.dhbwstuttgart.sat.asp.writer;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.model.*;
import de.dhbwstuttgart.sat.asp.writer.model.*;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
@ -11,13 +10,10 @@ 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.UnifyType;
import java.sql.Ref;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class ASPGenerator {
ASPWriter writer = new ASPWriter();

View File

@ -1,8 +1,6 @@
package de.dhbwstuttgart.sat.asp;
package de.dhbwstuttgart.sat.asp.writer;
import de.dhbwstuttgart.sat.asp.model.ASPRefType;
import de.dhbwstuttgart.sat.asp.model.ASPStatement;
import de.dhbwstuttgart.sat.asp.model.ASPType;
import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement;
import java.util.HashSet;

View File

@ -1,7 +1,8 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
public class ASPGenericType implements ASPType{
public static final String ASP_GENERIC_TYPE_NAME = "genericType";
private final String name;
public ASPGenericType(String name){
@ -9,6 +10,6 @@ public class ASPGenericType implements ASPType{
}
public String toString(){
return ASP_GENERIC_TYPE_NAME + "(" + name + ")";
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
}
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
public abstract class ASPPair {
public final ASPType leftSide;

View File

@ -1,13 +1,14 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
public class ASPPairEquals extends ASPPair{
private final static String ASP_PAIR_EQUALS_NAME = "equals";
public ASPPairEquals(ASPType ls, ASPType rs){
super(ls, rs);
}
@Override
protected String getRuleName() {
return ASP_PAIR_EQUALS_NAME;
return ASPRule.ASP_PAIR_EQUALS_NAME.toString();
}
}

View File

@ -1,13 +1,16 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import java.util.Map;
public class ASPPairSmaller extends ASPPair{
private final static String ASP_PAIR_SMALLER_NAME = "smaller";
public ASPPairSmaller(ASPType ls, ASPType rs){
super(ls, rs);
}
@Override
protected String getRuleName() {
return ASP_PAIR_SMALLER_NAME;
return ASPRule.ASP_PAIR_SMALLER_NAME.toString();
}
}
}

View File

@ -1,13 +1,14 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
public class ASPPairSmallerDot extends ASPPair{
private final static String ASP_PAIR_SMALLER_NAME = "smallerDot";
public ASPPairSmallerDot(ASPType ls, ASPType rs){
super(ls, rs);
}
@Override
protected String getRuleName() {
return ASP_PAIR_SMALLER_NAME;
return ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString();
}
}

View File

@ -1,24 +1,22 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.ASPGenerator;
import de.dhbwstuttgart.sat.asp.ASPWriter;
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.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class ASPParameterList {
private final static String ASP_PARAMLIST_NAME = "param";
private final static String ASP_PARAMLIST_END_POINTER = "null";
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 = ASP_PARAMLIST_END_POINTER;
name = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
}else{
name = newName();
String nextPointer = name;
@ -27,9 +25,11 @@ public class ASPParameterList {
ASPType t = it.next();
String param = nextPointer + "," + t.toString() + ",";
nextPointer = newName();
if(! it.hasNext())nextPointer = ASP_PARAMLIST_END_POINTER;
if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
param += nextPointer;
writer.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")"));
writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")"));
paramNum++;
//paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
}
}

View File

@ -1,7 +1,8 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
public class ASPRefType implements ASPType {
public static final String ASP_TYPE = "type";
private final ASPParameterList params;
private final String name;
@ -15,6 +16,6 @@ public class ASPRefType implements ASPType {
}
public String toString(){
return ASP_TYPE + "(" + name +"," + params.name + ")";
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
}
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
public class ASPStatement {
private final String stmt;

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.sat.asp.writer.model;
public interface ASPType {
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.sat.asp.model;
package de.dhbwstuttgart.sat.asp.writer.model;
public class ASPTypeVar implements ASPType{
private final String name;

View File

@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.type.*;
import javax.management.Notification;
import java.lang.reflect.Modifier;
import java.util.Iterator;
@ -61,7 +62,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
}
private void visitMethod(Method method){
method.getType().accept(this);
method.getReturnType().accept(this);
method.getParameterList().accept(this);
if(method.block != null)
method.block.accept(this);
@ -157,12 +158,13 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override
public void visit(ForStmt forStmt) {
forStmt.body_Loop_block.accept(this);
}
@Override
public void visit(IfStmt ifStmt) {
ifStmt.then_block.accept(this);
ifStmt.else_block.accept(this);
}
@Override
@ -202,6 +204,11 @@ public abstract class AbstractASTWalker implements ASTVisitor{
receiver.expr.accept(this);
}
@Override
public void visit(UnaryExpr unaryExpr) {
unaryExpr.expr.accept(this);
}
@Override
public void visit(Return aReturn) {
aReturn.retexpr.accept(this);
@ -227,19 +234,14 @@ public abstract class AbstractASTWalker implements ASTVisitor{
}
@Override
public void visit(UnaryPlus unaryPlus) {
}
@Override
public void visit(WhileStmt whileStmt) {
whileStmt.loopBlock.accept(this);
}
@Override
public void visit(DoStmt whileStmt) {
whileStmt.loopBlock.accept(this);
}
@Override

View File

@ -14,9 +14,9 @@ public class Constructor extends Method {
//TODO: Constructor braucht ein super-Statement
public Constructor(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, int modifiers, ParameterList parameterList, Block codeInsideConstructor,
public Constructor(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block codeInsideConstructor,
GenericDeclarationList gtvDeclarations, Token offset, List<Statement> fieldInitializations) {
super(modifier, name, returnType, modifiers, parameterList, prepareBlock(codeInsideConstructor,fieldInitializations), gtvDeclarations, offset);
super(modifier, name, returnType, parameterList, prepareBlock(codeInsideConstructor,fieldInitializations), gtvDeclarations, offset);
}

View File

@ -6,7 +6,8 @@ import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
public class Field extends SyntaxTreeNode implements TypeScope{
public final int modifier;
private String name;
private RefTypeOrTPHOrWildcardOrGeneric type;
@ -14,6 +15,7 @@ public class Field extends SyntaxTreeNode implements TypeScope{
super(offset);
this.name = name;
this.type = type;
this.modifier = modifier;
}
public String getName(){

View File

@ -22,16 +22,22 @@ import de.dhbwstuttgart.syntaxtree.statement.Block;
* @author janulrich
*
*/
public class Method extends Field implements IItemWithOffset
public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
{
public final Block block;
public final int modifier;
public final String name;
private ParameterList parameterlist = new ParameterList(new ArrayList<>(), new NullToken());
private ExceptionList exceptionlist;
private GenericDeclarationList generics;
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, int modifiers, ParameterList parameterList, Block block,
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
GenericDeclarationList gtvDeclarations, Token offset) {
super(name, returnType, modifiers, offset);
super(offset);
this.name = name;
this.modifier = modifier;
this.returnType = returnType;
this.parameterlist = parameterList;
this.block = block;
this.generics = gtvDeclarations;
@ -47,11 +53,20 @@ public class Method extends Field implements IItemWithOffset
@Override
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return this.getType();
return this.returnType;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public Token getOffset() {
return null;
}
public String getName() {
return name;
}
}

View File

@ -50,8 +50,6 @@ public interface StatementVisitor {
void visit(This aThis);
void visit(UnaryPlus unaryPlus);
void visit(WhileStmt whileStmt);
void visit(DoStmt whileStmt);
@ -67,4 +65,6 @@ public interface StatementVisitor {
void visit(SuperCall superCall);
void visit(ExpressionReceiver expressionReceiver);
void visit(UnaryExpr unaryExpr);
}

View File

@ -48,7 +48,7 @@ public class ASTFactory {
if(superjreClass != null){
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for(TypeVariable tv : superjreClass.getTypeParameters()){
params.add(new RefType(new GenericTypeName(new GenericContext( name, null),tv.getName()), new NullToken()));
params.add(new GenericRefType(new GenericTypeName(new GenericContext( name, null),tv.getName()), new NullToken()));
}
superClass = new RefType(new JavaClassName(superjreClass.getName()), params, new NullToken());
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
@ -88,7 +88,7 @@ public class ASTFactory {
return null;
}
return new de.dhbwstuttgart.syntaxtree.Constructor(constructor.getModifiers(), name,returnType, modifier, parameterList, block, gtvDeclarations, offset, new ArrayList<>());
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset, new ArrayList<>());
}
//private static RefType createType(Class classType) {
@ -109,9 +109,8 @@ public class ASTFactory {
Block block = new Block(new ArrayList<Statement>(), new NullToken());
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
Token offset = new NullToken();
int modifier = jreMethod.getModifiers();
return new Method(jreMethod.getModifiers(), name,returnType, modifier, parameterList, block, gtvDeclarations, offset);
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset);
}
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
@ -134,7 +133,7 @@ public class ASTFactory {
}
*/
public static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){
if(type.getTypeName().equals("void")){
return new Void(new NullToken());
}else if(type.getTypeName().equals("int")){

View File

@ -6,6 +6,7 @@ import java.util.stream.Collectors;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
@ -25,7 +26,6 @@ public class UnifyTypeFactory {
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses) throws ClassNotFoundException {
/*
TODO: Generics werden zu TPHs
Die transitive Hülle muss funktionieren.
Man darf schreiben List<A> extends AL<A>
und Vector<B> extends List<B>
@ -35,57 +35,7 @@ public class UnifyTypeFactory {
Generell dürfen sie immer die gleichen Namen haben.
TODO: die transitive Hülle bilden
*/
HashSet<UnifyPair> pairs = new HashSet<>();
for(ClassOrInterface cly : fromClasses){
pairs.addAll(getSuperTypes(cly, fromClasses));
}
return new FiniteClosure(pairs);
}
/**
* Bildet eine Kette vom übergebenen Typ bis hin zum höchsten bekannten Typ
* Als Generics werden TPHs benutzt, welche der Unifikationsalgorithmus korrekt interpretieren muss.
* Die verwendeten TPHs werden in der Kette nach oben gereicht, so erhält der selbe GTV immer den selben TPH
* @param forType
* @return
*/
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, List<ClassOrInterface> availableClasses) throws ClassNotFoundException {
return getSuperTypes(forType, availableClasses, new HashMap<>());
}
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, List<ClassOrInterface> availableClasses, HashMap<String, PlaceholderType> gtvs) throws ClassNotFoundException {
List<UnifyType> params = new ArrayList<>();
//Generics mit gleichem Namen müssen den selben TPH bekommen
for(GenericTypeVar gtv : forType.getGenerics()){
if(!gtvs.containsKey(gtv.getParsedName()))
gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
params.add(gtvs.get(gtv.getParsedName()));
}
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny();
ClassOrInterface superClass;
if(!hasSuperclass.isPresent()) //TODO: Wenn es die Object-Klasse ist, dann ist es in Ordnung, ansonsten Fehler ausgeben:
{
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString()));
}else{
superClass = hasSuperclass.get();
}
List<UnifyPair> superTypes;
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
superTypes = Arrays.asList(generateSmallerPair(convert(ASTFactory.createObjectType()), convert(ASTFactory.createObjectType())));
}else{
superTypes = getSuperTypes(superClass, availableClasses, gtvs);
}
TypeParams paramList = new TypeParams(params);
UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList);
UnifyType t2 = superTypes.get(0).getLhsType();
UnifyPair ret = generateSmallerPair(t1, t2);
List<UnifyPair> retList = new ArrayList<>();
retList.add(ret);
retList.addAll(superTypes);
return retList;
return new FiniteClosure(FCGenerator.toFC(fromClasses));
}
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){

View File

@ -11,11 +11,11 @@ import org.antlr.v4.runtime.Token;
public class IfStmt extends Statement
{
public final Expression expr;
public final Block then_block;
public final Block else_block;
public final Statement then_block;
public final Statement else_block;
public IfStmt(RefTypeOrTPHOrWildcardOrGeneric type,
Expression expr, Block thenBlock, Block elseBlock, Token offset)
Expression expr, Statement thenBlock, Statement elseBlock, Token offset)
{
super(type,offset);
this.expr = expr;

View File

@ -0,0 +1,12 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
import java.nio.charset.StandardCharsets;
public abstract class JavaInternalExpression extends Statement{
public JavaInternalExpression(RefTypeOrTPHOrWildcardOrGeneric retType, Token offset){
super(retType, offset);
}
}

View File

@ -1,18 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.antlr.v4.runtime.Token;
public class NegativeExpr extends UnaryExpr
{
public NegativeExpr(Token offset)
{
super(offset);
}
private UnaryMinus neg;
public Expression expr;
}

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import org.antlr.v4.runtime.Token;
public class NotExpr extends UnaryExpr
{
public NotExpr(Token offset)
{
super(offset);
}
private UnaryNot not;
public Expression expr;
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import org.antlr.v4.runtime.Token;
public class PositivExpr extends UnaryExpr
{
public PositivExpr(Token offset)
{
super(offset);
}
protected UnaryPlus plus;
public Expression expr;
}

View File

@ -1,17 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
public class PostDecExpr extends PostIncExpr
{
public PostDecExpr(Expression expr) {
super(expr);
}
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.exceptions.NotImplementedException;
public class PostIncExpr extends UnaryExpr
{
public PostIncExpr(Expression expr) {
super(null);
}
}

View File

@ -1,17 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.antlr.v4.runtime.Token;
public class PreDecExpr extends UnaryExpr
{
public PreDecExpr(Token offset)
{
super(offset);
}
}

View File

@ -1,12 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import org.antlr.v4.runtime.Token;
public class PreIncExpr extends UnaryExpr
{
public PreIncExpr(Token offset)
{
super(offset);
}
}

View File

@ -1,14 +1,37 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
public abstract class UnaryExpr extends MethodCall
public class UnaryExpr extends JavaInternalExpression
{
public enum Operation{
NOT,
MINUS,
PREINCREMENT,
PREDECREMENT,
POSTINCREMENT,
PLUS, POSTDECREMENT
}
public final Operation operation;
public Expression expr;
public UnaryExpr(Token offset)
public UnaryExpr(Operation operation, Expression argument, RefTypeOrTPHOrWildcardOrGeneric retType, Token offset)
{
super(null,null,null,null,null);
super(retType, offset);
this.expr = argument;
this.operation = operation;
}
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,12 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
public class UnaryMinus extends UnaryPlus
{
public UnaryMinus(Expression expression) {
super(expression);
}
}

View File

@ -1,7 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
public class UnaryNot
{
}

View File

@ -1,20 +0,0 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.exceptions.NotImplementedException;
public class UnaryPlus extends Expression
{
public UnaryPlus(Expression expression){
super(expression.getType(),expression.getOffset());
}
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -81,7 +81,7 @@ public class OutputGenerator implements ASTVisitor{
@Override
public void visit(Method method) {
method.getType().accept(this);
method.getReturnType().accept(this);
out.append(" " + method.getName());
method.getParameterList().accept(this);
if(method.block != null)
@ -296,11 +296,6 @@ public class OutputGenerator implements ASTVisitor{
out.append("this");
}
@Override
public void visit(UnaryPlus unaryPlus) {
}
@Override
public void visit(WhileStmt whileStmt) {
out.append("while(");
@ -349,4 +344,27 @@ public class OutputGenerator implements ASTVisitor{
public void visit(ExpressionReceiver receiver) {
receiver.expr.accept(this);
}
@Override
public void visit(UnaryExpr unaryExpr) {
if(unaryExpr.operation == UnaryExpr.Operation.MINUS){
out.append("-");
}
if(unaryExpr.operation == UnaryExpr.Operation.PLUS){
out.append("+");
}
if(unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT){
out.append("--");
}
if(unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
out.append("++");
}
unaryExpr.expr.accept(this);
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT){
out.append("--");
}
if(unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT){
out.append("++");
}
}
}

View File

@ -214,11 +214,6 @@ public class TypeOutputGenerator extends OutputGenerator {
aThis.getType().accept(this);
}
@Override
public void visit(UnaryPlus unaryPlus) {
super.visit(unaryPlus);
}
@Override
public void visit(WhileStmt whileStmt) {
super.visit(whileStmt);

View File

@ -1,6 +1,8 @@
package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultSet;

View File

@ -2,12 +2,14 @@ package de.dhbwstuttgart.typeinference.typeAlgo;
//import com.sun.org.apache.xpath.internal.Arg;
import com.sun.org.apache.xpath.internal.operations.Bool;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
@ -193,6 +195,23 @@ public class TYPEStmt implements StatementVisitor{
receiver.expr.accept(this);
}
@Override
public void visit(UnaryExpr unaryExpr) {
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT ||
unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT ||
unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT ||
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset());
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT));
//The type of the postfix increment expression is the type of the variable
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
}else{
throw new NotImplementedException();
}
}
@Override
public void visit(Return returnExpr) {
returnExpr.retexpr.accept(this);
@ -241,14 +260,11 @@ public class TYPEStmt implements StatementVisitor{
};
}
@Override
public void visit(UnaryPlus unaryPlus) {
throw new NotImplementedException();
}
@Override
public void visit(WhileStmt whileStmt) {
throw new NotImplementedException();
RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken());
constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT));
whileStmt.loopBlock.accept(this);
}
@Override
@ -345,7 +361,7 @@ public class TYPEStmt implements StatementVisitor{
for(Method m : cl.getMethods()){
if(m.getName().equals(name) &&
m.getParameterList().getFormalparalist().size() == numArgs){
RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getType());
RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getReturnType());
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
createTypeScope(cl, m)));

View File

@ -305,7 +305,7 @@ public class RuleSet implements IRuleSet{
if(!rhsSType.getName().equals(lhsSType.getName()))
return Optional.empty();
if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung");
if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung"+ " " + lhsSType.toString() + " " + rhsSType.toString());
//if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
// return Optional.empty();

View File

@ -94,6 +94,6 @@ class Node<T> {
@Override
public String toString() {
return "Node(" + content.toString() + ")";
return "Node(" + content.toString() + ")\n";
}
}

View File

@ -96,4 +96,14 @@ public abstract class UnifyType {
ret.addAll(typeParams.getInvolvedPlaceholderTypes());
return ret;
}
@Override
public int hashCode() {
return this.toString().hashCode();
}
@Override
public boolean equals(Object obj) {
return this.toString().equals(obj.toString());
}
}

46
test/asp/ClingoTest.java Normal file
View File

@ -0,0 +1,46 @@
package asp;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
import de.dhbwstuttgart.sat.asp.Clingo;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class ClingoTest {
public static final String rootDirectory = "~/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards";
public static final String tempDirectory = "/tmp/";
@Test
public void test() throws IOException, InterruptedException {
String content = "";
content = new ASPGenerator(this.getPairs(), this.getFC()).getASP();
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
writer.println(content);
writer.close();
Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp")));
System.out.println(clingo.runClingo());
}
public Collection<ClassOrInterface> getFC() {
Set<ClassOrInterface> ret = new HashSet<>();
ret.add(ASTFactory.createObjectClass());
ret.add(ASTFactory.createClass(java.util.List.class));
return ret;
}
public ConstraintSet<Pair> getPairs() {
ConstraintSet<Pair> ret = new ConstraintSet<>();
ret.addUndConstraint(new Pair(TypePlaceholder.fresh(new NullToken()), ASTFactory.createObjectType(), PairOperator.SMALLERDOT));
return ret;
}
}

View File

@ -1,7 +1,7 @@
package asp.typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.sat.asp.ASPGenerator;
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;

View File

@ -0,0 +1,10 @@
package asp.unifywithoutwildcards;
import org.junit.Test;
public class ASPTests {
@Test
public void test(){
}
}

View File

@ -1,54 +1,26 @@
import java.util.Vector;
import java.lang.Integer;
import java.lang.Boolean;
class Matrix extends Vector<Vector<Integer>> {
methode(Matrix m) {
Vector<Vector<Integer>> i;
methode(i);
}
}
/*
import java.util.Vector;
class Matrix extends Vector<Vector<Integer>> {
Matrix mul_rec(Matrix m) {
auto v1 = new Vector<Integer>();
auto v2 = new Vector<Integer>();
auto i = 0;
while(i < m.size()) {
auto v;
v = m.elementAt(i);
v2.addElement(v.remove(v.size()-1));
i++;
}
Matrix ret;
if (m.elementAt(0).size() > 0) {
ret = this.mul_rec(m);
}
else {
ret = new Matrix();
i = 0;
while (i < this.size()) {
ret.addElement(new Vector<Integer>());
i++;
}
}
i = 0;
while (i < this.size()) {
int erg = 0;
auto j;
j = 0;
while (j < v2.size()) {
erg = erg + this.elementAt(i).elementAt(j).intValue()
* v2.elementAt(j).intValue();
j++;
}
ret.elementAt(i).addElement(erg);
i++;
}
return ret;
}
mul(m) {
var ret = new Matrix();
var i = 0;
while(i < size()) {
var v1 = this.elementAt(i);
var v2 = new Vector<Integer>();
var j = 0;
while(j < v1.size()) {
var erg = 0;
var k = 0;
while(k < v1.size()) {
erg = erg + v1.elementAt(k)
* m.elementAt(k).elementAt(j);
k++; }
v2.addElement(new Integer(erg));
j++; }
ret.addElement(v2);
i++; }
return ret;
}
}
*/

View File

@ -1,29 +1,16 @@
package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.ASPGenerator;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -32,7 +19,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class JavaTXCompilerTest {
@ -66,6 +52,7 @@ public class JavaTXCompilerTest {
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();

View File

@ -0,0 +1,9 @@
package typeinference;
import java.io.File;
public class MatrixTest extends JavaTXCompilerTest{
public MatrixTest() {
this.fileToTest = new File(rootDirectory+"Matrix.jav");
}
}