Compare commits
498 Commits
parser
...
unify-Part
Author | SHA1 | Date | |
---|---|---|---|
d33335a6d9 | |||
25b1d3e62d | |||
85a15cb256 | |||
0c03c2fbc8 | |||
db91e73750 | |||
e52181a0c7 | |||
c8daa665f6 | |||
33f2bf3d21 | |||
aa0b157374 | |||
aaae762ca8 | |||
9e1d58f4b1 | |||
7f239d11ee | |||
ca7c76a99a | |||
26634bb038 | |||
9dcb1f76ca | |||
e0da6b3d31 | |||
3c0beabc1b | |||
e83d59d97d | |||
3ad51f952e | |||
449a11f433 | |||
25487469c7 | |||
188ea1f7f8 | |||
cf951043ef | |||
38d4481756 | |||
01891c9513 | |||
aae2e5244b | |||
8c517e7f4a | |||
b3622df2fd | |||
fa42a69374 | |||
eb43a616e2 | |||
faccdf5896 | |||
6de1c50542 | |||
58d757398d | |||
755fd5c821 | |||
c1e4f14fa4 | |||
7d514d617c | |||
4490de575c | |||
752b68d447 | |||
edd263ac15 | |||
d0a261f55c | |||
72a84323de | |||
9e0a6151fd | |||
013539e7e8 | |||
e07b189ba4 | |||
531b484c53 | |||
cbe77d3722 | |||
20abd181b6 | |||
90c0cd431f | |||
f8d3263d24 | |||
ffa30e50c3 | |||
5798c47d62 | |||
f21959fef8 | |||
85fcef8289 | |||
5a3145281e | |||
5624af609c | |||
a4eaaa748e | |||
83b9f7edb8 | |||
b71efd65a0 | |||
e380c77ce6 | |||
794412a402 | |||
f256714223 | |||
1931c61392 | |||
c1a4617085 | |||
a733f373a7 | |||
9dbfbe9e6a | |||
6b33fdc5fb | |||
2f9d44d0b0 | |||
3bf45888e5 | |||
dab0dc180c | |||
2d73b4e47f | |||
54325d5168 | |||
af6537841c | |||
964b73e8c4 | |||
c7c9f65ecf | |||
416d68bcb0 | |||
5c74c69b9e | |||
4da4966b86 | |||
7bfc222037 | |||
a269ee9690 | |||
134496129a | |||
d4b6073760 | |||
2275153590 | |||
95043455fa | |||
2ef7bae78a | |||
0ceae1ebb7 | |||
07c679a598 | |||
74ad081e78 | |||
af93ea4750 | |||
e72310278d | |||
3ce60eec8d | |||
d27e0af57c | |||
0a9e325f54 | |||
ea65a87336 | |||
623705d38a | |||
72fa0978c2 | |||
fc3331d810 | |||
d08708878f | |||
d5d49ad30e | |||
35696efd1c | |||
f0ba7c03b5 | |||
e6387dca6b | |||
5ddc9201f7 | |||
26477b60fb | |||
9bf273ac1a | |||
4ef360e41e | |||
5849cd6f39 | |||
27b73f55e7 | |||
a02e5a16a8 | |||
788ddb2bcc | |||
de08e5830d | |||
7a1ed7ce6f | |||
d4c17053d7 | |||
e6d8b92ffa | |||
d7e59ecdc7 | |||
141194c983 | |||
6dce7058a0 | |||
225f380735 | |||
6a87f443e4 | |||
6ce9f4415e | |||
e3f2e4d793 | |||
3fb95600a0 | |||
94b93c39df | |||
60be47c0f1 | |||
693b47b619 | |||
99bf02606b | |||
2869f07a58 | |||
2be9055608 | |||
0d83ee8505 | |||
f325b04ee2 | |||
56dd759762 | |||
1b7bded3c3 | |||
bda7dcb5c1 | |||
241c7f37d9 | |||
54b4ad97f6 | |||
674233e2f9 | |||
b56f18c16e | |||
8e220b81d5 | |||
8a43839c28 | |||
0594fc7381 | |||
77a952c997 | |||
3c7b1451d4 | |||
ceba60cccb | |||
88e2366eab | |||
334b56234f | |||
4ace3b6f92 | |||
355df5fab7 | |||
85d5485595 | |||
d3d1d658b8 | |||
2add9f518c | |||
f46d26e53f | |||
315b6172a0 | |||
ea3ff69047 | |||
44edc7e9cb | |||
673c249b68 | |||
d165260be0 | |||
aeb8bb92ed | |||
5768783828 | |||
acc7d95060 | |||
50027a9da0 | |||
236afea4f9 | |||
b8741d881b | |||
16ca123780 | |||
654f347450 | |||
c72204428f | |||
1e037a0019 | |||
8759a9cc5d | |||
0ee5a6791d | |||
1a8115bf07 | |||
72e128d3f3 | |||
b70e261b23 | |||
df95c244bf | |||
1061f355ff | |||
4ca671631d | |||
7ee06254f0 | |||
a823ef2b16 | |||
9281786db4 | |||
77d397fc53 | |||
5f89188d00 | |||
6bdd347298 | |||
9b131c48b0 | |||
5e14acfa12 | |||
7d9976e638 | |||
2bbb6e0b6b | |||
6d34ae89ae | |||
9492c43e70 | |||
f18083ba06 | |||
b9aee4da77 | |||
70972a5cbf | |||
f99d4dae5a | |||
dc535ad9b7 | |||
dd8b4f322e | |||
af894ebfe4 | |||
cc676f32c5 | |||
272948f70d | |||
5d0603f423 | |||
3e9e222d73 | |||
d6364040fa | |||
52c445435d | |||
6264d928b2 | |||
89387d2718 | |||
0443f1e528 | |||
34969e66ba | |||
dcbcf873e4 | |||
deb632050a | |||
acf8c108e8 | |||
968dc06edc | |||
47808c4e6f | |||
5029cca0f1 | |||
79eb3135d6 | |||
adf675e595 | |||
f3e60e50ef | |||
30f75f2f17 | |||
4e5c75673d | |||
2421dd0222 | |||
14be882b7b | |||
448d3e04f8 | |||
fe99db81b3 | |||
c3ca4777bb | |||
16b7db9218 | |||
2d5f03a3e0 | |||
fd64b84072 | |||
2a5c727400 | |||
3fedbcc4a0 | |||
4f84e60246 | |||
d373b3dbf8 | |||
7c3ca93c0b | |||
72a4c64c5c | |||
72c2e19def | |||
bd0bfed2cb | |||
80b4f631ed | |||
cee86a6b61 | |||
f1f34a6733 | |||
1a2454e00b | |||
bc1a796e28 | |||
9f53d1fdc2 | |||
69706ee1d2 | |||
b8e229cf3f | |||
e0c5afcd6d | |||
9123e222f4 | |||
29bd9a3f4f | |||
7926c25c7d | |||
b4c604e2b1 | |||
d8bb4d6188 | |||
0ecaf36648 | |||
2eb7a63480 | |||
1991bbbcd3 | |||
b5bc9fa01a | |||
a92521f04a | |||
895b5a972e | |||
11649b39d3 | |||
303cfa5409 | |||
660ef68f7e | |||
23eab0c9a4 | |||
162ca3eb27 | |||
6d70464a1c | |||
1437788f5a | |||
04d3ac84e7 | |||
2db5ecc260 | |||
b325e205a1 | |||
ff2bca5ce5 | |||
c08d4b8457 | |||
d2d02e26f0 | |||
e0d5699ae7 | |||
3f2558d21e | |||
814aef082d | |||
5a0e53485c | |||
1ca7fba835 | |||
98eb1827b8 | |||
ee1fa17aba | |||
66078360da | |||
bb26112a9b | |||
26f24db0a3 | |||
97d893e66b | |||
57fb90afaf | |||
63ac79f02c | |||
07fa62d11d | |||
c7042d185f | |||
7e3fca2da9 | |||
66587a8f71 | |||
ad42282485 | |||
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 | |||
bc2cab8c95 | |||
dca5d21c23 | |||
51a2acdbaf | |||
832623a738 | |||
dcc36f082f | |||
9575afd0b4 | |||
5c797a44a1 | |||
87dbcfdad4 | |||
8048af2106 | |||
e4243b612c | |||
da4c59f2cf | |||
1c22fc7d57 | |||
0b7aea21d9 | |||
521a1cbf3b | |||
22ca2cbd4a | |||
49ea4ee283 | |||
225dc16a89 | |||
4738add4fc | |||
35d5fb2f03 | |||
c8728bab10 | |||
bc99dc4c8b | |||
2bbf9eac36 | |||
a785c85d42 | |||
ec2b501e63 | |||
8be4f94edf | |||
1b6cae1be0 | |||
41774b3faf | |||
62d44eb15c | |||
5f8c73f176 | |||
0ae777b4ac | |||
087170bdbf | |||
93d0caaefb | |||
1f031149d3 | |||
fc870fd706 | |||
4450f5c0cd | |||
92693c2c15 | |||
50a1f979a0 | |||
478a2df3dc | |||
59243d9f94 | |||
82b08c5aae | |||
615983bf37 | |||
f40c82af4a | |||
21bc2a67a1 | |||
52a96d7253 | |||
fef4d27d21 | |||
603c4c9c46 | |||
baee0024e9 | |||
1baaf79f8c | |||
52f480147e | |||
9717c54d53 | |||
c271c689de | |||
24c27303dd | |||
117106a7b3 | |||
5680f913ef | |||
22ff521d08 | |||
32ab198f9e | |||
fae26a8f26 | |||
bb5a4e8580 | |||
000c16b907 | |||
87a2ed8117 | |||
a0de7a4467 | |||
3e829eee54 | |||
7ff3f22db5 | |||
4886976752 | |||
daf684deef | |||
0b680f831d | |||
41c87e3085 | |||
bcee5e5209 | |||
95e9b2dbda | |||
72f27fab7a | |||
06bb978cf6 | |||
dbe05bb718 | |||
9a735e86dd | |||
240d57a8ba | |||
dd18c7c40e | |||
45ccfb58e3 | |||
4ac99b61bf | |||
f107c8d1f7 | |||
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/
|
||||
|
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/PluginBau.pdf
Normal file
24
doc/parser.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Dateien
|
||||
* sämtliche Datein im Ordner de.dhbwstuttgart.parser gehören zum Parser
|
||||
* Auch zu beachten: pom.xml
|
||||
* Ein Teil der pom.xml instruiert maven zur Kompilierung der Java8.g4 Datei
|
||||
* VORSICHT! Wird nicht zwangsläufig von der IDE ausgeführt
|
||||
* siehe Kapitel "Grammatik -> Parser"
|
||||
|
||||
|
||||
## Unterordner antlr
|
||||
* Java8.g4
|
||||
* die eigentliche Java Grammatik
|
||||
* hier wurden Anpassungen vorgenommen, damit sie auch typloses Java annimmt
|
||||
* alle anderen Dateien in diesem Ordner sind vom ANTLR-Parsergenerator autogeneriert
|
||||
|
||||
## Unterordner SyntaxTreeGenerator
|
||||
* SyntaxTreeGenerator
|
||||
* TODO
|
||||
|
||||
# Grammatik -> Parser
|
||||
* Die Antlr-Grammatik (Java8.g4) wandelt
|
||||
* Folgende Stellen sind relevant
|
||||
* TODO
|
||||
|
||||
|
257
pom.xml
@ -1,90 +1,173 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.dhbwstuttgart</groupId>
|
||||
<artifactId>JavaTXcompiler</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.1</version>
|
||||
<name>JavaTXcompiler</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4</artifactId>
|
||||
<version>4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>22.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-all</artifactId>
|
||||
<version>[4.0.0,)</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.dhbwstuttgart</groupId>
|
||||
<artifactId>JavaTXcompiler</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<finalName>${artifactId}-${version}</finalName>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>src/</sourceDirectory>
|
||||
<testSourceDirectory>test/</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>4.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr</id>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
<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>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<version>0.1</version>
|
||||
<name>JavaTXcompiler</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4</artifactId>
|
||||
<version>4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>22.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.11</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>7.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency> <groupId>org.ow2.asm</groupId> <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>${project.artifactId}-${project.version}</finalName>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>4.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr</id>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/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/main/antlr4/sat</sourceDirectory>
|
||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
||||
<arguments>
|
||||
<argument>-package</argument>
|
||||
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<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 -->
|
||||
</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>
|
||||
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
# A basic script to compile the necessary packages and their subpackages to work with the parser.
|
||||
# Messages are logged to stderr.
|
||||
>&2 echo "Building de.dhbwstuttgart.typecheck..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/typecheck/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.factory..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/factory/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.operator..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/operator/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.statement..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/statement/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.statement.literal..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/statement/literal/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.syntaxtree.type..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/syntaxtree/type/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.parser..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/parser/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.parser.SyntaxTreeGenerator..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/parser/SyntaxTreeGenerator/*.java
|
||||
>&2 echo "Building de.dhbwstuttgart.parser.antlr..."
|
||||
javac -d ../bin ./de/dhbwstuttgart/parser/antlr/*.java
|
||||
echo "Done. Now its your turn to debug:)."
|
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
@ -1,440 +0,0 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
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.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
ClassWriter cw =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
String type;
|
||||
|
||||
String className;
|
||||
private boolean isInterface;
|
||||
private ResultSet resultSet;
|
||||
private int indexOfFirstParam = 0;
|
||||
|
||||
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
// stores generics and their bounds of class
|
||||
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
||||
// stores generics and their bounds of method
|
||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||
|
||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||
byte[] bytecode;
|
||||
HashMap<String,byte[]> classFiles;
|
||||
|
||||
public BytecodeGen(HashMap<String,byte[]> classFiles, ResultSet resultSet) {
|
||||
this.classFiles = classFiles;
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
@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);
|
||||
cl.accept(classGen);
|
||||
classGen.writeClass(cl.getClassName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates the bytecode of the class that was build with the classWriter {@link #cw}
|
||||
* with the class name in the map {@link #classFiles}
|
||||
*
|
||||
* @param name name of the class with which the the bytecode is to be associated
|
||||
*/
|
||||
private void writeClass(String name) {
|
||||
bytecode = cw.toByteArray();
|
||||
classFiles.put(name, bytecode);
|
||||
|
||||
}
|
||||
|
||||
public HashMap<String,byte[]> getClassFiles() {
|
||||
return classFiles;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
className = classOrInterface.getClassName().toString();
|
||||
|
||||
cw.visitSource(className +".jav", null);
|
||||
|
||||
isInterface = (classOrInterface.getModifiers()&512)==512;
|
||||
|
||||
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds);
|
||||
sig = signature.toString();
|
||||
}
|
||||
// needs implemented Interfaces?
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
// for each field in the class
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
f.accept(this);
|
||||
}
|
||||
|
||||
for(Constructor c : classOrInterface.getConstructors()) {
|
||||
c.accept(this);
|
||||
}
|
||||
|
||||
for(Method m : classOrInterface.getMethods()) {
|
||||
m.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor field) {
|
||||
field.getParameterList().accept(this);
|
||||
|
||||
String desc = null;
|
||||
boolean hasGen = false;
|
||||
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||
hasGen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String sig = null;
|
||||
if(hasGen) {
|
||||
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes);
|
||||
sig = signature.toString();
|
||||
}
|
||||
NormalConstructor constructor = new NormalConstructor(field,genericsAndBounds,hasGen);
|
||||
desc = constructor.accept(new DescriptorToString(resultSet));
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||
mv.visitCode();
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||
if(!field.getParameterList().iterator().hasNext()) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
// TODO: check if the method is static => if static then the first param will be stored in pos 0
|
||||
// else it will be stored in pos 1 and this will be stored in pos 0
|
||||
method.getParameterList().accept(this);
|
||||
|
||||
String methDesc = null;
|
||||
|
||||
// Method getModifiers() ?
|
||||
int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier;
|
||||
|
||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||
if(!hasGenInParameterList) {
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||
hasGenInParameterList = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
|
||||
//than create the descriptor with the new syntax.
|
||||
|
||||
String sig = null;
|
||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||
|
||||
/* if method has generics or return type is TPH, create signature */
|
||||
if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
|
||||
// resultset hier zum testen
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
||||
sig = signature.toString();
|
||||
}
|
||||
System.out.println(sig);
|
||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||
System.out.println(methDesc);
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
|
||||
|
||||
mv.visitCode();
|
||||
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,cw,
|
||||
genericsAndBounds,genericsAndBounds,isInterface,classFiles);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
paramsAndLocals = new HashMap<>();
|
||||
methodParamsAndTypes = new HashMap<>();
|
||||
Iterator<FormalParameter> itr = formalParameters.iterator();
|
||||
int i = 1;
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
paramsAndLocals.put(fp.getName(), i);
|
||||
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
|
||||
fp.accept(this);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FormalParameter formalParameter) {
|
||||
formalParameter.getType().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
type = "L"+refType.toString()+";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperWildcardType superWildcardType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
// ??
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
|
||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L"+fieldVar.getType()+";", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
|
||||
// access flages?? modifiers
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, field.getName(), "L"+field.getType().toString().replace(".", "/")+";", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
// ???
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericTypeVar genericTypeVar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericDeclarationList genericTypeVars) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
@ -1,660 +0,0 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Handle;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class BytecodeGenMethod implements StatementVisitor{
|
||||
|
||||
private Method m;
|
||||
private MethodVisitor mv;
|
||||
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
private String className;
|
||||
private int lamCounter = -1;
|
||||
private ClassWriter cw;
|
||||
private ResultSet resultSet;
|
||||
private boolean isInterface;
|
||||
HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String,String> genericsAndBounds;
|
||||
private boolean isBinaryExp = false;
|
||||
|
||||
//for tests **
|
||||
private String fieldName;
|
||||
private String fieldDesc;
|
||||
private Expression rightSideTemp;
|
||||
private boolean isRightSideALambda = false;
|
||||
private KindOfLambda kindOfLambda;
|
||||
private HashMap<String, byte[]> classFiles;
|
||||
|
||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||
|
||||
public BytecodeGenMethod(String className,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String,String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||
|
||||
this.className = className;
|
||||
this.resultSet = resultSet;
|
||||
this.m = m;
|
||||
this.mv = mv;
|
||||
this.paramsAndLocals = paramsAndLocals;
|
||||
this.cw = cw;
|
||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
|
||||
if(!isInterface)
|
||||
this.m.block.accept(this);
|
||||
|
||||
}
|
||||
|
||||
public BytecodeGenMethod(LambdaExpression lambdaExpression,ResultSet resultSet ,MethodVisitor mv,
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||
|
||||
this.resultSet = resultSet;
|
||||
this.mv = mv;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
int i = indexOfFirstParamLam;
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
this.paramsAndLocals.put(fp.getName(), i);
|
||||
i++;
|
||||
}
|
||||
lambdaExpression.methodBody.accept(this);
|
||||
}
|
||||
|
||||
private String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
for(Statement stmt : block.getStatements()) {
|
||||
// System.out.println(where);
|
||||
stmt.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
superCall.receiver.accept(this);
|
||||
superCall.arglist.accept(this);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), superCall.name, "()V",isInterface);
|
||||
}
|
||||
|
||||
// ??
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
||||
if(isBinaryExp) {
|
||||
getVlaue(getResolvedType(localVar.getType()));
|
||||
}
|
||||
}
|
||||
// ??
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
// if the right side is a lambda => the left side must be a functional interface
|
||||
if(assign.rightSide instanceof LambdaExpression) {
|
||||
isRightSideALambda = true;
|
||||
}else {
|
||||
isRightSideALambda = false;
|
||||
}
|
||||
|
||||
if(assign.rightSide instanceof BinaryExpr)
|
||||
isBinaryExp = true;
|
||||
|
||||
if(assign.lefSide instanceof AssignToField) {
|
||||
// load_0, ldc or .. then putfield
|
||||
this.rightSideTemp = assign.rightSide;
|
||||
}else {
|
||||
assign.rightSide.accept(this);
|
||||
}
|
||||
if(isBinaryExp) {
|
||||
doAssign(getResolvedType(assign.lefSide.getType()));
|
||||
isBinaryExp = false;
|
||||
}
|
||||
assign.lefSide.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
binary.lexpr.accept(this);
|
||||
binary.rexpr.accept(this);
|
||||
switch (binary.operation.toString()) {
|
||||
case "ADD":
|
||||
mv.visitInsn(Opcodes.IADD);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
this.lamCounter++;
|
||||
|
||||
Lambda lam = new Lambda(lambdaExpression);
|
||||
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
||||
//Call site, which, when invoked, returns an instance of the functional interface to which
|
||||
//the lambda is being converted
|
||||
MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
|
||||
MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
|
||||
|
||||
|
||||
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory",
|
||||
"metafactory", mt.toMethodDescriptorString(), false);
|
||||
String methodName = "lambda$new$" + this.lamCounter;
|
||||
|
||||
// Für die Parameter-Typen und Return-Typ braucht man die Bounds (für die Typlöschung)
|
||||
|
||||
String typeErasure = "(";
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
while(itr.hasNext()) {
|
||||
itr.next();
|
||||
typeErasure += "L"+Type.getInternalName(Object.class) + ";";
|
||||
}
|
||||
|
||||
typeErasure += ")L"+Type.getInternalName(Object.class) + ";";
|
||||
// Type erasure
|
||||
Type arg1 = Type.getMethodType(typeErasure);
|
||||
// Type arg1 = Type.getMethodType(lamDesc);
|
||||
// real Type
|
||||
Type arg3 = Type.getMethodType(lamDesc);
|
||||
|
||||
int staticOrSpecial=0;
|
||||
int staticOrInstance=0;
|
||||
int indexOfFirstParamLam = 0;
|
||||
this.kindOfLambda = new KindOfLambda(lambdaExpression);
|
||||
|
||||
if(kindOfLambda.isInstanceCapturingLambda()) {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
staticOrSpecial = Opcodes.H_INVOKESPECIAL;
|
||||
indexOfFirstParamLam = 1;
|
||||
}else {
|
||||
staticOrSpecial = Opcodes.H_INVOKESTATIC;
|
||||
staticOrInstance = Opcodes.ACC_STATIC;
|
||||
}
|
||||
|
||||
// first check if capturing lambda then invokestatic or invokespecial
|
||||
Handle arg2 = new Handle(staticOrSpecial, this.className, methodName,
|
||||
arg3.toString(),false);
|
||||
// Descriptor of functional interface methode
|
||||
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
||||
// Desc: (this/nothing)TargetType
|
||||
String fiMethodDesc = samMethod.accept(new DescriptorToString(resultSet));
|
||||
mv.visitInvokeDynamicInsn("apply", fiMethodDesc, bootstrap, arg1, arg2,arg3);
|
||||
|
||||
MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE+ staticOrInstance + Opcodes.ACC_SYNTHETIC,
|
||||
methodName, arg3.toString(), null, null);
|
||||
|
||||
new BytecodeGenMethod(lambdaExpression,this.resultSet,mvLambdaBody,indexOfFirstParamLam,isInterface,
|
||||
classFiles);
|
||||
|
||||
mvLambdaBody.visitMaxs(0, 0);
|
||||
mvLambdaBody.visitEnd();
|
||||
cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
|
||||
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL);
|
||||
|
||||
// generateBCForFunN(lambdaExpression,typeErasure);
|
||||
}
|
||||
|
||||
private void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc) {
|
||||
ClassWriter classWriter =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
SignatureWriter methSig = new SignatureWriter();
|
||||
|
||||
int numberOfParams = 0;
|
||||
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
while(itr.hasNext()) {
|
||||
numberOfParams++;
|
||||
// getBounds
|
||||
paramVisitor.visitTypeVariable("T"+numberOfParams);
|
||||
itr.next();
|
||||
}
|
||||
methSig.visitReturnType().visitTypeVariable("R");
|
||||
// ")"+lam.getReturn.getBounds
|
||||
Signature sig = new Signature(lambdaExpression,numberOfParams);
|
||||
String name = "Fun"+numberOfParams;
|
||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_INTERFACE+Opcodes.ACC_ABSTRACT, name,
|
||||
sig.toString(), Type.getInternalName(Object.class), null);
|
||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC+Opcodes.ACC_ABSTRACT, "apply",
|
||||
methDesc, methSig.toString(), null);
|
||||
mvApply.visitEnd();
|
||||
writeClassFile(classWriter.toByteArray(),name);
|
||||
}
|
||||
|
||||
public void writeClassFile(byte[] bytecode, String name) {
|
||||
FileOutputStream output;
|
||||
try {
|
||||
System.out.println("generating "+name+ ".class file...");
|
||||
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/examples/" +name+".class"));
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name+".class file generated");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
|
||||
fieldName = fieldVar.fieldVarName;
|
||||
fieldDesc = "L"+getResolvedType(fieldVar.getType())+";";
|
||||
|
||||
fieldVar.receiver.accept(this);
|
||||
// test (if)
|
||||
if(!fieldVar.receiver.getClass().equals(StaticClassName.class)) {
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD,getResolvedType(fieldVar.receiver.getType()),
|
||||
fieldName ,fieldDesc);
|
||||
}
|
||||
|
||||
// mv.visitFieldInsn(Opcodes.GETSTATIC, fieldVar.receiver.getType().toString().replace(".", "/"),
|
||||
// fieldVar.fieldVarName, fieldVar.getType().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
System.out.println("If");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.arglist.accept(this);
|
||||
|
||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||
genericsAndBoundsMethod,genericsAndBounds);
|
||||
String mDesc = method.accept(new DescriptorToString(resultSet));
|
||||
|
||||
// is methodCall.receiver functional Interface)?
|
||||
if(varsFunInterface.contains(methodCall.receiver.getType())) {
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()),
|
||||
methodCall.name, mDesc, false);
|
||||
}else {
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getResolvedType(methodCall.receiver.getType()),
|
||||
methodCall.name, mDesc, isInterface);
|
||||
}
|
||||
// test
|
||||
// if(!methodCall.getType().toString().equals("V")) {
|
||||
// mv.visitInsn(Opcodes.POP);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
|
||||
mv.visitTypeInsn(Opcodes.NEW, methodCall.name.replace(".", "/"));
|
||||
mv.visitInsn(Opcodes.DUP);
|
||||
// creates Descriptor
|
||||
methodCall.arglist.accept(this);
|
||||
String d = "(";
|
||||
for(Expression e : methodCall.arglist.getArguments()) {
|
||||
d = d + "L"+getResolvedType(e.getType()) + ";";
|
||||
}
|
||||
d += ")V";
|
||||
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, methodCall.name.replace(".", "/"), "<init>", d, isInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver receiver) {
|
||||
receiver.expr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
System.out.println(unaryExpr.operation.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
aReturn.retexpr.accept(this);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
// mv.visitMethodInsn(Opcodes.INVOKESTATIC, staticClassName.getType().toString().replace(".", "/"),
|
||||
// staticClassName.toString(), staticClassName.getType().toString(), false);
|
||||
mv.visitFieldInsn(Opcodes.GETSTATIC, getResolvedType(staticClassName.getType()),
|
||||
fieldName, fieldDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
whileStmt.expr.accept(this);
|
||||
whileStmt.loopBlock.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
Object value = literal.value;
|
||||
String typeOfLiteral = resultSet.resolveType(literal.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(this.isBinaryExp) {
|
||||
getVlaue(typeOfLiteral);
|
||||
}else {
|
||||
doAssign(typeOfLiteral, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void getVlaue(String typeOfLiteral) {
|
||||
switch (typeOfLiteral) {
|
||||
case "java/lang/String":
|
||||
break;
|
||||
case "java/lang/Boolean":
|
||||
break;
|
||||
case "java/lang/Byte":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf",
|
||||
"(B)Ljava/lang/Byte;", false);
|
||||
break;
|
||||
case "java/lang/Short":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf",
|
||||
"(S)Ljava/lang/Short;", false);
|
||||
break;
|
||||
case "java/lang/Integer":
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue",
|
||||
"()I", false);
|
||||
break;
|
||||
case "java/lang/Long":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf",
|
||||
"(J)Ljava/lang/Long;", false);
|
||||
break;
|
||||
case "java/lang/Float":
|
||||
break;
|
||||
case "java/lang/Double":
|
||||
break;
|
||||
case "java/lang/Character":
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void doAssign(String type, Object value) {
|
||||
switch (type) {
|
||||
case "java/lang/String":
|
||||
mv.visitLdcInsn(String.valueOf(value));
|
||||
break;
|
||||
case "java/lang/Boolean":
|
||||
visitBooleanLiteral((Boolean) value);
|
||||
break;
|
||||
case "java/lang/Byte":
|
||||
visitByteLiteral(((Double) value).byteValue(),false);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf",
|
||||
"(B)Ljava/lang/Byte;", false);
|
||||
break;
|
||||
case "java/lang/Short":
|
||||
visitShortLiteral(((Double) value).shortValue(),false);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf",
|
||||
"(S)Ljava/lang/Short;", false);
|
||||
break;
|
||||
case "java/lang/Integer":
|
||||
//zweite Argument isLong
|
||||
visitIntegerLiteral(((Double) value).intValue(), false);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf",
|
||||
"(I)Ljava/lang/Integer;", false);
|
||||
break;
|
||||
case "java/lang/Long":
|
||||
visitLongLiteral(((Double) value).longValue(), true);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf",
|
||||
"(J)Ljava/lang/Long;", false);
|
||||
break;
|
||||
case "java/lang/Float":
|
||||
visitFloatLiteral(((Double) value).floatValue());
|
||||
break;
|
||||
case "java/lang/Double":
|
||||
visitDoubleLiteral((Double) value);
|
||||
break;
|
||||
case "java/lang/Character":
|
||||
visitCharLiteral((Character) value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void doAssign(String type) {
|
||||
switch (type) {
|
||||
case "java/lang/String":
|
||||
break;
|
||||
case "java/lang/Boolean":
|
||||
break;
|
||||
case "java/lang/Byte":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf",
|
||||
"(B)Ljava/lang/Byte;", false);
|
||||
break;
|
||||
case "java/lang/Short":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf",
|
||||
"(S)Ljava/lang/Short;", false);
|
||||
break;
|
||||
case "java/lang/Integer":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf",
|
||||
"(I)Ljava/lang/Integer;", false);
|
||||
break;
|
||||
case "java/lang/Long":
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf",
|
||||
"(J)Ljava/lang/Long;", false);
|
||||
break;
|
||||
case "java/lang/Float":
|
||||
break;
|
||||
case "java/lang/Double":
|
||||
break;
|
||||
case "java/lang/Character":
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void visitCharLiteral(Character value) {
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, (int) value);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf",
|
||||
"(C)Ljava/lang/Character;", false);
|
||||
}
|
||||
|
||||
private void visitDoubleLiteral(Double value) {
|
||||
if(value == 0) {
|
||||
mv.visitInsn(Opcodes.DCONST_0);
|
||||
}else if(value == 1) {
|
||||
mv.visitInsn(Opcodes.DCONST_1);
|
||||
}else {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf",
|
||||
"(D)Ljava/lang/Double;", false);
|
||||
}
|
||||
|
||||
private void visitFloatLiteral(Float value) {
|
||||
if(value.intValue()>-1 && value.intValue() < 3) {
|
||||
//Opcodes.FCONST_0 = 11, Opcodes.FCONST_1 = 12, usw
|
||||
mv.visitInsn(value.intValue()+11);
|
||||
}else {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf",
|
||||
"(F)Ljava/lang/Float;", false);
|
||||
}
|
||||
|
||||
private void visitLongLiteral(Long value, boolean isLong) {
|
||||
if(value<Math.pow(2, 15) || (value>=-Math.pow(2, 15))&&value<-128) {
|
||||
visitShortLiteral(value.shortValue(),isLong);
|
||||
}else {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void visitShortLiteral(Short value,boolean isLong) {
|
||||
if(value< 128 || (value>-129 && value<-1)) {
|
||||
visitByteLiteral(value.byteValue(), isLong);
|
||||
}else if(value<Math.pow(2, 15) || (value>=-Math.pow(2, 15))&&value<-128) {
|
||||
mv.visitIntInsn(Opcodes.SIPUSH, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void visitByteLiteral(Byte value, boolean isLong) {
|
||||
|
||||
if(!isLong && value<6 && value>-1) {
|
||||
//Opcodes.ICONST_0 = 3, Opcodes.ICONST_1 = 4, usw
|
||||
mv.visitInsn(value+3);
|
||||
}else if(isLong && value>-1 && value<2){
|
||||
//Opcodes.LCONST_0 = 9, Opcodes.LCONST_1 = 10
|
||||
mv.visitInsn(value+9);
|
||||
}else {
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void visitIntegerLiteral(Integer value, boolean isLong) {
|
||||
|
||||
if(value<Math.pow(2, 15) || (value>=-Math.pow(2, 15))&&value<-128) {
|
||||
visitShortLiteral(value.shortValue(),isLong);
|
||||
}else {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void visitBooleanLiteral(Boolean b) {
|
||||
if(b) {
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
}else {
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
}
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf",
|
||||
"(Z)Ljava/lang/Boolean;", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
for(Expression al : argumentList.getArguments()) {
|
||||
al.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
// temporäre Lösung für testen, bis ich weiss wie man funktionale
|
||||
// interfaces erkennt
|
||||
if(isRightSideALambda)
|
||||
varsFunInterface.add(assignLeftSide.field.getType());
|
||||
// Loads the an object reference from the local variable
|
||||
// array slot onto the top of the operand stack.
|
||||
assignLeftSide.field.receiver.accept(this);
|
||||
this.rightSideTemp.accept(this);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, getResolvedType(assignLeftSide.field.receiver.getType()),
|
||||
assignLeftSide.field.fieldVarName, getResolvedType(assignLeftSide.field.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
if(isRightSideALambda)
|
||||
varsFunInterface.add(assignLeftSide.localVar.getType());
|
||||
paramsAndLocals.put(assignLeftSide.localVar.name, paramsAndLocals.size()+1);
|
||||
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.size());
|
||||
// Debug:::
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
package de.dhbwstuttgart.bytecode.signature;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.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;
|
||||
|
||||
public class Signature {
|
||||
private ClassOrInterface classOrInterface;
|
||||
private HashMap<String, String> genericsAndBounds;
|
||||
private HashMap<String, String> genericsAndBoundsMethod;
|
||||
private SignatureWriter sw;
|
||||
private Constructor constructor;
|
||||
private Method method;
|
||||
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
||||
private ResultSet resultSet;
|
||||
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds) {
|
||||
this.classOrInterface = classOrInterface;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForClassOrInterface();
|
||||
}
|
||||
|
||||
public Signature(Constructor constructor, HashMap<String, String> genericsAndBounds, HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes) {
|
||||
this.constructor = constructor;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForConsOrMethod(this.constructor,true);
|
||||
}
|
||||
|
||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet) {
|
||||
this.method = method;
|
||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||
this.resultSet = resultSet;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForConsOrMethod(this.method,false);
|
||||
}
|
||||
|
||||
public Signature(LambdaExpression lambdaExpression,int numberOfParams) {
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForFunN(lambdaExpression, numberOfParams);
|
||||
}
|
||||
|
||||
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
|
||||
|
||||
sw.visitFormalTypeParameter("R");
|
||||
// getBounds vom Return-Type
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
for(int i = 0;i<numberOfParams;i++) {
|
||||
int j = i+1;
|
||||
sw.visitFormalTypeParameter("T"+ j);
|
||||
// getBounds von Params
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
// TODO: prüfe ob Return-Type = void,
|
||||
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));;
|
||||
sw.visitEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates signature for a method or constructor with @see {@link SignatureWriter}
|
||||
* Signature looks like:
|
||||
* <typevaliables (K:Ljava/lang/Object "Bounds")>(params L.. OR T.. Or basistape)ReturnType
|
||||
*
|
||||
* @param method method or constructor
|
||||
* @param isConstructor true if constructor
|
||||
*/
|
||||
private void createSignatureForConsOrMethod(Method method, boolean isConstructor) {
|
||||
Iterator<? extends GenericTypeVar> itr = method.getGenerics().iterator();
|
||||
// visits all formal type parameter and visits their bounds <T:...;B:...;...>
|
||||
while(itr.hasNext()) {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||
}
|
||||
// visits each method-parameter to create the signature
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||
// parameter type deswegen ist true
|
||||
doVisitParamsOrReturn(t,true);
|
||||
}
|
||||
if(isConstructor) {
|
||||
sw.visitReturnType().visitBaseType('V');
|
||||
}else {
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
// return type deswegen ist false
|
||||
doVisitParamsOrReturn(returnType, false);
|
||||
}
|
||||
// sw.visitEnd();
|
||||
}
|
||||
/**
|
||||
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
||||
* the method signature
|
||||
* @param t type of parameter or return type
|
||||
* @param isParameterType true if t is type of parameter
|
||||
*/
|
||||
private void doVisitParamsOrReturn(RefTypeOrTPHOrWildcardOrGeneric t, boolean isParameterType) {
|
||||
String type = t.acceptTV(new TypeToString());
|
||||
SignatureVisitor sv;
|
||||
if(isParameterType) {
|
||||
sv = sw.visitParameterType();
|
||||
}
|
||||
else {
|
||||
sv = sw.visitReturnType();
|
||||
}
|
||||
switch (type) {
|
||||
case "RT":
|
||||
sv.visitClassType(t.acceptTV(new TypeToSignature()));
|
||||
break;
|
||||
case "GRT":
|
||||
GenericRefType g = (GenericRefType) t;
|
||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
||||
break;
|
||||
case "TPH":
|
||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||
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()));
|
||||
break;
|
||||
default:
|
||||
if(!isParameterType)
|
||||
sv.visitBaseType('V');
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates signature for class or interface with {@link SignatureWriter}
|
||||
* Signature looks like:
|
||||
* <typevaliables (K:Ljava/lang/Object "Bounds")>superclass
|
||||
*/
|
||||
private void createSignatureForClassOrInterface() {
|
||||
Iterator<GenericTypeVar> itr = classOrInterface.getGenerics().iterator();
|
||||
|
||||
while(itr.hasNext()) {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
||||
}
|
||||
|
||||
sw.visitSuperclass().visitClassType(classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()));;
|
||||
sw.visitEnd();
|
||||
}
|
||||
/**
|
||||
* Get bounds of type variable
|
||||
* @param g type variable
|
||||
* @param genAndBounds
|
||||
*/
|
||||
private void getBoundsOfTypeVar(GenericTypeVar g, HashMap<String, String> genAndBounds) {
|
||||
sw.visitFormalTypeParameter(g.getParsedName());
|
||||
|
||||
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
||||
while(bItr.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric b =bItr.next();
|
||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||
// System.out.println("GetBounds: " + boundDesc);
|
||||
// Ensure that <...> extends java.lang.Object OR ...
|
||||
sw.visitClassBound().visitClassType(boundDesc);
|
||||
genAndBounds.put(g.getParsedName(), boundDesc);
|
||||
}
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package de.dhbwstuttgart.bytecode.signature;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
||||
|
||||
public class TypeToSignature implements TypeVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
// return refType.toString().replace(".", "/");
|
||||
String params = "";
|
||||
if(refType.getParaList().size()>0){
|
||||
params += "<";
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
||||
while(it.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
||||
params += "L"+param.toString().replace(".", "/");
|
||||
if(it.hasNext())params += ";";
|
||||
}
|
||||
params += ";>";
|
||||
}
|
||||
return refType.getName().toString().replace(".", "/") + params+";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
return typePlaceholder.toString().replace(".", "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
return genericRefType.getParsedName().replace(".", "/");
|
||||
}
|
||||
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
|
||||
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.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import 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<>();
|
||||
|
||||
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 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();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result);
|
||||
results.addAll(result);
|
||||
}
|
||||
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,150 +0,0 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FCGenerator {
|
||||
/**
|
||||
* Baut die FiniteClosure aus availableClasses.
|
||||
* Klassen welche nicht in availableClasses vorkommen werden im Java Classpath nachgeschlagen.
|
||||
*
|
||||
* @param availableClasses - Alle geparsten Klassen
|
||||
*/
|
||||
public static Set<UnifyPair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
||||
HashSet<UnifyPair> pairs = new HashSet<>();
|
||||
for(ClassOrInterface cly : availableClasses){
|
||||
pairs.addAll(getSuperTypes(cly, availableClasses));
|
||||
}
|
||||
System.out.println(pairs);
|
||||
return pairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bildet eine Kette vom übergebenen Typ bis hin zum höchsten bekannten Typ
|
||||
* Als Generics werden TPHs benutzt, welche der Unifikationsalgorithmus korrekt interpretieren muss.
|
||||
* Die verwendeten TPHs werden in der Kette nach oben gereicht, so erhält der selbe GTV immer den selben TPH
|
||||
* @param forType
|
||||
* @return
|
||||
*/
|
||||
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
|
||||
return getSuperTypes(forType, availableClasses, new HashMap<>());
|
||||
}
|
||||
|
||||
//TODO: implements Interface auch als superklassen beachten
|
||||
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, HashMap<String, UnifyType> gtvs) throws ClassNotFoundException {
|
||||
List<UnifyType> params = new ArrayList<>();
|
||||
//Die GTVs, die in forType hinzukommen:
|
||||
HashMap<String, UnifyType> newGTVs = new HashMap<>();
|
||||
//Generics mit gleichem Namen müssen den selben TPH bekommen
|
||||
for(GenericTypeVar gtv : forType.getGenerics()){
|
||||
if(!gtvs.containsKey(gtv.getParsedName())){
|
||||
gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
|
||||
newGTVs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder());
|
||||
}
|
||||
params.add(gtvs.get(gtv.getParsedName()));
|
||||
}
|
||||
|
||||
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny();
|
||||
ClassOrInterface superClass;
|
||||
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
|
||||
{
|
||||
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString()));
|
||||
}else{
|
||||
superClass = hasSuperclass.get();
|
||||
}
|
||||
/*
|
||||
Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse
|
||||
modifiziert werden
|
||||
Beispie: Matrix<A> extends Vector<Vector<A>>
|
||||
Den ersten Parameter mit Vector<A> austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen
|
||||
*/
|
||||
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
||||
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = forType.getSuperClass().getParaList().iterator();
|
||||
while(itGenParams.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
|
||||
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
|
||||
UnifyType setSetType = setType.acceptTV(new TypeExchanger(gtvs));
|
||||
newGTVs.put(itGenParams.next().getParsedName(), setSetType);
|
||||
}
|
||||
|
||||
UnifyType superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs));
|
||||
|
||||
TypeParams paramList = new TypeParams(params);
|
||||
UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList);
|
||||
UnifyType t2 = superType;
|
||||
|
||||
UnifyPair ret = UnifyTypeFactory.generateSmallerPair(t1, t2);
|
||||
|
||||
List<UnifyPair> superTypes;
|
||||
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
|
||||
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
|
||||
superTypes = Arrays.asList(UnifyTypeFactory.generateSmallerPair(UnifyTypeFactory.convert(ASTFactory.createObjectType()), UnifyTypeFactory.convert(ASTFactory.createObjectType())));
|
||||
}else{
|
||||
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
|
||||
}
|
||||
|
||||
List<UnifyPair> retList = new ArrayList<>();
|
||||
retList.add(ret);
|
||||
retList.addAll(superTypes);
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
|
||||
*/
|
||||
private static class TypeExchanger implements TypeVisitor<UnifyType>{
|
||||
|
||||
private final HashMap<String, UnifyType> gtvs;
|
||||
|
||||
TypeExchanger(HashMap<String, UnifyType> gtvs){
|
||||
this.gtvs = gtvs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(RefType refType) {
|
||||
List<UnifyType> params = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
|
||||
params.add(param.acceptTV(this));
|
||||
}
|
||||
TypeParams paramList = new TypeParams(params);
|
||||
UnifyType ret = new ReferenceType(refType.getName().toString(), paramList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(SuperWildcardType superWildcardType) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(TypePlaceholder typePlaceholder) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType visit(GenericRefType genericRefType) {
|
||||
if(! gtvs.containsKey(genericRefType.getParsedName()))
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
//TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf.
|
||||
//return UnifyTypeFactory.convert(ASTFactory.createObjectType());
|
||||
return gtvs.get(genericRefType.getParsedName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
ABSTRACT=1
|
||||
ASSERT=2
|
||||
BOOLEAN=3
|
||||
BREAK=4
|
||||
BYTE=5
|
||||
CASE=6
|
||||
CATCH=7
|
||||
CHAR=8
|
||||
CLASS=9
|
||||
CONST=10
|
||||
CONTINUE=11
|
||||
DEFAULT=12
|
||||
DO=13
|
||||
DOUBLE=14
|
||||
ELSE=15
|
||||
ENUM=16
|
||||
EXTENDS=17
|
||||
FINAL=18
|
||||
FINALLY=19
|
||||
FLOAT=20
|
||||
FOR=21
|
||||
IF=22
|
||||
GOTO=23
|
||||
IMPLEMENTS=24
|
||||
IMPORT=25
|
||||
INSTANCEOF=26
|
||||
INT=27
|
||||
INTERFACE=28
|
||||
LONG=29
|
||||
NATIVE=30
|
||||
NEW=31
|
||||
PACKAGE=32
|
||||
PRIVATE=33
|
||||
PROTECTED=34
|
||||
PUBLIC=35
|
||||
RETURN=36
|
||||
SHORT=37
|
||||
STATIC=38
|
||||
STRICTFP=39
|
||||
SUPER=40
|
||||
SWITCH=41
|
||||
SYNCHRONIZED=42
|
||||
THIS=43
|
||||
THROW=44
|
||||
THROWS=45
|
||||
TRANSIENT=46
|
||||
TRY=47
|
||||
VOID=48
|
||||
VOLATILE=49
|
||||
WHILE=50
|
||||
IntegerLiteral=51
|
||||
FloatingPointLiteral=52
|
||||
BooleanLiteral=53
|
||||
CharacterLiteral=54
|
||||
StringLiteral=55
|
||||
NullLiteral=56
|
||||
LPAREN=57
|
||||
RPAREN=58
|
||||
LBRACE=59
|
||||
RBRACE=60
|
||||
LBRACK=61
|
||||
RBRACK=62
|
||||
SEMI=63
|
||||
COMMA=64
|
||||
DOT=65
|
||||
ASSIGN=66
|
||||
GT=67
|
||||
LT=68
|
||||
BANG=69
|
||||
TILDE=70
|
||||
QUESTION=71
|
||||
COLON=72
|
||||
EQUAL=73
|
||||
LE=74
|
||||
GE=75
|
||||
NOTEQUAL=76
|
||||
AND=77
|
||||
OR=78
|
||||
INC=79
|
||||
DEC=80
|
||||
ADD=81
|
||||
SUB=82
|
||||
MUL=83
|
||||
DIV=84
|
||||
BITAND=85
|
||||
BITOR=86
|
||||
CARET=87
|
||||
MOD=88
|
||||
ARROW=89
|
||||
COLONCOLON=90
|
||||
ADD_ASSIGN=91
|
||||
SUB_ASSIGN=92
|
||||
MUL_ASSIGN=93
|
||||
DIV_ASSIGN=94
|
||||
AND_ASSIGN=95
|
||||
OR_ASSIGN=96
|
||||
XOR_ASSIGN=97
|
||||
MOD_ASSIGN=98
|
||||
LSHIFT_ASSIGN=99
|
||||
RSHIFT_ASSIGN=100
|
||||
URSHIFT_ASSIGN=101
|
||||
Identifier=102
|
||||
AT=103
|
||||
ELLIPSIS=104
|
||||
WS=105
|
||||
COMMENT=106
|
||||
LINE_COMMENT=107
|
||||
'abstract'=1
|
||||
'assert'=2
|
||||
'boolean'=3
|
||||
'break'=4
|
||||
'byte'=5
|
||||
'case'=6
|
||||
'catch'=7
|
||||
'char'=8
|
||||
'class'=9
|
||||
'const'=10
|
||||
'continue'=11
|
||||
'default'=12
|
||||
'do'=13
|
||||
'double'=14
|
||||
'else'=15
|
||||
'enum'=16
|
||||
'extends'=17
|
||||
'final'=18
|
||||
'finally'=19
|
||||
'float'=20
|
||||
'for'=21
|
||||
'if'=22
|
||||
'goto'=23
|
||||
'implements'=24
|
||||
'import'=25
|
||||
'instanceof'=26
|
||||
'int'=27
|
||||
'interface'=28
|
||||
'long'=29
|
||||
'native'=30
|
||||
'new'=31
|
||||
'package'=32
|
||||
'private'=33
|
||||
'protected'=34
|
||||
'public'=35
|
||||
'return'=36
|
||||
'short'=37
|
||||
'static'=38
|
||||
'strictfp'=39
|
||||
'super'=40
|
||||
'switch'=41
|
||||
'synchronized'=42
|
||||
'this'=43
|
||||
'throw'=44
|
||||
'throws'=45
|
||||
'transient'=46
|
||||
'try'=47
|
||||
'void'=48
|
||||
'volatile'=49
|
||||
'while'=50
|
||||
'null'=56
|
||||
'('=57
|
||||
')'=58
|
||||
'{'=59
|
||||
'}'=60
|
||||
'['=61
|
||||
']'=62
|
||||
';'=63
|
||||
','=64
|
||||
'.'=65
|
||||
'='=66
|
||||
'>'=67
|
||||
'<'=68
|
||||
'!'=69
|
||||
'~'=70
|
||||
'?'=71
|
||||
':'=72
|
||||
'=='=73
|
||||
'<='=74
|
||||
'>='=75
|
||||
'!='=76
|
||||
'&&'=77
|
||||
'||'=78
|
||||
'++'=79
|
||||
'--'=80
|
||||
'+'=81
|
||||
'-'=82
|
||||
'*'=83
|
||||
'/'=84
|
||||
'&'=85
|
||||
'|'=86
|
||||
'^'=87
|
||||
'%'=88
|
||||
'->'=89
|
||||
'::'=90
|
||||
'+='=91
|
||||
'-='=92
|
||||
'*='=93
|
||||
'/='=94
|
||||
'&='=95
|
||||
'|='=96
|
||||
'^='=97
|
||||
'%='=98
|
||||
'<<='=99
|
||||
'>>='=100
|
||||
'>>>='=101
|
||||
'@'=103
|
||||
'...'=104
|
@ -1,591 +0,0 @@
|
||||
// Generated from Java8.g4 by ANTLR 4.7
|
||||
package de.dhbwstuttgart.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 Java8Lexer 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
|
||||
ABSTRACT=1, ASSERT=2, BOOLEAN=3, BREAK=4, BYTE=5, CASE=6, CATCH=7, CHAR=8,
|
||||
CLASS=9, CONST=10, CONTINUE=11, DEFAULT=12, DO=13, DOUBLE=14, ELSE=15,
|
||||
ENUM=16, EXTENDS=17, FINAL=18, FINALLY=19, FLOAT=20, FOR=21, IF=22, GOTO=23,
|
||||
IMPLEMENTS=24, IMPORT=25, INSTANCEOF=26, INT=27, INTERFACE=28, LONG=29,
|
||||
NATIVE=30, NEW=31, PACKAGE=32, PRIVATE=33, PROTECTED=34, PUBLIC=35, RETURN=36,
|
||||
SHORT=37, STATIC=38, STRICTFP=39, SUPER=40, SWITCH=41, SYNCHRONIZED=42,
|
||||
THIS=43, THROW=44, THROWS=45, TRANSIENT=46, TRY=47, VOID=48, VOLATILE=49,
|
||||
WHILE=50, IntegerLiteral=51, FloatingPointLiteral=52, BooleanLiteral=53,
|
||||
CharacterLiteral=54, StringLiteral=55, NullLiteral=56, LPAREN=57, RPAREN=58,
|
||||
LBRACE=59, RBRACE=60, LBRACK=61, RBRACK=62, SEMI=63, COMMA=64, DOT=65,
|
||||
ASSIGN=66, GT=67, LT=68, BANG=69, TILDE=70, QUESTION=71, COLON=72, EQUAL=73,
|
||||
LE=74, GE=75, NOTEQUAL=76, AND=77, OR=78, INC=79, DEC=80, ADD=81, SUB=82,
|
||||
MUL=83, DIV=84, BITAND=85, BITOR=86, CARET=87, MOD=88, ARROW=89, COLONCOLON=90,
|
||||
ADD_ASSIGN=91, SUB_ASSIGN=92, MUL_ASSIGN=93, DIV_ASSIGN=94, AND_ASSIGN=95,
|
||||
OR_ASSIGN=96, XOR_ASSIGN=97, MOD_ASSIGN=98, LSHIFT_ASSIGN=99, RSHIFT_ASSIGN=100,
|
||||
URSHIFT_ASSIGN=101, Identifier=102, AT=103, ELLIPSIS=104, WS=105, COMMENT=106,
|
||||
LINE_COMMENT=107;
|
||||
public static String[] channelNames = {
|
||||
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||
};
|
||||
|
||||
public static String[] modeNames = {
|
||||
"DEFAULT_MODE"
|
||||
};
|
||||
|
||||
public static final String[] ruleNames = {
|
||||
"ABSTRACT", "ASSERT", "BOOLEAN", "BREAK", "BYTE", "CASE", "CATCH", "CHAR",
|
||||
"CLASS", "CONST", "CONTINUE", "DEFAULT", "DO", "DOUBLE", "ELSE", "ENUM",
|
||||
"EXTENDS", "FINAL", "FINALLY", "FLOAT", "FOR", "IF", "GOTO", "IMPLEMENTS",
|
||||
"IMPORT", "INSTANCEOF", "INT", "INTERFACE", "LONG", "NATIVE", "NEW", "PACKAGE",
|
||||
"PRIVATE", "PROTECTED", "PUBLIC", "RETURN", "SHORT", "STATIC", "STRICTFP",
|
||||
"SUPER", "SWITCH", "SYNCHRONIZED", "THIS", "THROW", "THROWS", "TRANSIENT",
|
||||
"TRY", "VOID", "VOLATILE", "WHILE", "IntegerLiteral", "DecimalIntegerLiteral",
|
||||
"HexIntegerLiteral", "OctalIntegerLiteral", "BinaryIntegerLiteral", "IntegerTypeSuffix",
|
||||
"DecimalNumeral", "Digits", "Digit", "NonZeroDigit", "DigitsAndUnderscores",
|
||||
"DigitOrUnderscore", "Underscores", "HexNumeral", "HexDigits", "HexDigit",
|
||||
"HexDigitsAndUnderscores", "HexDigitOrUnderscore", "OctalNumeral", "OctalDigits",
|
||||
"OctalDigit", "OctalDigitsAndUnderscores", "OctalDigitOrUnderscore", "BinaryNumeral",
|
||||
"BinaryDigits", "BinaryDigit", "BinaryDigitsAndUnderscores", "BinaryDigitOrUnderscore",
|
||||
"FloatingPointLiteral", "DecimalFloatingPointLiteral", "ExponentPart",
|
||||
"ExponentIndicator", "SignedInteger", "Sign", "FloatTypeSuffix", "HexadecimalFloatingPointLiteral",
|
||||
"HexSignificand", "BinaryExponent", "BinaryExponentIndicator", "BooleanLiteral",
|
||||
"CharacterLiteral", "SingleCharacter", "StringLiteral", "StringCharacters",
|
||||
"StringCharacter", "EscapeSequence", "OctalEscape", "ZeroToThree", "UnicodeEscape",
|
||||
"NullLiteral", "LPAREN", "RPAREN", "LBRACE", "RBRACE", "LBRACK", "RBRACK",
|
||||
"SEMI", "COMMA", "DOT", "ASSIGN", "GT", "LT", "BANG", "TILDE", "QUESTION",
|
||||
"COLON", "EQUAL", "LE", "GE", "NOTEQUAL", "AND", "OR", "INC", "DEC", "ADD",
|
||||
"SUB", "MUL", "DIV", "BITAND", "BITOR", "CARET", "MOD", "ARROW", "COLONCOLON",
|
||||
"ADD_ASSIGN", "SUB_ASSIGN", "MUL_ASSIGN", "DIV_ASSIGN", "AND_ASSIGN",
|
||||
"OR_ASSIGN", "XOR_ASSIGN", "MOD_ASSIGN", "LSHIFT_ASSIGN", "RSHIFT_ASSIGN",
|
||||
"URSHIFT_ASSIGN", "Identifier", "JavaLetter", "JavaLetterOrDigit", "AT",
|
||||
"ELLIPSIS", "WS", "COMMENT", "LINE_COMMENT"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "'abstract'", "'assert'", "'boolean'", "'break'", "'byte'", "'case'",
|
||||
"'catch'", "'char'", "'class'", "'const'", "'continue'", "'default'",
|
||||
"'do'", "'double'", "'else'", "'enum'", "'extends'", "'final'", "'finally'",
|
||||
"'float'", "'for'", "'if'", "'goto'", "'implements'", "'import'", "'instanceof'",
|
||||
"'int'", "'interface'", "'long'", "'native'", "'new'", "'package'", "'private'",
|
||||
"'protected'", "'public'", "'return'", "'short'", "'static'", "'strictfp'",
|
||||
"'super'", "'switch'", "'synchronized'", "'this'", "'throw'", "'throws'",
|
||||
"'transient'", "'try'", "'void'", "'volatile'", "'while'", null, null,
|
||||
null, null, null, "'null'", "'('", "')'", "'{'", "'}'", "'['", "']'",
|
||||
"';'", "','", "'.'", "'='", "'>'", "'<'", "'!'", "'~'", "'?'", "':'",
|
||||
"'=='", "'<='", "'>='", "'!='", "'&&'", "'||'", "'++'", "'--'", "'+'",
|
||||
"'-'", "'*'", "'/'", "'&'", "'|'", "'^'", "'%'", "'->'", "'::'", "'+='",
|
||||
"'-='", "'*='", "'/='", "'&='", "'|='", "'^='", "'%='", "'<<='", "'>>='",
|
||||
"'>>>='", null, "'@'", "'...'"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, "ABSTRACT", "ASSERT", "BOOLEAN", "BREAK", "BYTE", "CASE", "CATCH",
|
||||
"CHAR", "CLASS", "CONST", "CONTINUE", "DEFAULT", "DO", "DOUBLE", "ELSE",
|
||||
"ENUM", "EXTENDS", "FINAL", "FINALLY", "FLOAT", "FOR", "IF", "GOTO", "IMPLEMENTS",
|
||||
"IMPORT", "INSTANCEOF", "INT", "INTERFACE", "LONG", "NATIVE", "NEW", "PACKAGE",
|
||||
"PRIVATE", "PROTECTED", "PUBLIC", "RETURN", "SHORT", "STATIC", "STRICTFP",
|
||||
"SUPER", "SWITCH", "SYNCHRONIZED", "THIS", "THROW", "THROWS", "TRANSIENT",
|
||||
"TRY", "VOID", "VOLATILE", "WHILE", "IntegerLiteral", "FloatingPointLiteral",
|
||||
"BooleanLiteral", "CharacterLiteral", "StringLiteral", "NullLiteral",
|
||||
"LPAREN", "RPAREN", "LBRACE", "RBRACE", "LBRACK", "RBRACK", "SEMI", "COMMA",
|
||||
"DOT", "ASSIGN", "GT", "LT", "BANG", "TILDE", "QUESTION", "COLON", "EQUAL",
|
||||
"LE", "GE", "NOTEQUAL", "AND", "OR", "INC", "DEC", "ADD", "SUB", "MUL",
|
||||
"DIV", "BITAND", "BITOR", "CARET", "MOD", "ARROW", "COLONCOLON", "ADD_ASSIGN",
|
||||
"SUB_ASSIGN", "MUL_ASSIGN", "DIV_ASSIGN", "AND_ASSIGN", "OR_ASSIGN", "XOR_ASSIGN",
|
||||
"MOD_ASSIGN", "LSHIFT_ASSIGN", "RSHIFT_ASSIGN", "URSHIFT_ASSIGN", "Identifier",
|
||||
"AT", "ELLIPSIS", "WS", "COMMENT", "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 Java8Lexer(CharStream input) {
|
||||
super(input);
|
||||
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "Java8.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; }
|
||||
|
||||
@Override
|
||||
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
|
||||
switch (ruleIndex) {
|
||||
case 146:
|
||||
return JavaLetter_sempred((RuleContext)_localctx, predIndex);
|
||||
case 147:
|
||||
return JavaLetterOrDigit_sempred((RuleContext)_localctx, predIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private boolean JavaLetter_sempred(RuleContext _localctx, int predIndex) {
|
||||
switch (predIndex) {
|
||||
case 0:
|
||||
return Character.isJavaIdentifierStart(_input.LA(-1));
|
||||
case 1:
|
||||
return Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) {
|
||||
switch (predIndex) {
|
||||
case 2:
|
||||
return Character.isJavaIdentifierPart(_input.LA(-1));
|
||||
case 3:
|
||||
return Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2m\u0448\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\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
|
||||
"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
|
||||
"\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+
|
||||
"\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t+\4"+
|
||||
",\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4\62\t\62\4\63\t\63\4\64\t"+
|
||||
"\64\4\65\t\65\4\66\t\66\4\67\t\67\48\t8\49\t9\4:\t:\4;\t;\4<\t<\4=\t="+
|
||||
"\4>\t>\4?\t?\4@\t@\4A\tA\4B\tB\4C\tC\4D\tD\4E\tE\4F\tF\4G\tG\4H\tH\4I"+
|
||||
"\tI\4J\tJ\4K\tK\4L\tL\4M\tM\4N\tN\4O\tO\4P\tP\4Q\tQ\4R\tR\4S\tS\4T\tT"+
|
||||
"\4U\tU\4V\tV\4W\tW\4X\tX\4Y\tY\4Z\tZ\4[\t[\4\\\t\\\4]\t]\4^\t^\4_\t_\4"+
|
||||
"`\t`\4a\ta\4b\tb\4c\tc\4d\td\4e\te\4f\tf\4g\tg\4h\th\4i\ti\4j\tj\4k\t"+
|
||||
"k\4l\tl\4m\tm\4n\tn\4o\to\4p\tp\4q\tq\4r\tr\4s\ts\4t\tt\4u\tu\4v\tv\4"+
|
||||
"w\tw\4x\tx\4y\ty\4z\tz\4{\t{\4|\t|\4}\t}\4~\t~\4\177\t\177\4\u0080\t\u0080"+
|
||||
"\4\u0081\t\u0081\4\u0082\t\u0082\4\u0083\t\u0083\4\u0084\t\u0084\4\u0085"+
|
||||
"\t\u0085\4\u0086\t\u0086\4\u0087\t\u0087\4\u0088\t\u0088\4\u0089\t\u0089"+
|
||||
"\4\u008a\t\u008a\4\u008b\t\u008b\4\u008c\t\u008c\4\u008d\t\u008d\4\u008e"+
|
||||
"\t\u008e\4\u008f\t\u008f\4\u0090\t\u0090\4\u0091\t\u0091\4\u0092\t\u0092"+
|
||||
"\4\u0093\t\u0093\4\u0094\t\u0094\4\u0095\t\u0095\4\u0096\t\u0096\4\u0097"+
|
||||
"\t\u0097\4\u0098\t\u0098\4\u0099\t\u0099\4\u009a\t\u009a\3\2\3\2\3\2\3"+
|
||||
"\2\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\4\3\4\3\4\3\4\3\4"+
|
||||
"\3\4\3\4\3\4\3\5\3\5\3\5\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3"+
|
||||
"\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n"+
|
||||
"\3\n\3\13\3\13\3\13\3\13\3\13\3\13\3\f\3\f\3\f\3\f\3\f\3\f\3\f\3\f\3\f"+
|
||||
"\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\16\3\16\3\16\3\17\3\17\3\17\3\17\3"+
|
||||
"\17\3\17\3\17\3\20\3\20\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3\21\3\22\3"+
|
||||
"\22\3\22\3\22\3\22\3\22\3\22\3\22\3\23\3\23\3\23\3\23\3\23\3\23\3\24\3"+
|
||||
"\24\3\24\3\24\3\24\3\24\3\24\3\24\3\25\3\25\3\25\3\25\3\25\3\25\3\26\3"+
|
||||
"\26\3\26\3\26\3\27\3\27\3\27\3\30\3\30\3\30\3\30\3\30\3\31\3\31\3\31\3"+
|
||||
"\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\32\3\32\3\32\3\32\3\32\3\32\3"+
|
||||
"\32\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\34\3\34\3"+
|
||||
"\34\3\34\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\36\3\36\3"+
|
||||
"\36\3\36\3\36\3\37\3\37\3\37\3\37\3\37\3\37\3\37\3 \3 \3 \3 \3!\3!\3!"+
|
||||
"\3!\3!\3!\3!\3!\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3#\3#\3#\3#\3#\3#\3#\3"+
|
||||
"#\3#\3#\3$\3$\3$\3$\3$\3$\3$\3%\3%\3%\3%\3%\3%\3%\3&\3&\3&\3&\3&\3&\3"+
|
||||
"\'\3\'\3\'\3\'\3\'\3\'\3\'\3(\3(\3(\3(\3(\3(\3(\3(\3(\3)\3)\3)\3)\3)\3"+
|
||||
")\3*\3*\3*\3*\3*\3*\3*\3+\3+\3+\3+\3+\3+\3+\3+\3+\3+\3+\3+\3+\3,\3,\3"+
|
||||
",\3,\3,\3-\3-\3-\3-\3-\3-\3.\3.\3.\3.\3.\3.\3.\3/\3/\3/\3/\3/\3/\3/\3"+
|
||||
"/\3/\3/\3\60\3\60\3\60\3\60\3\61\3\61\3\61\3\61\3\61\3\62\3\62\3\62\3"+
|
||||
"\62\3\62\3\62\3\62\3\62\3\62\3\63\3\63\3\63\3\63\3\63\3\63\3\64\3\64\3"+
|
||||
"\64\3\64\5\64\u028d\n\64\3\65\3\65\5\65\u0291\n\65\3\66\3\66\5\66\u0295"+
|
||||
"\n\66\3\67\3\67\5\67\u0299\n\67\38\38\58\u029d\n8\39\39\3:\3:\3:\5:\u02a4"+
|
||||
"\n:\3:\3:\3:\5:\u02a9\n:\5:\u02ab\n:\3;\3;\5;\u02af\n;\3;\5;\u02b2\n;"+
|
||||
"\3<\3<\5<\u02b6\n<\3=\3=\3>\6>\u02bb\n>\r>\16>\u02bc\3?\3?\5?\u02c1\n"+
|
||||
"?\3@\6@\u02c4\n@\r@\16@\u02c5\3A\3A\3A\3A\3B\3B\5B\u02ce\nB\3B\5B\u02d1"+
|
||||
"\nB\3C\3C\3D\6D\u02d6\nD\rD\16D\u02d7\3E\3E\5E\u02dc\nE\3F\3F\5F\u02e0"+
|
||||
"\nF\3F\3F\3G\3G\5G\u02e6\nG\3G\5G\u02e9\nG\3H\3H\3I\6I\u02ee\nI\rI\16"+
|
||||
"I\u02ef\3J\3J\5J\u02f4\nJ\3K\3K\3K\3K\3L\3L\5L\u02fc\nL\3L\5L\u02ff\n"+
|
||||
"L\3M\3M\3N\6N\u0304\nN\rN\16N\u0305\3O\3O\5O\u030a\nO\3P\3P\5P\u030e\n"+
|
||||
"P\3Q\3Q\3Q\5Q\u0313\nQ\3Q\5Q\u0316\nQ\3Q\5Q\u0319\nQ\3Q\3Q\3Q\5Q\u031e"+
|
||||
"\nQ\3Q\5Q\u0321\nQ\3Q\3Q\3Q\5Q\u0326\nQ\3Q\3Q\3Q\5Q\u032b\nQ\3R\3R\3R"+
|
||||
"\3S\3S\3T\5T\u0333\nT\3T\3T\3U\3U\3V\3V\3W\3W\3W\5W\u033e\nW\3X\3X\5X"+
|
||||
"\u0342\nX\3X\3X\3X\5X\u0347\nX\3X\3X\5X\u034b\nX\3Y\3Y\3Y\3Z\3Z\3[\3["+
|
||||
"\3[\3[\3[\3[\3[\3[\3[\5[\u035b\n[\3\\\3\\\3\\\3\\\3\\\3\\\3\\\3\\\5\\"+
|
||||
"\u0365\n\\\3]\3]\3^\3^\5^\u036b\n^\3^\3^\3_\6_\u0370\n_\r_\16_\u0371\3"+
|
||||
"`\3`\5`\u0376\n`\3a\3a\3a\3a\5a\u037c\na\3b\3b\3b\3b\3b\3b\3b\3b\3b\3"+
|
||||
"b\3b\5b\u0389\nb\3c\3c\3d\3d\3d\3d\3d\3d\3d\3e\3e\3e\3e\3e\3f\3f\3g\3"+
|
||||
"g\3h\3h\3i\3i\3j\3j\3k\3k\3l\3l\3m\3m\3n\3n\3o\3o\3p\3p\3q\3q\3r\3r\3"+
|
||||
"s\3s\3t\3t\3u\3u\3v\3v\3v\3w\3w\3w\3x\3x\3x\3y\3y\3y\3z\3z\3z\3{\3{\3"+
|
||||
"{\3|\3|\3|\3}\3}\3}\3~\3~\3\177\3\177\3\u0080\3\u0080\3\u0081\3\u0081"+
|
||||
"\3\u0082\3\u0082\3\u0083\3\u0083\3\u0084\3\u0084\3\u0085\3\u0085\3\u0086"+
|
||||
"\3\u0086\3\u0086\3\u0087\3\u0087\3\u0087\3\u0088\3\u0088\3\u0088\3\u0089"+
|
||||
"\3\u0089\3\u0089\3\u008a\3\u008a\3\u008a\3\u008b\3\u008b\3\u008b\3\u008c"+
|
||||
"\3\u008c\3\u008c\3\u008d\3\u008d\3\u008d\3\u008e\3\u008e\3\u008e\3\u008f"+
|
||||
"\3\u008f\3\u008f\3\u0090\3\u0090\3\u0090\3\u0090\3\u0091\3\u0091\3\u0091"+
|
||||
"\3\u0091\3\u0092\3\u0092\3\u0092\3\u0092\3\u0092\3\u0093\3\u0093\7\u0093"+
|
||||
"\u040e\n\u0093\f\u0093\16\u0093\u0411\13\u0093\3\u0094\3\u0094\3\u0094"+
|
||||
"\3\u0094\3\u0094\3\u0094\5\u0094\u0419\n\u0094\3\u0095\3\u0095\3\u0095"+
|
||||
"\3\u0095\3\u0095\3\u0095\5\u0095\u0421\n\u0095\3\u0096\3\u0096\3\u0097"+
|
||||
"\3\u0097\3\u0097\3\u0097\3\u0098\6\u0098\u042a\n\u0098\r\u0098\16\u0098"+
|
||||
"\u042b\3\u0098\3\u0098\3\u0099\3\u0099\3\u0099\3\u0099\7\u0099\u0434\n"+
|
||||
"\u0099\f\u0099\16\u0099\u0437\13\u0099\3\u0099\3\u0099\3\u0099\3\u0099"+
|
||||
"\3\u0099\3\u009a\3\u009a\3\u009a\3\u009a\7\u009a\u0442\n\u009a\f\u009a"+
|
||||
"\16\u009a\u0445\13\u009a\3\u009a\3\u009a\3\u0435\2\u009b\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\35\20\37\21!\22#\23"+
|
||||
"%\24\'\25)\26+\27-\30/\31\61\32\63\33\65\34\67\359\36;\37= ?!A\"C#E$G"+
|
||||
"%I&K\'M(O)Q*S+U,W-Y.[/]\60_\61a\62c\63e\64g\65i\2k\2m\2o\2q\2s\2u\2w\2"+
|
||||
"y\2{\2}\2\177\2\u0081\2\u0083\2\u0085\2\u0087\2\u0089\2\u008b\2\u008d"+
|
||||
"\2\u008f\2\u0091\2\u0093\2\u0095\2\u0097\2\u0099\2\u009b\2\u009d\2\u009f"+
|
||||
"\66\u00a1\2\u00a3\2\u00a5\2\u00a7\2\u00a9\2\u00ab\2\u00ad\2\u00af\2\u00b1"+
|
||||
"\2\u00b3\2\u00b5\67\u00b78\u00b9\2\u00bb9\u00bd\2\u00bf\2\u00c1\2\u00c3"+
|
||||
"\2\u00c5\2\u00c7\2\u00c9:\u00cb;\u00cd<\u00cf=\u00d1>\u00d3?\u00d5@\u00d7"+
|
||||
"A\u00d9B\u00dbC\u00ddD\u00dfE\u00e1F\u00e3G\u00e5H\u00e7I\u00e9J\u00eb"+
|
||||
"K\u00edL\u00efM\u00f1N\u00f3O\u00f5P\u00f7Q\u00f9R\u00fbS\u00fdT\u00ff"+
|
||||
"U\u0101V\u0103W\u0105X\u0107Y\u0109Z\u010b[\u010d\\\u010f]\u0111^\u0113"+
|
||||
"_\u0115`\u0117a\u0119b\u011bc\u011dd\u011fe\u0121f\u0123g\u0125h\u0127"+
|
||||
"\2\u0129\2\u012bi\u012dj\u012fk\u0131l\u0133m\3\2\30\4\2NNnn\3\2\63;\4"+
|
||||
"\2ZZzz\5\2\62;CHch\3\2\629\4\2DDdd\3\2\62\63\4\2GGgg\4\2--//\6\2FFHHf"+
|
||||
"fhh\4\2RRrr\4\2))^^\4\2$$^^\n\2$$))^^ddhhppttvv\3\2\62\65\6\2&&C\\aac"+
|
||||
"|\4\2\2\u0081\ud802\udc01\3\2\ud802\udc01\3\2\udc02\ue001\7\2&&\62;C\\"+
|
||||
"aac|\5\2\13\f\16\17\"\"\4\2\f\f\17\17\2\u0456\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\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2"+
|
||||
"\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2"+
|
||||
"\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2?\3\2"+
|
||||
"\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2\2G\3\2\2\2\2I\3\2\2\2\2K\3\2\2\2"+
|
||||
"\2M\3\2\2\2\2O\3\2\2\2\2Q\3\2\2\2\2S\3\2\2\2\2U\3\2\2\2\2W\3\2\2\2\2Y"+
|
||||
"\3\2\2\2\2[\3\2\2\2\2]\3\2\2\2\2_\3\2\2\2\2a\3\2\2\2\2c\3\2\2\2\2e\3\2"+
|
||||
"\2\2\2g\3\2\2\2\2\u009f\3\2\2\2\2\u00b5\3\2\2\2\2\u00b7\3\2\2\2\2\u00bb"+
|
||||
"\3\2\2\2\2\u00c9\3\2\2\2\2\u00cb\3\2\2\2\2\u00cd\3\2\2\2\2\u00cf\3\2\2"+
|
||||
"\2\2\u00d1\3\2\2\2\2\u00d3\3\2\2\2\2\u00d5\3\2\2\2\2\u00d7\3\2\2\2\2\u00d9"+
|
||||
"\3\2\2\2\2\u00db\3\2\2\2\2\u00dd\3\2\2\2\2\u00df\3\2\2\2\2\u00e1\3\2\2"+
|
||||
"\2\2\u00e3\3\2\2\2\2\u00e5\3\2\2\2\2\u00e7\3\2\2\2\2\u00e9\3\2\2\2\2\u00eb"+
|
||||
"\3\2\2\2\2\u00ed\3\2\2\2\2\u00ef\3\2\2\2\2\u00f1\3\2\2\2\2\u00f3\3\2\2"+
|
||||
"\2\2\u00f5\3\2\2\2\2\u00f7\3\2\2\2\2\u00f9\3\2\2\2\2\u00fb\3\2\2\2\2\u00fd"+
|
||||
"\3\2\2\2\2\u00ff\3\2\2\2\2\u0101\3\2\2\2\2\u0103\3\2\2\2\2\u0105\3\2\2"+
|
||||
"\2\2\u0107\3\2\2\2\2\u0109\3\2\2\2\2\u010b\3\2\2\2\2\u010d\3\2\2\2\2\u010f"+
|
||||
"\3\2\2\2\2\u0111\3\2\2\2\2\u0113\3\2\2\2\2\u0115\3\2\2\2\2\u0117\3\2\2"+
|
||||
"\2\2\u0119\3\2\2\2\2\u011b\3\2\2\2\2\u011d\3\2\2\2\2\u011f\3\2\2\2\2\u0121"+
|
||||
"\3\2\2\2\2\u0123\3\2\2\2\2\u0125\3\2\2\2\2\u012b\3\2\2\2\2\u012d\3\2\2"+
|
||||
"\2\2\u012f\3\2\2\2\2\u0131\3\2\2\2\2\u0133\3\2\2\2\3\u0135\3\2\2\2\5\u013e"+
|
||||
"\3\2\2\2\7\u0145\3\2\2\2\t\u014d\3\2\2\2\13\u0153\3\2\2\2\r\u0158\3\2"+
|
||||
"\2\2\17\u015d\3\2\2\2\21\u0163\3\2\2\2\23\u0168\3\2\2\2\25\u016e\3\2\2"+
|
||||
"\2\27\u0174\3\2\2\2\31\u017d\3\2\2\2\33\u0185\3\2\2\2\35\u0188\3\2\2\2"+
|
||||
"\37\u018f\3\2\2\2!\u0194\3\2\2\2#\u0199\3\2\2\2%\u01a1\3\2\2\2\'\u01a7"+
|
||||
"\3\2\2\2)\u01af\3\2\2\2+\u01b5\3\2\2\2-\u01b9\3\2\2\2/\u01bc\3\2\2\2\61"+
|
||||
"\u01c1\3\2\2\2\63\u01cc\3\2\2\2\65\u01d3\3\2\2\2\67\u01de\3\2\2\29\u01e2"+
|
||||
"\3\2\2\2;\u01ec\3\2\2\2=\u01f1\3\2\2\2?\u01f8\3\2\2\2A\u01fc\3\2\2\2C"+
|
||||
"\u0204\3\2\2\2E\u020c\3\2\2\2G\u0216\3\2\2\2I\u021d\3\2\2\2K\u0224\3\2"+
|
||||
"\2\2M\u022a\3\2\2\2O\u0231\3\2\2\2Q\u023a\3\2\2\2S\u0240\3\2\2\2U\u0247"+
|
||||
"\3\2\2\2W\u0254\3\2\2\2Y\u0259\3\2\2\2[\u025f\3\2\2\2]\u0266\3\2\2\2_"+
|
||||
"\u0270\3\2\2\2a\u0274\3\2\2\2c\u0279\3\2\2\2e\u0282\3\2\2\2g\u028c\3\2"+
|
||||
"\2\2i\u028e\3\2\2\2k\u0292\3\2\2\2m\u0296\3\2\2\2o\u029a\3\2\2\2q\u029e"+
|
||||
"\3\2\2\2s\u02aa\3\2\2\2u\u02ac\3\2\2\2w\u02b5\3\2\2\2y\u02b7\3\2\2\2{"+
|
||||
"\u02ba\3\2\2\2}\u02c0\3\2\2\2\177\u02c3\3\2\2\2\u0081\u02c7\3\2\2\2\u0083"+
|
||||
"\u02cb\3\2\2\2\u0085\u02d2\3\2\2\2\u0087\u02d5\3\2\2\2\u0089\u02db\3\2"+
|
||||
"\2\2\u008b\u02dd\3\2\2\2\u008d\u02e3\3\2\2\2\u008f\u02ea\3\2\2\2\u0091"+
|
||||
"\u02ed\3\2\2\2\u0093\u02f3\3\2\2\2\u0095\u02f5\3\2\2\2\u0097\u02f9\3\2"+
|
||||
"\2\2\u0099\u0300\3\2\2\2\u009b\u0303\3\2\2\2\u009d\u0309\3\2\2\2\u009f"+
|
||||
"\u030d\3\2\2\2\u00a1\u032a\3\2\2\2\u00a3\u032c\3\2\2\2\u00a5\u032f\3\2"+
|
||||
"\2\2\u00a7\u0332\3\2\2\2\u00a9\u0336\3\2\2\2\u00ab\u0338\3\2\2\2\u00ad"+
|
||||
"\u033a\3\2\2\2\u00af\u034a\3\2\2\2\u00b1\u034c\3\2\2\2\u00b3\u034f\3\2"+
|
||||
"\2\2\u00b5\u035a\3\2\2\2\u00b7\u0364\3\2\2\2\u00b9\u0366\3\2\2\2\u00bb"+
|
||||
"\u0368\3\2\2\2\u00bd\u036f\3\2\2\2\u00bf\u0375\3\2\2\2\u00c1\u037b\3\2"+
|
||||
"\2\2\u00c3\u0388\3\2\2\2\u00c5\u038a\3\2\2\2\u00c7\u038c\3\2\2\2\u00c9"+
|
||||
"\u0393\3\2\2\2\u00cb\u0398\3\2\2\2\u00cd\u039a\3\2\2\2\u00cf\u039c\3\2"+
|
||||
"\2\2\u00d1\u039e\3\2\2\2\u00d3\u03a0\3\2\2\2\u00d5\u03a2\3\2\2\2\u00d7"+
|
||||
"\u03a4\3\2\2\2\u00d9\u03a6\3\2\2\2\u00db\u03a8\3\2\2\2\u00dd\u03aa\3\2"+
|
||||
"\2\2\u00df\u03ac\3\2\2\2\u00e1\u03ae\3\2\2\2\u00e3\u03b0\3\2\2\2\u00e5"+
|
||||
"\u03b2\3\2\2\2\u00e7\u03b4\3\2\2\2\u00e9\u03b6\3\2\2\2\u00eb\u03b8\3\2"+
|
||||
"\2\2\u00ed\u03bb\3\2\2\2\u00ef\u03be\3\2\2\2\u00f1\u03c1\3\2\2\2\u00f3"+
|
||||
"\u03c4\3\2\2\2\u00f5\u03c7\3\2\2\2\u00f7\u03ca\3\2\2\2\u00f9\u03cd\3\2"+
|
||||
"\2\2\u00fb\u03d0\3\2\2\2\u00fd\u03d2\3\2\2\2\u00ff\u03d4\3\2\2\2\u0101"+
|
||||
"\u03d6\3\2\2\2\u0103\u03d8\3\2\2\2\u0105\u03da\3\2\2\2\u0107\u03dc\3\2"+
|
||||
"\2\2\u0109\u03de\3\2\2\2\u010b\u03e0\3\2\2\2\u010d\u03e3\3\2\2\2\u010f"+
|
||||
"\u03e6\3\2\2\2\u0111\u03e9\3\2\2\2\u0113\u03ec\3\2\2\2\u0115\u03ef\3\2"+
|
||||
"\2\2\u0117\u03f2\3\2\2\2\u0119\u03f5\3\2\2\2\u011b\u03f8\3\2\2\2\u011d"+
|
||||
"\u03fb\3\2\2\2\u011f\u03fe\3\2\2\2\u0121\u0402\3\2\2\2\u0123\u0406\3\2"+
|
||||
"\2\2\u0125\u040b\3\2\2\2\u0127\u0418\3\2\2\2\u0129\u0420\3\2\2\2\u012b"+
|
||||
"\u0422\3\2\2\2\u012d\u0424\3\2\2\2\u012f\u0429\3\2\2\2\u0131\u042f\3\2"+
|
||||
"\2\2\u0133\u043d\3\2\2\2\u0135\u0136\7c\2\2\u0136\u0137\7d\2\2\u0137\u0138"+
|
||||
"\7u\2\2\u0138\u0139\7v\2\2\u0139\u013a\7t\2\2\u013a\u013b\7c\2\2\u013b"+
|
||||
"\u013c\7e\2\2\u013c\u013d\7v\2\2\u013d\4\3\2\2\2\u013e\u013f\7c\2\2\u013f"+
|
||||
"\u0140\7u\2\2\u0140\u0141\7u\2\2\u0141\u0142\7g\2\2\u0142\u0143\7t\2\2"+
|
||||
"\u0143\u0144\7v\2\2\u0144\6\3\2\2\2\u0145\u0146\7d\2\2\u0146\u0147\7q"+
|
||||
"\2\2\u0147\u0148\7q\2\2\u0148\u0149\7n\2\2\u0149\u014a\7g\2\2\u014a\u014b"+
|
||||
"\7c\2\2\u014b\u014c\7p\2\2\u014c\b\3\2\2\2\u014d\u014e\7d\2\2\u014e\u014f"+
|
||||
"\7t\2\2\u014f\u0150\7g\2\2\u0150\u0151\7c\2\2\u0151\u0152\7m\2\2\u0152"+
|
||||
"\n\3\2\2\2\u0153\u0154\7d\2\2\u0154\u0155\7{\2\2\u0155\u0156\7v\2\2\u0156"+
|
||||
"\u0157\7g\2\2\u0157\f\3\2\2\2\u0158\u0159\7e\2\2\u0159\u015a\7c\2\2\u015a"+
|
||||
"\u015b\7u\2\2\u015b\u015c\7g\2\2\u015c\16\3\2\2\2\u015d\u015e\7e\2\2\u015e"+
|
||||
"\u015f\7c\2\2\u015f\u0160\7v\2\2\u0160\u0161\7e\2\2\u0161\u0162\7j\2\2"+
|
||||
"\u0162\20\3\2\2\2\u0163\u0164\7e\2\2\u0164\u0165\7j\2\2\u0165\u0166\7"+
|
||||
"c\2\2\u0166\u0167\7t\2\2\u0167\22\3\2\2\2\u0168\u0169\7e\2\2\u0169\u016a"+
|
||||
"\7n\2\2\u016a\u016b\7c\2\2\u016b\u016c\7u\2\2\u016c\u016d\7u\2\2\u016d"+
|
||||
"\24\3\2\2\2\u016e\u016f\7e\2\2\u016f\u0170\7q\2\2\u0170\u0171\7p\2\2\u0171"+
|
||||
"\u0172\7u\2\2\u0172\u0173\7v\2\2\u0173\26\3\2\2\2\u0174\u0175\7e\2\2\u0175"+
|
||||
"\u0176\7q\2\2\u0176\u0177\7p\2\2\u0177\u0178\7v\2\2\u0178\u0179\7k\2\2"+
|
||||
"\u0179\u017a\7p\2\2\u017a\u017b\7w\2\2\u017b\u017c\7g\2\2\u017c\30\3\2"+
|
||||
"\2\2\u017d\u017e\7f\2\2\u017e\u017f\7g\2\2\u017f\u0180\7h\2\2\u0180\u0181"+
|
||||
"\7c\2\2\u0181\u0182\7w\2\2\u0182\u0183\7n\2\2\u0183\u0184\7v\2\2\u0184"+
|
||||
"\32\3\2\2\2\u0185\u0186\7f\2\2\u0186\u0187\7q\2\2\u0187\34\3\2\2\2\u0188"+
|
||||
"\u0189\7f\2\2\u0189\u018a\7q\2\2\u018a\u018b\7w\2\2\u018b\u018c\7d\2\2"+
|
||||
"\u018c\u018d\7n\2\2\u018d\u018e\7g\2\2\u018e\36\3\2\2\2\u018f\u0190\7"+
|
||||
"g\2\2\u0190\u0191\7n\2\2\u0191\u0192\7u\2\2\u0192\u0193\7g\2\2\u0193 "+
|
||||
"\3\2\2\2\u0194\u0195\7g\2\2\u0195\u0196\7p\2\2\u0196\u0197\7w\2\2\u0197"+
|
||||
"\u0198\7o\2\2\u0198\"\3\2\2\2\u0199\u019a\7g\2\2\u019a\u019b\7z\2\2\u019b"+
|
||||
"\u019c\7v\2\2\u019c\u019d\7g\2\2\u019d\u019e\7p\2\2\u019e\u019f\7f\2\2"+
|
||||
"\u019f\u01a0\7u\2\2\u01a0$\3\2\2\2\u01a1\u01a2\7h\2\2\u01a2\u01a3\7k\2"+
|
||||
"\2\u01a3\u01a4\7p\2\2\u01a4\u01a5\7c\2\2\u01a5\u01a6\7n\2\2\u01a6&\3\2"+
|
||||
"\2\2\u01a7\u01a8\7h\2\2\u01a8\u01a9\7k\2\2\u01a9\u01aa\7p\2\2\u01aa\u01ab"+
|
||||
"\7c\2\2\u01ab\u01ac\7n\2\2\u01ac\u01ad\7n\2\2\u01ad\u01ae\7{\2\2\u01ae"+
|
||||
"(\3\2\2\2\u01af\u01b0\7h\2\2\u01b0\u01b1\7n\2\2\u01b1\u01b2\7q\2\2\u01b2"+
|
||||
"\u01b3\7c\2\2\u01b3\u01b4\7v\2\2\u01b4*\3\2\2\2\u01b5\u01b6\7h\2\2\u01b6"+
|
||||
"\u01b7\7q\2\2\u01b7\u01b8\7t\2\2\u01b8,\3\2\2\2\u01b9\u01ba\7k\2\2\u01ba"+
|
||||
"\u01bb\7h\2\2\u01bb.\3\2\2\2\u01bc\u01bd\7i\2\2\u01bd\u01be\7q\2\2\u01be"+
|
||||
"\u01bf\7v\2\2\u01bf\u01c0\7q\2\2\u01c0\60\3\2\2\2\u01c1\u01c2\7k\2\2\u01c2"+
|
||||
"\u01c3\7o\2\2\u01c3\u01c4\7r\2\2\u01c4\u01c5\7n\2\2\u01c5\u01c6\7g\2\2"+
|
||||
"\u01c6\u01c7\7o\2\2\u01c7\u01c8\7g\2\2\u01c8\u01c9\7p\2\2\u01c9\u01ca"+
|
||||
"\7v\2\2\u01ca\u01cb\7u\2\2\u01cb\62\3\2\2\2\u01cc\u01cd\7k\2\2\u01cd\u01ce"+
|
||||
"\7o\2\2\u01ce\u01cf\7r\2\2\u01cf\u01d0\7q\2\2\u01d0\u01d1\7t\2\2\u01d1"+
|
||||
"\u01d2\7v\2\2\u01d2\64\3\2\2\2\u01d3\u01d4\7k\2\2\u01d4\u01d5\7p\2\2\u01d5"+
|
||||
"\u01d6\7u\2\2\u01d6\u01d7\7v\2\2\u01d7\u01d8\7c\2\2\u01d8\u01d9\7p\2\2"+
|
||||
"\u01d9\u01da\7e\2\2\u01da\u01db\7g\2\2\u01db\u01dc\7q\2\2\u01dc\u01dd"+
|
||||
"\7h\2\2\u01dd\66\3\2\2\2\u01de\u01df\7k\2\2\u01df\u01e0\7p\2\2\u01e0\u01e1"+
|
||||
"\7v\2\2\u01e18\3\2\2\2\u01e2\u01e3\7k\2\2\u01e3\u01e4\7p\2\2\u01e4\u01e5"+
|
||||
"\7v\2\2\u01e5\u01e6\7g\2\2\u01e6\u01e7\7t\2\2\u01e7\u01e8\7h\2\2\u01e8"+
|
||||
"\u01e9\7c\2\2\u01e9\u01ea\7e\2\2\u01ea\u01eb\7g\2\2\u01eb:\3\2\2\2\u01ec"+
|
||||
"\u01ed\7n\2\2\u01ed\u01ee\7q\2\2\u01ee\u01ef\7p\2\2\u01ef\u01f0\7i\2\2"+
|
||||
"\u01f0<\3\2\2\2\u01f1\u01f2\7p\2\2\u01f2\u01f3\7c\2\2\u01f3\u01f4\7v\2"+
|
||||
"\2\u01f4\u01f5\7k\2\2\u01f5\u01f6\7x\2\2\u01f6\u01f7\7g\2\2\u01f7>\3\2"+
|
||||
"\2\2\u01f8\u01f9\7p\2\2\u01f9\u01fa\7g\2\2\u01fa\u01fb\7y\2\2\u01fb@\3"+
|
||||
"\2\2\2\u01fc\u01fd\7r\2\2\u01fd\u01fe\7c\2\2\u01fe\u01ff\7e\2\2\u01ff"+
|
||||
"\u0200\7m\2\2\u0200\u0201\7c\2\2\u0201\u0202\7i\2\2\u0202\u0203\7g\2\2"+
|
||||
"\u0203B\3\2\2\2\u0204\u0205\7r\2\2\u0205\u0206\7t\2\2\u0206\u0207\7k\2"+
|
||||
"\2\u0207\u0208\7x\2\2\u0208\u0209\7c\2\2\u0209\u020a\7v\2\2\u020a\u020b"+
|
||||
"\7g\2\2\u020bD\3\2\2\2\u020c\u020d\7r\2\2\u020d\u020e\7t\2\2\u020e\u020f"+
|
||||
"\7q\2\2\u020f\u0210\7v\2\2\u0210\u0211\7g\2\2\u0211\u0212\7e\2\2\u0212"+
|
||||
"\u0213\7v\2\2\u0213\u0214\7g\2\2\u0214\u0215\7f\2\2\u0215F\3\2\2\2\u0216"+
|
||||
"\u0217\7r\2\2\u0217\u0218\7w\2\2\u0218\u0219\7d\2\2\u0219\u021a\7n\2\2"+
|
||||
"\u021a\u021b\7k\2\2\u021b\u021c\7e\2\2\u021cH\3\2\2\2\u021d\u021e\7t\2"+
|
||||
"\2\u021e\u021f\7g\2\2\u021f\u0220\7v\2\2\u0220\u0221\7w\2\2\u0221\u0222"+
|
||||
"\7t\2\2\u0222\u0223\7p\2\2\u0223J\3\2\2\2\u0224\u0225\7u\2\2\u0225\u0226"+
|
||||
"\7j\2\2\u0226\u0227\7q\2\2\u0227\u0228\7t\2\2\u0228\u0229\7v\2\2\u0229"+
|
||||
"L\3\2\2\2\u022a\u022b\7u\2\2\u022b\u022c\7v\2\2\u022c\u022d\7c\2\2\u022d"+
|
||||
"\u022e\7v\2\2\u022e\u022f\7k\2\2\u022f\u0230\7e\2\2\u0230N\3\2\2\2\u0231"+
|
||||
"\u0232\7u\2\2\u0232\u0233\7v\2\2\u0233\u0234\7t\2\2\u0234\u0235\7k\2\2"+
|
||||
"\u0235\u0236\7e\2\2\u0236\u0237\7v\2\2\u0237\u0238\7h\2\2\u0238\u0239"+
|
||||
"\7r\2\2\u0239P\3\2\2\2\u023a\u023b\7u\2\2\u023b\u023c\7w\2\2\u023c\u023d"+
|
||||
"\7r\2\2\u023d\u023e\7g\2\2\u023e\u023f\7t\2\2\u023fR\3\2\2\2\u0240\u0241"+
|
||||
"\7u\2\2\u0241\u0242\7y\2\2\u0242\u0243\7k\2\2\u0243\u0244\7v\2\2\u0244"+
|
||||
"\u0245\7e\2\2\u0245\u0246\7j\2\2\u0246T\3\2\2\2\u0247\u0248\7u\2\2\u0248"+
|
||||
"\u0249\7{\2\2\u0249\u024a\7p\2\2\u024a\u024b\7e\2\2\u024b\u024c\7j\2\2"+
|
||||
"\u024c\u024d\7t\2\2\u024d\u024e\7q\2\2\u024e\u024f\7p\2\2\u024f\u0250"+
|
||||
"\7k\2\2\u0250\u0251\7|\2\2\u0251\u0252\7g\2\2\u0252\u0253\7f\2\2\u0253"+
|
||||
"V\3\2\2\2\u0254\u0255\7v\2\2\u0255\u0256\7j\2\2\u0256\u0257\7k\2\2\u0257"+
|
||||
"\u0258\7u\2\2\u0258X\3\2\2\2\u0259\u025a\7v\2\2\u025a\u025b\7j\2\2\u025b"+
|
||||
"\u025c\7t\2\2\u025c\u025d\7q\2\2\u025d\u025e\7y\2\2\u025eZ\3\2\2\2\u025f"+
|
||||
"\u0260\7v\2\2\u0260\u0261\7j\2\2\u0261\u0262\7t\2\2\u0262\u0263\7q\2\2"+
|
||||
"\u0263\u0264\7y\2\2\u0264\u0265\7u\2\2\u0265\\\3\2\2\2\u0266\u0267\7v"+
|
||||
"\2\2\u0267\u0268\7t\2\2\u0268\u0269\7c\2\2\u0269\u026a\7p\2\2\u026a\u026b"+
|
||||
"\7u\2\2\u026b\u026c\7k\2\2\u026c\u026d\7g\2\2\u026d\u026e\7p\2\2\u026e"+
|
||||
"\u026f\7v\2\2\u026f^\3\2\2\2\u0270\u0271\7v\2\2\u0271\u0272\7t\2\2\u0272"+
|
||||
"\u0273\7{\2\2\u0273`\3\2\2\2\u0274\u0275\7x\2\2\u0275\u0276\7q\2\2\u0276"+
|
||||
"\u0277\7k\2\2\u0277\u0278\7f\2\2\u0278b\3\2\2\2\u0279\u027a\7x\2\2\u027a"+
|
||||
"\u027b\7q\2\2\u027b\u027c\7n\2\2\u027c\u027d\7c\2\2\u027d\u027e\7v\2\2"+
|
||||
"\u027e\u027f\7k\2\2\u027f\u0280\7n\2\2\u0280\u0281\7g\2\2\u0281d\3\2\2"+
|
||||
"\2\u0282\u0283\7y\2\2\u0283\u0284\7j\2\2\u0284\u0285\7k\2\2\u0285\u0286"+
|
||||
"\7n\2\2\u0286\u0287\7g\2\2\u0287f\3\2\2\2\u0288\u028d\5i\65\2\u0289\u028d"+
|
||||
"\5k\66\2\u028a\u028d\5m\67\2\u028b\u028d\5o8\2\u028c\u0288\3\2\2\2\u028c"+
|
||||
"\u0289\3\2\2\2\u028c\u028a\3\2\2\2\u028c\u028b\3\2\2\2\u028dh\3\2\2\2"+
|
||||
"\u028e\u0290\5s:\2\u028f\u0291\5q9\2\u0290\u028f\3\2\2\2\u0290\u0291\3"+
|
||||
"\2\2\2\u0291j\3\2\2\2\u0292\u0294\5\u0081A\2\u0293\u0295\5q9\2\u0294\u0293"+
|
||||
"\3\2\2\2\u0294\u0295\3\2\2\2\u0295l\3\2\2\2\u0296\u0298\5\u008bF\2\u0297"+
|
||||
"\u0299\5q9\2\u0298\u0297\3\2\2\2\u0298\u0299\3\2\2\2\u0299n\3\2\2\2\u029a"+
|
||||
"\u029c\5\u0095K\2\u029b\u029d\5q9\2\u029c\u029b\3\2\2\2\u029c\u029d\3"+
|
||||
"\2\2\2\u029dp\3\2\2\2\u029e\u029f\t\2\2\2\u029fr\3\2\2\2\u02a0\u02ab\7"+
|
||||
"\62\2\2\u02a1\u02a8\5y=\2\u02a2\u02a4\5u;\2\u02a3\u02a2\3\2\2\2\u02a3"+
|
||||
"\u02a4\3\2\2\2\u02a4\u02a9\3\2\2\2\u02a5\u02a6\5\177@\2\u02a6\u02a7\5"+
|
||||
"u;\2\u02a7\u02a9\3\2\2\2\u02a8\u02a3\3\2\2\2\u02a8\u02a5\3\2\2\2\u02a9"+
|
||||
"\u02ab\3\2\2\2\u02aa\u02a0\3\2\2\2\u02aa\u02a1\3\2\2\2\u02abt\3\2\2\2"+
|
||||
"\u02ac\u02b1\5w<\2\u02ad\u02af\5{>\2\u02ae\u02ad\3\2\2\2\u02ae\u02af\3"+
|
||||
"\2\2\2\u02af\u02b0\3\2\2\2\u02b0\u02b2\5w<\2\u02b1\u02ae\3\2\2\2\u02b1"+
|
||||
"\u02b2\3\2\2\2\u02b2v\3\2\2\2\u02b3\u02b6\7\62\2\2\u02b4\u02b6\5y=\2\u02b5"+
|
||||
"\u02b3\3\2\2\2\u02b5\u02b4\3\2\2\2\u02b6x\3\2\2\2\u02b7\u02b8\t\3\2\2"+
|
||||
"\u02b8z\3\2\2\2\u02b9\u02bb\5}?\2\u02ba\u02b9\3\2\2\2\u02bb\u02bc\3\2"+
|
||||
"\2\2\u02bc\u02ba\3\2\2\2\u02bc\u02bd\3\2\2\2\u02bd|\3\2\2\2\u02be\u02c1"+
|
||||
"\5w<\2\u02bf\u02c1\7a\2\2\u02c0\u02be\3\2\2\2\u02c0\u02bf\3\2\2\2\u02c1"+
|
||||
"~\3\2\2\2\u02c2\u02c4\7a\2\2\u02c3\u02c2\3\2\2\2\u02c4\u02c5\3\2\2\2\u02c5"+
|
||||
"\u02c3\3\2\2\2\u02c5\u02c6\3\2\2\2\u02c6\u0080\3\2\2\2\u02c7\u02c8\7\62"+
|
||||
"\2\2\u02c8\u02c9\t\4\2\2\u02c9\u02ca\5\u0083B\2\u02ca\u0082\3\2\2\2\u02cb"+
|
||||
"\u02d0\5\u0085C\2\u02cc\u02ce\5\u0087D\2\u02cd\u02cc\3\2\2\2\u02cd\u02ce"+
|
||||
"\3\2\2\2\u02ce\u02cf\3\2\2\2\u02cf\u02d1\5\u0085C\2\u02d0\u02cd\3\2\2"+
|
||||
"\2\u02d0\u02d1\3\2\2\2\u02d1\u0084\3\2\2\2\u02d2\u02d3\t\5\2\2\u02d3\u0086"+
|
||||
"\3\2\2\2\u02d4\u02d6\5\u0089E\2\u02d5\u02d4\3\2\2\2\u02d6\u02d7\3\2\2"+
|
||||
"\2\u02d7\u02d5\3\2\2\2\u02d7\u02d8\3\2\2\2\u02d8\u0088\3\2\2\2\u02d9\u02dc"+
|
||||
"\5\u0085C\2\u02da\u02dc\7a\2\2\u02db\u02d9\3\2\2\2\u02db\u02da\3\2\2\2"+
|
||||
"\u02dc\u008a\3\2\2\2\u02dd\u02df\7\62\2\2\u02de\u02e0\5\177@\2\u02df\u02de"+
|
||||
"\3\2\2\2\u02df\u02e0\3\2\2\2\u02e0\u02e1\3\2\2\2\u02e1\u02e2\5\u008dG"+
|
||||
"\2\u02e2\u008c\3\2\2\2\u02e3\u02e8\5\u008fH\2\u02e4\u02e6\5\u0091I\2\u02e5"+
|
||||
"\u02e4\3\2\2\2\u02e5\u02e6\3\2\2\2\u02e6\u02e7\3\2\2\2\u02e7\u02e9\5\u008f"+
|
||||
"H\2\u02e8\u02e5\3\2\2\2\u02e8\u02e9\3\2\2\2\u02e9\u008e\3\2\2\2\u02ea"+
|
||||
"\u02eb\t\6\2\2\u02eb\u0090\3\2\2\2\u02ec\u02ee\5\u0093J\2\u02ed\u02ec"+
|
||||
"\3\2\2\2\u02ee\u02ef\3\2\2\2\u02ef\u02ed\3\2\2\2\u02ef\u02f0\3\2\2\2\u02f0"+
|
||||
"\u0092\3\2\2\2\u02f1\u02f4\5\u008fH\2\u02f2\u02f4\7a\2\2\u02f3\u02f1\3"+
|
||||
"\2\2\2\u02f3\u02f2\3\2\2\2\u02f4\u0094\3\2\2\2\u02f5\u02f6\7\62\2\2\u02f6"+
|
||||
"\u02f7\t\7\2\2\u02f7\u02f8\5\u0097L\2\u02f8\u0096\3\2\2\2\u02f9\u02fe"+
|
||||
"\5\u0099M\2\u02fa\u02fc\5\u009bN\2\u02fb\u02fa\3\2\2\2\u02fb\u02fc\3\2"+
|
||||
"\2\2\u02fc\u02fd\3\2\2\2\u02fd\u02ff\5\u0099M\2\u02fe\u02fb\3\2\2\2\u02fe"+
|
||||
"\u02ff\3\2\2\2\u02ff\u0098\3\2\2\2\u0300\u0301\t\b\2\2\u0301\u009a\3\2"+
|
||||
"\2\2\u0302\u0304\5\u009dO\2\u0303\u0302\3\2\2\2\u0304\u0305\3\2\2\2\u0305"+
|
||||
"\u0303\3\2\2\2\u0305\u0306\3\2\2\2\u0306\u009c\3\2\2\2\u0307\u030a\5\u0099"+
|
||||
"M\2\u0308\u030a\7a\2\2\u0309\u0307\3\2\2\2\u0309\u0308\3\2\2\2\u030a\u009e"+
|
||||
"\3\2\2\2\u030b\u030e\5\u00a1Q\2\u030c\u030e\5\u00adW\2\u030d\u030b\3\2"+
|
||||
"\2\2\u030d\u030c\3\2\2\2\u030e\u00a0\3\2\2\2\u030f\u0310\5u;\2\u0310\u0312"+
|
||||
"\7\60\2\2\u0311\u0313\5u;\2\u0312\u0311\3\2\2\2\u0312\u0313\3\2\2\2\u0313"+
|
||||
"\u0315\3\2\2\2\u0314\u0316\5\u00a3R\2\u0315\u0314\3\2\2\2\u0315\u0316"+
|
||||
"\3\2\2\2\u0316\u0318\3\2\2\2\u0317\u0319\5\u00abV\2\u0318\u0317\3\2\2"+
|
||||
"\2\u0318\u0319\3\2\2\2\u0319\u032b\3\2\2\2\u031a\u031b\7\60\2\2\u031b"+
|
||||
"\u031d\5u;\2\u031c\u031e\5\u00a3R\2\u031d\u031c\3\2\2\2\u031d\u031e\3"+
|
||||
"\2\2\2\u031e\u0320\3\2\2\2\u031f\u0321\5\u00abV\2\u0320\u031f\3\2\2\2"+
|
||||
"\u0320\u0321\3\2\2\2\u0321\u032b\3\2\2\2\u0322\u0323\5u;\2\u0323\u0325"+
|
||||
"\5\u00a3R\2\u0324\u0326\5\u00abV\2\u0325\u0324\3\2\2\2\u0325\u0326\3\2"+
|
||||
"\2\2\u0326\u032b\3\2\2\2\u0327\u0328\5u;\2\u0328\u0329\5\u00abV\2\u0329"+
|
||||
"\u032b\3\2\2\2\u032a\u030f\3\2\2\2\u032a\u031a\3\2\2\2\u032a\u0322\3\2"+
|
||||
"\2\2\u032a\u0327\3\2\2\2\u032b\u00a2\3\2\2\2\u032c\u032d\5\u00a5S\2\u032d"+
|
||||
"\u032e\5\u00a7T\2\u032e\u00a4\3\2\2\2\u032f\u0330\t\t\2\2\u0330\u00a6"+
|
||||
"\3\2\2\2\u0331\u0333\5\u00a9U\2\u0332\u0331\3\2\2\2\u0332\u0333\3\2\2"+
|
||||
"\2\u0333\u0334\3\2\2\2\u0334\u0335\5u;\2\u0335\u00a8\3\2\2\2\u0336\u0337"+
|
||||
"\t\n\2\2\u0337\u00aa\3\2\2\2\u0338\u0339\t\13\2\2\u0339\u00ac\3\2\2\2"+
|
||||
"\u033a\u033b\5\u00afX\2\u033b\u033d\5\u00b1Y\2\u033c\u033e\5\u00abV\2"+
|
||||
"\u033d\u033c\3\2\2\2\u033d\u033e\3\2\2\2\u033e\u00ae\3\2\2\2\u033f\u0341"+
|
||||
"\5\u0081A\2\u0340\u0342\7\60\2\2\u0341\u0340\3\2\2\2\u0341\u0342\3\2\2"+
|
||||
"\2\u0342\u034b\3\2\2\2\u0343\u0344\7\62\2\2\u0344\u0346\t\4\2\2\u0345"+
|
||||
"\u0347\5\u0083B\2\u0346\u0345\3\2\2\2\u0346\u0347\3\2\2\2\u0347\u0348"+
|
||||
"\3\2\2\2\u0348\u0349\7\60\2\2\u0349\u034b\5\u0083B\2\u034a\u033f\3\2\2"+
|
||||
"\2\u034a\u0343\3\2\2\2\u034b\u00b0\3\2\2\2\u034c\u034d\5\u00b3Z\2\u034d"+
|
||||
"\u034e\5\u00a7T\2\u034e\u00b2\3\2\2\2\u034f\u0350\t\f\2\2\u0350\u00b4"+
|
||||
"\3\2\2\2\u0351\u0352\7v\2\2\u0352\u0353\7t\2\2\u0353\u0354\7w\2\2\u0354"+
|
||||
"\u035b\7g\2\2\u0355\u0356\7h\2\2\u0356\u0357\7c\2\2\u0357\u0358\7n\2\2"+
|
||||
"\u0358\u0359\7u\2\2\u0359\u035b\7g\2\2\u035a\u0351\3\2\2\2\u035a\u0355"+
|
||||
"\3\2\2\2\u035b\u00b6\3\2\2\2\u035c\u035d\7)\2\2\u035d\u035e\5\u00b9]\2"+
|
||||
"\u035e\u035f\7)\2\2\u035f\u0365\3\2\2\2\u0360\u0361\7)\2\2\u0361\u0362"+
|
||||
"\5\u00c1a\2\u0362\u0363\7)\2\2\u0363\u0365\3\2\2\2\u0364\u035c\3\2\2\2"+
|
||||
"\u0364\u0360\3\2\2\2\u0365\u00b8\3\2\2\2\u0366\u0367\n\r\2\2\u0367\u00ba"+
|
||||
"\3\2\2\2\u0368\u036a\7$\2\2\u0369\u036b\5\u00bd_\2\u036a\u0369\3\2\2\2"+
|
||||
"\u036a\u036b\3\2\2\2\u036b\u036c\3\2\2\2\u036c\u036d\7$\2\2\u036d\u00bc"+
|
||||
"\3\2\2\2\u036e\u0370\5\u00bf`\2\u036f\u036e\3\2\2\2\u0370\u0371\3\2\2"+
|
||||
"\2\u0371\u036f\3\2\2\2\u0371\u0372\3\2\2\2\u0372\u00be\3\2\2\2\u0373\u0376"+
|
||||
"\n\16\2\2\u0374\u0376\5\u00c1a\2\u0375\u0373\3\2\2\2\u0375\u0374\3\2\2"+
|
||||
"\2\u0376\u00c0\3\2\2\2\u0377\u0378\7^\2\2\u0378\u037c\t\17\2\2\u0379\u037c"+
|
||||
"\5\u00c3b\2\u037a\u037c\5\u00c7d\2\u037b\u0377\3\2\2\2\u037b\u0379\3\2"+
|
||||
"\2\2\u037b\u037a\3\2\2\2\u037c\u00c2\3\2\2\2\u037d\u037e\7^\2\2\u037e"+
|
||||
"\u0389\5\u008fH\2\u037f\u0380\7^\2\2\u0380\u0381\5\u008fH\2\u0381\u0382"+
|
||||
"\5\u008fH\2\u0382\u0389\3\2\2\2\u0383\u0384\7^\2\2\u0384\u0385\5\u00c5"+
|
||||
"c\2\u0385\u0386\5\u008fH\2\u0386\u0387\5\u008fH\2\u0387\u0389\3\2\2\2"+
|
||||
"\u0388\u037d\3\2\2\2\u0388\u037f\3\2\2\2\u0388\u0383\3\2\2\2\u0389\u00c4"+
|
||||
"\3\2\2\2\u038a\u038b\t\20\2\2\u038b\u00c6\3\2\2\2\u038c\u038d\7^\2\2\u038d"+
|
||||
"\u038e\7w\2\2\u038e\u038f\5\u0085C\2\u038f\u0390\5\u0085C\2\u0390\u0391"+
|
||||
"\5\u0085C\2\u0391\u0392\5\u0085C\2\u0392\u00c8\3\2\2\2\u0393\u0394\7p"+
|
||||
"\2\2\u0394\u0395\7w\2\2\u0395\u0396\7n\2\2\u0396\u0397\7n\2\2\u0397\u00ca"+
|
||||
"\3\2\2\2\u0398\u0399\7*\2\2\u0399\u00cc\3\2\2\2\u039a\u039b\7+\2\2\u039b"+
|
||||
"\u00ce\3\2\2\2\u039c\u039d\7}\2\2\u039d\u00d0\3\2\2\2\u039e\u039f\7\177"+
|
||||
"\2\2\u039f\u00d2\3\2\2\2\u03a0\u03a1\7]\2\2\u03a1\u00d4\3\2\2\2\u03a2"+
|
||||
"\u03a3\7_\2\2\u03a3\u00d6\3\2\2\2\u03a4\u03a5\7=\2\2\u03a5\u00d8\3\2\2"+
|
||||
"\2\u03a6\u03a7\7.\2\2\u03a7\u00da\3\2\2\2\u03a8\u03a9\7\60\2\2\u03a9\u00dc"+
|
||||
"\3\2\2\2\u03aa\u03ab\7?\2\2\u03ab\u00de\3\2\2\2\u03ac\u03ad\7@\2\2\u03ad"+
|
||||
"\u00e0\3\2\2\2\u03ae\u03af\7>\2\2\u03af\u00e2\3\2\2\2\u03b0\u03b1\7#\2"+
|
||||
"\2\u03b1\u00e4\3\2\2\2\u03b2\u03b3\7\u0080\2\2\u03b3\u00e6\3\2\2\2\u03b4"+
|
||||
"\u03b5\7A\2\2\u03b5\u00e8\3\2\2\2\u03b6\u03b7\7<\2\2\u03b7\u00ea\3\2\2"+
|
||||
"\2\u03b8\u03b9\7?\2\2\u03b9\u03ba\7?\2\2\u03ba\u00ec\3\2\2\2\u03bb\u03bc"+
|
||||
"\7>\2\2\u03bc\u03bd\7?\2\2\u03bd\u00ee\3\2\2\2\u03be\u03bf\7@\2\2\u03bf"+
|
||||
"\u03c0\7?\2\2\u03c0\u00f0\3\2\2\2\u03c1\u03c2\7#\2\2\u03c2\u03c3\7?\2"+
|
||||
"\2\u03c3\u00f2\3\2\2\2\u03c4\u03c5\7(\2\2\u03c5\u03c6\7(\2\2\u03c6\u00f4"+
|
||||
"\3\2\2\2\u03c7\u03c8\7~\2\2\u03c8\u03c9\7~\2\2\u03c9\u00f6\3\2\2\2\u03ca"+
|
||||
"\u03cb\7-\2\2\u03cb\u03cc\7-\2\2\u03cc\u00f8\3\2\2\2\u03cd\u03ce\7/\2"+
|
||||
"\2\u03ce\u03cf\7/\2\2\u03cf\u00fa\3\2\2\2\u03d0\u03d1\7-\2\2\u03d1\u00fc"+
|
||||
"\3\2\2\2\u03d2\u03d3\7/\2\2\u03d3\u00fe\3\2\2\2\u03d4\u03d5\7,\2\2\u03d5"+
|
||||
"\u0100\3\2\2\2\u03d6\u03d7\7\61\2\2\u03d7\u0102\3\2\2\2\u03d8\u03d9\7"+
|
||||
"(\2\2\u03d9\u0104\3\2\2\2\u03da\u03db\7~\2\2\u03db\u0106\3\2\2\2\u03dc"+
|
||||
"\u03dd\7`\2\2\u03dd\u0108\3\2\2\2\u03de\u03df\7\'\2\2\u03df\u010a\3\2"+
|
||||
"\2\2\u03e0\u03e1\7/\2\2\u03e1\u03e2\7@\2\2\u03e2\u010c\3\2\2\2\u03e3\u03e4"+
|
||||
"\7<\2\2\u03e4\u03e5\7<\2\2\u03e5\u010e\3\2\2\2\u03e6\u03e7\7-\2\2\u03e7"+
|
||||
"\u03e8\7?\2\2\u03e8\u0110\3\2\2\2\u03e9\u03ea\7/\2\2\u03ea\u03eb\7?\2"+
|
||||
"\2\u03eb\u0112\3\2\2\2\u03ec\u03ed\7,\2\2\u03ed\u03ee\7?\2\2\u03ee\u0114"+
|
||||
"\3\2\2\2\u03ef\u03f0\7\61\2\2\u03f0\u03f1\7?\2\2\u03f1\u0116\3\2\2\2\u03f2"+
|
||||
"\u03f3\7(\2\2\u03f3\u03f4\7?\2\2\u03f4\u0118\3\2\2\2\u03f5\u03f6\7~\2"+
|
||||
"\2\u03f6\u03f7\7?\2\2\u03f7\u011a\3\2\2\2\u03f8\u03f9\7`\2\2\u03f9\u03fa"+
|
||||
"\7?\2\2\u03fa\u011c\3\2\2\2\u03fb\u03fc\7\'\2\2\u03fc\u03fd\7?\2\2\u03fd"+
|
||||
"\u011e\3\2\2\2\u03fe\u03ff\7>\2\2\u03ff\u0400\7>\2\2\u0400\u0401\7?\2"+
|
||||
"\2\u0401\u0120\3\2\2\2\u0402\u0403\7@\2\2\u0403\u0404\7@\2\2\u0404\u0405"+
|
||||
"\7?\2\2\u0405\u0122\3\2\2\2\u0406\u0407\7@\2\2\u0407\u0408\7@\2\2\u0408"+
|
||||
"\u0409\7@\2\2\u0409\u040a\7?\2\2\u040a\u0124\3\2\2\2\u040b\u040f\5\u0127"+
|
||||
"\u0094\2\u040c\u040e\5\u0129\u0095\2\u040d\u040c\3\2\2\2\u040e\u0411\3"+
|
||||
"\2\2\2\u040f\u040d\3\2\2\2\u040f\u0410\3\2\2\2\u0410\u0126\3\2\2\2\u0411"+
|
||||
"\u040f\3\2\2\2\u0412\u0419\t\21\2\2\u0413\u0414\n\22\2\2\u0414\u0419\6"+
|
||||
"\u0094\2\2\u0415\u0416\t\23\2\2\u0416\u0417\t\24\2\2\u0417\u0419\6\u0094"+
|
||||
"\3\2\u0418\u0412\3\2\2\2\u0418\u0413\3\2\2\2\u0418\u0415\3\2\2\2\u0419"+
|
||||
"\u0128\3\2\2\2\u041a\u0421\t\25\2\2\u041b\u041c\n\22\2\2\u041c\u0421\6"+
|
||||
"\u0095\4\2\u041d\u041e\t\23\2\2\u041e\u041f\t\24\2\2\u041f\u0421\6\u0095"+
|
||||
"\5\2\u0420\u041a\3\2\2\2\u0420\u041b\3\2\2\2\u0420\u041d\3\2\2\2\u0421"+
|
||||
"\u012a\3\2\2\2\u0422\u0423\7B\2\2\u0423\u012c\3\2\2\2\u0424\u0425\7\60"+
|
||||
"\2\2\u0425\u0426\7\60\2\2\u0426\u0427\7\60\2\2\u0427\u012e\3\2\2\2\u0428"+
|
||||
"\u042a\t\26\2\2\u0429\u0428\3\2\2\2\u042a\u042b\3\2\2\2\u042b\u0429\3"+
|
||||
"\2\2\2\u042b\u042c\3\2\2\2\u042c\u042d\3\2\2\2\u042d\u042e\b\u0098\2\2"+
|
||||
"\u042e\u0130\3\2\2\2\u042f\u0430\7\61\2\2\u0430\u0431\7,\2\2\u0431\u0435"+
|
||||
"\3\2\2\2\u0432\u0434\13\2\2\2\u0433\u0432\3\2\2\2\u0434\u0437\3\2\2\2"+
|
||||
"\u0435\u0436\3\2\2\2\u0435\u0433\3\2\2\2\u0436\u0438\3\2\2\2\u0437\u0435"+
|
||||
"\3\2\2\2\u0438\u0439\7,\2\2\u0439\u043a\7\61\2\2\u043a\u043b\3\2\2\2\u043b"+
|
||||
"\u043c\b\u0099\2\2\u043c\u0132\3\2\2\2\u043d\u043e\7\61\2\2\u043e\u043f"+
|
||||
"\7\61\2\2\u043f\u0443\3\2\2\2\u0440\u0442\n\27\2\2\u0441\u0440\3\2\2\2"+
|
||||
"\u0442\u0445\3\2\2\2\u0443\u0441\3\2\2\2\u0443\u0444\3\2\2\2\u0444\u0446"+
|
||||
"\3\2\2\2\u0445\u0443\3\2\2\2\u0446\u0447\b\u009a\2\2\u0447\u0134\3\2\2"+
|
||||
"\28\2\u028c\u0290\u0294\u0298\u029c\u02a3\u02a8\u02aa\u02ae\u02b1\u02b5"+
|
||||
"\u02bc\u02c0\u02c5\u02cd\u02d0\u02d7\u02db\u02df\u02e5\u02e8\u02ef\u02f3"+
|
||||
"\u02fb\u02fe\u0305\u0309\u030d\u0312\u0315\u0318\u031d\u0320\u0325\u032a"+
|
||||
"\u0332\u033d\u0341\u0346\u034a\u035a\u0364\u036a\u0371\u0375\u037b\u0388"+
|
||||
"\u040f\u0418\u0420\u042b\u0435\u0443\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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
ABSTRACT=1
|
||||
ASSERT=2
|
||||
BOOLEAN=3
|
||||
BREAK=4
|
||||
BYTE=5
|
||||
CASE=6
|
||||
CATCH=7
|
||||
CHAR=8
|
||||
CLASS=9
|
||||
CONST=10
|
||||
CONTINUE=11
|
||||
DEFAULT=12
|
||||
DO=13
|
||||
DOUBLE=14
|
||||
ELSE=15
|
||||
ENUM=16
|
||||
EXTENDS=17
|
||||
FINAL=18
|
||||
FINALLY=19
|
||||
FLOAT=20
|
||||
FOR=21
|
||||
IF=22
|
||||
GOTO=23
|
||||
IMPLEMENTS=24
|
||||
IMPORT=25
|
||||
INSTANCEOF=26
|
||||
INT=27
|
||||
INTERFACE=28
|
||||
LONG=29
|
||||
NATIVE=30
|
||||
NEW=31
|
||||
PACKAGE=32
|
||||
PRIVATE=33
|
||||
PROTECTED=34
|
||||
PUBLIC=35
|
||||
RETURN=36
|
||||
SHORT=37
|
||||
STATIC=38
|
||||
STRICTFP=39
|
||||
SUPER=40
|
||||
SWITCH=41
|
||||
SYNCHRONIZED=42
|
||||
THIS=43
|
||||
THROW=44
|
||||
THROWS=45
|
||||
TRANSIENT=46
|
||||
TRY=47
|
||||
VOID=48
|
||||
VOLATILE=49
|
||||
WHILE=50
|
||||
IntegerLiteral=51
|
||||
FloatingPointLiteral=52
|
||||
BooleanLiteral=53
|
||||
CharacterLiteral=54
|
||||
StringLiteral=55
|
||||
NullLiteral=56
|
||||
LPAREN=57
|
||||
RPAREN=58
|
||||
LBRACE=59
|
||||
RBRACE=60
|
||||
LBRACK=61
|
||||
RBRACK=62
|
||||
SEMI=63
|
||||
COMMA=64
|
||||
DOT=65
|
||||
ASSIGN=66
|
||||
GT=67
|
||||
LT=68
|
||||
BANG=69
|
||||
TILDE=70
|
||||
QUESTION=71
|
||||
COLON=72
|
||||
EQUAL=73
|
||||
LE=74
|
||||
GE=75
|
||||
NOTEQUAL=76
|
||||
AND=77
|
||||
OR=78
|
||||
INC=79
|
||||
DEC=80
|
||||
ADD=81
|
||||
SUB=82
|
||||
MUL=83
|
||||
DIV=84
|
||||
BITAND=85
|
||||
BITOR=86
|
||||
CARET=87
|
||||
MOD=88
|
||||
ARROW=89
|
||||
COLONCOLON=90
|
||||
ADD_ASSIGN=91
|
||||
SUB_ASSIGN=92
|
||||
MUL_ASSIGN=93
|
||||
DIV_ASSIGN=94
|
||||
AND_ASSIGN=95
|
||||
OR_ASSIGN=96
|
||||
XOR_ASSIGN=97
|
||||
MOD_ASSIGN=98
|
||||
LSHIFT_ASSIGN=99
|
||||
RSHIFT_ASSIGN=100
|
||||
URSHIFT_ASSIGN=101
|
||||
Identifier=102
|
||||
AT=103
|
||||
ELLIPSIS=104
|
||||
WS=105
|
||||
COMMENT=106
|
||||
LINE_COMMENT=107
|
||||
'abstract'=1
|
||||
'assert'=2
|
||||
'boolean'=3
|
||||
'break'=4
|
||||
'byte'=5
|
||||
'case'=6
|
||||
'catch'=7
|
||||
'char'=8
|
||||
'class'=9
|
||||
'const'=10
|
||||
'continue'=11
|
||||
'default'=12
|
||||
'do'=13
|
||||
'double'=14
|
||||
'else'=15
|
||||
'enum'=16
|
||||
'extends'=17
|
||||
'final'=18
|
||||
'finally'=19
|
||||
'float'=20
|
||||
'for'=21
|
||||
'if'=22
|
||||
'goto'=23
|
||||
'implements'=24
|
||||
'import'=25
|
||||
'instanceof'=26
|
||||
'int'=27
|
||||
'interface'=28
|
||||
'long'=29
|
||||
'native'=30
|
||||
'new'=31
|
||||
'package'=32
|
||||
'private'=33
|
||||
'protected'=34
|
||||
'public'=35
|
||||
'return'=36
|
||||
'short'=37
|
||||
'static'=38
|
||||
'strictfp'=39
|
||||
'super'=40
|
||||
'switch'=41
|
||||
'synchronized'=42
|
||||
'this'=43
|
||||
'throw'=44
|
||||
'throws'=45
|
||||
'transient'=46
|
||||
'try'=47
|
||||
'void'=48
|
||||
'volatile'=49
|
||||
'while'=50
|
||||
'null'=56
|
||||
'('=57
|
||||
')'=58
|
||||
'{'=59
|
||||
'}'=60
|
||||
'['=61
|
||||
']'=62
|
||||
';'=63
|
||||
','=64
|
||||
'.'=65
|
||||
'='=66
|
||||
'>'=67
|
||||
'<'=68
|
||||
'!'=69
|
||||
'~'=70
|
||||
'?'=71
|
||||
':'=72
|
||||
'=='=73
|
||||
'<='=74
|
||||
'>='=75
|
||||
'!='=76
|
||||
'&&'=77
|
||||
'||'=78
|
||||
'++'=79
|
||||
'--'=80
|
||||
'+'=81
|
||||
'-'=82
|
||||
'*'=83
|
||||
'/'=84
|
||||
'&'=85
|
||||
'|'=86
|
||||
'^'=87
|
||||
'%'=88
|
||||
'->'=89
|
||||
'::'=90
|
||||
'+='=91
|
||||
'-='=92
|
||||
'*='=93
|
||||
'/='=94
|
||||
'&='=95
|
||||
'|='=96
|
||||
'^='=97
|
||||
'%='=98
|
||||
'<<='=99
|
||||
'>>='=100
|
||||
'>>>='=101
|
||||
'@'=103
|
||||
'...'=104
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.parser;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ASPParser {
|
||||
ResultSet parse(String result){
|
||||
Set<ResultPair> ret = new HashSet<>();
|
||||
for(String pair : result.split(",")){
|
||||
|
||||
}
|
||||
return new ResultSet(ret);
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.sat.asp.parser.model;
|
||||
|
||||
public class ParsedASPStatement {
|
||||
public ParsedASPStatement(String statement){
|
||||
|
||||
}
|
||||
}
|
@ -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,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;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.assumptions;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.GenericsResolver;
|
||||
|
||||
public class FieldAssumption extends Assumption{
|
||||
private ClassOrInterface receiverClass;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric type;
|
||||
|
||||
public FieldAssumption(ClassOrInterface receiverType,
|
||||
RefTypeOrTPHOrWildcardOrGeneric type, TypeScope scope){
|
||||
super(scope);
|
||||
this.type = type;
|
||||
this.receiverClass = receiverType;
|
||||
}
|
||||
|
||||
public ClassOrInterface getReceiverClass() {
|
||||
return receiverClass;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getType(GenericsResolver resolver) {
|
||||
return resolver.resolve(type);
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,412 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.typeAlgo;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.*;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TYPEStmt implements StatementVisitor{
|
||||
|
||||
private final TypeInferenceBlockInformation info;
|
||||
private final ConstraintSet constraintsSet = new ConstraintSet();
|
||||
|
||||
public TYPEStmt(TypeInferenceBlockInformation info){
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public ConstraintSet getConstraints() {
|
||||
return constraintsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen neuen GenericResolver
|
||||
* Die Idee dieser Datenstruktur ist es, GTVs einen eindeutigen TPH zuzuweisen.
|
||||
* Bei Methodenaufrufen oder anderen Zugriffen, bei denen alle benutzten GTVs jeweils einen einheitlichen TPH bekommen müssen
|
||||
* kann diese Klasse eingesetzt werden. Wichtig ist, dass hierfür jeweils eine frische Instanz benutzt wird.
|
||||
* @return
|
||||
*/
|
||||
private static GenericsResolver getResolverInstance(){
|
||||
return new GenericsResolverSameName();
|
||||
}
|
||||
|
||||
private static TypeScope createTypeScope(ClassOrInterface cl, Method method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList arglist) {
|
||||
for(int i = 0;i<arglist.getArguments().size();i++){
|
||||
arglist.getArguments().get(i).accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
TypePlaceholder tphRetType = TypePlaceholder.fresh(new NullToken());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> lambdaParams = lambdaExpression.params.getFormalparalist().stream().map((formalParameter -> formalParameter.getType())).collect(Collectors.toList());
|
||||
//lambdaParams.add(tphRetType);
|
||||
lambdaParams.add(0,tphRetType);
|
||||
constraintsSet.addUndConstraint(
|
||||
new Pair(lambdaExpression.getType(),
|
||||
new FunN(lambdaParams),PairOperator.EQUALSDOT));
|
||||
constraintsSet.addUndConstraint(
|
||||
new Pair(lambdaExpression.getReturnType(),
|
||||
tphRetType,PairOperator.EQUALSDOT));
|
||||
|
||||
//Constraints des Bodys generieren:
|
||||
TYPEStmt lambdaScope = new TYPEStmt(new TypeInferenceBlockInformation(info, lambdaExpression));
|
||||
lambdaExpression.methodBody.accept(lambdaScope);
|
||||
constraintsSet.addAll(lambdaScope.getConstraints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
assign.lefSide.accept(this);
|
||||
assign.rightSide.accept(this);
|
||||
constraintsSet.addUndConstraint(new Pair(
|
||||
assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
for(Statement stmt : block.getStatements()){
|
||||
stmt.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
//Nothing :)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
fieldVar.receiver.accept(this);
|
||||
Set<Constraint> oderConstraints = new HashSet<>();
|
||||
for(FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)){
|
||||
Constraint constraint = new Constraint();
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
/*TODO Hier muss der Typ der Klasse ermittelt werden. In diesem müssen Generics mit TPHs ausgetauscht werden
|
||||
constraint.add(ConstraintsFactory.createPair(
|
||||
fieldVar.receiver.getType(),fieldAssumption.getReceiverType(), info.getCurrentTypeScope(), fieldAssumption.getTypeScope(), resolver));
|
||||
*/
|
||||
constraint.add(new Pair(fieldVar.receiver.getType(), fieldAssumption.getReceiverType(resolver), PairOperator.EQUALSDOT));
|
||||
constraint.add(new Pair(
|
||||
fieldVar.getType(), fieldAssumption.getType(resolver), PairOperator.EQUALSDOT));
|
||||
oderConstraints.add(constraint);
|
||||
}
|
||||
if(oderConstraints.size() == 0)
|
||||
throw new TypeinferenceException("Kein Feld "+fieldVar.fieldVarName+ " gefunden", fieldVar.getOffset());
|
||||
constraintsSet.addOderConstraint(oderConstraints);
|
||||
|
||||
//Wegen dem Problem oben:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
// Es werden nur bei Feldvariablen Constraints generiert. Lokale Variablen sind eindeutig
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
//Hier ist nichts zu tun. Allen lokalen Variablen bekommen beim parsen schon den korrekten Typ
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.receiver.accept(this);
|
||||
//Overloading:
|
||||
Set<Constraint> methodConstraints = new HashSet<>();
|
||||
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
methodConstraints.add(generateConstraint(methodCall, m, info, resolver));
|
||||
}
|
||||
if(methodConstraints.size()<1){
|
||||
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());
|
||||
}
|
||||
constraintsSet.addOderConstraint(methodConstraints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
//Overloading:
|
||||
Set<Constraint> methodConstraints = new HashSet<>();
|
||||
for(MethodAssumption m : this.getConstructors(info, (RefType) methodCall.getType(), methodCall.getArgumentList())){
|
||||
methodConstraints.add(generateConstructorConstraint(methodCall, m, info, getResolverInstance()));
|
||||
}
|
||||
if(methodConstraints.size()<1){
|
||||
throw new TypeinferenceException("Konstruktor in Klasse "+methodCall.getType().toString()+" ist nicht vorhanden!",methodCall.getOffset());
|
||||
}
|
||||
constraintsSet.addOderConstraint(methodConstraints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver receiver) {
|
||||
receiver.expr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT ||
|
||||
unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT ||
|
||||
unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT ||
|
||||
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
|
||||
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
||||
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||
RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset());
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT));
|
||||
//The type of the postfix increment expression is the type of the variable
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
//Nothing to do here. Literale kriegen beim parsen den korrekten Typ.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return returnExpr) {
|
||||
returnExpr.retexpr.accept(this);
|
||||
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
visit((Return) aReturn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
//Hier entstehen keine Constraints
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
//Im Falle von this, müssen die Generics in der Klasse als RefTypes behandelt werden.
|
||||
ClassOrInterface currentClass = info.getCurrentClass();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(GenericTypeVar gtv : currentClass.getGenerics()){
|
||||
params.add(new GenericRefType(gtv.getName(), aThis.getOffset()));
|
||||
}
|
||||
RefType thisType = new RefType(currentClass.getClassName(), params, aThis.getOffset());
|
||||
constraintsSet.addUndConstraint(new Pair(
|
||||
aThis.getType(), thisType, PairOperator.EQUALSDOT));
|
||||
}
|
||||
|
||||
private static TypeScope createNullTypeScope() {
|
||||
return new TypeScope() {
|
||||
@Override
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken());
|
||||
//Expression inferieren:
|
||||
whileStmt.expr.accept(this);
|
||||
//Expression muss boolean sein:
|
||||
constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT));
|
||||
//LoopBlock inferieren:
|
||||
whileStmt.loopBlock.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
//Hier ist kein Code nötig. Es werden keine extra Constraints generiert
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
//Hier ist kein Code nötig. Es werden keine extra Constraints generiert
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
//TODO: Für einen super-Call werden keine Constraints erzeugt bisher
|
||||
}
|
||||
|
||||
/*
|
||||
METHOD CALL Section:
|
||||
*/
|
||||
|
||||
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||
Constraint methodConstraint = new Constraint();
|
||||
ClassOrInterface receiverCl = assumption.getReceiver();
|
||||
/*
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(GenericTypeVar gtv : receiverCl.getGenerics()){
|
||||
//Die Generics werden alle zu TPHs umgewandelt.
|
||||
params.add(resolver.resolve(gtv.getParsedName()));
|
||||
}
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiverType = new RefType(assumption.getReceiver().getClassName(), params, forMethod.getOffset());
|
||||
*/
|
||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), assumption.getReceiverType(resolver),
|
||||
PairOperator.SMALLERDOT));
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(), forMethod.getType(),
|
||||
PairOperator.EQUALSDOT));
|
||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||
return methodConstraint;
|
||||
}
|
||||
|
||||
protected Set<Pair> generateParameterConstraints(MethodCall foMethod, MethodAssumption assumption,
|
||||
TypeInferenceBlockInformation info, GenericsResolver resolver) {
|
||||
Set<Pair> ret = new HashSet<>();
|
||||
for(int i = 0;i<foMethod.arglist.getArguments().size();i++){
|
||||
foMethod.arglist.getArguments().get(i).accept(this);
|
||||
RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType();
|
||||
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
||||
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static List<MethodAssumption> getMethods(String name, int numArgs, TypeInferenceBlockInformation info) {
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
//TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken)
|
||||
if(name.equals("apply")){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||
for(int i = 0; i< numArgs + 1 ; i++){
|
||||
funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
||||
}
|
||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()),
|
||||
new TypeScope() {
|
||||
@Override
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}));
|
||||
}
|
||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||
for(Method m : cl.getMethods()){
|
||||
if(m.getName().equals(name) &&
|
||||
m.getParameterList().getFormalparalist().size() == numArgs){
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getReturnType());
|
||||
|
||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
||||
createTypeScope(cl, m)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<MethodAssumption> getMethods(String name, ArgumentList arglist, TypeInferenceBlockInformation info) {
|
||||
return getMethods(name, arglist.getArguments().size(), info);
|
||||
}
|
||||
|
||||
protected static List<RefTypeOrTPHOrWildcardOrGeneric> convertParams(ParameterList parameterList, TypeInferenceBlockInformation info){
|
||||
//TODO: Hier müssen die Parameter mit den TPHs in den GEnerics des Receivers verknüpft werden
|
||||
/*
|
||||
BEispiel:
|
||||
auto test = new List<String>();
|
||||
test.add("hallo");
|
||||
|
||||
Hier kriegt der Receiver ja den COnstraint TPH REceiver <. List<TPH A>
|
||||
Dann mus bei dem Parameter der COnstraint entstehen: TPH A <. String
|
||||
*/
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(FormalParameter fp : parameterList.getFormalparalist()){
|
||||
params.add(info.checkGTV(fp.getType()));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public List<MethodAssumption> getConstructors(TypeInferenceBlockInformation info, RefType ofType, ArgumentList argList){
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||
if(cl.getClassName().equals(ofType.getName())){
|
||||
for(Method m : cl.getConstructors()){
|
||||
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
||||
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
||||
info), createTypeScope(cl, m)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected Constraint<Pair> generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption,
|
||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||
Constraint methodConstraint = new Constraint();
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(), forConstructor.getType(),
|
||||
PairOperator.SMALLERDOT));
|
||||
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
||||
return methodConstraint;
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class TypeUnify {
|
||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
pool.invoke(unifyTask);
|
||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||
return res;
|
||||
}
|
||||
|
||||
public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc) {
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false);
|
||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
@ -1,634 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the type unification algorithm
|
||||
* @author Florian Steurer
|
||||
*/
|
||||
public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The implementation of setOps that will be used during the unification
|
||||
*/
|
||||
protected ISetOperations setOps = new GuavaSetOperations();
|
||||
|
||||
/**
|
||||
* The implementation of the standard unify that will be used during the unification
|
||||
*/
|
||||
protected IUnify stdUnify = new MartelliMontanariUnify();
|
||||
|
||||
/**
|
||||
* The implementation of the rules that will be used during the unification.
|
||||
*/
|
||||
protected IRuleSet rules = new RuleSet();
|
||||
|
||||
protected Set<UnifyPair> eq;
|
||||
|
||||
protected IFiniteClosure fc;
|
||||
|
||||
protected boolean parallel;
|
||||
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||
this.eq = eq;
|
||||
this.fc = fc;
|
||||
this.parallel = parallel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Set<UnifyPair>> compute() {
|
||||
return unify(eq, fc, parallel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes all principal type unifiers for a set of constraints.
|
||||
* @param eq The set of constraints
|
||||
* @param fc The finite closure
|
||||
* @return The set of all principal type unifiers
|
||||
*/
|
||||
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||
/*
|
||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||
*/
|
||||
Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc);
|
||||
|
||||
/*
|
||||
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
|
||||
*/
|
||||
Set<UnifyPair> eq1s = new HashSet<>();
|
||||
Set<UnifyPair> eq2s = new HashSet<>();
|
||||
splitEq(eq0, eq1s, eq2s);
|
||||
|
||||
/*
|
||||
* Step 4: Create possible typings
|
||||
*
|
||||
* "Manche Autoren identifizieren die Paare (a, (b,c)) und ((a,b),c)
|
||||
* mit dem geordneten Tripel (a,b,c), wodurch das kartesische Produkt auch assoziativ wird." - Wikipedia
|
||||
*/
|
||||
|
||||
// There are up to 10 toplevel set. 8 of 10 are the result of the
|
||||
// cartesian product of the sets created by pattern matching.
|
||||
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
||||
|
||||
if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty.
|
||||
Set<Set<UnifyPair>> wrap = new HashSet<>();
|
||||
wrap.add(eq1s);
|
||||
topLevelSets.add(wrap); // Add Eq1'
|
||||
}
|
||||
|
||||
// Add the set of [a =. Theta | (a=. Theta) in Eq2']
|
||||
Set<UnifyPair> bufferSet = eq2s.stream()
|
||||
.filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if(bufferSet.size() != 0) { // Do not add empty sets or the cartesian product will always be empty.
|
||||
Set<Set<UnifyPair>> wrap = new HashSet<>();
|
||||
wrap.add(bufferSet);
|
||||
topLevelSets.add(wrap);
|
||||
eq2s.removeAll(bufferSet);
|
||||
}
|
||||
|
||||
// Sets that originate from pair pattern matching
|
||||
// Sets of the "second level"
|
||||
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
||||
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
|
||||
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
|
||||
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
||||
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
||||
//Typen getestet werden.
|
||||
// If pairs occured that did not match one of the cartesian product cases,
|
||||
// those pairs are contradictory and the unification is impossible.
|
||||
if(!undefinedPairs.isEmpty())
|
||||
return new HashSet<>();
|
||||
|
||||
/* Up to here, no cartesian products are calculated.
|
||||
* filters for pairs and sets can be applied here */
|
||||
|
||||
// Sub cartesian products of the second level (pattern matched) sets
|
||||
// "the big (x)"
|
||||
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||
List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
|
||||
Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
|
||||
|
||||
// Flatten and add to top level sets
|
||||
Set<Set<UnifyPair>> flat = new HashSet<>();
|
||||
for(List<Set<UnifyPair>> s : cartResult) {
|
||||
Set<UnifyPair> flat1 = new HashSet<>();
|
||||
for(Set<UnifyPair> s1 : s)
|
||||
flat1.addAll(s1);
|
||||
flat.add(flat1);
|
||||
}
|
||||
topLevelSets.add(flat);
|
||||
}
|
||||
|
||||
// Cartesian product over all (up to 10) top level sets
|
||||
Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
||||
.stream().map(x -> new HashSet<>(x))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||
|
||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
|
||||
// Flatten the cartesian product
|
||||
Set<UnifyPair> eqPrime = new HashSet<>();
|
||||
setToFlatten.stream().forEach(x -> eqPrime.addAll(x));
|
||||
|
||||
/*
|
||||
* Step 5: Substitution
|
||||
*/
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
|
||||
/*
|
||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||
*/
|
||||
if(parallel) {
|
||||
if //(eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch
|
||||
(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt
|
||||
//Begruendung: Wenn in der Substitution keine Veraenderung
|
||||
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent()) {
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
else {
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
}
|
||||
else { // sequentiell (Step 6b is included)
|
||||
if //(eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch
|
||||
(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt
|
||||
//Begruendung: Wenn in der Substitution keine Veraenderung
|
||||
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent())
|
||||
eqPrimePrimeSet.addAll(unify(eqPrimePrime.get(), fc, false));
|
||||
else
|
||||
eqPrimePrimeSet.addAll(unify(eqPrime, fc, false));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Step 6 b) Build the union over everything.
|
||||
*/
|
||||
|
||||
if(parallel)
|
||||
for(TypeUnifyTask fork : forks)
|
||||
eqPrimePrimeSet.addAll(fork.join());
|
||||
|
||||
/*
|
||||
* Step 7: Filter empty sets;
|
||||
*/
|
||||
return eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a set of pairs is in solved form.
|
||||
* @param eqPrimePrime The set of pair
|
||||
* @return True if in solved form, false otherwise.
|
||||
*/
|
||||
protected boolean isSolvedForm(Set<UnifyPair> eqPrimePrime) {
|
||||
for(UnifyPair pair : eqPrimePrime) {
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
||||
if(!(lhsType instanceof PlaceholderType))
|
||||
return false;
|
||||
|
||||
// If operator is not equals, both sides must be placeholders
|
||||
if(pair.getPairOp() != PairOperator.EQUALSDOT && !(rhsType instanceof PlaceholderType))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeatedly applies type unification rules to a set of equations.
|
||||
* This is step one of the unification algorithm.
|
||||
* @return The set of pairs that results from repeated application of the inference rules.
|
||||
*/
|
||||
protected Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> eq, IFiniteClosure fc) {
|
||||
|
||||
/*
|
||||
* Rule Application Strategy:
|
||||
*
|
||||
* 1. Swap all pairs and erase all erasable pairs
|
||||
* 2. Apply all possible rules to a single pair, then move it to the result set.
|
||||
* Iterating over pairs first, then iterating over rules prevents the application
|
||||
* of rules to a "finished" pair over and over.
|
||||
* 2.1 Apply all rules repeatedly except for erase rules. If
|
||||
* the application of a rule creates new pairs, check immediately
|
||||
* against the erase rules.
|
||||
*/
|
||||
|
||||
|
||||
LinkedHashSet<UnifyPair> targetSet = new LinkedHashSet<UnifyPair>();
|
||||
LinkedList<UnifyPair> eqQueue = new LinkedList<>();
|
||||
|
||||
/*
|
||||
* Swap all pairs and erase all erasable pairs
|
||||
*/
|
||||
eq.forEach(x -> swapAddOrErase(x, fc, eqQueue));
|
||||
|
||||
/*
|
||||
* Apply rules until the queue is empty
|
||||
*/
|
||||
while(!eqQueue.isEmpty()) {
|
||||
UnifyPair pair = eqQueue.pollFirst();
|
||||
|
||||
// ReduceUp, ReduceLow, ReduceUpLow
|
||||
Optional<UnifyPair> opt = rules.reduceUpLow(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceLow(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceUp(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardLow(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardLowRight(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardUp(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardUpRight(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair);
|
||||
opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair);
|
||||
|
||||
// Reduce TPH
|
||||
opt = opt.isPresent() ? opt : rules.reduceTph(pair);
|
||||
|
||||
// One of the rules has been applied
|
||||
if(opt.isPresent()) {
|
||||
swapAddOrErase(opt.get(), fc, eqQueue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq
|
||||
Optional<Set<UnifyPair>> optSet = rules.reduce1(pair, fc);
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduce2(pair);
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceExt(pair, fc);
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceSup(pair, fc);
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceEq(pair);
|
||||
|
||||
// ReduceTphExt, ReduceTphSup
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceTphExt(pair);
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceTphSup(pair);
|
||||
|
||||
|
||||
// FunN Rules
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
|
||||
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair);
|
||||
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair);
|
||||
|
||||
// One of the rules has been applied
|
||||
if(optSet.isPresent()) {
|
||||
optSet.get().forEach(x -> swapAddOrErase(x, fc, eqQueue));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Adapt, AdaptExt, AdaptSup
|
||||
opt = rules.adapt(pair, fc);
|
||||
opt = opt.isPresent() ? opt : rules.adaptExt(pair, fc);
|
||||
opt = opt.isPresent() ? opt : rules.adaptSup(pair, fc);
|
||||
|
||||
// One of the rules has been applied
|
||||
if(opt.isPresent()) {
|
||||
swapAddOrErase(opt.get(), fc, eqQueue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// None of the rules has been applied
|
||||
targetSet.add(pair);
|
||||
}
|
||||
|
||||
return targetSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the rule swap to a pair if possible. Then adds the pair to the set if no erase rule applies.
|
||||
* If an erase rule applies, the pair is not added (erased).
|
||||
* @param pair The pair to swap and add or erase.
|
||||
* @param collection The collection to which the pairs are added.
|
||||
*/
|
||||
protected void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
|
||||
Optional<UnifyPair> opt = rules.swap(pair);
|
||||
UnifyPair pair2 = opt.isPresent() ? opt.get() : pair;
|
||||
|
||||
if(rules.erase1(pair2, fc) || rules.erase3(pair2) || rules.erase2(pair2, fc))
|
||||
return;
|
||||
|
||||
collection.add(pair2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the equation eq into a set eq1s where both terms are type variables,
|
||||
* and a set eq2s where one of both terms is not a type variable.
|
||||
* @param eq Set of pairs to be splitted.
|
||||
* @param eq1s Subset of eq where both terms are type variables.
|
||||
* @param eq2s eq/eq1s.
|
||||
*/
|
||||
protected void splitEq(Set<UnifyPair> eq, Set<UnifyPair> eq1s, Set<UnifyPair> eq2s) {
|
||||
for(UnifyPair pair : eq)
|
||||
if(pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType)
|
||||
eq1s.add(pair);
|
||||
else
|
||||
eq2s.add(pair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates sets of pairs specified in the fourth step. Does not calculate cartesian products.
|
||||
* @param undefined All pairs that did not match one of the 8 cases are added to this set.
|
||||
* @return The set of the eight cases (without empty sets). Each case is a set, containing sets generated
|
||||
* from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements
|
||||
* (as in case 1 where sigma is added to the innermost set).
|
||||
*/
|
||||
protected Set<Set<Set<Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, IFiniteClosure fc, Set<UnifyPair> undefined) {
|
||||
List<Set<Set<Set<UnifyPair>>>> result = new ArrayList<>(8);
|
||||
|
||||
// Init all 8 cases
|
||||
for(int i = 0; i < 8; i++)
|
||||
result.add(new HashSet<>());
|
||||
|
||||
for(UnifyPair pair : eq2s) {
|
||||
PairOperator pairOp = pair.getPairOp();
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
||||
// Case 1: (a <. Theta')
|
||||
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType)
|
||||
result.get(0).add(unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc));
|
||||
|
||||
// Case 2: (a <.? ? ext Theta')
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
|
||||
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
|
||||
|
||||
// Case 3: (a <.? ? sup Theta')
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
|
||||
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc));
|
||||
|
||||
// Case 4 was replaced by an inference rule
|
||||
// Case 4: (a <.? Theta')
|
||||
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType)
|
||||
// result.get(3).add(unifyCase4((PlaceholderType) lhsType, rhsType, fc));
|
||||
|
||||
// Case 5: (Theta <. a)
|
||||
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
|
||||
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc));
|
||||
|
||||
// Case 6 was replaced by an inference rule.
|
||||
// Case 6: (? ext Theta <.? a)
|
||||
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType)
|
||||
// result.get(5).add(unifyCase6((ExtendsType) lhsType, (PlaceholderType) rhsType, fc));
|
||||
|
||||
// Case 7 was replaced by an inference rule
|
||||
// Case 7: (? sup Theta <.? a)
|
||||
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType)
|
||||
// result.get(6).add(unifyCase7((SuperType) lhsType, (PlaceholderType) rhsType, fc));
|
||||
|
||||
// Case 8: (Theta <.? a)
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
|
||||
result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc));
|
||||
// Case unknown: If a pair fits no other case, then the type unification has failed.
|
||||
// Through application of the rules, every pair should have one of the above forms.
|
||||
// Pairs that do not have one of the aboves form are contradictory.
|
||||
else {
|
||||
// If a pair is not defined, the unificiation will fail, so the loop can be stopped here.
|
||||
undefined.add(pair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter empty sets or sets that only contain an empty set.
|
||||
return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new)))
|
||||
.filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cartesian product Case 1: (a <. Theta')
|
||||
*/
|
||||
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
boolean allGen = thetaPrime.getTypeParams().size() > 0;
|
||||
for(UnifyType t : thetaPrime.getTypeParams())
|
||||
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||
allGen = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
||||
cs.add(thetaPrime);
|
||||
|
||||
for(UnifyType c : cs) {
|
||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||
thetaQs.add(thetaPrime); //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
||||
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist
|
||||
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
||||
TypeParams cParams = c.getTypeParams();
|
||||
if(cParams.size() == 0)
|
||||
thetaQPrimes.add(c);
|
||||
else {
|
||||
ArrayList<Set<UnifyType>> candidateParams = new ArrayList<>();
|
||||
|
||||
for(UnifyType param : cParams)
|
||||
candidateParams.add(fc.grArg(param));
|
||||
|
||||
for(TypeParams tp : permuteParams(candidateParams))
|
||||
thetaQPrimes.add(c.setTypeParams(tp));
|
||||
}
|
||||
|
||||
for(UnifyType tqp : thetaQPrimes) {
|
||||
Optional<Unifier> opt = stdUnify.unify(tqp, thetaPrime);
|
||||
if (!opt.isPresent())
|
||||
continue;
|
||||
|
||||
Unifier unifier = opt.get();
|
||||
unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams());
|
||||
Set<UnifyPair> substitutionSet = new HashSet<>();
|
||||
for (Entry<PlaceholderType, UnifyType> sigma : unifier)
|
||||
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
|
||||
|
||||
List<UnifyType> freshTphs = new ArrayList<>();
|
||||
for (UnifyType tq : thetaQs) {
|
||||
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
|
||||
for(UnifyType theta : smaller) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
|
||||
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
|
||||
if(freshTphs.size()-1 < i)
|
||||
freshTphs.add(PlaceholderType.freshPlaceholder());
|
||||
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC));
|
||||
}
|
||||
|
||||
if(allGen)
|
||||
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
|
||||
else
|
||||
resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT));
|
||||
resultPrime.addAll(substitutionSet);
|
||||
result.add(resultPrime);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cartesian Product Case 2: (a <.? ? ext Theta')
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||
UnifyType extAPrime = new ExtendsType(aPrime);
|
||||
UnifyType thetaPrime = extThetaPrime.getExtendedType();
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT));
|
||||
result.add(resultPrime);
|
||||
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT));
|
||||
result.add(resultPrime);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cartesian Product Case 3: (a <.? ? sup Theta')
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||
UnifyType supAPrime = new SuperType(aPrime);
|
||||
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT));
|
||||
result.add(resultPrime);
|
||||
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
|
||||
result.add(resultPrime);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cartesian Product Case 5: (Theta <. a)
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
boolean allGen = theta.getTypeParams().size() > 0;
|
||||
for(UnifyType t : theta.getTypeParams())
|
||||
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||
allGen = false;
|
||||
break;
|
||||
}
|
||||
|
||||
for(UnifyType thetaS : fc.greater(theta)) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
|
||||
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
||||
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC));
|
||||
}
|
||||
|
||||
if(allGen)
|
||||
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
|
||||
else
|
||||
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT));
|
||||
result.add(resultPrime);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cartesian Product Case 8: (Theta <.? a)
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
//for(UnifyType thetaS : fc.grArg(theta)) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
|
||||
result.add(resultPrime);
|
||||
|
||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT));
|
||||
result.add(resultPrime);
|
||||
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT));
|
||||
result.add(resultPrime);
|
||||
//}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a set of candidates for each position and computes all possible permutations.
|
||||
* @param candidates The length of the list determines the number of type params. Each set
|
||||
* contains the candidates for the corresponding position.
|
||||
*/
|
||||
protected Set<TypeParams> permuteParams(ArrayList<Set<UnifyType>> candidates) {
|
||||
Set<TypeParams> result = new HashSet<>();
|
||||
permuteParams(candidates, 0, result, new UnifyType[candidates.size()]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a set of candidates for each position and computes all possible permutations.
|
||||
* @param candidates The length of the list determines the number of type params. Each set
|
||||
* contains the candidates for the corresponding position.
|
||||
* @param idx Idx for the current permutatiton.
|
||||
* @param result Set of all permutations found so far
|
||||
* @param current The permutation of type params that is currently explored
|
||||
*/
|
||||
private void permuteParams(ArrayList<Set<UnifyType>> candidates, int idx, Set<TypeParams> result, UnifyType[] current) {
|
||||
if(candidates.size() == idx) {
|
||||
result.add(new TypeParams(Arrays.copyOf(current, current.length)));
|
||||
return;
|
||||
}
|
||||
|
||||
Set<UnifyType> localCandidates = candidates.get(idx);
|
||||
|
||||
for(UnifyType t : localCandidates) {
|
||||
current[idx] = t;
|
||||
permuteParams(candidates, idx+1, result, current);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.interfaces;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Florian Steurer
|
||||
*/
|
||||
public interface IFiniteClosure {
|
||||
|
||||
/**
|
||||
* Returns all types of the finite closure that are subtypes of the argument.
|
||||
* @return The set of subtypes of the argument.
|
||||
*/
|
||||
public Set<UnifyType> smaller(UnifyType type);
|
||||
|
||||
/**
|
||||
* Returns all types of the finite closure that are supertypes of the argument.
|
||||
* @return The set of supertypes of the argument.
|
||||
*/
|
||||
public Set<UnifyType> greater(UnifyType type);
|
||||
|
||||
/**
|
||||
* Wo passt Type rein?
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public Set<UnifyType> grArg(UnifyType type);
|
||||
|
||||
/**
|
||||
* Was passt in Type rein?
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public Set<UnifyType> smArg(UnifyType type);
|
||||
|
||||
public Set<UnifyType> grArg(ReferenceType type);
|
||||
public Set<UnifyType> smArg(ReferenceType type);
|
||||
|
||||
public Set<UnifyType> grArg(ExtendsType type);
|
||||
public Set<UnifyType> smArg(ExtendsType type);
|
||||
|
||||
public Set<UnifyType> grArg(SuperType type);
|
||||
public Set<UnifyType> smArg(SuperType type);
|
||||
|
||||
public Set<UnifyType> grArg(PlaceholderType type);
|
||||
public Set<UnifyType> smArg(PlaceholderType type);
|
||||
|
||||
public Set<UnifyType> grArg(FunNType type);
|
||||
public Set<UnifyType> smArg(FunNType type);
|
||||
|
||||
public Optional<UnifyType> getLeftHandedType(String typeName);
|
||||
public Set<UnifyType> getAncestors(UnifyType t);
|
||||
public Set<UnifyType> getChildren(UnifyType t);
|
||||
public Set<UnifyType> getAllTypesByName(String typeName);
|
||||
}
|
@ -1,414 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||
|
||||
/**
|
||||
* The finite closure for the type unification
|
||||
* @author Florian Steurer
|
||||
*/
|
||||
public class FiniteClosure implements IFiniteClosure {
|
||||
|
||||
/**
|
||||
* A map that maps every type to the node in the inheritance graph that contains that type.
|
||||
*/
|
||||
private HashMap<UnifyType, Node<UnifyType>> inheritanceGraph;
|
||||
|
||||
/**
|
||||
* A map that maps every typename to the nodes of the inheritance graph that contain a type with that name.
|
||||
*/
|
||||
private HashMap<String, Set<Node<UnifyType>>> strInheritanceGraph;
|
||||
|
||||
|
||||
/**
|
||||
* The initial pairs of that define the inheritance tree
|
||||
*/
|
||||
private Set<UnifyPair> pairs;
|
||||
|
||||
/**
|
||||
* Creates a new instance using the inheritance tree defined in the pairs.
|
||||
*/
|
||||
public FiniteClosure(Set<UnifyPair> pairs) {
|
||||
this.pairs = new HashSet<>(pairs);
|
||||
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
||||
|
||||
// Build the transitive closure of the inheritance tree
|
||||
for(UnifyPair pair : pairs) {
|
||||
if(pair.getPairOp() != PairOperator.SMALLER)
|
||||
continue;
|
||||
|
||||
// Add nodes if not already in the graph
|
||||
if(!inheritanceGraph.containsKey(pair.getLhsType()))
|
||||
inheritanceGraph.put(pair.getLhsType(), new Node<UnifyType>(pair.getLhsType()));
|
||||
if(!inheritanceGraph.containsKey(pair.getRhsType()))
|
||||
inheritanceGraph.put(pair.getRhsType(), new Node<UnifyType>(pair.getRhsType()));
|
||||
|
||||
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
|
||||
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
|
||||
|
||||
// Add edge
|
||||
parentNode.addDescendant(childNode);
|
||||
|
||||
// Add edges to build the transitive closure
|
||||
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
||||
}
|
||||
|
||||
// Build the alternative representation with strings as keys
|
||||
strInheritanceGraph = new HashMap<>();
|
||||
for(UnifyType key : inheritanceGraph.keySet()) {
|
||||
if(!strInheritanceGraph.containsKey(key.getName()))
|
||||
strInheritanceGraph.put(key.getName(), new HashSet<>());
|
||||
|
||||
strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all types of the finite closure that are subtypes of the argument.
|
||||
* @return The set of subtypes of the argument.
|
||||
*/
|
||||
@Override
|
||||
public Set<UnifyType> smaller(UnifyType type) {
|
||||
if(type instanceof FunNType)
|
||||
return computeSmallerFunN((FunNType) type);
|
||||
|
||||
Set<UnifyType> ts = new HashSet<>();
|
||||
ts.add(type);
|
||||
return computeSmaller(ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the smaller functions for every type except FunNTypes.
|
||||
*/
|
||||
private Set<UnifyType> computeSmaller(Set<UnifyType> types) {
|
||||
HashSet<UnifyType> result = new HashSet<>();
|
||||
|
||||
IUnify unify = new MartelliMontanariUnify();
|
||||
|
||||
for(UnifyType t : types) {
|
||||
|
||||
// if T = T' then T <* T'
|
||||
result.add(t);
|
||||
|
||||
// if C<...> <* C<...> then ... (third case in definition of <*)
|
||||
if(t.getTypeParams().size() > 0) {
|
||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||
for (int i = 0; i < t.getTypeParams().size(); i++)
|
||||
paramCandidates.add(smArg(t.getTypeParams().get(i)));
|
||||
permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x)));
|
||||
}
|
||||
|
||||
if(!strInheritanceGraph.containsKey(t.getName()))
|
||||
continue;
|
||||
|
||||
// if T <* T' then sigma(T) <* sigma(T')
|
||||
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName());
|
||||
for(Node<UnifyType> candidate : candidates) {
|
||||
UnifyType theta2 = candidate.getContent();
|
||||
Optional<Unifier> optSigma = unify.unify(theta2, t);
|
||||
if(!optSigma.isPresent())
|
||||
continue;
|
||||
|
||||
Unifier sigma = optSigma.get();
|
||||
sigma.swapPlaceholderSubstitutions(t.getTypeParams());
|
||||
|
||||
Set<UnifyType> theta1Set = candidate.getContentOfDescendants();
|
||||
|
||||
for(UnifyType theta1 : theta1Set)
|
||||
result.add(theta1.apply(sigma));
|
||||
}
|
||||
}
|
||||
|
||||
if(result.equals(types))
|
||||
return result;
|
||||
return computeSmaller(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the smaller-Function for FunNTypes.
|
||||
*/
|
||||
private Set<UnifyType> computeSmallerFunN(FunNType type) {
|
||||
Set<UnifyType> result = new HashSet<>();
|
||||
|
||||
// if T = T' then T <=* T'
|
||||
result.add(type);
|
||||
|
||||
// Because real function types are implicitly variant
|
||||
// it is enough to permute the params with the values of greater / smaller.
|
||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||
paramCandidates.add(smaller(type.getTypeParams().get(0)));
|
||||
for (int i = 1; i < type.getTypeParams().size(); i++)
|
||||
paramCandidates.add(greater(type.getTypeParams().get(i)));
|
||||
|
||||
permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x)));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all types of the finite closure that are supertypes of the argument.
|
||||
* @return The set of supertypes of the argument.
|
||||
*/
|
||||
@Override
|
||||
public Set<UnifyType> greater(UnifyType type) {
|
||||
if(type instanceof FunNType)
|
||||
return computeGreaterFunN((FunNType) type);
|
||||
|
||||
Set<UnifyType> ts = new HashSet<>();
|
||||
ts.add(type);
|
||||
return computeGreater(ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the greater function for all types except function types.
|
||||
*/
|
||||
protected Set<UnifyType> computeGreater(Set<UnifyType> types) {
|
||||
HashSet<UnifyType> result = new HashSet<>();
|
||||
|
||||
IUnify unify = new MartelliMontanariUnify();
|
||||
|
||||
for(UnifyType t : types) {
|
||||
|
||||
// if T = T' then T <=* T'
|
||||
result.add(t);
|
||||
|
||||
// if C<...> <* C<...> then ... (third case in definition of <*)
|
||||
if(t.getTypeParams().size() > 0) {
|
||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||
for (int i = 0; i < t.getTypeParams().size(); i++)
|
||||
paramCandidates.add(grArg(t.getTypeParams().get(i)));
|
||||
permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x)));
|
||||
}
|
||||
|
||||
if(!strInheritanceGraph.containsKey(t.getName()))
|
||||
continue;
|
||||
|
||||
// if T <* T' then sigma(T) <* sigma(T')
|
||||
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName());
|
||||
for(Node<UnifyType> candidate : candidates) {
|
||||
UnifyType theta1 = candidate.getContent();
|
||||
Optional<Unifier> optSigma = unify.unify(theta1, t);
|
||||
if(!optSigma.isPresent())
|
||||
continue;
|
||||
|
||||
Unifier sigma = optSigma.get();
|
||||
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
||||
|
||||
Set<UnifyType> theta2Set = candidate.getContentOfPredecessors();
|
||||
|
||||
for(UnifyType theta2 : theta2Set)
|
||||
result.add(theta2.apply(sigma));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(result.equals(types))
|
||||
return result;
|
||||
return computeGreater(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the greater function for FunN-Types
|
||||
*/
|
||||
protected Set<UnifyType> computeGreaterFunN(FunNType type) {
|
||||
Set<UnifyType> result = new HashSet<>();
|
||||
|
||||
// if T = T' then T <=* T'
|
||||
result.add(type);
|
||||
|
||||
// Because real function types are implicitly variant
|
||||
// it is enough to permute the params with the values of greater / smaller.
|
||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||
paramCandidates.add(greater(type.getTypeParams().get(0)));
|
||||
for (int i = 1; i < type.getTypeParams().size(); i++)
|
||||
paramCandidates.add(smaller(type.getTypeParams().get(i)));
|
||||
permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x)));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> grArg(UnifyType type) {
|
||||
return type.grArg(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> grArg(ReferenceType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
smaller(type).forEach(x -> result.add(new SuperType(x)));
|
||||
greater(type).forEach(x -> result.add(new ExtendsType(x)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> grArg(FunNType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
smaller(type).forEach(x -> result.add(new SuperType(x)));
|
||||
greater(type).forEach(x -> result.add(new ExtendsType(x)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> grArg(ExtendsType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
UnifyType t = type.getExtendedType();
|
||||
greater(t).forEach(x -> result.add(new ExtendsType(x)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> grArg(SuperType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
UnifyType t = type.getSuperedType();
|
||||
smaller(t).forEach(x -> result.add(new SuperType(x)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> grArg(PlaceholderType type) {
|
||||
HashSet<UnifyType> result = new HashSet<>();
|
||||
result.add(type);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> smArg(UnifyType type) {
|
||||
return type.smArg(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> smArg(ReferenceType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> smArg(FunNType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> smArg(ExtendsType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
UnifyType t = type.getExtendedType();
|
||||
result.add(t);
|
||||
smaller(t).forEach(x -> {
|
||||
result.add(new ExtendsType(x));
|
||||
result.add(x);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> smArg(SuperType type) {
|
||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||
result.add(type);
|
||||
UnifyType t = type.getSuperedType();
|
||||
result.add(t);
|
||||
greater(t).forEach(x -> {
|
||||
result.add(new SuperType(x));
|
||||
result.add(x);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> smArg(PlaceholderType type) {
|
||||
HashSet<UnifyType> result = new HashSet<>();
|
||||
result.add(type);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> getAllTypesByName(String typeName) {
|
||||
if(!strInheritanceGraph.containsKey(typeName))
|
||||
return new HashSet<>();
|
||||
return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UnifyType> getLeftHandedType(String typeName) {
|
||||
if(!strInheritanceGraph.containsKey(typeName))
|
||||
return Optional.empty();
|
||||
|
||||
for(UnifyPair pair : pairs)
|
||||
if(pair.getLhsType().getName().equals(typeName))
|
||||
return Optional.of(pair.getLhsType());
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> getAncestors(UnifyType t) {
|
||||
if(!inheritanceGraph.containsKey(t))
|
||||
return new HashSet<>();
|
||||
Set<UnifyType> result = inheritanceGraph.get(t).getContentOfPredecessors();
|
||||
result.add(t);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> getChildren(UnifyType t) {
|
||||
if(!inheritanceGraph.containsKey(t))
|
||||
return new HashSet<>();
|
||||
Set<UnifyType> result = inheritanceGraph.get(t).getContentOfDescendants();
|
||||
result.add(t);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a set of candidates for each position and computes all possible permutations.
|
||||
* @param candidates The length of the list determines the number of type params. Each set
|
||||
* contains the candidates for the corresponding position.
|
||||
*/
|
||||
protected Set<TypeParams> permuteParams(ArrayList<Set<UnifyType>> candidates) {
|
||||
Set<TypeParams> result = new HashSet<>();
|
||||
permuteParams(candidates, 0, result, new UnifyType[candidates.size()]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a set of candidates for each position and computes all possible permutations.
|
||||
* @param candidates The length of the list determines the number of type params. Each set
|
||||
* contains the candidates for the corresponding position.
|
||||
* @param idx Idx for the current permutatiton.
|
||||
* @param result Set of all permutations found so far
|
||||
* @param current The permutation of type params that is currently explored
|
||||
*/
|
||||
protected void permuteParams(ArrayList<Set<UnifyType>> candidates, int idx, Set<TypeParams> result, UnifyType[] current) {
|
||||
if(candidates.size() == idx) {
|
||||
result.add(new TypeParams(Arrays.copyOf(current, current.length)));
|
||||
return;
|
||||
}
|
||||
|
||||
Set<UnifyType> localCandidates = candidates.get(idx);
|
||||
|
||||
for(UnifyType t : localCandidates) {
|
||||
current[idx] = t;
|
||||
permuteParams(candidates, idx+1, result, current);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.inheritanceGraph.toString();
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A pair which contains two types and an operator, e.q. (Integer <. a).
|
||||
* @author Florian Steurer
|
||||
*/
|
||||
public class UnifyPair {
|
||||
|
||||
/**
|
||||
* The type on the left hand side of the pair.
|
||||
*/
|
||||
private final UnifyType lhs;
|
||||
|
||||
/**
|
||||
* The type on the right hand side of the pair.
|
||||
*/
|
||||
private final UnifyType rhs;
|
||||
|
||||
/**
|
||||
* The operator that determines the relation between the left and right hand side type.
|
||||
*/
|
||||
private PairOperator pairOp;
|
||||
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the pair.
|
||||
* @param lhs The type on the left hand side of the pair.
|
||||
* @param rhs The type on the right hand side of the pair.
|
||||
* @param op The operator that determines the relation between the left and right hand side type.
|
||||
*/
|
||||
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
pairOp = op;
|
||||
|
||||
// Caching hashcode
|
||||
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type on the left hand side of the pair.
|
||||
*/
|
||||
public UnifyType getLhsType() {
|
||||
return lhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type on the right hand side of the pair.
|
||||
*/
|
||||
public UnifyType getRhsType() {
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the operator that determines the relation between the left and right hand side type.
|
||||
*/
|
||||
public PairOperator getPairOp() {
|
||||
return pairOp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof UnifyPair))
|
||||
return false;
|
||||
|
||||
if(obj.hashCode() != this.hashCode())
|
||||
return false;
|
||||
|
||||
UnifyPair other = (UnifyPair) obj;
|
||||
|
||||
return other.getPairOp() == pairOp
|
||||
&& other.getLhsType().equals(lhs)
|
||||
&& other.getRhsType().equals(rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + lhs + " " + pairOp + " " + rhs + ")";
|
||||
}
|
||||
|
||||
/*
|
||||
public List<? extends PlaceholderType> getInvolvedPlaceholderTypes() {
|
||||
ArrayList<PlaceholderType> ret = new ArrayList<>();
|
||||
ret.addAll(lhs.getInvolvedPlaceholderTypes());
|
||||
ret.addAll(rhs.getInvolvedPlaceholderTypes());
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,6 @@ classOrInterfaceType
|
||||
| interfaceType_lfno_classOrInterfaceType
|
||||
)
|
||||
( classType_lf_classOrInterfaceType
|
||||
| interfaceType_lf_classOrInterfaceType
|
||||
)*
|
||||
;
|
||||
|
||||
@ -333,7 +332,7 @@ classMemberDeclaration
|
||||
;
|
||||
|
||||
fieldDeclaration
|
||||
: fieldModifier* unannType? variableDeclaratorList ';'
|
||||
: fieldModifier* unannTypeOrAuto? variableDeclaratorList ';'
|
||||
;
|
||||
|
||||
fieldModifier
|
||||
@ -732,6 +731,7 @@ localVariableDeclarationStatement
|
||||
|
||||
unannTypeOrAuto
|
||||
: unannType
|
||||
| 'var'
|
||||
;
|
||||
|
||||
localVariableDeclaration
|
207
src/main/antlr4/java8/Java8.tokens
Normal file
@ -0,0 +1,207 @@
|
||||
T__0=1
|
||||
ABSTRACT=2
|
||||
ASSERT=3
|
||||
BOOLEAN=4
|
||||
BREAK=5
|
||||
BYTE=6
|
||||
CASE=7
|
||||
CATCH=8
|
||||
CHAR=9
|
||||
CLASS=10
|
||||
CONST=11
|
||||
CONTINUE=12
|
||||
DEFAULT=13
|
||||
DO=14
|
||||
DOUBLE=15
|
||||
ELSE=16
|
||||
ENUM=17
|
||||
EXTENDS=18
|
||||
FINAL=19
|
||||
FINALLY=20
|
||||
FLOAT=21
|
||||
FOR=22
|
||||
IF=23
|
||||
GOTO=24
|
||||
IMPLEMENTS=25
|
||||
IMPORT=26
|
||||
INSTANCEOF=27
|
||||
INT=28
|
||||
INTERFACE=29
|
||||
LONG=30
|
||||
NATIVE=31
|
||||
NEW=32
|
||||
PACKAGE=33
|
||||
PRIVATE=34
|
||||
PROTECTED=35
|
||||
PUBLIC=36
|
||||
RETURN=37
|
||||
SHORT=38
|
||||
STATIC=39
|
||||
STRICTFP=40
|
||||
SUPER=41
|
||||
SWITCH=42
|
||||
SYNCHRONIZED=43
|
||||
THIS=44
|
||||
THROW=45
|
||||
THROWS=46
|
||||
TRANSIENT=47
|
||||
TRY=48
|
||||
VOID=49
|
||||
VOLATILE=50
|
||||
WHILE=51
|
||||
IntegerLiteral=52
|
||||
FloatingPointLiteral=53
|
||||
BooleanLiteral=54
|
||||
CharacterLiteral=55
|
||||
StringLiteral=56
|
||||
NullLiteral=57
|
||||
LPAREN=58
|
||||
RPAREN=59
|
||||
LBRACE=60
|
||||
RBRACE=61
|
||||
LBRACK=62
|
||||
RBRACK=63
|
||||
SEMI=64
|
||||
COMMA=65
|
||||
DOT=66
|
||||
ASSIGN=67
|
||||
GT=68
|
||||
LT=69
|
||||
BANG=70
|
||||
TILDE=71
|
||||
QUESTION=72
|
||||
COLON=73
|
||||
EQUAL=74
|
||||
LE=75
|
||||
GE=76
|
||||
NOTEQUAL=77
|
||||
AND=78
|
||||
OR=79
|
||||
INC=80
|
||||
DEC=81
|
||||
ADD=82
|
||||
SUB=83
|
||||
MUL=84
|
||||
DIV=85
|
||||
BITAND=86
|
||||
BITOR=87
|
||||
CARET=88
|
||||
MOD=89
|
||||
ARROW=90
|
||||
COLONCOLON=91
|
||||
ADD_ASSIGN=92
|
||||
SUB_ASSIGN=93
|
||||
MUL_ASSIGN=94
|
||||
DIV_ASSIGN=95
|
||||
AND_ASSIGN=96
|
||||
OR_ASSIGN=97
|
||||
XOR_ASSIGN=98
|
||||
MOD_ASSIGN=99
|
||||
LSHIFT_ASSIGN=100
|
||||
RSHIFT_ASSIGN=101
|
||||
URSHIFT_ASSIGN=102
|
||||
Identifier=103
|
||||
AT=104
|
||||
ELLIPSIS=105
|
||||
WS=106
|
||||
COMMENT=107
|
||||
LINE_COMMENT=108
|
||||
'var'=1
|
||||
'abstract'=2
|
||||
'assert'=3
|
||||
'boolean'=4
|
||||
'break'=5
|
||||
'byte'=6
|
||||
'case'=7
|
||||
'catch'=8
|
||||
'char'=9
|
||||
'class'=10
|
||||
'const'=11
|
||||
'continue'=12
|
||||
'default'=13
|
||||
'do'=14
|
||||
'double'=15
|
||||
'else'=16
|
||||
'enum'=17
|
||||
'extends'=18
|
||||
'final'=19
|
||||
'finally'=20
|
||||
'float'=21
|
||||
'for'=22
|
||||
'if'=23
|
||||
'goto'=24
|
||||
'implements'=25
|
||||
'import'=26
|
||||
'instanceof'=27
|
||||
'int'=28
|
||||
'interface'=29
|
||||
'long'=30
|
||||
'native'=31
|
||||
'new'=32
|
||||
'package'=33
|
||||
'private'=34
|
||||
'protected'=35
|
||||
'public'=36
|
||||
'return'=37
|
||||
'short'=38
|
||||
'static'=39
|
||||
'strictfp'=40
|
||||
'super'=41
|
||||
'switch'=42
|
||||
'synchronized'=43
|
||||
'this'=44
|
||||
'throw'=45
|
||||
'throws'=46
|
||||
'transient'=47
|
||||
'try'=48
|
||||
'void'=49
|
||||
'volatile'=50
|
||||
'while'=51
|
||||
'null'=57
|
||||
'('=58
|
||||
')'=59
|
||||
'{'=60
|
||||
'}'=61
|
||||
'['=62
|
||||
']'=63
|
||||
';'=64
|
||||
','=65
|
||||
'.'=66
|
||||
'='=67
|
||||
'>'=68
|
||||
'<'=69
|
||||
'!'=70
|
||||
'~'=71
|
||||
'?'=72
|
||||
':'=73
|
||||
'=='=74
|
||||
'<='=75
|
||||
'>='=76
|
||||
'!='=77
|
||||
'&&'=78
|
||||
'||'=79
|
||||
'++'=80
|
||||
'--'=81
|
||||
'+'=82
|
||||
'-'=83
|
||||
'*'=84
|
||||
'/'=85
|
||||
'&'=86
|
||||
'|'=87
|
||||
'^'=88
|
||||
'%'=89
|
||||
'->'=90
|
||||
'::'=91
|
||||
'+='=92
|
||||
'-='=93
|
||||
'*='=94
|
||||
'/='=95
|
||||
'&='=96
|
||||
'|='=97
|
||||
'^='=98
|
||||
'%='=99
|
||||
'<<='=100
|
||||
'>>='=101
|
||||
'>>>='=102
|
||||
'@'=104
|
||||
'...'=105
|
207
src/main/antlr4/java8/Java8Lexer.tokens
Normal file
@ -0,0 +1,207 @@
|
||||
T__0=1
|
||||
ABSTRACT=2
|
||||
ASSERT=3
|
||||
BOOLEAN=4
|
||||
BREAK=5
|
||||
BYTE=6
|
||||
CASE=7
|
||||
CATCH=8
|
||||
CHAR=9
|
||||
CLASS=10
|
||||
CONST=11
|
||||
CONTINUE=12
|
||||
DEFAULT=13
|
||||
DO=14
|
||||
DOUBLE=15
|
||||
ELSE=16
|
||||
ENUM=17
|
||||
EXTENDS=18
|
||||
FINAL=19
|
||||
FINALLY=20
|
||||
FLOAT=21
|
||||
FOR=22
|
||||
IF=23
|
||||
GOTO=24
|
||||
IMPLEMENTS=25
|
||||
IMPORT=26
|
||||
INSTANCEOF=27
|
||||
INT=28
|
||||
INTERFACE=29
|
||||
LONG=30
|
||||
NATIVE=31
|
||||
NEW=32
|
||||
PACKAGE=33
|
||||
PRIVATE=34
|
||||
PROTECTED=35
|
||||
PUBLIC=36
|
||||
RETURN=37
|
||||
SHORT=38
|
||||
STATIC=39
|
||||
STRICTFP=40
|
||||
SUPER=41
|
||||
SWITCH=42
|
||||
SYNCHRONIZED=43
|
||||
THIS=44
|
||||
THROW=45
|
||||
THROWS=46
|
||||
TRANSIENT=47
|
||||
TRY=48
|
||||
VOID=49
|
||||
VOLATILE=50
|
||||
WHILE=51
|
||||
IntegerLiteral=52
|
||||
FloatingPointLiteral=53
|
||||
BooleanLiteral=54
|
||||
CharacterLiteral=55
|
||||
StringLiteral=56
|
||||
NullLiteral=57
|
||||
LPAREN=58
|
||||
RPAREN=59
|
||||
LBRACE=60
|
||||
RBRACE=61
|
||||
LBRACK=62
|
||||
RBRACK=63
|
||||
SEMI=64
|
||||
COMMA=65
|
||||
DOT=66
|
||||
ASSIGN=67
|
||||
GT=68
|
||||
LT=69
|
||||
BANG=70
|
||||
TILDE=71
|
||||
QUESTION=72
|
||||
COLON=73
|
||||
EQUAL=74
|
||||
LE=75
|
||||
GE=76
|
||||
NOTEQUAL=77
|
||||
AND=78
|
||||
OR=79
|
||||
INC=80
|
||||
DEC=81
|
||||
ADD=82
|
||||
SUB=83
|
||||
MUL=84
|
||||
DIV=85
|
||||
BITAND=86
|
||||
BITOR=87
|
||||
CARET=88
|
||||
MOD=89
|
||||
ARROW=90
|
||||
COLONCOLON=91
|
||||
ADD_ASSIGN=92
|
||||
SUB_ASSIGN=93
|
||||
MUL_ASSIGN=94
|
||||
DIV_ASSIGN=95
|
||||
AND_ASSIGN=96
|
||||
OR_ASSIGN=97
|
||||
XOR_ASSIGN=98
|
||||
MOD_ASSIGN=99
|
||||
LSHIFT_ASSIGN=100
|
||||
RSHIFT_ASSIGN=101
|
||||
URSHIFT_ASSIGN=102
|
||||
Identifier=103
|
||||
AT=104
|
||||
ELLIPSIS=105
|
||||
WS=106
|
||||
COMMENT=107
|
||||
LINE_COMMENT=108
|
||||
'var'=1
|
||||
'abstract'=2
|
||||
'assert'=3
|
||||
'boolean'=4
|
||||
'break'=5
|
||||
'byte'=6
|
||||
'case'=7
|
||||
'catch'=8
|
||||
'char'=9
|
||||
'class'=10
|
||||
'const'=11
|
||||
'continue'=12
|
||||
'default'=13
|
||||
'do'=14
|
||||
'double'=15
|
||||
'else'=16
|
||||
'enum'=17
|
||||
'extends'=18
|
||||
'final'=19
|
||||
'finally'=20
|
||||
'float'=21
|
||||
'for'=22
|
||||
'if'=23
|
||||
'goto'=24
|
||||
'implements'=25
|
||||
'import'=26
|
||||
'instanceof'=27
|
||||
'int'=28
|
||||
'interface'=29
|
||||
'long'=30
|
||||
'native'=31
|
||||
'new'=32
|
||||
'package'=33
|
||||
'private'=34
|
||||
'protected'=35
|
||||
'public'=36
|
||||
'return'=37
|
||||
'short'=38
|
||||
'static'=39
|
||||
'strictfp'=40
|
||||
'super'=41
|
||||
'switch'=42
|
||||
'synchronized'=43
|
||||
'this'=44
|
||||
'throw'=45
|
||||
'throws'=46
|
||||
'transient'=47
|
||||
'try'=48
|
||||
'void'=49
|
||||
'volatile'=50
|
||||
'while'=51
|
||||
'null'=57
|
||||
'('=58
|
||||
')'=59
|
||||
'{'=60
|
||||
'}'=61
|
||||
'['=62
|
||||
']'=63
|
||||
';'=64
|
||||
','=65
|
||||
'.'=66
|
||||
'='=67
|
||||
'>'=68
|
||||
'<'=69
|
||||
'!'=70
|
||||
'~'=71
|
||||
'?'=72
|
||||
':'=73
|
||||
'=='=74
|
||||
'<='=75
|
||||
'>='=76
|
||||
'!='=77
|
||||
'&&'=78
|
||||
'||'=79
|
||||
'++'=80
|
||||
'--'=81
|
||||
'+'=82
|
||||
'-'=83
|
||||
'*'=84
|
||||
'/'=85
|
||||
'&'=86
|
||||
'|'=87
|
||||
'^'=88
|
||||
'%'=89
|
||||
'->'=90
|
||||
'::'=91
|
||||
'+='=92
|
||||
'-='=93
|
||||
'*='=94
|
||||
'/='=95
|
||||
'&='=96
|
||||
'|='=97
|
||||
'^='=98
|
||||
'%='=99
|
||||
'<<='=100
|
||||
'>>='=101
|
||||
'>>>='=102
|
||||
'@'=104
|
||||
'...'=105
|
37
src/main/antlr4/sat/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/main/antlr4/sat/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
|
23
src/main/antlr4/sat/UnifyResultLexer.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
|
30
src/main/java/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/main/java/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);
|
||||
}
|
||||
|
||||
}
|
258
src/main/java/de/dhbwstuttgart/bytecode/ArgumentVisitor.java
Normal file
@ -0,0 +1,258 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
|
||||
public class ArgumentVisitor implements StatementVisitor {
|
||||
private List<Boolean> argListMethCall;
|
||||
private BytecodeGenMethod bytecodeGenMethod;
|
||||
|
||||
public ArgumentVisitor(List<Boolean> argListMethCall, BytecodeGenMethod bytecodeGenMethod) {
|
||||
this.argListMethCall = argListMethCall;
|
||||
this.bytecodeGenMethod = bytecodeGenMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
lambdaExpression.accept(bytecodeGenMethod);
|
||||
// Zieltype des Lambas ist Funktionale Interface
|
||||
// kann nie primitiv sein => un-/boxing wird hier nicht gebraucht
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
assign.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(assign.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
binary.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0)) {
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
||||
} else {
|
||||
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
||||
}
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
castExpr.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(castExpr.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
fieldVar.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(fieldVar.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
instanceOf.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(instanceOf.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
localVar.accept(bytecodeGenMethod);
|
||||
if(!bytecodeGenMethod.isBinaryExp) {
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(localVar.getType()));
|
||||
}
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
methodCall.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
aThis.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(aThis.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
unaryExpr.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(unaryExpr.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
literal.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(literal.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
}
|
11
src/main/java/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);
|
||||
}
|
||||
|
||||
}
|
646
src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java
Normal file
@ -0,0 +1,646 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToString;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
ClassWriter cw =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
String type;
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
||||
String className;
|
||||
private boolean isInterface;
|
||||
private List<ResultSet> listOfResultSets;
|
||||
private ResultSet resultSet;
|
||||
private SourceFile sf;
|
||||
private String path;
|
||||
|
||||
private Optional<Constructor> fieldInitializations;
|
||||
|
||||
private int indexOfFirstParam = 0;
|
||||
|
||||
private String superClass;
|
||||
|
||||
private ArrayList<TypePlaceholder> tphsClass;
|
||||
|
||||
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
// stores generics and their bounds of class
|
||||
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
||||
|
||||
private int constructorPos = 0;
|
||||
|
||||
private final TPHExtractor tphExtractor = new TPHExtractor();
|
||||
private final ArrayList<GenericInsertPair> commonPairs = new ArrayList<>();
|
||||
|
||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||
byte[] bytecode;
|
||||
HashMap<String,byte[]> classFiles;
|
||||
|
||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||
|
||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
|
||||
this.classFiles = classFiles;
|
||||
this.listOfResultSets = listOfResultSets;
|
||||
this.sf = sf;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SourceFile sourceFile) {
|
||||
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
||||
System.out.println("in Class: " + cl.getClassName().toString());
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
||||
cl.accept(classGen);
|
||||
classGen.writeClass(cl.getClassName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates the bytecode of the class that was build with the classWriter {@link #cw}
|
||||
* with the class name in the map {@link #classFiles}
|
||||
*
|
||||
* @param name name of the class with which the the bytecode is to be associated
|
||||
*/
|
||||
private void writeClass(String name) {
|
||||
bytecode = cw.toByteArray();
|
||||
classFiles.put(name, bytecode);
|
||||
|
||||
}
|
||||
|
||||
public HashMap<String,byte[]> getClassFiles() {
|
||||
return classFiles;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
|
||||
className = classOrInterface.getClassName().toString();
|
||||
|
||||
cw.visitSource(className +".jav", null);
|
||||
|
||||
isInterface = (classOrInterface.getModifiers()&512)==512;
|
||||
|
||||
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
||||
|
||||
fieldInitializations = classOrInterface.getfieldInitializations();
|
||||
|
||||
// resultSet = listOfResultSets.get(0);
|
||||
boolean isConsWithNoParamsVisited = false;
|
||||
boolean isVisited = false;
|
||||
for(ResultSet rs : listOfResultSets) {
|
||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||
resultSet = rs;
|
||||
tphExtractor.setResultSet(resultSet);
|
||||
|
||||
// Nur einmal ausführen!!
|
||||
if(!isVisited) {
|
||||
classOrInterface.accept(tphExtractor);
|
||||
|
||||
getCommonTPHS(tphExtractor);
|
||||
|
||||
tphsClass = new ArrayList<>();
|
||||
for(TypePlaceholder t : tphExtractor.allTPHS.keySet()) {
|
||||
if(!tphExtractor.allTPHS.get(t))
|
||||
tphsClass.add(t);
|
||||
}
|
||||
|
||||
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
||||
for(TPHConstraint cons : tphExtractor.allCons) {
|
||||
TypePlaceholder right = null;
|
||||
for(TypePlaceholder tph : tphsClass) {
|
||||
if(cons.getLeft().equals(tph.getName())) {
|
||||
|
||||
consClass.add(cons);
|
||||
right = getTPH(cons.getRight());
|
||||
}
|
||||
}
|
||||
if(right != null) {
|
||||
tphsClass.add(right);
|
||||
removeFromMethod(right.getName());
|
||||
right = null;
|
||||
}
|
||||
}
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
||||
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
||||
|| !tphsClass.isEmpty()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass);
|
||||
sig = signature.toString();
|
||||
System.out.println("Signature: => " + sig);
|
||||
}
|
||||
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
isVisited = true;
|
||||
}
|
||||
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
f.accept(this);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void removeFromMethod(String name) {
|
||||
for(MethodAndTPH m : tphExtractor.ListOfMethodsAndTph) {
|
||||
ArrayList<String> toRemove = new ArrayList<>();
|
||||
for(String tph : m.getTphs()) {
|
||||
if(tph.equals(name)) {
|
||||
toRemove.add(tph);
|
||||
}
|
||||
}
|
||||
|
||||
if(!toRemove.isEmpty()) {
|
||||
m.getTphs().removeAll(toRemove);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TypePlaceholder getTPH(String name) {
|
||||
for(TypePlaceholder tph: tphExtractor.allTPHS.keySet()) {
|
||||
if(tph.getName().equals(name))
|
||||
return tph;
|
||||
}
|
||||
throw new NoSuchElementException("TPH "+name +" does not exist");
|
||||
}
|
||||
|
||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
||||
// Gemeinsame TPHs
|
||||
ArrayList<TypePlaceholder> cTPHs = new ArrayList<>();
|
||||
// Alle TPHs der Felder speichern
|
||||
for(TypePlaceholder tph : tphExtractor.allTPHS.keySet()) {
|
||||
if(!tphExtractor.allTPHS.get(tph))
|
||||
cTPHs.add(tph);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor field) {
|
||||
System.out.println("ResultSet: ");
|
||||
resultSet.results.forEach(a->{
|
||||
System.out.println(a.getLeft().toString() + " = " + a.getRight().toString());
|
||||
});
|
||||
System.out.println("---------------");
|
||||
|
||||
// stores generics and their bounds of method
|
||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||
|
||||
field.getParameterList().accept(this);
|
||||
|
||||
String methParamTypes = field.name+"%%";
|
||||
|
||||
Iterator<FormalParameter> itr = field.getParameterList().iterator();
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
// methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature())+";";
|
||||
}
|
||||
|
||||
if(methodNameAndParamsT.contains(methParamTypes)) {
|
||||
System.out.println("ignore - Method: "+field.name +" , paramsType: "+methParamTypes);
|
||||
return;
|
||||
}
|
||||
methodNameAndParamsT.add(methParamTypes);
|
||||
System.out.println("Method: "+field.name +" , paramsType: "+methParamTypes);
|
||||
|
||||
String desc = null;
|
||||
boolean hasGen = false;
|
||||
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||
System.out.println(typeOfParam);
|
||||
if(genericsAndBounds.containsKey(typeOfParam) ||typeOfParam.contains("$")
|
||||
|| typeOfParam.contains("<")) {
|
||||
hasGen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String sig = null;
|
||||
if(hasGen) {
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,tphsClass);
|
||||
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
||||
sig = signature.toString();
|
||||
}
|
||||
if(field.getParameterList().iterator().hasNext())
|
||||
System.out.println(field.getParameterList().iterator().next().getType().acceptTV(new TypeToDescriptor()));
|
||||
|
||||
NormalConstructor constructor = new NormalConstructor(field,genericsAndBounds,hasGen);
|
||||
desc = constructor.accept(new DescriptorToString(resultSet));
|
||||
System.out.println("Constructor: " + field.getName() + " Sig: "+ sig + " Desc: " + desc);
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||
mv.visitCode();
|
||||
|
||||
Block block = fieldInitializations.get().block;
|
||||
|
||||
constructorPos += 1;
|
||||
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path, block, constructorPos);
|
||||
if(!field.getParameterList().iterator().hasNext() && !(field.block.statements.get(field.block.statements.size()-1) instanceof ReturnVoid)) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
// TODO: check if the method is static => if static then the first param will be stored in pos 0
|
||||
// else it will be stored in pos 1 and this will be stored in pos 0
|
||||
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
// String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
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())+";";
|
||||
// methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature())+";";
|
||||
}
|
||||
|
||||
if(methodNameAndParamsT.contains(methParamTypes)) {
|
||||
return;
|
||||
}
|
||||
methodNameAndParamsT.add(methParamTypes);
|
||||
System.out.println("Method: "+method.name +" , paramsType: "+methParamTypes);
|
||||
// stores generics and their bounds of method
|
||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||
String methDesc = null;
|
||||
|
||||
// Method getModifiers() ?
|
||||
int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier;
|
||||
System.out.println(acc);
|
||||
|
||||
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ") ||
|
||||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).contains("<");
|
||||
/*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());
|
||||
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")||sigOfParam.contains("<")) {
|
||||
hasGenInParameterList = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
|
||||
//then create the descriptor with the new syntax.
|
||||
|
||||
String sig = null;
|
||||
/* method.getGenerics: <....> RT method(..)
|
||||
* */
|
||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||
/* if method has generics or return type is TPH, create signature */
|
||||
// zwite operand muss weggelassen werden
|
||||
if(hasGen||resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString()).equals("TPH")) {
|
||||
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
||||
tphExtractor.allCons.forEach(c->System.out.println(c.toString()));
|
||||
System.out.println("----------------");
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name, tphExtractor, tphsClass);
|
||||
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
||||
sig = signature.toString();
|
||||
}
|
||||
System.out.println(method.getName()+" ==> "+sig);
|
||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||
|
||||
// System.out.println(methDesc);
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
|
||||
|
||||
mv.visitCode();
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,method, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path);
|
||||
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
paramsAndLocals = new HashMap<>();
|
||||
methodParamsAndTypes = new HashMap<>();
|
||||
Iterator<FormalParameter> itr = formalParameters.iterator();
|
||||
int i = 1;
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
paramsAndLocals.put(fp.getName(), i);
|
||||
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
|
||||
fp.accept(this);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FormalParameter formalParameter) {
|
||||
formalParameter.getType().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
type = "L"+refType.toString()+";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperWildcardType superWildcardType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
// ??
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
System.out.println("In FieldVar ---");
|
||||
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
|
||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L"+fieldVar.getType()+";", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
System.out.println("In Field ---");
|
||||
String des = "L";
|
||||
if(resultSet.resolveType(field.getType()).resolvedType instanceof TypePlaceholder) {
|
||||
des += Type.getInternalName(Object.class);
|
||||
} else {
|
||||
des += resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
des +=";";
|
||||
System.out.println(des);
|
||||
String sig = resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
System.out.println(sig);
|
||||
if(sig.charAt(sig.length()-1) != (";").charAt(0)) {
|
||||
sig +=";";
|
||||
}
|
||||
cw.visitField(field.modifier, field.getName(),
|
||||
des, sig,
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
// ???
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericTypeVar genericTypeVar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericDeclarationList genericTypeVars) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
1446
src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java
Normal file
9
src/main/java/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);
|
||||
}
|
29
src/main/java/de/dhbwstuttgart/bytecode/IfStatement.java
Normal file
@ -0,0 +1,29 @@
|
||||
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 IfStatement extends AStatement{
|
||||
|
||||
private Statement then_block;
|
||||
private Statement else_block;
|
||||
|
||||
public IfStatement(Expression expr, Statement then_block, Statement else_block) {
|
||||
super(expr);
|
||||
this.then_block = then_block;
|
||||
this.else_block = else_block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
||||
bytecodeGenMethod.isBinary(false);
|
||||
this.then_block.accept(bytecodeGenMethod);
|
||||
|
||||
mv.visitLabel(branchLabel);
|
||||
this.else_block.accept(bytecodeGenMethod);
|
||||
}
|
||||
}
|
26
src/main/java/de/dhbwstuttgart/bytecode/LoopStmt.java
Normal file
@ -0,0 +1,26 @@
|
||||
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) {
|
||||
bytecodeGenMethod.isBinary(false);
|
||||
this.loopBlock.accept(bytecodeGenMethod);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
}
|
||||
}
|
14
src/main/java/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);
|
||||
}
|
||||
|
||||
}
|
78
src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
/**
|
||||
* @author Fayez Abu Alia
|
||||
*
|
||||
*/
|
||||
public class TPHExtractor extends AbstractASTWalker{
|
||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||
final HashMap<TypePlaceholder,Boolean> allTPHS = new HashMap<>();
|
||||
MethodAndTPH methodAndTph;
|
||||
Boolean inMethod = false;
|
||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||
private ResultSet resultSet;
|
||||
|
||||
public TPHExtractor() {
|
||||
|
||||
}
|
||||
|
||||
public void setResultSet(ResultSet resultSet) {
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder tph) {
|
||||
if(resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||
if(inMethod)
|
||||
methodAndTph.getTphs().add(resolvedTPH.getName());
|
||||
|
||||
allTPHS.put(resolvedTPH,inMethod);
|
||||
resultSet.resolveType(tph).additionalGenerics.forEach(ag ->{
|
||||
if(ag.contains(resolvedTPH)&&ag.TA1.equals(resolvedTPH)&&!contains(allPairs,ag)) {
|
||||
if(inMethod)
|
||||
methodAndTph.getPairs().add(ag);
|
||||
allPairs.add(ag);
|
||||
TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||
allCons.add(con);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||
for(int i=0; i<pairs.size();++i) {
|
||||
GenericInsertPair p = pairs.get(i);
|
||||
if(p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
methodAndTph = new MethodAndTPH(method.name);
|
||||
super.visit(method);
|
||||
inMethod = false;
|
||||
ListOfMethodsAndTph.add(methodAndTph);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.bytecode.constraint;
|
||||
|
||||
public class EqualConstraint extends TPHConstraint {
|
||||
|
||||
public EqualConstraint(String left, String right, Relation rel) {
|
||||
super(left, right, rel);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.bytecode.constraint;
|
||||
|
||||
public class ExtendsConstraint extends TPHConstraint {
|
||||
|
||||
public ExtendsConstraint(String left, String right, Relation rel) {
|
||||
super(left, right, rel);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package de.dhbwstuttgart.bytecode.constraint;
|
||||
|
||||
public class TPHConstraint {
|
||||
protected String left;
|
||||
protected String right;
|
||||
protected Relation rel;
|
||||
public enum Relation{
|
||||
EXTENDS, EQUAL
|
||||
}
|
||||
|
||||
public TPHConstraint(String left, String right, Relation rel) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.rel = rel;
|
||||
}
|
||||
|
||||
public String getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
public String getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
|
||||
public Relation getRel() {
|
||||
return rel;
|
||||
}
|
||||
|
||||
public void setLeft(String left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public void setRight(String right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public void setRel(Relation rel) {
|
||||
this.rel = rel;
|
||||
}
|
||||
|
||||
public boolean containTPH(String tph) {
|
||||
return left.equals(tph)||right.equals(tph);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(rel == Relation.EXTENDS) {
|
||||
return left + " < " + right;
|
||||
}else {
|
||||
return left + " = " + right;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,12 +2,14 @@ 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 org.objectweb.asm.Type;
|
||||
|
||||
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 +48,20 @@ 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 ")) {
|
||||
// Bound ist immer Object
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} 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 +77,13 @@ 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)+"$")+ ";";
|
||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += ")" + "L"+resType+ ";";
|
||||
}
|
||||
}
|
||||
}else {
|
||||
desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
@ -90,10 +106,17 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
if(constructor.getGenericsAndBounds().containsKey(fpDesc)){
|
||||
desc += "L"+constructor.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 ")) {
|
||||
// Bound ist immer Object
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += "L"+resType+ ";";
|
||||
}
|
||||
}
|
||||
}else {
|
||||
// System.out.println("Cons has NOT Gens");
|
||||
// System.out.println("Cons has NO Gens");
|
||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}
|
||||
@ -107,9 +130,21 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";";
|
||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + "L"+ d + ";";
|
||||
}
|
||||
}
|
||||
|
||||
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + ")"+"L"+retType+";";
|
||||
}
|
||||
desc = addReturnType(desc, lambdaExpression.getReturnType(), resultSet);
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -119,9 +154,22 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
|
||||
while(itr.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||
desc = desc + "L"+resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc += "L"+ d + ";";
|
||||
|
||||
}
|
||||
}
|
||||
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + ")"+"L"+retType+";";
|
||||
}
|
||||
desc = desc + ")"+"L"+resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -129,26 +177,34 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
public String visit(MethodFromMethodCall methodFromMethodCall) {
|
||||
String desc = "(";
|
||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||
String d = e.getType().acceptTV(new TypeToDescriptor());
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
|
||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.toString().equals("void")) {
|
||||
String retType = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
System.out.println("DescriptorToString retType = " + retType);
|
||||
if(retType.equals("void")) {
|
||||
desc += ")V";
|
||||
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
String ret = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(ret)) {
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(ret)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(ret)){
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(ret)+ ";";
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(retType)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(retType)){
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(retType)+ ";";
|
||||
}else {
|
||||
desc += ")" + "L"+resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
desc += ")" + "L"+retType+ ";";
|
||||
}
|
||||
}
|
||||
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
|
@ -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,11 +13,15 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
return refType.getName().toString().replace(".", "/");
|
||||
// String t = refType.getName().toString().replace(".", "/");
|
||||
// return t.equals("Fun1")?(t+"$$"):t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
||||
return superWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,7 +31,9 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
||||
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
469
src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java
Normal file
@ -0,0 +1,469 @@
|
||||
package de.dhbwstuttgart.bytecode.signature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class Signature {
|
||||
private ClassOrInterface classOrInterface;
|
||||
private HashMap<String, String> genericsAndBounds;
|
||||
private HashMap<String, String> genericsAndBoundsMethod;
|
||||
private SignatureWriter sw;
|
||||
private Constructor constructor;
|
||||
private Method method;
|
||||
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
||||
private ResultSet resultSet;
|
||||
private ArrayList<GenericInsertPair> commonPairs;
|
||||
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
||||
private ArrayList<TypePlaceholder> tphsClass;
|
||||
private ArrayList<TPHConstraint> consClass;
|
||||
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||
ArrayList<GenericInsertPair> commonPairs, ArrayList<TypePlaceholder> tphsClass, ArrayList<TPHConstraint> consClass) {
|
||||
this.classOrInterface = classOrInterface;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.commonPairs = commonPairs;
|
||||
this.tphsClass = tphsClass;
|
||||
this.consClass = consClass;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForClassOrInterface();
|
||||
}
|
||||
|
||||
public Signature(Constructor constructor, HashMap<String, String> genericsAndBounds,
|
||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes,ResultSet resultSet,
|
||||
HashMap<TPHConstraint,HashSet<String>> methodConstraints) {
|
||||
this.constructor = constructor;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||
this.resultSet = resultSet;
|
||||
this.methodConstraints = methodConstraints;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForConsOrMethod(this.constructor,true);
|
||||
}
|
||||
|
||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,HashMap<String, String> genericsAndBounds,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet,
|
||||
HashMap<TPHConstraint,HashSet<String>> methodConstraints) {
|
||||
this.method = method;
|
||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||
this.resultSet = resultSet;
|
||||
this.methodConstraints = methodConstraints;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForConsOrMethod(this.method,false);
|
||||
}
|
||||
|
||||
public Signature(LambdaExpression lambdaExpression,int numberOfParams) {
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForFunN(lambdaExpression, numberOfParams);
|
||||
}
|
||||
|
||||
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
|
||||
|
||||
// sw.visitClassBound().visitEnd();
|
||||
for(int i = 0;i<numberOfParams;i++) {
|
||||
int j = i+1;
|
||||
sw.visitFormalTypeParameter("T"+ j);
|
||||
// getBounds von Params
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
|
||||
sw.visitFormalTypeParameter("R");
|
||||
// getBounds vom Return-Type
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
// TODO: prüfe ob Return-Type = void,
|
||||
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));;
|
||||
sw.visitEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates signature for a method or constructor with @see {@link SignatureWriter}
|
||||
* Signature looks like:
|
||||
* <typevaliables (K:Ljava/lang/Object "Bounds")>(params L.. OR T.. Or basistape)ReturnType
|
||||
*
|
||||
* @param method method or constructor
|
||||
* @param isConstructor true if constructor
|
||||
*/
|
||||
private void createSignatureForConsOrMethod(Method method, boolean isConstructor) {
|
||||
Iterator<? extends GenericTypeVar> itr = method.getGenerics().iterator();
|
||||
// visits all formal type parameter and visits their bounds <T:...;B:...;...>
|
||||
while(itr.hasNext()) {
|
||||
System.out.println("HAS GENERICS!!");
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||
}
|
||||
|
||||
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
|
||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||
if(!isConstructor) {
|
||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
ArrayList<TPHConstraint> allConsBeforeSimplify = new ArrayList<>();
|
||||
|
||||
HashMap<TPHConstraint,HashSet<String>> allConstraints = new HashMap<>();
|
||||
|
||||
if(ret.contains("<")) {
|
||||
allConsBeforeSimplify = getAllConstraints((RefType) resultSet.resolveType(method.getReturnType()).resolvedType);
|
||||
}
|
||||
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||
String pT = t.acceptTV(new TypeToSignature());
|
||||
|
||||
if(pT.contains("<"))
|
||||
allConsBeforeSimplify = getAllConstraints((RefType) t);
|
||||
}
|
||||
boolean doSimplify = false;
|
||||
if(!allConsBeforeSimplify.isEmpty()) {
|
||||
addConstraintsToMap(allConstraints,allConsBeforeSimplify);
|
||||
doSimplify = true;
|
||||
}
|
||||
createTypeVars(allConstraints, doSimplify);
|
||||
|
||||
if(!ret.equals("V")) {
|
||||
if(ret.contains("$") && !ret.contains("$$") && !ret.contains("<")) {
|
||||
if(genericsAndBounds.containsKey(ret)) {
|
||||
genericsAndBoundsMethod.put(ret.substring(1), genericsAndBounds.get(ret.substring(1)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// visit each method-parameter to create the signature
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||
// parameter type deswegen ist true
|
||||
doVisitParamsOrReturn(t,true);
|
||||
}
|
||||
if(isConstructor ||
|
||||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).equals("V")) {
|
||||
sw.visitReturnType().visitBaseType('V');
|
||||
}else {
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
// return type deswegen ist false
|
||||
doVisitParamsOrReturn(returnType, false);
|
||||
}
|
||||
// sw.visitEnd();
|
||||
}
|
||||
|
||||
private void addConstraintsToMap(HashMap<TPHConstraint, HashSet<String>> allConstraints,
|
||||
ArrayList<TPHConstraint> allConsBeforeSimplify) {
|
||||
for(TPHConstraint tphCons : allConsBeforeSimplify) {
|
||||
allConstraints.put(tphCons, null);
|
||||
}
|
||||
}
|
||||
|
||||
private String getEqualTPH(HashMap<TPHConstraint, HashSet<String>> methodConstraints, String tph) {
|
||||
for(TPHConstraint cons : methodConstraints.keySet()) {
|
||||
if(methodConstraints.get(cons) != null) {
|
||||
if(methodConstraints.get(cons).contains(tph)) {
|
||||
return cons.getLeft();
|
||||
}
|
||||
}
|
||||
}
|
||||
return tph;
|
||||
}
|
||||
|
||||
private void createTypeVars(HashMap<TPHConstraint, HashSet<String>> allConstraints, boolean doSimplify) {
|
||||
allConstraints.putAll(methodConstraints);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> simplifiedConstraints;
|
||||
if(doSimplify) {
|
||||
simplifiedConstraints = Simplify.simplifyContraints(allConstraints);
|
||||
}else {
|
||||
simplifiedConstraints = allConstraints;
|
||||
}
|
||||
|
||||
for(TPHConstraint cons : simplifiedConstraints.keySet()) {
|
||||
// need subst.
|
||||
String sub = cons.getLeft()+"$";
|
||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||
sw.visitFormalTypeParameter(sub);
|
||||
String bound = cons.getRight();
|
||||
if(bound.equals(Type.getInternalName(Object.class))) {
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(sub, bound);
|
||||
} else {
|
||||
String boundName = bound+"$";
|
||||
sw.visitClassBound().visitTypeVariable(boundName);
|
||||
genericsAndBoundsMethod.put(sub, boundName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<TPHConstraint> getAllConstraints(RefType ref) {
|
||||
final ArrayList<TPHConstraint> res = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
ResolvedType resType;
|
||||
if(p instanceof WildcardType) {
|
||||
resType = resultSet.resolveType(((WildcardType) p).getInnerType());
|
||||
}else {
|
||||
resType = resultSet.resolveType(p);
|
||||
}
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
||||
if(resolved instanceof TypePlaceholder) {
|
||||
resType.additionalGenerics.forEach(ag ->{
|
||||
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||
if(!contains(res,constr)) {
|
||||
res.add(constr);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(resolved instanceof WildcardType) {
|
||||
WildcardType resWC = (WildcardType) resolved;
|
||||
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
||||
if(resType2.resolvedType instanceof TypePlaceholder) {
|
||||
resType2.additionalGenerics.forEach(ag ->{
|
||||
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||
if(!contains(res,constr)) {
|
||||
res.add(constr);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("RES GIP === " + res.size());
|
||||
return res;
|
||||
}
|
||||
private boolean contains(ArrayList<TPHConstraint> constraints, TPHConstraint constr) {
|
||||
for(int i=0; i<constraints.size();++i) {
|
||||
TPHConstraint p = constraints.get(i);
|
||||
if(constr.getLeft().equals(p.getLeft()) && constr.getRight().equals(p.getRight()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
||||
* the method signature
|
||||
* @param t type of parameter or return type
|
||||
* @param isParameterType true if t is type of parameter
|
||||
*/
|
||||
private void doVisitParamsOrReturn(RefTypeOrTPHOrWildcardOrGeneric t, boolean isParameterType) {
|
||||
String type = t.acceptTV(new TypeToString());
|
||||
SignatureVisitor sv;
|
||||
if(isParameterType) {
|
||||
sv = sw.visitParameterType();
|
||||
}
|
||||
else {
|
||||
sv = sw.visitReturnType();
|
||||
}
|
||||
switch (type) {
|
||||
case "RT":
|
||||
String sig = t.acceptTV(new TypeToSignature());
|
||||
sv.visitClassType(sig.substring(1, sig.length()));
|
||||
break;
|
||||
case "GRT":
|
||||
GenericRefType g = (GenericRefType) t;
|
||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
||||
break;
|
||||
case "TPH":
|
||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||
// der Fall wenn die Type eine Interface ist, muss betrachtet werden
|
||||
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
|
||||
// Interface oder eine Klasse ist.
|
||||
|
||||
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
||||
//
|
||||
String sig2 = r.acceptTV(new TypeToSignature());
|
||||
String eqTPH = getEqualTPH(methodConstraints, sig2.substring(1, sig2.length()-1))+"$";
|
||||
if(!(r instanceof TypePlaceholder)) {
|
||||
if(sig2.contains("$$")) {
|
||||
System.out.println(" Signature FUN$$: "+r);
|
||||
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
||||
} else {
|
||||
sv.visitClassType(sig2.substring(1, sig2.length()));
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
||||
sv.visitTypeVariable(eqTPH);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "SWC":
|
||||
System.out.println("SWC---Signature");
|
||||
SuperWildcardType swc = (SuperWildcardType) t;
|
||||
String sigInner = swc.getInnerType().acceptTV(new TypeToSignature());
|
||||
if(swc.getInnerType() instanceof TypePlaceholder) {
|
||||
sv.visitTypeArgument('-').visitTypeVariable(sigInner.substring(1, sigInner.length()));
|
||||
} else if(swc.getInnerType() instanceof RefType) {
|
||||
if(sigInner.contains("$$")) {
|
||||
sv.visitTypeArgument('-').visitInterface().visitClassType(sigInner.substring(1,sigInner.length()));
|
||||
}else {
|
||||
sv.visitTypeArgument('-').visitClassType(sigInner.substring(1,sigInner.length()));
|
||||
}
|
||||
}else {
|
||||
sv.visitTypeArgument('-').visitTypeVariable(sigInner.substring(1));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "EWC":
|
||||
System.out.println("EWC---Signature");
|
||||
ExtendsWildcardType ewc = (ExtendsWildcardType) t;
|
||||
String esigInner = ewc.getInnerType().acceptTV(new TypeToSignature());
|
||||
System.out.println(esigInner);
|
||||
if(ewc.getInnerType() instanceof TypePlaceholder) {
|
||||
sv.visitTypeArgument('+').visitTypeVariable(esigInner.substring(1, esigInner.length()));
|
||||
} else if(ewc.getInnerType() instanceof RefType) {
|
||||
if(esigInner.contains("$$")) {
|
||||
sv.visitTypeArgument('+').visitInterface().visitClassType(esigInner.substring(1,esigInner.length()));
|
||||
}else {
|
||||
// sv.visitClassType(esigInner.substring(1,esigInner.length()));
|
||||
sv.visitTypeArgument('+').visitClassType(esigInner.substring(1,esigInner.length()));
|
||||
}
|
||||
}else {
|
||||
sv.visitTypeArgument('+').visitTypeVariable(esigInner.substring(1));
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if(!isParameterType)
|
||||
sv.visitBaseType('V');
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates signature for class or interface with {@link SignatureWriter}
|
||||
* Signature looks like:
|
||||
* <typevaliables (K:Ljava/lang/Object "Bounds")>superclass
|
||||
*/
|
||||
private void createSignatureForClassOrInterface() {
|
||||
Iterator<GenericTypeVar> itr = classOrInterface.getGenerics().iterator();
|
||||
|
||||
while(itr.hasNext()) {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
||||
}
|
||||
|
||||
if(!consClass.isEmpty()) {
|
||||
ArrayList<String> types = new ArrayList<>();
|
||||
ArrayList<String> superTypes = new ArrayList<>();
|
||||
|
||||
for(TPHConstraint cons : consClass) {
|
||||
types.add(cons.getLeft());
|
||||
superTypes.add(cons.getRight());
|
||||
}
|
||||
|
||||
for(TPHConstraint cons : consClass) {
|
||||
String t = cons.getLeft()+"$";
|
||||
String bound = cons.getRight()+"$";
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
}
|
||||
|
||||
for(TPHConstraint cons : consClass) {
|
||||
if(!types.contains(cons.getRight())) {
|
||||
String t = cons.getRight()+"$";
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*if(!commonPairs.isEmpty()) {
|
||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
types.add(p.TA1);
|
||||
superTypes.add(p.TA2);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
String t = p.TA1.getName()+"$";
|
||||
String bound = p.TA2.getName()+"$";
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
if(!types.contains(p.TA2)) {
|
||||
String t = p.TA2.getName()+"$";
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
for(TypePlaceholder t : tphsClass) {
|
||||
String n = t.getName()+"$";
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(n);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBounds.put(n, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}*/
|
||||
String sClass = classOrInterface.getSuperClass().acceptTV(new TypeToSignature());
|
||||
sw.visitSuperclass().visitClassType(sClass.substring(1, sClass.length()-1));
|
||||
sw.visitEnd();
|
||||
}
|
||||
/**
|
||||
* Get bounds of type variable
|
||||
* @param g type variable
|
||||
* @param genAndBounds
|
||||
*/
|
||||
private void getBoundsOfTypeVar(GenericTypeVar g, HashMap<String, String> genAndBounds) {
|
||||
sw.visitFormalTypeParameter(g.getName());
|
||||
|
||||
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
||||
while(bItr.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric b =bItr.next();
|
||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||
// System.out.println("GetBounds: " + boundDesc);
|
||||
// Ensure that <...> extends java.lang.Object OR ...
|
||||
sw.visitClassBound().visitClassType(boundDesc);
|
||||
genAndBounds.put(g.getName(), boundDesc);
|
||||
}
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package de.dhbwstuttgart.bytecode.signature;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
||||
|
||||
public class TypeToSignature implements TypeVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
if(refType.getName().toString().equals("void"))
|
||||
return "V";
|
||||
// return refType.toString().replace(".", "/");
|
||||
String params = "";
|
||||
if(refType.getParaList().size()>0){
|
||||
params += "<";
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
||||
while(it.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
||||
// if(param instanceof TypePlaceholder) {
|
||||
// params += "T" + ((TypePlaceholder) param).getName() + "$";
|
||||
// } else if(param instanceof ExtendsWildcardType) {
|
||||
// params += "+" + ((ExtendsWildcardType) param).getInnerType().acceptTV(new TypeToSignature());
|
||||
// } else if(param instanceof SuperWildcardType) {
|
||||
// params += "-" + ((SuperWildcardType) param).getInnerType().acceptTV(new TypeToSignature());
|
||||
// } else {
|
||||
// params += "L"+param.toString().replace(".", "/");
|
||||
// }
|
||||
params += param.acceptTV(new TypeToSignature());
|
||||
|
||||
if(param instanceof TypePlaceholder)
|
||||
params += ";";
|
||||
}
|
||||
params += ">";
|
||||
}
|
||||
// String t = refType.getName().toString().replace(".", "/");
|
||||
// return t.equals("Fun1")?t+"$$"+params+";":t+params+";";
|
||||
return "L"+refType.getName().toString().replace(".", "/") + params+";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
// throw new NotImplementedException();
|
||||
String sig = "-" + superWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
||||
if(superWildcardType.getInnerType() instanceof TypePlaceholder)
|
||||
sig += ";";
|
||||
return sig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
// return typePlaceholder.toString().replace(".", "/");
|
||||
return "T" + typePlaceholder.getName() + "$";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
// throw new NotImplementedException();
|
||||
String sig = "+" + extendsWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
||||
if(extendsWildcardType.getInnerType() instanceof TypePlaceholder)
|
||||
sig += ";";
|
||||
return sig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
return genericRefType.getParsedName().replace(".", "/");
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ public class TypeToString implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
return "SWC";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,7 +27,7 @@ public class TypeToString implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
return "EWC";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,25 +1,37 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
public class KindOfLambda implements StatementVisitor{
|
||||
private ParameterList params;
|
||||
private boolean isInstanceCapturingLambda = false;
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> argumentList = new ArrayList<>();
|
||||
private ArrayList<String> usedVars = new ArrayList<>();
|
||||
private boolean hasThis = false;
|
||||
private ArrayList<String> definedLocals = new ArrayList<>();
|
||||
|
||||
public KindOfLambda(LambdaExpression lambdaExpression) {
|
||||
this.params = lambdaExpression.params;
|
||||
lambdaExpression.methodBody.accept(this);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getUsedVars() {
|
||||
return usedVars;
|
||||
}
|
||||
|
||||
public boolean isInstanceCapturingLambda() {
|
||||
return this.isInstanceCapturingLambda;
|
||||
}
|
||||
@ -28,6 +40,10 @@ public class KindOfLambda implements StatementVisitor{
|
||||
return argumentList;
|
||||
}
|
||||
|
||||
public boolean isHasThis() {
|
||||
return hasThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
// TODO Auto-generated method stub
|
||||
@ -46,8 +62,8 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
binary.lexpr.accept(this);
|
||||
binary.rexpr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,8 +98,9 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
ifStmt.expr.accept(this);
|
||||
ifStmt.then_block.accept(this);
|
||||
ifStmt.else_block.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,14 +111,31 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if(!contain(params, localVar.name) && !definedLocals.contains(localVar.name)) {
|
||||
argumentList.add(localVar.getType());
|
||||
if(hasThis) {
|
||||
usedVars.add(1, localVar.name);
|
||||
} else {
|
||||
usedVars.add(0, localVar.name);
|
||||
}
|
||||
if(!isInstanceCapturingLambda)
|
||||
isInstanceCapturingLambda=true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean contain(ParameterList params2, String name) {
|
||||
Iterator<FormalParameter> itr = params2.iterator();
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
if(fp.getName().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
definedLocals.add(localVarDecl.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +162,7 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,13 +190,20 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
this.isInstanceCapturingLambda = true;
|
||||
this.argumentList.add(aThis.getType());
|
||||
if(!hasThis) {
|
||||
hasThis = true;
|
||||
this.argumentList.add(0,aThis.getType());
|
||||
}
|
||||
if(!isInstanceCapturingLambda) {
|
||||
this.isInstanceCapturingLambda = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
whileStmt.expr.accept(this);
|
||||
whileStmt.loopBlock.accept(this);
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
@ -0,0 +1,29 @@
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
|
||||
public class MethodAndTPH {
|
||||
|
||||
private String name;
|
||||
private final ArrayList<String> tphs = new ArrayList<>();
|
||||
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||
|
||||
public MethodAndTPH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<String> getTphs() {
|
||||
return tphs;
|
||||
}
|
||||
|
||||
public ArrayList<GenericInsertPair> getPairs(){
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -9,13 +9,16 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
public class MethodFromMethodCall {
|
||||
private ArgumentList argList;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
private String receiverName;
|
||||
private HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String,String> genericsAndBounds;
|
||||
|
||||
public MethodFromMethodCall(ArgumentList argList,RefTypeOrTPHOrWildcardOrGeneric returnType,
|
||||
HashMap<String, String> genericsAndBoundsMethod,HashMap<String,String> genericsAndBounds) {
|
||||
public MethodFromMethodCall(ArgumentList argList,RefTypeOrTPHOrWildcardOrGeneric returnType,
|
||||
String receiverName, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String,String> genericsAndBounds) {
|
||||
this.argList = argList;
|
||||
this.returnType = returnType;
|
||||
this.receiverName = receiverName;
|
||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
}
|
||||
@ -28,6 +31,10 @@ public class MethodFromMethodCall {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public String getReceiverName() {
|
||||
return receiverName;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getGenericsAndBoundsMethod(){
|
||||
return genericsAndBoundsMethod;
|
||||
}
|
@ -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;
|
||||
|
651
src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java
Normal file
@ -0,0 +1,651 @@
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.EqualConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class Simplify {
|
||||
|
||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor, ArrayList<TypePlaceholder> tphsClass) {
|
||||
// 1. check if there are any simple cycles like L<R and R<L:
|
||||
// a) yes => set L=R and:
|
||||
// * remove both constraints
|
||||
// * substitute L with R in all constraint
|
||||
// b)no => go to next step
|
||||
// 2. check the result of step 1 if there are any equal-constraints like L=R, M=R ..
|
||||
// a) yes => put all such TPhs in a map and define "key-Cons"
|
||||
// -- key-Cons = TPH < Object --
|
||||
// put this Constraint and the
|
||||
// b) no
|
||||
// 3. is
|
||||
|
||||
// all constraints that will be simplified
|
||||
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||
|
||||
// step 1:
|
||||
for(TPHConstraint c : allCons) {
|
||||
|
||||
String left = c.getLeft();
|
||||
String right = c.getRight();
|
||||
if(c.getRel() == Relation.EXTENDS) {
|
||||
TPHConstraint revCon = getReverseConstraint(allCons,left,right);
|
||||
if(revCon != null) {
|
||||
revCon.setRel(Relation.EQUAL);
|
||||
// the reverse constraint is removed because
|
||||
// otherwise there is the same constraint twice
|
||||
// (e.g. A<B and B<A => A=B and B=A)
|
||||
consToRemove.add(revCon);
|
||||
c.setRel(Relation.EQUAL);
|
||||
substituteTPH(allCons,left, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("NEW ALL CONST: " + allCons.size());
|
||||
allCons.forEach(c->System.out.println(c.toString()));
|
||||
System.out.println("----------------");
|
||||
allCons.removeAll(consToRemove);
|
||||
consToRemove = new ArrayList<>();
|
||||
|
||||
int size = allCons.size();
|
||||
|
||||
System.out.println("AFTER DELETE ALL CONST: " + allCons.size());
|
||||
allCons.forEach(c->System.out.println(c.toString()));
|
||||
System.out.println("----------------");
|
||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||||
|
||||
// check if there is any long cycle (e.g. A<B<C<A)
|
||||
|
||||
// to save all types that are in relation
|
||||
LinkedList<String> allTypes = new LinkedList<>();
|
||||
// we will put all constraints which are in the cycle, in this ArrayList.
|
||||
// Later these contraints will be converted to equal-constraints
|
||||
ArrayList<TPHConstraint> constraints = new ArrayList<>(size);
|
||||
int visited = 0;
|
||||
|
||||
// contains all constraints
|
||||
HashMap<String,String> ss1 = new HashMap<>();
|
||||
|
||||
for(TPHConstraint constr : allCons) {
|
||||
ss1.put(constr.getLeft(), constr.getRight());
|
||||
}
|
||||
|
||||
for(TPHConstraint c : allCons) {
|
||||
|
||||
if(visited >= size)
|
||||
break;
|
||||
// Only extends-constraints will be checked
|
||||
if(c.getRel() == Relation.EXTENDS) {
|
||||
++visited;
|
||||
|
||||
String left = c.getLeft();
|
||||
String right = c.getRight();
|
||||
// put the types in linked list
|
||||
allTypes.add(left);
|
||||
allTypes.add(right);
|
||||
|
||||
constraints.add(c);
|
||||
|
||||
boolean isCycle = false;
|
||||
|
||||
// iterate through the map to check if there is a cycle
|
||||
while(ss1.containsKey(right)) {
|
||||
++visited;
|
||||
String oldRight = right;
|
||||
right = ss1.get(right);
|
||||
|
||||
TPHConstraint toAdd = getConstraint(oldRight, right, allCons);
|
||||
|
||||
if(toAdd != null)
|
||||
constraints.add(toAdd);
|
||||
|
||||
if(left.equals(right)) {
|
||||
isCycle = true;
|
||||
break;
|
||||
}
|
||||
|
||||
allTypes.add(right);
|
||||
}
|
||||
|
||||
if(isCycle) {
|
||||
// convert all constraints to equal constraints
|
||||
setAllEqual(constraints);
|
||||
// these constraints will be removed from allCons
|
||||
consToRemove.addAll(constraints);
|
||||
// all equal types will be substitute with one type
|
||||
substituteAllTPH(allCons,constraints,left);
|
||||
|
||||
HashSet<String> eq = new HashSet<>();
|
||||
// put all equal types in a set
|
||||
for(String t:allTypes) {
|
||||
eq.add(t);
|
||||
}
|
||||
// generate a new constraint (left < Object)
|
||||
TPHConstraint constraint = new ExtendsConstraint(left, Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
// put the generated constraint and its equal set into result set
|
||||
result.put(constraint, eq);
|
||||
constraints.clear();
|
||||
}
|
||||
allTypes.clear();
|
||||
}
|
||||
}
|
||||
// build an equal set that contains all types
|
||||
// which are equal and for each equal constraint put left side and right side
|
||||
// in this set Then generate a constraint type < Object and put it
|
||||
// with the equal set into the result.
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getRel()==Relation.EQUAL) {
|
||||
if(!isTPHInResEqual(result, c.getLeft())) {
|
||||
HashSet<String> equalTPHs = getEqualsTPHs(result, c);
|
||||
TPHConstraint constraint = getKeyConstraint(result,c);
|
||||
equalTPHs.add(c.getLeft());
|
||||
equalTPHs.add(c.getRight());
|
||||
result.put(constraint, equalTPHs);
|
||||
}
|
||||
consToRemove.add(c);
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Step 2 Result: ");
|
||||
result.forEach((c,hs)->{
|
||||
System.out.print(c.toString() + " -> ");
|
||||
hs.forEach(s->{
|
||||
System.out.print(s + ", ");
|
||||
});
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
// remove all equal-constraints
|
||||
allCons.removeAll(consToRemove);
|
||||
// add all generated constraints to allCons
|
||||
allCons.addAll(result.keySet());
|
||||
|
||||
if(!allCons.isEmpty() && allCons.size()<2) {
|
||||
TPHConstraint cons = allCons.get(0);
|
||||
if(!result.containsKey(cons)) {
|
||||
result.put(cons, null);
|
||||
result.put(new ExtendsConstraint(cons.getRight(), Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
size += result.keySet().size();
|
||||
// all constraints which have Object on the right side will
|
||||
// be ignored, because they are simplified and can not be changed.
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getRight().equals(Type.getInternalName(Object.class)))
|
||||
size--;
|
||||
}
|
||||
// get all tph of the method
|
||||
ArrayList<String> methodTphs = new ArrayList<>();
|
||||
for(MethodAndTPH m : tphExtractor.ListOfMethodsAndTph) {
|
||||
if(m.getName().equals(name)) {
|
||||
methodTphs = m.getTphs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// check if there are multiple constraint with the same left side.
|
||||
// if yes => check if the super type in the method, if not
|
||||
// then ignore it.
|
||||
HashMap<String, String> subAndSuper = new HashMap<>();
|
||||
ArrayList<TPHConstraint> eqCons = new ArrayList<>();
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(subAndSuper.containsKey(c.getLeft())) {
|
||||
LinkedList<String> all = new LinkedList<>();
|
||||
all.add(c.getLeft());
|
||||
String sup =c.getRight();
|
||||
all.add(sup);
|
||||
HashMap<String, String> ss = new HashMap<>();
|
||||
for(TPHConstraint constr : allCons) {
|
||||
ss.put(constr.getLeft(), constr.getRight());
|
||||
}
|
||||
while(ss.containsKey(sup)) {
|
||||
sup = ss.get(sup);
|
||||
all.add(sup);
|
||||
}
|
||||
if(!containTPH(methodTphs, all.getLast()))
|
||||
continue;
|
||||
}
|
||||
if(subAndSuper.containsKey(c.getLeft())) {
|
||||
System.out.println(c.getLeft());
|
||||
String r = c.getRight();
|
||||
String r2 = subAndSuper.get(c.getLeft());
|
||||
EqualConstraint eq = new EqualConstraint(r2, r, Relation.EQUAL);
|
||||
eqCons.add(eq);
|
||||
substituteInMap(subAndSuper,eqCons,allCons,r,r2);
|
||||
}
|
||||
subAndSuper.put(c.getLeft(), c.getRight());
|
||||
}
|
||||
|
||||
System.out.println("SAME LEFT SIDE: ");
|
||||
subAndSuper.forEach((c,hs)->{
|
||||
if(c!=null) {
|
||||
System.out.print(c+ " -> " + hs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
int numOfVisitedPairs = 0;
|
||||
for(String sub : subAndSuper.keySet()) {
|
||||
if(isTPHInConstraint(result,sub))
|
||||
continue;
|
||||
|
||||
if(!containTPH(methodTphs,sub))
|
||||
continue;
|
||||
|
||||
if(numOfVisitedPairs>=size)
|
||||
break;
|
||||
LinkedList<String> tphInRel = new LinkedList<>();
|
||||
tphInRel.add(sub);
|
||||
String superT = subAndSuper.get(sub);
|
||||
tphInRel.add(superT);
|
||||
|
||||
numOfVisitedPairs++;
|
||||
while(subAndSuper.containsKey(superT)) {
|
||||
superT = subAndSuper.get(superT);
|
||||
if(tphInRel.contains(superT)) {
|
||||
break;
|
||||
}
|
||||
tphInRel.add(superT);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
// Subtype
|
||||
String subTphRes = tphInRel.getFirst();
|
||||
// Die größte Supertype
|
||||
String superTphRes = tphInRel.getLast();
|
||||
|
||||
// if there is any constraint X < subTph, then
|
||||
// add X at the beginning of the list.
|
||||
while(subAndSuper.containsValue(subTphRes)) {
|
||||
for(String tph : subAndSuper.keySet()) {
|
||||
if(containTPH(methodTphs,tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
||||
subTphRes = tph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(subTphRes.equals(tphInRel.getFirst())) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(isTPHInConstraint(result, subTphRes))
|
||||
break;
|
||||
|
||||
tphInRel.addFirst(subTphRes);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
subTphRes = tphInRel.getFirst();
|
||||
// if the last type in the list not a type in method-types
|
||||
// then find the last type in front of this type, which is
|
||||
// a type in method-types
|
||||
int i = 2;
|
||||
while(!containTPH(methodTphs,superTphRes) && (tphInRel.size()-i) >0) {
|
||||
superTphRes = tphInRel.get(tphInRel.size()-i);
|
||||
i++;
|
||||
}
|
||||
|
||||
if(!containTPH(methodTphs, superTphRes)) {
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,superTphRes);
|
||||
if(classTPHSContainsTPH(tphsClass,superTphRes)) {
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||
} else {
|
||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), equals);
|
||||
}
|
||||
|
||||
} else {
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,subTphRes);
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||
if(!isTPHInConstraint(result, superTphRes) && !isTphInEqualSet(result,superTphRes)) {
|
||||
HashSet<String> equals2 = getEqualsTphsFromEqualCons(eqCons,superTphRes);
|
||||
result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), equals2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(String tph : methodTphs) {
|
||||
if(!isTPHInConstraint(result, tph) && !isTphInEqualSet(result,tph)) {
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,tph);
|
||||
result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class), Relation.EXTENDS), equals);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("EndResult: ");
|
||||
result.forEach((c,hs)->{
|
||||
if(c!=null) {
|
||||
System.out.print(c.toString() + " -> ");
|
||||
if(hs == null) {
|
||||
System.out.print(" [] ");
|
||||
}else {
|
||||
hs.forEach(s->{
|
||||
System.out.print(s + ", ");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean classTPHSContainsTPH(ArrayList<TypePlaceholder> tphsClass, String superTphRes) {
|
||||
for(TypePlaceholder tph : tphsClass) {
|
||||
if(tph.getName().equals(superTphRes))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isTphInEqualSet(HashMap<TPHConstraint, HashSet<String>> result, String tph) {
|
||||
for(HashSet<String> hs: result.values()) {
|
||||
if(hs.contains(tph))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HashSet<String> getEqualsTphsFromEqualCons(ArrayList<TPHConstraint> eqCons, String tph) {
|
||||
HashSet<String> ee = new HashSet<>();
|
||||
for(TPHConstraint c : eqCons) {
|
||||
if(c.getLeft().equals(tph))
|
||||
ee.add(c.getRight());
|
||||
if(c.getRight().equals(tph))
|
||||
ee.add(c.getLeft());
|
||||
}
|
||||
return ee;
|
||||
}
|
||||
|
||||
private static void substituteInMap(HashMap<String, String> subAndSuper, ArrayList<TPHConstraint> allCons,ArrayList<TPHConstraint> eqCons, String toSubs,
|
||||
String tph) {
|
||||
substituteTPH(allCons, toSubs, tph);
|
||||
if(subAndSuper.containsKey(toSubs) && subAndSuper.containsKey(tph)) {
|
||||
toSubs = subAndSuper.remove(toSubs);
|
||||
EqualConstraint eq = new EqualConstraint(subAndSuper.get(tph), toSubs, Relation.EQUAL);
|
||||
eqCons.add(eq);
|
||||
substituteInMap(subAndSuper, allCons,eqCons,toSubs, subAndSuper.get(tph));
|
||||
} else if(subAndSuper.containsKey(toSubs) && !subAndSuper.containsKey(tph)) {
|
||||
String val = subAndSuper.remove(toSubs);
|
||||
subAndSuper.put(tph, val);
|
||||
} else {
|
||||
for(String k : subAndSuper.keySet()) {
|
||||
subAndSuper.replace(k, toSubs, tph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TPHConstraint getConstraint(String oldRight, String right, ArrayList<TPHConstraint> allCons) {
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getLeft().equals(oldRight) && c.getRight().equals(right))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isTPHInResEqual(HashMap<TPHConstraint, HashSet<String>> result, String left) {
|
||||
for(HashSet<String> eq : result.values()) {
|
||||
if(eq.contains(left)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void substituteAllTPH(ArrayList<TPHConstraint> allCons, ArrayList<TPHConstraint> constraints,
|
||||
String first) {
|
||||
for(TPHConstraint c : allCons) {
|
||||
for(TPHConstraint c2 : constraints) {
|
||||
if(c.getRel() == Relation.EXTENDS) {
|
||||
if(c2.getLeft().equals(c.getLeft()) || c2.getRight().equals(c.getLeft()))
|
||||
c.setLeft(first);
|
||||
if(c2.getLeft().equals(c.getRight()) || c2.getRight().equals(c.getRight()))
|
||||
c.setRight(first);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setAllEqual(ArrayList<TPHConstraint> constraints) {
|
||||
for(TPHConstraint c:constraints) {
|
||||
c.setRel(Relation.EQUAL);
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyContraints(HashMap<TPHConstraint, HashSet<String>> allConstraints) {
|
||||
// 1. check if there are any cycles like L<R and R<L:
|
||||
// a) yes => set L=R and:
|
||||
// * remove both constraints
|
||||
// * substitute L with R in all constraint
|
||||
// b)no => go to next step
|
||||
// 2. check the result of step 1 if there are any equal-constraints like L=R, M=R ..
|
||||
// a) yes => put all such TPhs in a map and define "key-Cons"
|
||||
// -- key-Cons = TPH < Object --
|
||||
// put this Constraint and the
|
||||
// b) no
|
||||
// 3. is
|
||||
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||
for(TPHConstraint tphCons : allConstraints.keySet()) {
|
||||
allCons.add(tphCons);
|
||||
}
|
||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||
// step 1:
|
||||
for(TPHConstraint c : allCons) {
|
||||
|
||||
String left = c.getLeft();
|
||||
String right = c.getRight();
|
||||
if(c.getRel() == Relation.EXTENDS) {
|
||||
TPHConstraint revCon = getReverseConstraint(allCons,left,right);
|
||||
if(revCon != null) {
|
||||
revCon.setRel(Relation.EQUAL);
|
||||
consToRemove.add(revCon);
|
||||
c.setRel(Relation.EQUAL);
|
||||
substituteTPH(allCons,left, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("NEW ALL CONST: " + allCons.size());
|
||||
allCons.forEach(c->System.out.println(c.toString()));
|
||||
System.out.println("----------------");
|
||||
allCons.removeAll(consToRemove);
|
||||
consToRemove = new ArrayList<>();
|
||||
|
||||
// int size = allCons.size();
|
||||
|
||||
System.out.println("AFTER DELETE ALL CONST: " + allCons.size());
|
||||
allCons.forEach(c->System.out.println(c.toString()));
|
||||
System.out.println("----------------");
|
||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||||
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getRel()==Relation.EQUAL) {
|
||||
HashSet<String> equalTPHs = getEqualsTPHs(result, c);
|
||||
TPHConstraint constraint = getKeyConstraint(result,c);
|
||||
equalTPHs.add(c.getLeft());
|
||||
equalTPHs.add(c.getRight());
|
||||
result.put(constraint, equalTPHs);
|
||||
consToRemove.add(c);
|
||||
// size--;
|
||||
}
|
||||
}
|
||||
System.out.println("Step 2 Result: ");
|
||||
result.forEach((c,hs)->{
|
||||
System.out.print(c.toString() + " -> ");
|
||||
hs.forEach(s->{
|
||||
System.out.print(s + ", ");
|
||||
});
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
allCons.removeAll(consToRemove);
|
||||
allCons.addAll(result.keySet());
|
||||
|
||||
if(!allCons.isEmpty() && allCons.size()<2) {
|
||||
|
||||
if(!result.containsKey(allCons.get(0)))
|
||||
result.put(allCons.get(0), null);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// size += result.keySet().size();
|
||||
|
||||
// for(TPHConstraint c : allCons) {
|
||||
// if(c.getRight().equals(Type.getInternalName(Object.class)))
|
||||
// size--;
|
||||
// }
|
||||
|
||||
HashMap<String, String> subAndSuper = new HashMap<>();
|
||||
|
||||
for(TPHConstraint c : allCons) {
|
||||
subAndSuper.put(c.getLeft(), c.getRight());
|
||||
}
|
||||
|
||||
// int numOfVisitedPairs = 0;
|
||||
for(String sub : subAndSuper.keySet()) {
|
||||
if(isTPHInConstraint(result,sub))
|
||||
continue;
|
||||
|
||||
// if(numOfVisitedPairs>=size)
|
||||
// break;
|
||||
|
||||
LinkedList<String> tphInRel = new LinkedList<>();
|
||||
tphInRel.add(sub);
|
||||
String superT = subAndSuper.get(sub);
|
||||
tphInRel.add(superT);
|
||||
|
||||
// numOfVisitedPairs++;
|
||||
while(subAndSuper.containsKey(superT)) {
|
||||
superT = subAndSuper.get(superT);
|
||||
if(tphInRel.contains(superT)) {
|
||||
break;
|
||||
}
|
||||
tphInRel.add(superT);
|
||||
// numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
// Subtype
|
||||
String subTphRes = tphInRel.getFirst();
|
||||
// Die größte Supertype
|
||||
String superTphRes = tphInRel.getLast();
|
||||
|
||||
while(subAndSuper.containsValue(subTphRes)) {
|
||||
for(String tph : subAndSuper.keySet()) {
|
||||
if(subAndSuper.get(tph).equals(subTphRes)) {
|
||||
subTphRes = tph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(subTphRes.equals(tphInRel.getFirst())) {
|
||||
break;
|
||||
}
|
||||
tphInRel.addFirst(subTphRes);
|
||||
// numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
subTphRes = tphInRel.getFirst();
|
||||
|
||||
int i = 2;
|
||||
while(superTphRes.equals(Type.getInternalName(Object.class)) && (tphInRel.size()-i) >0) {
|
||||
superTphRes = tphInRel.get(tphInRel.size()-i);
|
||||
i++;
|
||||
}
|
||||
if(superTphRes.equals(Type.getInternalName(Object.class))) {
|
||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
} else {
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), null);
|
||||
result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("EndResult: ");
|
||||
result.forEach((c,hs)->{
|
||||
if(c!=null) {
|
||||
System.out.print(c.toString() + " -> ");
|
||||
if(hs == null) {
|
||||
System.out.print(" [] ");
|
||||
}else {
|
||||
hs.forEach(s->{
|
||||
System.out.print(s + ", ");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void substituteTPH(ArrayList<TPHConstraint> allCons,String left ,String right) {
|
||||
allCons.forEach(c->{
|
||||
if(c.getRel() == Relation.EXTENDS) {
|
||||
if(c.getLeft().equals(left))
|
||||
c.setLeft(right);
|
||||
if(c.getRight().equals(left))
|
||||
c.setRight(right);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static TPHConstraint getReverseConstraint(ArrayList<TPHConstraint> allCons, String left, String right) {
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getLeft().equals(right) && c.getRight().equals(left)){
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isTPHInConstraint(HashMap<TPHConstraint, HashSet<String>> result, String sub) {
|
||||
for(TPHConstraint c : result.keySet()) {
|
||||
if(c.getLeft().equals(sub))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean containTPH(ArrayList<String> methodTphs, String sub) {
|
||||
for(String tph : methodTphs) {
|
||||
if(tph.equals(sub))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static TPHConstraint getKeyConstraint(HashMap<TPHConstraint, HashSet<String>> result, TPHConstraint toFind) {
|
||||
for(TPHConstraint c : result.keySet()) {
|
||||
if(c.containTPH(toFind.getLeft()) || c.containTPH(toFind.getRight()))
|
||||
return c;
|
||||
}
|
||||
return new ExtendsConstraint(toFind.getRight(), Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
}
|
||||
|
||||
private static HashSet<String> getEqualsTPHs(HashMap<TPHConstraint,HashSet<String>> result, TPHConstraint toFind) {
|
||||
for(TPHConstraint c : result.keySet()) {
|
||||
if(c.containTPH(toFind.getLeft()) || c.containTPH(toFind.getRight()))
|
||||
return result.get(c);
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|