Compare commits
252 Commits
parser
...
strucTypes
Author | SHA1 | Date | |
---|---|---|---|
|
23786184ad | ||
|
55f6fe47ac | ||
|
4919dd34b2 | ||
|
c08d4b8457 | ||
|
aac113e12e | ||
|
d2d02e26f0 | ||
|
e9d5d5f7c7 | ||
|
092ee53f74 | ||
|
413cb48a96 | ||
|
e0d5699ae7 | ||
|
3f2558d21e | ||
|
24f93f0bcb | ||
|
f44f08b895 | ||
|
814aef082d | ||
|
5a0e53485c | ||
|
e972282620 | ||
|
f7160c10f4 | ||
|
7a5940ac65 | ||
|
86e94b8cc0 | ||
|
25a5e79509 | ||
|
7e1d6fad01 | ||
|
c7e0281d53 | ||
|
23ae5d5745 | ||
|
bb26112a9b | ||
|
97d893e66b | ||
|
57fb90afaf | ||
|
63ac79f02c | ||
|
07fa62d11d | ||
|
66587a8f71 | ||
|
581e5e574e | ||
|
ae14dfd947 | ||
|
9d53d9d5d1 | ||
|
58f5e17ab5 | ||
|
6fce2760c5 | ||
|
1de897fb1f | ||
|
87dede5d5f | ||
|
f085f9f499 | ||
|
a40d2b991f | ||
|
704415ae3b | ||
|
65531ac12e | ||
|
34e632b872 | ||
|
3470215bae | ||
|
f5398fa8e9 | ||
|
f617ad8946 | ||
|
876ec6a4f6 | ||
|
26d9b1215f | ||
|
0f29bc038a | ||
|
a5ed5a2a46 | ||
|
c597b0430a | ||
|
06a0cb8eaf | ||
|
b5a601d798 | ||
|
7ea6777906 | ||
|
6b1896f58c | ||
|
d81c06cdd9 | ||
|
8baff8f376 | ||
|
427a87598c | ||
|
bc2cab8c95 | ||
|
dca5d21c23 | ||
|
51a2acdbaf | ||
|
dcc36f082f | ||
|
9575afd0b4 | ||
|
403430d0c4 | ||
|
d9ab487253 | ||
|
5c797a44a1 | ||
|
87dbcfdad4 | ||
|
8048af2106 | ||
|
e4243b612c | ||
|
da4c59f2cf | ||
|
1c22fc7d57 | ||
|
0b7aea21d9 | ||
|
521a1cbf3b | ||
|
22ca2cbd4a | ||
|
49ea4ee283 | ||
|
225dc16a89 | ||
|
6f85c2b376 | ||
|
a17342458e | ||
|
4738add4fc | ||
|
ab46709390 | ||
|
bc99dc4c8b | ||
|
2bbf9eac36 | ||
|
a785c85d42 | ||
|
48e22982c8 | ||
|
3ed300268f | ||
|
ec2b501e63 | ||
|
8be4f94edf | ||
|
1b6cae1be0 | ||
|
41774b3faf | ||
|
62d44eb15c | ||
|
5f8c73f176 | ||
|
0ae777b4ac | ||
|
087170bdbf | ||
|
93d0caaefb | ||
|
1f031149d3 | ||
|
fc870fd706 | ||
4450f5c0cd | |||
|
478a2df3dc | ||
|
59243d9f94 | ||
|
82b08c5aae | ||
|
615983bf37 | ||
|
21bc2a67a1 | ||
|
52a96d7253 | ||
|
fef4d27d21 | ||
|
603c4c9c46 | ||
|
baee0024e9 | ||
|
1baaf79f8c | ||
|
52f480147e | ||
|
9717c54d53 | ||
|
c271c689de | ||
|
24c27303dd | ||
|
117106a7b3 | ||
|
5680f913ef | ||
|
ebacb72dcb | ||
22ff521d08 | |||
|
32ab198f9e | ||
|
fae26a8f26 | ||
|
bb5a4e8580 | ||
|
000c16b907 | ||
|
663ce36e22 | ||
|
87a2ed8117 | ||
|
a0de7a4467 | ||
|
ce2b4e0303 | ||
|
4886976752 | ||
|
daf684deef | ||
|
0b680f831d | ||
|
41c87e3085 | ||
|
52dd0e6276 | ||
|
bcee5e5209 | ||
|
95e9b2dbda | ||
|
72f27fab7a | ||
|
06bb978cf6 | ||
|
dbe05bb718 | ||
|
9a735e86dd | ||
|
240d57a8ba | ||
dd18c7c40e | |||
|
45ccfb58e3 | ||
|
4ac99b61bf | ||
|
f107c8d1f7 | ||
|
f29faa2680 | ||
161c1a1b53 | |||
6b1a4eddfc | |||
|
ae7a63fbca | ||
79810be94f | |||
|
8870bc326c | ||
|
e1c6369bcb | ||
|
46255efb70 | ||
|
fb77f9192f | ||
|
a71e56ea97 | ||
|
5dfa6769b2 | ||
|
77be216ee5 | ||
|
100db9baac | ||
|
e1f579664a | ||
|
7a9c0a1e69 | ||
|
7e5aa852d7 | ||
|
5d39863cc6 | ||
|
01dd4e57e6 | ||
|
6faffdf90c | ||
|
f4bc057aff | ||
|
78db0f0177 | ||
|
3233ccd845 | ||
|
b0b1426e20 | ||
|
103c7e4b14 | ||
|
3638edfa73 | ||
|
bd98bed5ca | ||
|
6299086297 | ||
|
de5b43d72b | ||
|
7e6dee8e1d | ||
|
dafcd2f125 | ||
|
6a5ababa51 | ||
|
273ddb92d7 | ||
|
4a2b901465 | ||
|
dea3da3b69 | ||
|
13c70148a8 | ||
|
bb5945898a | ||
|
123f94aea7 | ||
|
dff72b0c97 | ||
|
1667b394f2 | ||
|
95943b1627 | ||
|
0315a1f144 | ||
|
52a5fd7904 | ||
|
b5b5b5d9c9 | ||
|
83aaff140c | ||
|
3deaceec01 | ||
|
9862df9e63 | ||
|
9f2702276f | ||
|
87cf674352 | ||
|
dfd6a1f532 | ||
|
e8388e2748 | ||
|
095f9a7956 | ||
|
c4aec8379e | ||
|
ccc16fd22b | ||
|
54cf24926e | ||
|
94d39ee21a | ||
|
725b071d28 | ||
|
284af1246b | ||
|
f453343f1c | ||
|
bb016e6417 | ||
|
831bf1fe17 | ||
|
cba489f279 | ||
|
9f3439a15e | ||
|
356b8a7a34 | ||
|
ab37e1a607 | ||
|
18545cff9a | ||
|
9840281d83 | ||
|
6256bdfe2e | ||
|
6a9db81981 | ||
|
53087a8e04 | ||
|
aa631b5099 | ||
|
a3a02fe475 | ||
|
99ce7c1122 | ||
|
cef82c6359 | ||
|
67fe88215a | ||
|
f31023b4fa | ||
|
a733eee8b5 | ||
|
15f5a2dc76 | ||
|
6fcaafe477 | ||
|
35b99a4095 | ||
|
327f36f1c2 | ||
|
6b57aacef0 | ||
|
f023754328 | ||
|
77aaa0ecb6 | ||
|
9f9a94b5cf | ||
|
b66d06a165 | ||
|
92b110a971 | ||
|
2277f68509 | ||
|
1c0fa6a820 | ||
|
10b5d87119 | ||
|
73c37027d9 | ||
|
8e198679c7 | ||
|
419e4a6d0e | ||
|
5cd2ee7d80 | ||
|
9c35f04a09 | ||
|
89246ece5c | ||
|
d53faa0c86 | ||
|
5270cecec9 | ||
|
87fe51767c | ||
|
f0610aeff1 | ||
|
e4fbd17a55 | ||
|
9c526f20fb | ||
|
1f269918fb | ||
|
2d5c863008 | ||
5a3dcd7100 | |||
1a1ab2696d | |||
9186f5dff5 | |||
5c9b40e0b7 | |||
|
bd0678f362 | ||
a08e2e8815 | |||
47689f2fc6 | |||
b7aca99301 | |||
|
8920b32020 | ||
da41857a4f | |||
09dcdaeb96 | |||
6d0392956d |
3
.gitignore
vendored
@@ -20,3 +20,6 @@ bin
|
||||
.project
|
||||
.settings/
|
||||
/target/
|
||||
|
||||
#
|
||||
manually/
|
||||
|
19
README.md
Normal 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/
|
BIN
Website/JavaTXExamples.zip
Normal file
88
Website/index.html
Normal file
@@ -0,0 +1,88 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<title>Java-TX Plugin</title></head>
|
||||
<center>
|
||||
<h1>Java-TX Plugin</h1>
|
||||
</center>
|
||||
<h2>Content</h2>
|
||||
<ul>
|
||||
<li><h4><a href="#introduction">Introduction</a></h4></li>
|
||||
<li><h4><a href="newJavaTXProject/newJavaTXProject.html" >New Java-TX project</a></h4></li>
|
||||
<li><h4><a href=" JavaTXExamples.zip" >Example project</a></h4></li>
|
||||
<li><a href="usePlugin/usePlugin.html" >Using the plugin</a></li>
|
||||
<li><h4><a href="install/install.html" >Installation</a></h4>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<br/>
|
||||
<h2 id="introduction">Introduction</h2>
|
||||
Java-TX (Java Type eXtended) is an extension of Java in which a global type inference algorithm and real function types are added. Since the end of the nineties features from functional program- ming languages have been transferred to Java. Parametric polymorphism extended by wildcards, called generics, were transfered to Java 5.0. Higher-order functions and lambda expression were introduced in Java 8. Java 8 uses functional interfaces as target types of lambda expressions in contrast to real function types as in functional programming languages.
|
||||
The powerful feature type inference from functional programming languages is incorporated into Java, as into other object-oriented
|
||||
languages, i.e. only in a restricted way called local type inference. Local type inference allows certain type annotations to be omitted. For instance, it is often not necessary to specify the type of a variable. Type parameters of classes in the new-statement can be left out. Return types of methods can often also be omitted. Local type inference is at its most pronounced in Scala. In Java 10 an extention of local type inference is introduced, where types of local variables can be replaced by the keyword var and inferred automatically during the compilation. In contrast to global type inference, local type inference allows types of recursive methods and lambda expressions not to be omitted.<br>
|
||||
The Java-TX project contributes to the design of object-oriented languages by developing global type inference algorithms for Java-like languages.
|
||||
|
||||
<h3>First Example</h3>
|
||||
The class <tt>Id</tt> has the method <tt>id</tt>. The type annotations are omitted.
|
||||
<br/>
|
||||
|
||||
<pre> <code class="language-java">
|
||||
class Id {
|
||||
id(x) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
</code> </pre>
|
||||
The type inference algorithm inferrs the types, such that <tt>Id</tt> can be applied:
|
||||
<pre>
|
||||
new Id().id(1);
|
||||
|
||||
new Id().id("hallo");
|
||||
</pre>
|
||||
|
||||
<h3>More complex example</h3>
|
||||
<pre>
|
||||
import java.lang.Integer;
|
||||
import java.lang.Double;
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
class OL {
|
||||
m(x) { return x + x; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
class OLMain {
|
||||
main(x) {
|
||||
var ol;
|
||||
ol = new OL();
|
||||
return ol.m(x);
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
The type inference mechanism considers only imported types. Therefore <tt>Integer</tt> <tt>Double</tt>, and <tt>String</tt> are imported.
|
||||
<br/>
|
||||
As the operator <tt>+</tt> is overloaded by all numeric types and String the methods <tt>m</tt> in the class <tt>OL</tt> and <tt>main</tt> in the class <tt>OLMain</tt>, respectively, gets all these types. The generated classfile demonstrates this:
|
||||
<pre>
|
||||
> javap OL.class
|
||||
Compiled from "OL.jav"
|
||||
class OL {
|
||||
public OL();
|
||||
public java.lang.Integer m(java.lang.Integer);
|
||||
public java.lang.Double m(java.lang.Double);
|
||||
}
|
||||
|
||||
> javap OLMain.class
|
||||
Compiled from "OLMain.jav"
|
||||
class OLMain {
|
||||
public OLMain();
|
||||
public java.lang.Integer main(java.lang.Integer);
|
||||
public java.lang.Double main(java.lang.Double);
|
||||
}
|
||||
</pre>
|
||||
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start -->Last modified: Fri Jun 1 16:43:55 CEST 2018 <!-- hhmts end -->
|
||||
</body> </html>
|
BIN
Website/install/Restart.png
Normal file
After ![]() (image error) Size: 25 KiB |
BIN
Website/install/availableSoftware1.png
Normal file
After ![]() (image error) Size: 80 KiB |
BIN
Website/install/availableSoftware2.png
Normal file
After ![]() (image error) Size: 109 KiB |
40
Website/install/instal.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<title>Install Java-TX Plugin</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Install Java-TX Plugin</h1>
|
||||
<ol>
|
||||
<li>Select "Install New Software ..."<br>
|
||||
<img width= 400 src="newsoftware.png" >
|
||||
|
||||
</li>
|
||||
<li>Add ...<br>
|
||||
<img width=550 src="availableSoftware1.png" >
|
||||
</li>
|
||||
<li>Insert address<br>
|
||||
<img width=550 src="availableSoftware2.png" >
|
||||
</li>
|
||||
<li>Select installation<br>
|
||||
<img width=550 src="selectInstallation.png" >
|
||||
</li>
|
||||
<li>Installation details<br>
|
||||
<img width=550 src="installationDetails.png" >
|
||||
</li>
|
||||
<li>Accept license agreement<br>
|
||||
<img width=550 src="licenseAgreement.png" >
|
||||
</li>
|
||||
<li>Install anyway<br>
|
||||
<img width=450 src="installAnyway.png">
|
||||
</li>
|
||||
<li>Restart<br>
|
||||
<img width=450 src="Restart.png">
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start -->Last modified: Fri Jun 1 11:57:15 CEST 2018 <!-- hhmts end -->
|
||||
</body> </html>
|
40
Website/install/install.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<title>Install Java-TX Plugin</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Install Java-TX Plugin</h2>
|
||||
<ol>
|
||||
<li>Select "Install New Software ..."<br>
|
||||
<img width= 400 src="newsoftware.png" >
|
||||
|
||||
</li>
|
||||
<li>Add ...<br>
|
||||
<img width=550 src="availableSoftware1.png" >
|
||||
</li>
|
||||
<li>Insert address<br>
|
||||
<img width=550 src="availableSoftware2.png" >
|
||||
</li>
|
||||
<li>Select installation<br>
|
||||
<img width=550 src="selectInstallation.png" >
|
||||
</li>
|
||||
<li>Installation details<br>
|
||||
<img width=550 src="installationDetails.png" >
|
||||
</li>
|
||||
<li>Accept license agreement<br>
|
||||
<img width=550 src="licenseAgreement.png" >
|
||||
</li>
|
||||
<li>Install anyway<br>
|
||||
<img width=450 src="installAnyway.png">
|
||||
</li>
|
||||
<li>Restart<br>
|
||||
<img width=450 src="Restart.png">
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start -->Last modified: Fri Jun 1 12:05:43 CEST 2018 <!-- hhmts end -->
|
||||
</body> </html>
|
BIN
Website/install/installAnyway.png
Normal file
After ![]() (image error) Size: 32 KiB |
BIN
Website/install/installationDetails.png
Normal file
After ![]() (image error) Size: 52 KiB |
BIN
Website/install/licenseAgreement.png
Normal file
After ![]() (image error) Size: 61 KiB |
BIN
Website/install/newsoftware.png
Normal file
After ![]() (image error) Size: 96 KiB |
BIN
Website/install/selectInstallation.png
Normal file
After ![]() (image error) Size: 93 KiB |
BIN
Website/newJavaTXProject/addLibrary2.png
Normal file
After ![]() (image error) Size: 163 KiB |
BIN
Website/newJavaTXProject/buildPath1.png
Normal file
After ![]() (image error) Size: 163 KiB |
BIN
Website/newJavaTXProject/buildPath2.png
Normal file
After ![]() (image error) Size: 88 KiB |
BIN
Website/newJavaTXProject/buildPath3.png
Normal file
After ![]() (image error) Size: 50 KiB |
BIN
Website/newJavaTXProject/buildPath4.png
Normal file
After ![]() (image error) Size: 96 KiB |
BIN
Website/newJavaTXProject/newJavFile.png
Normal file
After ![]() (image error) Size: 102 KiB |
BIN
Website/newJavaTXProject/newJavFolder1.png
Normal file
After ![]() (image error) Size: 100 KiB |
BIN
Website/newJavaTXProject/newJavFolder2.png
Normal file
After ![]() (image error) Size: 76 KiB |
34
Website/newJavaTXProject/newJavaTXProject.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<title></title>
|
||||
</head>
|
||||
<h2>New Java-TX project in eclipse</h2>
|
||||
<ol>
|
||||
<li>New -> Java Project<br/>
|
||||
<img width= 400 src="newJavaTXProject.png" >
|
||||
</li>
|
||||
<br/>
|
||||
<li>Generate a jav-File folder<br/>
|
||||
<img width= 550 src="newJavFolder1.png" ><br/><br/>
|
||||
<img width= 550 src="newJavFolder2.png" >
|
||||
</li>
|
||||
<br/>
|
||||
<li>Add jav-File folder as library<br/>
|
||||
At the moment no package system is implemented, Therefore the compiled class files are in the jav-File folder. This has to be added as library:<br/>
|
||||
<img width= 550 src="buildPath1.png" ><br/><br/>
|
||||
<img width= 550 src="buildPath2.png" ><br/><br/>
|
||||
<img width= 400 src="buildPath3.png" ><br/><br/>
|
||||
<img width= 550 src="buildPath4.png" ><br/>
|
||||
|
||||
|
||||
</li>
|
||||
</ol>
|
||||
<body>
|
||||
<h1></h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start -->Last modified: Fri Jun 1 16:50:02 CEST 2018 <!-- hhmts end -->
|
||||
</body> </html>
|
BIN
Website/newJavaTXProject/newJavaTXProject.png
Normal file
After ![]() (image error) Size: 150 KiB |
24
Website/usePlugin/usePlugin.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<title>Using the plugin</title>
|
||||
</head>
|
||||
<h2>Using the plugin</h2>
|
||||
<ol>
|
||||
<li>Overview<br/>
|
||||
<img width=800 src="usePlugin1.png" >
|
||||
</li>
|
||||
<br/>
|
||||
<li>Select types<br/>
|
||||
If the method is overloaded the user can select types in the outline the right mouse button:<br/><br/>
|
||||
<img src="usePlugin2.png" ><br/>
|
||||
</li>
|
||||
</ol>
|
||||
<body>
|
||||
<h1></h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start -->Last modified: Fri Jun 1 16:51:28 CEST 2018 <!-- hhmts end -->
|
||||
</body> </html>
|
BIN
Website/usePlugin/usePlugin1.png
Normal file
After ![]() (image error) Size: 112 KiB |
BIN
Website/usePlugin/usePlugin2.png
Normal file
After ![]() (image error) Size: 33 KiB |
BIN
doc/Studienarbeiten/S2018_Marcel_Vollmer_Implementierung eines Typinferenzalgorithmus für Strukturelle Typen.pdf
Normal file
95
pom.xml
@@ -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>
|
||||
@@ -42,12 +43,18 @@
|
||||
<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>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<finalName>${artifactId}-${version}</finalName>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>src/</sourceDirectory>
|
||||
<testSourceDirectory>test/</testSourceDirectory>
|
||||
@@ -65,14 +72,78 @@
|
||||
<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>
|
||||
<version>1.1.2-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<!-- specify your depencies here -->
|
||||
<!-- 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>
|
||||
@@ -83,8 +154,28 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>reficio</id>
|
||||
<url>http://repo.reficio.org/maven/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven-repository</id>
|
||||
<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>
|
||||
|
30
src/de/dhbwstuttgart/bytecode/AStatement.java
Normal 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);
|
||||
}
|
||||
}
|
11
src/de/dhbwstuttgart/bytecode/ArgumentExpr.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
11
src/de/dhbwstuttgart/bytecode/AssignStmt.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
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.*;
|
||||
@@ -9,11 +11,14 @@ 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;
|
||||
@@ -23,6 +28,7 @@ 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 {
|
||||
@@ -30,9 +36,10 @@ public class BytecodeGen implements ASTVisitor {
|
||||
ClassWriter cw =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
String type;
|
||||
|
||||
|
||||
String className;
|
||||
private boolean isInterface;
|
||||
private List<ResultSet> listOfResultSets;
|
||||
private ResultSet resultSet;
|
||||
private int indexOfFirstParam = 0;
|
||||
|
||||
@@ -47,16 +54,18 @@ public class BytecodeGen implements ASTVisitor {
|
||||
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()) {
|
||||
System.out.println("in Class: " + cl.getClassName().toString());
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, resultSet);
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
|
||||
cl.accept(classGen);
|
||||
classGen.writeClass(cl.getClassName().toString());
|
||||
}
|
||||
@@ -101,18 +110,27 @@ public class BytecodeGen implements ASTVisitor {
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
// for each field in the class
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,23 +164,40 @@ public class BytecodeGen implements ASTVisitor {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||
/*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)) {
|
||||
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")) {
|
||||
hasGenInParameterList = true;
|
||||
break;
|
||||
}
|
||||
@@ -170,27 +205,31 @@ public class BytecodeGen implements ASTVisitor {
|
||||
}
|
||||
|
||||
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
|
||||
//than create the descriptor with the new syntax.
|
||||
//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);
|
||||
// System.out.println(sig);
|
||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||
System.out.println(methDesc);
|
||||
|
||||
// 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,
|
||||
genericsAndBounds,genericsAndBounds,isInterface,classFiles);
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
9
src/de/dhbwstuttgart/bytecode/IStatement.java
Normal 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);
|
||||
}
|
25
src/de/dhbwstuttgart/bytecode/LoopStmt.java
Normal 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);
|
||||
}
|
||||
}
|
14
src/de/dhbwstuttgart/bytecode/ReturnStmt.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@@ -2,12 +2,12 @@ package de.dhbwstuttgart.bytecode.descriptor;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.MethodFromMethodCall;
|
||||
import de.dhbwstuttgart.bytecode.NormalConstructor;
|
||||
import de.dhbwstuttgart.bytecode.NormalMethod;
|
||||
import de.dhbwstuttgart.bytecode.SamMethod;
|
||||
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;
|
||||
@@ -46,12 +46,19 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
|
||||
desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
// 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+ ";";
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if(((RefType) fp.getType()).getParaList().size() > 0){
|
||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "%").replace("<", "%%").replace(">", "%%")+ ";";
|
||||
// }
|
||||
//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())+ ";";
|
||||
}
|
||||
@@ -67,7 +74,12 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
}else if(method.getGenericsAndBounds().containsKey(ret)){
|
||||
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
||||
}else {
|
||||
desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
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())+ ";";
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package de.dhbwstuttgart.bytecode.descriptor;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.MethodFromMethodCall;
|
||||
import de.dhbwstuttgart.bytecode.NormalConstructor;
|
||||
import de.dhbwstuttgart.bytecode.NormalMethod;
|
||||
import de.dhbwstuttgart.bytecode.SamMethod;
|
||||
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);
|
||||
|
@@ -13,6 +13,8 @@ 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
|
||||
@@ -27,7 +29,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -10,12 +10,10 @@ 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.FormalParameter;
|
||||
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.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
@@ -61,10 +59,7 @@ public class Signature {
|
||||
|
||||
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
|
||||
|
||||
sw.visitFormalTypeParameter("R");
|
||||
// getBounds vom Return-Type
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
// sw.visitClassBound().visitEnd();
|
||||
for(int i = 0;i<numberOfParams;i++) {
|
||||
int j = i+1;
|
||||
sw.visitFormalTypeParameter("T"+ j);
|
||||
@@ -72,6 +67,11 @@ public class Signature {
|
||||
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();
|
||||
@@ -92,7 +92,31 @@ public class Signature {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||
}
|
||||
// visits each method-parameter to create the signature
|
||||
// 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
|
||||
@@ -101,6 +125,15 @@ public class Signature {
|
||||
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);
|
||||
@@ -132,10 +165,16 @@ public class Signature {
|
||||
break;
|
||||
case "TPH":
|
||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||
if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH "))
|
||||
sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
|
||||
// sv.visitClassType(r.acceptTV(new TypeToSignature()));
|
||||
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
||||
// 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)
|
||||
@@ -165,7 +204,7 @@ public class Signature {
|
||||
* @param genAndBounds
|
||||
*/
|
||||
private void getBoundsOfTypeVar(GenericTypeVar g, HashMap<String, String> genAndBounds) {
|
||||
sw.visitFormalTypeParameter(g.getParsedName());
|
||||
sw.visitFormalTypeParameter(g.getName());
|
||||
|
||||
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
||||
while(bItr.hasNext()) {
|
||||
@@ -174,7 +213,7 @@ public class Signature {
|
||||
// System.out.println("GetBounds: " + boundDesc);
|
||||
// Ensure that <...> extends java.lang.Object OR ...
|
||||
sw.visitClassBound().visitClassType(boundDesc);
|
||||
genAndBounds.put(g.getParsedName(), boundDesc);
|
||||
genAndBounds.put(g.getName(), boundDesc);
|
||||
}
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
|
@@ -27,6 +27,8 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
}
|
||||
params += ";>";
|
||||
}
|
||||
// String t = refType.getName().toString().replace(".", "/");
|
||||
// return t.equals("Fun1")?t+"$$"+params+";":t+params+";";
|
||||
return refType.getName().toString().replace(".", "/") + params+";";
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.List;
|
||||
|
@@ -1,133 +1,180 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.Solve;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||
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.interfaces.IFiniteClosure;
|
||||
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.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFile));
|
||||
}
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFile));
|
||||
}
|
||||
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for (File forSourceFile : sourceFiles.keySet())
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||
// FC
|
||||
for (File forSourceFile : sourceFiles.keySet())
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||
// beachtet
|
||||
ClassOrInterface importedClass = ASTFactory
|
||||
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||
// beachtet
|
||||
ClassOrInterface importedClass = ASTFactory
|
||||
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
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(sf.getClasses());
|
||||
}
|
||||
public List<SolvedClass> strucTypeInference()
|
||||
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
|
||||
List<SolvedClass> solvedClasses = new ArrayList<>();
|
||||
for (SourceFile sourceFile : sourceFiles.values()) {
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints();
|
||||
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
|
||||
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
inferredTypes = construct.getInferredTypes();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
IFiniteClosure fc = UnifyTypeFactory.generateFC(this.getAvailableClasses(sourceFile));
|
||||
Solve solve = new Solve(subTypeConstraints, clsA, fc, inferredTypes, constructedInterfaces);
|
||||
SolvedClass solvedClass = solve.getSolvedClass();
|
||||
solvedClasses.add(solvedClass);
|
||||
}
|
||||
return solvedClasses;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
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(sf.getClasses());
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result);
|
||||
results.addAll(result);
|
||||
}
|
||||
return results.stream().map((unifyPairs ->
|
||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||
}
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
if (p.TA1 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
||||
}
|
||||
if (p.TA2 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
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.size());
|
||||
results.addAll(result);
|
||||
}
|
||||
return results.stream()
|
||||
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons)))))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
if (p.TA1 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
||||
}
|
||||
if (p.TA2 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
|
||||
new GenericsRegistry(null));
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
@@ -17,4 +18,9 @@ public class AssignToLocal extends AssignLeftSide {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToLocal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
@@ -11,6 +11,7 @@ import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FCGenerator {
|
||||
/**
|
||||
@@ -19,12 +20,15 @@ public class FCGenerator {
|
||||
*
|
||||
* @param availableClasses - Alle geparsten Klassen
|
||||
*/
|
||||
public static Set<UnifyPair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
||||
HashSet<UnifyPair> pairs = new HashSet<>();
|
||||
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));
|
||||
}
|
||||
System.out.println(pairs);
|
||||
return pairs;
|
||||
}
|
||||
|
||||
@@ -35,67 +39,84 @@ public class FCGenerator {
|
||||
* @param forType
|
||||
* @return
|
||||
*/
|
||||
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
||||
private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
||||
return getSuperTypes(forType, availableClasses, new HashMap<>());
|
||||
}
|
||||
|
||||
//TODO: implements Interface auch als superklassen beachten
|
||||
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, HashMap<String, UnifyType> gtvs) throws ClassNotFoundException {
|
||||
List<UnifyType> params = new ArrayList<>();
|
||||
/**
|
||||
*
|
||||
* @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, UnifyType> newGTVs = new HashMap<>();
|
||||
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.getParsedName())){
|
||||
gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
|
||||
newGTVs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
|
||||
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.getParsedName()));
|
||||
params.add(gtvs.get(gtv.getName()));
|
||||
}
|
||||
|
||||
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny();
|
||||
ClassOrInterface superClass;
|
||||
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
|
||||
{
|
||||
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString()));
|
||||
}else{
|
||||
superClass = hasSuperclass.get();
|
||||
|
||||
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);
|
||||
}
|
||||
/*
|
||||
Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse
|
||||
modifiziert werden
|
||||
Beispie: Matrix<A> extends Vector<Vector<A>>
|
||||
Den ersten Parameter mit Vector<A> austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen
|
||||
*/
|
||||
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
||||
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = forType.getSuperClass().getParaList().iterator();
|
||||
while(itGenParams.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
|
||||
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
|
||||
UnifyType setSetType = setType.acceptTV(new TypeExchanger(gtvs));
|
||||
newGTVs.put(itGenParams.next().getParsedName(), setSetType);
|
||||
}
|
||||
|
||||
UnifyType superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs));
|
||||
|
||||
TypeParams paramList = new TypeParams(params);
|
||||
UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList);
|
||||
UnifyType t2 = superType;
|
||||
|
||||
UnifyPair ret = UnifyTypeFactory.generateSmallerPair(t1, t2);
|
||||
|
||||
List<UnifyPair> superTypes;
|
||||
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
|
||||
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
|
||||
superTypes = Arrays.asList(UnifyTypeFactory.generateSmallerPair(UnifyTypeFactory.convert(ASTFactory.createObjectType()), UnifyTypeFactory.convert(ASTFactory.createObjectType())));
|
||||
}else{
|
||||
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
|
||||
}
|
||||
|
||||
List<UnifyPair> retList = new ArrayList<>();
|
||||
retList.add(ret);
|
||||
retList.addAll(superTypes);
|
||||
|
||||
return retList;
|
||||
}
|
||||
@@ -103,46 +124,43 @@ public class FCGenerator {
|
||||
/**
|
||||
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
|
||||
*/
|
||||
private static class TypeExchanger implements TypeVisitor<UnifyType>{
|
||||
private static class TypeExchanger implements TypeVisitor<RefTypeOrTPHOrWildcardOrGeneric>{
|
||||
|
||||
private final HashMap<String, UnifyType> gtvs;
|
||||
private final HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs;
|
||||
|
||||
TypeExchanger(HashMap<String, UnifyType> gtvs){
|
||||
TypeExchanger(HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs){
|
||||
this.gtvs = gtvs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(RefType refType) {
|
||||
List<UnifyType> params = new ArrayList<>();
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||
params.add(param.acceptTV(this));
|
||||
}
|
||||
TypeParams paramList = new TypeParams(params);
|
||||
UnifyType ret = new ReferenceType(refType.getName().toString(), paramList);
|
||||
RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(SuperWildcardType superWildcardType) {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(TypePlaceholder typePlaceholder) {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(ExtendsWildcardType extendsWildcardType) {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(GenericRefType genericRefType) {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
|
||||
if(! gtvs.containsKey(genericRefType.getParsedName()))
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
//TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf.
|
||||
//return UnifyTypeFactory.convert(ASTFactory.createObjectType());
|
||||
return gtvs.get(genericRefType.getParsedName());
|
||||
}
|
||||
|
||||
|
@@ -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 = "";
|
||||
|
@@ -832,7 +832,7 @@ public class StatementGenerator {
|
||||
}else if(literal.StringLiteral()!=null){
|
||||
RefType type = new RefType(reg.getName("java.lang.String"),literal.getStart());
|
||||
return new Literal(type,
|
||||
literal.StringLiteral().getText(),
|
||||
literal.StringLiteral().getText().substring(1, literal.StringLiteral().getText().length()-1),
|
||||
literal.getStart());
|
||||
}else if(literal.NullLiteral() != null){
|
||||
return new Literal(TypePlaceholder.fresh(literal.getStart()), null,
|
||||
@@ -904,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());
|
||||
}
|
||||
}
|
||||
|
@@ -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());
|
||||
@@ -165,8 +175,8 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
}
|
||||
String className = this.pkgName + (this.pkgName.length()>0?".":"") + ctx.Identifier().getText();
|
||||
JavaClassName name = reg.getName(className);
|
||||
if(! name.toString().equals(className)){
|
||||
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());
|
||||
}
|
||||
@@ -203,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;
|
||||
}
|
||||
@@ -400,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());
|
||||
@@ -417,13 +427,16 @@ public class SyntaxTreeGenerator{
|
||||
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
|
||||
ret.putAll(generics);
|
||||
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
||||
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||
ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod));
|
||||
}
|
||||
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -23,18 +22,20 @@ import java.util.List;
|
||||
public class TypeGenerator {
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
String name;
|
||||
if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
|
||||
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
|
||||
}
|
||||
Java8Parser.TypeArgumentsContext arguments;
|
||||
if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){
|
||||
name = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
|
||||
arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
|
||||
}else{// if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
|
||||
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().getText();
|
||||
arguments = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
|
||||
}
|
||||
/**
|
||||
* Problem sind hier die verschachtelten Typen mit verschachtelten Typargumenten
|
||||
* Beispiel: Typ<String>.InnererTyp<Integer>
|
||||
*/
|
||||
String name = unannClassOrInterfaceTypeContext.getText();
|
||||
if(name.contains("<")){
|
||||
name = name.split("<")[0]; //Der Typ ist alles vor den ersten Argumenten
|
||||
}
|
||||
return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics);
|
||||
}
|
||||
|
||||
@@ -75,8 +76,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());
|
||||
generics.put(name, new GenericContext(parentClass, parentMethod));
|
||||
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class TypeGenerator {
|
||||
return ret;
|
||||
}
|
||||
if(typeBoundContext.classOrInterfaceType() != null){
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType()));
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
|
||||
if(typeBoundContext.additionalBound() != null)
|
||||
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
|
||||
ret.add(convert(addCtx.interfaceType()));
|
||||
@@ -102,8 +102,9 @@ public class TypeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) {
|
||||
throw new NotImplementedException();
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
|
||||
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),classOrInterfaceTypeContext.getStart(), reg, generics);
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
|
||||
@@ -113,10 +114,7 @@ public class TypeGenerator {
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
if(referenceTypeContext.classOrInterfaceType() != null){
|
||||
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
|
||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType();
|
||||
//return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
if(ctx.typeArguments() != null)throw new NotImplementedException();
|
||||
return convertTypeName(referenceTypeContext.getText(), null,referenceTypeContext.getStart(), reg, generics);
|
||||
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -133,7 +131,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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
40
src/de/dhbwstuttgart/sat/asp/ASPStringConverter.java
Normal 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;
|
||||
}
|
||||
}
|
@@ -17,26 +17,32 @@ public class Clingo {
|
||||
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/reduce1.lp"));
|
||||
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce2.lp"));
|
||||
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/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=2"); //use JSON-Output
|
||||
commands.add("--outf=1"); //use JSON-Output
|
||||
for(File file : input){
|
||||
commands.add(file.getPath());
|
||||
}
|
||||
commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList()));
|
||||
|
||||
Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start();
|
||||
InputStream output = clingo.getInputStream();
|
||||
clingo.waitFor();
|
||||
|
26
src/de/dhbwstuttgart/sat/asp/model/ASPGencayRule.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public enum ASPGencayRule {
|
||||
ASP_PAIR_EQUALS_NAME("equals"),
|
||||
ASP_PAIR_SMALLER_NAME("sub"),
|
||||
ASP_PAIR_SMALLER_DOT_NAME("subEq"),
|
||||
ASP_PARAMLIST_NAME("paramEq"),
|
||||
ASP_FC_PARAMLIST_NAME("param"),
|
||||
ASP_PARAMLIST_END_POINTER("null"),
|
||||
ASP_TYPE("typeEq"),
|
||||
ASP_FCTYPE("type"),
|
||||
ASP_TYPE_VAR("var"),
|
||||
ASP_GENERIC_VAR("pph"),
|
||||
ASP_PARAMLIST_ORDER("paramOrder");
|
||||
|
||||
private final String text;
|
||||
|
||||
private ASPGencayRule(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
}
|
@@ -1,16 +1,14 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public enum ASPRule {
|
||||
ASP_GENERIC_TYPE_NAME("genericType"),
|
||||
ASP_PAIR_EQUALS_NAME("equals"),
|
||||
ASP_PAIR_SMALLER_NAME("smaller"),
|
||||
ASP_PAIR_SMALLER_DOT_NAME("smallerDot"),
|
||||
ASP_PARAMLIST_NAME("param"),
|
||||
ASP_PARAMLISTNUMERATION_NAME("paramNum"),
|
||||
ASP_PARAMLIST_END_POINTER("null"),
|
||||
ASP_TYPE("type"),
|
||||
ASP_FCTYPE("type")
|
||||
;
|
||||
ASP_FCTYPE("typeFC"),
|
||||
ASP_TYPE_VAR("typeVar");
|
||||
|
||||
private final String text;
|
||||
|
||||
|
@@ -1,17 +1,231 @@
|
||||
package de.dhbwstuttgart.sat.asp.parser;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
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 java.util.HashSet;
|
||||
import java.util.Set;
|
||||
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;
|
||||
|
||||
public class ASPParser {
|
||||
ResultSet parse(String result){
|
||||
Set<ResultPair> ret = new HashSet<>();
|
||||
for(String pair : result.split(",")){
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return new ResultSet(ret);
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
37
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.g4
Normal file
@@ -0,0 +1,37 @@
|
||||
grammar UnifyResult;
|
||||
|
||||
answer : 'ANSWER' (resultSetRule '.')*;
|
||||
|
||||
resultSetRule :
|
||||
parameter
|
||||
| equals
|
||||
| smaller
|
||||
| typeVar
|
||||
| type
|
||||
| otherRule
|
||||
;
|
||||
|
||||
parameterList : '(' value (',' value)* ')';
|
||||
value : NAME
|
||||
| resultSetRule ;
|
||||
|
||||
parameter : PARAMLIST_NAME parameterList;
|
||||
equals : EQUALS_NAME parameterList;
|
||||
smaller : SMALLER_NAME parameterList;
|
||||
typeVar : TYPEVAR_NAME parameterList;
|
||||
type : TYPE_NAME parameterList;
|
||||
otherRule : NAME parameterList;
|
||||
|
||||
//TODO: Es sollte Regeln für das Result set geben, welche sich nicht mit den anderen überdecken, dann auch nur diese im Result ausgeben
|
||||
PARAMLIST_NAME : 'param';
|
||||
EQUALS_NAME : 'equals';
|
||||
SMALLER_NAME : 'smaller';
|
||||
TYPEVAR_NAME : 'typeVar';
|
||||
TYPE_NAME : 'type';
|
||||
NAME : [a-zA-Z0-9_]+;
|
||||
|
||||
WS : [ \t\r\n\u000C]+ -> skip
|
||||
;
|
||||
LINE_COMMENT
|
||||
: '%' ~[\r\n]* -> skip
|
||||
;
|
23
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResult.tokens
Normal file
@@ -0,0 +1,23 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
PARAMLIST_NAME=6
|
||||
EQUALS_NAME=7
|
||||
SMALLER_NAME=8
|
||||
TYPEVAR_NAME=9
|
||||
TYPE_NAME=10
|
||||
NAME=11
|
||||
WS=12
|
||||
LINE_COMMENT=13
|
||||
'ANSWER'=1
|
||||
'.'=2
|
||||
'('=3
|
||||
','=4
|
||||
')'=5
|
||||
'param'=6
|
||||
'equals'=7
|
||||
'smaller'=8
|
||||
'typeVar'=9
|
||||
'type'=10
|
@@ -0,0 +1,159 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.tree.ErrorNode;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
/**
|
||||
* This class provides an empty implementation of {@link UnifyResultListener},
|
||||
* which can be extended to create a listener which only needs to handle a subset
|
||||
* of the available methods.
|
||||
*/
|
||||
public class UnifyResultBaseListener implements UnifyResultListener {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterAnswer(UnifyResultParser.AnswerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitAnswer(UnifyResultParser.AnswerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterResultSetRule(UnifyResultParser.ResultSetRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitResultSetRule(UnifyResultParser.ResultSetRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterParameterList(UnifyResultParser.ParameterListContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitParameterList(UnifyResultParser.ParameterListContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterValue(UnifyResultParser.ValueContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitValue(UnifyResultParser.ValueContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterParameter(UnifyResultParser.ParameterContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitParameter(UnifyResultParser.ParameterContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterEquals(UnifyResultParser.EqualsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitEquals(UnifyResultParser.EqualsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterSmaller(UnifyResultParser.SmallerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitSmaller(UnifyResultParser.SmallerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterTypeVar(UnifyResultParser.TypeVarContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitTypeVar(UnifyResultParser.TypeVarContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterType(UnifyResultParser.TypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitType(UnifyResultParser.TypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterOtherRule(UnifyResultParser.OtherRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitOtherRule(UnifyResultParser.OtherRuleContext ctx) { }
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterEveryRule(ParserRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitEveryRule(ParserRuleContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void visitTerminal(TerminalNode node) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void visitErrorNode(ErrorNode node) { }
|
||||
}
|
134
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultLexer.java
Normal file
@@ -0,0 +1,134 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
||||
public class UnifyResultLexer extends Lexer {
|
||||
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
|
||||
|
||||
protected static final DFA[] _decisionToDFA;
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
new PredictionContextCache();
|
||||
public static final int
|
||||
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, EQUALS_NAME=7,
|
||||
SMALLER_NAME=8, TYPEVAR_NAME=9, TYPE_NAME=10, NAME=11, WS=12, LINE_COMMENT=13;
|
||||
public static String[] channelNames = {
|
||||
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||
};
|
||||
|
||||
public static String[] modeNames = {
|
||||
"DEFAULT_MODE"
|
||||
};
|
||||
|
||||
public static final String[] ruleNames = {
|
||||
"T__0", "T__1", "T__2", "T__3", "T__4", "PARAMLIST_NAME", "EQUALS_NAME",
|
||||
"SMALLER_NAME", "TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'equals'", "'smaller'",
|
||||
"'typeVar'", "'type'"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, null, null, null, null, null, "PARAMLIST_NAME", "EQUALS_NAME", "SMALLER_NAME",
|
||||
"TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
|
||||
};
|
||||
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #VOCABULARY} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String[] tokenNames;
|
||||
static {
|
||||
tokenNames = new String[_SYMBOLIC_NAMES.length];
|
||||
for (int i = 0; i < tokenNames.length; i++) {
|
||||
tokenNames[i] = VOCABULARY.getLiteralName(i);
|
||||
if (tokenNames[i] == null) {
|
||||
tokenNames[i] = VOCABULARY.getSymbolicName(i);
|
||||
}
|
||||
|
||||
if (tokenNames[i] == null) {
|
||||
tokenNames[i] = "<INVALID>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getTokenNames() {
|
||||
return tokenNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Vocabulary getVocabulary() {
|
||||
return VOCABULARY;
|
||||
}
|
||||
|
||||
|
||||
public UnifyResultLexer(CharStream input) {
|
||||
super(input);
|
||||
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "UnifyResult.g4"; }
|
||||
|
||||
@Override
|
||||
public String[] getRuleNames() { return ruleNames; }
|
||||
|
||||
@Override
|
||||
public String getSerializedATN() { return _serializedATN; }
|
||||
|
||||
@Override
|
||||
public String[] getChannelNames() { return channelNames; }
|
||||
|
||||
@Override
|
||||
public String[] getModeNames() { return modeNames; }
|
||||
|
||||
@Override
|
||||
public ATN getATN() { return _ATN; }
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\17c\b\1\4\2\t\2\4"+
|
||||
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
|
||||
"\13\4\f\t\f\4\r\t\r\4\16\t\16\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\4"+
|
||||
"\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3"+
|
||||
"\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13"+
|
||||
"\3\13\3\13\3\13\3\13\3\f\6\fP\n\f\r\f\16\fQ\3\r\6\rU\n\r\r\r\16\rV\3\r"+
|
||||
"\3\r\3\16\3\16\7\16]\n\16\f\16\16\16`\13\16\3\16\3\16\2\2\17\3\3\5\4\7"+
|
||||
"\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\3\2\5\6\2\62;C\\"+
|
||||
"aac|\5\2\13\f\16\17\"\"\4\2\f\f\17\17\2e\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3"+
|
||||
"\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2"+
|
||||
"\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\3\35"+
|
||||
"\3\2\2\2\5$\3\2\2\2\7&\3\2\2\2\t(\3\2\2\2\13*\3\2\2\2\r,\3\2\2\2\17\62"+
|
||||
"\3\2\2\2\219\3\2\2\2\23A\3\2\2\2\25I\3\2\2\2\27O\3\2\2\2\31T\3\2\2\2\33"+
|
||||
"Z\3\2\2\2\35\36\7C\2\2\36\37\7P\2\2\37 \7U\2\2 !\7Y\2\2!\"\7G\2\2\"#\7"+
|
||||
"T\2\2#\4\3\2\2\2$%\7\60\2\2%\6\3\2\2\2&\'\7*\2\2\'\b\3\2\2\2()\7.\2\2"+
|
||||
")\n\3\2\2\2*+\7+\2\2+\f\3\2\2\2,-\7r\2\2-.\7c\2\2./\7t\2\2/\60\7c\2\2"+
|
||||
"\60\61\7o\2\2\61\16\3\2\2\2\62\63\7g\2\2\63\64\7s\2\2\64\65\7w\2\2\65"+
|
||||
"\66\7c\2\2\66\67\7n\2\2\678\7u\2\28\20\3\2\2\29:\7u\2\2:;\7o\2\2;<\7c"+
|
||||
"\2\2<=\7n\2\2=>\7n\2\2>?\7g\2\2?@\7t\2\2@\22\3\2\2\2AB\7v\2\2BC\7{\2\2"+
|
||||
"CD\7r\2\2DE\7g\2\2EF\7X\2\2FG\7c\2\2GH\7t\2\2H\24\3\2\2\2IJ\7v\2\2JK\7"+
|
||||
"{\2\2KL\7r\2\2LM\7g\2\2M\26\3\2\2\2NP\t\2\2\2ON\3\2\2\2PQ\3\2\2\2QO\3"+
|
||||
"\2\2\2QR\3\2\2\2R\30\3\2\2\2SU\t\3\2\2TS\3\2\2\2UV\3\2\2\2VT\3\2\2\2V"+
|
||||
"W\3\2\2\2WX\3\2\2\2XY\b\r\2\2Y\32\3\2\2\2Z^\7\'\2\2[]\n\4\2\2\\[\3\2\2"+
|
||||
"\2]`\3\2\2\2^\\\3\2\2\2^_\3\2\2\2_a\3\2\2\2`^\3\2\2\2ab\b\16\2\2b\34\3"+
|
||||
"\2\2\2\6\2QV^\3\b\2\2";
|
||||
public static final ATN _ATN =
|
||||
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
|
||||
static {
|
||||
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
|
||||
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
|
||||
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
PARAMLIST_NAME=6
|
||||
EQUALS_NAME=7
|
||||
SMALLER_NAME=8
|
||||
TYPEVAR_NAME=9
|
||||
TYPE_NAME=10
|
||||
NAME=11
|
||||
WS=12
|
||||
LINE_COMMENT=13
|
||||
'ANSWER'=1
|
||||
'.'=2
|
||||
'('=3
|
||||
','=4
|
||||
')'=5
|
||||
'param'=6
|
||||
'equals'=7
|
||||
'smaller'=8
|
||||
'typeVar'=9
|
||||
'type'=10
|
@@ -0,0 +1,110 @@
|
||||
// Generated from UnifyResult.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.sat.asp.parser.antlr;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
/**
|
||||
* This interface defines a complete listener for a parse tree produced by
|
||||
* {@link UnifyResultParser}.
|
||||
*/
|
||||
public interface UnifyResultListener extends ParseTreeListener {
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#answer}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterAnswer(UnifyResultParser.AnswerContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#answer}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitAnswer(UnifyResultParser.AnswerContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#resultSetRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterResultSetRule(UnifyResultParser.ResultSetRuleContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#resultSetRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitResultSetRule(UnifyResultParser.ResultSetRuleContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#parameterList}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterParameterList(UnifyResultParser.ParameterListContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#parameterList}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitParameterList(UnifyResultParser.ParameterListContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#value}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterValue(UnifyResultParser.ValueContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#value}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitValue(UnifyResultParser.ValueContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#parameter}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterParameter(UnifyResultParser.ParameterContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#parameter}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitParameter(UnifyResultParser.ParameterContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#equals}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterEquals(UnifyResultParser.EqualsContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#equals}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitEquals(UnifyResultParser.EqualsContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#smaller}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterSmaller(UnifyResultParser.SmallerContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#smaller}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitSmaller(UnifyResultParser.SmallerContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#typeVar}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterTypeVar(UnifyResultParser.TypeVarContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#typeVar}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitTypeVar(UnifyResultParser.TypeVarContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#type}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterType(UnifyResultParser.TypeContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#type}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitType(UnifyResultParser.TypeContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link UnifyResultParser#otherRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterOtherRule(UnifyResultParser.OtherRuleContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link UnifyResultParser#otherRule}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitOtherRule(UnifyResultParser.OtherRuleContext ctx);
|
||||
}
|
639
src/de/dhbwstuttgart/sat/asp/parser/antlr/UnifyResultParser.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.parser.model;
|
||||
|
||||
public class ParsedASPStatement {
|
||||
public ParsedASPStatement(String statement){
|
||||
|
||||
}
|
||||
}
|
12
src/de/dhbwstuttgart/sat/asp/parser/model/ParsedType.java
Normal 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;
|
||||
}
|
||||
}
|
127
src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java
Normal file
@@ -0,0 +1,127 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ASPFactory implements TypeVisitor<String>{
|
||||
|
||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException{
|
||||
ASPFactory factory = new ASPFactory();
|
||||
factory.convertFC(fcClasses);
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
for(Pair p : constraint){
|
||||
factory.convertPair(p);
|
||||
}
|
||||
}
|
||||
|
||||
return factory.writer.getASPFile();
|
||||
}
|
||||
|
||||
ASPWriter writer = new ASPWriter();
|
||||
boolean isFCType = false;
|
||||
|
||||
private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
|
||||
Set<Pair> fc = FCGenerator.toFC(classes);
|
||||
isFCType = true;
|
||||
for(Pair fcp : fc){
|
||||
convertPair(fcp);
|
||||
}
|
||||
isFCType = false;
|
||||
}
|
||||
|
||||
private void convertPair(Pair p){
|
||||
String ls = p.TA1.acceptTV(this);
|
||||
String rs = p.TA2.acceptTV(this);
|
||||
ASPStatement pairStmt = null;
|
||||
if(p.GetOperator().equals(PairOperator.SMALLERDOT)){
|
||||
pairStmt = makeStatement(ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)){
|
||||
pairStmt = makeStatement(ASPRule.ASP_PAIR_EQUALS_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
|
||||
pairStmt = makeStatement(ASPRule.ASP_PAIR_SMALLER_NAME.toString(), ls, rs);
|
||||
}else throw new NotImplementedException();
|
||||
writer.add(pairStmt);
|
||||
}
|
||||
|
||||
private ASPStatement makeStatement(String rule, String... params){
|
||||
String stmt = rule + "(";
|
||||
for(String param : params){
|
||||
stmt += param + ",";
|
||||
}
|
||||
stmt = stmt.substring(0,stmt.length()-1);
|
||||
stmt += ")";
|
||||
return new ASPStatement(stmt);
|
||||
}
|
||||
|
||||
private String convertParameterlist(List<String> pointers){
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
Iterator<String> it = pointers.iterator();
|
||||
String p = pointer;
|
||||
if(!it.hasNext()){
|
||||
return ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
}
|
||||
while (it.hasNext()){
|
||||
ASPStatement stmt;
|
||||
String type = it.next();
|
||||
String nextP = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
if(it.hasNext()){
|
||||
stmt = makeStatement(ASPRule.ASP_PARAMLIST_NAME.toString(), p, type, nextP);
|
||||
}else{
|
||||
stmt = makeStatement(ASPRule.ASP_PARAMLIST_NAME.toString(), p, type,
|
||||
ASPRule.ASP_PARAMLIST_END_POINTER.toString());
|
||||
}
|
||||
p = nextP;
|
||||
writer.add(stmt);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
List<String> params = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||
params.add(param.acceptTV(this));
|
||||
}
|
||||
String typeName = ASPStringConverter.toConstant(refType.getName());
|
||||
String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString();
|
||||
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, convertParameterlist(params));
|
||||
writer.add(stmt);
|
||||
return pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
String name = ASPStringConverter.toConstant(typePlaceholder.getName());
|
||||
ASPStatement stmt = makeStatement(ASPRule.ASP_TYPE_VAR.toString(), name);
|
||||
writer.add(stmt);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
264
src/de/dhbwstuttgart/sat/asp/writer/ASPGencayFactory.java
Normal file
@@ -0,0 +1,264 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPGencayRule;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class ASPGencayFactory implements TypeVisitor<String> {
|
||||
/* TODO:
|
||||
* Alle TPHs müssen als var(tph) definiert sein
|
||||
* Wenn es eine Variable ist, dann direkt in die type-Regel schreiben: type(p, type, tph)
|
||||
* Für die FCTypen eindeutige Namen für die pph-Regeln
|
||||
* (ergibt sich von selbst, weil man einfach den Namen der TPH in der FC verwenden kann)
|
||||
* paramOrder wird benötigt!
|
||||
* Nur bei parameterlisten > 1
|
||||
* paramOrder(paralistPointer, parameter, num)
|
||||
* (ähnlich meiner paramNum)
|
||||
* Trennung von FC und Eq:
|
||||
* sub -> type -> param
|
||||
* ...Eq -> typeEq -> paramEq
|
||||
* type..(_,_,_p): p kann sein:
|
||||
* 1. Variable
|
||||
* 2. ParameterPointer
|
||||
* 3. null
|
||||
*/
|
||||
ASPWriter writer = new ASPWriter();
|
||||
boolean isFCType = false;
|
||||
|
||||
private static List<ASPStatement> generateVar(ConstraintSet<Pair> constraints){
|
||||
List<ASPStatement> ret = new ArrayList<>();
|
||||
for(TypePlaceholder tph : getInvolvedTPHS(constraints)){
|
||||
ret.add(makeStatement(ASPGencayRule.ASP_TYPE_VAR.toString(),
|
||||
ASPStringConverter.toConstant(tph.getName())));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected static Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
|
||||
List<TypePlaceholder> ret = new ArrayList<>();
|
||||
toTest.map((Pair p)-> {
|
||||
ret.addAll(p.TA1.acceptTV(new TPHExtractor()));
|
||||
ret.addAll(p.TA2.acceptTV(new TPHExtractor()));
|
||||
return p;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String generateASP(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException{
|
||||
ASPGencayFactory factory = new ASPGencayFactory();
|
||||
factory.convertFC(fcClasses);
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
for(Pair p : constraint){
|
||||
factory.convertPair(p);
|
||||
}
|
||||
}
|
||||
factory.writer.addAll(generateVar(constraints));
|
||||
|
||||
return factory.writer.getASPFile();
|
||||
}
|
||||
|
||||
private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
|
||||
Set<Pair> fc = FCGenerator.toFC(classes);
|
||||
isFCType = true;
|
||||
for(Pair fcp : fc){
|
||||
generateTheta((RefType) fcp.TA1);
|
||||
generateTheta((RefType) fcp.TA2);
|
||||
convertPair(fcp);
|
||||
}
|
||||
isFCType = false;
|
||||
}
|
||||
|
||||
private void generateTheta(RefType t){
|
||||
String rule = "theta"+t.getParaList().size() ;
|
||||
String name = ASPStringConverter.toConstant(t.getName());
|
||||
writer.add(makeStatement(rule, name));
|
||||
}
|
||||
|
||||
private void convertPair(Pair p){
|
||||
String ls = p.TA1.acceptTV(this);
|
||||
String rs = p.TA2.acceptTV(this);
|
||||
ASPStatement pairStmt = null;
|
||||
if(p.GetOperator().equals(PairOperator.SMALLERDOT)){
|
||||
pairStmt = makeStatement(ASPGencayRule.ASP_PAIR_SMALLER_DOT_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)){
|
||||
pairStmt = makeStatement(ASPGencayRule.ASP_PAIR_EQUALS_NAME.toString(), ls, rs);
|
||||
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
|
||||
pairStmt = makeStatement(ASPGencayRule.ASP_PAIR_SMALLER_NAME.toString(), ls, rs);
|
||||
}else throw new NotImplementedException();
|
||||
writer.add(pairStmt);
|
||||
}
|
||||
|
||||
private static ASPStatement makeStatement(String rule, String... params){
|
||||
String stmt = rule + "(";
|
||||
for(String param : params){
|
||||
stmt += param + ",";
|
||||
}
|
||||
stmt = stmt.substring(0,stmt.length()-1);
|
||||
stmt += ")";
|
||||
return new ASPStatement(stmt);
|
||||
}
|
||||
|
||||
private String convertParameterlist(List<String> pointers){
|
||||
//if(pointers.size()==1)return pointers.get(0);
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
Iterator<String> it = pointers.iterator();
|
||||
String p = pointer;
|
||||
String paramname = ASPGencayRule.ASP_PARAMLIST_NAME.toString();
|
||||
if(this.isFCType)paramname = ASPGencayRule.ASP_FC_PARAMLIST_NAME.toString();
|
||||
if(!it.hasNext()){
|
||||
return ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
}
|
||||
while (it.hasNext()){
|
||||
ASPStatement stmt;
|
||||
String type = it.next();
|
||||
String nextP = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
if(it.hasNext()){
|
||||
stmt = makeStatement(paramname, p, type, nextP);
|
||||
}else{
|
||||
stmt = makeStatement(paramname, p, type,
|
||||
ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString());
|
||||
}
|
||||
p = nextP;
|
||||
writer.add(stmt);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
//Wird zum erstellen der pph(..) Regeln gebraucht
|
||||
private String currentFCTypePointer = "";
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
currentFCTypePointer = pointer;
|
||||
String paramPointer = ASPGencayRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
if(refType.getParaList().size() == 1 ){
|
||||
if(refType.getParaList().get(0) instanceof TypePlaceholder){
|
||||
TypePlaceholder typePlaceholder = (TypePlaceholder) refType.getParaList().get(0);
|
||||
paramPointer = typePlaceholder.acceptTV(this);
|
||||
}
|
||||
}else{
|
||||
List<String> params = null;
|
||||
params = generateParameter(refType);
|
||||
params.remove(0);
|
||||
paramPointer = convertParameterlist(params);
|
||||
if(refType.getParaList().size()>1){
|
||||
//paramOrder generieren:
|
||||
for(String param : params) {
|
||||
ASPStatement pOstmt = makeStatement(ASPGencayRule.ASP_PARAMLIST_ORDER.toString(),
|
||||
paramPointer, param);
|
||||
writer.add(pOstmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
String typeName = ASPStringConverter.toConstant(refType.getName());
|
||||
String ruleName = isFCType? ASPGencayRule.ASP_FCTYPE.toString(): ASPGencayRule.ASP_TYPE.toString();
|
||||
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, paramPointer);
|
||||
writer.add(stmt);
|
||||
return pointer;
|
||||
/*
|
||||
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
|
||||
List<String> params = null;
|
||||
params = generateParameter(refType);
|
||||
params.remove(0); //Das erste ist der eigentliche Typ kein parameter
|
||||
String typeName = ASPStringConverter.toConstant(refType.getName());
|
||||
String ruleName = isFCType? ASPGencayRule.ASP_FCTYPE.toString(): ASPGencayRule.ASP_TYPE.toString();
|
||||
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, convertParameterlist(params));
|
||||
writer.add(stmt);
|
||||
return pointer;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt die Parameterliste, wobei type auch schon als Parameter betrachtet wird.
|
||||
* Die RefTypes werden nicht zu extra type-Regeln umgewandelt. Es wird nur ihr Name als Konstante benutzt
|
||||
* Das funktioniert, weil nacher das ParamOrder zuteilt, welche Typen zusammenhängen.
|
||||
* Diese funktion nur verwenden, wenn auch ein paramOrder generiert wird
|
||||
*/
|
||||
private List<String> generateParameter(RefType type){
|
||||
List<String> ret = new ArrayList<>();
|
||||
ret.add(ASPStringConverter.toConstant(type.getName()));
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : type.getParaList()){
|
||||
if(param instanceof RefType){
|
||||
ret.addAll(generateParameter((RefType) param));
|
||||
}else if(param instanceof TypePlaceholder){
|
||||
ret.add(param.acceptTV(this));
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
String name = ASPStringConverter.toConstant(typePlaceholder.getName());
|
||||
|
||||
ASPStatement stmt = null;
|
||||
if(isFCType){
|
||||
stmt = makeStatement(ASPGencayRule.ASP_GENERIC_VAR.toString(),
|
||||
currentFCTypePointer, name);
|
||||
} else {
|
||||
stmt = makeStatement(ASPGencayRule.ASP_TYPE_VAR.toString(), name);
|
||||
}
|
||||
|
||||
writer.add(stmt);
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static class TPHExtractor implements TypeVisitor<List<TypePlaceholder>>{
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(RefType refType) {
|
||||
ArrayList<TypePlaceholder> ret = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||
ret.addAll(param.acceptTV(this));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(SuperWildcardType superWildcardType) {
|
||||
return superWildcardType.getInnerType().acceptTV(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(TypePlaceholder typePlaceholder) {
|
||||
return Arrays.asList(typePlaceholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(ExtendsWildcardType extendsWildcardType) {
|
||||
return extendsWildcardType.getInnerType().acceptTV(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypePlaceholder> visit(GenericRefType genericRefType) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.sat.asp.writer.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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPGenerator {
|
||||
ASPWriter writer = new ASPWriter();
|
||||
private final String asp;
|
||||
|
||||
public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses){
|
||||
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){
|
||||
ASPRefType superClass = (ASPRefType) cl.getSuperClass().acceptTV(converter);
|
||||
ASPPairSmaller fcEntry = new ASPPairSmaller(new ASPFCType(convert(cl)), new ASPFCType(superClass), writer);
|
||||
writer.add(new ASPStatement(fcEntry.toASP()));
|
||||
}
|
||||
for(Pair cons : constraintSet){
|
||||
writer.add(new ASPStatement(convert(cons).toASP()));
|
||||
}
|
||||
|
||||
return writer.getASPFile();
|
||||
}
|
||||
|
||||
private ASPPair convert(Pair pair){
|
||||
TypeConverter converter = new TypeConverter();
|
||||
ASPType ls = pair.TA1.acceptTV(converter);
|
||||
ASPType rs = pair.TA2.acceptTV(converter);
|
||||
if(pair.OperatorEqual()){
|
||||
return new ASPPairEquals(ls, rs,writer);
|
||||
}else if(pair.OperatorSmallerDot()){
|
||||
return new ASPPairSmallerDot(ls, rs, writer);
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ASPRefType 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
public class ASPStatement {
|
||||
private final String stmt;
|
@@ -1,8 +1,8 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPWriter {
|
||||
|
||||
@@ -19,4 +19,8 @@ public class ASPWriter {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void addAll(Collection<ASPStatement> aspStatements) {
|
||||
content.addAll(aspStatements);
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public class ASPFCType extends ASPRefType {
|
||||
public ASPFCType(ASPRefType refType){
|
||||
super(refType.name, refType.params);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASPRule.ASP_FCTYPE + "(" + name +"," + params.name + ")";
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
|
||||
public class ASPGenericType implements ASPType{
|
||||
private final String name;
|
||||
|
||||
public ASPGenericType(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public abstract class ASPPair {
|
||||
public final ASPType leftSide;
|
||||
public final ASPType rightSide;
|
||||
|
||||
public ASPPair(ASPType ls, ASPType rs, ASPWriter writer){
|
||||
this.leftSide = ls;
|
||||
this.rightSide = rs;
|
||||
writer.add(new ASPStatement(ls.toASP()));
|
||||
writer.add(new ASPStatement(rs.toASP()));
|
||||
}
|
||||
|
||||
public String toASP(){
|
||||
return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")";
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return toASP();
|
||||
}
|
||||
|
||||
protected abstract String getRuleName();
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public class ASPPairEquals extends ASPPair{
|
||||
public ASPPairEquals(ASPType ls, ASPType rs, ASPWriter writer){
|
||||
super(ls, rs, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASPRule.ASP_PAIR_EQUALS_NAME.toString();
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ASPPairSmaller extends ASPPair{
|
||||
public ASPPairSmaller(ASPFCType ls, ASPFCType rs, ASPWriter writer){
|
||||
super(ls, rs, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASPRule.ASP_PAIR_SMALLER_NAME.toString();
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
|
||||
public class ASPPairSmallerDot extends ASPPair{
|
||||
public ASPPairSmallerDot(ASPType ls, ASPType rs, ASPWriter writer){
|
||||
super(ls, rs, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString();
|
||||
}
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPParameterList {
|
||||
public final String name;
|
||||
private final List<ASPType> types;
|
||||
|
||||
public ASPParameterList(List<ASPType> types, ASPWriter writer){
|
||||
int paramNum = 0;
|
||||
this.types = types;
|
||||
if(types.size() == 0){
|
||||
name = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
}else{
|
||||
name = newName();
|
||||
String nextPointer = name;
|
||||
Iterator<ASPType> it = types.iterator();
|
||||
while(it.hasNext()){
|
||||
ASPType t = it.next();
|
||||
String param = nextPointer + "," + t.toString() + ",";
|
||||
nextPointer = newName();
|
||||
if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString();
|
||||
param += nextPointer;
|
||||
writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")"));
|
||||
writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")"));
|
||||
paramNum++;
|
||||
//paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String newName() {
|
||||
return ASPGenerator.toConstant(NameGenerator.makeNewName());
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRule;
|
||||
|
||||
public class ASPRefType implements ASPType {
|
||||
protected final ASPParameterList params;
|
||||
protected final String name;
|
||||
|
||||
public ASPRefType(String name, ASPParameterList params){
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public ASPParameterList getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
public interface ASPType {
|
||||
String toASP();
|
||||
|
||||
String getPointer();
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.writer.model;
|
||||
|
||||
public class ASPTypeVar implements ASPType{
|
||||
private final String name;
|
||||
|
||||
public ASPTypeVar(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "typeVar("+ name +")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toASP() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointer() {
|
||||
return name;
|
||||
}
|
||||
}
|
158
src/de/dhbwstuttgart/strucTypes/Construct.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.IllegalInterfaceTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class Construct extends DefaultASTVisitor {
|
||||
|
||||
private Set<SubTypeConstraint> subTypeConstraints = new HashSet<>();
|
||||
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
||||
private Set<RefTypeOrTPHOrWildcardOrGeneric> newInterf = new HashSet<>();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
private List<ClassOrInterface> constructedInterfaces = new ArrayList<>();
|
||||
|
||||
public Construct(ConstraintsSet constraintsSet, InferredTypes inferredTypes) throws ImpossibleSubTypeException {
|
||||
this.constraintsSet = constraintsSet;
|
||||
this.inferredTypes = inferredTypes;
|
||||
this.gatherSubTypeConstraints(constraintsSet);
|
||||
for (SubTypeConstraint constraint : this.subTypeConstraints) {
|
||||
constraint.checkConstraintPossible();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getConstructedInterfaces() {
|
||||
this.newInterf.forEach(i -> i.accept(this));
|
||||
return constructedInterfaces;
|
||||
}
|
||||
|
||||
public InferredTypes getInferredTypes() {
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||
this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes));
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
// public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs() {
|
||||
// return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet());
|
||||
// }
|
||||
|
||||
private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) {
|
||||
this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints());
|
||||
constraintsSet.getFieldConstraints().forEach(fc -> this.newInterf.add(fc.getClassType()));
|
||||
constraintsSet.getMethodConstraints().forEach(mc -> {
|
||||
this.subTypeConstraints.addAll(mc.getArguments());
|
||||
this.newInterf.add(mc.getClassType());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
JavaClassName name = new JavaClassName( typePlaceholder.getName());
|
||||
this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name));
|
||||
}
|
||||
|
||||
// check nur TPH in newInterf
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
throw new IllegalInterfaceTypeException(
|
||||
String.format("%s is not a valid type to generate an interface for.", refType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
System.out.println(String.format("%s is not a valid type to generate an interface for.", genericRefType));
|
||||
}
|
||||
|
||||
private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) {
|
||||
List<Field> fielddecl = new ArrayList<>();
|
||||
List<Method> methods = new ArrayList<>();
|
||||
List<GenericTypeVar> generics = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> parameterInhTyterm = new ArrayList<>();
|
||||
final Token offset = new NullToken();
|
||||
|
||||
// Schleife <20>ber alle FieldConstraints mit ClassType i
|
||||
this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
// Typ f<>r field: GenericRefType
|
||||
GenericRefType grt = new GenericRefType(tph.getName(), offset);
|
||||
parameterInhTyterm.add(fc.getFieldType());
|
||||
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
|
||||
Field field = new Field(fc.getFieldName(), grt, Modifier.PUBLIC, offset);
|
||||
fielddecl.add(field);
|
||||
});
|
||||
|
||||
// Schleife <20>ber alle MethodConstraints mit ClassType i
|
||||
this.constraintsSet.getMethodConstraints().stream().filter(mc -> mc.getClassType().equals(i)).forEach(mc -> {
|
||||
TypePlaceholder returnType = TypePlaceholder.fresh(offset);
|
||||
parameterInhTyterm.add(mc.getReturnType());
|
||||
generics.add(new GenericTypeVar(returnType.getName(), new ArrayList<>(), offset, offset));
|
||||
Block block = new Block(new ArrayList<>(), offset);
|
||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset);
|
||||
List<FormalParameter> params = new ArrayList<>();
|
||||
mc.getArguments().stream().map(a -> a.getSupertype()).forEach(supertype -> {
|
||||
// Typ f<>r argument: GenericRefType
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
GenericRefType grt = new GenericRefType(tph.getName(), offset);
|
||||
params.add(new FormalParameter("arg" + tph.getName(), grt, offset));
|
||||
parameterInhTyterm.add(supertype);
|
||||
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
|
||||
});
|
||||
ParameterList parameterList = new ParameterList(params, offset);
|
||||
// returnType f<>r method: GenericRefType
|
||||
Method method = new Method(Modifier.PUBLIC, mc.getMethodName(),
|
||||
new GenericRefType(returnType.getName(), offset), parameterList, block, gtvDeclarations, offset);
|
||||
methods.add(method);
|
||||
});
|
||||
|
||||
RefType inh_tyterm = new RefType(name, parameterInhTyterm, offset);
|
||||
TypePlaceholder x = TypePlaceholder.fresh(offset);
|
||||
this.subTypeConstraints.add(new SubTypeConstraint(x, inh_tyterm));
|
||||
this.inferredTypes.put(i, x);
|
||||
|
||||
final int modifiers = Modifier.PUBLIC;
|
||||
final RefType superClass = this.createSuperClass();
|
||||
final boolean isInterface = true;
|
||||
final List<Constructor> constructors = new ArrayList<>();
|
||||
final List<RefType> implementedInterfaces = new ArrayList<>();
|
||||
GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset());
|
||||
ClassOrInterface constructedInterface = new ClassOrInterface(modifiers, name, fielddecl, methods, constructors,
|
||||
genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
|
||||
return constructedInterface;
|
||||
}
|
||||
|
||||
private RefType createSuperClass() {
|
||||
JavaClassName name = new JavaClassName(Object.class.getName());
|
||||
GenericDeclarationList genericsOfClass = new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
||||
return ClassOrInterface.generateTypeOfClass(name, genericsOfClass, new NullToken());
|
||||
}
|
||||
|
||||
}
|
182
src/de/dhbwstuttgart/strucTypes/RuleSetStrucType.java
Normal file
@@ -0,0 +1,182 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class RuleSetStrucType extends RuleSet {
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeReduce(UnifyPair pair) {
|
||||
return super.reduce2(pair);
|
||||
}
|
||||
|
||||
public Optional<UnifyPair> strucTypeAdapt1(UnifyPair pair, IFiniteClosure fc) {
|
||||
return super.adapt(pair, fc);
|
||||
}
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeAdapt2(Set<UnifyPair> pairs, IFiniteClosure fc) {
|
||||
// Filter SMALLERDOT Pairs
|
||||
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
|
||||
.collect(Collectors.toSet());
|
||||
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
|
||||
for (UnifyPair pair : pairsSmallerDot) {
|
||||
// check outerLeftPair pair has Form (D<theta.1,..,theta.n> <. TPH S1)
|
||||
UnifyType typeD = pair.getLhsType();
|
||||
if (!(pair.getRhsType() instanceof PlaceholderType) || !(typeD instanceof ReferenceType)) {
|
||||
continue;
|
||||
}
|
||||
// filter potential outer Pairs for Linking
|
||||
pairsSmallerDot.stream()
|
||||
// check outerRightPair p has Form (TPH Sn <. D'<theta'.1,...,theta'.m>)
|
||||
.filter(p -> (p.getLhsType() instanceof PlaceholderType)
|
||||
&& (p.getRhsType() instanceof ReferenceType))
|
||||
.filter(p -> {
|
||||
UnifyType typeD1 = p.getRhsType();
|
||||
// check not(D<theta.1,..,theta.n> <=* D'<theta'.1,..,theta'.m>)
|
||||
if (fc.getAncestors(typeD).contains(typeD1))
|
||||
return false;
|
||||
Optional<UnifyType> opt = fc.getLeftHandedType(typeD.getName());
|
||||
if (!opt.isPresent())
|
||||
return false;
|
||||
|
||||
UnifyType typeDgen = opt.get();
|
||||
Set<UnifyType> greater = fc.getAncestors(typeDgen);
|
||||
opt = greater.stream().filter(x -> x.getName().equals(typeD1.getName())).findAny();
|
||||
// check (D<T1,..,Tn> <=* D'<ty1',...,tym'>)
|
||||
if (!opt.isPresent())
|
||||
return false;
|
||||
// UnifyType typeD1gen = opt.get();
|
||||
return true;
|
||||
}).map(p -> new Pair<>(pair, p)).forEach(tupleOfPotentialLinkings::add);
|
||||
}
|
||||
|
||||
// Build Linking between the Pairs. Empty if no Linking is possible.
|
||||
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
|
||||
UnifyPair outerLeftPair = tuple.getKey();
|
||||
UnifyPair outerRightPair = tuple.getValue();
|
||||
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
|
||||
pairsSmallerDot);
|
||||
if (!opt.isPresent())
|
||||
continue;
|
||||
// Linking has been found
|
||||
UnifyType typeD = outerLeftPair.getLhsType();
|
||||
UnifyType typeD1 = outerRightPair.getRhsType();
|
||||
// present already checked s.o.
|
||||
UnifyType typeDgen = fc.getLeftHandedType(typeD.getName()).get();
|
||||
// present already checked s.o.
|
||||
UnifyType typeD1gen = fc.getAncestors(typeDgen).stream().filter(x -> x.getName().equals(typeD1.getName()))
|
||||
.findAny().get();
|
||||
TypeParams typeDParams = typeD.getTypeParams();
|
||||
TypeParams typeDgenParams = typeDgen.getTypeParams();
|
||||
|
||||
Unifier unifD1gen = Unifier.identity();
|
||||
for (int i = 0; i < typeDParams.size(); i++)
|
||||
unifD1gen.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
|
||||
Optional<Unifier> sigmaopt = new MartelliMontanariUnify().unify(unifD1gen.apply(typeD1gen), typeD);
|
||||
|
||||
if (!sigmaopt.isPresent())
|
||||
continue;
|
||||
// replace outerLeftPair.lhs and outerRightPair.rhs witch new Types
|
||||
Unifier sigma = sigmaopt.get();
|
||||
pairs.remove(outerLeftPair);
|
||||
pairs.remove(outerRightPair);
|
||||
pairs.add(UnifyTypeFactory.generateSmallerDotPair(sigma.apply(typeD), outerLeftPair.getRhsType()));
|
||||
pairs.add(UnifyTypeFactory.generateSmallerDotPair(outerRightPair.getLhsType(), sigma.apply(typeD1)));
|
||||
// TODO pairs.add mit sigma als Pair
|
||||
return Optional.of(pairs);
|
||||
}
|
||||
// No Linking found
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean strucTypeErase1(UnifyPair pair, IFiniteClosure fc) {
|
||||
return super.erase1(pair, fc);
|
||||
}
|
||||
|
||||
public boolean strucTypeErase2(UnifyPair pair) {
|
||||
return super.erase3(pair);
|
||||
}
|
||||
|
||||
public Optional<UnifyPair> strucTypeSwap(UnifyPair pair) {
|
||||
return super.swap(pair);
|
||||
}
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeSubst(Set<UnifyPair> pairs) {
|
||||
return super.subst(pairs);
|
||||
}
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeRefl(Set<UnifyPair> pairs) {
|
||||
// Filter SMALLERDOT Pairs
|
||||
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
|
||||
.collect(Collectors.toSet());
|
||||
// System.out.println("Pairs to test: " + pairsSmallerDot);
|
||||
// Filter Tuples of Pairs for a potential Linking (t<T1,T1<T2,...,Tn<t)
|
||||
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
|
||||
for (UnifyPair pair : pairsSmallerDot) {
|
||||
if (!(pair.getRhsType() instanceof PlaceholderType)) {
|
||||
// System.out.println("Pair not suitable for outerLeftPair: " + pair);
|
||||
continue;
|
||||
}
|
||||
// System.out.println("Try to find tuple of potential linkings for pair " + pair);
|
||||
pairsSmallerDot.stream().filter(p -> {
|
||||
// System.out.println(" Pair pair: " + pair);
|
||||
// System.out.println("Pair p: " + p);
|
||||
// System.out.println("p.lhs instnceof PH: " + (p.getLhsType() instanceof PlaceholderType));
|
||||
// System.out.println("p.rhs equals pair.lhs: " + (p.getRhsType().equals(pair.getLhsType())));
|
||||
return (p.getLhsType() instanceof PlaceholderType) && (p.getRhsType().equals(pair.getLhsType()));
|
||||
}).map(p -> {
|
||||
// System.out.println("Pair to map: " + p);
|
||||
return new Pair<>(pair, p);
|
||||
}).forEach(tupleOfPotentialLinkings::add);
|
||||
// System.out.println("tuple of potential linkings: " + tupleOfPotentialLinkings);
|
||||
}
|
||||
// Build Linking between the Pairs. Empty if no Linking is possible.
|
||||
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
|
||||
UnifyPair outerLeftPair = tuple.getKey();
|
||||
UnifyPair outerRightPair = tuple.getValue();
|
||||
// System.out.println("Try linking pair: " + outerLeftPair + ", " + outerRightPair);
|
||||
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
|
||||
pairsSmallerDot);
|
||||
// Remove Pairs of the Linking incl. outerLeft and outerRight, add
|
||||
// EQUALSDOT Pairs instead.
|
||||
if (opt.isPresent()) {
|
||||
// System.out.println("Linking found: " + opt.get());
|
||||
pairs.remove(outerLeftPair);
|
||||
pairs.remove(outerRightPair);
|
||||
pairs.removeAll(opt.get());
|
||||
// Get all Placeholder in Linking.
|
||||
Set<UnifyType> placeholderInLinking = new HashSet<>();
|
||||
opt.get().forEach(p -> {
|
||||
placeholderInLinking.add(p.getLhsType());
|
||||
placeholderInLinking.add(p.getRhsType());
|
||||
});
|
||||
// Generate and add new EQUALSDOT Pairs of Placeholder and
|
||||
// outermost UnifyType to the result.
|
||||
final UnifyType outermostUnifyType = outerLeftPair.getLhsType();
|
||||
placeholderInLinking.forEach(placeholder -> pairs
|
||||
.add(UnifyTypeFactory.generateEqualDotPair(placeholder, outermostUnifyType)));
|
||||
return Optional.of(pairs);
|
||||
}
|
||||
// System.out.println("No Linking found");
|
||||
}
|
||||
// No Linking was found.
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
129
src/de/dhbwstuttgart/strucTypes/Solve.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class Solve {
|
||||
|
||||
private Set<SubTypeConstraint> constraints = new HashSet<>();
|
||||
private IFiniteClosure fc;
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
private ClassOrInterface clsA;
|
||||
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
|
||||
|
||||
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
|
||||
InferredTypes inferredTypes, List<ClassOrInterface> generatedInterfaces) {
|
||||
this.constraints = constraints;
|
||||
this.fc = fc;
|
||||
this.inferredTypes = inferredTypes;
|
||||
this.clsA = clsA;
|
||||
this.generatedInterfaces = generatedInterfaces;
|
||||
}
|
||||
|
||||
public SolvedClass getSolvedClass() throws InconsistentConstraintsException {
|
||||
Set<UnifyPair> constraintsUnifyPair = this.constraints.stream().map(SubTypeConstraint::getAsUnifyPair)
|
||||
.collect(Collectors.toSet());
|
||||
StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc);
|
||||
Set<UnifyPair> subst = strucTypeUnify.unify();
|
||||
|
||||
Map<String, TypePlaceholder> tphs = this.generateTPHMap(constraints);
|
||||
InferredTypes sigma = new InferredTypes();
|
||||
sigma.putAll(inferredTypes);
|
||||
sigma.putAll(
|
||||
StrucTypeUnifyUtils.convertEqualsdot(
|
||||
subst.stream()
|
||||
.filter(p -> p.getLhsType() instanceof PlaceholderType
|
||||
&& p.getPairOp().equals(PairOperator.EQUALSDOT))
|
||||
.collect(Collectors.toSet()),
|
||||
tphs));
|
||||
|
||||
Set<SubTypeConstraint> cs = StrucTypeUnifyUtils.convertSmallerdot(
|
||||
subst.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp())).collect(Collectors.toSet()),
|
||||
tphs);
|
||||
|
||||
List<GenericTypeVar> values = new ArrayList<>();
|
||||
// extract typeplaceholder (type variables) of clsA
|
||||
TypeVar typeVar = new TypeVar(inferredTypes);
|
||||
clsA.accept(typeVar);
|
||||
final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> bounds = new ArrayList<>();
|
||||
final NullToken offset = new NullToken();
|
||||
// add type variables of clsA as GenericTypeVar to values of
|
||||
// tNew
|
||||
typeVar.getTypeVars().stream().map(tph -> new GenericTypeVar(tph.getName(), bounds, offset, offset))
|
||||
.forEach(gtv -> {
|
||||
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
|
||||
values.add(gtv);
|
||||
};
|
||||
});
|
||||
// add type variables of cs as GenericRefType to values of
|
||||
// tNew
|
||||
cs.stream().flatMap(c -> Stream.of(c.getSubtype(), c.getSupertype())).filter(t -> t instanceof TypePlaceholder)
|
||||
.map(tph -> new GenericTypeVar(((TypePlaceholder) tph).getName(), bounds, offset, offset))
|
||||
.forEach(gtv -> {
|
||||
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
|
||||
values.add(gtv);
|
||||
};
|
||||
});
|
||||
// add generics of all superclasses and superinterfaces of clsA to
|
||||
// values of tNew
|
||||
TypeExtract typeExtract = new TypeExtract();
|
||||
clsA.accept(typeExtract);
|
||||
typeExtract.getGenerics().forEach(gtv -> {
|
||||
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
|
||||
values.add(gtv);
|
||||
};
|
||||
});
|
||||
GenericDeclarationList tNew = new GenericDeclarationList(values, offset);
|
||||
|
||||
if (!consistent(cs)) {
|
||||
throw new InconsistentConstraintsException();
|
||||
}
|
||||
return new SolvedClass(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew,
|
||||
cs, this.generatedInterfaces);
|
||||
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(Set<SubTypeConstraint> constraints) {
|
||||
Map<String, TypePlaceholder> tphs = new HashMap<>();
|
||||
constraints.stream().forEach(c -> {
|
||||
if (c.getSubtype() instanceof TypePlaceholder) {
|
||||
TypePlaceholder subtype = (TypePlaceholder) c.getSubtype();
|
||||
tphs.put(subtype.getName(), subtype);
|
||||
}
|
||||
if (c.getSupertype() instanceof TypePlaceholder) {
|
||||
TypePlaceholder supertype = (TypePlaceholder) c.getSupertype();
|
||||
tphs.put(supertype.getName(), supertype);
|
||||
}
|
||||
});
|
||||
return tphs;
|
||||
}
|
||||
|
||||
private boolean consistent(Set<SubTypeConstraint> cs) {
|
||||
// TODO update inconsistencies
|
||||
return true;
|
||||
}
|
||||
}
|
63
src/de/dhbwstuttgart/strucTypes/StrucTYPE.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TYPEExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class StrucTYPE extends DefaultASTVisitor {
|
||||
|
||||
private ClassOrInterface clsA;
|
||||
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
|
||||
public StrucTYPE(ClassOrInterface clsA) {
|
||||
this.clsA = clsA;
|
||||
}
|
||||
|
||||
public ConstraintsSet getConstraints() {
|
||||
TYPEExpr typeExpr = new TYPEExpr();
|
||||
this.clsA.accept(typeExpr);
|
||||
this.clsA.getMethods().forEach(m -> m.accept(this));
|
||||
this.evaluateTypeExpr(typeExpr);
|
||||
return this.constraintsSet;
|
||||
}
|
||||
|
||||
public InferredTypes getInferredTypes() {
|
||||
return this.inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
// Es gibt nur ein Return Statement
|
||||
Expression retexpr = ((Return) method.block.statements.get(0)).retexpr;
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric methodReturnType = method.getReturnType();
|
||||
RefTypeOrTPHOrWildcardOrGeneric retExprType = retexpr.getType();
|
||||
|
||||
// ordnet dem Methodentyp den Returntyp zu [sigma(Mt)]
|
||||
if (methodReturnType instanceof TypePlaceholder) {
|
||||
this.inferredTypes.put((TypePlaceholder) methodReturnType, retExprType);
|
||||
}
|
||||
if (methodReturnType instanceof RefType && retExprType instanceof TypePlaceholder) {
|
||||
this.inferredTypes.put((TypePlaceholder) retExprType, methodReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluateTypeExpr(TYPEExpr typeExpr) {
|
||||
this.inferredTypes.putAll(typeExpr.getInferredTypes());
|
||||
this.inferredTypes.resolveTransitiveTypes();
|
||||
|
||||
ConstraintsSet constraints = typeExpr.getConstraints();
|
||||
constraints.inferTypes(this.inferredTypes);
|
||||
this.constraintsSet.addConstraintsSet(constraints);
|
||||
}
|
||||
|
||||
}
|
89
src/de/dhbwstuttgart/strucTypes/StrucTypeUnify.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class StrucTypeUnify {
|
||||
|
||||
private Set<UnifyPair> pairs;
|
||||
private IFiniteClosure fc;
|
||||
private RuleSetStrucType rules = new RuleSetStrucType();
|
||||
|
||||
public StrucTypeUnify(Set<UnifyPair> unifyPairs, IFiniteClosure finiteClosure) {
|
||||
this.pairs = unifyPairs;
|
||||
this.fc = finiteClosure;
|
||||
}
|
||||
|
||||
public Set<UnifyPair> unify() {
|
||||
Set<UnifyPair> pairs = this.applyTypeUnificationRules(this.pairs, fc);
|
||||
return pairs;
|
||||
}
|
||||
|
||||
|
||||
private Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> pairs, IFiniteClosure fc) {
|
||||
Set<UnifyPair> resultSet = new HashSet<>();
|
||||
|
||||
LinkedList<UnifyPair> pairQueue = new LinkedList<>();
|
||||
|
||||
pairs.forEach(p -> this.swapAddOrErase(p, fc, pairQueue));
|
||||
|
||||
while (!pairQueue.isEmpty()) {
|
||||
UnifyPair pair = pairQueue.pollFirst();
|
||||
|
||||
// reduce
|
||||
Optional<Set<UnifyPair>> optSet = rules.strucTypeReduce(pair);
|
||||
if (optSet.isPresent()) {
|
||||
optSet.get().forEach(p -> swapAddOrErase(p, fc, pairQueue));
|
||||
continue;
|
||||
}
|
||||
|
||||
// adapt1
|
||||
Optional<UnifyPair> opt = rules.strucTypeAdapt1(pair, fc);
|
||||
|
||||
if (opt.isPresent()) {
|
||||
this.swapAddOrErase(opt.get(), fc, pairQueue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// none of the above rules applied
|
||||
resultSet.add(pair);
|
||||
}
|
||||
|
||||
// adapt2
|
||||
Optional<Set<UnifyPair>> adapt2 = rules.strucTypeAdapt2(resultSet, fc);
|
||||
if(adapt2.isPresent()){
|
||||
resultSet = this.applyTypeUnificationRules(adapt2.get(), fc);
|
||||
}
|
||||
|
||||
// subst
|
||||
Optional<Set<UnifyPair>> subst = rules.strucTypeSubst(resultSet);
|
||||
if(subst.isPresent()){
|
||||
resultSet = this.applyTypeUnificationRules(subst.get(), fc);
|
||||
}
|
||||
|
||||
// refl
|
||||
Optional<Set<UnifyPair>> refl = rules.strucTypeRefl(resultSet);
|
||||
if(refl.isPresent()){
|
||||
resultSet = this.applyTypeUnificationRules(refl.get(), fc);
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
private void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
|
||||
// swap
|
||||
Optional<UnifyPair> opt = rules.strucTypeSwap(pair);
|
||||
UnifyPair unifyPair = opt.isPresent() ? opt.get() : pair;
|
||||
|
||||
// erase
|
||||
if (rules.strucTypeErase1(unifyPair, fc) || rules.strucTypeErase2(unifyPair))
|
||||
return;
|
||||
collection.add(unifyPair);
|
||||
}
|
||||
}
|
66
src/de/dhbwstuttgart/strucTypes/StrucTypeUnifyUtils.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class StrucTypeUnifyUtils {
|
||||
|
||||
public static Optional<Set<UnifyPair>> linkPairs(UnifyPair outerLeft, UnifyPair outerRight,
|
||||
Collection<UnifyPair> pairs) {
|
||||
|
||||
Set<UnifyPair> resultLinking = new HashSet<>();
|
||||
|
||||
if (outerLeft.getRhsType().equals(outerRight.getLhsType())) {
|
||||
resultLinking.add(outerLeft);
|
||||
return Optional.of(resultLinking);
|
||||
}
|
||||
|
||||
List<UnifyPair> nextLinks = pairs.stream().filter(p -> outerLeft.getRhsType().equals(p.getLhsType()))
|
||||
.collect(Collectors.toList());
|
||||
for (UnifyPair nextLink : nextLinks) {
|
||||
Optional<Set<UnifyPair>> opt = linkPairs(nextLink, outerRight, pairs);
|
||||
if (opt.isPresent()) {
|
||||
resultLinking = opt.get();
|
||||
resultLinking.add(nextLink);
|
||||
return Optional.of(resultLinking);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static InferredTypes convertEqualsdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
|
||||
InferredTypes inferredTypes = new InferredTypes();
|
||||
if (!pairs.stream().allMatch(
|
||||
p -> PairOperator.EQUALSDOT.equals(p.getPairOp()) && p.getLhsType() instanceof PlaceholderType)) {
|
||||
throw new IllegalArgumentException("Not all UnifyPairs were EQUALSDOT pairs.");
|
||||
}
|
||||
for (UnifyPair pair : pairs) {
|
||||
TypePlaceholder lhs = (TypePlaceholder) UnifyTypeFactory.convert(pair.getLhsType(), tphs);
|
||||
RefTypeOrTPHOrWildcardOrGeneric rhs = UnifyTypeFactory.convert(pair.getRhsType(), tphs);
|
||||
inferredTypes.put(lhs, rhs);
|
||||
}
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
public static Set<SubTypeConstraint> convertSmallerdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
|
||||
if (!pairs.stream().allMatch(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))) {
|
||||
throw new IllegalArgumentException("Not all UnifyPairs were SMALLERDOT pairs.");
|
||||
}
|
||||
return pairs.stream().map(p -> new SubTypeConstraint(UnifyTypeFactory.convert(p.getLhsType(), tphs),
|
||||
UnifyTypeFactory.convert(p.getRhsType(), tphs))).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
|
||||
public class ConstraintsSet {
|
||||
|
||||
private Set<SubTypeConstraint> subTypeConstraints;
|
||||
private Set<FieldConstraint> fieldConstraints;
|
||||
private Set<MethodConstraint> methodConstraints;
|
||||
|
||||
public ConstraintsSet() {
|
||||
this.subTypeConstraints = new HashSet<>();
|
||||
this.fieldConstraints = new HashSet<>();
|
||||
this.methodConstraints = new HashSet<>();
|
||||
}
|
||||
|
||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
public Set<FieldConstraint> getFieldConstraints() {
|
||||
return fieldConstraints;
|
||||
}
|
||||
|
||||
public Set<MethodConstraint> getMethodConstraints() {
|
||||
return methodConstraints;
|
||||
}
|
||||
|
||||
public void addConstraint(SubTypeConstraint constraint) {
|
||||
this.subTypeConstraints.add(constraint);
|
||||
}
|
||||
|
||||
public void addConstraint(FieldConstraint constraint) {
|
||||
this.fieldConstraints.add(constraint);
|
||||
}
|
||||
|
||||
public void addConstraint(MethodConstraint constraint) {
|
||||
this.methodConstraints.add(constraint);
|
||||
}
|
||||
|
||||
public void addConstraintsSet(ConstraintsSet constraintsSet) {
|
||||
constraintsSet.getSubTypeConstraints().forEach(this::addConstraint);
|
||||
constraintsSet.getFieldConstraints().forEach(this::addConstraint);
|
||||
constraintsSet.getMethodConstraints().forEach(this::addConstraint);
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
this.subTypeConstraints.forEach(c -> c.inferTypes(inferredTypes));
|
||||
this.fieldConstraints.forEach(c -> c.inferTypes(inferredTypes));
|
||||
this.methodConstraints.forEach(c -> c.inferTypes(inferredTypes));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/**
|
||||
* fc(c, f, c') : Klasse/Typ c hat ein Feld f mit Typ c'
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class FieldConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric classType;
|
||||
private String fieldName;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric fieldType;
|
||||
|
||||
public FieldConstraint(RefTypeOrTPHOrWildcardOrGeneric classType, String fieldName,
|
||||
RefTypeOrTPHOrWildcardOrGeneric fieldType) {
|
||||
this.classType = classType;
|
||||
this.fieldName = fieldName;
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getClassType() {
|
||||
return classType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
// if (inferredTypes.containsKey(classType)) {
|
||||
// this.classType = inferredTypes.get(classType);
|
||||
// }
|
||||
// if (inferredTypes.containsKey(fieldType)) {
|
||||
// this.fieldType = inferredTypes.get(fieldType);
|
||||
// }
|
||||
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||
classType = classType.accept(inferTypes);
|
||||
fieldType = fieldType.accept(inferTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("F(%s, %s, %s)", this.classType, this.fieldName, this.fieldType);
|
||||
}
|
||||
|
||||
}
|
114
src/de/dhbwstuttgart/strucTypes/constraint/MethodConstraint.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* mc(c, m, C, (c', C')) : Klasse/Typ c hat Methode m mit Argumenten von Typ C
|
||||
* mit R<>ckgabewert c' und Subtyp-Constraints C <. C' wobei C = {c1,... , cn)
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class MethodConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric classType;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
private String methodName;
|
||||
private List<SubTypeConstraint> arguments;
|
||||
|
||||
public MethodConstraint(RefTypeOrTPHOrWildcardOrGeneric classType, String methodName,
|
||||
List<SubTypeConstraint> arguments, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||
this.classType = classType;
|
||||
this.returnType = returnType;
|
||||
this.methodName = methodName;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getClassType() {
|
||||
return classType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public List<SubTypeConstraint> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public void addArguments(SubTypeConstraint... subTypeConstraints) {
|
||||
for (SubTypeConstraint subTypeConstraint : subTypeConstraints) {
|
||||
this.arguments.add(subTypeConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
public void addArguments(RefTypeOrTPHOrWildcardOrGeneric... parameters) {
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric parameter : parameters) {
|
||||
Token offset = parameter.getOffset();
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
SubTypeConstraint subTypeConstraint = new SubTypeConstraint(parameter, tph);
|
||||
this.arguments.add(subTypeConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
// if (inferredTypes.containsKey(classType)) {
|
||||
// this.classType = inferredTypes.get(classType);
|
||||
// }
|
||||
// if (inferredTypes.containsKey(returnType)) {
|
||||
// this.returnType = inferredTypes.get(returnType);
|
||||
// }
|
||||
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||
classType = classType.accept(inferTypes);
|
||||
returnType = returnType.accept(inferTypes);
|
||||
arguments.forEach(c -> c.inferTypes(inferredTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("M(");
|
||||
sb.append(this.classType);
|
||||
sb.append(", ");
|
||||
sb.append(this.methodName);
|
||||
sb.append(", [");
|
||||
List<SubTypeConstraint> arguments = this.arguments;
|
||||
if (!arguments.isEmpty()) {
|
||||
Iterator<SubTypeConstraint> iterator = arguments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric subtype = iterator.next().getSubtype();
|
||||
sb.append(subtype.toString());
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("],(");
|
||||
sb.append(this.returnType);
|
||||
sb.append(", [");
|
||||
if (!arguments.isEmpty()) {
|
||||
Iterator<SubTypeConstraint> iterator = arguments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric supertype = iterator.next().getSupertype();
|
||||
sb.append(supertype.toString());
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("]))");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
/**
|
||||
* c <. c' : c ist subtyp von c'
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class SubTypeConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric subtype;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric supertype;
|
||||
|
||||
public SubTypeConstraint(RefTypeOrTPHOrWildcardOrGeneric subtype, RefTypeOrTPHOrWildcardOrGeneric supertype) {
|
||||
this.subtype = subtype;
|
||||
this.supertype = supertype;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSubtype() {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSupertype() {
|
||||
return supertype;
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
// if (inferredTypes.containsKey(subtype)) {
|
||||
// this.subtype = inferredTypes.get(subtype);
|
||||
// }
|
||||
// if (inferredTypes.containsKey(supertype)) {
|
||||
// this.supertype = inferredTypes.get(supertype);
|
||||
// }
|
||||
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||
subtype = subtype.accept(inferTypes);
|
||||
supertype = supertype.accept(inferTypes);
|
||||
}
|
||||
|
||||
|
||||
public boolean checkConstraintPossible() throws ImpossibleSubTypeException {
|
||||
if (this.subtype instanceof RefType && this.supertype instanceof RefType) {
|
||||
Class<?> subClass = this.createClass(((RefType) this.subtype).getName().toString());
|
||||
Class<?> superClass = this.createClass(((RefType) this.supertype).getName().toString());
|
||||
if (subClass != null && superClass != null) {
|
||||
if (superClass.isAssignableFrom(subClass))
|
||||
return true;
|
||||
else
|
||||
throw new ImpossibleSubTypeException(
|
||||
String.format("%s ist kein subtyp von %s", subClass.getName(), superClass.getName()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public UnifyPair getAsUnifyPair(){
|
||||
UnifyType tl = UnifyTypeFactory.convert(this.subtype);
|
||||
UnifyType tr = UnifyTypeFactory.convert(this.supertype);
|
||||
return UnifyTypeFactory.generateSmallerDotPair(tl, tr);
|
||||
}
|
||||
|
||||
private Class<?> createClass(String name) {
|
||||
try {
|
||||
return ClassLoader.getSystemClassLoader().loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((subtype == null) ? 0 : subtype.hashCode());
|
||||
result = prime * result + ((supertype == null) ? 0 : supertype.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SubTypeConstraint other = (SubTypeConstraint) obj;
|
||||
if (subtype == null) {
|
||||
if (other.subtype != null)
|
||||
return false;
|
||||
} else if (!subtype.equals(other.subtype))
|
||||
return false;
|
||||
if (supertype == null) {
|
||||
if (other.supertype != null)
|
||||
return false;
|
||||
} else if (!supertype.equals(other.supertype))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s <* %s", this.subtype, this.supertype);
|
||||
}
|
||||
|
||||
}
|
503
src/de/dhbwstuttgart/strucTypes/diagram/Trans.ucls
Normal file
@@ -0,0 +1,503 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.2" icons="false" always-add-relationships="false" generalizations="true" realizations="true"
|
||||
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<class id="1" language="java" name="de.dhbwstuttgart.strucTypes.StrucTYPE" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="136" y="291"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="2" language="java" name="de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/ConstraintsSet.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="593" y="277"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="3" language="java" name="de.dhbwstuttgart.strucTypes.model.InferredTypes" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/model/InferredTypes.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="626" y="450"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="4" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TYPEExpr" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TYPEExpr.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="242" y="464"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="5" language="java" name="de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/DefaultASTVisitor.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="601" y="86"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="6" language="java" name="de.dhbwstuttgart.strucTypes.Construct" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/Construct.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="1019" y="494"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="7" language="java" name="de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/SubTypeConstraint.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="220" x="1088" y="164"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="8" language="java" name="de.dhbwstuttgart.strucTypes.exception.IllegalInterfaceTypeException"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/IllegalInterfaceTypeException.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="218" x="1151" y="371"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="9" language="java" name="de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/ImpossibleSubTypeException.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="218" x="1156" y="472"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="10" language="java" name="de.dhbwstuttgart.strucTypes.Solve" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/Solve.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="587" y="685"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<interface id="11" language="java" name="de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="665" y="849"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</interface>
|
||||
<class id="12" language="java" name="de.dhbwstuttgart.strucTypes.StrucTypeUnify" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTypeUnify.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="334" y="859"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="13" language="java" name="de.dhbwstuttgart.strucTypes.StrucTypeUnifyUtils" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTypeUnifyUtils.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="315" y="642"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="14" language="java" name="de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/InconsistentConstraintsException.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="1241" y="600"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="15" language="java" name="de.dhbwstuttgart.strucTypes.model.SolvedClass" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="782" y="572"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="16" language="java" name="de.dhbwstuttgart.strucTypes.visitor.InferTypes" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/InferTypes.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="864" y="690"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="17" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TypeExtract" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="198" x="-2" y="553"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="18" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TypeVar" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TypeVar.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="198" x="-2" y="640"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="19" language="java" name="de.dhbwstuttgart.typeinference.unify.model.UnifyPair" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="292" y="767"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="20" language="java" name="de.dhbwstuttgart.strucTypes.constraint.FieldConstraint" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/FieldConstraint.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="862" y="72"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="21" language="java" name="de.dhbwstuttgart.strucTypes.constraint.MethodConstraint" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/MethodConstraint.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="1110" y="77"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<interface id="22" language="java" name="de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor"
|
||||
project="JavaTXcompiler" file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="198" x="1031" y="703"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</interface>
|
||||
<association id="23">
|
||||
<end type="SOURCE" refId="1" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="24" name="constraintsSet"/>
|
||||
<multiplicity id="25" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="26">
|
||||
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="27" name="fieldConstraints"/>
|
||||
<multiplicity id="28" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="20" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="29">
|
||||
<end type="SOURCE" refId="4"/>
|
||||
<end type="TARGET" refId="17"/>
|
||||
</dependency>
|
||||
<generalization id="30">
|
||||
<end type="SOURCE" refId="1"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<generalization id="31">
|
||||
<end type="SOURCE" refId="4"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<generalization id="32">
|
||||
<end type="SOURCE" refId="17"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<association id="33">
|
||||
<end type="SOURCE" refId="15" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="34" name="constraints"/>
|
||||
<multiplicity id="35" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="36">
|
||||
<end type="SOURCE" refId="4" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="37" name="constraints"/>
|
||||
<multiplicity id="38" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="39">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="13"/>
|
||||
</dependency>
|
||||
<dependency id="40">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="9"/>
|
||||
</dependency>
|
||||
<association id="41">
|
||||
<end type="SOURCE" refId="17" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="42" name="grtToTphMap"/>
|
||||
<multiplicity id="43" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="44">
|
||||
<end type="SOURCE" refId="7"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<association id="45">
|
||||
<end type="SOURCE" refId="17" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="46" name="subTypeConstraints"/>
|
||||
<multiplicity id="47" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="48">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="18"/>
|
||||
</dependency>
|
||||
<association id="49">
|
||||
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="50" name="subTypeConstraints"/>
|
||||
<multiplicity id="51" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="52">
|
||||
<end type="SOURCE" refId="21" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="53" name="arguments"/>
|
||||
<multiplicity id="54" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="55">
|
||||
<end type="SOURCE" refId="4"/>
|
||||
<end type="TARGET" refId="7"/>
|
||||
</dependency>
|
||||
<association id="56">
|
||||
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="57" name="subTypeConstraints"/>
|
||||
<multiplicity id="58" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="59">
|
||||
<end type="SOURCE" refId="21"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<dependency id="60">
|
||||
<end type="SOURCE" refId="21"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<dependency id="61">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="12"/>
|
||||
</dependency>
|
||||
<dependency id="62">
|
||||
<end type="SOURCE" refId="20"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<association id="63">
|
||||
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="64" name="fc"/>
|
||||
<multiplicity id="65" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="11" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<generalization id="66">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<association id="67">
|
||||
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="68" name="inferredTypes"/>
|
||||
<multiplicity id="69" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="70">
|
||||
<end type="SOURCE" refId="1"/>
|
||||
<end type="TARGET" refId="4"/>
|
||||
</dependency>
|
||||
<association id="71">
|
||||
<end type="SOURCE" refId="4" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="72" name="inferredTypes"/>
|
||||
<multiplicity id="73" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="74">
|
||||
<end type="SOURCE" refId="2"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<association id="75">
|
||||
<end type="SOURCE" refId="3" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="76" name="EMPTY"/>
|
||||
<multiplicity id="77" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="78">
|
||||
<end type="SOURCE" refId="13"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<dependency id="79">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<dependency id="80">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="8"/>
|
||||
</dependency>
|
||||
<association id="81">
|
||||
<end type="SOURCE" refId="1" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="82" name="inferredTypes"/>
|
||||
<multiplicity id="83" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="84">
|
||||
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="85" name="inferredTypes"/>
|
||||
<multiplicity id="86" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="87">
|
||||
<end type="SOURCE" refId="18" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="88" name="inferredTypes"/>
|
||||
<multiplicity id="89" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="90">
|
||||
<end type="SOURCE" refId="16" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="91" name="inferredTypes"/>
|
||||
<multiplicity id="92" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="93">
|
||||
<end type="SOURCE" refId="12" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="94" name="fc"/>
|
||||
<multiplicity id="95" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="11" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="96">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="14"/>
|
||||
</dependency>
|
||||
<realization id="97">
|
||||
<end type="SOURCE" refId="16"/>
|
||||
<end type="TARGET" refId="22"/>
|
||||
</realization>
|
||||
<dependency id="98">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="15"/>
|
||||
</dependency>
|
||||
<association id="99">
|
||||
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="100" name="constraintsSet"/>
|
||||
<multiplicity id="101" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="102">
|
||||
<end type="SOURCE" refId="20"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<association id="103">
|
||||
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="104" name="constraints"/>
|
||||
<multiplicity id="105" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="106">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="19"/>
|
||||
</dependency>
|
||||
<association id="107">
|
||||
<end type="SOURCE" refId="12" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="108" name="pairs"/>
|
||||
<multiplicity id="109" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="19" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="110">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="17"/>
|
||||
</dependency>
|
||||
<dependency id="111">
|
||||
<end type="SOURCE" refId="7"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<association id="112">
|
||||
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="113" name="methodConstraints"/>
|
||||
<multiplicity id="114" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="21" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</classifier-display>
|
||||
<association-display labels="true" multiplicity="true"/>
|
||||
</class-diagram>
|
@@ -0,0 +1,27 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class IllegalInterfaceTypeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public IllegalInterfaceTypeException() {
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class ImpossibleSubTypeException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ImpossibleSubTypeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class InconsistentConstraintsException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InconsistentConstraintsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package de.dhbwstuttgart.strucTypes.model;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
public class ClassOrInterfaceFactory {
|
||||
|
||||
public static Optional<ClassOrInterface> createClass(JavaClassName name) {
|
||||
try {
|
||||
return Optional.of(ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static Optional<ClassOrInterface> createClass(RefType refType) {
|
||||
return ClassOrInterfaceFactory.createClass(refType.getName());
|
||||
}
|
||||
}
|