forked from JavaTX/JavaCompilerCore
erste Assumptions eingefügt
This commit is contained in:
parent
dd5c8a56ad
commit
593bb74b12
5
src/de/dhbwstuttgart/strucTypes/AS_Abstract.java
Normal file
5
src/de/dhbwstuttgart/strucTypes/AS_Abstract.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
public class AS_Abstract {
|
||||
|
||||
}
|
28
src/de/dhbwstuttgart/strucTypes/AS_Argument.java
Normal file
28
src/de/dhbwstuttgart/strucTypes/AS_Argument.java
Normal file
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
public class AS_Argument extends AS_Abstract {
|
||||
|
||||
|
||||
FormalParameter fp;
|
||||
TV_Alpha tv_alpha;
|
||||
|
||||
|
||||
|
||||
public AS_Argument(FormalParameter fp, Integer index, Method method, ClassOrInterface cl) {
|
||||
super();
|
||||
this.fp = fp;
|
||||
this.tv_alpha = new TV_Alpha(method, index, cl, fp);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format("Assumption: { %s : %s } )" , fp.toString() , tv_alpha.toString() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
31
src/de/dhbwstuttgart/strucTypes/AS_Field.java
Normal file
31
src/de/dhbwstuttgart/strucTypes/AS_Field.java
Normal file
@ -0,0 +1,31 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
|
||||
public class AS_Field extends AS_Abstract {
|
||||
|
||||
private ClassOrInterface cl;
|
||||
private Field field;
|
||||
private TV_Field tv_field;
|
||||
|
||||
public AS_Field (ClassOrInterface cl, Field field) {
|
||||
super();
|
||||
this.cl = cl;
|
||||
this.field = field;
|
||||
|
||||
this.tv_field = new TV_Field(cl,field);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
String klname = cl.getClassName().toString();
|
||||
return String.format( "Assumption: { %s.%s : %s } " , klname, field.getName() , tv_field.toString() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
32
src/de/dhbwstuttgart/strucTypes/AS_Method.java
Normal file
32
src/de/dhbwstuttgart/strucTypes/AS_Method.java
Normal file
@ -0,0 +1,32 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
public class AS_Method extends AS_Abstract {
|
||||
|
||||
ClassOrInterface cl;
|
||||
Method method;
|
||||
TV_Method typvar;
|
||||
|
||||
|
||||
|
||||
public AS_Method (ClassOrInterface cl , Method method ) {
|
||||
super();
|
||||
this.cl = cl;
|
||||
this.method = method;
|
||||
|
||||
this.typvar = new TV_Method(cl,method);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Assumption: { " + cl.getClassName().toString() + "." + method.getName() + " : " + this.typvar.toString() + "}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
38
src/de/dhbwstuttgart/strucTypes/Construct.java
Normal file
38
src/de/dhbwstuttgart/strucTypes/Construct.java
Normal file
@ -0,0 +1,38 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
/*
|
||||
* Generating the Interfaces from the goods
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class Construct {
|
||||
|
||||
|
||||
|
||||
|
||||
public Construct(SourceFile sf, List<TC_Abstract> constraints ) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
5
src/de/dhbwstuttgart/strucTypes/TC_Abstract.java
Normal file
5
src/de/dhbwstuttgart/strucTypes/TC_Abstract.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
public class TC_Abstract {
|
||||
|
||||
}
|
49
src/de/dhbwstuttgart/strucTypes/TC_Field.java
Normal file
49
src/de/dhbwstuttgart/strucTypes/TC_Field.java
Normal file
@ -0,0 +1,49 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
|
||||
/* Formal Idea -> Implementation:
|
||||
*
|
||||
* Phi(c,f,c') = means c provides a field f with the type c'
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* Phi(A,f1,Integer)
|
||||
* Phi( class , field, type or typevariable)
|
||||
*
|
||||
* Idea Implementation -> Use object - reference
|
||||
*
|
||||
* Phi( Class , Field , typevariable of Field f )
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public class TC_Field extends TC_Abstract {
|
||||
|
||||
// Not completely implemented
|
||||
private ClassOrInterface cl;
|
||||
private Field field;
|
||||
|
||||
|
||||
/*
|
||||
* here the type(variable) has to be supplemented
|
||||
*/
|
||||
public TC_Field (ClassOrInterface cl , Field field ) {
|
||||
this.cl = cl;
|
||||
this.field = field;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String toString () {
|
||||
return "Phi( " + cl.getClassName().toString() + "," + field.getName().toString() + "," + "Typvariable?" + ")";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
39
src/de/dhbwstuttgart/strucTypes/TC_Method.java
Normal file
39
src/de/dhbwstuttgart/strucTypes/TC_Method.java
Normal file
@ -0,0 +1,39 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
/* Formal Idea:
|
||||
*
|
||||
* Mue( c , m , c` , (c`, c_all ))
|
||||
* means c provides a method m applicable to the arguments of type c, with return type c' and parameters of type c
|
||||
*
|
||||
* Mue( class , method or methodname , Arguments[] , ( B , Parameters [] )
|
||||
*
|
||||
*/
|
||||
|
||||
public class TC_Method extends TC_Abstract {
|
||||
|
||||
// Not completely implemented in the moment
|
||||
private ClassOrInterface cl;
|
||||
private Method method;
|
||||
|
||||
|
||||
public TC_Method(ClassOrInterface cl, Method method ) {
|
||||
super();
|
||||
this.cl = cl;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
|
||||
|
||||
|
||||
return "Mue( " + cl.getClassName().toString() + "," + method.getName() + "...)" ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
20
src/de/dhbwstuttgart/strucTypes/TI.java
Normal file
20
src/de/dhbwstuttgart/strucTypes/TI.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
public class TI {
|
||||
|
||||
|
||||
public TI (Object assumptions, SourceFile sf ) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
5
src/de/dhbwstuttgart/strucTypes/TV_Abstract.java
Normal file
5
src/de/dhbwstuttgart/strucTypes/TV_Abstract.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
public class TV_Abstract {
|
||||
|
||||
}
|
39
src/de/dhbwstuttgart/strucTypes/TV_Alpha.java
Normal file
39
src/de/dhbwstuttgart/strucTypes/TV_Alpha.java
Normal file
@ -0,0 +1,39 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
public class TV_Alpha extends TV_Abstract {
|
||||
|
||||
|
||||
Method method;
|
||||
Integer index;
|
||||
ClassOrInterface cl;
|
||||
|
||||
// Nicht direkt gefordert...
|
||||
FormalParameter fp;
|
||||
|
||||
|
||||
public TV_Alpha( Method method, Integer index , ClassOrInterface cl , FormalParameter fp ) {
|
||||
super();
|
||||
this.method = method;
|
||||
this.index = index;
|
||||
this.cl = cl;
|
||||
this.fp = fp;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
// Ausgabe Alpha( Methodenname , Index, Klasse)
|
||||
return String.format("Alpha( %s , %s , %s) " , method.getName() , index.toString() , cl.getClassName().toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
30
src/de/dhbwstuttgart/strucTypes/TV_Field.java
Normal file
30
src/de/dhbwstuttgart/strucTypes/TV_Field.java
Normal file
@ -0,0 +1,30 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
|
||||
public class TV_Field extends TV_Abstract{
|
||||
|
||||
|
||||
ClassOrInterface cl;
|
||||
Field f;
|
||||
|
||||
|
||||
|
||||
public TV_Field (ClassOrInterface cl , Field f ) {
|
||||
super();
|
||||
this.cl = cl;
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format("Delta( %s , %s )", f.getName() , cl.getClassName().toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
28
src/de/dhbwstuttgart/strucTypes/TV_Gamma.java
Normal file
28
src/de/dhbwstuttgart/strucTypes/TV_Gamma.java
Normal file
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
public class TV_Gamma extends TV_Abstract {
|
||||
|
||||
|
||||
Method method;
|
||||
ClassOrInterface cl;
|
||||
|
||||
public TV_Gamma(Method method, ClassOrInterface cl) {
|
||||
super();
|
||||
this.method = method;
|
||||
this.cl = cl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format("Gamma( %s , %s ) " , method.getName() , cl.getClassName().toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
57
src/de/dhbwstuttgart/strucTypes/TV_Method.java
Normal file
57
src/de/dhbwstuttgart/strucTypes/TV_Method.java
Normal file
@ -0,0 +1,57 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
public class TV_Method extends TV_Abstract {
|
||||
|
||||
ClassOrInterface cl;
|
||||
Method method;
|
||||
|
||||
List<TV_Alpha> alpha_strich;
|
||||
TV_Gamma tv_gamma;
|
||||
|
||||
public TV_Method(ClassOrInterface cl, Method method ) {
|
||||
super();
|
||||
this.cl = cl;
|
||||
this.method = method;
|
||||
|
||||
// Typvariablen Parameter
|
||||
this.alpha_strich = new ArrayList<TV_Alpha>();
|
||||
|
||||
|
||||
for (int i = 0; i < method.parameterlist.formalparameter.size(); i++ ) {
|
||||
FormalParameter fp = method.parameterlist.formalparameter.get(i);
|
||||
TV_Alpha tv_alpha = new TV_Alpha(method, i , cl, fp);
|
||||
this.alpha_strich.add(tv_alpha);
|
||||
}
|
||||
|
||||
|
||||
// Returntyp
|
||||
this.tv_gamma = new TV_Gamma(method, cl);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
|
||||
String typvarpar = "";
|
||||
for (TV_Alpha tv : this.alpha_strich ) {
|
||||
typvarpar = typvarpar + tv.toString();
|
||||
}
|
||||
// TODO : Ausgabe Return type
|
||||
// Ausgabe TV_Method( parametertypevar -> returntype)
|
||||
return String.format("( %s -> %s )" , typvarpar, this.tv_gamma.toString() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
5
src/de/dhbwstuttgart/strucTypes/TV_Typ.java
Normal file
5
src/de/dhbwstuttgart/strucTypes/TV_Typ.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
public class TV_Typ {
|
||||
|
||||
}
|
120
src/de/dhbwstuttgart/strucTypes/Type.java
Normal file
120
src/de/dhbwstuttgart/strucTypes/Type.java
Normal file
@ -0,0 +1,120 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
public class Type {
|
||||
|
||||
|
||||
|
||||
private Object result_cl_t;
|
||||
private List<TC_Abstract> result_constraint_set;
|
||||
|
||||
|
||||
public Type(List<AS_Abstract> ass, SourceFile sf) {
|
||||
|
||||
this.result_constraint_set = new ArrayList<TC_Abstract>();
|
||||
|
||||
// =:fass
|
||||
List<AS_Field> fass = make_field_assumptions(sf);
|
||||
|
||||
// =: mass
|
||||
List<AS_Method> mass = make_method_assumptions(sf);
|
||||
|
||||
// -> AssAll = ass + fass + mass
|
||||
List<AS_Abstract> assAll = new ArrayList<AS_Abstract>();
|
||||
assAll.addAll(fass);
|
||||
assAll.addAll(mass);
|
||||
assAll.addAll(ass);
|
||||
// TODO: AssAll + this: A für die aktuelle Klasse
|
||||
|
||||
|
||||
//Beispielhafte Ausgabe der Assumptions
|
||||
for (AS_Abstract as : assAll ) {
|
||||
System.out.println(as.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// für alle Methoden der Klasse
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TypeExpression muss noch ausgeführt werden
|
||||
// TypeExpression (insert Types and collects corrospending constraints)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// fass
|
||||
private List<AS_Field> make_field_assumptions(SourceFile sf) {
|
||||
|
||||
List<AS_Field> fass = new ArrayList<AS_Field>();
|
||||
|
||||
for (ClassOrInterface cl : sf.KlassenVektor ) {
|
||||
for (Field f : cl.getFieldDecl() ) {
|
||||
AS_Field as_f = new AS_Field(cl, f) ;
|
||||
fass.add(as_f);
|
||||
}
|
||||
}
|
||||
return fass;
|
||||
}
|
||||
|
||||
// mass
|
||||
private List<AS_Method> make_method_assumptions(SourceFile sf) {
|
||||
|
||||
List<AS_Method> mass = new ArrayList<AS_Method>();
|
||||
|
||||
for(ClassOrInterface cl : sf.KlassenVektor) {
|
||||
for(Method m : cl.getMethods() ) {
|
||||
AS_Method as_m = new AS_Method(cl,m);
|
||||
mass.add(as_m);
|
||||
}
|
||||
}
|
||||
return mass;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TypeExpression
|
||||
|
||||
|
||||
|
||||
|
||||
// Gettermethoden
|
||||
public Object getResult_cl_t() {
|
||||
return result_cl_t;
|
||||
}
|
||||
|
||||
|
||||
public List<TC_Abstract> getResult_constraint_set() {
|
||||
return result_constraint_set;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -7,6 +7,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.strucTypes.AS_Abstract;
|
||||
import de.dhbwstuttgart.strucTypes.TC_Abstract;
|
||||
import de.dhbwstuttgart.strucTypes.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -35,18 +38,30 @@ public class GeneralParserTest{
|
||||
//filenames.add("BoundedParameter.jav");
|
||||
//filenames.add("GenericFieldVarTest.jav");
|
||||
//filenames.add("FieldVarTest.jav");
|
||||
|
||||
//filenames.add("StructuralTypesField.jav");
|
||||
filenames.add("StructuralTypesSimple.jav");
|
||||
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
try{
|
||||
for(String filename : filenames) {
|
||||
System.out.println("Teste: "+filename);
|
||||
|
||||
System.out.println("Teste: "+ filename);
|
||||
|
||||
SourceFile sf = parser.parse(new File(rootDirectory + filename));
|
||||
|
||||
//sf.TypeAlgo();
|
||||
SourceFile sfdebug = sf;
|
||||
|
||||
List<AS_Abstract> ass = new ArrayList<AS_Abstract>();
|
||||
Type type = new Type( ass , sf);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//SourceFile sfdebug = sf;
|
||||
|
||||
//TODO: Test ANTLR Parser
|
||||
}
|
||||
}catch(Exception exc){
|
||||
exc.printStackTrace();
|
||||
|
7
test/strucTypes/StructuralTypesField.jav
Normal file
7
test/strucTypes/StructuralTypesField.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class A {
|
||||
|
||||
das_feld_1;
|
||||
|
||||
das_feld_2;
|
||||
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
|
||||
class A {
|
||||
|
||||
A f1;
|
||||
|
||||
A f2;
|
||||
|
||||
|
||||
mt4(a,b,c) { return a.add(b).sub(c) ; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user