diff --git a/src/de/dhbwstuttgart/strucTypes/AS_Abstract.java b/src/de/dhbwstuttgart/strucTypes/AS_Abstract.java new file mode 100644 index 00000000..b7e0bd28 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/AS_Abstract.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.strucTypes; + +public class AS_Abstract { + +} diff --git a/src/de/dhbwstuttgart/strucTypes/AS_Argument.java b/src/de/dhbwstuttgart/strucTypes/AS_Argument.java new file mode 100644 index 00000000..69ff723a --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/AS_Argument.java @@ -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() ); + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/AS_Field.java b/src/de/dhbwstuttgart/strucTypes/AS_Field.java new file mode 100644 index 00000000..1a0c32b2 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/AS_Field.java @@ -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() ); + } + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/AS_Method.java b/src/de/dhbwstuttgart/strucTypes/AS_Method.java new file mode 100644 index 00000000..aa0cf702 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/AS_Method.java @@ -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() + "}"; + } + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/Construct.java b/src/de/dhbwstuttgart/strucTypes/Construct.java new file mode 100644 index 00000000..80773969 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/Construct.java @@ -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 constraints ) { + + + + + + + + } + + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TC_Abstract.java b/src/de/dhbwstuttgart/strucTypes/TC_Abstract.java new file mode 100644 index 00000000..4e1068b3 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TC_Abstract.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.strucTypes; + +public class TC_Abstract { + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TC_Field.java b/src/de/dhbwstuttgart/strucTypes/TC_Field.java new file mode 100644 index 00000000..a5ed5c1f --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TC_Field.java @@ -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?" + ")"; + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TC_Method.java b/src/de/dhbwstuttgart/strucTypes/TC_Method.java new file mode 100644 index 00000000..55e9edbb --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TC_Method.java @@ -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() + "...)" ; + } + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TI.java b/src/de/dhbwstuttgart/strucTypes/TI.java new file mode 100644 index 00000000..6238eab4 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TI.java @@ -0,0 +1,20 @@ +package de.dhbwstuttgart.strucTypes; + +import de.dhbwstuttgart.syntaxtree.SourceFile; + +public class TI { + + + public TI (Object assumptions, SourceFile sf ) { + + + + + } + + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TV_Abstract.java b/src/de/dhbwstuttgart/strucTypes/TV_Abstract.java new file mode 100644 index 00000000..7ad1c043 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TV_Abstract.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.strucTypes; + +public class TV_Abstract { + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TV_Alpha.java b/src/de/dhbwstuttgart/strucTypes/TV_Alpha.java new file mode 100644 index 00000000..676af54a --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TV_Alpha.java @@ -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()); + } + + + + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TV_Field.java b/src/de/dhbwstuttgart/strucTypes/TV_Field.java new file mode 100644 index 00000000..22335e9e --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TV_Field.java @@ -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()); + } + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TV_Gamma.java b/src/de/dhbwstuttgart/strucTypes/TV_Gamma.java new file mode 100644 index 00000000..188719f9 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TV_Gamma.java @@ -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()); + } + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TV_Method.java b/src/de/dhbwstuttgart/strucTypes/TV_Method.java new file mode 100644 index 00000000..d7a9a792 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TV_Method.java @@ -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 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(); + + + 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() ); + } + + + + + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes/TV_Typ.java b/src/de/dhbwstuttgart/strucTypes/TV_Typ.java new file mode 100644 index 00000000..ad82967a --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/TV_Typ.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.strucTypes; + +public class TV_Typ { + +} diff --git a/src/de/dhbwstuttgart/strucTypes/Type.java b/src/de/dhbwstuttgart/strucTypes/Type.java new file mode 100644 index 00000000..c4c12dd8 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/Type.java @@ -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 result_constraint_set; + + + public Type(List ass, SourceFile sf) { + + this.result_constraint_set = new ArrayList(); + + // =:fass + List fass = make_field_assumptions(sf); + + // =: mass + List mass = make_method_assumptions(sf); + + // -> AssAll = ass + fass + mass + List assAll = new ArrayList(); + 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 make_field_assumptions(SourceFile sf) { + + List fass = new ArrayList(); + + 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 make_method_assumptions(SourceFile sf) { + + List mass = new ArrayList(); + + 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 getResult_constraint_set() { + return result_constraint_set; + } + + + + + + + + + + + + + + + + + +} diff --git a/test/strucTypes/GeneralParserTest.java b/test/strucTypes/GeneralParserTest.java index a365ccdc..b8603254 100644 --- a/test/strucTypes/GeneralParserTest.java +++ b/test/strucTypes/GeneralParserTest.java @@ -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 ass = new ArrayList(); + Type type = new Type( ass , sf); + + + + + + - //SourceFile sfdebug = sf; - //TODO: Test ANTLR Parser } }catch(Exception exc){ exc.printStackTrace(); diff --git a/test/strucTypes/StructuralTypesField.jav b/test/strucTypes/StructuralTypesField.jav new file mode 100644 index 00000000..a4d5c1eb --- /dev/null +++ b/test/strucTypes/StructuralTypesField.jav @@ -0,0 +1,7 @@ +class A { + +das_feld_1; + +das_feld_2; + +} diff --git a/test/strucTypes/StructuralTypesSimple.jav b/test/strucTypes/StructuralTypesSimple.jav index 4c6b399e..52edef03 100644 --- a/test/strucTypes/StructuralTypesSimple.jav +++ b/test/strucTypes/StructuralTypesSimple.jav @@ -1,6 +1,10 @@ class A { + A f1; + + A f2; + mt4(a,b,c) { return a.add(b).sub(c) ; }