merge Keine Ahnung mit was ...

This commit is contained in:
JanUlrich 2018-05-28 16:21:43 +02:00
commit 07fa62d11d
270 changed files with 9403 additions and 2138 deletions

3
.gitignore vendored
View File

@ -20,3 +20,6 @@ bin
.project
.settings/
/target/
#
manually/

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# plugin site erstellen
* die JAvaTXCOmpiler DAtei in ein plugin umwandeln und deployen.
* siehe: http://www.vogella.com/tutorials/EclipseJarToPlugin/article.html#convert-jar-files-to-osgi-bundles-with-the-p2-maven-plugin
* AUsführung:
* mvn deploy #erstellt die JAR-Datei und steckt sie in ein lokales Repo (maven-repository)
* mvn p2:site
* mvn package # hier wird die ZIP-Filf zum Einbinden in Eclipse erstellt
# Einbinden in Eclipse
* In Eclipse kann die Zip-FIle wie ein Plugin installiert werden
* Hier tritt FEhler auf. Reflections-Library kann nicht installiert werden. Möglicherweise wird sie auch nicht gebraucht
* Nach dem installieren de.dhbwstuttagrt.JavaTXcompiler zu den DEpendencies des plugins hinzufügen
* Anschließend unter "Overview" auf "Updata Classpath" klicken
# Windows
* JAVA_HOME setzen:
* export JAVA_HOME=/c/Program\ Files/Java/jdk1.8.0_102/

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.BoolLiteral</li>
@ -253,7 +253,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.CharLiteral</li>
@ -253,7 +253,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.DoubleLiteral</li>
@ -263,7 +263,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.FloatLiteral</li>
@ -263,7 +263,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.NumberLiteral</li>
@ -263,7 +263,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.Literal</li>
<li>de.dhbwstuttgart.syntaxtree.statement.Literal</li>
</ul>
</li>
</ul>

View File

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.LongLiteral</li>
@ -263,7 +263,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

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

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.Null</li>
@ -245,7 +245,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

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

@ -112,7 +112,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Expr.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Expr</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.literal.Literal</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">de.dhbwstuttgart.syntaxtree.statement.Literal</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.statement.literal.StringLiteral</li>
@ -253,7 +253,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html"
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.literal.Literal">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.statement.Literal">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.statement.<a href="../../../../de/dhbwstuttgart/syntaxtree/statement/Literal.html" title="class in de.dhbwstuttgart.syntaxtree.statement">Literal</a></h3>

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.literal.Literal</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.statement.Literal</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,7 +70,7 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.literal.Literal" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.Literal</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.statement.Literal" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.statement.Literal</h2>
</div>
<div class="classUseContainer">
<ul class="blockList">

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">
<!-- -->

83
pom.xml
View File

@ -7,6 +7,7 @@
<groupId>de.dhbwstuttgart</groupId>
<artifactId>JavaTXcompiler</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>JavaTXcompiler</name>
<url>http://maven.apache.org</url>
@ -22,6 +23,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>
@ -37,6 +43,12 @@
<artifactId>asm-all</artifactId>
<version>[4.0.0,)</version>
</dependency>
<!--
<dependency>
<groupId>org.bitbucket.mstrobel</groupId>
<artifactId>procyon-reflection</artifactId>
<version>[0.5.32,)</version>
</dependency> -->
</dependencies>
<build>
@ -60,14 +72,42 @@
<configuration>
<sourceDirectory>src/de/dhbwstuttgart/parser/antlr/</sourceDirectory>
<outputDirectory>src/de/dhbwstuttgart/parser/antlr/</outputDirectory>
<arguments> <argument>-package</argument> <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.parser.antlr</argument>
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
@ -78,15 +118,40 @@
<configuration>
<artifacts>
<!-- specify your depencies here -->
<!-- groupId:artifactId:version -->
<!-- groupId:artifactId:version -->
<artifact>
<id>de.dhbwstuttgart:JavaTXcompiler:0.1</id>
</artifact>
<artifact><id>org.reflections:reflections:0.9.11</id></artifact>
<artifact><id>com.google.guava:guava:22.0</id></artifact>
<artifact><id>javax.annotation:javax.annotation-api:1.3.1</id></artifact>
<artifact><id>org.glassfish:javax.annotation:3.1.1</id></artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>archive-repository</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
@ -96,13 +161,21 @@
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<repository>
<id>maven-repository</id>
<url>file:///${project.basedir}/maven-repository</url>
</repository>
<url>file:///${project.basedir}/target</url>
</repository>
</repositories>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<tycho.version>0.23.0</tycho.version>
</properties>
<distributionManagement>
<repository>
<id>maven-repository</id>
<name>MyCo Internal Repository</name>
<url>file:///${project.basedir}/maven-repository/</url>
</repository>
</distributionManagement>
</project>

View File

@ -0,0 +1,30 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public abstract class AStatement implements IStatement {
protected Expression expr;
public AStatement(Expression expr) {
this.expr = expr;
}
@Override
public boolean isExprBinary() {
return (expr instanceof BinaryExpr);
}
@Override
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
mv.visitInsn(Opcodes.ICONST_1);
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
mv.visitLabel(branchLabel);
mv.visitInsn(Opcodes.ICONST_0);
mv.visitLabel(endLabel);
}
}

View File

@ -0,0 +1,11 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public class ArgumentExpr extends AStatement {
public ArgumentExpr(Expression expr) {
super(expr);
}
}

View File

@ -0,0 +1,11 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public class AssignStmt extends AStatement {
public AssignStmt(Expression rightSide) {
super(rightSide);
}
}

View File

@ -1,58 +1,82 @@
package de.dhbwstuttgart.bytecode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
import de.dhbwstuttgart.bytecode.signature.Signature;
import de.dhbwstuttgart.bytecode.signature.TypeToString;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class BytecodeGen implements ASTVisitor {
ClassWriter cw =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
// String methDesc;
String type;
String className;
private boolean isInterface;
private List<ResultSet> listOfResultSets;
private ResultSet resultSet;
private int indexOfFirstParam = 0;
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
// stores generics and their bounds of class
HashMap<String, String> genericsAndBounds = new HashMap<>();
// stores generics and their bounds of method
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
byte[] bytecode;
HashMap<String,byte[]> classFiles;
public BytecodeGen(HashMap<String,byte[]> classFiles, ResultSet resultSet) {
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets) {
this.classFiles = classFiles;
this.resultSet = resultSet;
this.listOfResultSets = listOfResultSets;
}
@Override
public void visit(SourceFile sourceFile) {
for(ClassOrInterface cl : sourceFile.getClasses()) {
isInterface = (cl.getModifiers()&512)==512;
System.out.println("IS Interface = "+"modifiers= "+cl.getModifiers()+" ->"+(cl.getModifiers()&512) + isInterface);
BytecodeGen classGen = new BytecodeGen(classFiles, resultSet);
System.out.println("in Class: " + cl.getClassName().toString());
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
cl.accept(classGen);
classGen.writeClass(cl.getClassName().toString());
}
}
/**
* Associates the bytecode of the class that was build with the classWriter {@link #cw}
* with the class name in the map {@link #classFiles}
*
* @param name name of the class with which the the bytecode is to be associated
*/
private void writeClass(String name) {
bytecode = cw.toByteArray();
classFiles.put(name, bytecode);
@ -62,54 +86,150 @@ public class BytecodeGen implements ASTVisitor {
public HashMap<String,byte[]> getClassFiles() {
return classFiles;
}
@Override
public void visit(ClassOrInterface classOrInterface) {
className = classOrInterface.getClassName().toString();
// access flages??
cw.visit(Opcodes.V1_8, classOrInterface.getModifiers()+Opcodes.ACC_SUPER, classOrInterface.getClassName().toString()
, null, classOrInterface.getSuperClass().toString().replace(".", "/"), null);
// for each field in the class
cw.visitSource(className +".jav", null);
isInterface = (classOrInterface.getModifiers()&512)==512;
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
String sig = null;
/* if class has generics then creates signature
* Signature looks like:
* <E:Ljava/...>Superclass
*/
if(classOrInterface.getGenerics().iterator().hasNext()) {
Signature signature = new Signature(classOrInterface, genericsAndBounds);
sig = signature.toString();
}
// needs implemented Interfaces?
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
for(Field f : classOrInterface.getFieldDecl()) {
System.out.println("get Fields");
System.out.println(f.getName());
f.accept(this);
}
// resultSet = listOfResultSets.get(0);
boolean isConsWithNoParamsVisited = false;
for(ResultSet rs : listOfResultSets) {
resultSet = rs;
for(Constructor c : classOrInterface.getConstructors()) {
if(!isConsWithNoParamsVisited)
c.accept(this);
if(!c.getParameterList().iterator().hasNext())
isConsWithNoParamsVisited = true;
}
for(Method m : classOrInterface.getMethods()) {
m.accept(this);
}
for(Constructor c : classOrInterface.getConstructors()) {
c.accept(this);
}
for(Method m : classOrInterface.getMethods()) {
m.accept(this);
}
cw.visitSource(classOrInterface.getClassName().toString()+".jav", null);
}
@Override
public void visit(Constructor field) {
Descriptor desc = new Descriptor(field, resultSet);
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc.getDesc(), null, null);
field.getParameterList().accept(this);
String desc = null;
boolean hasGen = false;
for(String paramName : methodParamsAndTypes.keySet()) {
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
if(genericsAndBounds.containsKey(typeOfParam)) {
hasGen = true;
break;
}
}
String sig = null;
if(hasGen) {
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes);
sig = signature.toString();
}
NormalConstructor constructor = new NormalConstructor(field,genericsAndBounds,hasGen);
desc = constructor.accept(new DescriptorToString(resultSet));
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
mv.visitCode();
System.out.println("-----Constructor-----");
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,desc.getDesc(),cw,isInterface);
mv.visitInsn(Opcodes.RETURN);
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,cw,
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
if(!field.getParameterList().iterator().hasNext()) {
mv.visitInsn(Opcodes.RETURN);
}
mv.visitMaxs(0, 0);
mv.visitEnd();
}
@Override
public void visit(Method method) {
// TODO: check if the method is static => if static then the first param will be stored in pos 0
// else it will be stored in pos 1 and this will be stored in pos 0
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
String methParamTypes = retType+method.name+"%%";
method.getParameterList().accept(this);
Descriptor methDesc = new Descriptor(method,resultSet);
System.out.println("-----Method-----");
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methDesc.getDesc(), null, null);
mv.visitCode();
Iterator<FormalParameter> itr = method.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
}
if(methodNameAndParamsT.contains(methParamTypes)) {
return;
}
methodNameAndParamsT.add(methParamTypes);
System.out.println("Method: "+method.name +" , paramsType: "+methParamTypes);
String methDesc = null;
// Method getModifiers() ?
int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier;
System.out.println(acc);
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ");
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
if(!hasGenInParameterList) {
for(String paramName : methodParamsAndTypes.keySet()) {
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")) {
hasGenInParameterList = true;
break;
}
}
}
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
//then create the descriptor with the new syntax.
String sig = null;
/* method.getGenerics: <....> RT method(..)
* */
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
/* if method has generics or return type is TPH, create signature */
// zwite operand muss weggelassen werden
if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
// resultset hier zum testen
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
sig = signature.toString();
}
// System.out.println(sig);
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
methDesc = meth.accept(new DescriptorToString(resultSet));
// System.out.println(methDesc);
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
mv.visitCode();
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,cw,
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,methDesc.getDesc(),cw,isInterface);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
@ -117,11 +237,13 @@ public class BytecodeGen implements ASTVisitor {
@Override
public void visit(ParameterList formalParameters) {
paramsAndLocals = new HashMap<>();
methodParamsAndTypes = new HashMap<>();
Iterator<FormalParameter> itr = formalParameters.iterator();
int i = 1;
while(itr.hasNext()) {
FormalParameter fp = itr.next();
paramsAndLocals.put(fp.getName(), i);
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
fp.accept(this);
i++;
}
@ -164,7 +286,6 @@ public class BytecodeGen implements ASTVisitor {
// ??
@Override
public void visit(FieldVar fieldVar) {
System.out.println("in fieldvar");
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L"+fieldVar.getType()+";", null, null);
fv.visitEnd();
@ -173,7 +294,6 @@ public class BytecodeGen implements ASTVisitor {
// access flages?? modifiers
@Override
public void visit(Field field) {
System.out.println("in field");
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, field.getName(), "L"+field.getType().toString().replace(".", "/")+";", null, null);
fv.visitEnd();
}
@ -191,9 +311,8 @@ public class BytecodeGen implements ASTVisitor {
}
@Override
public void visit(Binary binary) {
// TODO Auto-generated method stub
public void visit(BinaryExpr binary) {
}
@Override
@ -292,12 +411,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
@ -310,11 +423,6 @@ public class BytecodeGen implements ASTVisitor {
}
@Override
public void visit(Null aNull) {
// TODO Auto-generated method stub
}
// ???
@Override
public void visit(Literal literal) {
@ -363,4 +471,9 @@ public class BytecodeGen implements ASTVisitor {
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.bytecode;
public class ClassFile {
String name;
byte[] bytecode;
public ClassFile(String name, byte[] bytecode) {
this.name = name;
this.bytecode = bytecode;
}
}

View File

@ -1,112 +0,0 @@
package de.dhbwstuttgart.bytecode;
import java.util.List;
import java.util.Iterator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class Descriptor {
String desc;
public Descriptor(Method method, ResultSet resultSet) {
desc = "(";
Iterator<FormalParameter> itr = method.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
desc = addReturnType(desc,method.getReturnType(), resultSet);
}
private class TypeToDescriptor implements TypeVisitor<String>{
@Override
public String visit(RefType refType) {
return refType.getName().toString().replace(".", "/");
}
@Override
public String visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(TypePlaceholder typePlaceholder) {
return typePlaceholder.toString();
}
@Override
public String visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(GenericRefType genericRefType) {
return genericRefType.getParsedName();
}
}
private String addReturnType(String desc2, RefTypeOrTPHOrWildcardOrGeneric returnType, ResultSet resultSet) {
System.out.println("DescType = "+returnType.toString());
if(resultSet.resolveType(returnType).resolvedType.toString().equals("void")){
desc = desc + ")V";
}else {
desc = desc + ")" + "L"+resultSet.resolveType(returnType).resolvedType.toString().replace(".", "/")+";";
}
return desc;
}
public Descriptor(Constructor constructor, ResultSet resultSet) {
desc = "(";
Iterator<FormalParameter> itr = constructor.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "/") + ";";
}
desc = desc + ")V";
}
public Descriptor(LambdaExpression lambdaExpr, ResultSet resultSet) {
desc = "(";
Iterator<FormalParameter> itr = lambdaExpr.params.iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "/") + ";";
}
desc = addReturnType(desc, lambdaExpr.getReturnType(), resultSet);
}
public Descriptor(ArgumentList argList, RefTypeOrTPHOrWildcardOrGeneric returnType, ResultSet resultSet) {
desc = "(";
for(Expression e : argList.getArguments()) {
desc = desc + "L"+resultSet.resolveType(e.getType()).resolvedType.toString().replace(".", "/") + ";";
}
desc = addReturnType(desc, returnType, resultSet);
}
public Descriptor(List<RefTypeOrTPHOrWildcardOrGeneric> argumentList,RefTypeOrTPHOrWildcardOrGeneric returnType ,ResultSet resultSet) {
desc = "(";
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = argumentList.iterator();
while(itr.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
desc = desc + "L"+resultSet.resolveType(rt).resolvedType.toString().replace(".", "/")+";";
}
desc = desc + ")"+"L"+resultSet.resolveType(returnType).resolvedType.toString().replace(".", "/")+";";
}
public String getDesc() {
return this.desc;
}
}

View File

@ -0,0 +1,9 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
public interface IStatement {
public boolean isExprBinary();
public void genBCForRelOp(MethodVisitor mv, Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod);
}

View File

@ -0,0 +1,25 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
public class LoopStmt extends AStatement {
private Statement loopBlock;
public LoopStmt(Expression expr, Statement loopBlock) {
super(expr);
this.loopBlock = loopBlock;
}
@Override
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
this.loopBlock.accept(bytecodeGenMethod);
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
mv.visitLabel(branchLabel);
}
}

View File

@ -0,0 +1,14 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.MethodVisitor;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
public class ReturnStmt extends AStatement {
public ReturnStmt(Expression retexpr) {
super(retexpr);
}
}

View File

@ -1,150 +0,0 @@
package de.dhbwstuttgart.bytecode;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.invoke.CallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
public class Test {
private static final String rootDirectory = System.getProperty("user.dir") + "/bin/de/dhbwstuttgart/bytecode/";
protected static ClassLoader getClassLoader() throws Exception {
File file = new File(rootDirectory);
URL url = file.toURI().toURL();
URL[] urls = new URL[] { url };
System.out.println(urls[0]);
return new URLClassLoader(urls);
}
public static void main(String[] args) {
// Test Lambda
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "TestClass", null, "java/lang/Object", null);
cw.visitSource("TestClass.java", null);
// Create Constructor
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
// mv.visitMethodInsn(INVOKEDYNAMIC, "#0", "run", "()Ljava/lang/Runnable");
//Call site, which, when invoked, returns an instance of the functional interface to which
//the lambda is being converted
MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
mt.toMethodDescriptorString());
Handle arg2 = new Handle(Opcodes.H_INVOKESTATIC, "TestClass", "lambda$0", "()V");
mv.visitInvokeDynamicInsn("run", "()Ljava/lang/Runnable;", bootstrap,
Type.getMethodType("()V"), arg2,
Type.getMethodType("()V"));
mv.visitVarInsn(Opcodes.ASTORE, 1);
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Runnable", "run", "()V");
mv.visitInsn(Opcodes.RETURN);
// creates bridge method, contains lambdas body
MethodVisitor mvl = cw.visitMethod(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC, "lambda$0",
"()V", null, null);
mvl.visitCode();
mvl.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mvl.visitLdcInsn("lambda");
mvl.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
mvl.visitInsn(Opcodes.RETURN);
mvl.visitMaxs(2, 0);
mvl.visitEnd();
mv.visitMaxs(1, 2);
mv.visitEnd();
cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL);
cw.visitEnd();
byte[] b = cw.toByteArray();
// Test if statement
/*
* ClassWriter cw = new
* ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
*
* cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_SUPER, "TestIf", null,
* "java/lang/Object", null); MethodVisitor mv =
* cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/lang/Boolean;)V", null,
* null); mv.visitCode();
*
* // Label l0 = new Label(); // mv.visitLabel(l0);
*
* mv.visitVarInsn(Opcodes.ALOAD, 0);
*
* mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>",
* "()V");
*
* // Label l1 = new Label(); // mv.visitLabel(l1);
* mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
* "java/lang/Boolean", "booleanValue", "()Z");
*
* Label label = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, label);
*
* mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out",
* "Ljava/io/PrintStream;"); mv.visitLdcInsn("1");
* mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println",
* "(Ljava/lang/String;)V");
*
* Label endLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, endLabel);
*
* mv.visitLabel(label); mv.visitFieldInsn(Opcodes.GETSTATIC,
* "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("0");
* mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println",
* "(Ljava/lang/String;)V");
*
*
*
* mv.visitLabel(endLabel); mv.visitInsn(Opcodes.RETURN);
*
* // Label l2 = new Label(); // mv.visitLabel(l2);
*
* // mv.visitLocalVariable("this", "LTestIf;", null, l0, l2, 0); //
* mv.visitLocalVariable("b", "Ljava/lang/Boolean;", null, l0, l2, 1);
* mv.visitMaxs(2, 2); mv.visitEnd();
*
* cw.visitEnd(); byte[] b = cw.toByteArray();
*/
FileOutputStream output;
try {
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/TestClass.class"));
output.write(b);
output.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -1,8 +0,0 @@
package de.dhbwstuttgart.bytecode;
public class TestClass {
public TestClass() {
Runnable lam = () -> System.out.println("lambda");
lam.run();
}
}

View File

@ -1,59 +0,0 @@
package de.dhbwstuttgart.bytecode;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
public class TestFields {
private static final String rootDirectory = System.getProperty("user.dir") + "/bin/de/dhbwstuttgart/bytecode/";
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "TetsF", null, "java/lang/Object", null);
cw.visitSource("TetsF.java", null);
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, "z", Type.INT_TYPE.getDescriptor(), null, null);
fv.visitEnd();
FieldVisitor fvS = cw.visitField(Opcodes.ACC_PUBLIC, "s", "Ljava/lang/String;", null, null);
fvS.visitEnd();
// Create Constructor
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitLdcInsn("");
mv.visitFieldInsn(Opcodes.PUTFIELD, "TetsF", "s", "Ljava/lang/String;");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
byte[] b = cw.toByteArray();
FileOutputStream output;
try {
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/TetsF.class"));
output.write(b);
output.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.bytecode;
public class TestIf {
public TestIf(Boolean b) {
if(b) {
System.out.println("1");
}else {
System.out.println("0");
}
}
}

View File

@ -1,18 +0,0 @@
package de.dhbwstuttgart.bytecode;
public class TestMeth {
private int z;
public String s;
public TestMeth(int temp) {
this.z = temp;
}
public void m1(int a, int b) {
int y = m2(1,2,3,4);
}
public int m2(int a, int b, int x, int y) {
Integer c = 55;
Integer g;
return a+b+y+c;
}
}

View File

@ -1,6 +0,0 @@
package de.dhbwstuttgart.bytecode;
public class TetsF {
private int z;
public String s = "";
}

View File

@ -0,0 +1,170 @@
package de.dhbwstuttgart.bytecode.descriptor;
import java.util.Iterator;
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
import de.dhbwstuttgart.bytecode.utilities.Lambda;
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class DescriptorToString implements DescriptorVisitor{
ResultSet resultSet;
public DescriptorToString(ResultSet resultSet) {
this.resultSet = resultSet;
}
private String addReturnType(String desc, RefTypeOrTPHOrWildcardOrGeneric returnType, ResultSet resultSet) {
if(resultSet.resolveType(returnType).resolvedType.toString().equals("void")){
desc = desc + ")V";
}else {
desc = desc + ")" + "L"+resultSet.resolveType(returnType).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
return desc;
}
@Override
public String visit(NormalMethod method) {
String desc = "(";
Iterator<FormalParameter> itr = method.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
// System.out.println(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature()));
// System.out.println("Parmetrisierte typ ? "+ ((RefType) fp.getType()).getParaList().size());
if(method.hasGen()) {
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
desc += "L"+method.getGenericsAndBoundsMethod().get(fpDesc)+ ";";
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";";
}else {
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.subSequence(0, 4).equals("TPH ")) {
desc += "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
} else {
desc += "L"+resType+ ";";
}
}
}
//TODO: generate a class java%% ... %%
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
}
else {
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
if(resultSet.resolveType(method.getReturnType()).resolvedType.toString().equals("void")) {
desc += ")V";
}else {
if(method.hasGen()) {
String ret = method.getReturnType().acceptTV(new TypeToDescriptor());
if(method.getGenericsAndBoundsMethod().containsKey(ret)) {
desc += ")L"+method.getGenericsAndBoundsMethod().get(ret)+ ";";
}else if(method.getGenericsAndBounds().containsKey(ret)){
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
}else {
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.subSequence(0, 4).equals("TPH ")) {
desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
} else {
desc += ")" + "L"+resType+ ";";
}
}
}else {
desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
// desc = addReturnType(desc,method.getReturnType(), resultSet);
return desc;
}
@Override
public String visit(NormalConstructor constructor) {
String desc = "(";
Iterator<FormalParameter> itr = constructor.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
if(constructor.hasGen()) {
// System.out.println("Cons has Gens");
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
// System.out.println(fpDesc);
if(constructor.getGenericsAndBounds().containsKey(fpDesc)){
desc += "L"+constructor.getGenericsAndBounds().get(fpDesc)+ ";";
}else {
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}else {
// System.out.println("Cons has NOT Gens");
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
desc = desc + ")V";
return desc;
}
@Override
public String visit(Lambda lambdaExpression) {
String desc = "(";
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";";
}
desc = addReturnType(desc, lambdaExpression.getReturnType(), resultSet);
return desc;
}
@Override
public String visit(SamMethod samMethod) {
String desc = "(";
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
while(itr.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
desc = desc + "L"+resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor())+";";
}
desc = desc + ")"+"L"+resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
return desc;
}
@Override
public String visit(MethodFromMethodCall methodFromMethodCall) {
String desc = "(";
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
String d = e.getType().acceptTV(new TypeToDescriptor());
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
}else {
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
if(resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.toString().equals("void")) {
desc += ")V";
}else {
String ret = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(ret)) {
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(ret)+ ";";
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(ret)){
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(ret)+ ";";
}else {
desc += ")" + "L"+resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
}
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
return desc;
}
}

View File

@ -0,0 +1,15 @@
package de.dhbwstuttgart.bytecode.descriptor;
import de.dhbwstuttgart.bytecode.utilities.Lambda;
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
public interface DescriptorVisitor {
public String visit(NormalMethod method);
public String visit(NormalConstructor constructor);
public String visit(Lambda lambdaExpression);
public String visit(SamMethod samMethod);
public String visit(MethodFromMethodCall methodFromMethodCall);
}

View File

@ -0,0 +1,40 @@
package de.dhbwstuttgart.bytecode.descriptor;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
public class TypeToDescriptor implements TypeVisitor<String>{
@Override
public String visit(RefType refType) {
return refType.getName().toString().replace(".", "/");
// String t = refType.getName().toString().replace(".", "/");
// return t.equals("Fun1")?(t+"$$"):t;
}
@Override
public String visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(TypePlaceholder typePlaceholder) {
return typePlaceholder.toString().replace(".", "/");
}
@Override
public String visit(ExtendsWildcardType extendsWildcardType) {
return extendsWildcardType.getInnerType().toString().replace(".", "/");
//throw new NotImplementedException();
}
@Override
public String visit(GenericRefType genericRefType) {
return genericRefType.getParsedName().replace(".", "/");
}
}

View File

@ -0,0 +1,225 @@
package de.dhbwstuttgart.bytecode.signature;
import java.util.HashMap;
import java.util.Iterator;
import org.objectweb.asm.Type;
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.signature.SignatureWriter;
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class Signature {
private ClassOrInterface classOrInterface;
private HashMap<String, String> genericsAndBounds;
private HashMap<String, String> genericsAndBoundsMethod;
private SignatureWriter sw;
private Constructor constructor;
private Method method;
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
private ResultSet resultSet;
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds) {
this.classOrInterface = classOrInterface;
this.genericsAndBounds = genericsAndBounds;
sw = new SignatureWriter();
createSignatureForClassOrInterface();
}
public Signature(Constructor constructor, HashMap<String, String> genericsAndBounds, HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes) {
this.constructor = constructor;
this.genericsAndBounds = genericsAndBounds;
this.methodParamsAndTypes = methodParamsAndTypes;
sw = new SignatureWriter();
createSignatureForConsOrMethod(this.constructor,true);
}
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet) {
this.method = method;
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
this.methodParamsAndTypes = methodParamsAndTypes;
this.resultSet = resultSet;
sw = new SignatureWriter();
createSignatureForConsOrMethod(this.method,false);
}
public Signature(LambdaExpression lambdaExpression,int numberOfParams) {
sw = new SignatureWriter();
createSignatureForFunN(lambdaExpression, numberOfParams);
}
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
// sw.visitClassBound().visitEnd();
for(int i = 0;i<numberOfParams;i++) {
int j = i+1;
sw.visitFormalTypeParameter("T"+ j);
// getBounds von Params
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
}
sw.visitFormalTypeParameter("R");
// getBounds vom Return-Type
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
// TODO: prüfe ob Return-Type = void,
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));;
sw.visitEnd();
}
/**
* Creates signature for a method or constructor with @see {@link SignatureWriter}
* Signature looks like:
* <typevaliables (K:Ljava/lang/Object "Bounds")>(params L.. OR T.. Or basistape)ReturnType
*
* @param method method or constructor
* @param isConstructor true if constructor
*/
private void createSignatureForConsOrMethod(Method method, boolean isConstructor) {
Iterator<? extends GenericTypeVar> itr = method.getGenerics().iterator();
// visits all formal type parameter and visits their bounds <T:...;B:...;...>
while(itr.hasNext()) {
GenericTypeVar g = itr.next();
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
}
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
if(ret.substring(0,4).equals("TPH ")) {
String g = ret.substring(4)+"$";
sw.visitFormalTypeParameter(g);
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
}
for(String paramName : methodParamsAndTypes.keySet()) {
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
String pT = t.acceptTV(new TypeToSignature());
// S.o
if(pT.substring(0,4).equals("TPH ") && !genericsAndBoundsMethod.containsKey(pT)) {
String gP = pT.substring(4)+"$";
sw.visitFormalTypeParameter(gP);
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
genericsAndBoundsMethod.put(gP, Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
}
}
// visit each method-parameter to create the signature
for(String paramName : methodParamsAndTypes.keySet()) {
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
// parameter type deswegen ist true
doVisitParamsOrReturn(t,true);
}
if(isConstructor) {
sw.visitReturnType().visitBaseType('V');
}else {
// String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
// if(ret.substring(0,4).equals("TPH ")) {
// String g = ret.substring(4);
// if(!genericsAndBoundsMethod.containsKey(g)) {
// genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
// } else {
// genericsAndBoundsMethod.put(g+"_", Type.getInternalName(Object.class));
// }
// }
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
// return type deswegen ist false
doVisitParamsOrReturn(returnType, false);
}
// sw.visitEnd();
}
/**
* Visits parameter type or return type with {@link SignatureVisitor} to create
* the method signature
* @param t type of parameter or return type
* @param isParameterType true if t is type of parameter
*/
private void doVisitParamsOrReturn(RefTypeOrTPHOrWildcardOrGeneric t, boolean isParameterType) {
String type = t.acceptTV(new TypeToString());
SignatureVisitor sv;
if(isParameterType) {
sv = sw.visitParameterType();
}
else {
sv = sw.visitReturnType();
}
switch (type) {
case "RT":
sv.visitClassType(t.acceptTV(new TypeToSignature()));
break;
case "GRT":
GenericRefType g = (GenericRefType) t;
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
break;
case "TPH":
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
// der Fall wenn die Type eine Interface ist, muss betrachtet werden
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
// Interface oder eine Klasse ist.
if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) {
// sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
sv.visitClassType(r.acceptTV(new TypeToSignature()));
} else {
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
sv.visitTypeVariable(r.acceptTV(new TypeToSignature()).substring(4)+"$");
}
break;
default:
if(!isParameterType)
sv.visitBaseType('V');
break;
}
}
/**
* Creates signature for class or interface with {@link SignatureWriter}
* Signature looks like:
* <typevaliables (K:Ljava/lang/Object "Bounds")>superclass
*/
private void createSignatureForClassOrInterface() {
Iterator<GenericTypeVar> itr = classOrInterface.getGenerics().iterator();
while(itr.hasNext()) {
GenericTypeVar g = itr.next();
getBoundsOfTypeVar(g,genericsAndBounds);
}
sw.visitSuperclass().visitClassType(classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()));;
sw.visitEnd();
}
/**
* Get bounds of type variable
* @param g type variable
* @param genAndBounds
*/
private void getBoundsOfTypeVar(GenericTypeVar g, HashMap<String, String> genAndBounds) {
sw.visitFormalTypeParameter(g.getName());
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
while(bItr.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric b =bItr.next();
String boundDesc = b.acceptTV(new TypeToDescriptor());
// System.out.println("GetBounds: " + boundDesc);
// Ensure that <...> extends java.lang.Object OR ...
sw.visitClassBound().visitClassType(boundDesc);
genAndBounds.put(g.getName(), boundDesc);
}
sw.visitClassBound().visitEnd();
}
public String toString() {
return sw.toString();
}
}

View File

@ -0,0 +1,55 @@
package de.dhbwstuttgart.bytecode.signature;
import java.util.Iterator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
public class TypeToSignature implements TypeVisitor<String> {
@Override
public String visit(RefType refType) {
// return refType.toString().replace(".", "/");
String params = "";
if(refType.getParaList().size()>0){
params += "<";
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
while(it.hasNext()){
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
params += "L"+param.toString().replace(".", "/");
if(it.hasNext())params += ";";
}
params += ";>";
}
// String t = refType.getName().toString().replace(".", "/");
// return t.equals("Fun1")?t+"$$"+params+";":t+params+";";
return refType.getName().toString().replace(".", "/") + params+";";
}
@Override
public String visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(TypePlaceholder typePlaceholder) {
return typePlaceholder.toString().replace(".", "/");
}
@Override
public String visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(GenericRefType genericRefType) {
return genericRefType.getParsedName().replace(".", "/");
}
}

View File

@ -0,0 +1,38 @@
package de.dhbwstuttgart.bytecode.signature;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
public class TypeToString implements TypeVisitor<String>{
@Override
public String visit(RefType refType) {
return "RT";
}
@Override
public String visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(TypePlaceholder typePlaceholder) {
return "TPH";
}
@Override
public String visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public String visit(GenericRefType genericRefType) {
return "GRT";
}
}

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;
import java.util.ArrayList;
@ -7,8 +8,7 @@ import java.util.List;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
public class KindOfLambda implements StatementVisitor{
@ -45,7 +45,7 @@ public class KindOfLambda implements StatementVisitor{
}
@Override
public void visit(Binary binary) {
public void visit(BinaryExpr binary) {
// TODO Auto-generated method stub
}
@ -126,6 +126,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 +160,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
@ -173,12 +172,6 @@ public class KindOfLambda implements StatementVisitor{
}
@Override
public void visit(Null aNull) {
// TODO Auto-generated method stub
}
@Override
public void visit(Literal literal) {
// TODO Auto-generated method stub

View File

@ -0,0 +1,26 @@
package de.dhbwstuttgart.bytecode.utilities;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
public class Lambda {
private LambdaExpression lambdaExpression;
public Lambda(LambdaExpression lambdaExpression) {
this.lambdaExpression = lambdaExpression;
}
public ParameterList getParams() {
return lambdaExpression.params;
}
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return lambdaExpression.getReturnType();
}
public String accept(DescriptorVisitor descVisitor) {
return descVisitor.visit(this);
}
}

View File

@ -0,0 +1,42 @@
package de.dhbwstuttgart.bytecode.utilities;
import java.util.HashMap;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
public class MethodFromMethodCall {
private ArgumentList argList;
private RefTypeOrTPHOrWildcardOrGeneric returnType;
private HashMap<String, String> genericsAndBoundsMethod;
private HashMap<String,String> genericsAndBounds;
public MethodFromMethodCall(ArgumentList argList,RefTypeOrTPHOrWildcardOrGeneric returnType,
HashMap<String, String> genericsAndBoundsMethod,HashMap<String,String> genericsAndBounds) {
this.argList = argList;
this.returnType = returnType;
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
this.genericsAndBounds = genericsAndBounds;
}
public ArgumentList getArgList() {
return argList;
}
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return returnType;
}
public HashMap<String, String> getGenericsAndBoundsMethod(){
return genericsAndBoundsMethod;
}
public HashMap<String,String> getGenericsAndBounds(){
return genericsAndBounds;
}
public String accept(DescriptorVisitor descVisitor) {
return descVisitor.visit(this);
}
}

View File

@ -0,0 +1,40 @@
package de.dhbwstuttgart.bytecode.utilities;
import java.util.HashMap;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.ParameterList;
public class NormalConstructor {
private Constructor constructor;
private HashMap<String, String> genericsAndBounds;
private boolean hasGenerics;
public NormalConstructor(Constructor constructor, boolean hasGenerics) {
this.constructor = constructor;
this.hasGenerics = hasGenerics;
}
public NormalConstructor(Constructor constructor, HashMap<String, String> genericsAndBounds, boolean hasGenerics) {
this.constructor = constructor;
this.genericsAndBounds = genericsAndBounds;
this.hasGenerics = hasGenerics;
}
public HashMap<String, String> getGenericsAndBounds() {
return genericsAndBounds;
}
public boolean hasGen() {
return hasGenerics;
}
public ParameterList getParameterList() {
return constructor.getParameterList();
}
public String accept(DescriptorVisitor descVisitor) {
return descVisitor.visit(this);
}
}

View File

@ -0,0 +1,56 @@
package de.dhbwstuttgart.bytecode.utilities;
import java.util.HashMap;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
public class NormalMethod {
private Method method;
private HashMap<String, String> genericsAndBounds;
private HashMap<String, String> genericsAndBoundsMethod;
private boolean hasGenerics;
public NormalMethod(Method method, boolean hasGenerics) {
this.method = method;
this.hasGenerics = hasGenerics;
}
public NormalMethod(Method method, HashMap<String, String> genericsAndBounds,
HashMap<String, String> genericsAndBoundsMethod,boolean hasGenerics) {
this.method = method;
this.genericsAndBounds = genericsAndBounds;
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
this.hasGenerics = hasGenerics;
}
public Method getMethod() {
return method;
}
public ParameterList getParameterList() {
return method.getParameterList();
}
public HashMap<String, String> getGenericsAndBounds(){
return genericsAndBounds;
}
public HashMap<String, String> getGenericsAndBoundsMethod(){
return genericsAndBoundsMethod;
}
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return method.getReturnType();
}
public boolean hasGen() {
return this.hasGenerics;
}
public String accept(DescriptorVisitor descVisitor) {
return descVisitor.visit(this);
}
}

View File

@ -0,0 +1,32 @@
package de.dhbwstuttgart.bytecode.utilities;
import java.util.List;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
public class SamMethod {
private List<RefTypeOrTPHOrWildcardOrGeneric> argumentList;
private RefTypeOrTPHOrWildcardOrGeneric returnType;
public SamMethod(List<RefTypeOrTPHOrWildcardOrGeneric> argumentList, RefTypeOrTPHOrWildcardOrGeneric returnType) {
this.argumentList = argumentList;
this.returnType = returnType;
}
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgumentList() {
return argumentList;
}
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return returnType;
}
public String accept(DescriptorVisitor descVisitor) {
return descVisitor.visit(this);
}
}

View File

@ -1,31 +1,41 @@
package de.dhbwstuttgart.core;
import de.dhbwstuttgart.bytecode.BytecodeGen;
import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
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.RuleSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class JavaTXCompiler {
@ -82,31 +92,127 @@ public class JavaTXCompiler {
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for(SourceFile sf : this.sourceFiles.values()) {
//allClasses.addAll(getAvailableClasses(sf));
allClasses.addAll(getAvailableClasses(sf));
allClasses.addAll(sf.getClasses());
}
final ConstraintSet<Pair> cons = getConstraints();
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
System.out.println(finiteClosure);
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
TypeUnify unify = new TypeUnify();
Set<Set<UnifyPair>> results = new HashSet<>();
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
Set<UnifyPair> xConsSet = new HashSet<>();
for (Constraint<UnifyPair> constraint : xCons) {
xConsSet.addAll(constraint);
}
System.out.println(xConsSet);
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result);
results.addAll(result);
try {
FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log"));
logFile.write("FC:\\" + finiteClosure.toString()+"\n");
for(SourceFile sf : this.sourceFiles.values()) {
logFile.write(ASTTypePrinter.print(sf));
}
logFile.flush();
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
for (List<Constraint<UnifyPair>> xCons : cardProd ){
Set<UnifyPair> xConsSet = new HashSet<>();
for (Constraint<UnifyPair> constraint : xCons) {
xConsSet.addAll(constraint);
}
//.collect(Collectors.toCollection(ArrayList::new))))
System.out.println(xConsSet);
Set<String> paraTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
xConsSet = xConsSet.stream().map(x -> {
//Hier muss ueberlegt werden, ob
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
// mit disableWildcardtable() werden.
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
//PL 2018-04-23
if ((x.getLhsType() instanceof PlaceholderType)) {
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
((PlaceholderType)x.getLhsType()).disableWildcardtable();
}
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
((PlaceholderType)x.getLhsType()).disableWildcardtable();
}
}
if ((x.getRhsType() instanceof PlaceholderType)) {
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
((PlaceholderType)x.getRhsType()).disableWildcardtable();
}
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
((PlaceholderType)x.getRhsType()).disableWildcardtable();
}
}
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
}).map( y -> {
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
}
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
}
}
return y; } )
.collect(Collectors.toCollection(HashSet::new));
varianceInheritance(xConsSet);
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile);
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
}
catch (IOException e) { }
return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
}
return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
}
/**
* Vererbt alle Variancen
* @param eq The set of constraints
*/
private void varianceInheritance(Set<UnifyPair> eq) {
Set<PlaceholderType> usedTPH = new HashSet<>();
Set<PlaceholderType> phSet = eq.stream().map(x -> {
Set<PlaceholderType> pair = new HashSet<>();
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
return pair;
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
phSetVariance.removeIf(x -> (x.getVariance() == 0));
while(!phSetVariance.isEmpty()) {
PlaceholderType a = phSetVariance.remove(0);
usedTPH.add(a);
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
//ht.put(a, a.getVariance());
Set<UnifyPair> eq1 = new HashSet<>(eq);
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
eq1 = new HashSet<>(eq);
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
phSetVariance = new ArrayList<>(phSet);
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
}
}
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
@ -128,5 +234,28 @@ public class JavaTXCompiler {
SourceFile ret = generator.convert(tree, environment.packageCrawler);
return ret;
}
public void generateBytecode() throws ClassNotFoundException, IOException {
for(File f : sourceFiles.keySet()) {
HashMap<String,byte[]> classFiles = new HashMap<>();
SourceFile sf = sourceFiles.get(f);
List<ResultSet> typeinferenceResult = this.typeInference();
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult);
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
bytecodeGen.visit(sf);
this.writeClassFile(bytecodeGen.getClassFiles());
}
}
}
private void writeClassFile(HashMap<String, byte[]> classFiles) throws IOException {
FileOutputStream output;
for(String name : classFiles.keySet()) {
byte[] bytecode = classFiles.get(name);
System.out.println("generating "+name+ ".class file ...");
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class"));
output.write(bytecode);
output.close();
System.out.println(name+".class file generated");
}
}
}

View File

@ -40,15 +40,29 @@ public class CompilationEnvironment {
* @param sourceFiles die zu kompilierenden Dateien
*/
public CompilationEnvironment(List<File> sourceFiles) {
String bootClassPath = System.getProperty("sun.boot.class.path");
librarys = new ArrayList<>();
for(String path : bootClassPath.split(File.pathSeparator)) {
try {
librarys.add(new URL("file:"+path));
} catch (MalformedURLException e) {
new DebugException("Fehler im Classpath auf diesem System");
/**
* Java 9 bringt einige Änderungen am Classloader
* So funktioniert der BootClassLoader nicht mehr.
* hier gibts ein paar Quellen zum nachlesen:
* http://java9.wtf/class-loading/
* https://stackoverflow.com/questions/46494112/classloaders-hierarchy-in-java-9
*
*/
//String bootClassPath = System.getProperty("sun.boot.class.path");
// ClassLoader cl = ClassLoader.getPlatformClassLoader();
ClassLoader cl = ClassLoader.getSystemClassLoader();
String bootClassPath = System.getProperty("java.class.path");
librarys = new ArrayList<>();
for(String path : bootClassPath.split(File.pathSeparator)) {
try {
librarys.add(new URL("file:"+path));
} catch (MalformedURLException e) {
new DebugException("Fehler im Classpath auf diesem System");
}
}
}
//URLClassLoader loader = new URLClassLoader(new URL[0], cl);
//librarys = Arrays.asList(loader.getURLs());
this.sourceFiles = sourceFiles;
this.packageCrawler = new PackageCrawler(librarys);
}

View File

@ -29,7 +29,7 @@ public class JavaTXParser {
*/
}
/* Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet:
/* Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet:
public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException {
return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
}

View File

@ -0,0 +1,168 @@
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.parser.NullToken;
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.*;
import java.util.stream.Collectors;
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> toUnifyFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
return toFC(availableClasses).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
}
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
HashSet<Pair> pairs = new HashSet<>();
for(ClassOrInterface cly : availableClasses){
pairs.addAll(getSuperTypes(cly, availableClasses));
}
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<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
return getSuperTypes(forType, availableClasses, new HashMap<>());
}
/**
*
* @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())){
TypePlaceholder replacePlaceholder = TypePlaceholder.fresh(new NullToken());
gtvs.put(gtv.getName(), replacePlaceholder);
newGTVs.put(gtv.getName(), replacePlaceholder);
}
params.add(gtvs.get(gtv.getName()));
}
List<RefType> superClasses = new ArrayList<>();
superClasses.add(forType.getSuperClass());
superClasses.addAll(forType.getSuperInterfaces());
List<Pair> retList = new ArrayList<>();
for(RefType superType : superClasses){
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> superType.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(superType.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 in der Superklasse ausgetauscht werden müssen
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = superType.getParaList().iterator();
while(itSetParams.hasNext()){
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs));
newGTVs.put(itGenParams.next().getName(), setSetType);
}
//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;
Pair ret = new Pair(t1, t2, PairOperator.SMALLER);
List<Pair> superTypes;
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER));
}else{
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
}
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<RefTypeOrTPHOrWildcardOrGeneric>{
private final HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs;
TypeExchanger(HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs){
this.gtvs = gtvs;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
params.add(param.acceptTV(this));
}
RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
return ret;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
throw new DebugException("Dieser Fall darf nicht auftreten");
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
if(! gtvs.containsKey(genericRefType.getParsedName()))
throw new DebugException("Dieser Fall darf nicht auftreten");
return gtvs.get(genericRefType.getParsedName());
}
}
}

View File

@ -3,8 +3,8 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.parser.scope.JavaClassName;
public class GenericContext {
public final String parentMethod;
public final JavaClassName parentClass;
private final String parentMethod;
private final JavaClassName parentClass;
public GenericContext(JavaClassName parentClass, String parentMethod) {
if(parentMethod == null)parentMethod = "";

View File

@ -7,7 +7,7 @@ import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.*;
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr.Operation;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -95,7 +95,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 +121,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());
}
@ -279,23 +279,24 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
//TODO
throw new NotImplementedException();
Expression argument = convert(stmt.unaryExpression());
Token offset = stmt.getStart();
return new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
}
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
//TODO
throw new NotImplementedException();
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
}
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) {
//TODO
throw new NotImplementedException();
return new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
}
private Statement convert(Java8Parser.AssignmentContext 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){
@ -541,8 +544,7 @@ public class StatementGenerator {
if(expression.conditionalOrExpression() == null){
return convert(expression.conditionalAndExpression());
}else{
return new Binary(convert(expression.conditionalOrExpression()),
convert(expression.conditionalAndExpression()), Binary.Operator.OR);
throw new NotImplementedException();
}
}
@ -550,8 +552,7 @@ public class StatementGenerator {
if(expression.conditionalAndExpression() == null){
return convert(expression.inclusiveOrExpression());
}else{
return new Binary(convert(expression.conditionalAndExpression()),
convert(expression.inclusiveOrExpression()), Binary.Operator.AND);
throw new NotImplementedException();
}
}
@ -588,11 +589,43 @@ public class StatementGenerator {
}
private Expression convert(Java8Parser.RelationalExpressionContext expression) {
if(expression.relationalExpression() == null){
if(expression.relationalExpression() == null) {
return convert(expression.shiftExpression());
}else{
throw new NotImplementedException();
}else {
String operator = expression.getChild(1).getText();
return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()),
convert(expression.relationalExpression()),
convert(expression.shiftExpression()), expression.getStart());
}
//}else throw new NotImplementedException();
}
private BinaryExpr.Operator convertBinaryOperator(String operator) {
//return BinaryExpr.Operator.ADD;
if(operator.equals("+")) {
return BinaryExpr.Operator.ADD;
}else if(operator.equals("-")) {
return BinaryExpr.Operator.SUB;
}else if(operator.equals("*")) {
return BinaryExpr.Operator.MUL;
}else if(operator.equals("&")) {
return BinaryExpr.Operator.AND;
}else if(operator.equals("|")) {
return BinaryExpr.Operator.OR;
}else if(operator.equals("/")) {
return BinaryExpr.Operator.DIV;
}else if(operator.equals("<")) {
return BinaryExpr.Operator.LESSTHAN;
}else if(operator.equals(">")) {
return BinaryExpr.Operator.BIGGERTHAN;
}else if(operator.equals(">=")) {
return BinaryExpr.Operator.BIGGEREQUAL;
} else if(operator.equals("<=")) {
return BinaryExpr.Operator.LESSEQUAL;
} else {
throw new NotImplementedException();
}
// throw new NotImplementedException();
}
private Expression convert(Java8Parser.ShiftExpressionContext expression) {
@ -604,10 +637,15 @@ public class StatementGenerator {
}
private Expression convert(Java8Parser.AdditiveExpressionContext expression) {
if(expression.additiveExpression() == null){
return convert(expression.multiplicativeExpression());
}else{
throw new NotImplementedException();
}else {
Expression leftSide = convert(expression.additiveExpression());
Expression rightSide = convert(expression.multiplicativeExpression());
BinaryExpr.Operator op = convertBinaryOperator(expression.getChild(1).getText());
Token offset = expression.getStart();
return new BinaryExpr(op, TypePlaceholder.fresh(expression.getStart()), leftSide, rightSide, offset);
}
}
@ -615,7 +653,11 @@ public class StatementGenerator {
if(expression.multiplicativeExpression() == null){
return convert(expression.unaryExpression());
}else{
throw new NotImplementedException();
Expression leftSide = convert(expression.multiplicativeExpression());
Expression rightSide = convert(expression.unaryExpression());
BinaryExpr.Operator op = convertBinaryOperator(expression.getChild(1).getText());
Token offset = expression.getStart();
return new BinaryExpr(op, TypePlaceholder.fresh(offset), leftSide, rightSide, offset);
}
}
@ -627,9 +669,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 +716,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;
@ -771,25 +815,27 @@ public class StatementGenerator {
private Expression convert(Java8Parser.LiteralContext literal) {
if(literal.IntegerLiteral() != null || literal.FloatingPointLiteral()!= null){
Number value = Double.parseDouble(literal.IntegerLiteral().getText());
return new NumberLiteral(TypePlaceholder.fresh(literal.getStart()),
return new Literal(TypePlaceholder.fresh(literal.getStart()),
value, literal.getStart());
}else if(literal.BooleanLiteral() != null){
RefType type = new RefType(reg.getName("java.lang.Boolean"),literal.getStart());
return new BoolLiteral(type,
return new Literal(type,
Boolean.parseBoolean(literal.BooleanLiteral().getText()),
literal.getStart());
}else if(literal.CharacterLiteral() != null){
RefType type = new RefType(reg.getName("java.lang.Character"),literal.getStart());
return new CharLiteral(type,
literal.CharacterLiteral().getText().charAt(0),
return new Literal(type,
// das gibt immer ' zurück, der Char befindet sich in Position 1
//literal.CharacterLiteral().getText().charAt(0),
literal.CharacterLiteral().getText().charAt(1),
literal.getStart());
}else if(literal.StringLiteral()!=null){
RefType type = new RefType(reg.getName("java.lang.String"),literal.getStart());
return new StringLiteral(type,
literal.StringLiteral().getText(),
return new Literal(type,
literal.StringLiteral().getText().substring(1, literal.StringLiteral().getText().length()-1),
literal.getStart());
}else if(literal.NullLiteral() != null){
return new Null(TypePlaceholder.fresh(literal.getStart()),
return new Literal(TypePlaceholder.fresh(literal.getStart()), null,
literal.getStart());
}else {
throw new NotImplementedException();
@ -850,7 +896,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
@ -858,7 +904,7 @@ public class StatementGenerator {
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
//RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()),
//funNParams, name.getStart());
//funNParams, name.getStart());
return new LambdaExpression(lambdaType, params, block, expression.getStart());
}
}

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

@ -73,6 +73,7 @@ public class SyntaxTreeGenerator{
}
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler) throws ClassNotFoundException{
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
List<ClassOrInterface> classes = new ArrayList<>();
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler);
this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet());
@ -89,6 +90,15 @@ public class SyntaxTreeGenerator{
return new SourceFile(this.pkgName, classes, this.imports);
}
private String convert(Java8Parser.PackageDeclarationContext packageDeclarationContext) {
String ret = "";
for(TerminalNode identifier : packageDeclarationContext.Identifier()){
ret += identifier.getText()+".";
}
ret = ret.substring(0, ret.length()-1);
return ret;
}
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
@ -136,12 +146,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());
}
}
@ -164,7 +174,12 @@ public class SyntaxTreeGenerator{
modifiers += newModifier;
}
}
JavaClassName name = reg.getName(ctx.Identifier().getText());
String className = this.pkgName + (this.pkgName.length()>0?".":"") + ctx.Identifier().getText();
JavaClassName name = reg.getName(className); //Holt den Package Namen mit dazu
if(! name.toString().equals(className)){ //Kommt die Klasse schon in einem anderen Package vor?
throw new TypeinferenceException("Name " + className + " bereits vorhanden in " + reg.getName(className).toString()
,ctx.getStart());
}
GenericsRegistry generics = createGenerics(ctx.typeParameters(), name, "", reg, new GenericsRegistry(globalGenerics));
Token offset = ctx.getStart();
GenericDeclarationList genericClassParameters;
@ -198,20 +213,20 @@ public class SyntaxTreeGenerator{
}
Boolean isInterface = false;
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = convert(ctx.superinterfaces(), generics);
List<RefType> implementedInterfaces = convert(ctx.superinterfaces(), generics);
return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass,
isInterface, implementedInterfaces, offset);
}
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
private List<RefType> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
if(ctx == null)return new ArrayList<>();
return convert(ctx.interfaceTypeList(), generics);
}
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
private List<RefType> convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
List<RefType> ret = new ArrayList<>();
for(Java8Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){
ret.add(TypeGenerator.convert(interfaceType.classType(), reg, generics));
ret.add((RefType) TypeGenerator.convert(interfaceType.classType(), reg, generics));
}
return ret;
}
@ -221,10 +236,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) {
@ -396,7 +410,7 @@ public class SyntaxTreeGenerator{
List<Field> fields = convertFields(ctx.interfaceBody());
List<Method> methods = convertMethods(ctx.interfaceBody(), name, superClass, generics);
List<RefTypeOrTPHOrWildcardOrGeneric> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
List<RefType> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
return new ClassOrInterface(modifiers, name, fields, methods, new ArrayList<>(),
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
@ -419,7 +433,7 @@ public class SyntaxTreeGenerator{
return ret;
}
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
private List<RefType> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
if(extendsInterfacesContext == null)return new ArrayList<>();
return convert(extendsInterfacesContext.interfaceTypeList(), generics);
}

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.scope.GenericTypeName;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
@ -40,7 +39,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());
@ -70,7 +74,7 @@ public class TypeGenerator {
//Problem <A extends B, B> ist erlaubt, würde aber bei den Bounds von A den Generic B nicht als solchen erkennen
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
GenericTypeVar ret = new GenericTypeVar(new GenericTypeName(new GenericContext(parentClass, parentMethod), name), bounds, typeParameter.getStart(), typeParameter.getStop());
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
generics.put(name, new GenericContext(parentClass, parentMethod));
return ret;
}
@ -126,7 +130,7 @@ public class TypeGenerator {
String name, Java8Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein
if(generics.contains(name)){
return new GenericRefType(new GenericTypeName(generics.get(name),name), offset);
return new GenericRefType(name, offset);
}else{
throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",offset);
}

View File

@ -72,7 +72,7 @@ public class GatherNames {
public static Map<String, Integer> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages) throws ClassNotFoundException {
Map<String, Integer> ret = new HashMap<>();
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
ret.putAll(packages.getClassNames("java.lang"));
//ret.putAll(packages.getClassNames("java.lang"));
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
if(importDeclCtx.singleTypeImportDeclaration() != null){
Class cl = classLoader.loadClass(importDeclCtx.singleTypeImportDeclaration().typeName().getText());

View File

@ -1,26 +0,0 @@
package de.dhbwstuttgart.parser.scope;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
public class GenericTypeName extends JavaClassName {
private final static String DELIMITER = "%";
private final JavaClassName parentClass;
private final String methodName;
public GenericTypeName(GenericContext genericContext, String name) {
super(name);
this.parentClass = genericContext.parentClass;
this.methodName = genericContext.parentMethod;
}
public String getUniqueIdentifier() {
return parentClass.toString()
+ DELIMITER + methodName
+ DELIMITER + super.toString();
}
public JavaClassName getParentClass() {
return parentClass;
}
}

View File

@ -1,115 +0,0 @@
package de.dhbwstuttgart.sat.asp;
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.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
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();
private final String asp;
public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses){
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
List<Pair> constraintPairs = new ArrayList<>();
for(Constraint<Pair> constraint : constraints1){
System.out.println(UnifyTypeFactory.convert(constraint));
constraintPairs.addAll(constraint);
}
asp = toASP(constraintPairs, fcClasses);
}
public String getASP(){
return asp;
}
private String toASP(List<Pair> constraintSet, Collection<ClassOrInterface> fcClasses){
TypeConverter converter = new TypeConverter();
for(ClassOrInterface cl : fcClasses){
ASPType superClass = cl.getSuperClass().acceptTV(converter);
ASPPairSmaller fcEntry = new ASPPairSmaller(convert(cl), superClass);
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);
}else if(pair.OperatorSmallerDot()){
return new ASPPairSmallerDot(ls, rs);
}else throw new NotImplementedException();
}
private ASPType convert(ClassOrInterface cl){
List<ASPType> paramList = new ArrayList<>();
for(GenericTypeVar gtv : cl.getGenerics()){
paramList.add(new ASPGenericType(toConstant(gtv.getName())));
}
ASPParameterList params = new ASPParameterList(paramList, writer);
return new ASPRefType(toConstant(cl.getClassName()), params);
}
public static String toConstant(JavaClassName name){
return toConstant(name.toString().replace(".", "_"));
}
public static String toConstant(String name){
return "c" + name.toString().replace(".", "_");
}
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(toConstant(type.getName()), params);
}
@Override
public ASPType visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public ASPType visit(TypePlaceholder typePlaceholder) {
return new ASPTypeVar(toConstant(typePlaceholder.getName()));
}
@Override
public ASPType visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public ASPType visit(GenericRefType genericRefType) {
return new ASPRefType(toConstant(genericRefType.getName()),
new ASPParameterList(new ArrayList<>(), writer));
}
}
}

View File

@ -0,0 +1,40 @@
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());
}
public static String toConstant(String name){
return "c" + replace(name);
}
public static String fromConstant(String s){
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;
}
}

View File

@ -0,0 +1,52 @@
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/finiteclosure.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/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/adapt.lp"));
}
public Clingo(List<File> inputFiles){
this.input = inputFiles;
}
/*
TODO: Clingo per Java Wrapper https://stackoverflow.com/questions/3356200/using-java-to-wrap-over-c
*/
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
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();
String result = IOUtils.toString(output, StandardCharsets.UTF_8);
return result;
}
}

View 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;
}
}

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
public class ASPGenericType implements ASPType{
public static final String ASP_GENERIC_TYPE_NAME = "genericType";
private final String name;
public ASPGenericType(String name){
this.name = name;
}
public String toString(){
return ASP_GENERIC_TYPE_NAME + "(" + name + ")";
}
}

View File

@ -1,21 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
public abstract class ASPPair {
public final ASPType leftSide;
public final ASPType rightSide;
public ASPPair(ASPType ls, ASPType rs){
this.leftSide = ls;
this.rightSide = rs;
}
public String toASP(){
return this.getRuleName() + "(" + leftSide + ","+ rightSide + ")";
}
public String toString(){
return toASP();
}
protected abstract String getRuleName();
}

View File

@ -1,13 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
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;
}
}

View File

@ -1,13 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
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;
}
}

View File

@ -1,13 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
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;
}
}

View File

@ -1,45 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
import de.dhbwstuttgart.sat.asp.ASPGenerator;
import de.dhbwstuttgart.sat.asp.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){
this.types = types;
if(types.size() == 0){
name = ASP_PARAMLIST_END_POINTER;
}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 = ASP_PARAMLIST_END_POINTER;
param += nextPointer;
writer.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
//paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
}
}
}
private String newName() {
return ASPGenerator.toConstant(NameGenerator.makeNewName());
}
public String toString(){
return name;
}
}

View File

@ -1,20 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
public class ASPRefType implements ASPType {
public static final String ASP_TYPE = "type";
private final ASPParameterList params;
private final String name;
public ASPRefType(String name, ASPParameterList params){
this.name = name;
this.params = params;
}
public ASPParameterList getParams() {
return params;
}
public String toString(){
return ASP_TYPE + "(" + name +"," + params.name + ")";
}
}

View File

@ -0,0 +1,23 @@
package de.dhbwstuttgart.sat.asp.model;
public enum ASPRule {
ASP_PAIR_EQUALS_NAME("equals"),
ASP_PAIR_SMALLER_NAME("smaller"),
ASP_PAIR_SMALLER_DOT_NAME("smallerDot"),
ASP_PARAMLIST_NAME("param"),
ASP_PARAMLIST_END_POINTER("null"),
ASP_TYPE("type"),
ASP_FCTYPE("typeFC"),
ASP_TYPE_VAR("typeVar");
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

@ -1,14 +0,0 @@
package de.dhbwstuttgart.sat.asp.model;
public class ASPTypeVar implements ASPType{
private final String name;
public ASPTypeVar(String name){
this.name = name;
}
@Override
public String toString() {
return "typeVar("+ name +")";
}
}

View File

@ -0,0 +1,231 @@
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.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;
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;
/**
* Ablauf:
* - Erst werden alle benötigten Statements eingelesen. Die Pointer bleiben als Strings erhalten
* - Anschließend müssen diese wieder zu einem Unify Ergebnis zurückgewandelt werden
* - Hier nicht die Typen aus dem unify.model packages verwenden.
* TODO: Überlegen welche Informationen noch nach der Unifizierung gebraucht werden
* -> Eigentlich nur die korrekten Namen der Typen und TPHs
*/
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
* @param toParse
* @return
*/
public static ResultSet parse(String toParse, Collection<TypePlaceholder> oldPlaceholders){
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(String paramPointer : types.values().stream().map(parsedType -> parsedType.params).collect(Collectors.toList())){ }
//Dann die Equalsdot Statements
for(Relation eq : equalsRelations){
RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(eq.left);
RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(eq.right);
if(lsType instanceof TypePlaceholder && rsType instanceof RefType)
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();
}
this.resultSet = new ResultSet(ret);
}
private RefTypeOrTPHOrWildcardOrGeneric getType(String name) {
if(tphs.contains(name)){
name = ASPStringConverter.fromConstant(name);
for(TypePlaceholder tph : originalTPHs){
if(tph.getName().equals(name))return tph;
}
return TypePlaceholder.fresh(new NullToken());
}else
if(types.containsKey(name)){
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
ParsedType t = types.get(name);
for(String param : getParams(t.params)){
params.add(this.getType(param));
}
return new RefType(new JavaClassName(ASPStringConverter.fromConstant(t.name)), params, new NullToken());
}else throw new DebugException("Der Typ " + name + " konnte nicht bestimmt werden");
}
private static class ParameterListNode{
final String type;
final String nextNode;
public ParameterListNode(String type, String next) {
this.type = type;
this.nextNode = next;
}
}
private List<String> getParams(String pointer) {
List<String> params = new ArrayList<>();
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);
}
return params;
//Optional<ASPParameterList> ret = parameterLists.stream().filter(aspParameterList -> aspParameterList.name.equals(rs)).findAny();
//return ret.get();
}
}

View 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
;

View 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

View File

@ -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) { }
}

View 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);
}
}
}

View 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

View File

@ -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);
}

View 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);
}
}
}

View File

@ -0,0 +1,12 @@
package de.dhbwstuttgart.sat.asp.parser.model;
import java.util.List;
public class ParsedType {
public final String name;
public final String params;
public ParsedType(String name, String params){
this.name = name;
this.params = params;
}
}

View 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();
}
}

View 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<>();
}
}
}

View File

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

View File

@ -1,10 +1,8 @@
package de.dhbwstuttgart.sat.asp;
import de.dhbwstuttgart.sat.asp.model.ASPRefType;
import de.dhbwstuttgart.sat.asp.model.ASPStatement;
import de.dhbwstuttgart.sat.asp.model.ASPType;
package de.dhbwstuttgart.sat.asp.writer;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
public class ASPWriter {
@ -21,4 +19,8 @@ public class ASPWriter {
}
return ret;
}
public void addAll(Collection<ASPStatement> aspStatements) {
content.addAll(aspStatements);
}
}

View File

@ -1,12 +1,6 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import java.lang.reflect.Type;
public interface ASTVisitor extends StatementVisitor{

View File

@ -1,13 +1,10 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.type.*;
import java.lang.reflect.Modifier;
import java.util.Iterator;
public abstract class AbstractASTWalker implements ASTVisitor{
@ -61,7 +58,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);
@ -129,7 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
}
@Override
public void visit(Binary binary) {
public void visit(BinaryExpr binary) {
}
@ -157,12 +154,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 +200,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,24 +230,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) {
}
@Override
public void visit(Null aNull) {
whileStmt.loopBlock.accept(this);
}
@Override

View File

@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -26,11 +27,11 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
private GenericDeclarationList genericClassParameters;
private RefType superClass;
protected boolean isInterface;
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
private List<RefType> implementedInterfaces;
private List<Constructor> constructors;
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
RefType superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
super(offset);
this.modifiers = modifiers;
this.name = name;
@ -101,4 +102,12 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
public Collection<RefType> getSuperInterfaces() {
return implementedInterfaces;
}
public String toString() {
return this.name.toString() + this.genericClassParameters.toString();
}
}

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

@ -31,4 +31,8 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
public String toString() {
return this.gtvs.toString();
}
}

View File

@ -1,7 +1,5 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.parser.scope.GenericTypeName;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
@ -26,9 +24,9 @@ public class GenericTypeVar extends SyntaxTreeNode
*/
List<? extends RefTypeOrTPHOrWildcardOrGeneric> bounds=new ArrayList<RefTypeOrTPHOrWildcardOrGeneric>();
private Token endOffset;
private GenericTypeName name;
private String name;
public GenericTypeVar(GenericTypeName s, List<? extends RefTypeOrTPHOrWildcardOrGeneric> bounds, Token offset, Token endOffset)
public GenericTypeVar(String s, List<? extends RefTypeOrTPHOrWildcardOrGeneric> bounds, Token offset, Token endOffset)
{
super(offset);
name = s;
@ -50,18 +48,15 @@ public class GenericTypeVar extends SyntaxTreeNode
return "BoGTV " + this.name;
}
public GenericTypeName getName() {
return name;
}
public String getParsedName(){
public String getName(){
return name.toString();
}
/*
public JavaClassName definingClass(){
return name.getParentClass();
}
*/
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);

Some files were not shown because too many files have changed in this diff Show More