Compare commits
22 Commits
strucTypes
...
UnifyDepen
Author | SHA1 | Date | |
---|---|---|---|
1a2454e00b | |||
bc1a796e28 | |||
b8e229cf3f | |||
e0c5afcd6d | |||
9123e222f4 | |||
29bd9a3f4f | |||
7926c25c7d | |||
b4c604e2b1 | |||
d8bb4d6188 | |||
0ecaf36648 | |||
2eb7a63480 | |||
11649b39d3 | |||
303cfa5409 | |||
660ef68f7e | |||
23eab0c9a4 | |||
162ca3eb27 | |||
6d70464a1c | |||
04d3ac84e7 | |||
2db5ecc260 | |||
b325e205a1 | |||
ff2bca5ce5 | |||
66078360da |
@ -1,88 +0,0 @@
|
||||
<!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>
|
Before ![]() (image error) Size: 25 KiB |
Before ![]() (image error) Size: 80 KiB |
Before ![]() (image error) Size: 109 KiB |
@ -1,40 +0,0 @@
|
||||
<!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>
|
@ -1,40 +0,0 @@
|
||||
<!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>
|
Before ![]() (image error) Size: 32 KiB |
Before ![]() (image error) Size: 52 KiB |
Before ![]() (image error) Size: 61 KiB |
Before ![]() (image error) Size: 96 KiB |
Before ![]() (image error) Size: 93 KiB |
Before ![]() (image error) Size: 163 KiB |
Before ![]() (image error) Size: 163 KiB |
Before ![]() (image error) Size: 88 KiB |
Before ![]() (image error) Size: 50 KiB |
Before ![]() (image error) Size: 96 KiB |
Before ![]() (image error) Size: 102 KiB |
Before ![]() (image error) Size: 100 KiB |
Before ![]() (image error) Size: 76 KiB |
@ -1,34 +0,0 @@
|
||||
<!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>
|
Before ![]() (image error) Size: 150 KiB |
@ -1,24 +0,0 @@
|
||||
<!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>
|
Before ![]() (image error) Size: 112 KiB |
Before ![]() (image error) Size: 33 KiB |
BIN
src/de/dhbwstuttgart/.DS_Store
vendored
@ -17,6 +17,7 @@ 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.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
@ -28,6 +29,8 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
@ -41,8 +44,13 @@ public class BytecodeGen implements ASTVisitor {
|
||||
private boolean isInterface;
|
||||
private List<ResultSet> listOfResultSets;
|
||||
private ResultSet resultSet;
|
||||
|
||||
private String path;
|
||||
|
||||
private int indexOfFirstParam = 0;
|
||||
|
||||
private String superClass;
|
||||
|
||||
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
// stores generics and their bounds of class
|
||||
@ -50,22 +58,26 @@ public class BytecodeGen implements ASTVisitor {
|
||||
// stores generics and their bounds of method
|
||||
HashMap<String, String> genericsAndBoundsMethod = new HashMap<>();
|
||||
|
||||
private final TPHExtractor tphExtractor = new TPHExtractor();
|
||||
private final ArrayList<GenericInsertPair> commonPairs = new ArrayList<>();
|
||||
|
||||
HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||
byte[] bytecode;
|
||||
HashMap<String,byte[]> classFiles;
|
||||
|
||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||
|
||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets) {
|
||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets, String path) {
|
||||
this.classFiles = classFiles;
|
||||
this.listOfResultSets = listOfResultSets;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SourceFile sourceFile) {
|
||||
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
||||
System.out.println("in Class: " + cl.getClassName().toString());
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
|
||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets,path);
|
||||
cl.accept(classGen);
|
||||
classGen.writeClass(cl.getClassName().toString());
|
||||
}
|
||||
@ -90,6 +102,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
|
||||
className = classOrInterface.getClassName().toString();
|
||||
|
||||
cw.visitSource(className +".jav", null);
|
||||
@ -97,27 +110,41 @@ public class BytecodeGen implements ASTVisitor {
|
||||
isInterface = (classOrInterface.getModifiers()&512)==512;
|
||||
|
||||
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds);
|
||||
sig = signature.toString();
|
||||
}
|
||||
// needs implemented Interfaces?
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
f.accept(this);
|
||||
}
|
||||
|
||||
// resultSet = listOfResultSets.get(0);
|
||||
boolean isConsWithNoParamsVisited = false;
|
||||
boolean isVisited = false;
|
||||
for(ResultSet rs : listOfResultSets) {
|
||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||
resultSet = rs;
|
||||
// Nur einmal ausführen!!
|
||||
if(!isVisited) {
|
||||
classOrInterface.accept(tphExtractor);
|
||||
|
||||
getCommonTPHS(tphExtractor);
|
||||
|
||||
String sig = null;
|
||||
/* if class has generics then creates signature
|
||||
* Signature looks like:
|
||||
* <E:Ljava/...>Superclass
|
||||
*/
|
||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty()) {
|
||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs);
|
||||
sig = signature.toString();
|
||||
System.out.println("Signature: => " + sig);
|
||||
}
|
||||
|
||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||
|
||||
isVisited = true;
|
||||
}
|
||||
|
||||
for(Field f : classOrInterface.getFieldDecl()) {
|
||||
f.accept(this);
|
||||
}
|
||||
|
||||
for(Constructor c : classOrInterface.getConstructors()) {
|
||||
if(!isConsWithNoParamsVisited)
|
||||
c.accept(this);
|
||||
@ -133,6 +160,16 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
}
|
||||
|
||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
||||
// Gemeinsame TPHs
|
||||
ArrayList<TypePlaceholder> cTPHs = new ArrayList<>();
|
||||
// Alle TPHs der Felder speichern
|
||||
for(TypePlaceholder tph : tphExtractor.allTPHS.keySet()) {
|
||||
if(!tphExtractor.allTPHS.get(tph))
|
||||
cTPHs.add(tph);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor field) {
|
||||
field.getParameterList().accept(this);
|
||||
@ -156,8 +193,8 @@ public class BytecodeGen implements ASTVisitor {
|
||||
desc = constructor.accept(new DescriptorToString(resultSet));
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||
mv.visitCode();
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, path);
|
||||
if(!field.getParameterList().iterator().hasNext()) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
@ -215,11 +252,14 @@ public class BytecodeGen implements ASTVisitor {
|
||||
/* 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);
|
||||
|
||||
ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs);
|
||||
System.out.println(method.name + " => Simplified Pairs: ");
|
||||
pairs.forEach(p->System.out.println(p.TA1.getName() + " -> "+p.TA2.getName()));
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet, pairs);
|
||||
sig = signature.toString();
|
||||
}
|
||||
// System.out.println(sig);
|
||||
System.out.println(method.getName()+" ==> "+sig);
|
||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||
methDesc = meth.accept(new DescriptorToString(resultSet));
|
||||
|
||||
@ -227,13 +267,103 @@ public class BytecodeGen implements ASTVisitor {
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null);
|
||||
|
||||
mv.visitCode();
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,method, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles);
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,method, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, path);
|
||||
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
private ArrayList<GenericInsertPair> simplifyPairs(String methodName, ArrayList<GenericInsertPair> allPairs) {
|
||||
allPairs.forEach(p->System.out.print(p.TA1 + " < "+ p.TA2+ " ; "));
|
||||
|
||||
if(allPairs.size() < 2)
|
||||
return allPairs;
|
||||
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>();
|
||||
|
||||
MethodAndTPH method;
|
||||
ArrayList<TypePlaceholder> methodTphs = new ArrayList<>();
|
||||
ArrayList<GenericInsertPair> methodPairs = new ArrayList<>();
|
||||
for(MethodAndTPH m : tphExtractor.ListOfMethodsAndTph) {
|
||||
if(m.getName().equals(methodName)) {
|
||||
methodTphs = m.getTphs();
|
||||
methodPairs = m.getPairs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
||||
for(GenericInsertPair p : allPairs) {
|
||||
// Tph2.jav
|
||||
if(subAndSuperTph.containsKey(p.TA1)) {
|
||||
if(methodTphs.contains(subAndSuperTph.get(p.TA1)))
|
||||
continue;
|
||||
}
|
||||
subAndSuperTph.put(p.TA1, p.TA2);
|
||||
}
|
||||
int numOfVisitedPairs = 0;
|
||||
for(TypePlaceholder subTph: subAndSuperTph.keySet()) {
|
||||
|
||||
if(numOfVisitedPairs>=subAndSuperTph.size())
|
||||
break;
|
||||
|
||||
if(!methodTphs.contains(subTph))
|
||||
continue;
|
||||
|
||||
HashMap<Integer, TypePlaceholder> tphsInRel= new HashMap<>();
|
||||
|
||||
tphsInRel.put(tphsInRel.size(), subTph);
|
||||
TypePlaceholder superTph = subAndSuperTph.get(subTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
|
||||
numOfVisitedPairs++;
|
||||
|
||||
while(subAndSuperTph.containsKey(superTph)) {
|
||||
superTph = subAndSuperTph.get(superTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
// Subtype
|
||||
TypePlaceholder subTphRes = tphsInRel.get(0);
|
||||
// Die größte Supertype
|
||||
TypePlaceholder superTphRes = tphsInRel.get(tphsInRel.size()-1);
|
||||
|
||||
while(subAndSuperTph.containsValue(subTphRes)) {
|
||||
for(TypePlaceholder tph : subAndSuperTph.keySet()) {
|
||||
if(methodTphs.contains(tph) && subAndSuperTph.get(tph).equals(subTphRes)) {
|
||||
subTphRes = tph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(subTphRes.equals(tphsInRel.get(0))) {
|
||||
break;
|
||||
}
|
||||
tphsInRel.put(0, subTphRes);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
subTphRes = tphsInRel.get(0);
|
||||
|
||||
int i = 2;
|
||||
while(!methodTphs.contains(superTphRes) && (tphsInRel.size()-i) >0) {
|
||||
superTphRes = tphsInRel.get(tphsInRel.size()-i);
|
||||
i++;
|
||||
}
|
||||
// teste noch den Fall X < Y und Y nicht in TPHS der Methode
|
||||
// Dann hat man nach der While-Schleife X < Y
|
||||
// Y muss durch Object ersetzt.
|
||||
|
||||
// Zweite Operand für die Fälle wie in Lambda.jav (Paramtrisierte Typen)
|
||||
if(methodTphs.contains(superTphRes) || !tphExtractor.allTPHS.containsKey(superTphRes)) {
|
||||
GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes);
|
||||
simplifiedPairs.add(sPair);
|
||||
}
|
||||
}
|
||||
return simplifiedPairs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
paramsAndLocals = new HashMap<>();
|
||||
@ -475,5 +605,50 @@ public class BytecodeGen implements ASTVisitor {
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private class TPHExtractor extends AbstractASTWalker{
|
||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||
final HashMap<TypePlaceholder,Boolean> allTPHS = new HashMap<>();
|
||||
MethodAndTPH methodAndTph;
|
||||
Boolean inMethod = false;
|
||||
final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder tph) {
|
||||
if(resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||
if(inMethod)
|
||||
methodAndTph.getTphs().add(resolvedTPH);
|
||||
|
||||
allTPHS.put(resolvedTPH,inMethod);
|
||||
resultSet.resolveType(tph).additionalGenerics.forEach(ag ->{
|
||||
if(ag.contains(resolvedTPH)&&ag.TA1.equals(resolvedTPH)&&!contains(allPairs,ag)) {
|
||||
if(inMethod)
|
||||
methodAndTph.getPairs().add(ag);
|
||||
allPairs.add(ag);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||
for(int i=0; i<pairs.size();++i) {
|
||||
GenericInsertPair p = pairs.get(i);
|
||||
if(p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
methodAndTph = new MethodAndTPH(method.name);
|
||||
super.visit(method);
|
||||
inMethod = false;
|
||||
ListOfMethodsAndTph.add(methodAndTph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,15 +29,18 @@ import org.objectweb.asm.signature.SignatureWriter;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class BytecodeGenMethod implements StatementVisitor {
|
||||
@ -50,10 +53,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
private ClassWriter cw;
|
||||
private ResultSet resultSet;
|
||||
private boolean isInterface;
|
||||
HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String, String> genericsAndBounds;
|
||||
private boolean isBinaryExp = false;
|
||||
|
||||
private String superClass;
|
||||
private String path;
|
||||
private IStatement statement = null;
|
||||
|
||||
// for tests **
|
||||
@ -67,11 +71,12 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||
|
||||
public BytecodeGenMethod(String className, ResultSet resultSet, Method m, MethodVisitor mv,
|
||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||
|
||||
this.className = className;
|
||||
this.superClass = superClass;
|
||||
this.resultSet = resultSet;
|
||||
this.m = m;
|
||||
this.mv = mv;
|
||||
@ -81,19 +86,21 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
|
||||
this.path = path;
|
||||
|
||||
if (!isInterface)
|
||||
this.m.block.accept(this);
|
||||
|
||||
}
|
||||
|
||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||
|
||||
this.resultSet = resultSet;
|
||||
this.mv = mv;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
this.path = path;
|
||||
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
int i = indexOfFirstParamLam;
|
||||
@ -104,7 +111,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
lambdaExpression.methodBody.accept(this);
|
||||
}
|
||||
|
||||
|
||||
public void isBinary(boolean isBinary) {
|
||||
this.isBinaryExp =isBinary;
|
||||
}
|
||||
|
||||
private String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
@ -120,7 +131,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
public void visit(SuperCall superCall) {
|
||||
superCall.receiver.accept(this);
|
||||
superCall.arglist.accept(this);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), superCall.name, "()V",
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.superClass, superCall.name, "()V",
|
||||
isInterface);
|
||||
}
|
||||
|
||||
@ -167,6 +178,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
doBoxing(binaryType);
|
||||
isBinaryExp = false;
|
||||
}
|
||||
System.out.println("ASSIGN TYPE R: " + getResolvedType(assign.rightSide.getType()));
|
||||
String typeOfRightSide = getResolvedType(assign.rightSide.getType());
|
||||
if(typeOfRightSide.contains("<")) {
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, typeOfRightSide.substring(0, typeOfRightSide.indexOf('<')));
|
||||
}
|
||||
assign.lefSide.accept(this);
|
||||
|
||||
statement = null;
|
||||
@ -520,7 +536,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
methodName, arg3.toString(), null, null);
|
||||
|
||||
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||
classFiles);
|
||||
classFiles,this.path);
|
||||
|
||||
mvLambdaBody.visitMaxs(0, 0);
|
||||
mvLambdaBody.visitEnd();
|
||||
@ -561,7 +577,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
try {
|
||||
System.out.println("generating " + name + ".class file...");
|
||||
output = new FileOutputStream(
|
||||
new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" + name + ".class"));
|
||||
new File(path + name + ".class"));
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name + ".class file generated");
|
||||
@ -621,14 +637,30 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
|
||||
|
||||
//ClassLoader.getSystemClassLoader().loadClass(className).getMethod(name, parameterTypes)
|
||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
try {
|
||||
java.lang.reflect.Method[] methods = cl.loadClass("java.util.Vector").getMethods();
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
for(java.lang.reflect.Method m : methods) {
|
||||
System.out.println(m.getName() + " " + m.toGenericString()+ " ==> ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.arglist.accept(this);
|
||||
|
||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||
genericsAndBoundsMethod, genericsAndBounds);
|
||||
String mDesc = method.accept(new DescriptorToString(resultSet));
|
||||
|
||||
System.out.println("Methodcall Desc : " + mDesc);
|
||||
// is methodCall.receiver functional Interface)?
|
||||
if (varsFunInterface.contains(methodCall.receiver.getType())) {
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()), methodCall.name,
|
||||
@ -641,6 +673,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// if(!methodCall.getType().toString().equals("V")) {
|
||||
// mv.visitInsn(Opcodes.POP);
|
||||
// }
|
||||
if(isBinaryExp) {
|
||||
doUnboxing(getResolvedType(methodCall.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -799,7 +834,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock);
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
whileStmt.expr.accept(this);
|
||||
isBinaryExp = false;
|
||||
// isBinaryExp = false;
|
||||
statement = null;
|
||||
}
|
||||
|
||||
@ -1040,13 +1075,18 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
String var = assignLeftSide.localVar.name;
|
||||
if (!paramsAndLocals.containsKey(var)) {
|
||||
paramsAndLocals.put(var, index + 1);
|
||||
} else {
|
||||
paramsAndLocals.put(var, index);
|
||||
}
|
||||
|
||||
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.get(var));
|
||||
}
|
||||
|
||||
private class TPHEx extends AbstractASTWalker{
|
||||
// Liste enthält alle tph der Methode
|
||||
ArrayList<TypePlaceholder> allTPHS = new ArrayList<>();
|
||||
@Override
|
||||
public void visit(TypePlaceholder tph) {
|
||||
allTPHS.add(tph);
|
||||
}
|
||||
|
||||
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.size());
|
||||
// Debug:::
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class LoopStmt extends AStatement {
|
||||
|
||||
@Override
|
||||
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
||||
bytecodeGenMethod.isBinary(false);
|
||||
this.loopBlock.accept(bytecodeGenMethod);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.bytecode.descriptor;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||
@ -49,7 +51,8 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
// 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)+"$")+ ";";
|
||||
// Bound ist immer Object
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += "L"+resType+ ";";
|
||||
}
|
||||
@ -76,7 +79,8 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
}else {
|
||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||
desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += ")" + "L"+resType+ ";";
|
||||
}
|
||||
@ -119,9 +123,21 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
Iterator<FormalParameter> itr = lambdaExpression.getParams().iterator();
|
||||
while(itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
desc = desc + "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()) + ";";
|
||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + "L"+ d + ";";
|
||||
}
|
||||
}
|
||||
|
||||
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + ")"+"L"+retType+";";
|
||||
}
|
||||
desc = addReturnType(desc, lambdaExpression.getReturnType(), resultSet);
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -131,9 +147,22 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itr = samMethod.getArgumentList().iterator();
|
||||
while(itr.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||
desc = desc + "L"+resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc += "L"+ d + ";";
|
||||
|
||||
}
|
||||
}
|
||||
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc = desc + ")"+"L"+retType+";";
|
||||
}
|
||||
desc = desc + ")"+"L"+resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+";";
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -141,26 +170,34 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
public String visit(MethodFromMethodCall methodFromMethodCall) {
|
||||
String desc = "(";
|
||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||
String d = e.getType().acceptTV(new TypeToDescriptor());
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
|
||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
|
||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(d)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(d)) {
|
||||
desc += "L"+methodFromMethodCall.getGenericsAndBounds().get(d)+ ";";
|
||||
}else {
|
||||
desc += "L"+resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.toString().equals("void")) {
|
||||
String retType = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
System.out.println("DescriptorToString retType = " + retType);
|
||||
if(retType.equals("void")) {
|
||||
desc += ")V";
|
||||
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||
}else {
|
||||
String ret = resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(ret)) {
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(ret)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(ret)){
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(ret)+ ";";
|
||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBoundsMethod().get(retType)+ ";";
|
||||
}else if(methodFromMethodCall.getGenericsAndBounds().containsKey(retType)){
|
||||
desc += ")L"+methodFromMethodCall.getGenericsAndBounds().get(retType)+ ";";
|
||||
}else {
|
||||
desc += ")" + "L"+resultSet.resolveType(methodFromMethodCall.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
desc += ")" + "L"+retType+ ";";
|
||||
}
|
||||
}
|
||||
// desc = addReturnType(desc, methodFromMethodCall.getReturnType(), resultSet);
|
||||
|
@ -19,7 +19,9 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
||||
return superWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,6 +31,7 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
||||
return extendsWildcardType.getInnerType().toString().replace(".", "/");
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.bytecode.signature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -8,13 +9,19 @@ import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class Signature {
|
||||
@ -26,10 +33,13 @@ public class Signature {
|
||||
private Method method;
|
||||
private HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes;
|
||||
private ResultSet resultSet;
|
||||
private ArrayList<GenericInsertPair> commonPairs;
|
||||
private ArrayList<GenericInsertPair> methodPairs;
|
||||
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds) {
|
||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,ArrayList<GenericInsertPair> commonPairs) {
|
||||
this.classOrInterface = classOrInterface;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.commonPairs = commonPairs;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForClassOrInterface();
|
||||
}
|
||||
@ -42,12 +52,14 @@ public class Signature {
|
||||
createSignatureForConsOrMethod(this.constructor,true);
|
||||
}
|
||||
|
||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet) {
|
||||
public Signature(Method method, HashMap<String, String> genericsAndBoundsMethod,HashMap<String, String> genericsAndBounds,
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes, ResultSet resultSet, ArrayList<GenericInsertPair> methodPairs) {
|
||||
this.method = method;
|
||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||
this.genericsAndBounds = genericsAndBounds;
|
||||
this.methodParamsAndTypes = methodParamsAndTypes;
|
||||
this.resultSet = resultSet;
|
||||
this.methodPairs = methodPairs;
|
||||
sw = new SignatureWriter();
|
||||
createSignatureForConsOrMethod(this.method,false);
|
||||
}
|
||||
@ -92,27 +104,92 @@ public class Signature {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||
}
|
||||
|
||||
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
|
||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
if(ret.substring(0,4).equals("TPH ")) {
|
||||
String g = ret.substring(4)+"$";
|
||||
sw.visitFormalTypeParameter(g);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
String g = ret.substring(4,ret.length())+"$";
|
||||
if(genericsAndBounds.containsKey(g)) {
|
||||
genericsAndBoundsMethod.put(g, genericsAndBounds.get(g));
|
||||
}else {
|
||||
sw.visitFormalTypeParameter(g);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.contains("<")) {
|
||||
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
|
||||
if(hasTPHs(ref)) {
|
||||
createSignatureForParameterizedType(ref);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Parameters
|
||||
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();
|
||||
if(pT.substring(0,4).equals("TPH ")) {
|
||||
String gP = pT.substring(4,pT.length())+"$";
|
||||
if(!genericsAndBounds.containsKey(gP) && !genericsAndBoundsMethod.containsKey(gP)) {
|
||||
sw.visitFormalTypeParameter(gP);
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
boolean isTypeVar = false;
|
||||
for(GenericInsertPair pair : methodPairs) {
|
||||
if(pT.substring(4).equals(pair.TA1.getName())) {
|
||||
bound = pair.TA2.getName()+"$";
|
||||
isTypeVar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(isTypeVar) {
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
}else {
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
|
||||
genericsAndBoundsMethod.put(gP, bound);
|
||||
}
|
||||
}
|
||||
|
||||
if(pT.contains("<")) {
|
||||
RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
||||
if(hasTPHs(ref))
|
||||
createSignatureForParameterizedType(ref);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p:methodPairs) {
|
||||
String name = p.TA1.getName()+"$";
|
||||
if(!genericsAndBoundsMethod.containsKey(name)) {
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitTypeVariable(p.TA2.getName()+"$");
|
||||
genericsAndBoundsMethod.put(name, p.TA2.getName()+"$");
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
||||
|
||||
for(GenericInsertPair p : methodPairs) {
|
||||
types.add(p.TA1);
|
||||
superTypes.add(p.TA2);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : methodPairs) {
|
||||
String name = p.TA2.getName()+"$";
|
||||
if(!types.contains(p.TA2) && !genericsAndBoundsMethod.containsKey(name)) {
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBoundsMethod.put(name, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,21 +202,148 @@ 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);
|
||||
}
|
||||
// sw.visitEnd();
|
||||
}
|
||||
|
||||
private void createSignatureForParameterizedType(RefType ref) {
|
||||
ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
||||
allPairs.addAll(methodPairs);
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
||||
|
||||
HashMap<String, String> names = new HashMap<>();
|
||||
|
||||
for(GenericInsertPair pair : simplifiedPairs) {
|
||||
if(ref.getParaList().contains(pair.TA1)) {
|
||||
String sub = pair.TA1.getName()+"$";
|
||||
String superT = pair.TA2.getName()+"$";
|
||||
names.put(sub, superT);
|
||||
}
|
||||
}
|
||||
|
||||
for(String sub : names.keySet()) {
|
||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||
sw.visitFormalTypeParameter(sub);
|
||||
String bound = names.get(sub);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBoundsMethod.put(sub, bound);
|
||||
}
|
||||
}
|
||||
|
||||
for(String superT : names.values()) {
|
||||
if(!names.containsKey(superT)) {
|
||||
if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
||||
sw.visitFormalTypeParameter(superT);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p: ref.getParaList()) {
|
||||
if(p instanceof TypePlaceholder) {
|
||||
String name = ((TypePlaceholder) p).getName() + "$";
|
||||
if(!genericsAndBoundsMethod.containsKey(name) && !genericsAndBounds.containsKey(name)) {
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(name, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<GenericInsertPair> getAllPairs(RefType ref) {
|
||||
final ArrayList<GenericInsertPair> res = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resultSet.resolveType(p).resolvedType;
|
||||
if(resolved instanceof TypePlaceholder) {
|
||||
resultSet.resolveType(p).additionalGenerics.forEach(ag ->{
|
||||
if(!contains(res,ag)) {
|
||||
res.add(ag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||
for(int i=0; i<pairs.size();++i) {
|
||||
GenericInsertPair p = pairs.get(i);
|
||||
if(p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private ArrayList<GenericInsertPair> simplifyPairs(ArrayList<GenericInsertPair> allPairs) {
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>();
|
||||
|
||||
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
||||
for(GenericInsertPair p : allPairs) {
|
||||
subAndSuperTph.put(p.TA1, p.TA2);
|
||||
}
|
||||
|
||||
subAndSuperTph.forEach((k,v)->System.out.println(k.getName() + " || " + v.getName()));
|
||||
|
||||
int numOfVisitedPairs = 0;
|
||||
for(TypePlaceholder subTph: subAndSuperTph.keySet()) {
|
||||
|
||||
if(numOfVisitedPairs>=subAndSuperTph.size())
|
||||
break;
|
||||
|
||||
HashMap<Integer, TypePlaceholder> tphsInRel= new HashMap<>();
|
||||
|
||||
tphsInRel.put(tphsInRel.size(), subTph);
|
||||
TypePlaceholder superTph = subAndSuperTph.get(subTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
|
||||
numOfVisitedPairs++;
|
||||
|
||||
while(subAndSuperTph.containsKey(superTph)) {
|
||||
superTph = subAndSuperTph.get(superTph);
|
||||
tphsInRel.put(tphsInRel.size(), superTph);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
// Subtype
|
||||
TypePlaceholder subTphRes = tphsInRel.get(0);
|
||||
// Die größte Supertype
|
||||
TypePlaceholder superTphRes = tphsInRel.get(tphsInRel.size()-1);
|
||||
|
||||
|
||||
while(subAndSuperTph.containsValue(subTphRes)) {
|
||||
for(TypePlaceholder tph : subAndSuperTph.keySet()) {
|
||||
if(subAndSuperTph.get(tph).equals(subTphRes)) {
|
||||
subTphRes = tph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tphsInRel.put(0, subTphRes);
|
||||
numOfVisitedPairs++;
|
||||
}
|
||||
|
||||
subTphRes = tphsInRel.get(0);
|
||||
GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes);
|
||||
simplifiedPairs.add(sPair);
|
||||
}
|
||||
return simplifiedPairs;
|
||||
}
|
||||
|
||||
private boolean hasTPHs(RefType ref) {
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
if(resultSet.resolveType(p).resolvedType instanceof TypePlaceholder)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits parameter type or return type with {@link SignatureVisitor} to create
|
||||
* the method signature
|
||||
@ -194,7 +398,34 @@ public class Signature {
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBounds);
|
||||
}
|
||||
|
||||
if(!commonPairs.isEmpty()) {
|
||||
ArrayList<TypePlaceholder> types = new ArrayList<>();
|
||||
ArrayList<TypePlaceholder> superTypes = new ArrayList<>();
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
types.add(p.TA1);
|
||||
superTypes.add(p.TA2);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
String t = p.TA1.getName()+"$";
|
||||
String bound = p.TA2.getName()+"$";
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p : commonPairs) {
|
||||
if(!types.contains(p.TA2)) {
|
||||
String t = p.TA2.getName()+"$";
|
||||
String bound = Type.getInternalName(Object.class);
|
||||
sw.visitFormalTypeParameter(t);
|
||||
sw.visitClassBound().visitClassType(bound);
|
||||
genericsAndBounds.put(t, bound);
|
||||
sw.visitClassBound().visitEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
sw.visitSuperclass().visitClassType(classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()));;
|
||||
sw.visitEnd();
|
||||
}
|
||||
|
@ -22,7 +22,12 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
||||
while(it.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
||||
params += "L"+param.toString().replace(".", "/");
|
||||
if(param instanceof TypePlaceholder) {
|
||||
params += "T" + ((TypePlaceholder) param).getName() + "$";
|
||||
} else {
|
||||
params += "L"+param.toString().replace(".", "/");
|
||||
}
|
||||
|
||||
if(it.hasNext())params += ";";
|
||||
}
|
||||
params += ";>";
|
||||
|
29
src/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
Normal file
@ -0,0 +1,29 @@
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
|
||||
public class MethodAndTPH {
|
||||
|
||||
private String name;
|
||||
private final ArrayList<TypePlaceholder> tphs = new ArrayList<>();
|
||||
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||
|
||||
public MethodAndTPH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<TypePlaceholder> getTphs() {
|
||||
return tphs;
|
||||
}
|
||||
|
||||
public ArrayList<GenericInsertPair> getPairs(){
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,32 +1,15 @@
|
||||
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.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
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.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
@ -41,140 +24,245 @@ 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.distributeVariance;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||
|
||||
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(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||
this(sourceFile);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
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);
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for (File forSourceFile : sourceFiles.keySet())
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for(SourceFile sf : this.sourceFiles.values()) {
|
||||
allClasses.addAll(getAvailableClasses(sf));
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log"));
|
||||
logFile.write("FC:\\" + finiteClosure.toString()+"\n");
|
||||
for(SourceFile sf : this.sourceFiles.values()) {
|
||||
logFile.write(ASTTypePrinter.print(sf));
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||
// beachtet
|
||||
ClassOrInterface importedClass = ASTFactory
|
||||
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
public List<SolvedClass> strucTypeInference()
|
||||
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
|
||||
List<SolvedClass> solvedClasses = new ArrayList<>();
|
||||
for (SourceFile sourceFile : sourceFiles.values()) {
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
logFile.flush();
|
||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
//.collect(Collectors.toCollection(ArrayList::new))))
|
||||
System.out.println(xConsSet);
|
||||
Set<String> paraTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
||||
|
||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||
|
||||
|
||||
xConsSet = xConsSet.stream().map(x -> {
|
||||
//Hier muss ueberlegt werden, ob
|
||||
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
||||
// mit disableWildcardtable() werden.
|
||||
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
||||
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
||||
//PL 2018-04-23
|
||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||
}
|
||||
}
|
||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||
}
|
||||
}
|
||||
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
||||
}).map( y -> {
|
||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
||||
}
|
||||
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
||||
}
|
||||
}
|
||||
return y; } )
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
varianceInheritance(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result);
|
||||
logFile.write("RES: " + result.toString()+"\n");
|
||||
logFile.flush();
|
||||
results.addAll(result);
|
||||
}
|
||||
}
|
||||
catch (IOException e) { }
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints();
|
||||
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||
return results.stream().map((unifyPairs ->
|
||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Vererbt alle Variancen
|
||||
* @param eq The set of constraints
|
||||
*/
|
||||
private void varianceInheritance(Set<UnifyPair> eq) {
|
||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||
Set<PlaceholderType> pair = new HashSet<>();
|
||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
||||
return pair;
|
||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
||||
|
||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||
while(!phSetVariance.isEmpty()) {
|
||||
PlaceholderType a = phSetVariance.remove(0);
|
||||
usedTPH.add(a);
|
||||
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
||||
//ht.put(a, a.getVariance());
|
||||
Set<UnifyPair> eq1 = new HashSet<>(eq);
|
||||
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
||||
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
|
||||
eq1 = new HashSet<>(eq);
|
||||
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
||||
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
|
||||
phSetVariance = new ArrayList<>(phSet);
|
||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
||||
}
|
||||
}
|
||||
|
||||
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
|
||||
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
inferredTypes = construct.getInferredTypes();
|
||||
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;
|
||||
}
|
||||
|
||||
IFiniteClosure fc = UnifyTypeFactory.generateFC(this.getAvailableClasses(sourceFile));
|
||||
Solve solve = new Solve(subTypeConstraints, clsA, fc, inferredTypes, constructedInterfaces);
|
||||
SolvedClass solvedClass = solve.getSolvedClass();
|
||||
solvedClasses.add(solvedClass);
|
||||
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;
|
||||
}
|
||||
// um pfad erweitern
|
||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
|
||||
for(File f : sourceFiles.keySet()) {
|
||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||
SourceFile sf = sourceFiles.get(f);
|
||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,path);
|
||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||
bytecodeGen.visit(sf);
|
||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeClassFile(HashMap<String, byte[]> classFiles, String path) throws IOException {
|
||||
FileOutputStream output;
|
||||
for(String name : classFiles.keySet()) {
|
||||
byte[] bytecode = classFiles.get(name);
|
||||
System.out.println("generating "+name+ ".class file ...");
|
||||
//output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class"));
|
||||
output = new FileOutputStream(new File(path +name+".class"));
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name+".class file generated");
|
||||
}
|
||||
return solvedClasses;
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||
// FC
|
||||
for (SourceFile sf : this.sourceFiles.values()) {
|
||||
allClasses.addAll(getAvailableClasses(sf));
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result.size());
|
||||
results.addAll(result);
|
||||
}
|
||||
return results.stream()
|
||||
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons)))))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
if (p.TA1 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
||||
}
|
||||
if (p.TA2 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
|
||||
new GenericsRegistry(null));
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
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;
|
||||
@ -18,9 +17,4 @@ public class AssignToLocal extends AssignLeftSide {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToLocal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -427,9 +427,6 @@ 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);
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ 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;
|
||||
}
|
||||
|
||||
@ -91,7 +92,7 @@ public class TypeGenerator {
|
||||
return ret;
|
||||
}
|
||||
if(typeBoundContext.classOrInterfaceType() != null){
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType()));
|
||||
if(typeBoundContext.additionalBound() != null)
|
||||
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
|
||||
ret.add(convert(addCtx.interfaceType()));
|
||||
@ -102,9 +103,8 @@ public class TypeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
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.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
|
||||
@ -114,7 +114,8 @@ 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){
|
||||
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType();
|
||||
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -1,158 +0,0 @@
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
@ -1,182 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,503 +0,0 @@
|
||||
<?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>
|
@ -1,27 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
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());
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
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) + "]"));
|
||||
}
|
||||
}
|
@ -1,405 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
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);
|
||||
|
||||
}
|
@ -1,309 +0,0 @@
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,389 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,253 +0,0 @@
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
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) {
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -13,7 +12,6 @@ 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;
|
||||
@ -28,7 +26,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private RefType superClass;
|
||||
public boolean isInterface;
|
||||
protected boolean isInterface;
|
||||
private List<RefType> implementedInterfaces;
|
||||
private List<Constructor> constructors;
|
||||
|
||||
@ -36,7 +34,6 @@ 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;
|
||||
@ -105,13 +102,8 @@ 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 List<RefType> getSuperInterfaces() {
|
||||
public Collection<RefType> getSuperInterfaces() {
|
||||
return implementedInterfaces;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ 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;
|
||||
@ -36,9 +35,4 @@ public class Constructor extends Method {
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -41,10 +40,5 @@ public class Field extends SyntaxTreeNode implements TypeScope{
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -27,9 +26,4 @@ public class FormalParameter extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameter accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@ -23,10 +21,6 @@ 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() {
|
||||
@ -38,12 +32,6 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GenericDeclarationList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.gtvs.toString();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -62,9 +61,4 @@ public class GenericTypeVar extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericTypeVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -70,9 +69,4 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -41,9 +39,4 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ 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;
|
||||
@ -44,9 +43,4 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFile accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ 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;
|
||||
@ -21,6 +20,4 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
}
|
||||
|
||||
public abstract void accept(ASTVisitor visitor);
|
||||
|
||||
public abstract <T> T accept(ASTReturnVisitor visitor);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class UnifyTypeFactory {
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map<String,TypePlaceholder> tphs) {
|
||||
RefType ret = new RefType(new JavaClassName(t.getName()), convert(t.getTypeParams(), tphs), new NullToken());
|
||||
RefType ret = new RefType(new JavaClassName(t.getName()+"$$"), convert(t.getTypeParams(), tphs), new NullToken());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -31,9 +30,4 @@ public class ArgumentList extends SyntaxTreeNode
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
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;
|
||||
@ -27,9 +26,4 @@ public class Assign extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Assign accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
|
||||
public class AssignToField extends AssignLeftSide{
|
||||
@ -14,9 +13,4 @@ public class AssignToField extends AssignLeftSide{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToField accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +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;
|
||||
@ -12,11 +11,6 @@ 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, // +
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -29,11 +28,6 @@ public class Block extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -23,9 +22,4 @@ public class CastExpr extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
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;
|
||||
@ -16,9 +15,4 @@ public class DoStmt extends WhileStmt
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
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;
|
||||
@ -20,9 +19,4 @@ public class EmptyStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
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;
|
||||
@ -19,9 +18,4 @@ public class ExpressionReceiver extends Receiver
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionReceiver accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -29,9 +28,4 @@ public class FieldVar extends Expression {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -27,9 +26,4 @@ public class ForStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -28,9 +27,4 @@ public class IfStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
|
||||
@ -22,9 +21,4 @@ public class InstanceOf extends BinaryExpr
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceOf accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -40,9 +39,4 @@ public class LambdaExpression extends Expression implements TypeScope {
|
||||
//return type.getParaList().get(0);
|
||||
return methodBody.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaExpression accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -22,9 +21,4 @@ public class Literal extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Literal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
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;
|
||||
@ -25,9 +24,4 @@ public class LocalVar extends Statement{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ 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;
|
||||
@ -29,9 +28,4 @@ public class LocalVarDecl extends Statement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVarDecl accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -39,9 +38,4 @@ public class MethodCall extends Statement
|
||||
public ArgumentList getArgumentList() {
|
||||
return arglist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodCall accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
|
||||
public class NewArray extends Expression
|
||||
@ -22,9 +21,4 @@ public class NewArray extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewArray accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
@ -38,9 +37,4 @@ public class NewClass extends MethodCall
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewClass accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -19,9 +18,4 @@ public class Return extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Return accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -13,9 +12,4 @@ public class ReturnVoid extends Return{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnVoid accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -18,9 +17,4 @@ public class StaticClassName extends Receiver {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaticClassName accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
public class Super extends Expression
|
||||
{
|
||||
@ -19,9 +18,4 @@ public class Super extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Super accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|