Compare commits

...

198 Commits

Author SHA1 Message Date
Martin Plümicke
23786184ad modified: test/strucType/javFiles/testLocalVar.jav 2018-07-04 11:05:25 +02:00
Pluemicke Martin
55f6fe47ac geändert: src/de/dhbwstuttgart/core/JavaTXCompiler.java
geändert:   src/de/dhbwstuttgart/strucTypes/visitor/InferTypes.java
	geändert:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
nach merge mit plugin-Branch
2018-06-09 16:34:05 +02:00
Martin Plümicke
4919dd34b2 Merge branch 'plugin' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypesNew 2018-06-08 14:42:18 +02:00
Martin Plümicke
c08d4b8457 Merge branch 'plugin' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into plugin 2018-06-08 14:39:51 +02:00
Martin Plümicke
aac113e12e Merge branch 'plugin' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypesNew
src/de/dhbwstuttgart/core/JavaTXCompiler.java
	src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java
	src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java
 It looks like you may be committing a merge.
 If this is not correct, please remove the file
	.git/MERGE_HEAD
 and try again.
2018-06-08 14:37:04 +02:00
Martin Plümicke
d2d02e26f0 modified: target/JavaTXcompiler-0.1-jar-with-dependencies.jar 2018-06-08 14:35:22 +02:00
Aldaron7
e9d5d5f7c7 classdiagram added 2018-06-08 14:06:27 +02:00
Aldaron7
092ee53f74 Studienarbeit added. 2018-06-06 21:22:40 +02:00
Aldaron7
413cb48a96 updates to strukture. 2018-06-06 21:22:09 +02:00
Martin Plümicke
e0d5699ae7 deleted: Installation/install.html 2018-06-01 17:13:05 +02:00
Martin Plümicke
3f2558d21e new file: Website/Installation/install.html
new file:   Website/JavaTXExamples.zip
	new file:   Website/index.html
	new file:   Website/install/Restart.png
	new file:   Website/install/availableSoftware1.png
	new file:   Website/install/availableSoftware2.png
	new file:   Website/install/instal.html
	new file:   Website/install/install.html
	new file:   Website/install/installAnyway.png
	new file:   Website/install/installationDetails.png
	new file:   Website/install/licenseAgreement.png
	new file:   Website/install/newsoftware.png
	new file:   Website/install/selectInstallation.png
	new file:   Website/newJavaTXProject/addLibrary2.png
	new file:   Website/newJavaTXProject/buildPath1.png
	new file:   Website/newJavaTXProject/buildPath2.png
	new file:   Website/newJavaTXProject/buildPath3.png
	new file:   Website/newJavaTXProject/buildPath4.png
	new file:   Website/newJavaTXProject/newJavFile.png
	new file:   Website/newJavaTXProject/newJavFolder1.png
	new file:   Website/newJavaTXProject/newJavFolder2.png
	new file:   Website/newJavaTXProject/newJavaTXProject.html
	new file:   Website/newJavaTXProject/newJavaTXProject.png
	new file:   Website/usePlugin/usePlugin.html
	new file:   Website/usePlugin/usePlugin1.png
	new file:   Website/usePlugin/usePlugin2.png
	modified:   test/bytecode/javFiles/OL.jav
2018-06-01 16:57:35 +02:00
Aldaron7
24f93f0bcb updated project structure. Implemented trans. 2018-05-31 15:13:39 +02:00
Aldaron7
f44f08b895 TYPEExpr fixed for newClass. 2018-05-30 23:50:32 +02:00
Martin Plümicke
814aef082d modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
log-File schreiben entfernt
2018-05-30 18:35:57 +02:00
Martin Plümicke
5a0e53485c modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
Unary-Expression SMALLERNEQDOT eingefuegt
	modified:   test/bytecode/javFiles/Fac.jav
2018-05-30 17:23:55 +02:00
JanUlrich
e972282620 Generics fix 2018-05-30 16:14:09 +02:00
JanUlrich
f7160c10f4 Fix Generics parsing 2018-05-30 16:04:13 +02:00
Aldaron7
7a5940ac65 cherrypick ee1fa17 Typegenerator 2018-05-30 15:51:25 +02:00
JanUlrich
86e94b8cc0 cherrypick ee1fa17 Typegenerator 2018-05-30 15:51:08 +02:00
Aldaron7
25a5e79509 update solve (not fixed). 2018-05-30 15:36:28 +02:00
Aldaron7
7e1d6fad01 solve tNew generics superclass and interfaces added. 2018-05-30 12:39:11 +02:00
Aldaron7
c7e0281d53 solve tph zu grt 2018-05-30 11:52:38 +02:00
Aldaron7
23ae5d5745 returntypevisitor added. restructuring. 2018-05-30 09:00:46 +02:00
Martin Plümicke
bb26112a9b modified: ../../../target/JavaTXcompiler-0.1-jar-with-dependencies.jar
modified:   Fac.jav
	modified:   Faculty.jav
	modified:   OL.jav
	modified:   While.jav
	modified:   ../../javFiles/AddLong.jav
2018-05-30 00:27:20 +02:00
Martin Plümicke
97d893e66b Merge branch 'plugin' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into plugin
merge
2018-05-28 16:36:46 +02:00
Martin Plümicke
57fb90afaf modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
LogFile  optional gemacht
2018-05-28 16:35:47 +02:00
JanUlrich
63ac79f02c Hotfix für Typparsen Problem 2018-05-28 16:21:52 +02:00
JanUlrich
07fa62d11d merge Keine Ahnung mit was ... 2018-05-28 16:21:43 +02:00
Martin Plümicke
66587a8f71 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
SMALERNEQDOT in Regel a <!=. Theta korrigiert
SMALERNEQDOT in Regel Theta <!=. a geloescht
2018-05-28 16:07:29 +02:00
Martin Plümicke
581e5e574e Merge branch 'bytecode2' into plugin 2018-05-25 14:41:22 +02:00
Martin Plümicke
ae14dfd947 modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
2018-05-25 14:39:54 +02:00
Martin Plümicke
9d53d9d5d1 modified: src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
kleiner Fehler korrigiert
	modified:   test/javFiles/Matrix.jav
2018-05-25 11:16:02 +02:00
Fayez Abu Alia
58f5e17ab5 FacTest.java 2018-05-25 10:01:44 +02:00
Fayez Abu Alia
6fce2760c5 While.jav 2018-05-25 09:53:30 +02:00
Martin Plümicke
1de897fb1f modified: src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
System.out.println geloescht
2018-05-24 17:59:51 +02:00
Martin Plümicke
87dede5d5f modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
F-Bounded Problematik durche neues greater ggf. geloest.
Es werden Falle ausgeschlossen. Diese Faelle muessen noch ergaenzt werden.
2018-05-24 17:45:10 +02:00
Fayez Abu Alia
f085f9f499 Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2 2018-05-24 16:44:28 +02:00
Fayez Abu Alia
a40d2b991f kleine Änderung 2018-05-24 16:44:05 +02:00
Martin Plümicke
704415ae3b Merge branch 'unifyOptimierung' into plugin
fixed	test/javFiles/Matrix.jav
2018-05-24 16:43:31 +02:00
Martin Plümicke
65531ac12e modified: ../../src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
modified:   ../../src/de/dhbwstuttgart/typeinference/constraints/Pair.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java
Einführung eines neuen Operators SMALLERNEQDOT um Ungleichungen a <!=. Number für die Relationsoperatoren einfuehren zu koennen.

	modified:   ../../test/javFiles/Matrix.jav
2018-05-24 16:20:57 +02:00
Martin Plümicke
34e632b872 modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
Reduce ausgetauscht bei ArgPara und Returntype
	modified:   ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
isUndefinedPair korrigiert.
	modified:   ../../test/bytecode/LambdaTest.java
	modified:   ../../test/bytecode/javFiles/Plus.jav
	modified:   ../../test/bytecode/javFiles/RelOps.jav
2018-05-24 14:11:04 +02:00
Martin Plümicke
3470215bae Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2 2018-05-24 10:48:57 +02:00
Martin Plümicke
f5398fa8e9 deleted: ../../test/logFiles/log 2018-05-24 10:34:50 +02:00
Martin Plümicke
f617ad8946 modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
Relationen auf verschiedene Numeric-Typen umgestellt
im equals Null abgefragt
2018-05-24 10:28:22 +02:00
Martin Plümicke
876ec6a4f6 Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unifyOptimierung
Conflicts:
	src/de/dhbwstuttgart/core/JavaTXCompiler.java
solved
2018-05-24 09:41:15 +02:00
Martin Plümicke
26d9b1215f modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
	modified:   ../../test/javFiles/Matrix.jav
F-Bounded angefangen
2018-05-24 09:17:31 +02:00
Fayez Abu Alia
0f29bc038a Bugs gefixt. Tests für relationalen Operatoren(GreaterEqualTest, ...) laufen.
Für Typplaceholder werden Generics verwendet.

Neue Tests angefügt.
2018-05-23 15:38:41 +02:00
Martin Plümicke
a5ed5a2a46 Merge branch 'unifyOptimierung' into plugin 2018-05-22 17:29:44 +02:00
Martin Plümicke
c597b0430a modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
cardProd als Variable eingfuegt
	modified:   ../../src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java
toString() eingfuegt
	modified:   ../../src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java
toString() eingfuegt
	modified:   ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
BinaryOp <. statt =.
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Bei nicht importierten (result []) undefinPair gesetzt
	modified:   ../javFiles/Matrix.jav
falsche importe rausgenommen
2018-05-22 17:10:07 +02:00
Martin Plümicke
06a0cb8eaf modified: TypeUnifyTask.java
noAllErasedElements eingefuegt
2018-05-19 10:13:08 +02:00
Martin Plümicke
b5a601d798 modified: TypeUnifyTask.java
Varianceweitergabe in den verschiedenen Cases eingefuegt
Erste Zaehlungen eingefuegt
2018-05-19 09:50:57 +02:00
Martin Plümicke
7ea6777906 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   ../javFiles/Lambda.jav
	modified:   ../typeinference/UnifyTest.java
2018-05-18 13:12:49 +02:00
Martin Plümicke
6b1896f58c modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified:   src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java
greaterFUNN und smallFUNN fuer generierte TPHs Variance gesetzt
	modified:   test/javFiles/Lambda.jav
vom bytecode ruebergeholt
2018-05-18 09:55:45 +02:00
Martin Plümicke
d81c06cdd9 modified: ../../src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java
Implementierung fuer FuNN eingefuegt
	deleted:    ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java

wahrscheinlich bei FuNN-Regeln Variance setzen.
2018-05-18 00:03:07 +02:00
Martin Plümicke
8baff8f376 modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
Variancenvererbung eingefuegt
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Variancenvererbung geloescht
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   ../../test/typeinference/UnifyTest.java
2018-05-17 22:51:41 +02:00
Aldaron7
427a87598c solve added 2018-05-17 21:35:14 +02:00
Martin Plümicke
bc2cab8c95 modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   test/javFiles/Lambda.jav
	modified:   test/javFiles/Lambda3.jav
2018-05-17 18:07:21 +02:00
JanUlrich
dca5d21c23 JavaCompilerCoreWithDependencies upload 2018-05-17 12:47:01 +02:00
Martin Plümicke
51a2acdbaf modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   test/typeinference/UnifyTest.java
2018-05-17 11:42:03 +02:00
Fayez Abu Alia
dcc36f082f code aufräumen 2018-05-16 13:37:31 +02:00
Fayez Abu Alia
9575afd0b4 Fun umbenannt und Argumente umgedreht 2018-05-15 10:33:30 +02:00
Aldaron7
403430d0c4 adapt2 incode docu added 2018-05-12 15:22:31 +02:00
Aldaron7
d9ab487253 adapt2 rule implemented 2018-05-12 14:59:48 +02:00
Martin Plümicke
5c797a44a1 modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
disableWildcardtable in den FUNN-Regeln eingefuegt.
2018-05-10 09:07:33 +02:00
Martin Plümicke
87dbcfdad4 Merge branch 'unifyOptimierung' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unifyOptimierung
Merge
2018-05-09 18:10:17 +02:00
Martin Plümicke
8048af2106 modified: ../../test/javFiles/Lambda2.jav
modified:   ../../test/typeinference/UnifyTest.java
2018-05-09 18:10:08 +02:00
Martin Plümicke
e4243b612c modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
Operatoren neue getypte
Returnargument bei FUNN nach hinten verschoben
	modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
Returnargument bei FUNN nach hinten verschoben
Wildcards in Argumenten von als Undefined Pairs (funktioniert noch nicht)
Methode wrongWildcard eingefuegt
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
Methode doubleWildcard ind wrongWildcard umbenannt
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
Methode doubleWildcard ind wrongWildcard umbenannt
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java
Methode doubleWildcard ind wrongWildcard umbenannt
2018-05-09 18:05:06 +02:00
Martin Plümicke
da4c59f2cf modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
modified:   ../../test/typeinference/UnifyTest.java
2018-05-09 16:24:28 +02:00
Martin Plümicke
1c22fc7d57 Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unifyOptimierung
merge bytecode2
2018-05-09 13:29:11 +02:00
Martin Plümicke
0b7aea21d9 modified: ../../test/bytecode/LambdaTest.java
modified:   ../../test/bytecode/javFiles/Lambda2.jav
2018-05-08 18:52:43 +02:00
Fayez Abu Alia
521a1cbf3b Bug 77 gefixt 2018-05-08 17:42:58 +02:00
Martin Plümicke
22ca2cbd4a modified: BytecodeGenMethod.java 2018-05-08 11:28:24 +02:00
Fayez Abu Alia
49ea4ee283 Pfad der erzeugten klassendateien angepasst 2018-05-08 10:19:13 +02:00
Martin Plümicke
225dc16a89 modified: test/typeinference/UnifyTest.java 2018-05-08 09:23:20 +02:00
Aldaron7
6f85c2b376 fixed RuleSetStrucType refl(). 2018-05-07 19:03:47 +02:00
Aldaron7
a17342458e fixed Construct. Changed Field and Method Types to GenericRefType. 2018-05-07 18:37:21 +02:00
Martin Plümicke
4738add4fc modified: ../../../../../test/javFiles/Matrix.jav
modified:   ../../../../../test/typeinference/UnifyTest.java
2018-05-07 15:31:31 +02:00
Aldaron7
ab46709390 Fixed Construct. Added Structure for TUnify. Implemented refl. 2018-05-06 19:06:41 +02:00
JanUlrich
bc99dc4c8b Merge branch 'plugin' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into plugin 2018-05-02 21:30:11 +02:00
JanUlrich
2bbf9eac36 target/repository anlegen 2018-05-02 21:08:32 +02:00
Fayez Abu Alia
a785c85d42 tests 2018-05-02 20:54:07 +02:00
Aldaron7
48e22982c8 Fehler in Construct für Typen der Felder, und Methoden der generierten Interfaces markiert mit //TODO 2018-04-30 20:28:12 +02:00
Aldaron7
3ed300268f fixed: Interfaces des selben Typs werden nur noch einmal generiert, auch wenn sie mehrfach in unterschiedlichen Constraints vorkommen. 2018-04-30 19:43:26 +02:00
Martin Plümicke
ec2b501e63 new file: test/javFiles/LambdaField.jav
modified:   test/typeinference/UnifyTest.java
Lambda-Ausdruck als Attribute/field eingefuegt
2018-04-26 15:10:23 +02:00
Martin Plümicke
8be4f94edf modified: test/javFiles/Matrix.jav
In Matrix.jav Binary-Operation eingefuegt.

	new file:   test/javFiles/Meth_Gen.jav
	new file:   test/typeinference/Meth_GenTest.java
Test zu Constraints ueber eine Methode hinaus
2018-04-25 23:32:12 +02:00
Fayez Abu Alia
1b6cae1be0 GenTest angefügt 2018-04-25 16:44:27 +02:00
JanUlrich
41774b3faf Merge mit bytecode 2018-04-25 16:13:23 +02:00
Martin Plümicke
62d44eb15c modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Undefined Pairs auf oberster Ebene wird zu new HashTable<>() in compute
	new file:   ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
Unterscheidung zw. <. <? ein compere eingefuegt
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
Attribut wildcardable eingefuegt
2018-04-24 00:53:33 +02:00
Martin Plümicke
5f8c73f176 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
In compare wird die Gleichung a =. Theta neu gefiltert
2018-04-22 00:56:49 +02:00
Martin Plümicke
0ae777b4ac modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
varianceInheritance nach TypeUnifyTask.java verschoben
Kommentar eingefuegt

TODO:
1. compare-Funktinen nochmals ueberpruefen
2. Undef-Pairs in JavaTXiCompiler.java abfangen
3. ? extends bei allen Argumenttypen und Returntypen rauslassen
2018-04-20 23:52:12 +02:00
Martin Plümicke
087170bdbf modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
Variance wieder auskommentiert
	modified:   test/javFiles/Matrix.jav
import String
2018-04-20 13:16:49 +02:00
Martin Plümicke
93d0caaefb modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Varianceberechnung geaendert
2018-04-20 09:36:29 +02:00
Martin Plümicke
1f031149d3 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
Varianceweitergabe eingefuegt
2018-04-20 01:08:35 +02:00
Martin Plümicke
fc870fd706 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java 2018-04-18 19:44:00 +02:00
4450f5c0cd Merge 2018-04-18 15:08:37 +02:00
Fayez Abu Alia
478a2df3dc Statische Methoden Test 2018-04-18 11:51:10 +02:00
Martin Plümicke
59243d9f94 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java 2018-04-17 16:31:13 +02:00
Martin Plümicke
82b08c5aae modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
Wildcard Ordnung veraendert
2018-04-17 14:25:52 +02:00
Martin Plümicke
615983bf37 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
resuat add in cartesion angepasst
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java

equals in UnfyPair auf UndefinedPairs angepasst
2018-04-13 18:13:31 +02:00
Martin Plümicke
21bc2a67a1 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java 2018-04-11 16:58:38 +02:00
Fayez Abu Alia
52a96d7253 OL Test eingefügt 2018-04-11 13:55:32 +02:00
Martin Plümicke
fef4d27d21 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java 2018-04-11 11:10:08 +02:00
Martin Plümicke
603c4c9c46 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
logging ergaenzt

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
getSubstitution() durch getAllSubstitutions() ersetzt
2018-04-06 20:01:14 +02:00
Martin Plümicke
baee0024e9 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Zu beginn von unify werden doppelte wildcard konstruktionen entfernt
Variableneumbenennung bei smaller in Fall 1 weider entfernt

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
In computeGreater unify durch match ersetzt

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java
Abfrage ob eine doppelte wildcard konstruktion vorhanden ist eingefuegt
2018-04-05 18:09:24 +02:00
Martin Plümicke
1baaf79f8c modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
UndefPairs werden zurueckgegegeben und die naechsten gefiltert

protected boolean isUndefinedPairSet(Set<UnifyPair> s) hat Fehler
2018-04-04 21:47:07 +02:00
Martin Plümicke
52f480147e modified: src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java
modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java

Subsitution auf UnifyPair umgestellt
2018-04-04 01:14:30 +02:00
Martin Plümicke
9717c54d53 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Mehrfacher Aufruf von computeCartesianRecursive entfernt
2018-04-03 14:16:38 +02:00
Martin Plümicke
c271c689de modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
abhaengige Substitutionen auch bei Faellen 1 - 8 eingefuegt
2018-04-03 10:29:58 +02:00
Martin Plümicke
24c27303dd modified: src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java
modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
Substututions die eine UnifyPair erzeugen eingefuegt
UnifyCase1-8 weitermachen
2018-04-01 22:04:10 +02:00
Martin Plümicke
117106a7b3 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
? ext theta bei smaller eingefuegt

	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
basiPair und Subsitution nur noch gefuegt, wen wirk etwas eingesetzt wurde

	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
unifier umbenannt in substitution
getBasePair und getSubsitutuon eingefuegt
2018-04-01 17:07:58 +02:00
Martin Plümicke
5680f913ef modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
new file:   src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	new file:   src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java
2018-03-28 17:42:25 +02:00
Aldaron7
ebacb72dcb Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypesNew 2018-03-28 16:37:09 +02:00
Fayez Abu Alia
32ab198f9e Bugfix für duplicate methods 2018-03-28 14:57:36 +02:00
Martin Plümicke
fae26a8f26 modified: src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java
modified:   src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java

Visitors verallgemeinert
2018-03-28 12:06:23 +02:00
Fayez Abu Alia
bb5a4e8580 Bug 72 gefixt 2018-03-28 11:31:32 +02:00
Martin Plümicke
663ce36e22 modified: test/strucType/javFiles/testFieldMethod.jav
Mehrfache Aufrufe eines Receivers mit unterschiedlichen Methoden/Fields eingefügt
Fehler: die Interfaces werden zwar richtig generiert. Allerdings werden die Inerfaces
mehrfach mit unterschiedlichen generisches Typvariabeln generiert. Einmal würde reichen:

class: constructedinterface.DE <BoGTV MH, BoGTV MI, BoGTV MK>
field: g : TPH MH

 method: m2 : TPH MI
parameter: MK : TPH MK

 superClass: java.lang.Object

und

class: constructedinterface.DE <BoGTV MR, BoGTV MS, BoGTV MU>
field: g : TPH MR

 method: m2 : TPH MS
parameter: MU : TPH MU

 superClass: java.lang.Object
2018-03-27 18:55:07 +02:00
Fayez Abu Alia
a0de7a4467 Test, bei dem Bug 72 auftritt 2018-03-24 20:28:26 +01:00
Aldaron7
ce2b4e0303 Anpassung bei typisierungen in TYPEExpr, Anpassung Ausgabe 2018-03-23 21:41:31 +01:00
Martin Plümicke
0b680f831d modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
2018-03-22 20:40:22 +01:00
JanUlrich
52dd0e6276 Merge branch 'bigRefactoring' into strucTypesNew 2018-03-22 11:42:46 +01:00
Martin Plümicke
95e9b2dbda modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
Variance auf PlacehloderType uebertragen
2018-03-22 11:26:29 +01:00
Pluemicke Martin
dbe05bb718 modified: src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java
Feher rausgemacht

TODO: Varianven werden nicht uebertragen wahrscheinlich subst
2018-03-21 17:37:34 +01:00
Pluemicke Martin
4ac99b61bf Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test 2018-03-21 17:07:14 +01:00
Pluemicke Martin
f107c8d1f7 modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
Variancebestimmung fuer Argument- und Returntypen der Methoden eingefuegt.
2018-03-21 17:03:32 +01:00
Aldaron7
f29faa2680 Neuer Branch. Merge mit bigRefactoring 2018-03-21 16:04:41 +01:00
Fayez Abu Alia
8870bc326c Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2 2018-03-21 13:47:19 +01:00
Fayez Abu Alia
e1c6369bcb Bytecode für Post-/Preincrement und Post-/Predecrement 2018-03-21 13:08:39 +01:00
Pluemicke Martin
46255efb70 Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test 2018-03-21 11:29:01 +01:00
Pluemicke Martin
5dfa6769b2 Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test 2018-03-21 11:16:45 +01:00
Pluemicke Martin
100db9baac Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test
Fehler by atElement
2018-03-21 11:13:20 +01:00
Martin Plümicke
5d39863cc6 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Maximumsbildung auf maximale Elemente soweit fertig
Argument von mul funktion nicht, liefret nur Vec<TypPl>
2018-03-20 22:30:57 +01:00
Martin Plümicke
01dd4e57e6 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
Letzte Version bevor MatchUnifyTask
2018-03-20 10:14:01 +01:00
Martin Plümicke
6faffdf90c modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java 2018-03-19 17:43:27 +01:00
Martin Plümicke
f4bc057aff modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
LogAusgabe FC

	modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
fresh TV in unifyCase1 auf alle cs ausgedehnt
	modified:   test/javFiles/Matrix.jav
2018-03-19 15:25:40 +01:00
Martin Plümicke
78db0f0177 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Errorrueckgabe auskommentiert
	new file:   src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java
eingecheckt vorher vergessen
	modified:   test/javFiles/Matrix.jav
add und mul aktiviert
2018-03-19 09:38:37 +01:00
Fayez Abu Alia
3233ccd845 Overloading funktioniert. Erzeugt Bytecode für Postincrement (für Integers). 2018-03-18 16:08:52 +01:00
Martin Plümicke
b0b1426e20 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
new file:   src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
freshtypevraiable Vistor soweit fertig noch nicht getestet
2018-03-18 15:11:45 +01:00
Martin Plümicke
103c7e4b14 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
visitor freshPlaceholder implements UnifyTypeVisitor
2018-03-17 15:01:03 +01:00
Martin Plümicke
3638edfa73 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   test/javFiles/Matrix.jav
Fehler entdeckt, in unifyCase1 fuer die Typen aus FC keine fresh TV getsetzt werden.
2018-03-16 14:10:40 +01:00
Martin Plümicke
bd98bed5ca Merge branch 'unify-test' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test
Merge
2018-03-15 20:50:59 +01:00
Martin Plümicke
6299086297 modified: typeinference/unify/TypeUnifyTask.java
modified:   typeinference/unify/model/UnifyPair.java
2018-03-15 20:47:16 +01:00
Martin Plümicke
de5b43d72b modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java

Links der substitierten Pare eingefuegt.
2018-03-15 17:00:26 +01:00
Martin Plümicke
7e6dee8e1d modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   ../javFiles/Matrix.jav
2018-03-14 17:48:04 +01:00
Fayez Abu Alia
dafcd2f125 Bytecode für While-Schleifen 2018-03-14 15:51:38 +01:00
Martin Plümicke
273ddb92d7 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
	modified:   ../javFiles/Matrix.jav
2018-03-14 13:56:28 +01:00
Martin Plümicke
dea3da3b69 Merge branch 'bigRefactoring' into unify-test
Fehelr mit elementAt geloest
2018-03-13 10:41:57 +01:00
Martin Plümicke
13c70148a8 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
	modified:   ../javFiles/Matrix.jav
mul1 und add ergaenzt.
Fehler bei elementAt: Liefert Object als Returntyp
2018-03-13 08:46:25 +01:00
Martin Plümicke
1667b394f2 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
Variancen gesetzt
2018-03-11 20:39:38 +01:00
Martin Plümicke
95943b1627 modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
compare(Matrix, Vector<gen_ab>, ? extends Vector<? extends Integer>> <.? gen_ab
   eingefuegt.
2018-03-10 12:32:07 +01:00
Martin Plümicke
0315a1f144 modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
compare(Matrix, Vector<gen_ab>, ? extends Vector<? extends Integer>> <.? gen_ab
funktioniert nicht
2018-03-10 01:04:19 +01:00
Fayez Abu Alia
52a5fd7904 erzeugt Bytecode für relationale Operatoren. Getestet. 2018-03-09 21:57:39 +01:00
Martin Plümicke
b5b5b5d9c9 modified: ../../src/de/dhbwstuttgart/typeinference/constraints/Pair.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
Varinace in UnfyPair eingefuegt und Abfrage in computeCartesianRecursive eingefuegt
Pruefen, ob Varianve bei Subst und andrene erhalten bleibt.
2018-03-09 01:23:02 +01:00
Martin Plümicke
9862df9e63 modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java

Minimum funktion soweit
2018-03-08 01:12:17 +01:00
Martin Plümicke
ccc16fd22b modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java

1. Version mit compare von UnifyPairs
2018-03-07 13:09:47 +01:00
Fayez Abu Alia
54cf24926e Bytecode arithmetische Operatoren unterschiedlischer Typen vollständig und getestet 2018-03-07 12:26:30 +01:00
Fayez Abu Alia
94d39ee21a Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2 2018-03-07 11:49:16 +01:00
Fayez Abu Alia
f453343f1c Bytecode für arithmetische Operatoren mit Parametern unterschiedlicher Typen. Testfälle bereinigt und aufgeräumt. 2018-03-06 19:14:27 +01:00
Martin Plümicke
bb016e6417 modified: src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java
modified:   src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
2018-03-05 20:04:10 +01:00
Martin Plümicke
831bf1fe17 modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
weitere Fälle in die Ordnung eingebaut
2018-03-04 22:58:31 +01:00
Martin Plümicke
cba489f279 modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
eine Variable korrigiert
TODO eingefuegt
compare muss fuer ale moeglichen Faelle aus calculatePairSets erstellt werden
2018-03-03 01:07:25 +01:00
Martin Plümicke
9f3439a15e x 2018-03-02 14:12:06 +01:00
Martin Plümicke
356b8a7a34 modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Eq for Unify vereinfachen noch nicht fertig
2018-03-01 18:00:38 +01:00
Martin Plümicke
6256bdfe2e modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
In Unfy:
- Bildung des kartesischen Produkts auf secondlevel-Ebene entfernt

In computeCartesianRecursive:
- Vereinigung der Ergebnisse ueber die Schleifen und die Rekursion eingefuegt
- Minimumbestimmung korrigiert
2018-03-01 12:27:38 +01:00
Martin Plümicke
6a9db81981 Merge 2018-02-28 17:16:28 +01:00
JanUlrich
aa631b5099 UnifyTest korrekt benennen 2018-02-28 16:35:45 +01:00
JanUlrich
a3a02fe475 Merge branch 'bigRefactoring' into unify-Test 2018-02-28 16:34:48 +01:00
Martin Plümicke
cef82c6359 Typgenerator auf alten Stand setzen, damit Matrix test lauft 2018-02-28 16:27:08 +01:00
Martin Plümicke
67fe88215a eigenerTest 2018-02-28 16:25:45 +01:00
Martin Plümicke
f31023b4fa merge2 2018-02-28 16:16:22 +01:00
Martin Plümicke
a733eee8b5 merge 2018-02-28 16:12:57 +01:00
Martin Plümicke
15f5a2dc76 Merge branch 'bigRefactoring' into unify-Test 2018-02-28 16:10:08 +01:00
Martin Plümicke
6fcaafe477 test 2018-02-28 16:07:02 +01:00
Fayez Abu Alia
35b99a4095 Bytecode kann für folgende Operationen +,-,*,/,% erzeugt werden 2018-02-28 15:59:21 +01:00
Fayez Abu Alia
6b57aacef0 Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2 2018-02-28 14:58:58 +01:00
Fayez Abu Alia
2277f68509 Ordner manually/ in .gitignore hinzugefügt 2018-02-25 13:20:19 +01:00
Martin Plümicke
1c0fa6a820 modified: de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified:   de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
logFile eingefuegt
2018-02-24 19:56:22 +01:00
Martin Plümicke
8e198679c7 Instabiler Zustand reduce funktionert nicht 2018-02-23 00:37:59 +01:00
Martin Plümicke
419e4a6d0e MERGE
Merge branch 'unify-test' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test
2018-02-21 17:55:47 +01:00
Pluemicke Martin
5cd2ee7d80 geändert: src/de/dhbwstuttgart/core/JavaTXCompiler.java
geändert:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
recursiveCartesionProduct wieder entfernt
2018-02-21 17:54:26 +01:00
Martin Plümicke
9c35f04a09 modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java 2018-02-21 17:22:23 +01:00
Martin Plümicke
89246ece5c modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   test/javFiles/Matrix.jav
2018-02-21 14:02:48 +01:00
Martin Plümicke
5270cecec9 Changes to be committed:
modified:   src/de/dhbwstuttgart/core/JavaTXCompiler.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   test/javFiles/Matrix.jav

Fehler in der Aufteilung von Unify korrigiert.
Equalcheck in Schritt 6 wiedre eingefuegt.
2018-02-14 17:45:08 +01:00
Martin Plümicke
87fe51767c modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
Reduce 1
C und D koennen auch gleich sein.
Muss nochmals ueberprueft werden.
2018-02-09 22:55:40 +01:00
Martin Plümicke
f0610aeff1 Changes to be committed:
modified:   src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   test/typeinference/JavaTXCompilerTest.java
2018-02-09 21:32:15 +01:00
Martin Plümicke
e4fbd17a55 modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified:   test/javFiles/Matrix.jav
Rekursive Berechnung des Kartesischen Produkts
2018-02-08 00:02:27 +01:00
Martin Plümicke
1f269918fb nicht lauffaehig 2018-02-07 16:53:24 +01:00
5a3dcd7100 Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into plugin 2018-01-31 16:43:04 +01:00
1a1ab2696d Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into plugin 2018-01-31 16:06:21 +01:00
9186f5dff5 Alle Dependencies werden in eine Jar gepackt. Diese in Eclipseplugin umwandeln und einbinden funktioniert \o/ 2018-01-24 19:05:09 +01:00
5c9b40e0b7 Rumprobieren. Nicht lauffähig 2018-01-24 16:37:01 +01:00
JanUlrich
bd0678f362 Lokales Repo eintragen 2018-01-21 11:17:20 +01:00
a08e2e8815 Versuche google und reflections auch noch als plugin zu verpacken. WIll nicht funktionieren 2018-01-19 17:48:25 +01:00
47689f2fc6 ZIP-FIle erstellen 2018-01-19 16:55:23 +01:00
b7aca99301 local maven repository 2018-01-19 16:36:08 +01:00
JanUlrich
8920b32020 Unnötige import entfernen 2018-01-19 15:28:54 +01:00
da41857a4f Plugin deploy backup 2018-01-19 15:22:29 +01:00
09dcdaeb96 Local Repo anfügen 2018-01-19 15:14:39 +01:00
6d0392956d Pom anpassen 2018-01-19 14:34:41 +01:00
266 changed files with 10030 additions and 970 deletions

3
.gitignore vendored
View File

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

19
README.md Normal file
View File

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

BIN
Website/JavaTXExamples.zip Normal file

Binary file not shown.

88
Website/index.html Normal file
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

84
pom.xml
View File

@@ -7,6 +7,7 @@
<groupId>de.dhbwstuttgart</groupId>
<artifactId>JavaTXcompiler</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>JavaTXcompiler</name>
<url>http://maven.apache.org</url>
@@ -53,7 +54,7 @@
<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/</sourceDirectory>
<testSourceDirectory>test/</testSourceDirectory>
@@ -71,10 +72,7 @@
<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>
<arguments> <argument>-package</argument> <argument>de.dhbwstuttgart.parser.antlr</argument> </arguments>
</configuration>
</execution>
<execution>
@@ -93,19 +91,91 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.1.2-SNAPSHOT</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<!-- specify your depencies here -->
<!-- groupId:artifactId:version -->
<artifact>
<id>de.dhbwstuttgart:JavaTXcompiler:0.1</id>
</artifact>
<artifact><id>org.reflections:reflections:0.9.11</id></artifact>
<artifact><id>com.google.guava:guava:22.0</id></artifact>
<artifact><id>javax.annotation:javax.annotation-api:1.3.1</id></artifact>
<artifact><id>org.glassfish:javax.annotation:3.1.1</id></artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>archive-repository</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
<source>9</source>
<target>9</target>
</configuration>
</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>

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,9 @@
package de.dhbwstuttgart.bytecode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;
@@ -9,11 +11,14 @@ import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
import de.dhbwstuttgart.bytecode.signature.Signature;
import de.dhbwstuttgart.bytecode.signature.TypeToString;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
@@ -23,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class BytecodeGen implements ASTVisitor {
@@ -30,9 +36,10 @@ public class BytecodeGen implements ASTVisitor {
ClassWriter cw =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
String type;
String className;
private boolean isInterface;
private List<ResultSet> listOfResultSets;
private ResultSet resultSet;
private int indexOfFirstParam = 0;
@@ -47,16 +54,18 @@ public class BytecodeGen implements ASTVisitor {
byte[] bytecode;
HashMap<String,byte[]> classFiles;
public BytecodeGen(HashMap<String,byte[]> classFiles, ResultSet resultSet) {
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets) {
this.classFiles = classFiles;
this.resultSet = resultSet;
this.listOfResultSets = listOfResultSets;
}
@Override
public void visit(SourceFile sourceFile) {
for(ClassOrInterface cl : sourceFile.getClasses()) {
System.out.println("in Class: " + cl.getClassName().toString());
BytecodeGen classGen = new BytecodeGen(classFiles, resultSet);
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
cl.accept(classGen);
classGen.writeClass(cl.getClassName().toString());
}
@@ -101,18 +110,27 @@ public class BytecodeGen implements ASTVisitor {
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
// for each field in the class
for(Field f : classOrInterface.getFieldDecl()) {
f.accept(this);
}
// resultSet = listOfResultSets.get(0);
boolean isConsWithNoParamsVisited = false;
for(ResultSet rs : listOfResultSets) {
resultSet = rs;
for(Constructor c : classOrInterface.getConstructors()) {
if(!isConsWithNoParamsVisited)
c.accept(this);
if(!c.getParameterList().iterator().hasNext())
isConsWithNoParamsVisited = true;
}
for(Method m : classOrInterface.getMethods()) {
m.accept(this);
}
for(Constructor c : classOrInterface.getConstructors()) {
c.accept(this);
}
for(Method m : classOrInterface.getMethods()) {
m.accept(this);
}
}
@Override
@@ -146,23 +164,40 @@ public class BytecodeGen implements ASTVisitor {
mv.visitMaxs(0, 0);
mv.visitEnd();
}
@Override
public void visit(Method method) {
// TODO: check if the method is static => if static then the first param will be stored in pos 0
// else it will be stored in pos 1 and this will be stored in pos 0
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
String methParamTypes = retType+method.name+"%%";
method.getParameterList().accept(this);
Iterator<FormalParameter> itr = method.getParameterList().iterator();
while(itr.hasNext()) {
FormalParameter fp = itr.next();
methParamTypes += resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
}
if(methodNameAndParamsT.contains(methParamTypes)) {
return;
}
methodNameAndParamsT.add(methParamTypes);
System.out.println("Method: "+method.name +" , paramsType: "+methParamTypes);
String methDesc = null;
// Method getModifiers() ?
int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier;
System.out.println(acc);
boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()));
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ");
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
if(!hasGenInParameterList) {
for(String paramName : methodParamsAndTypes.keySet()) {
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
if(genericsAndBounds.containsKey(typeOfParam)) {
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")) {
hasGenInParameterList = true;
break;
}
@@ -170,27 +205,31 @@ public class BytecodeGen implements ASTVisitor {
}
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
//than create the descriptor with the new syntax.
//then create the descriptor with the new syntax.
String sig = null;
/* method.getGenerics: <....> RT method(..)
* */
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
/* if method has generics or return type is TPH, create signature */
// zwite operand muss weggelassen werden
if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
// resultset hier zum testen
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
sig = signature.toString();
}
System.out.println(sig);
// System.out.println(sig);
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
methDesc = meth.accept(new DescriptorToString(resultSet));
System.out.println(methDesc);
// System.out.println(methDesc);
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
mv.visitCode();
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,cw,
genericsAndBounds,genericsAndBounds,isInterface,classFiles);
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
mv.visitMaxs(0, 0);
mv.visitEnd();
}

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@@ -2,12 +2,12 @@ package de.dhbwstuttgart.bytecode.descriptor;
import java.util.Iterator;
import de.dhbwstuttgart.bytecode.Lambda;
import de.dhbwstuttgart.bytecode.MethodFromMethodCall;
import de.dhbwstuttgart.bytecode.NormalConstructor;
import de.dhbwstuttgart.bytecode.NormalMethod;
import de.dhbwstuttgart.bytecode.SamMethod;
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
import de.dhbwstuttgart.bytecode.utilities.Lambda;
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.type.RefType;
@@ -46,12 +46,19 @@ public class DescriptorToString implements DescriptorVisitor{
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";";
}else {
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.subSequence(0, 4).equals("TPH ")) {
desc += "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
} else {
desc += "L"+resType+ ";";
}
}
}
// else if(((RefType) fp.getType()).getParaList().size() > 0){
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "%").replace("<", "%%").replace(">", "%%")+ ";";
// }
//TODO: generate a class java%% ... %%
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
}
else {
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
}
@@ -67,7 +74,12 @@ public class DescriptorToString implements DescriptorVisitor{
}else if(method.getGenericsAndBounds().containsKey(ret)){
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
}else {
desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
if(resType.subSequence(0, 4).equals("TPH ")) {
desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
} else {
desc += ")" + "L"+resType+ ";";
}
}
}else {
desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";

View File

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

View File

@@ -13,6 +13,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
@Override
public String visit(RefType refType) {
return refType.getName().toString().replace(".", "/");
// String t = refType.getName().toString().replace(".", "/");
// return t.equals("Fun1")?(t+"$$"):t;
}
@Override
@@ -27,7 +29,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
@Override
public String visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
return extendsWildcardType.getInnerType().toString().replace(".", "/");
//throw new NotImplementedException();
}
@Override

View File

@@ -59,10 +59,7 @@ public class Signature {
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
sw.visitFormalTypeParameter("R");
// getBounds vom Return-Type
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
// sw.visitClassBound().visitEnd();
for(int i = 0;i<numberOfParams;i++) {
int j = i+1;
sw.visitFormalTypeParameter("T"+ j);
@@ -70,6 +67,11 @@ public class Signature {
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
}
sw.visitFormalTypeParameter("R");
// getBounds vom Return-Type
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
// TODO: prüfe ob Return-Type = void,
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));;
sw.visitEnd();
@@ -90,7 +92,31 @@ public class Signature {
GenericTypeVar g = itr.next();
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
}
// visits each method-parameter to create the signature
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
if(ret.substring(0,4).equals("TPH ")) {
String g = ret.substring(4)+"$";
sw.visitFormalTypeParameter(g);
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
}
for(String paramName : methodParamsAndTypes.keySet()) {
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
String pT = t.acceptTV(new TypeToSignature());
// S.o
if(pT.substring(0,4).equals("TPH ") && !genericsAndBoundsMethod.containsKey(pT)) {
String gP = pT.substring(4)+"$";
sw.visitFormalTypeParameter(gP);
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
genericsAndBoundsMethod.put(gP, Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
}
}
// visit each method-parameter to create the signature
for(String paramName : methodParamsAndTypes.keySet()) {
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
// parameter type deswegen ist true
@@ -99,6 +125,15 @@ public class Signature {
if(isConstructor) {
sw.visitReturnType().visitBaseType('V');
}else {
// String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
// if(ret.substring(0,4).equals("TPH ")) {
// String g = ret.substring(4);
// if(!genericsAndBoundsMethod.containsKey(g)) {
// genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
// } else {
// genericsAndBoundsMethod.put(g+"_", Type.getInternalName(Object.class));
// }
// }
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
// return type deswegen ist false
doVisitParamsOrReturn(returnType, false);
@@ -130,10 +165,16 @@ public class Signature {
break;
case "TPH":
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH "))
sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
// sv.visitClassType(r.acceptTV(new TypeToSignature()));
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
// der Fall wenn die Type eine Interface ist, muss betrachtet werden
// Deswegen muss in ResutSet noch enthalten werden, ob die Type eine
// Interface oder eine Klasse ist.
if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) {
// sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
sv.visitClassType(r.acceptTV(new TypeToSignature()));
} else {
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
sv.visitTypeVariable(r.acceptTV(new TypeToSignature()).substring(4)+"$");
}
break;
default:
if(!isParameterType)

View File

@@ -27,6 +27,8 @@ public class TypeToSignature implements TypeVisitor<String> {
}
params += ";>";
}
// String t = refType.getName().toString().replace(".", "/");
// return t.equals("Fun1")?t+"$$"+params+";":t+params+";";
return refType.getName().toString().replace(".", "/") + params+";";
}

View File

@@ -1,4 +1,4 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.statement.*;

View File

@@ -1,4 +1,4 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import de.dhbwstuttgart.bytecode.descriptor.DescriptorVisitor;
import de.dhbwstuttgart.syntaxtree.ParameterList;

View File

@@ -1,4 +1,4 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package de.dhbwstuttgart.bytecode;
package de.dhbwstuttgart.bytecode.utilities;
import java.util.List;

View File

@@ -1,133 +1,180 @@
package de.dhbwstuttgart.core;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.bytecode.BytecodeGen;
import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.strucTypes.Construct;
import de.dhbwstuttgart.strucTypes.Solve;
import de.dhbwstuttgart.strucTypes.StrucTYPE;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class JavaTXCompiler {
final CompilationEnvironment environment;
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
final CompilationEnvironment environment;
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile));
}
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile));
}
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
environment = new CompilationEnvironment(sources);
for (File s : sources) {
sourceFiles.put(s, parse(s));
}
}
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
environment = new CompilationEnvironment(sources);
for (File s : sources) {
sourceFiles.put(s, parse(s));
}
}
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
for (SourceFile sf : sourceFiles.values()) {
allClasses.addAll(sf.getClasses());
}
List<ClassOrInterface> importedClasses = new ArrayList<>();
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for (File forSourceFile : sourceFiles.keySet())
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
ClassOrInterface importedClass = ASTFactory.createClass(
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
importedClasses.add(importedClass);
}
allClasses.addAll(importedClasses);
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
for (SourceFile sf : sourceFiles.values()) {
allClasses.addAll(sf.getClasses());
}
List<ClassOrInterface> importedClasses = new ArrayList<>();
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
// FC
for (File forSourceFile : sourceFiles.keySet())
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
// beachtet
ClassOrInterface importedClass = ASTFactory
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
importedClasses.add(importedClass);
}
allClasses.addAll(importedClasses);
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
}
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
}
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
for (SourceFile sf : sourceFiles.values()) {
allClasses.addAll(sf.getClasses());
}
List<ClassOrInterface> importedClasses = new ArrayList<>();
for (JavaClassName name : forSourceFile.getImports()) {
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
ClassOrInterface importedClass = ASTFactory.createClass(
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
importedClasses.add(importedClass);
allClasses.addAll(importedClasses);
}
return allClasses;
}
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
for (SourceFile sf : sourceFiles.values()) {
allClasses.addAll(sf.getClasses());
}
List<ClassOrInterface> importedClasses = new ArrayList<>();
for (JavaClassName name : forSourceFile.getImports()) {
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
// beachtet
ClassOrInterface importedClass = ASTFactory
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
importedClasses.add(importedClass);
allClasses.addAll(importedClasses);
}
return allClasses;
}
public List<ResultSet> typeInference() throws ClassNotFoundException {
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for(SourceFile sf : this.sourceFiles.values()) {
allClasses.addAll(getAvailableClasses(sf));
allClasses.addAll(sf.getClasses());
}
public List<SolvedClass> strucTypeInference()
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
List<SolvedClass> solvedClasses = new ArrayList<>();
for (SourceFile sourceFile : sourceFiles.values()) {
ClassOrInterface clsA = sourceFile.getClasses().get(0);
StrucTYPE strucTYPE = new StrucTYPE(clsA);
ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints();
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
final ConstraintSet<Pair> cons = getConstraints();
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
inferredTypes = construct.getInferredTypes();
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
System.out.println(finiteClosure);
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
IFiniteClosure fc = UnifyTypeFactory.generateFC(this.getAvailableClasses(sourceFile));
Solve solve = new Solve(subTypeConstraints, clsA, fc, inferredTypes, constructedInterfaces);
SolvedClass solvedClass = solve.getSolvedClass();
solvedClasses.add(solvedClass);
}
return solvedClasses;
}
TypeUnify unify = new TypeUnify();
Set<Set<UnifyPair>> results = new HashSet<>();
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
Set<UnifyPair> xConsSet = new HashSet<>();
for (Constraint<UnifyPair> constraint : xCons) {
xConsSet.addAll(constraint);
}
public List<ResultSet> typeInference() throws ClassNotFoundException {
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
// FC
for (SourceFile sf : this.sourceFiles.values()) {
allClasses.addAll(getAvailableClasses(sf));
allClasses.addAll(sf.getClasses());
}
System.out.println(xConsSet);
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result.size());
results.addAll(result);
}
return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
}
final ConstraintSet<Pair> cons = getConstraints();
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
constraints.map((Pair p) -> {
if (p.TA1 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
}
if (p.TA2 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
}
return null;
});
return ret;
}
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
System.out.println(finiteClosure);
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
SourceFile ret = generator.convert(tree, environment.packageCrawler);
return ret;
}
TypeUnify unify = new TypeUnify();
Set<Set<UnifyPair>> results = new HashSet<>();
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
Set<UnifyPair> xConsSet = new HashSet<>();
for (Constraint<UnifyPair> constraint : xCons) {
xConsSet.addAll(constraint);
}
System.out.println(xConsSet);
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result.size());
results.addAll(result);
}
return results.stream()
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons)))))
.collect(Collectors.toList());
}
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
constraints.map((Pair p) -> {
if (p.TA1 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
}
if (p.TA2 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
}
return null;
});
return ret;
}
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
new GenericsRegistry(null));
SourceFile ret = generator.convert(tree, environment.packageCrawler);
return ret;
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
@@ -17,4 +18,9 @@ public class AssignToLocal extends AssignLeftSide {
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public AssignToLocal accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -832,7 +832,7 @@ public class StatementGenerator {
}else if(literal.StringLiteral()!=null){
RefType type = new RefType(reg.getName("java.lang.String"),literal.getStart());
return new Literal(type,
literal.StringLiteral().getText(),
literal.StringLiteral().getText().substring(1, literal.StringLiteral().getText().length()-1),
literal.getStart());
}else if(literal.NullLiteral() != null){
return new Literal(TypePlaceholder.fresh(literal.getStart()), null,
@@ -904,7 +904,7 @@ public class StatementGenerator {
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
//RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()),
//funNParams, name.getStart());
//funNParams, name.getStart());
return new LambdaExpression(lambdaType, params, block, expression.getStart());
}
}

View File

@@ -427,6 +427,9 @@ public class SyntaxTreeGenerator{
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
ret.putAll(generics);
if(ctx == null || ctx.typeParameterList() == null)return ret;
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod));
}
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
}

View File

@@ -22,18 +22,20 @@ import java.util.List;
public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
String name;
if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
}
Java8Parser.TypeArgumentsContext arguments;
if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){
name = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
}else{// if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().getText();
arguments = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
}
/**
* Problem sind hier die verschachtelten Typen mit verschachtelten Typargumenten
* Beispiel: Typ<String>.InnererTyp<Integer>
*/
String name = unannClassOrInterfaceTypeContext.getText();
if(name.contains("<")){
name = name.split("<")[0]; //Der Typ ist alles vor den ersten Argumenten
}
return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics);
}
@@ -75,7 +77,6 @@ public class TypeGenerator {
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
generics.put(name, new GenericContext(parentClass, parentMethod));
return ret;
}
@@ -90,7 +91,7 @@ public class TypeGenerator {
return ret;
}
if(typeBoundContext.classOrInterfaceType() != null){
ret.add(convert(typeBoundContext.classOrInterfaceType()));
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
if(typeBoundContext.additionalBound() != null)
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
ret.add(convert(addCtx.interfaceType()));
@@ -101,8 +102,9 @@ public class TypeGenerator {
}
}
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) {
throw new NotImplementedException();
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),classOrInterfaceTypeContext.getStart(), reg, generics);
}
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
@@ -112,10 +114,7 @@ public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
if(referenceTypeContext.classOrInterfaceType() != null){
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType();
//return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
if(ctx.typeArguments() != null)throw new NotImplementedException();
return convertTypeName(referenceTypeContext.getText(), null,referenceTypeContext.getStart(), reg, generics);
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
}else{
throw new NotImplementedException();
}

View File

@@ -0,0 +1,158 @@
package de.dhbwstuttgart.strucTypes;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.exception.IllegalInterfaceTypeException;
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class Construct extends DefaultASTVisitor {
private Set<SubTypeConstraint> subTypeConstraints = new HashSet<>();
private ConstraintsSet constraintsSet = new ConstraintsSet();
private Set<RefTypeOrTPHOrWildcardOrGeneric> newInterf = new HashSet<>();
private InferredTypes inferredTypes = new InferredTypes();
private List<ClassOrInterface> constructedInterfaces = new ArrayList<>();
public Construct(ConstraintsSet constraintsSet, InferredTypes inferredTypes) throws ImpossibleSubTypeException {
this.constraintsSet = constraintsSet;
this.inferredTypes = inferredTypes;
this.gatherSubTypeConstraints(constraintsSet);
for (SubTypeConstraint constraint : this.subTypeConstraints) {
constraint.checkConstraintPossible();
}
}
public List<ClassOrInterface> getConstructedInterfaces() {
this.newInterf.forEach(i -> i.accept(this));
return constructedInterfaces;
}
public InferredTypes getInferredTypes() {
return inferredTypes;
}
public Set<SubTypeConstraint> getSubTypeConstraints() {
this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes));
return subTypeConstraints;
}
// public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs() {
// return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet());
// }
private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) {
this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints());
constraintsSet.getFieldConstraints().forEach(fc -> this.newInterf.add(fc.getClassType()));
constraintsSet.getMethodConstraints().forEach(mc -> {
this.subTypeConstraints.addAll(mc.getArguments());
this.newInterf.add(mc.getClassType());
});
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
JavaClassName name = new JavaClassName( typePlaceholder.getName());
this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name));
}
// check nur TPH in newInterf
@Override
public void visit(RefType refType) {
throw new IllegalInterfaceTypeException(
String.format("%s is not a valid type to generate an interface for.", refType));
}
@Override
public void visit(GenericRefType genericRefType) {
System.out.println(String.format("%s is not a valid type to generate an interface for.", genericRefType));
}
private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) {
List<Field> fielddecl = new ArrayList<>();
List<Method> methods = new ArrayList<>();
List<GenericTypeVar> generics = new ArrayList<>();
List<RefTypeOrTPHOrWildcardOrGeneric> parameterInhTyterm = new ArrayList<>();
final Token offset = new NullToken();
// Schleife <20>ber alle FieldConstraints mit ClassType i
this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> {
TypePlaceholder tph = TypePlaceholder.fresh(offset);
// Typ f<>r field: GenericRefType
GenericRefType grt = new GenericRefType(tph.getName(), offset);
parameterInhTyterm.add(fc.getFieldType());
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
Field field = new Field(fc.getFieldName(), grt, Modifier.PUBLIC, offset);
fielddecl.add(field);
});
// Schleife <20>ber alle MethodConstraints mit ClassType i
this.constraintsSet.getMethodConstraints().stream().filter(mc -> mc.getClassType().equals(i)).forEach(mc -> {
TypePlaceholder returnType = TypePlaceholder.fresh(offset);
parameterInhTyterm.add(mc.getReturnType());
generics.add(new GenericTypeVar(returnType.getName(), new ArrayList<>(), offset, offset));
Block block = new Block(new ArrayList<>(), offset);
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset);
List<FormalParameter> params = new ArrayList<>();
mc.getArguments().stream().map(a -> a.getSupertype()).forEach(supertype -> {
// Typ f<>r argument: GenericRefType
TypePlaceholder tph = TypePlaceholder.fresh(offset);
GenericRefType grt = new GenericRefType(tph.getName(), offset);
params.add(new FormalParameter("arg" + tph.getName(), grt, offset));
parameterInhTyterm.add(supertype);
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
});
ParameterList parameterList = new ParameterList(params, offset);
// returnType f<>r method: GenericRefType
Method method = new Method(Modifier.PUBLIC, mc.getMethodName(),
new GenericRefType(returnType.getName(), offset), parameterList, block, gtvDeclarations, offset);
methods.add(method);
});
RefType inh_tyterm = new RefType(name, parameterInhTyterm, offset);
TypePlaceholder x = TypePlaceholder.fresh(offset);
this.subTypeConstraints.add(new SubTypeConstraint(x, inh_tyterm));
this.inferredTypes.put(i, x);
final int modifiers = Modifier.PUBLIC;
final RefType superClass = this.createSuperClass();
final boolean isInterface = true;
final List<Constructor> constructors = new ArrayList<>();
final List<RefType> implementedInterfaces = new ArrayList<>();
GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset());
ClassOrInterface constructedInterface = new ClassOrInterface(modifiers, name, fielddecl, methods, constructors,
genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
return constructedInterface;
}
private RefType createSuperClass() {
JavaClassName name = new JavaClassName(Object.class.getName());
GenericDeclarationList genericsOfClass = new GenericDeclarationList(new ArrayList<>(), new NullToken());
return ClassOrInterface.generateTypeOfClass(name, genericsOfClass, new NullToken());
}
}

View File

@@ -0,0 +1,182 @@
package de.dhbwstuttgart.strucTypes;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import javafx.util.Pair;
public class RuleSetStrucType extends RuleSet {
public Optional<Set<UnifyPair>> strucTypeReduce(UnifyPair pair) {
return super.reduce2(pair);
}
public Optional<UnifyPair> strucTypeAdapt1(UnifyPair pair, IFiniteClosure fc) {
return super.adapt(pair, fc);
}
public Optional<Set<UnifyPair>> strucTypeAdapt2(Set<UnifyPair> pairs, IFiniteClosure fc) {
// Filter SMALLERDOT Pairs
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
.collect(Collectors.toSet());
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
for (UnifyPair pair : pairsSmallerDot) {
// check outerLeftPair pair has Form (D<theta.1,..,theta.n> <. TPH S1)
UnifyType typeD = pair.getLhsType();
if (!(pair.getRhsType() instanceof PlaceholderType) || !(typeD instanceof ReferenceType)) {
continue;
}
// filter potential outer Pairs for Linking
pairsSmallerDot.stream()
// check outerRightPair p has Form (TPH Sn <. D'<theta'.1,...,theta'.m>)
.filter(p -> (p.getLhsType() instanceof PlaceholderType)
&& (p.getRhsType() instanceof ReferenceType))
.filter(p -> {
UnifyType typeD1 = p.getRhsType();
// check not(D<theta.1,..,theta.n> <=* D'<theta'.1,..,theta'.m>)
if (fc.getAncestors(typeD).contains(typeD1))
return false;
Optional<UnifyType> opt = fc.getLeftHandedType(typeD.getName());
if (!opt.isPresent())
return false;
UnifyType typeDgen = opt.get();
Set<UnifyType> greater = fc.getAncestors(typeDgen);
opt = greater.stream().filter(x -> x.getName().equals(typeD1.getName())).findAny();
// check (D<T1,..,Tn> <=* D'<ty1',...,tym'>)
if (!opt.isPresent())
return false;
// UnifyType typeD1gen = opt.get();
return true;
}).map(p -> new Pair<>(pair, p)).forEach(tupleOfPotentialLinkings::add);
}
// Build Linking between the Pairs. Empty if no Linking is possible.
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
UnifyPair outerLeftPair = tuple.getKey();
UnifyPair outerRightPair = tuple.getValue();
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
pairsSmallerDot);
if (!opt.isPresent())
continue;
// Linking has been found
UnifyType typeD = outerLeftPair.getLhsType();
UnifyType typeD1 = outerRightPair.getRhsType();
// present already checked s.o.
UnifyType typeDgen = fc.getLeftHandedType(typeD.getName()).get();
// present already checked s.o.
UnifyType typeD1gen = fc.getAncestors(typeDgen).stream().filter(x -> x.getName().equals(typeD1.getName()))
.findAny().get();
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
Unifier unifD1gen = Unifier.identity();
for (int i = 0; i < typeDParams.size(); i++)
unifD1gen.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
Optional<Unifier> sigmaopt = new MartelliMontanariUnify().unify(unifD1gen.apply(typeD1gen), typeD);
if (!sigmaopt.isPresent())
continue;
// replace outerLeftPair.lhs and outerRightPair.rhs witch new Types
Unifier sigma = sigmaopt.get();
pairs.remove(outerLeftPair);
pairs.remove(outerRightPair);
pairs.add(UnifyTypeFactory.generateSmallerDotPair(sigma.apply(typeD), outerLeftPair.getRhsType()));
pairs.add(UnifyTypeFactory.generateSmallerDotPair(outerRightPair.getLhsType(), sigma.apply(typeD1)));
// TODO pairs.add mit sigma als Pair
return Optional.of(pairs);
}
// No Linking found
return Optional.empty();
}
public boolean strucTypeErase1(UnifyPair pair, IFiniteClosure fc) {
return super.erase1(pair, fc);
}
public boolean strucTypeErase2(UnifyPair pair) {
return super.erase3(pair);
}
public Optional<UnifyPair> strucTypeSwap(UnifyPair pair) {
return super.swap(pair);
}
public Optional<Set<UnifyPair>> strucTypeSubst(Set<UnifyPair> pairs) {
return super.subst(pairs);
}
public Optional<Set<UnifyPair>> strucTypeRefl(Set<UnifyPair> pairs) {
// Filter SMALLERDOT Pairs
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
.collect(Collectors.toSet());
// System.out.println("Pairs to test: " + pairsSmallerDot);
// Filter Tuples of Pairs for a potential Linking (t<T1,T1<T2,...,Tn<t)
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
for (UnifyPair pair : pairsSmallerDot) {
if (!(pair.getRhsType() instanceof PlaceholderType)) {
// System.out.println("Pair not suitable for outerLeftPair: " + pair);
continue;
}
// System.out.println("Try to find tuple of potential linkings for pair " + pair);
pairsSmallerDot.stream().filter(p -> {
// System.out.println(" Pair pair: " + pair);
// System.out.println("Pair p: " + p);
// System.out.println("p.lhs instnceof PH: " + (p.getLhsType() instanceof PlaceholderType));
// System.out.println("p.rhs equals pair.lhs: " + (p.getRhsType().equals(pair.getLhsType())));
return (p.getLhsType() instanceof PlaceholderType) && (p.getRhsType().equals(pair.getLhsType()));
}).map(p -> {
// System.out.println("Pair to map: " + p);
return new Pair<>(pair, p);
}).forEach(tupleOfPotentialLinkings::add);
// System.out.println("tuple of potential linkings: " + tupleOfPotentialLinkings);
}
// Build Linking between the Pairs. Empty if no Linking is possible.
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
UnifyPair outerLeftPair = tuple.getKey();
UnifyPair outerRightPair = tuple.getValue();
// System.out.println("Try linking pair: " + outerLeftPair + ", " + outerRightPair);
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
pairsSmallerDot);
// Remove Pairs of the Linking incl. outerLeft and outerRight, add
// EQUALSDOT Pairs instead.
if (opt.isPresent()) {
// System.out.println("Linking found: " + opt.get());
pairs.remove(outerLeftPair);
pairs.remove(outerRightPair);
pairs.removeAll(opt.get());
// Get all Placeholder in Linking.
Set<UnifyType> placeholderInLinking = new HashSet<>();
opt.get().forEach(p -> {
placeholderInLinking.add(p.getLhsType());
placeholderInLinking.add(p.getRhsType());
});
// Generate and add new EQUALSDOT Pairs of Placeholder and
// outermost UnifyType to the result.
final UnifyType outermostUnifyType = outerLeftPair.getLhsType();
placeholderInLinking.forEach(placeholder -> pairs
.add(UnifyTypeFactory.generateEqualDotPair(placeholder, outermostUnifyType)));
return Optional.of(pairs);
}
// System.out.println("No Linking found");
}
// No Linking was found.
return Optional.empty();
}
}

View File

@@ -0,0 +1,129 @@
package de.dhbwstuttgart.strucTypes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
import de.dhbwstuttgart.strucTypes.visitor.TypeVar;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class Solve {
private Set<SubTypeConstraint> constraints = new HashSet<>();
private IFiniteClosure fc;
private InferredTypes inferredTypes = new InferredTypes();
private ClassOrInterface clsA;
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
InferredTypes inferredTypes, List<ClassOrInterface> generatedInterfaces) {
this.constraints = constraints;
this.fc = fc;
this.inferredTypes = inferredTypes;
this.clsA = clsA;
this.generatedInterfaces = generatedInterfaces;
}
public SolvedClass getSolvedClass() throws InconsistentConstraintsException {
Set<UnifyPair> constraintsUnifyPair = this.constraints.stream().map(SubTypeConstraint::getAsUnifyPair)
.collect(Collectors.toSet());
StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc);
Set<UnifyPair> subst = strucTypeUnify.unify();
Map<String, TypePlaceholder> tphs = this.generateTPHMap(constraints);
InferredTypes sigma = new InferredTypes();
sigma.putAll(inferredTypes);
sigma.putAll(
StrucTypeUnifyUtils.convertEqualsdot(
subst.stream()
.filter(p -> p.getLhsType() instanceof PlaceholderType
&& p.getPairOp().equals(PairOperator.EQUALSDOT))
.collect(Collectors.toSet()),
tphs));
Set<SubTypeConstraint> cs = StrucTypeUnifyUtils.convertSmallerdot(
subst.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp())).collect(Collectors.toSet()),
tphs);
List<GenericTypeVar> values = new ArrayList<>();
// extract typeplaceholder (type variables) of clsA
TypeVar typeVar = new TypeVar(inferredTypes);
clsA.accept(typeVar);
final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> bounds = new ArrayList<>();
final NullToken offset = new NullToken();
// add type variables of clsA as GenericTypeVar to values of
// tNew
typeVar.getTypeVars().stream().map(tph -> new GenericTypeVar(tph.getName(), bounds, offset, offset))
.forEach(gtv -> {
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
values.add(gtv);
};
});
// add type variables of cs as GenericRefType to values of
// tNew
cs.stream().flatMap(c -> Stream.of(c.getSubtype(), c.getSupertype())).filter(t -> t instanceof TypePlaceholder)
.map(tph -> new GenericTypeVar(((TypePlaceholder) tph).getName(), bounds, offset, offset))
.forEach(gtv -> {
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
values.add(gtv);
};
});
// add generics of all superclasses and superinterfaces of clsA to
// values of tNew
TypeExtract typeExtract = new TypeExtract();
clsA.accept(typeExtract);
typeExtract.getGenerics().forEach(gtv -> {
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
values.add(gtv);
};
});
GenericDeclarationList tNew = new GenericDeclarationList(values, offset);
if (!consistent(cs)) {
throw new InconsistentConstraintsException();
}
return new SolvedClass(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew,
cs, this.generatedInterfaces);
}
private Map<String, TypePlaceholder> generateTPHMap(Set<SubTypeConstraint> constraints) {
Map<String, TypePlaceholder> tphs = new HashMap<>();
constraints.stream().forEach(c -> {
if (c.getSubtype() instanceof TypePlaceholder) {
TypePlaceholder subtype = (TypePlaceholder) c.getSubtype();
tphs.put(subtype.getName(), subtype);
}
if (c.getSupertype() instanceof TypePlaceholder) {
TypePlaceholder supertype = (TypePlaceholder) c.getSupertype();
tphs.put(supertype.getName(), supertype);
}
});
return tphs;
}
private boolean consistent(Set<SubTypeConstraint> cs) {
// TODO update inconsistencies
return true;
}
}

View File

@@ -0,0 +1,63 @@
package de.dhbwstuttgart.strucTypes;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
import de.dhbwstuttgart.strucTypes.visitor.TYPEExpr;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class StrucTYPE extends DefaultASTVisitor {
private ClassOrInterface clsA;
private ConstraintsSet constraintsSet = new ConstraintsSet();
private InferredTypes inferredTypes = new InferredTypes();
public StrucTYPE(ClassOrInterface clsA) {
this.clsA = clsA;
}
public ConstraintsSet getConstraints() {
TYPEExpr typeExpr = new TYPEExpr();
this.clsA.accept(typeExpr);
this.clsA.getMethods().forEach(m -> m.accept(this));
this.evaluateTypeExpr(typeExpr);
return this.constraintsSet;
}
public InferredTypes getInferredTypes() {
return this.inferredTypes;
}
@Override
public void visit(Method method) {
// Es gibt nur ein Return Statement
Expression retexpr = ((Return) method.block.statements.get(0)).retexpr;
RefTypeOrTPHOrWildcardOrGeneric methodReturnType = method.getReturnType();
RefTypeOrTPHOrWildcardOrGeneric retExprType = retexpr.getType();
// ordnet dem Methodentyp den Returntyp zu [sigma(Mt)]
if (methodReturnType instanceof TypePlaceholder) {
this.inferredTypes.put((TypePlaceholder) methodReturnType, retExprType);
}
if (methodReturnType instanceof RefType && retExprType instanceof TypePlaceholder) {
this.inferredTypes.put((TypePlaceholder) retExprType, methodReturnType);
}
}
private void evaluateTypeExpr(TYPEExpr typeExpr) {
this.inferredTypes.putAll(typeExpr.getInferredTypes());
this.inferredTypes.resolveTransitiveTypes();
ConstraintsSet constraints = typeExpr.getConstraints();
constraints.inferTypes(this.inferredTypes);
this.constraintsSet.addConstraintsSet(constraints);
}
}

View File

@@ -0,0 +1,89 @@
package de.dhbwstuttgart.strucTypes;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class StrucTypeUnify {
private Set<UnifyPair> pairs;
private IFiniteClosure fc;
private RuleSetStrucType rules = new RuleSetStrucType();
public StrucTypeUnify(Set<UnifyPair> unifyPairs, IFiniteClosure finiteClosure) {
this.pairs = unifyPairs;
this.fc = finiteClosure;
}
public Set<UnifyPair> unify() {
Set<UnifyPair> pairs = this.applyTypeUnificationRules(this.pairs, fc);
return pairs;
}
private Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> pairs, IFiniteClosure fc) {
Set<UnifyPair> resultSet = new HashSet<>();
LinkedList<UnifyPair> pairQueue = new LinkedList<>();
pairs.forEach(p -> this.swapAddOrErase(p, fc, pairQueue));
while (!pairQueue.isEmpty()) {
UnifyPair pair = pairQueue.pollFirst();
// reduce
Optional<Set<UnifyPair>> optSet = rules.strucTypeReduce(pair);
if (optSet.isPresent()) {
optSet.get().forEach(p -> swapAddOrErase(p, fc, pairQueue));
continue;
}
// adapt1
Optional<UnifyPair> opt = rules.strucTypeAdapt1(pair, fc);
if (opt.isPresent()) {
this.swapAddOrErase(opt.get(), fc, pairQueue);
continue;
}
// none of the above rules applied
resultSet.add(pair);
}
// adapt2
Optional<Set<UnifyPair>> adapt2 = rules.strucTypeAdapt2(resultSet, fc);
if(adapt2.isPresent()){
resultSet = this.applyTypeUnificationRules(adapt2.get(), fc);
}
// subst
Optional<Set<UnifyPair>> subst = rules.strucTypeSubst(resultSet);
if(subst.isPresent()){
resultSet = this.applyTypeUnificationRules(subst.get(), fc);
}
// refl
Optional<Set<UnifyPair>> refl = rules.strucTypeRefl(resultSet);
if(refl.isPresent()){
resultSet = this.applyTypeUnificationRules(refl.get(), fc);
}
return resultSet;
}
private void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
// swap
Optional<UnifyPair> opt = rules.strucTypeSwap(pair);
UnifyPair unifyPair = opt.isPresent() ? opt.get() : pair;
// erase
if (rules.strucTypeErase1(unifyPair, fc) || rules.strucTypeErase2(unifyPair))
return;
collection.add(unifyPair);
}
}

View File

@@ -0,0 +1,66 @@
package de.dhbwstuttgart.strucTypes;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class StrucTypeUnifyUtils {
public static Optional<Set<UnifyPair>> linkPairs(UnifyPair outerLeft, UnifyPair outerRight,
Collection<UnifyPair> pairs) {
Set<UnifyPair> resultLinking = new HashSet<>();
if (outerLeft.getRhsType().equals(outerRight.getLhsType())) {
resultLinking.add(outerLeft);
return Optional.of(resultLinking);
}
List<UnifyPair> nextLinks = pairs.stream().filter(p -> outerLeft.getRhsType().equals(p.getLhsType()))
.collect(Collectors.toList());
for (UnifyPair nextLink : nextLinks) {
Optional<Set<UnifyPair>> opt = linkPairs(nextLink, outerRight, pairs);
if (opt.isPresent()) {
resultLinking = opt.get();
resultLinking.add(nextLink);
return Optional.of(resultLinking);
}
}
return Optional.empty();
}
public static InferredTypes convertEqualsdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
InferredTypes inferredTypes = new InferredTypes();
if (!pairs.stream().allMatch(
p -> PairOperator.EQUALSDOT.equals(p.getPairOp()) && p.getLhsType() instanceof PlaceholderType)) {
throw new IllegalArgumentException("Not all UnifyPairs were EQUALSDOT pairs.");
}
for (UnifyPair pair : pairs) {
TypePlaceholder lhs = (TypePlaceholder) UnifyTypeFactory.convert(pair.getLhsType(), tphs);
RefTypeOrTPHOrWildcardOrGeneric rhs = UnifyTypeFactory.convert(pair.getRhsType(), tphs);
inferredTypes.put(lhs, rhs);
}
return inferredTypes;
}
public static Set<SubTypeConstraint> convertSmallerdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
if (!pairs.stream().allMatch(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))) {
throw new IllegalArgumentException("Not all UnifyPairs were SMALLERDOT pairs.");
}
return pairs.stream().map(p -> new SubTypeConstraint(UnifyTypeFactory.convert(p.getLhsType(), tphs),
UnifyTypeFactory.convert(p.getRhsType(), tphs))).collect(Collectors.toSet());
}
}

View File

@@ -0,0 +1,56 @@
package de.dhbwstuttgart.strucTypes.constraint;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
public class ConstraintsSet {
private Set<SubTypeConstraint> subTypeConstraints;
private Set<FieldConstraint> fieldConstraints;
private Set<MethodConstraint> methodConstraints;
public ConstraintsSet() {
this.subTypeConstraints = new HashSet<>();
this.fieldConstraints = new HashSet<>();
this.methodConstraints = new HashSet<>();
}
public Set<SubTypeConstraint> getSubTypeConstraints() {
return subTypeConstraints;
}
public Set<FieldConstraint> getFieldConstraints() {
return fieldConstraints;
}
public Set<MethodConstraint> getMethodConstraints() {
return methodConstraints;
}
public void addConstraint(SubTypeConstraint constraint) {
this.subTypeConstraints.add(constraint);
}
public void addConstraint(FieldConstraint constraint) {
this.fieldConstraints.add(constraint);
}
public void addConstraint(MethodConstraint constraint) {
this.methodConstraints.add(constraint);
}
public void addConstraintsSet(ConstraintsSet constraintsSet) {
constraintsSet.getSubTypeConstraints().forEach(this::addConstraint);
constraintsSet.getFieldConstraints().forEach(this::addConstraint);
constraintsSet.getMethodConstraints().forEach(this::addConstraint);
}
public void inferTypes(InferredTypes inferredTypes) {
this.subTypeConstraints.forEach(c -> c.inferTypes(inferredTypes));
this.fieldConstraints.forEach(c -> c.inferTypes(inferredTypes));
this.methodConstraints.forEach(c -> c.inferTypes(inferredTypes));
}
}

View File

@@ -0,0 +1,55 @@
package de.dhbwstuttgart.strucTypes.constraint;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/**
* fc(c, f, c') : Klasse/Typ c hat ein Feld f mit Typ c'
*
* @author mvr
*
*/
public class FieldConstraint {
private RefTypeOrTPHOrWildcardOrGeneric classType;
private String fieldName;
private RefTypeOrTPHOrWildcardOrGeneric fieldType;
public FieldConstraint(RefTypeOrTPHOrWildcardOrGeneric classType, String fieldName,
RefTypeOrTPHOrWildcardOrGeneric fieldType) {
this.classType = classType;
this.fieldName = fieldName;
this.fieldType = fieldType;
}
public RefTypeOrTPHOrWildcardOrGeneric getClassType() {
return classType;
}
public RefTypeOrTPHOrWildcardOrGeneric getFieldType() {
return fieldType;
}
public String getFieldName() {
return fieldName;
}
public void inferTypes(InferredTypes inferredTypes) {
// if (inferredTypes.containsKey(classType)) {
// this.classType = inferredTypes.get(classType);
// }
// if (inferredTypes.containsKey(fieldType)) {
// this.fieldType = inferredTypes.get(fieldType);
// }
InferTypes inferTypes = new InferTypes(inferredTypes);
classType = classType.accept(inferTypes);
fieldType = fieldType.accept(inferTypes);
}
@Override
public String toString() {
return String.format("F(%s, %s, %s)", this.classType, this.fieldName, this.fieldType);
}
}

View File

@@ -0,0 +1,114 @@
package de.dhbwstuttgart.strucTypes.constraint;
import java.util.Iterator;
import java.util.List;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* mc(c, m, C, (c', C')) : Klasse/Typ c hat Methode m mit Argumenten von Typ C
* mit R<>ckgabewert c' und Subtyp-Constraints C <. C' wobei C = {c1,... , cn)
*
* @author mvr
*
*/
public class MethodConstraint {
private RefTypeOrTPHOrWildcardOrGeneric classType;
private RefTypeOrTPHOrWildcardOrGeneric returnType;
private String methodName;
private List<SubTypeConstraint> arguments;
public MethodConstraint(RefTypeOrTPHOrWildcardOrGeneric classType, String methodName,
List<SubTypeConstraint> arguments, RefTypeOrTPHOrWildcardOrGeneric returnType) {
this.classType = classType;
this.returnType = returnType;
this.methodName = methodName;
this.arguments = arguments;
}
public RefTypeOrTPHOrWildcardOrGeneric getClassType() {
return classType;
}
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return returnType;
}
public String getMethodName() {
return methodName;
}
public List<SubTypeConstraint> getArguments() {
return arguments;
}
public void addArguments(SubTypeConstraint... subTypeConstraints) {
for (SubTypeConstraint subTypeConstraint : subTypeConstraints) {
this.arguments.add(subTypeConstraint);
}
}
public void addArguments(RefTypeOrTPHOrWildcardOrGeneric... parameters) {
for (RefTypeOrTPHOrWildcardOrGeneric parameter : parameters) {
Token offset = parameter.getOffset();
TypePlaceholder tph = TypePlaceholder.fresh(offset);
SubTypeConstraint subTypeConstraint = new SubTypeConstraint(parameter, tph);
this.arguments.add(subTypeConstraint);
}
}
public void inferTypes(InferredTypes inferredTypes) {
// if (inferredTypes.containsKey(classType)) {
// this.classType = inferredTypes.get(classType);
// }
// if (inferredTypes.containsKey(returnType)) {
// this.returnType = inferredTypes.get(returnType);
// }
InferTypes inferTypes = new InferTypes(inferredTypes);
classType = classType.accept(inferTypes);
returnType = returnType.accept(inferTypes);
arguments.forEach(c -> c.inferTypes(inferredTypes));
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("M(");
sb.append(this.classType);
sb.append(", ");
sb.append(this.methodName);
sb.append(", [");
List<SubTypeConstraint> arguments = this.arguments;
if (!arguments.isEmpty()) {
Iterator<SubTypeConstraint> iterator = arguments.iterator();
while (iterator.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric subtype = iterator.next().getSubtype();
sb.append(subtype.toString());
if (iterator.hasNext()) {
sb.append(", ");
}
}
}
sb.append("],(");
sb.append(this.returnType);
sb.append(", [");
if (!arguments.isEmpty()) {
Iterator<SubTypeConstraint> iterator = arguments.iterator();
while (iterator.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric supertype = iterator.next().getSupertype();
sb.append(supertype.toString());
if (iterator.hasNext()) {
sb.append(", ");
}
}
}
sb.append("]))");
return sb.toString();
}
}

View File

@@ -0,0 +1,117 @@
package de.dhbwstuttgart.strucTypes.constraint;
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
/**
* c <. c' : c ist subtyp von c'
*
* @author mvr
*
*/
public class SubTypeConstraint {
private RefTypeOrTPHOrWildcardOrGeneric subtype;
private RefTypeOrTPHOrWildcardOrGeneric supertype;
public SubTypeConstraint(RefTypeOrTPHOrWildcardOrGeneric subtype, RefTypeOrTPHOrWildcardOrGeneric supertype) {
this.subtype = subtype;
this.supertype = supertype;
}
public RefTypeOrTPHOrWildcardOrGeneric getSubtype() {
return subtype;
}
public RefTypeOrTPHOrWildcardOrGeneric getSupertype() {
return supertype;
}
public void inferTypes(InferredTypes inferredTypes) {
// if (inferredTypes.containsKey(subtype)) {
// this.subtype = inferredTypes.get(subtype);
// }
// if (inferredTypes.containsKey(supertype)) {
// this.supertype = inferredTypes.get(supertype);
// }
InferTypes inferTypes = new InferTypes(inferredTypes);
subtype = subtype.accept(inferTypes);
supertype = supertype.accept(inferTypes);
}
public boolean checkConstraintPossible() throws ImpossibleSubTypeException {
if (this.subtype instanceof RefType && this.supertype instanceof RefType) {
Class<?> subClass = this.createClass(((RefType) this.subtype).getName().toString());
Class<?> superClass = this.createClass(((RefType) this.supertype).getName().toString());
if (subClass != null && superClass != null) {
if (superClass.isAssignableFrom(subClass))
return true;
else
throw new ImpossibleSubTypeException(
String.format("%s ist kein subtyp von %s", subClass.getName(), superClass.getName()));
}
}
return true;
}
public UnifyPair getAsUnifyPair(){
UnifyType tl = UnifyTypeFactory.convert(this.subtype);
UnifyType tr = UnifyTypeFactory.convert(this.supertype);
return UnifyTypeFactory.generateSmallerDotPair(tl, tr);
}
private Class<?> createClass(String name) {
try {
return ClassLoader.getSystemClassLoader().loadClass(name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subtype == null) ? 0 : subtype.hashCode());
result = prime * result + ((supertype == null) ? 0 : supertype.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SubTypeConstraint other = (SubTypeConstraint) obj;
if (subtype == null) {
if (other.subtype != null)
return false;
} else if (!subtype.equals(other.subtype))
return false;
if (supertype == null) {
if (other.supertype != null)
return false;
} else if (!supertype.equals(other.supertype))
return false;
return true;
}
@Override
public String toString() {
return String.format("%s <* %s", this.subtype, this.supertype);
}
}

View File

@@ -0,0 +1,503 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.2.2" icons="false" always-add-relationships="false" generalizations="true" realizations="true"
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="de.dhbwstuttgart.strucTypes.StrucTYPE" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="136" y="291"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="2" language="java" name="de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/ConstraintsSet.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="593" y="277"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="3" language="java" name="de.dhbwstuttgart.strucTypes.model.InferredTypes" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/model/InferredTypes.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="626" y="450"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="4" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TYPEExpr" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TYPEExpr.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="242" y="464"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="5" language="java" name="de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/DefaultASTVisitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="601" y="86"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="6" language="java" name="de.dhbwstuttgart.strucTypes.Construct" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/Construct.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1019" y="494"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="7" language="java" name="de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/SubTypeConstraint.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="60" width="220" x="1088" y="164"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="8" language="java" name="de.dhbwstuttgart.strucTypes.exception.IllegalInterfaceTypeException"
project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/IllegalInterfaceTypeException.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="60" width="218" x="1151" y="371"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="9" language="java" name="de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException"
project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/ImpossibleSubTypeException.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="60" width="218" x="1156" y="472"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="10" language="java" name="de.dhbwstuttgart.strucTypes.Solve" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/Solve.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="587" y="685"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<interface id="11" language="java" name="de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure"
project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="665" y="849"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</interface>
<class id="12" language="java" name="de.dhbwstuttgart.strucTypes.StrucTypeUnify" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTypeUnify.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="334" y="859"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="13" language="java" name="de.dhbwstuttgart.strucTypes.StrucTypeUnifyUtils" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTypeUnifyUtils.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="315" y="642"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="14" language="java" name="de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException"
project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/InconsistentConstraintsException.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1241" y="600"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="15" language="java" name="de.dhbwstuttgart.strucTypes.model.SolvedClass" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="782" y="572"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="16" language="java" name="de.dhbwstuttgart.strucTypes.visitor.InferTypes" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/InferTypes.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="864" y="690"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="17" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TypeExtract" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java" binary="false" corner="BOTTOM_RIGHT">
<position height="60" width="198" x="-2" y="553"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="18" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TypeVar" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TypeVar.java" binary="false" corner="BOTTOM_RIGHT">
<position height="60" width="198" x="-2" y="640"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="19" language="java" name="de.dhbwstuttgart.typeinference.unify.model.UnifyPair" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="292" y="767"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="20" language="java" name="de.dhbwstuttgart.strucTypes.constraint.FieldConstraint" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/FieldConstraint.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="862" y="72"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<class id="21" language="java" name="de.dhbwstuttgart.strucTypes.constraint.MethodConstraint" project="JavaTXcompiler"
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/MethodConstraint.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1110" y="77"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</class>
<interface id="22" language="java" name="de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor"
project="JavaTXcompiler" file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="60" width="198" x="1031" y="703"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</display>
</interface>
<association id="23">
<end type="SOURCE" refId="1" navigable="false" variant="ASSOCIATION">
<attribute id="24" name="constraintsSet"/>
<multiplicity id="25" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="26">
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
<attribute id="27" name="fieldConstraints"/>
<multiplicity id="28" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="20" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="29">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="17"/>
</dependency>
<generalization id="30">
<end type="SOURCE" refId="1"/>
<end type="TARGET" refId="5"/>
</generalization>
<generalization id="31">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="5"/>
</generalization>
<generalization id="32">
<end type="SOURCE" refId="17"/>
<end type="TARGET" refId="5"/>
</generalization>
<association id="33">
<end type="SOURCE" refId="15" navigable="false" variant="ASSOCIATION">
<attribute id="34" name="constraints"/>
<multiplicity id="35" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="36">
<end type="SOURCE" refId="4" navigable="false" variant="ASSOCIATION">
<attribute id="37" name="constraints"/>
<multiplicity id="38" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="39">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="13"/>
</dependency>
<dependency id="40">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="9"/>
</dependency>
<association id="41">
<end type="SOURCE" refId="17" navigable="false" variant="ASSOCIATION">
<attribute id="42" name="grtToTphMap"/>
<multiplicity id="43" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="44">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="16"/>
</dependency>
<association id="45">
<end type="SOURCE" refId="17" navigable="false" variant="ASSOCIATION">
<attribute id="46" name="subTypeConstraints"/>
<multiplicity id="47" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="48">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="18"/>
</dependency>
<association id="49">
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
<attribute id="50" name="subTypeConstraints"/>
<multiplicity id="51" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="52">
<end type="SOURCE" refId="21" navigable="false" variant="ASSOCIATION">
<attribute id="53" name="arguments"/>
<multiplicity id="54" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="55">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="7"/>
</dependency>
<association id="56">
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
<attribute id="57" name="subTypeConstraints"/>
<multiplicity id="58" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="59">
<end type="SOURCE" refId="21"/>
<end type="TARGET" refId="3"/>
</dependency>
<dependency id="60">
<end type="SOURCE" refId="21"/>
<end type="TARGET" refId="16"/>
</dependency>
<dependency id="61">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="12"/>
</dependency>
<dependency id="62">
<end type="SOURCE" refId="20"/>
<end type="TARGET" refId="16"/>
</dependency>
<association id="63">
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
<attribute id="64" name="fc"/>
<multiplicity id="65" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="11" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="66">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="5"/>
</generalization>
<association id="67">
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
<attribute id="68" name="inferredTypes"/>
<multiplicity id="69" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="70">
<end type="SOURCE" refId="1"/>
<end type="TARGET" refId="4"/>
</dependency>
<association id="71">
<end type="SOURCE" refId="4" navigable="false" variant="ASSOCIATION">
<attribute id="72" name="inferredTypes"/>
<multiplicity id="73" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="74">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="3"/>
</dependency>
<association id="75">
<end type="SOURCE" refId="3" navigable="false" variant="ASSOCIATION">
<attribute id="76" name="EMPTY"/>
<multiplicity id="77" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="78">
<end type="SOURCE" refId="13"/>
<end type="TARGET" refId="3"/>
</dependency>
<dependency id="79">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="16"/>
</dependency>
<dependency id="80">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="8"/>
</dependency>
<association id="81">
<end type="SOURCE" refId="1" navigable="false" variant="ASSOCIATION">
<attribute id="82" name="inferredTypes"/>
<multiplicity id="83" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="84">
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
<attribute id="85" name="inferredTypes"/>
<multiplicity id="86" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="87">
<end type="SOURCE" refId="18" navigable="false" variant="ASSOCIATION">
<attribute id="88" name="inferredTypes"/>
<multiplicity id="89" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="90">
<end type="SOURCE" refId="16" navigable="false" variant="ASSOCIATION">
<attribute id="91" name="inferredTypes"/>
<multiplicity id="92" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="93">
<end type="SOURCE" refId="12" navigable="false" variant="ASSOCIATION">
<attribute id="94" name="fc"/>
<multiplicity id="95" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="11" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="96">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="14"/>
</dependency>
<realization id="97">
<end type="SOURCE" refId="16"/>
<end type="TARGET" refId="22"/>
</realization>
<dependency id="98">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="15"/>
</dependency>
<association id="99">
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
<attribute id="100" name="constraintsSet"/>
<multiplicity id="101" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="102">
<end type="SOURCE" refId="20"/>
<end type="TARGET" refId="3"/>
</dependency>
<association id="103">
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
<attribute id="104" name="constraints"/>
<multiplicity id="105" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="106">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="19"/>
</dependency>
<association id="107">
<end type="SOURCE" refId="12" navigable="false" variant="ASSOCIATION">
<attribute id="108" name="pairs"/>
<multiplicity id="109" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="19" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="110">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="17"/>
</dependency>
<dependency id="111">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="3"/>
</dependency>
<association id="112">
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
<attribute id="113" name="methodConstraints"/>
<multiplicity id="114" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="21" navigable="true" variant="ASSOCIATION"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
sort-features="false" accessors="false" visibility="false">
<attributes public="false" package="false" protected="false" private="false" static="false"/>
<operations public="false" package="false" protected="false" private="false" static="false"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

View File

@@ -0,0 +1,27 @@
package de.dhbwstuttgart.strucTypes.exception;
public class IllegalInterfaceTypeException extends RuntimeException {
private static final long serialVersionUID = 1L;
public IllegalInterfaceTypeException() {
}
public IllegalInterfaceTypeException(String message) {
super(message);
}
public IllegalInterfaceTypeException(Throwable cause) {
super(cause);
}
public IllegalInterfaceTypeException(String message, Throwable cause) {
super(message, cause);
}
public IllegalInterfaceTypeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@@ -0,0 +1,28 @@
package de.dhbwstuttgart.strucTypes.exception;
public class ImpossibleSubTypeException extends Exception {
private static final long serialVersionUID = 1L;
public ImpossibleSubTypeException() {
super();
}
public ImpossibleSubTypeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public ImpossibleSubTypeException(String message, Throwable cause) {
super(message, cause);
}
public ImpossibleSubTypeException(String message) {
super(message);
}
public ImpossibleSubTypeException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,28 @@
package de.dhbwstuttgart.strucTypes.exception;
public class InconsistentConstraintsException extends Exception {
private static final long serialVersionUID = 1L;
public InconsistentConstraintsException() {
super();
}
public InconsistentConstraintsException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public InconsistentConstraintsException(String message, Throwable cause) {
super(message, cause);
}
public InconsistentConstraintsException(String message) {
super(message);
}
public InconsistentConstraintsException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,24 @@
package de.dhbwstuttgart.strucTypes.model;
import java.util.Optional;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.RefType;
public class ClassOrInterfaceFactory {
public static Optional<ClassOrInterface> createClass(JavaClassName name) {
try {
return Optional.of(ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return Optional.empty();
}
public static Optional<ClassOrInterface> createClass(RefType refType) {
return ClassOrInterfaceFactory.createClass(refType.getName());
}
}

View File

@@ -0,0 +1,107 @@
package de.dhbwstuttgart.strucTypes.model;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class InferredTypes implements Map<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric> {
private Map<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric> inferredTypes = new HashMap<>();
public static final InferredTypes EMPTY = new InferredTypes();
public void resolveTransitiveTypes() {
Set<RefTypeOrTPHOrWildcardOrGeneric> keySet = this.inferredTypes.keySet();
for (RefTypeOrTPHOrWildcardOrGeneric key : keySet) {
RefTypeOrTPHOrWildcardOrGeneric value = this.inferredTypes.get(key);
if (value instanceof TypePlaceholder && keySet.contains(value)) {
this.inferredTypes.put(key, this.inferredTypes.get(value));
}
}
}
@Override
public int size() {
return inferredTypes.size();
}
@Override
public boolean isEmpty() {
return inferredTypes.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return inferredTypes.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return inferredTypes.containsValue(value);
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric get(Object key) {
return inferredTypes.get(key);
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric put(RefTypeOrTPHOrWildcardOrGeneric key, RefTypeOrTPHOrWildcardOrGeneric value) {
return inferredTypes.put(key, value);
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric remove(Object key) {
return inferredTypes.remove(key);
}
@Override
public void putAll(Map<? extends RefTypeOrTPHOrWildcardOrGeneric, ? extends RefTypeOrTPHOrWildcardOrGeneric> m) {
inferredTypes.putAll(m);
}
@Override
public void clear() {
inferredTypes.clear();
}
@Override
public Set<RefTypeOrTPHOrWildcardOrGeneric> keySet() {
return inferredTypes.keySet();
}
@Override
public Collection<RefTypeOrTPHOrWildcardOrGeneric> values() {
return inferredTypes.values();
}
@Override
public Set<java.util.Map.Entry<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric>> entrySet() {
return inferredTypes.entrySet();
}
public RefTypeOrTPHOrWildcardOrGeneric infer(RefTypeOrTPHOrWildcardOrGeneric type){
return inferredTypes.get(type) != null ? inferredTypes.get(type) : type;
}
@Override
public String toString() {
String s = "[";
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iterator = this.inferredTypes.keySet().iterator();
while (iterator.hasNext()) {
RefTypeOrTPHOrWildcardOrGeneric type = iterator.next();
s += type + " -> " + inferredTypes.get(type);
if (iterator.hasNext()) {
s += ", ";
}
}
s += "]";
return s;
}
}

View File

@@ -0,0 +1,58 @@
package de.dhbwstuttgart.strucTypes.model;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.RefType;
public class SolvedClass extends ClassOrInterface {
private Set<SubTypeConstraint> constraints = new HashSet<>();
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
public SolvedClass(int modifiers, JavaClassName name, List<Field> fielddecl,
List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset,
Set<SubTypeConstraint> constraints, List<ClassOrInterface> generatedInterfaces) {
super(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface,
implementedInterfaces, offset);
this.constraints = constraints;
this.generatedInterfaces = generatedInterfaces;
}
public SolvedClass(ClassOrInterface classOrInterface, Set<SubTypeConstraint> constraints,
List<ClassOrInterface> generatedInterfaces) {
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
classOrInterface.getMethods(), classOrInterface.getConstructors(), classOrInterface.getGenerics(),
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
classOrInterface.getOffset(), constraints, generatedInterfaces);
}
public SolvedClass(ClassOrInterface classOrInterface, GenericDeclarationList generics,
Set<SubTypeConstraint> constraints, List<ClassOrInterface> generatedInterfaces) {
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
classOrInterface.getMethods(), classOrInterface.getConstructors(), generics,
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
classOrInterface.getOffset(), constraints, generatedInterfaces);
}
public Set<SubTypeConstraint> getConstraints() {
return this.constraints;
}
public List<ClassOrInterface> getGeneratedInterfaces() {
return generatedInterfaces;
}
}

View File

@@ -0,0 +1,81 @@
package de.dhbwstuttgart.strucTypes.printutils;
import java.util.Set;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint;
import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class PrintConstraints {
public void print(ConstraintsSet constraintsSet) {
printSubTypeConstraints(constraintsSet.getSubTypeConstraints());
printFieldConstraints(constraintsSet.getFieldConstraints());
printMethodConstraints(constraintsSet.getMethodConstraints());
}
public void printSubTypeConstraints(Set<SubTypeConstraint> constraints) {
System.out.println("\n SubTypeConstraints:");
constraints.forEach(System.out::println);
// constraints.forEach(c -> System.out
// .println(String.format("%s <* %s", c.getSubtype().toString(),
// c.getSupertype().toString())));
}
public void printSubTypeConstraintsAsUnifyPair(Set<UnifyPair> constraints){
System.out.println("\n SubTypeConstraints:");
constraints.forEach(System.out::println);
}
public void printFieldConstraints(Set<FieldConstraint> constraints) {
System.out.println("\n FieldConstraints:");
constraints.forEach(System.out::println);
// constraints.forEach(c -> System.out.println(String.format("F(%s, %s,
// %s)", c.getClassType().toString(),
// c.getFieldName(), c.getFieldType().toString())));
}
public void printMethodConstraints(Set<MethodConstraint> constraints) {
System.out.println("\n MethodConstraints:");
constraints.forEach(System.out::println);
// constraints.forEach(c -> {
// StringBuilder sb = new StringBuilder("M(");
// sb.append(c.getClassType().toString());
// sb.append(", ");
// sb.append(c.getMethodName());
// sb.append(", [");
// List<SubTypeConstraint> arguments = c.getArguments();
// if (!arguments.isEmpty()) {
// Iterator<SubTypeConstraint> iterator = arguments.iterator();
// while (iterator.hasNext()) {
// RefTypeOrTPHOrWildcardOrGeneric subtype =
// iterator.next().getSubtype();
// sb.append(subtype.toString());
// if (iterator.hasNext()) {
// sb.append(", ");
// }
// }
// }
// sb.append("],(");
// sb.append(c.getReturnType().toString());
// sb.append(", [");
// if (!arguments.isEmpty()) {
// Iterator<SubTypeConstraint> iterator = arguments.iterator();
// while (iterator.hasNext()) {
// RefTypeOrTPHOrWildcardOrGeneric supertype =
// iterator.next().getSupertype();
// sb.append(supertype.toString());
// if (iterator.hasNext()) {
// sb.append(", ");
// }
// }
// }
// sb.append("]))");
// System.out.println(sb.toString());
// });
}
}

View File

@@ -0,0 +1,11 @@
package de.dhbwstuttgart.strucTypes.printutils;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
public class PrintInferredTypes {
public static void print(InferredTypes inferredTypes){
System.out.println("\n Inferred Types:");
inferredTypes.keySet().forEach(key -> System.out.println("[" + key + " -> " + inferredTypes.get(key) + "]"));
}
}

View File

@@ -0,0 +1,405 @@
package de.dhbwstuttgart.strucTypes.printutils;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
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.Expression;
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.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.Receiver;
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;
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;
public class SyntaxTreePrinter implements ASTVisitor {
private InferredTypes inferredTypes;
public SyntaxTreePrinter() {
this(InferredTypes.EMPTY);
}
public SyntaxTreePrinter(InferredTypes inferredTypes) {
this.inferredTypes = inferredTypes;
}
@Override
public void visit(SourceFile sourceFile) {
sourceFile.KlassenVektor.forEach(cl -> cl.accept(this));
}
@Override
public void visit(ClassOrInterface classOrInterface) {
JavaClassName className = classOrInterface.getClassName();
List<Field> fields = classOrInterface.getFieldDecl();
List<Method> methods = classOrInterface.getMethods();
RefType superClass = classOrInterface.getSuperClass();
Collection<RefType> implementedInterfaces = classOrInterface.getSuperInterfaces();
GenericDeclarationList generics = classOrInterface.getGenerics();
System.out.print("\nclass: " + className);
Iterator<GenericTypeVar> iterator = generics.iterator();
if (iterator.hasNext()) {
System.out.print(" <");
while (iterator.hasNext()) {
GenericTypeVar g = iterator.next();
g.accept(this);
if (iterator.hasNext()) {
System.out.print(", ");
}
}
System.out.print(">");
}
System.out.println();
fields.forEach(f -> f.accept(this));
methods.forEach(m -> m.accept(this));
System.out.print("\n superClass: ");
superClass.accept(this);
System.out.println();
if (!implementedInterfaces.isEmpty()) {
System.out.println("\n implemented Interfaces: ");
implementedInterfaces.forEach(i -> i.accept(this));
}
}
@Override
public void visit(Field field) {
String name = field.getName();
RefTypeOrTPHOrWildcardOrGeneric type = field.getType();
System.out.print("field: " + name + " : ");
type.accept(this);
System.out.println();
}
@Override
public void visit(Method method) {
String name = method.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
ParameterList parameterList = method.getParameterList();
System.out.print("\n method: " + name + " : ");
returnType.accept(this);
System.out.println();
parameterList.accept(this);
method.block.accept(this);
}
@Override
public void visit(Block block) {
block.statements.forEach(s -> s.accept(this));
}
@Override
public void visit(ArgumentList argumentList) {
List<Expression> arguments = argumentList.getArguments();
if (!arguments.isEmpty()) {
System.out.println("arguments: ");
arguments.forEach(a -> a.accept(this));
}
}
@Override
public void visit(ParameterList formalParameters) {
List<FormalParameter> formalparalist = formalParameters.getFormalparalist();
formalparalist.forEach(p -> p.accept(this));
}
@Override
public void visit(FormalParameter formalParameter) {
String name = formalParameter.getName();
RefTypeOrTPHOrWildcardOrGeneric type = formalParameter.getType();
System.out.print("parameter: " + name + " : ");
type.accept(this);
System.out.println();
}
@Override
public void visit(MethodCall methodCall) {
String name = methodCall.name;
RefTypeOrTPHOrWildcardOrGeneric type = methodCall.getType();
ArgumentList argumentList = methodCall.getArgumentList();
Receiver receiver = methodCall.receiver;
System.out.print("methodCall: " + name + " : ");
type.accept(this);
System.out.println();
argumentList.accept(this);
System.out.print("receiver: ");
receiver.accept(this);
}
@Override
public void visit(Return aReturn) {
RefTypeOrTPHOrWildcardOrGeneric type = aReturn.getType();
System.out.print("returnType: ");
type.accept(this);
System.out.println();
aReturn.retexpr.accept(this);
}
@Override
public void visit(LocalVar localVar) {
String name = localVar.name;
RefTypeOrTPHOrWildcardOrGeneric type = localVar.getType();
System.out.print("localVar: " + name + " : ");
type.accept(this);
System.out.println();
}
@Override
public void visit(LocalVarDecl localVarDecl) {
throw new NotImplementedException();
}
@Override
public void visit(FieldVar fieldVar) {
String name = fieldVar.fieldVarName;
RefTypeOrTPHOrWildcardOrGeneric type = fieldVar.getType();
Expression receiver = fieldVar.receiver;
System.out.print("fieldVar: " + name + " : ");
type.accept(this);
System.out.println();
System.out.println("receiver: ");
receiver.accept(this);
}
@Override
public void visit(CastExpr castExpr) {
Expression expr = castExpr.expr;
RefTypeOrTPHOrWildcardOrGeneric type = castExpr.getType();
System.out.print("castExpr: ");
expr.accept(this);
System.out.print("typeCastExpr: ");
type.accept(this);
System.out.println();
}
@Override
public void visit(NewClass newClass) {
String name = newClass.name;
RefTypeOrTPHOrWildcardOrGeneric type = newClass.getType();
ArgumentList argumentList = newClass.getArgumentList();
System.out.print("new: " + name + " : ");
type.accept(this);
System.out.println();
argumentList.accept(this);
}
@Override
public void visit(This aThis) {
ArgumentList arglist = aThis.arglist;
RefTypeOrTPHOrWildcardOrGeneric type = aThis.getType();
System.out.print("this : ");
type.accept(this);
if (arglist != null)
arglist.accept(this);
System.out.println();
}
@Override
public void visit(RefType refType) {
System.out.print(refType);
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
if (inferredTypes.get(typePlaceholder) != null) {
inferredTypes.get(typePlaceholder).accept(this);
} else {
System.out.print(typePlaceholder);
}
}
@Override
public void visit(NewArray newArray) {
throw new NotImplementedException();
}
@Override
public void visit(ReturnVoid aReturn) {
throw new NotImplementedException();
}
@Override
public void visit(StaticClassName staticClassName) {
throw new NotImplementedException();
}
@Override
public void visit(Super aSuper) {
throw new NotImplementedException();
}
@Override
public void visit(LambdaExpression lambdaExpression) {
throw new NotImplementedException();
}
@Override
public void visit(WhileStmt whileStmt) {
throw new NotImplementedException();
}
@Override
public void visit(DoStmt whileStmt) {
throw new NotImplementedException();
}
@Override
public void visit(Assign assign) {
throw new NotImplementedException();
}
@Override
public void visit(ForStmt forStmt) {
throw new NotImplementedException();
}
@Override
public void visit(BinaryExpr binary) {
System.out.println("binary");
// binary.lexpr.accept(this);
// System.out.println(binary.operation);
// binary.rexpr.accept(this);
}
@Override
public void visit(IfStmt ifStmt) {
throw new NotImplementedException();
}
@Override
public void visit(EmptyStmt emptyStmt) {
System.out.println("empty statement");
}
@Override
public void visit(Literal literal) {
RefTypeOrTPHOrWildcardOrGeneric type = literal.getType();
System.out.print("literal: ");
type.accept(this);
System.out.println();
}
@Override
public void visit(InstanceOf instanceOf) {
throw new NotImplementedException();
}
@Override
public void visit(AssignToField assignLeftSide) {
throw new NotImplementedException();
}
@Override
public void visit(AssignToLocal assignLeftSide) {
throw new NotImplementedException();
}
@Override
public void visit(SuperCall superCall) {
throw new NotImplementedException();
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
Expression expr = expressionReceiver.expr;
// RefTypeOrTPHOrWildcardOrGeneric type = expressionReceiver.getType();
// System.out.print("expressionReceiverType: ");
// type.accept(this);
// System.out.print(" expressionReceiver: ");
expr.accept(this);
}
@Override
public void visit(GenericTypeVar genericTypeVar) {
System.out.print(genericTypeVar);
}
@Override
public void visit(GenericDeclarationList genericTypeVars) {
throw new NotImplementedException();
}
@Override
public void visit(Constructor field) {
throw new NotImplementedException();
}
@Override
public void visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public void visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public void visit(GenericRefType genericRefType) {
System.out.println("GRT " + genericRefType.getParsedName());
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,137 @@
package de.dhbwstuttgart.strucTypes.visitor;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
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;
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;
public interface ASTReturnVisitor {
// ASTVisitor
SourceFile visit(SourceFile sourceFile);
GenericTypeVar visit(GenericTypeVar genericTypeVar);
FormalParameter visit(FormalParameter formalParameter);
GenericDeclarationList visit(GenericDeclarationList genericTypeVars);
Field visit(Field field);
Method visit(Method method);
Constructor visit(Constructor constructor);
ParameterList visit(ParameterList formalParameters);
ClassOrInterface visit(ClassOrInterface classOrInterface);
RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType);
RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType);
RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder);
RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType);
RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType);
//StatementVisitor
ArgumentList visit(ArgumentList argumentList);
LambdaExpression visit(LambdaExpression lambdaExpression);
Assign visit(Assign assign);
BinaryExpr visit(BinaryExpr binary);
Block visit(Block block);
CastExpr visit(CastExpr castExpr);
EmptyStmt visit(EmptyStmt emptyStmt);
FieldVar visit(FieldVar fieldVar);
ForStmt visit(ForStmt forStmt);
IfStmt visit(IfStmt ifStmt);
InstanceOf visit(InstanceOf instanceOf);
LocalVar visit(LocalVar localVar);
LocalVarDecl visit(LocalVarDecl localVarDecl);
MethodCall visit(MethodCall methodCall);
NewClass visit(NewClass newClass);
NewArray visit(NewArray newArray);
Return visit(Return aReturn);
ReturnVoid visit(ReturnVoid aReturn);
StaticClassName visit(StaticClassName staticClassName);
Super visit(Super aSuper);
This visit(This aThis);
WhileStmt visit(WhileStmt whileStmt);
DoStmt visit(DoStmt doStmt);
AssignToField visit(AssignToField assignLeftSide);
AssignToLocal visit(AssignToLocal assignLeftSide);
SuperCall visit(SuperCall superCall);
ExpressionReceiver visit(ExpressionReceiver expressionReceiver);
UnaryExpr visit(UnaryExpr unaryExpr);
Literal visit(Literal literal);
}

View File

@@ -0,0 +1,309 @@
package de.dhbwstuttgart.strucTypes.visitor;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
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;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public abstract class DefaultASTVisitor implements ASTVisitor {
@Override
public void visit(ArgumentList argumentList) {
throw new NotImplementedException();
}
@Override
public void visit(LambdaExpression lambdaExpression) {
throw new NotImplementedException();
}
@Override
public void visit(Assign assign) {
throw new NotImplementedException();
}
@Override
public void visit(BinaryExpr binary) {
throw new NotImplementedException();
}
@Override
public void visit(Block block) {
throw new NotImplementedException();
}
@Override
public void visit(CastExpr castExpr) {
throw new NotImplementedException();
}
@Override
public void visit(EmptyStmt emptyStmt) {
throw new NotImplementedException();
}
@Override
public void visit(FieldVar fieldVar) {
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) {
throw new NotImplementedException();
}
@Override
public void visit(LocalVarDecl localVarDecl) {
throw new NotImplementedException();
}
@Override
public void visit(MethodCall methodCall) {
throw new NotImplementedException();
}
@Override
public void visit(NewClass methodCall) {
throw new NotImplementedException();
}
@Override
public void visit(NewArray newArray) {
throw new NotImplementedException();
}
@Override
public void visit(Return aReturn) {
throw new NotImplementedException();
}
@Override
public void visit(ReturnVoid aReturn) {
throw new NotImplementedException();
}
@Override
public void visit(StaticClassName staticClassName) {
throw new NotImplementedException();
}
@Override
public void visit(Super aSuper) {
throw new NotImplementedException();
}
@Override
public void visit(This aThis) {
throw new NotImplementedException();
}
@Override
public void visit(WhileStmt whileStmt) {
throw new NotImplementedException();
}
@Override
public void visit(DoStmt whileStmt) {
throw new NotImplementedException();
}
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
@Override
public void visit(Literal literal) {
throw new NotImplementedException();
}
@Override
public void visit(AssignToField assignLeftSide) {
throw new NotImplementedException();
}
@Override
public void visit(AssignToLocal assignLeftSide) {
throw new NotImplementedException();
}
@Override
public void visit(SuperCall superCall) {
throw new NotImplementedException();
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
throw new NotImplementedException();
}
@Override
public void visit(SourceFile sourceFile) {
throw new NotImplementedException();
}
@Override
public void visit(GenericTypeVar genericTypeVar) {
throw new NotImplementedException();
}
@Override
public void visit(FormalParameter formalParameter) {
throw new NotImplementedException();
}
@Override
public void visit(GenericDeclarationList genericTypeVars) {
throw new NotImplementedException();
}
@Override
public void visit(Field field) {
throw new NotImplementedException();
}
@Override
public void visit(Method field) {
throw new NotImplementedException();
}
@Override
public void visit(Constructor field) {
throw new NotImplementedException();
}
@Override
public void visit(ParameterList formalParameters) {
throw new NotImplementedException();
}
@Override
public void visit(ClassOrInterface classOrInterface) {
throw new NotImplementedException();
}
@Override
public void visit(RefType refType) {
throw new NotImplementedException();
}
@Override
public void visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
throw new NotImplementedException();
}
@Override
public void visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public void visit(GenericRefType genericRefType) {
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,389 @@
package de.dhbwstuttgart.strucTypes.visitor;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
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.Expression;
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.Statement;
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;
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;
/**
* Inferiert alle TypePlaceholder durch inferredTypes und erstzt sie durch
* GenericTypeVar, falls der Name des Typeplaceholder mit dem Namen eines
* generics in der GenericdeclarationList generics <20>bereinstimmt.
*
* @author mvr
*
*/
public class InferTypes implements ASTReturnVisitor {
private InferredTypes inferredTypes = new InferredTypes();
private GenericDeclarationList generics = new GenericDeclarationList(new ArrayList<>(), new NullToken());
public InferTypes(InferredTypes inferredTypes) {
this.inferredTypes = inferredTypes;
}
public InferTypes(InferredTypes inferredTypes, GenericDeclarationList generics) {
this.inferredTypes = inferredTypes;
this.generics = generics;
}
@Override
public SourceFile visit(SourceFile sourceFile) {
return new SourceFile(sourceFile.getPkgName(),
sourceFile.getClasses().stream().map(c -> c.accept(this)).collect(Collectors.toList()),
sourceFile.getImports());
}
@Override
public Constructor visit(Constructor constructor) {
int modifier = constructor.modifier;
String name = constructor.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType = constructor.getReturnType().accept(this);
ParameterList parameterList = constructor.getParameterList().accept(this);
Block codeInsideConstructor = constructor.block.accept(this);
GenericDeclarationList gtvDeclarations = ((GenericDeclarationList) constructor.getGenerics()).accept(this);
Token offset = constructor.getOffset();
List<Statement> fieldInitializations = new ArrayList<>();
return new Constructor(modifier, name, returnType, parameterList, codeInsideConstructor, gtvDeclarations,
offset, fieldInitializations);
}
@Override
public GenericTypeVar visit(GenericTypeVar genericTypeVar) {
return new GenericTypeVar(
genericTypeVar.getName(), genericTypeVar.getBounds().stream()
.map(b -> (RefTypeOrTPHOrWildcardOrGeneric) b.accept(this)).collect(Collectors.toList()),
genericTypeVar.getOffset(), new NullToken());
}
@Override
public FormalParameter visit(FormalParameter formalParameter) {
return new FormalParameter(formalParameter.getName(), formalParameter.getType().accept(this),
formalParameter.getOffset());
}
@Override
public GenericDeclarationList visit(GenericDeclarationList genericTypeVars) {
List<GenericTypeVar> values = new ArrayList<>();
genericTypeVars.forEach(gtv -> values.add(gtv.accept(this)));
return new GenericDeclarationList(values, genericTypeVars.getOffset());
}
@Override
public Field visit(Field field) {
return new Field(field.getName(), field.getType().accept(this), field.modifier, field.getOffset());
}
@Override
public Method visit(Method method) {
int modifier = method.modifier;
String name = method.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType().accept(this);
ParameterList parameterList = method.getParameterList().accept(this);
Block block = method.block.accept(this);
GenericDeclarationList gtvDeclarations = ((GenericDeclarationList) method.getGenerics()).accept(this);
Token offset = method.getOffset();
return new Method(modifier, name, returnType, parameterList, block, gtvDeclarations, offset);
}
@Override
public ParameterList visit(ParameterList formalParameters) {
for (FormalParameter formalParameter : formalParameters) {
formalParameter.accept(this);
}
return new ParameterList(
formalParameters.getFormalparalist().stream().map(p -> p.accept(this)).collect(Collectors.toList()),
formalParameters.getOffset());
}
@Override
public ClassOrInterface visit(ClassOrInterface classOrInterface) {
int modifiers = classOrInterface.getModifiers();
JavaClassName name = classOrInterface.getClassName();
List<Field> fielddecl = classOrInterface.getFieldDecl().stream().map(f -> f.accept(this))
.collect(Collectors.toList());
List<Method> methods = classOrInterface.getMethods().stream().map(m -> m.accept(this))
.collect(Collectors.toList());
List<Constructor> constructors = classOrInterface.getConstructors().stream()
.map(c -> (Constructor) c.accept(this)).collect(Collectors.toList());
GenericDeclarationList genericClassParameters = classOrInterface.getGenerics().accept(this);
RefType superClass = (RefType) classOrInterface.getSuperClass().accept(this);
Boolean isInterface = classOrInterface.isInterface;
List<RefType> implementedInterfaces = classOrInterface.getSuperInterfaces().stream()
.map(i -> (RefType) i.accept(this)).collect(Collectors.toList());
Token offset = classOrInterface.getOffset();
return new ClassOrInterface(modifiers, name, fielddecl, methods, constructors, genericClassParameters,
superClass, isInterface, implementedInterfaces, offset);
}
@Override
public RefType visit(RefType refType) {
return refType.getParaList() == null ? refType
: new RefType(refType.getName(), refType.getParaList().stream()
.map(p -> (RefTypeOrTPHOrWildcardOrGeneric) p.accept(this)).collect(Collectors.toList()),
refType.getOffset());
}
@Override
public SuperWildcardType visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException();
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
RefTypeOrTPHOrWildcardOrGeneric inferredType = inferredTypes.infer(typePlaceholder);
if (inferredType instanceof TypePlaceholder) {
TypePlaceholder inferredTypeTPH = (TypePlaceholder) inferredType;
if (generics.contains(inferredTypeTPH.getName())) {
return new GenericRefType(inferredTypeTPH.getName(), typePlaceholder.getOffset());
}
}
return inferredType;
}
@Override
public ExtendsWildcardType visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException();
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
RefTypeOrTPHOrWildcardOrGeneric inferredType = inferredTypes.infer(genericRefType);
return inferredType;
}
@Override
public ArgumentList visit(ArgumentList argumentList) {
return new ArgumentList(argumentList.getArguments().stream().map(expr -> (Expression) expr.accept(this))
.collect(Collectors.toList()), argumentList.getOffset());
}
@Override
public LambdaExpression visit(LambdaExpression lambdaExpression) {
throw new NotImplementedException();
}
@Override
public Assign visit(Assign assign) {
return assign;
}
@Override
public BinaryExpr visit(BinaryExpr binary) {
return binary;
}
@Override
public Block visit(Block block) {
return new Block(
block.getStatements().stream().map(s -> (Statement) s.accept(this)).collect(Collectors.toList()),
block.getOffset());
}
@Override
public CastExpr visit(CastExpr castExpr) {
return new CastExpr(castExpr.getType().accept(this), castExpr.expr == null ? null : castExpr.expr.accept(this),
castExpr.getOffset());
}
@Override
public EmptyStmt visit(EmptyStmt emptyStmt) {
return emptyStmt;
}
@Override
public FieldVar visit(FieldVar fieldVar) {
return new FieldVar(fieldVar.receiver == null ? null : fieldVar.receiver.accept(this), fieldVar.fieldVarName,
fieldVar.getType().accept(this), fieldVar.getOffset());
}
@Override
public ForStmt visit(ForStmt forStmt) {
throw new NotImplementedException();
}
@Override
public IfStmt visit(IfStmt ifStmt) {
throw new NotImplementedException();
}
@Override
public InstanceOf visit(InstanceOf instanceOf) {
throw new NotImplementedException();
}
@Override
public LocalVar visit(LocalVar localVar) {
return new LocalVar(localVar.name, localVar.getType().accept(this), localVar.getOffset());
}
@Override
public LocalVarDecl visit(LocalVarDecl localVarDecl) {
throw new NotImplementedException();
}
@Override
public MethodCall visit(MethodCall methodCall) {
methodCall.getType().accept(this);
methodCall.getArgumentList().accept(this);
return new MethodCall(methodCall.getType().accept(this),
methodCall.receiver == null ? null : methodCall.receiver.accept(this), methodCall.name,
methodCall.getArgumentList().accept(this), methodCall.getOffset());
}
@Override
public NewClass visit(NewClass newClass) {
return new NewClass(newClass.getType().accept(this), newClass.getArgumentList().accept(this),
newClass.getOffset());
}
@Override
public NewArray visit(NewArray newArray) {
throw new NotImplementedException();
}
@Override
public Return visit(Return aReturn) {
return new Return(aReturn.retexpr == null ? null : aReturn.retexpr.accept(this), aReturn.getOffset());
}
@Override
public ReturnVoid visit(ReturnVoid aReturn) {
return aReturn;
}
@Override
public StaticClassName visit(StaticClassName staticClassName) {
throw new NotImplementedException();
}
@Override
public Super visit(Super aSuper) {
throw new NotImplementedException();
}
@Override
public This visit(This aThis) {
// als Typ wird immer ein neuer TypePlaceholder zugeordnet.
return aThis;
}
@Override
public WhileStmt visit(WhileStmt whileStmt) {
throw new NotImplementedException();
}
@Override
public DoStmt visit(DoStmt whileStmt) {
throw new NotImplementedException();
}
@Override
public AssignToField visit(AssignToField assignLeftSide) {
throw new NotImplementedException();
}
@Override
public AssignToLocal visit(AssignToLocal assignLeftSide) {
throw new NotImplementedException();
}
@Override
public SuperCall visit(SuperCall superCall) {
if (superCall.getArgumentList().getArguments() == null) {
return superCall;
}
return new SuperCall(superCall.getArgumentList().accept(this), superCall.getOffset());
}
@Override
public ExpressionReceiver visit(ExpressionReceiver expressionReceiver) {
return new ExpressionReceiver(expressionReceiver.expr == null ? null : expressionReceiver.expr.accept(this));
}
@Override
public UnaryExpr visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
}
@Override
public Literal visit(Literal literal) {
return literal;
}
}

View File

@@ -0,0 +1,253 @@
package de.dhbwstuttgart.strucTypes.visitor;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint;
import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.Literal;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class TYPEExpr extends DefaultASTVisitor {
private ClassOrInterface aThis;
private ConstraintsSet constraints = new ConstraintsSet();
private InferredTypes inferredTypes = new InferredTypes();
public TYPEExpr() {
}
public ConstraintsSet getConstraints() {
return this.constraints;
}
public InferredTypes getInferredTypes() {
return inferredTypes;
}
@Override
public void visit(ClassOrInterface classOrInterface) {
this.aThis = classOrInterface;
classOrInterface.getMethods().forEach(m -> m.accept(this));
}
@Override
public void visit(LocalVar localVar) {
// keine neuen Constraints. Typisierung bereits im SyntaxTree vorhanden.
}
@Override
public void visit(FieldVar fieldVar) {
fieldVar.receiver.accept(this);
// L<>st Typen zwischen Feld und Feldvariable auf
boolean receiverIsThis = this.inferFieldVarTypes(fieldVar);
// Ermittelt den Typ ty von fieldVar.receiver und fields(f)
TypeExtract fieldTypeVisitor = new TypeExtract();
// unterscheide fieldVar.receiver == this
if (receiverIsThis) {
this.aThis.accept(fieldTypeVisitor);
} else {
fieldVar.receiver.getType().accept(fieldTypeVisitor);
}
if (!fieldTypeVisitor.isTypeVariable() && fieldTypeVisitor.getField(fieldVar.fieldVarName).isPresent()) {
fieldTypeVisitor.getField(fieldVar.fieldVarName)
.ifPresent(f -> this.inferredTypes.put((TypePlaceholder) fieldVar.getType(), f.getType()));
} // keine neuen Constraints
else {
FieldConstraint fieldConstraint = new FieldConstraint(fieldVar.receiver.getType(), fieldVar.fieldVarName,
fieldVar.getType());
this.constraints.addConstraint(fieldConstraint);
}
this.constraints.inferTypes(fieldTypeVisitor.getGrtToTphMap());
}
/**
* L<>st die Typenzugeh<65>rigkeit zwischen fieldVar mit receiver this und dem
* korrespondierenden Feld in der Instanz auf.
*
* @param fieldVar
* @return true, wenn ein passendes Feld in der Instanz gefunden wird.
*/
private boolean inferFieldVarTypes(FieldVar fieldVar) {
if (fieldVar.receiver instanceof This) {
this.aThis.getFieldDecl().stream().filter(f -> f.getName().equals(fieldVar.fieldVarName))
// keine statische Polymorphie zugelassen
.findFirst()
.ifPresent(f -> this.inferredTypes.put((TypePlaceholder) fieldVar.getType(), f.getType()));
return true;
}
return false;
}
@Override
public void visit(MethodCall methodCall) {
methodCall.receiver.accept(this);
methodCall.arglist.accept(this);
// ermittelt den Typ ty0 von methodCall.receiver und mtype(m, ty0)
TypeExtract methodTypeVisitor = new TypeExtract();
// unterscheide methodcall.receiver == this
if (methodCall.receiver instanceof ExpressionReceiver
&& ((ExpressionReceiver) methodCall.receiver).expr instanceof This) {
this.aThis.accept(methodTypeVisitor);
} else {
methodCall.receiver.getType().accept(methodTypeVisitor);
}
List<Expression> arguments = methodCall.getArgumentList().getArguments();
Optional<Method> method = methodTypeVisitor.getMethod(methodCall.name, arguments.size());
if (!methodTypeVisitor.isTypeVariable() && method.isPresent()) {
Method m = method.get();
for (int i = 0; i < arguments.size(); i++) {
this.constraints.addConstraint(new SubTypeConstraint(arguments.get(i).getType(),
m.getParameterList().getParameterAt(i).getType()));
}
this.inferredTypes.put((TypePlaceholder) methodCall.getType(), m.getReturnType());
} else {
MethodConstraint methodConstraint = new MethodConstraint(methodCall.receiver.getType(), methodCall.name,
new ArrayList<SubTypeConstraint>(), methodCall.getType());
arguments.forEach(e -> methodConstraint.addArguments(e.getType()));
this.constraints.addConstraint(methodConstraint);
}
// System.out.println("\ninferred grt:");
// System.out.println("map: " + methodTypeVisitor.getGrtToTphMap());
// System.out.println("generics: " + methodTypeVisitor.getGenerics());
this.constraints.inferTypes(methodTypeVisitor.getGrtToTphMap());
}
@Override
public void visit(ArgumentList argumentList) {
argumentList.getArguments().forEach(a -> a.accept(this));
}
@Override
public void visit(CastExpr castExpr) {
castExpr.expr.accept(this);
if (((RefType) castExpr.getType()).getName().equals(this.aThis.getClassName())) {
// keine neuen Constraints
} else {
// implement generics nicht n<>tig
}
}
@Override
public void visit(NewClass newClass) {
newClass.getArgumentList().accept(this);
RefType type = (RefType) newClass.getType();
TypeExtract typeExtract = new TypeExtract();
if (type.getName().equals(this.aThis.getClassName())) {
this.aThis.accept(typeExtract);
} else {
type.accept(typeExtract);
// implement generics nicht n<>tig
}
this.createNewClassSubTypeConstraints(newClass, typeExtract);
}
private void createNewClassSubTypeConstraints(NewClass newClass, TypeExtract typeExtract) {
final List<Expression> arguments = newClass.getArgumentList().getArguments();
final List<Field> fields = typeExtract.getFields();
final int argumentsSize = arguments.size();
final int fieldsSize = fields.size();
if (argumentsSize != fieldsSize) {
throw new IllegalArgumentException(String.format(
"The number of fields (%d) in %s doesn't match the number of arguments (%d) passed to its constructor.",
fieldsSize, newClass.name, argumentsSize));
}
// List of Generics of newClass
List<RefTypeOrTPHOrWildcardOrGeneric> paraList = ((RefType) newClass.getType()).getParaList();
List<FormalParameter> formalparalist = typeExtract.getConstructors().get(0).getParameterList()
.getFormalparalist();
for (int i = 0; i < argumentsSize; i++) {
// Bei Fields wird kein GenericRefType sondern Object als Typ
// geparst. Workaround <20>ber den Konstruktor.
// SubTypeConstraint subTypeConstraint = new
// SubTypeConstraint(arguments.get(i).getType(),
// fields.get(i).getType());
// Es darf nur einen Konstruktor mit allen Feldern geben.
RefTypeOrTPHOrWildcardOrGeneric supertype = formalparalist.get(i).getType();
supertype = supertype instanceof GenericRefType ? paraList.remove(0) : supertype;
SubTypeConstraint subTypeConstraint = new SubTypeConstraint(arguments.get(i).getType(), supertype);
this.constraints.addConstraint(subTypeConstraint);
}
typeExtract.getSubTypeConstraints().forEach(this.constraints::addConstraint);
// System.out.println("\ninferred grt:");
// System.out.println("map: " + typeExtract.getGrtToTphMap());
// System.out.println("generics: " + typeExtract.getGenerics());
this.constraints.inferTypes(typeExtract.getGrtToTphMap());
}
@Override
public void visit(This aThis) {
// TPH von This mit Klasse in inferredTypes verkn<6B>pfen
if (this.aThis != null) {
this.inferredTypes.put((TypePlaceholder) aThis.getType(), ClassOrInterface
.generateTypeOfClass(this.aThis.getClassName(), this.aThis.getGenerics(), this.aThis.getOffset()));
}
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
expressionReceiver.expr.accept(this);
}
@Override
public void visit(Method method) {
method.block.accept(this);
}
@Override
public void visit(Block block) {
// Es gibt nur ein Statement: Return
block.getStatements().forEach(s -> s.accept(this));
}
@Override
public void visit(Return aReturn) {
aReturn.retexpr.accept(this);
}
@Override
public void visit(GenericRefType genericRefType) {
}
@Override
public void visit(Literal literal) {
}
@Override
public void visit(BinaryExpr binary) {
}
}

View File

@@ -0,0 +1,167 @@
package de.dhbwstuttgart.strucTypes.visitor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.model.ClassOrInterfaceFactory;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Extrahiert die typisierten Felder und Methoden von ClassOrInterface bzw. von
* RefType rekursiv <20>ber alle Superklassen und implementierten Interfaces.
*
* @author mvr
*
*/
public class TypeExtract extends DefaultASTVisitor {
private List<Field> fields = new ArrayList<>();
private List<Method> methods = new ArrayList<>();
private List<Constructor> constructors = new ArrayList<>();
private List<GenericTypeVar> generics = new ArrayList<>();
private InferredTypes grtToTphMap = InferredTypes.EMPTY;
private List<SubTypeConstraint> subTypeConstraints = new ArrayList<>();
private boolean typeVariable = false;
private boolean initialClass = true;
public List<Field> getFields() {
return this.fields;
}
public List<Method> getMethods() {
return this.methods;
}
public List<Constructor> getConstructors() {
return constructors;
}
public List<GenericTypeVar> getGenerics() {
return generics;
}
public InferredTypes getGrtToTphMap() {
return grtToTphMap;
}
public List<SubTypeConstraint> getSubTypeConstraints() {
return subTypeConstraints;
}
public Optional<Field> getField(String fieldName) {
return this.fields.stream().filter(f -> f.getName().equals(fieldName))
// keine statische Polymorphie zugelassen
.findFirst();
}
public Optional<Method> getMethod(String methodName, int parameterCount) {
return this.methods.stream()
.filter(m -> m.getName().equals(methodName)
&& m.getParameterList().getFormalparalist().size() == parameterCount)
// keine statische Polymorphie zugelassen
.findFirst();
}
public boolean isTypeVariable() {
return this.typeVariable;
}
@Override
public void visit(ClassOrInterface classOrInterface) {
classOrInterface.getFieldDecl().forEach(f -> f.accept(this));
classOrInterface.getMethods().forEach(m -> m.accept(this));
classOrInterface.getConstructors().forEach(c -> {
if (c != null && this.initialClass)
c.accept(this);
});
classOrInterface.getGenerics().accept(this);
this.initialClass = false;
// superClass(Object) -> Object => unendliche Rekursionstiefe!
if (!classOrInterface.getClassName().equals(new JavaClassName("java.lang.Object"))) {
classOrInterface.getSuperClass().accept(this);
classOrInterface.getSuperInterfaces().forEach(i -> i.accept(this));
}
}
@Override
public void visit(RefType refType) {
this.typeVariable = false;
Optional<ClassOrInterface> createClass = ClassOrInterfaceFactory.createClass(refType);
// refType und createClass haben evtl. unterschiedliche
// Klassenparameter (refType -> tph| createClass -> gtv). Diese werden
// in grtToTphMap gespeichert.
if (createClass.isPresent()) {
ClassOrInterface cls = createClass.get();
cls.getGenerics().accept(this);
Iterator<GenericTypeVar> iteratorGtv = cls.getGenerics().iterator();
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iteratorTPH = refType.getParaList().iterator();
while (iteratorGtv.hasNext()) {
GenericTypeVar nextGtv = iteratorGtv.next();
GenericRefType grt = new GenericRefType(nextGtv.getName(), nextGtv.getOffset());
RefTypeOrTPHOrWildcardOrGeneric nextTPH = iteratorTPH.next();
if (nextTPH instanceof TypePlaceholder) {
TypePlaceholder tph = (TypePlaceholder) nextTPH;
this.grtToTphMap.put(grt, tph);
}
}
cls.accept(this);
}
}
@Override
public void visit(Field field) {
this.fields.add(field);
}
@Override
public void visit(Method method) {
this.methods.add(method);
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
this.typeVariable = true;
}
@Override
public void visit(Constructor constructor) {
this.constructors.add(constructor);
}
@Override
public void visit(GenericDeclarationList genericTypeVars) {
genericTypeVars.forEach(gtv -> gtv.accept(this));
}
@Override
public void visit(GenericTypeVar genericTypeVar) {
if (!this.generics.contains(genericTypeVar)) {
this.generics.add(genericTypeVar);
// Aus den bounds k<>nnen die Subtypconstraints abgeleitet werden.
RefTypeOrTPHOrWildcardOrGeneric bound = genericTypeVar.getBounds().get(0);
if (!((bound instanceof RefType)
&& ((RefType) bound).getName().equals(new JavaClassName("java.lang.Object")))) {
this.subTypeConstraints.add(new SubTypeConstraint(
new GenericRefType(genericTypeVar.getName(), genericTypeVar.getOffset()), bound));
}
}
}
@Override
public void visit(GenericRefType genericRefType) {
}
}

View File

@@ -0,0 +1,38 @@
package de.dhbwstuttgart.strucTypes.visitor;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Extrahiert alle TypePlaceholder.
*
* @author mvr
*
*/
public class TypeVar extends AbstractASTWalker {
private Set<TypePlaceholder> typeVars = new HashSet<>();
private InferredTypes inferredTypes = new InferredTypes();
public TypeVar(InferredTypes inferredTypes) {
this.inferredTypes = inferredTypes;
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
super.visit(typePlaceholder);
RefTypeOrTPHOrWildcardOrGeneric inferredType = this.inferredTypes.infer(typePlaceholder);
if (inferredType instanceof TypePlaceholder) {
this.typeVars.add((TypePlaceholder) inferredType);
}
}
public Set<TypePlaceholder> getTypeVars() {
return typeVars;
}
}

View File

@@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
@@ -12,6 +13,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import org.antlr.v4.runtime.Token;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -26,7 +28,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
private List<Method> methods = new ArrayList<>();
private GenericDeclarationList genericClassParameters;
private RefType superClass;
protected boolean isInterface;
public boolean isInterface;
private List<RefType> implementedInterfaces;
private List<Constructor> constructors;
@@ -34,6 +36,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
super(offset);
this.modifiers = modifiers;
if(isInterface)this.modifiers += Modifier.INTERFACE;
this.name = name;
this.fields = fielddecl;
this.genericClassParameters = genericClassParameters;
@@ -102,8 +105,17 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public ClassOrInterface accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
public Collection<RefType> getSuperInterfaces() {
public List<RefType> getSuperInterfaces() {
return implementedInterfaces;
}
public String toString() {
return this.name.toString() + this.genericClassParameters.toString();
}
}

View File

@@ -6,6 +6,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import java.util.List;
@@ -35,4 +36,9 @@ public class Constructor extends Method {
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public Constructor accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
@@ -40,5 +41,10 @@ public class Field extends SyntaxTreeNode implements TypeScope{
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
return type;
}
@Override
public Field accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
@@ -26,4 +27,9 @@ public class FormalParameter extends SyntaxTreeNode
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public FormalParameter accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -2,6 +2,8 @@ package de.dhbwstuttgart.syntaxtree;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import java.util.*;
@@ -21,6 +23,10 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
gtvs = values;
this.offsetOfLastElement = endOffset;
}
public boolean contains(String genericTypeVarName){
return gtvs.stream().anyMatch(gtv-> gtv.getName().equals(genericTypeVarName));
}
@Override
public Iterator<GenericTypeVar> iterator() {
@@ -31,4 +37,14 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public GenericDeclarationList accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
public String toString() {
return this.gtvs.toString();
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
@@ -61,4 +62,9 @@ public class GenericTypeVar extends SyntaxTreeNode
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public GenericTypeVar accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
import java.util.ArrayList;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
@@ -69,4 +70,9 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
public String getName() {
return name;
}
@Override
public Method accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -4,6 +4,8 @@ package de.dhbwstuttgart.syntaxtree;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import java.util.Iterator;
import java.util.List;
@@ -39,4 +41,9 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public ParameterList accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -4,6 +4,7 @@ import java.util.*;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
//import sun.security.x509.X509CertInfo;
@@ -43,4 +44,9 @@ public class SourceFile extends SyntaxTreeNode{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public SourceFile accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import org.antlr.v4.runtime.Token;
//import org.antlr.v4.runtime.misc.Pair;
@@ -20,4 +21,6 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
}
public abstract void accept(ASTVisitor visitor);
public abstract <T> T accept(ASTReturnVisitor visitor);
}

View File

@@ -26,6 +26,8 @@ import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.unify.model.*;
public class UnifyTypeFactory {
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses) throws ClassNotFoundException {
/*
@@ -49,6 +51,10 @@ public class UnifyTypeFactory {
return new UnifyPair(tl, tr, PairOperator.SMALLERDOT);
}
public static UnifyPair generateSmallNotEqualDotPair(UnifyType tl, UnifyType tr){
return new UnifyPair(tl, tr, PairOperator.SMALLERNEQDOT);
}
public static UnifyPair generateEqualDotPair(UnifyType tl, UnifyType tr){
return new UnifyPair(tl, tr, PairOperator.EQUALSDOT);
}
@@ -113,7 +119,15 @@ public class UnifyTypeFactory {
}
public static UnifyType convert(TypePlaceholder tph){
return new PlaceholderType(tph.getName());
PlaceholderType ntph = new PlaceholderType(tph.getName());
int in = PLACEHOLDERS.indexOf(ntph);
if (in == -1) {
PLACEHOLDERS.add(ntph);
return ntph;
}
else {
return PLACEHOLDERS.get(in);
}
}
public static UnifyType convert(GenericRefType t){
@@ -142,6 +156,10 @@ public class UnifyTypeFactory {
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) {
UnifyPair ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) {
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
@@ -30,4 +31,9 @@ public class ArgumentList extends SyntaxTreeNode
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public ArgumentList accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
@@ -26,4 +27,9 @@ public class Assign extends Statement
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public Assign accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
public class AssignToField extends AssignLeftSide{
@@ -13,4 +14,9 @@ public class AssignToField extends AssignLeftSide{
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public AssignToField accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
@@ -11,6 +12,11 @@ public class BinaryExpr extends Expression
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public BinaryExpr accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
public enum Operator{
ADD, // +

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.*;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
@@ -28,6 +29,11 @@ public class Block extends Statement
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public Block accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
@@ -22,4 +23,9 @@ public class CastExpr extends Expression
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public CastExpr accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import org.antlr.v4.runtime.Token;
@@ -15,4 +16,9 @@ public class DoStmt extends WhileStmt
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public DoStmt accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
@@ -19,4 +20,9 @@ public class EmptyStmt extends Statement
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public EmptyStmt accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
@@ -18,4 +19,9 @@ public class ExpressionReceiver extends Receiver
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public ExpressionReceiver accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
@@ -28,4 +29,9 @@ public class FieldVar extends Expression {
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
@Override
public FieldVar accept(ASTReturnVisitor visitor) {
return visitor.visit(this);
}
}

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