forked from JavaTX/JavaCompilerCore
Type Constraints angepasst
This commit is contained in:
parent
b0ef4aecd6
commit
cccc9f4d49
@ -43,6 +43,25 @@ public class AS_Abstract {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static AS_Argument find_AS_Argument(FormalParameter f, Method m , List<AS_Abstract> ass ) {
|
||||
AS_Argument res = null;
|
||||
|
||||
for (AS_Abstract as : ass) {
|
||||
if ( as.getClass().equals(AS_Argument.class) ) {
|
||||
AS_Argument asa = (AS_Argument) as;
|
||||
if (f == asa.fp) {
|
||||
if (asa.tv_alpha.method == m) {
|
||||
res = asa;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static AS_Argument find_AS_Argument_by_Name(String name, List<AS_Abstract> ass ) {
|
||||
|
||||
// if
|
||||
|
@ -6,7 +6,9 @@ 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 Algo_Type {
|
||||
|
||||
@ -61,7 +63,7 @@ public class Algo_Type {
|
||||
}
|
||||
|
||||
// ASS = AssAll vereinigt mit ass_arguments (wird oben erledigt)
|
||||
//-> assAll.addAll(ass_arguments);
|
||||
|
||||
|
||||
|
||||
// (Test) Beispielhafte Ausgabe der Assumptions
|
||||
@ -84,11 +86,7 @@ public class Algo_Type {
|
||||
// Hier ist ein Fehler -> der Contraint bezieht sich auf die Expression
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -121,10 +119,6 @@ public class Algo_Type {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Gettermethoden
|
||||
public Object getResult_cl_t() {
|
||||
return result_cl_t;
|
||||
|
@ -3,8 +3,6 @@ package de.dhbwstuttgart.strucTypes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Receiver;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
@ -13,339 +11,324 @@ import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
|
||||
public class Algo_TypeExpr {
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Hier sind die Ergebnisse
|
||||
*
|
||||
*
|
||||
*/
|
||||
// Ergebnisse: Expression Typed und Constraint-Set
|
||||
List<TC_Abstract> res_constriant_set;
|
||||
//TODO Hier muss noch ein passendes Datenformat gefunden werden
|
||||
String res_expression_typed;
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
// Ergebnisse: Expression Typed und Constraint-Set
|
||||
List<TC_Abstract> res_constriant_set;
|
||||
// TODO Hier muss noch ein passendes Datenformat gefunden werden
|
||||
String res_expression_typed;
|
||||
|
||||
public Algo_TypeExpr() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// übergabe der assumptions und der Statments der Methode
|
||||
public Algo_TypeExpr(List<AS_Abstract> ass , List<Statement> statements ) {
|
||||
|
||||
this.res_constriant_set = new ArrayList<TC_Abstract>();
|
||||
res_expression_typed = "";
|
||||
|
||||
|
||||
|
||||
public Algo_TypeExpr(List<AS_Abstract> ass, List<Statement> statements) {
|
||||
|
||||
this.res_constriant_set = new ArrayList<TC_Abstract>();
|
||||
res_expression_typed = "";
|
||||
|
||||
// Methode enthält kein Statement
|
||||
if (statements.size() == 0 ) {
|
||||
if (statements.size() == 0) {
|
||||
System.out.println("Not Implemmented");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Methode enthält nur ein Return Statement das ein feld zurückgibt
|
||||
if (statements.size() == 1) {
|
||||
if (statements.get(0).getClass().equals(Return.class)) {
|
||||
Return exp_rt = (Return) statements.get(0);
|
||||
if (exp_rt.get_Expression().getClass().equals(LocalVar.class )) {
|
||||
if (statements.get(0).getClass().equals(Return.class)) {
|
||||
Return exp_rt = (Return) statements.get(0);
|
||||
if (exp_rt.get_Expression().getClass().equals(LocalVar.class)) {
|
||||
LocalVar lvar = (LocalVar) exp_rt.get_Expression();
|
||||
|
||||
String feldname = lvar.get_expression();
|
||||
|
||||
|
||||
String feldname = lvar.get_expression();
|
||||
|
||||
for (AS_Abstract as : ass) {
|
||||
if (as.getClass().equals(AS_Argument.class)) {
|
||||
AS_Argument as_arg = (AS_Argument) as;
|
||||
AS_Argument as_arg = (AS_Argument) as;
|
||||
if (as_arg.fp.getName().equals(feldname)) {
|
||||
res_expression_typed = feldname + " : " + as_arg.tv_alpha.toString();
|
||||
// res_constraint_set
|
||||
}
|
||||
// res_constraint_set
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Methode nur ein Return statment das ein feld zurückgibt und eine Methode aufruft
|
||||
|
||||
|
||||
//-> Es muss so sein dass ich diese Return Statement beurteilen kann
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Methode nur ein Return statment das ein feld zurückgibt und eine
|
||||
// Methode aufruft
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Methode generiert Quellcode aus einer Methode
|
||||
* Letztendlich wird in der Methode der gesamte Datentyp durchwandert und erstellt
|
||||
* Nach dem selben Schema muss auch die generierung der Constriants erfolgen:
|
||||
*/
|
||||
public static String expression2code(List<AS_Abstract> ass , List<Statement> statements ) {
|
||||
String res = "";
|
||||
|
||||
// Leere methode
|
||||
* Methode generiert Quellcode aus einer Methode Letztendlich wird in der
|
||||
* Methode der gesamte Datentyp durchwandert und erstellt Nach dem selben
|
||||
* Schema muss auch die generierung der Constriants erfolgen:
|
||||
*/
|
||||
public static String expression2code(List<AS_Abstract> ass, List<Statement> statements) {
|
||||
String res = "";
|
||||
|
||||
// Leere methode
|
||||
if (statements.size() == 0) {
|
||||
res = "---";
|
||||
res = "---";
|
||||
}
|
||||
|
||||
// Methode mit einer Return Expression
|
||||
|
||||
// Methode mit einer Return Expression
|
||||
if (statements.size() == 1) {
|
||||
if (statements.get(0).getClass() == Return.class) {
|
||||
Return ret = (Return) statements.get(0);
|
||||
Statement ret2 = (Statement) ret.get_Expression();
|
||||
res = statement2code(ass,ret2);
|
||||
}
|
||||
}
|
||||
Return ret = (Return) statements.get(0);
|
||||
if (ret.getClass().equals(Statement.class)) {
|
||||
Statement ret2 = (Statement) ret.get_Expression();
|
||||
res = statement2code(ass, ret2);
|
||||
} else if (ret.getClass().equals(FieldVar.class)) {
|
||||
|
||||
// Neu Implementiert - funktioniert es ??
|
||||
Expression ex = (Expression) ret;
|
||||
FieldVar fvar = (FieldVar) ex;
|
||||
|
||||
String exp_str = fvar.getFieldVarName();
|
||||
|
||||
// Statement Cast evtl. problematisch
|
||||
List<Statement> liste = new ArrayList<Statement>();
|
||||
liste.add((Statement) fvar.receiver);
|
||||
String reciever_str = expression2code(ass, liste);
|
||||
|
||||
return reciever_str + "." + exp_str;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static String statement2code(List<AS_Abstract> ass , Statement statement) {
|
||||
|
||||
|
||||
public static String statement2code(List<AS_Abstract> ass, Statement statement) {
|
||||
|
||||
// TODO: Else if
|
||||
|
||||
if ( statement.getClass().equals(LocalVar.class) ) {
|
||||
|
||||
if (statement.getClass().equals(LocalVar.class)) {
|
||||
LocalVar lvar = (LocalVar) statement;
|
||||
String exp_str = lvar.get_expression();
|
||||
String exp_str = lvar.get_expression();
|
||||
return exp_str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// fieldvar muss ausgelagert werden weil es von Expression ableitett
|
||||
if (statement.getClass().equals(FieldVar.class)) {
|
||||
// FieldVar ist nicht implementiert
|
||||
// Neu Implementiert - funktioniert es ??
|
||||
Expression ex = (Expression) statement;
|
||||
FieldVar fvar = (FieldVar) ex;
|
||||
|
||||
String exp_str = fvar.getFieldVarName();
|
||||
|
||||
// Statement Cast evtl. problematisch
|
||||
String reciever_str = statement2code(ass, (Statement) fvar.receiver);
|
||||
|
||||
return reciever_str + "." + exp_str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (statement.getClass().equals(MethodCall.class)) {
|
||||
MethodCall mtcall = (MethodCall) statement;
|
||||
Statement receiver = (Statement) mtcall.get_Receiver().get_Expression();
|
||||
String str = statement2code(ass,receiver);
|
||||
MethodCall mtcall = (MethodCall) statement;
|
||||
Statement receiver = (Statement) mtcall.get_Receiver().get_Expression();
|
||||
String str = statement2code(ass, receiver);
|
||||
ArgumentList list = mtcall.get_ArgList();
|
||||
String arg_str = "";
|
||||
String arg_str = "";
|
||||
for (Expression exp : list.getArguments()) {
|
||||
// TODO Cast evtl ist falsch
|
||||
Statement st = (Statement) exp;
|
||||
arg_str = arg_str + statement2code(ass,st);
|
||||
Statement st = (Statement) exp;
|
||||
arg_str = arg_str + statement2code(ass, st);
|
||||
}
|
||||
// Todo Implementing Types:
|
||||
return str + "."+ mtcall.get_Name() + "( " + arg_str + " )";
|
||||
}
|
||||
return "Fehler";
|
||||
// Todo Implementing Types:
|
||||
return str + "." + mtcall.get_Name() + "( " + arg_str + " )";
|
||||
}
|
||||
return "Fehler";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<TC_Abstract> generate(List<AS_Abstract> ass, List<Statement> exp) {
|
||||
|
||||
|
||||
// Methoden enhält keine Statements
|
||||
if (exp.size() == 0) {
|
||||
this.res_constriant_set = null;
|
||||
this.res_expression_typed = null;
|
||||
this.res_constriant_set = null;
|
||||
this.res_expression_typed = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Methoden enthält ein Return Statement
|
||||
if (exp.size() == 1) {
|
||||
Statement std = (Statement) exp.get(0);
|
||||
Statement std = (Statement) exp.get(0);
|
||||
if (std.getClass() == Return.class) {
|
||||
Return ret = (Return) std;
|
||||
generate_return(ass, ret);
|
||||
Return ret = (Return) std;
|
||||
generate_return(ass, ret);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<TC_Abstract> generate_return(List<AS_Abstract> ass, Return ret) {
|
||||
|
||||
|
||||
Expression exp = ret.get_Expression();
|
||||
|
||||
|
||||
|
||||
if (exp.getClass() == LocalVar.class) {
|
||||
LocalVar lvar = (LocalVar) exp;
|
||||
// TODO wie soll ich hier mit der Language umgehen
|
||||
return new ArrayList<TC_Abstract>();
|
||||
}
|
||||
|
||||
|
||||
if (exp.getClass() == FieldVar.class) {
|
||||
|
||||
return new ArrayList<TC_Abstract>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (exp.getClass() == FieldVar.class) {
|
||||
// Hier kommt der Constraint für die Field Var hinein.
|
||||
|
||||
}
|
||||
|
||||
if (exp.getClass() == MethodCall.class) {
|
||||
MethodCall mt_call = (MethodCall) exp;
|
||||
|
||||
MethodCall mt_call = (MethodCall) exp;
|
||||
|
||||
// Constraint
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<TC_Abstract> getRes_constriant_set() {
|
||||
return res_constriant_set;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getRes_expression_typed() {
|
||||
return res_expression_typed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Neuer Versuch mit neuer herangehensweise um den Typen zu berechnen
|
||||
/*
|
||||
* Es werden die Typen der Methoden berechnet und als String ausgegeben
|
||||
*/
|
||||
public static TV_Abstract get_rt_Type_of(Expression o, List<AS_Abstract> ass) {
|
||||
|
||||
|
||||
if (o.getClass().equals(LocalVar.class)) {
|
||||
LocalVar v = (LocalVar) o;
|
||||
return get_rt_Type_of_LocalVar(v, ass);
|
||||
LocalVar v = (LocalVar) o;
|
||||
return get_rt_Type_of_LocalVar(v, ass);
|
||||
} else if (o.getClass().equals(MethodCall.class)) {
|
||||
MethodCall m_call = (MethodCall) o;
|
||||
return get_rt_Type_of_MethodCall(m_call, ass);
|
||||
} else if (o.getClass().equals(FieldVar.class)) {
|
||||
FieldVar fvar = (FieldVar) o;
|
||||
String type_fvar = get_rt_Type_of_FieldVar(fvar, ass);
|
||||
return new TV_Dummy(type_fvar);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
else if (o.getClass().equals(MethodCall.class)) {
|
||||
MethodCall m_call = (MethodCall) o;
|
||||
return get_rt_Type_of_MethodCall(m_call, ass);
|
||||
}
|
||||
else if (o.getClass().equals(FieldVar.class)){
|
||||
// FieldVar ist noch nicht implementiert
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static TV_Alpha get_rt_Type_of_LocalVar(LocalVar v, List<AS_Abstract> ass) {
|
||||
AS_Argument arg = AS_Abstract.find_AS_Argument_by_Name(v.get_expression(), ass);
|
||||
return arg.tv_alpha;
|
||||
AS_Argument arg = AS_Abstract.find_AS_Argument_by_Name(v.get_expression(), ass);
|
||||
return arg.tv_alpha;
|
||||
}
|
||||
|
||||
|
||||
public static TV_ReturnType2 get_rt_Type_of_MethodCall(MethodCall mt_call, List<AS_Abstract> ass) {
|
||||
TV_Abstract tv_receiver = get_rt_Type_of(mt_call.get_Receiver().get_Expression(), ass);
|
||||
TV_ReturnType2 res = new TV_ReturnType2(mt_call.get_Name(), tv_receiver.toString() );
|
||||
return res;
|
||||
|
||||
public static TV_ReturnType2 get_rt_Type_of_MethodCall(MethodCall mt_call, List<AS_Abstract> ass) {
|
||||
TV_Abstract tv_receiver = get_rt_Type_of(mt_call.get_Receiver().get_Expression(), ass);
|
||||
TV_ReturnType2 res = new TV_ReturnType2(mt_call.get_Name(), tv_receiver.toString());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static String get_rt_Type_of_FieldVar(FieldVar fvar, List<AS_Abstract> ass) {
|
||||
|
||||
TV_Abstract exp = get_rt_Type_of(fvar.getReceiver(), ass);
|
||||
|
||||
return "DeltaXXX ( " + fvar.getFieldVarName() + "," + exp.toString() + ")";
|
||||
}
|
||||
|
||||
// Neuer Versuch eine Methode berechneten Typen auszugeben
|
||||
public static String get_Return_typed(Method m, List<AS_Abstract> ass) {
|
||||
Return r = (Return) m.get_Block().statements.get(0);
|
||||
Expression ex = r.get_Expression();
|
||||
return get_rt_Type_of(ex,ass).toString();
|
||||
public static String get_Return_typed(Method m, List<AS_Abstract> ass) {
|
||||
Return r = (Return) m.get_Block().statements.get(0);
|
||||
Expression ex = r.get_Expression();
|
||||
return get_rt_Type_of(ex, ass).toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Erstellen der Constraints.
|
||||
// Erstellen der Constraints.
|
||||
// Auch dieses erstellen muss Rekursiv erfolgen
|
||||
// -------------------------------
|
||||
|
||||
public static List<TC_Abstract> generateConstraint(ClassOrInterface cl, List<AS_Abstract> ass ) {
|
||||
List<TC_Abstract> result = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
public static List<TC_Abstract> generateConstraint(ClassOrInterface cl, List<AS_Abstract> ass) {
|
||||
List<TC_Abstract> result = new ArrayList<>();
|
||||
|
||||
// 1. Generate Field Constraints
|
||||
result.addAll(generateFieldConstraints(cl,ass));
|
||||
// 2. Generate Method Constraints
|
||||
result.addAll(generateMethodConstraints(cl,ass));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
result.addAll(generateFieldConstraints(cl, ass));
|
||||
// 2. Generate Method Constraints
|
||||
result.addAll(generateMethodConstraints(cl, ass));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static List<TC_Field> generateFieldConstraints(ClassOrInterface cl, List<AS_Abstract> ass ) {
|
||||
List<TC_Field> result = new ArrayList<>();
|
||||
|
||||
|
||||
public static List<TC_Field> generateFieldConstraints(ClassOrInterface cl, List<AS_Abstract> ass) {
|
||||
List<TC_Field> result = new ArrayList<>();
|
||||
|
||||
for (Field f : cl.getFieldDecl()) {
|
||||
AS_Field as = (AS_Field) AS_Abstract.find_AS_Field(f, ass);
|
||||
TC_Field constraint = new TC_Field(cl,f, as.get_TV_Field());
|
||||
result.add(constraint);
|
||||
}
|
||||
return result;
|
||||
AS_Field as = (AS_Field) AS_Abstract.find_AS_Field(f, ass);
|
||||
TC_Field constraint = new TC_Field(cl, f, as.get_TV_Field());
|
||||
result.add(constraint);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Leider hat das erstellen der Constraints für die Methoden nicht mehr funktioniert
|
||||
* Aus dies muss Rekursiv erfolgen
|
||||
* Leider hat das erstellen der Constraints für die Methoden nicht mehr
|
||||
* funktioniert Aus dies muss Rekursiv erfolgen
|
||||
*/
|
||||
|
||||
public static List<TC_Method> generateMethodConstraints(ClassOrInterface cl, List<AS_Abstract> ass) {
|
||||
List<TC_Method> result = new ArrayList<>();
|
||||
public static List<TC_Abstract> generateMethodConstraints(ClassOrInterface es, List<AS_Abstract> ass) {
|
||||
|
||||
for(Method m : cl.getMethods()) {
|
||||
|
||||
Return r = (Return) m.get_Block().getStatements().get(0);
|
||||
Expression ex = r.get_Expression();
|
||||
if (ex.getClass().equals(LocalVar.class)) {
|
||||
// Kein Constraint
|
||||
}
|
||||
else if (ex.getClass().equals(FieldVar.class)){
|
||||
// Noch nicht implementiert
|
||||
|
||||
|
||||
}
|
||||
else if (ex.getClass().equals(MethodCall.class)) {
|
||||
MethodCall m_call = (MethodCall) ex;
|
||||
|
||||
|
||||
TC_Method tc = new TC_Method(cl,m);
|
||||
|
||||
result.add(tc);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
// Darf nicht vorkommen
|
||||
System.out.println("Fehler - Type Expression");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return result;
|
||||
List<TC_Abstract> constraints = new ArrayList<TC_Abstract>();
|
||||
|
||||
for (Method m : es.getMethods() ) {
|
||||
Return r = (Return) m.get_Block().statements.get(0);
|
||||
constraints.addAll(generateMethodConstraints(r.get_Expression(), ass));
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<TC_Abstract> generateMethodConstraints(Expression ex, List<AS_Abstract> ass) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (ex.getClass().equals(LocalVar.class)) {
|
||||
List<TC_Abstract> result = new ArrayList<>();
|
||||
return result;
|
||||
} else if (ex.getClass().equals(FieldVar.class)) {
|
||||
FieldVar v = (FieldVar) ex;
|
||||
List<TC_Abstract> res = generateMethodConstraints(v.getReceiver(), ass);
|
||||
TV_Abstract rt_type = get_rt_Type_of(v.getReceiver(),ass);
|
||||
|
||||
|
||||
// NEW TC field TC_Field()
|
||||
res.add(new TC_Dummy(String.format("TC_Field: ( %s , %s , %s )" , rt_type.toString() , v.getFieldVarName() , "TV_Field(" + rt_type.toString() + " , " + v.getFieldVarName() ) ));
|
||||
|
||||
return res;
|
||||
|
||||
} else if (ex.getClass().equals(MethodCall.class)) {
|
||||
MethodCall m_call = (MethodCall) ex;
|
||||
List<TC_Abstract> res = generateMethodConstraints(m_call.get_Receiver().get_Expression(), ass);
|
||||
TV_Abstract rt_type = get_rt_Type_of(m_call, ass);
|
||||
|
||||
|
||||
res.add(new TC_Dummy("Klasse? " , m_call.get_Name() , "Arguments" , "ReturnType: " + rt_type.toString() , "Typvar: ?" ));
|
||||
return res;
|
||||
|
||||
} else {
|
||||
// Darf nicht vorkommen
|
||||
System.out.println("Fehler - Type Expression");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -58,8 +58,7 @@ public class CodeGenerator {
|
||||
|
||||
public static String generateMethod(Method m, List<AS_Abstract> ass ) {
|
||||
|
||||
String rt_type = Algo_TypeExpr.get_Return_typed(m, ass);
|
||||
|
||||
String rt_type = Algo_TypeExpr.get_Return_typed(m, ass);
|
||||
|
||||
|
||||
String code = rt_type +" " + m.getName() + " ( " ;
|
||||
@ -67,7 +66,8 @@ public class CodeGenerator {
|
||||
// Generate Formalparameter
|
||||
List<FormalParameter> fp = m.getParameterList().getFormalparalist();
|
||||
for (FormalParameter f : fp ) {
|
||||
AS_Argument arg = AS_Abstract.find_AS_Argument(f, ass);
|
||||
//AS_Argument arg = AS_Abstract.find_AS_Argument(f, ass);
|
||||
AS_Argument arg = AS_Abstract.find_AS_Argument(f, m, ass);
|
||||
code = code + arg.get_code() + ", ";
|
||||
}
|
||||
|
||||
|
23
src/de/dhbwstuttgart/strucTypes/TC_Dummy.java
Normal file
23
src/de/dhbwstuttgart/strucTypes/TC_Dummy.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
public class TC_Dummy extends TC_Abstract {
|
||||
|
||||
private String dummy;
|
||||
|
||||
public TC_Dummy(String inhalt) {
|
||||
this.dummy = inhalt;
|
||||
}
|
||||
|
||||
public TC_Dummy(String type1, String method, String arguments_of_type , String returntype , String typvar) {
|
||||
this.dummy = String.format("Mue( %s , %s , %s, (%s , %s )) " , type1, method, arguments_of_type, returntype, typvar);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return dummy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
|
||||
/* Formal Idea:
|
||||
*
|
||||
@ -16,18 +17,38 @@ public class TC_Method extends TC_Abstract {
|
||||
|
||||
// Not completely implemented in the moment
|
||||
private ClassOrInterface cl;
|
||||
private TV_Abstract typvar;
|
||||
private Method method;
|
||||
private MethodCall method_call;
|
||||
|
||||
|
||||
// variante 1 -> Klasse ist bekannt
|
||||
public TC_Method(ClassOrInterface cl, Method method ) {
|
||||
super();
|
||||
this.cl = cl;
|
||||
this.method = method;
|
||||
this.method = method;
|
||||
typvar = null;
|
||||
}
|
||||
|
||||
// variante 2 -> Klasse ist nicht bekannt
|
||||
public TC_Method(TV_Abstract typvar, MethodCall method_call) {
|
||||
super();
|
||||
this.cl = null;
|
||||
this.method = null;
|
||||
this.typvar = typvar;
|
||||
this.method_call = method_call;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Mue( " + cl.getClassName().toString() + "," + method.getName() + "...)" ;
|
||||
|
||||
if (cl != null) {
|
||||
return "Mue( " + cl.getClassName().toString() + "," + method.getName() + "...)" ;
|
||||
}
|
||||
else {
|
||||
return String.format("Mue( %s , %s ..." , typvar.toString() , method_call.get_Name() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
18
src/de/dhbwstuttgart/strucTypes/TV_Dummy.java
Normal file
18
src/de/dhbwstuttgart/strucTypes/TV_Dummy.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
public class TV_Dummy extends TV_Abstract {
|
||||
|
||||
|
||||
private String type = "";
|
||||
|
||||
|
||||
public TV_Dummy(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
}
|
5
src/de/dhbwstuttgart/strucTypes2/Assumption.java
Normal file
5
src/de/dhbwstuttgart/strucTypes2/Assumption.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
public class Assumption {
|
||||
|
||||
}
|
7
src/de/dhbwstuttgart/strucTypes2/Assumptions_Map.java
Normal file
7
src/de/dhbwstuttgart/strucTypes2/Assumptions_Map.java
Normal file
@ -0,0 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
public class Assumptions_Map {
|
||||
|
||||
private Map<TypePlaceholder, TVar> assumption_Map = new HashMap<>();
|
||||
|
||||
}
|
36
src/de/dhbwstuttgart/strucTypes2/CodeGenerator.java
Normal file
36
src/de/dhbwstuttgart/strucTypes2/CodeGenerator.java
Normal file
@ -0,0 +1,36 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
|
||||
|
||||
|
||||
public class CodeGenerator {
|
||||
|
||||
|
||||
|
||||
public static String generate_code_from_SourceFile(SourceFile sf) {
|
||||
String res = "";
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String generate_code_from_Class(ClassOrInterface cl) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
27
src/de/dhbwstuttgart/strucTypes2/Collect_Types.java
Normal file
27
src/de/dhbwstuttgart/strucTypes2/Collect_Types.java
Normal file
@ -0,0 +1,27 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
public class Collect_Types {
|
||||
|
||||
|
||||
public static Map<RefTypeOrTPHOrWildcardOrGeneric,String> collect(SourceFile sf) {
|
||||
|
||||
Map<RefTypeOrTPHOrWildcardOrGeneric,String> typen = new HashMap<>();
|
||||
|
||||
|
||||
// Sammle Typen aus Klassen
|
||||
|
||||
|
||||
|
||||
|
||||
return typen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
5
src/de/dhbwstuttgart/strucTypes2/TV_Abstract.java
Normal file
5
src/de/dhbwstuttgart/strucTypes2/TV_Abstract.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
public class TV_Abstract {
|
||||
|
||||
}
|
5
src/de/dhbwstuttgart/strucTypes2/TV_Argument.java
Normal file
5
src/de/dhbwstuttgart/strucTypes2/TV_Argument.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
public class TV_Argument {
|
||||
|
||||
}
|
42
src/de/dhbwstuttgart/strucTypes2/TV_Field.java
Normal file
42
src/de/dhbwstuttgart/strucTypes2/TV_Field.java
Normal file
@ -0,0 +1,42 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
|
||||
public class TV_Field extends TV_Abstract {
|
||||
|
||||
private TV_Abstract type_of_class;
|
||||
private Field field;
|
||||
|
||||
public TV_Field(TV_Abstract type_of_class, Field field) {
|
||||
super();
|
||||
this.type_of_class = type_of_class;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
|
||||
public TV_Abstract getType_of_class() {
|
||||
return type_of_class;
|
||||
}
|
||||
|
||||
public void setType_of_class(TV_Abstract type_of_class) {
|
||||
this.type_of_class = type_of_class;
|
||||
}
|
||||
|
||||
public Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(Field field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
15
src/de/dhbwstuttgart/strucTypes2/TV_Type.java
Normal file
15
src/de/dhbwstuttgart/strucTypes2/TV_Type.java
Normal file
@ -0,0 +1,15 @@
|
||||
package de.dhbwstuttgart.strucTypes2;
|
||||
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
|
||||
public class TV_Type extends TV_Abstract {
|
||||
|
||||
|
||||
private JavaClassName name;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -40,4 +40,19 @@ public class FieldVar extends Expression {
|
||||
ret.addOderConstraint(oderConstraints);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// @ Sebastian
|
||||
public String getFieldVarName() {
|
||||
return fieldVarName;
|
||||
}
|
||||
|
||||
// @ Sebastian
|
||||
public Expression getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public class GeneralParserTest{
|
||||
//filenames.add("GenericFieldVarTest.jav");
|
||||
//filenames.add("FieldVarTest.jav");
|
||||
|
||||
filenames.add("StructuralTypesField.jav");
|
||||
filenames.add("StructuralTypesSimple3.jav");
|
||||
//filenames.add("StructuralTypesField.jav");
|
||||
//filenames.add("Main.jav");
|
||||
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
|
@ -3,12 +3,12 @@ class A {
|
||||
|
||||
A f1;
|
||||
|
||||
A f2;
|
||||
|
||||
f2;
|
||||
|
||||
mt1(x) { return x; }
|
||||
|
||||
mt1(x1) { return x1; }
|
||||
|
||||
//mt2(x) { return x.feld ; }
|
||||
mt2(x2) { return x2.feld_von_x ; }
|
||||
|
||||
mt3(x,y,z) { return x.sub(y).add(z); }
|
||||
|
||||
|
74
test/strucTypes2/GeneralParserTest.java
Normal file
74
test/strucTypes2/GeneralParserTest.java
Normal file
@ -0,0 +1,74 @@
|
||||
package strucTypes2;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
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.Algo_Type;
|
||||
import de.dhbwstuttgart.strucTypes.Algo_TypeExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden.
|
||||
* Der dabei erstellte Syntaxbaum wird nicht kontrolliert.
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class GeneralParserTest{
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/strucTypes/";
|
||||
|
||||
@Test
|
||||
public void run(){
|
||||
|
||||
/*
|
||||
* Auflistung aller Files die getestet werden sollen
|
||||
*/
|
||||
List<String> filenames = new ArrayList<String>();
|
||||
//filenames.add("FieldInitializationTest.jav");
|
||||
//filenames.add("ImportTest.jav");
|
||||
//filenames.add("StatementsTest.jav");
|
||||
//filenames.add("ImportTestGeneric.jav");
|
||||
//filenames.add("BoundedParameter.jav");
|
||||
//filenames.add("GenericFieldVarTest.jav");
|
||||
//filenames.add("FieldVarTest.jav");
|
||||
|
||||
filenames.add("StructuralTypesSimple3.jav");
|
||||
//filenames.add("StructuralTypesField.jav");
|
||||
//filenames.add("Main.jav");
|
||||
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
try{
|
||||
for(String filename : filenames) {
|
||||
|
||||
System.out.println("Teste: "+ filename);
|
||||
|
||||
SourceFile sf = parser.parse(new File(rootDirectory + filename));
|
||||
|
||||
SourceFile sfdebug = sf;
|
||||
|
||||
|
||||
// Hier soll der CodeGenerator hin.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}catch(Exception exc){
|
||||
exc.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
assertTrue("Tests durchlaufen",filenames.size()>0);
|
||||
}
|
||||
|
||||
}
|
16
test/strucTypes2/StructuralTypesSimple3.jav
Normal file
16
test/strucTypes2/StructuralTypesSimple3.jav
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
class A {
|
||||
|
||||
A f1;
|
||||
|
||||
A f2;
|
||||
|
||||
|
||||
mt1(x) { return x; }
|
||||
|
||||
mt2(x) { return x.feld_von_x ; }
|
||||
|
||||
mt3(x,y,z) { return x.sub(y).add(z); }
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user