diff --git a/src/de/dhbwstuttgart/strucTypes/Algo_TypeExpr.java b/src/de/dhbwstuttgart/strucTypes/Algo_TypeExpr.java index c88f49de..11692d27 100644 --- a/src/de/dhbwstuttgart/strucTypes/Algo_TypeExpr.java +++ b/src/de/dhbwstuttgart/strucTypes/Algo_TypeExpr.java @@ -3,7 +3,10 @@ package de.dhbwstuttgart.strucTypes; import java.util.ArrayList; import java.util.List; +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.Return; import de.dhbwstuttgart.syntaxtree.statement.Statement; @@ -31,7 +34,7 @@ public class Algo_TypeExpr { - // Methode enthält nur ein Return statment das ein feld zurückgibt + // 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); @@ -59,28 +62,64 @@ public class Algo_TypeExpr { //-> Es muss so sein dass ich diese Return Statement beurteilen kann - - - - - - - - - - - - - - - - } + public static String expression2code(List ass , List statements ) { + String res = ""; + + // Leere methode + if (statements.size() == 0) { + res = "---"; + } + + // 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 res; + } + + + public static String statement2code(List ass , Statement statement) { + + + // TODO: Else if + + if ( statement.getClass().equals(LocalVar.class) ) { + LocalVar lvar = (LocalVar) statement; + String exp_str = lvar.get_expression(); + return exp_str; + } + + + if (statement.getClass().equals(FieldVar.class)) { + // FieldVar ist nicht implementiert + } + + + if (statement.getClass().equals(MethodCall.class)) { + MethodCall mtcall = (MethodCall) statement; + Statement receiver = (Statement) mtcall.get_Receiver().get_Expression(); + String str = statement2code(ass,receiver); + return str + "."+ mtcall.get_Name() + "()"; + } + + return "Fehler"; + } + + + + + + diff --git a/src/de/dhbwstuttgart/strucTypes/REPL.java b/src/de/dhbwstuttgart/strucTypes/REPL.java new file mode 100644 index 00000000..0b24638d --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes/REPL.java @@ -0,0 +1,19 @@ +package de.dhbwstuttgart.strucTypes; + +public class REPL { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + + Integer i = 1; + + + System.out.println(i.getClass() == Integer.class); + + System.out.println(i.getClass().equals(Integer.class)); + + + } + +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 7b33f17b..a7102d98 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -24,6 +24,19 @@ public class MethodCall extends Statement this.name = methodName; this.receiver = receiver; } + + + // Sebastian + public Receiver get_Receiver() { + return receiver; + } + + // Sebastian + public String get_Name() { + return name; + } + + @Override public ConstraintSet getConstraints(TypeInferenceInformation info) { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java index 14fc8740..1361ea05 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java @@ -16,6 +16,12 @@ public class Receiver extends Expression super(expr.getType(), expr.getOffset()); this.expr = expr; } + + // Sebastian + public Expression get_Expression() { + return expr; + } + @Override public ConstraintSet getConstraints(TypeInferenceInformation info) { diff --git a/test/strucTypes/Fragen.txt b/test/strucTypes/Fragen.txt new file mode 100644 index 00000000..ef0bf81a --- /dev/null +++ b/test/strucTypes/Fragen.txt @@ -0,0 +1,6 @@ + +Geht nicht ? + +mt4() { return f1; } + +Wie ist mit sowas umzugehen? Immer nur lokale Variable? \ No newline at end of file diff --git a/test/strucTypes/GeneralParserTest.java b/test/strucTypes/GeneralParserTest.java index c9989214..cc9e4580 100644 --- a/test/strucTypes/GeneralParserTest.java +++ b/test/strucTypes/GeneralParserTest.java @@ -10,6 +10,7 @@ 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; @@ -58,6 +59,9 @@ public class GeneralParserTest{ Algo_Type type = new Algo_Type( ass , sf.getClasses().get(0)); + // Print der Expression: + System.out.println(Algo_TypeExpr.expression2code(ass, sf.getClasses().get(0).getMethods().get(0).get_Block().statements)); + System.out.println(Algo_TypeExpr.expression2code(ass, sf.getClasses().get(0).getMethods().get(2).get_Block().statements)); // Erstellen der TypeExpression diff --git a/test/strucTypes/StructuralTypesSimple2.jav b/test/strucTypes/StructuralTypesSimple2.jav index a618c63e..dab9d0f0 100644 --- a/test/strucTypes/StructuralTypesSimple2.jav +++ b/test/strucTypes/StructuralTypesSimple2.jav @@ -11,6 +11,8 @@ class A { mt3(a,b,c) { return a.add(b).sub(c); } + + }