From 3c165f79e421b3f95d0ffe87c69b0b6031e7cd32 Mon Sep 17 00:00:00 2001 From: sebastian Date: Tue, 18 Apr 2017 21:12:39 +0200 Subject: [PATCH] neuer Versuch mit Parser gespeichert --- src/FLJ.g4 | 30 + src/FWJ.g4 | 47 + src/control/A.jal | 8 + src/control/A2.jal | 8 + src/control/Main.jal | 7 + src/control/Main.java | 71 + src/control/MyInteger.jal | 8 + src/control/ReadIn.java | 51 + src/control/Start.java | 40 + src/control/source.javLight | 36 + src/control/source2.javLight | 4 + src/control/source3.javLight | 4 + src/control/sourceNew.javLight | 4 + .../strucTypes4/Algo/ConstraintAbstract.java | 29 + .../strucTypes4/Algo/ConstraintField.java | 53 + .../strucTypes4/Algo/ConstraintGleich.java | 46 + .../strucTypes4/Algo/ConstraintMethod.java | 90 ++ .../strucTypes4/Algo/ConstraintSubType.java | 69 + .../Algo/ConstraintSubTypeInterface.java | 61 + .../strucTypes4/Algo/Construct.java | 216 +++ .../Algo/FrischeVariablenGenerator.java | 168 +++ .../strucTypes4/Algo/InformationTuple.java | 66 + .../strucTypes4/Algo/MakeAss.java | 7 + .../strucTypes4/Algo/TypeExpr.java | 82 ++ .../strucTypes4/grammar/FWJ.tokens | 29 + .../strucTypes4/grammar/FWJBaseListener.java | 218 +++ .../strucTypes4/grammar/FWJBaseVisitor.java | 118 ++ .../strucTypes4/grammar/FWJLexer.java | 125 ++ .../strucTypes4/grammar/FWJLexer.tokens | 29 + .../strucTypes4/grammar/FWJListener.java | 159 +++ .../strucTypes4/grammar/FWJParser.java | 1196 +++++++++++++++++ .../strucTypes4/grammar/FWJVisitor.java | 102 ++ .../strucTypes4/parser/Parser.java | 56 + .../strucTypes4/parser/SourceFileWalker.java | 72 + .../strucTypes4/parserFWJ/Parser.java | 178 +++ .../parserFWJ/SourceFileWalker.java | 280 ++++ .../strucTypes4/syntaxtree/Argument.java | 36 + .../strucTypes4/syntaxtree/Class.java | 104 ++ .../strucTypes4/syntaxtree/ClassTyped.java | 90 ++ .../strucTypes4/syntaxtree/ExprField.java | 42 + .../strucTypes4/syntaxtree/ExprMCall.java | 116 ++ .../strucTypes4/syntaxtree/ExprNew.java | 61 + .../strucTypes4/syntaxtree/ExprVar.java | 51 + .../strucTypes4/syntaxtree/Expression.java | 42 + .../syntaxtree/ExpressionAbstract.java | 17 + .../strucTypes4/syntaxtree/Field.java | 43 + .../syntaxtree/FieldInterface.java | 39 + .../strucTypes4/syntaxtree/Interface.java | 62 + .../strucTypes4/syntaxtree/Method.java | 93 ++ .../syntaxtree/MethodInterface.java | 52 + .../strucTypes4/syntaxtree/SourceFile.java | 36 + .../strucTypes4/syntaxtree/SyntaxNode.java | 19 + .../dhbwstuttgart/strucTypes4/typen/TPH.java | 61 + .../strucTypes4/typen/TPHFactory.java | 34 + .../strucTypes4/typen/TPHStore.java | 11 + .../dhbwstuttgart/strucTypes4/typen/TPHV.java | 36 + .../strucTypes4/typen/TPHVFactory.java | 17 + .../strucTypes4/typen/TPHwithClass.java | 18 + 58 files changed, 4847 insertions(+) create mode 100644 src/FLJ.g4 create mode 100644 src/FWJ.g4 create mode 100644 src/control/A.jal create mode 100644 src/control/A2.jal create mode 100644 src/control/Main.jal create mode 100644 src/control/Main.java create mode 100644 src/control/MyInteger.jal create mode 100644 src/control/ReadIn.java create mode 100644 src/control/Start.java create mode 100644 src/control/source.javLight create mode 100644 src/control/source2.javLight create mode 100644 src/control/source3.javLight create mode 100644 src/control/sourceNew.javLight create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintAbstract.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintField.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintGleich.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintMethod.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubType.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubTypeInterface.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/Construct.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/FrischeVariablenGenerator.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/InformationTuple.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/MakeAss.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/Algo/TypeExpr.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJ.tokens create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseListener.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseVisitor.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.tokens create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJListener.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJParser.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/grammar/FWJVisitor.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/parser/Parser.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/parser/SourceFileWalker.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/parserFWJ/Parser.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/parserFWJ/SourceFileWalker.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/Argument.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/Class.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/ClassTyped.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprField.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprMCall.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprNew.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprVar.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/Expression.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExpressionAbstract.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/Field.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/FieldInterface.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/Interface.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/Method.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/MethodInterface.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/SourceFile.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/syntaxtree/SyntaxNode.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/typen/TPH.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/typen/TPHFactory.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/typen/TPHStore.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/typen/TPHV.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/typen/TPHVFactory.java create mode 100644 src/de/dhbwstuttgart/strucTypes4/typen/TPHwithClass.java diff --git a/src/FLJ.g4 b/src/FLJ.g4 new file mode 100644 index 00000000..81444536 --- /dev/null +++ b/src/FLJ.g4 @@ -0,0 +1,30 @@ +grammar FLJ; + +// Inputsyntax für ein Featherweight Java + +l2 : (l)+; + +l : Class ClassName '{' (feld)* method* '}'; + + +feld: ClassName Var ';'; + +returnExpression: 'return' expression ';' ; +methodCall: Var '(' args? ')'; + + +expression: Var | expression'.'methodCall | expression'.'Var | 'new' ClassName generics? '('expressionArgs?')' expression? ; +method: Var '(' expressionArgs? ')' '{' returnExpression? '}' ; +args: Var | (Var ',')+ Var ; +expressionArgs : expression | (expression ',')+ expression; + +generics: '<''>'; + +Class: 'class'; +ClassName: [A-Z]+[a-z]*; +Var: [a-z]+; + + + +Linefeed: '\r'? '\n' -> skip; //'\r' für Windows linefeed +WS : [ \t]+ -> skip; //Überspringen aller Leerzeichen \ No newline at end of file diff --git a/src/FWJ.g4 b/src/FWJ.g4 new file mode 100644 index 00000000..a3283314 --- /dev/null +++ b/src/FWJ.g4 @@ -0,0 +1,47 @@ +grammar FWJ; + +// Inputsyntax für ein Federleichtes Java + +sourceFile : (classX)+; + +classX : Class bezeichner '{' (feld)* methodDecl* '}'; + + +feld: bezeichner bezeichner ';'; + +//returnExpression: 'return' expression ';' ; +//methodCall: Token2 '(' expr? ')'; + + +//expression: exprVar | exprNew | exprMcall ; +//method: Var '(' expressionArgs? ')' '{' returnExpression? '}' ; +//args: Var | (Var ',')+ Var ; +//expressionArgs : expression | (expression ',')+ expression; + +generics: '<' ( (generic ',' )+ generic | generic? ) '>'; +generic: (bezeichner '=' bezeichner); + +methodDecl: bezeichner '(' methodDeclArgs? ')' '{' returnExpr? '}' ; +methodDeclArgs: bezeichner | (bezeichner ',')+ bezeichner ; + +returnExpr: 'return' expr ';' ; + + +exprMCall : bezeichner '(' exprMCallArgs? ')'; +exprVar: bezeichner; +exprField: '.'bezeichner; +exprNew: 'new' bezeichner generics? '('exprMCallArgs?')'; + + +expr: exprVar | expr'.'expr | exprField | exprMCall | exprNew ; +exprMCallArgs: expr | ( expr ',')+ expr; + + +Class: 'class'; +// Für Klassen und Variablen +bezeichner: Token2; +Token2: [a-zA-Z0-9_]+; + + +Linefeed: '\r'? '\n' -> skip; //'\r' für Windows linefeed +WS : [ \t]+ -> skip; //Überspringen aller Leerzeichen \ No newline at end of file diff --git a/src/control/A.jal b/src/control/A.jal new file mode 100644 index 00000000..4b4a330d --- /dev/null +++ b/src/control/A.jal @@ -0,0 +1,8 @@ + +class A { + mt(x,y,z) { return x.sub(y).add(z) ; } +} + + + + diff --git a/src/control/A2.jal b/src/control/A2.jal new file mode 100644 index 00000000..55ff5dfe --- /dev/null +++ b/src/control/A2.jal @@ -0,0 +1,8 @@ + +class A { + mt(x,y,z) { return x.sub(y.div1() , y.mul2(z.fak())); } +} + + + + diff --git a/src/control/Main.jal b/src/control/Main.jal new file mode 100644 index 00000000..f846ca93 --- /dev/null +++ b/src/control/Main.jal @@ -0,0 +1,7 @@ +class Main { + +main() { return new A< T1=MyInteger , T7=MyInteger >().mt( new MyInteger(1) , new MyInteger(2) , new MyInteger(3) ); } + +} + + diff --git a/src/control/Main.java b/src/control/Main.java new file mode 100644 index 00000000..dbce2ae9 --- /dev/null +++ b/src/control/Main.java @@ -0,0 +1,71 @@ +package control; + +import java.util.HashMap; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.parserFWJ.Parser; +import de.dhbwstuttgart.strucTypes4.syntaxtree.ClassTyped; +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHwithClass; + +/** + * Created by sebastian on 07.04.17. + */ +public class Main { + + + public static void main(String[] args) { + + System.out.println("Hallo Welt"); + + // Pfade: + String s1 = "source3.javLight"; + String s2 = "source2.javLight"; + String s3 = "source.javLight"; + String ne = "sourceNew.javLight"; + + + // Neue Pfade + String myInteger = "MyInteger.jal"; + String main = "Main.jal"; + String a = "A.jal"; + String a2 = "A2.jal"; + + + Start start = new Start(a2, main); + + + + /* + // Lesen von A + Parser p = new Parser(); + Map ass = new HashMap<>(); + ClassTyped clta = p.parseCode(ReadIn.read(a),ass); + + TPHwithClass tph = new TPHwithClass(); + tph.classTyped = clta; + ass.put("$A", tph ); + //ass.put("$Integer",tph); + //ass.put("$MyInteger",tph); + + // Lesen von main + Parser p3 = new Parser(); + ClassTyped cltmain = p3.parseCode(ReadIn.read(main),ass); + System.out.println(cltmain); + */ + + + + + + + + + } + + + + + +} + diff --git a/src/control/MyInteger.jal b/src/control/MyInteger.jal new file mode 100644 index 00000000..b9f95202 --- /dev/null +++ b/src/control/MyInteger.jal @@ -0,0 +1,8 @@ + +class MyInteger { + +Integer i; +add(x) { return new MyInteger(x); } +sub(x) { return new MyInteger(x); } + +} \ No newline at end of file diff --git a/src/control/ReadIn.java b/src/control/ReadIn.java new file mode 100644 index 00000000..16991833 --- /dev/null +++ b/src/control/ReadIn.java @@ -0,0 +1,51 @@ +package control; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by sebastian on 07.04.17. + */ +public class ReadIn { + + public static String read(String sourcePath) { + + + String result = ""; + + try { + + + InputStream is = Main.class.getResourceAsStream(sourcePath); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader bf = new BufferedReader(isr); + List lines = new ArrayList<>(); + + while (true) { + String l = bf.readLine(); + if (l == null) { + break; + } else { + lines.add(l); + } + } + for (String l2 : lines) { + result = result.concat(l2 + "\n" ); + } + return result; + + + } catch (Exception ex) { + ex.printStackTrace(); + } + return result; + + } + + + + +} diff --git a/src/control/Start.java b/src/control/Start.java new file mode 100644 index 00000000..bdaa9902 --- /dev/null +++ b/src/control/Start.java @@ -0,0 +1,40 @@ +package control; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.parserFWJ.Parser; +import de.dhbwstuttgart.strucTypes4.syntaxtree.ClassTyped; +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHwithClass; + +/** + * Created by sebastian on 12.04.17. + */ +public class Start { + + + Map assumptionsGlobal = new HashMap<>(); + List results = new ArrayList<>(); + + + public Start(String... argsPfade ) { + + for (String arg : argsPfade) { + parseKlasse(arg); + } + } + + + private void parseKlasse(String pfad) { + Parser p = new Parser(); + ClassTyped classTyped = p.parseCode(ReadIn.read(pfad), assumptionsGlobal); + TPHwithClass tph = new TPHwithClass(); + tph.classTyped = classTyped; + assumptionsGlobal.put("$" + classTyped.getaClass().getName() , tph); + System.out.println(classTyped.toCodeTyped()); + results.add(classTyped); + } +} diff --git a/src/control/source.javLight b/src/control/source.javLight new file mode 100644 index 00000000..81245fee --- /dev/null +++ b/src/control/source.javLight @@ -0,0 +1,36 @@ +class A { +mt(x,y,z) { return x.sub(y).add(z) ;} +} + + +class B { +add(a,b,c) {return a.add(); } +} + +class BB { +add(a,b,c) {return a.add(a.b); } +} + + +class BBB { +add(a,b,c) {return a.add(a..b, a..c); } +} + + +class Main { +main() { return new A(); } +} + + +class Myinteger { +Myinteger i; +add(x) { return new Myinteger(x.i);} +sub(x) { return new Myinteger(x.i);} +} + + +class Main { +main() { return new A<>().mt(x,y,z); } +} + + diff --git a/src/control/source2.javLight b/src/control/source2.javLight new file mode 100644 index 00000000..31d01f48 --- /dev/null +++ b/src/control/source2.javLight @@ -0,0 +1,4 @@ +class A { +mt(x,y,z) { return x.sub(y).add(z.div(x,x)) ;} +} + diff --git a/src/control/source3.javLight b/src/control/source3.javLight new file mode 100644 index 00000000..9c96ade3 --- /dev/null +++ b/src/control/source3.javLight @@ -0,0 +1,4 @@ +class A { +mt(x,y,z) { return x.sub(y).add(z) ;} +} + diff --git a/src/control/sourceNew.javLight b/src/control/sourceNew.javLight new file mode 100644 index 00000000..0c314be1 --- /dev/null +++ b/src/control/sourceNew.javLight @@ -0,0 +1,4 @@ +class Main { +main() { return new A<>().mt( new MI() ) ;} +} + diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintAbstract.java b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintAbstract.java new file mode 100644 index 00000000..89aaa9d2 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintAbstract.java @@ -0,0 +1,29 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import java.util.HashSet; +import java.util.Set; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public abstract class ConstraintAbstract { + + + public abstract void replace(TPH old , TPH neu); + + public Set getAllTPH() { + System.err.println("Nicht vorgesehen"); + Set leereMenge = new HashSet<>(); + return leereMenge; + } + + public Set getAllReceiver() { + System.err.println("Nicht vorgesehen"); + Set leereMenge = new HashSet<>(); + return leereMenge; + } + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintField.java b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintField.java new file mode 100644 index 00000000..2722b126 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintField.java @@ -0,0 +1,53 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class ConstraintField extends ConstraintAbstract { + + TPH receiver; + String nameField; + TPH caller; + + public ConstraintField(TPH receiver, String nameField, TPH caller) { + this.receiver = receiver; + this.nameField = nameField; + this.caller = caller; + } + + public TPH getReceiver() { + return receiver; + } + + public void setReceiver(TPH receiver) { + this.receiver = receiver; + } + + public TPH getCaller() { + return caller; + } + + public void setCaller(TPH caller) { + this.caller = caller; + } + + public String getNameField() { + return nameField; + } + + @Override + public String toString() { + return String.format(" ConstField( %s , %s , %s ) " , receiver , nameField ,caller); + } + + + @Override + public void replace(TPH old, TPH neu) { + System.err.println("Nicht Implementiert"); + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintGleich.java b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintGleich.java new file mode 100644 index 00000000..38b7dc58 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintGleich.java @@ -0,0 +1,46 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class ConstraintGleich extends ConstraintAbstract{ + + TPH typeA; + TPH typeB; + + public ConstraintGleich(TPH typeA, TPH typeB) { + this.typeA = typeA; + this.typeB = typeB; + } + + public TPH getTypeA() { + return typeA; + } + + public void setTypeA(TPH typeA) { + this.typeA = typeA; + } + + public TPH getTypeB() { + return typeB; + } + + public void setTypeB(TPH typeB) { + this.typeB = typeB; + } + + + @Override + public String toString() { + return String.format( "ConsGleich: ( %s == %s ) " , typeA, typeB ); + } + + + @Override + public void replace(TPH old, TPH neu) { + System.err.println("Nicht Implementiert"); + } + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintMethod.java b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintMethod.java new file mode 100644 index 00000000..3373e1e7 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintMethod.java @@ -0,0 +1,90 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class ConstraintMethod extends ConstraintAbstract { + + TPH receiver; + String methodName; + List argsTypes; + TPH returnType; + List argsBetaTypes; + + public ConstraintMethod(TPH receiver, String methodName, List argsTypes, TPH returnType, List argsBetaTypes) { + this.receiver = receiver; + this.methodName = methodName; + this.argsTypes = argsTypes; + this.returnType = returnType; + this.argsBetaTypes = argsBetaTypes; + } + + + public TPH getReceiver() { + return receiver; + } + + public void setReceiver(TPH receiver) { + this.receiver = receiver; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public List getArgsTypes() { + return argsTypes; + } + + public void setArgsTypes(List argsTypes) { + this.argsTypes = argsTypes; + } + + public TPH getReturnType() { + return returnType; + } + + public void setReturnType(TPH returnType) { + this.returnType = returnType; + } + + public List getArgsBetaTypes() { + return argsBetaTypes; + } + + public void setArgsBetaTypes(List argsBetaTypes) { + this.argsBetaTypes = argsBetaTypes; + } + + + @Override + public String toString() { + return String.format(" Const Method( %s , %s , %s , ( %s , %s ))" , receiver, methodName , argsTypes , returnType , argsBetaTypes); + } + + @Override + public void replace(TPH old, TPH neu) { + System.err.println("Nicht Implementiert"); + } + + + public Set getAllReceiver() { + Set leereMenge = new HashSet<>(); + leereMenge.add(receiver); + return leereMenge; + } + + +} + + diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubType.java b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubType.java new file mode 100644 index 00000000..d2e34630 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubType.java @@ -0,0 +1,69 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import java.util.HashSet; +import java.util.Set; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class ConstraintSubType extends ConstraintAbstract { + + TPH typeKleiner; + TPH typeGroeßer; + + public ConstraintSubType(TPH typeKleiner, TPH typeGroeßer) { + this.typeKleiner = typeKleiner; + this.typeGroeßer = typeGroeßer; + } + + + public void replace(TPH old, TPH neu) { + if (typeKleiner.equals(old)) { + typeKleiner = neu; + } + if (typeGroeßer.equals(old)) { + typeGroeßer = neu; + } + } + + @Override + public Set getAllTPH() { + Set tphs = new HashSet<>(); + tphs.add(typeGroeßer); + tphs.add(typeKleiner); + return tphs; + } + + public TPH getTypeKleiner() { + return typeKleiner; + } + + public void setTypeKleiner(TPH typeKleiner) { + this.typeKleiner = typeKleiner; + } + + public TPH getTypeGroeßer() { + return typeGroeßer; + } + + public void setTypeGroeßer(TPH typeGroeßer) { + this.typeGroeßer = typeGroeßer; + } + + + @Override + public String toString() { + return String.format( "Const_Sub: ( %s <* %s ) " , typeKleiner , typeGroeßer ); + } + + + + public Set getAllReceiver() { + Set leereMenge = new HashSet<>(); + leereMenge.add(getTypeKleiner()); + return leereMenge; + } + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubTypeInterface.java b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubTypeInterface.java new file mode 100644 index 00000000..93b5f274 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/ConstraintSubTypeInterface.java @@ -0,0 +1,61 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 11.04.17. + */ +public class ConstraintSubTypeInterface extends ConstraintAbstract{ + + TPH kleiner; + List größer; + String nameInterface; + + public ConstraintSubTypeInterface(TPH kleiner, List größer , String nameInterface) { + this.kleiner = kleiner; + this.größer = größer; + this.nameInterface = nameInterface; + } + + + @Override + public Set getAllTPH() { + Set tphs = new HashSet<>(); + tphs.add(kleiner); + tphs.addAll(größer); + return tphs; + } + + @Override + public void replace(TPH old, TPH neu) { + if (kleiner.equals(old)) { + kleiner = neu; + } + + for (int i = 0 ; i < größer.size() ; i++) { + if (größer.get(i).equals(old)) { + größer.remove(i); + größer.add(i,neu); + } + } + } + + @Override + public String toString() { + return "ConstraintSubTypeInterface{" + kleiner + "<* " + nameInterface + "<" + größer +">"; + } + + + public Set getAllReceiver() { + Set leereMenge = new HashSet<>(); + leereMenge.add(kleiner); + return leereMenge; + } + +} + diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/Construct.java b/src/de/dhbwstuttgart/strucTypes4/Algo/Construct.java new file mode 100644 index 00000000..7017a3ad --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/Construct.java @@ -0,0 +1,216 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import de.dhbwstuttgart.strucTypes4.syntaxtree.*; +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHFactory; + +/** + * Created by sebastian on 09.04.17. + */ +public class Construct { + + List resultConstraints = new ArrayList<>(); + List resultInterfaces = new ArrayList<>(); + + + // Mapping der alten Typvariablen zu neuen + private Map altZuNeuTPH = new HashMap<>(); + private String nameInterface = ""; + + + + + public Construct(List constraints ) { + constructInterfacesSortet(constraints); + } + + + private void constructInterfacesSortet(List constraints) { + + Map> sortetConst = sortiereConstraints(constraints); + + resultInterfaces = new ArrayList<>(); + + // Erstelle Interfaces und Neue Subtype Constraints + for (TPH key : sortetConst.keySet() ) { + ConstructInterfaceForType constructInterfaceForType = new ConstructInterfaceForType(sortetConst.get(key) , altZuNeuTPH); + resultInterfaces.addAll(constructInterfaceForType.resultInterfaces); + resultConstraints.addAll(constructInterfaceForType.subTypeconstraints); + } + + + // KopiereSubconstraints + for (ConstraintAbstract c: constraints ) { + if (c.getClass().equals(ConstraintSubType.class)) { + resultConstraints.add(c); + } + } + + // Kopiere ConstraintSubTypeInterface + for (ConstraintAbstract c: constraints) { + if (c.getClass().equals(ConstraintSubTypeInterface.class)) { + resultConstraints.add(c); + } + } + } + + + + + + private Map> sortiereConstraints(List constraints) { + + Map> constraintMap = new ConcurrentHashMap<>(); + + for (ConstraintAbstract con : constraints) { + + TPH receiver = null; + + // Suche den Receiver der Metohde oder des Feldes + if (con.getClass().equals(ConstraintMethod.class)) { + ConstraintMethod cm = (ConstraintMethod) con; + receiver = cm.getReceiver(); + } + else if (con.getClass().equals(ConstraintField.class)) { + ConstraintField cf = (ConstraintField) con; + receiver = cf.getReceiver(); + } + + + // wenn Receiver vorhanden -> füge ihn in die Map ein; + if (receiver != null ) { + if (constraintMap.containsKey(receiver)) { + constraintMap.get(receiver).add(con); + } + else { + List clist = new ArrayList<>(); + clist.add(con); + constraintMap.put(receiver,clist); + } + } + } + + return constraintMap; + } + + + + + + + + public List getResultConstraints() { + return resultConstraints; + } + + public void setResultConstraints(List resultConstraints) { + this.resultConstraints = resultConstraints; + } + + public List getResultInterfaces() { + return resultInterfaces; + } + + public void setResultInterfaces(List resultInterfaces) { + this.resultInterfaces = resultInterfaces; + } +} + + + + +class ConstructInterfaceForType { + + List resultInterfaces = new ArrayList<>(); + List subTypeconstraints = new ArrayList<>(); + Map altZuNeuTPH; + + public ConstructInterfaceForType(List cons , Map altZuNeu ) { + this.altZuNeuTPH = altZuNeu; + constructInterfaces(cons); + } + + + + + public void constructInterfaces(List constraints) { + + List mlist = new ArrayList<>(); + List flist = new ArrayList<>(); + List generics = new ArrayList<>(); + String nameInterface = ""; + + + // generate Interface Fields + for (ConstraintAbstract c : constraints) { + + if (c.getClass().equals(ConstraintField.class)) { + ConstraintField constraintField = (ConstraintField) c; + + FieldInterface field = new FieldInterface(changeTPH(constraintField.getCaller()),constraintField.nameField); + flist.add(field); + + nameInterface = nameInterface.concat(constraintField.nameField); + + } + } + + + // generate Interface Methods // Wichtig ist es die Typvariablen in den Methoden auszutauschnen + for (ConstraintAbstract c : constraints) { + if (c.getClass().equals(ConstraintMethod.class)) { + ConstraintMethod constraintMethod = (ConstraintMethod) c; + + // Erstelle generics (erster ist return, alle weitere Arg der Methode + // + generics.add(changeTPH(constraintMethod.returnType)); + generics.addAll(changeTPHList(constraintMethod.argsBetaTypes)); + + + MethodInterface methodInterface = new MethodInterface(constraintMethod.methodName , changeTPH(constraintMethod.returnType) , changeTPHList(constraintMethod.argsBetaTypes)); + mlist.add(methodInterface); + + nameInterface = nameInterface + constraintMethod.getMethodName() ; + + // Ergebnis Subtype Relation + List genericsFuerConstraint = new ArrayList<>(); + genericsFuerConstraint.add(constraintMethod.returnType); + genericsFuerConstraint.addAll(constraintMethod.argsBetaTypes); + subTypeconstraints.add(new ConstraintSubTypeInterface( constraintMethod.getReceiver(), genericsFuerConstraint, "Type")); + + } + } + + // Ergebnis Interface + Interface anInterface = new Interface(nameInterface, flist , mlist, generics); + resultInterfaces.add(anInterface); + } + + + + + private TPH changeTPH(TPH alt) { + if (altZuNeuTPH.containsKey(alt)) { + return altZuNeuTPH.get(alt); + } + else { + altZuNeuTPH.put(alt, TPHFactory.makeTPH()); + return altZuNeuTPH.get(alt); + } + } + + private List changeTPHList(List list) { + List list1 = new ArrayList<>(); + list.forEach((x) -> list1.add(changeTPH(x))); + return list1; + } + + + +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/FrischeVariablenGenerator.java b/src/de/dhbwstuttgart/strucTypes4/Algo/FrischeVariablenGenerator.java new file mode 100644 index 00000000..70b50411 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/FrischeVariablenGenerator.java @@ -0,0 +1,168 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import java.util.*; + +import de.dhbwstuttgart.strucTypes4.Algo.*; +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHFactory; + +public class FrischeVariablenGenerator { + + public List neueConstraints; + public Map mapping; + + + public boolean createWithoutAssumptions(List constraints) { + Map assDummy = new HashMap<>(); + create(constraints,assDummy); + return true; + } + + + + public boolean create(List constraints, Map assumptions) { + + List tuples = new ArrayList<>(); + + List> gruppen = this.sucheGleichConstriants(constraints); + + // um anschaulich zu bleiben anders sortieren + Collections.reverse(gruppen); + + + // Löse Gleichconstraints auf + for (List gruppe : gruppen ) { + String varname = ""; + for (String key : assumptions.keySet() ) { + if (gruppe.contains(assumptions.get(key))) { + varname = key; + } + } + InformationTuple tuple = new InformationTuple(TPHFactory.makeTPHV(), gruppe , "" ,varname ); + tuples.add(tuple); + } + + // Für Zuordnung der neuen Typvariablen zu den alten -> duppelte Einträge werden entfernt + Map mapping = new HashMap<>(); + for (InformationTuple i : tuples) { + for (TPH tph : i.getAlteTypeVar()) { + mapping.put(tph,i); + } + } + + + // Erstelle neue Constriants mit frischen Variablen + ArrayList neueConstraintAbstracts = new ArrayList<>(); + + for (ConstraintAbstract c : constraints) { + + if (c.getClass().equals(ConstraintField.class)) { + ConstraintField cf = (ConstraintField) c; + ConstraintField newCf = new ConstraintField( addNewTPHV(cf.getCaller(),mapping), cf.getNameField() , addNewTPHV(cf.getReceiver() , mapping )); + neueConstraintAbstracts.add(newCf); + } + else if (c.getClass().equals(ConstraintMethod.class)) { + ConstraintMethod cm = (ConstraintMethod) c; + ConstraintMethod newCm = new ConstraintMethod(addNewTPHV(cm.getReceiver(),mapping) , cm.getMethodName() , addNewTPHV(cm.getArgsTypes(),mapping) , addNewTPHV(cm.getReturnType(),mapping) , addNewTPHV(cm.getArgsBetaTypes(),mapping)); + neueConstraintAbstracts.add(newCm); + } + else if (c.getClass().equals(ConstraintSubType.class)) { + ConstraintSubType cs = (ConstraintSubType) c; + ConstraintSubType newCs = new ConstraintSubType(addNewTPHV(cs.getTypeKleiner(),mapping), addNewTPHV(cs.getTypeGroeßer(),mapping)); + neueConstraintAbstracts.add(newCs); + } + } + + // Setze Result + this.mapping = mapping; + this.neueConstraints = neueConstraintAbstracts; + + return true; + } + + /* + Neuer TPHV wird erstellt wenn TPH noch nicht vorhanden ist. Ansonsten wird bereits vergebener Wert zurückgegeben + */ + public TPH addNewTPHV(TPH old, Map mapping) { + if (mapping.containsKey(old)) { + return mapping.get(old).getNewTV(); + } + else { + List oldlist = new ArrayList<>(); + oldlist.add(old); + mapping.put(old, new InformationTuple(TPHFactory.makeTPHV(), oldlist , "" ,"")); + System.out.println(mapping.size()); + return mapping.get(old).getNewTV(); + } + } + + + public List addNewTPHV(List old, Map mapping) { + List neueTPH = new ArrayList<>(); + for (TPH o : old) { + neueTPH.add(addNewTPHV(o,mapping)); + } + return neueTPH; + } + + + + + + public List> sucheGleichConstriants(List constraints) { + + List> tph = new ArrayList<>(); + + List gleichConstraints = new ArrayList<>(); + + // Liste aller Gleichconstriants + for (ConstraintAbstract constriant : constraints) { + if (constriant.getClass().equals(ConstraintGleich.class)) { + ConstraintGleich gc = (ConstraintGleich) constriant; + gleichConstraints.add(gc); + } + } + + // auflösen der Gleichconstraints + for (ConstraintGleich gc : gleichConstraints) { + List a = getGleicheTPH(gc.getTypeB(),gleichConstraints); + List b = getGleicheTPH(gc.getTypeA(),gleichConstraints); + a.addAll(b); + tph.add(b); + + } + return tph; + } + + + // Gibt eine liste zurück die gleiche TPH enthält + public List getGleicheTPH(TPH x, List menge) { + + List tphlist = new ArrayList<>(); + tphlist.add(x); + + for (ConstraintGleich gc : menge) { + if (gc.getTypeA().equals(x)) { + tphlist.add(gc.getTypeA()); + + // Rek. Aufuf + List menge2 = new ArrayList<>(); + menge2.addAll(menge); + menge2.remove(gc); + tphlist.addAll(getGleicheTPH(gc.getTypeB() , menge2)); + } + + if (gc.getTypeB().equals(x)) { + tphlist.add(gc.getTypeB()); + + // Rek. Aufuf + List menge2 = new ArrayList<>(); + menge2.addAll(menge); + menge2.remove(gc); + tphlist.addAll(getGleicheTPH(gc.getTypeA() , menge2)); + } + } + return tphlist; + } +} + diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/InformationTuple.java b/src/de/dhbwstuttgart/strucTypes4/Algo/InformationTuple.java new file mode 100644 index 00000000..40be4850 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/InformationTuple.java @@ -0,0 +1,66 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + + +import java.util.List; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +public class InformationTuple { + + TPH newTV; + List alteTypeVar; + String bekannterType; + String bekannterVarName; + + + public InformationTuple(TPH newTV, List alteTypeVar, String bekannterType, String bekannterVarName) { + this.newTV = newTV; + this.alteTypeVar = alteTypeVar; + this.bekannterType = bekannterType; + this.bekannterVarName = bekannterVarName; + } + + public TPH getNewTV() { + return newTV; + } + + public void setNewTV(TPH newTV) { + this.newTV = newTV; + } + + public List getAlteTypeVar() { + return alteTypeVar; + } + + public void setAlteTypeVar(List alteTypeVar) { + this.alteTypeVar = alteTypeVar; + } + + public String getBekannterType() { + return bekannterType; + } + + public void setBekannterType(String bekannterType) { + this.bekannterType = bekannterType; + } + + public String getBekannterVarName() { + return bekannterVarName; + } + + public void setBekannterVarName(String bekannterVarName) { + this.bekannterVarName = bekannterVarName; + } + + + @Override + public String toString() { + return "InformationTuple{" + + "newTV=" + newTV + + ", alteTypeVar=" + alteTypeVar + + ", bekannterType='" + bekannterType + '\'' + + ", bekannterVarName='" + bekannterVarName + '\'' + + '}'; + } +} + diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/MakeAss.java b/src/de/dhbwstuttgart/strucTypes4/Algo/MakeAss.java new file mode 100644 index 00000000..936729b6 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/MakeAss.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +/** + * Created by sebastian on 08.04.17. + */ +public class MakeAss { +} diff --git a/src/de/dhbwstuttgart/strucTypes4/Algo/TypeExpr.java b/src/de/dhbwstuttgart/strucTypes4/Algo/TypeExpr.java new file mode 100644 index 00000000..1b967f31 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/Algo/TypeExpr.java @@ -0,0 +1,82 @@ +package de.dhbwstuttgart.strucTypes4.Algo; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.syntaxtree.*; +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHwithClass; + +/** + * Created by sebastian on 09.04.17. + */ +public class TypeExpr { + + public static List typeExpr(ExpressionAbstract exp, Map ass , TPH rec , TPH returnType) { + + if (exp.getClass().equals(ExprVar.class )) { + ExprVar exprVar = (ExprVar) exp; + return exprVar.typeExpr(ass); + } + else if (exp.getClass().equals(ExprMCall.class)) { + ExprMCall exprMCall = (ExprMCall) exp; + return exprMCall.typeExpr(ass, rec ,returnType); + } + else if ( exp.getClass().equals(ExprField.class)) { + ExprField exprField = (ExprField) exp; + List constraints = new ArrayList<>(); + constraints.add(new ConstraintField(rec,exprField.getNameField(), returnType)); + return constraints; + + } + else if (exp.getClass().equals(Expression.class)) { + Expression expression = (Expression) exp; + List constraints = new ArrayList<>(); + constraints.addAll(typeExpr(expression.getReceiver(), ass, null ,null )); + constraints.addAll(typeExpr(expression.getCaller(),ass, expression.getReceiver().typePlaceHolder , expression.typePlaceHolder )); + return constraints; + } + else if (exp.getClass().equals(ExprNew.class) ) { + + ExprNew exprNew = (ExprNew) exp; + List constriants = new ArrayList<>(); + + System.out.println(exprNew.getGenerics().toString()); + + String klassenname = exprNew.getClassType(); + String key = new String("$" + klassenname); + TPH tph = ass.get(key); + + + if (ass.containsKey(key)) { + + + TPHwithClass tpHwithClass = (TPHwithClass) tph; + System.out.println("set Class" + exprNew.typePlaceHolder.toString()); + exprNew.typePlaceHolder.setType(tpHwithClass.classTyped); + constriants.addAll(tpHwithClass.classTyped.getConstraints()); + + + // Ersetzen der Generics + Map generic = exprNew.getGenerics(); + for (String gen : generic.keySet()) { + constriants.forEach((ConstraintAbstract cs) -> cs.replace(new TPH(gen) , new TPH(generic.get(gen)) )); + } + + + + + } + else { + // Rückgabe der Leeren Constraints + // ToDo (grenze des programms) + exprNew.typePlaceHolder.setType(new ClassTyped(klassenname)); + + return constriants; + } + return constriants; + } + return null; + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJ.tokens b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJ.tokens new file mode 100644 index 00000000..f4208138 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJ.tokens @@ -0,0 +1,29 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +Class=13 +Token2=14 +Linefeed=15 +WS=16 +'{'=1 +'}'=2 +';'=3 +'<'=4 +','=5 +'>'=6 +'='=7 +'('=8 +')'=9 +'return'=10 +'.'=11 +'new'=12 +'class'=13 diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseListener.java b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseListener.java new file mode 100644 index 00000000..d597672b --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseListener.java @@ -0,0 +1,218 @@ +package de.dhbwstuttgart.strucTypes4.grammar;// Generated from /home/sebastian/Schreibtisch/FLJava/src/FWJ.g4 by ANTLR 4.6 + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ErrorNode; +import org.antlr.v4.runtime.tree.TerminalNode; + +/** + * This class provides an empty implementation of {@link FWJListener}, + * which can be extended to create a listener which only needs to handle a subset + * of the available methods. + */ +public class FWJBaseListener implements FWJListener { + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterSourceFile(FWJParser.SourceFileContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitSourceFile(FWJParser.SourceFileContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterClassX(FWJParser.ClassXContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitClassX(FWJParser.ClassXContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterFeld(FWJParser.FeldContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitFeld(FWJParser.FeldContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterGenerics(FWJParser.GenericsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitGenerics(FWJParser.GenericsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterGeneric(FWJParser.GenericContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitGeneric(FWJParser.GenericContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMethodDecl(FWJParser.MethodDeclContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMethodDecl(FWJParser.MethodDeclContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterReturnExpr(FWJParser.ReturnExprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitReturnExpr(FWJParser.ReturnExprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExprMCall(FWJParser.ExprMCallContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExprMCall(FWJParser.ExprMCallContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExprVar(FWJParser.ExprVarContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExprVar(FWJParser.ExprVarContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExprField(FWJParser.ExprFieldContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExprField(FWJParser.ExprFieldContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExprNew(FWJParser.ExprNewContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExprNew(FWJParser.ExprNewContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExpr(FWJParser.ExprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExpr(FWJParser.ExprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExprMCallArgs(FWJParser.ExprMCallArgsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExprMCallArgs(FWJParser.ExprMCallArgsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterBezeichner(FWJParser.BezeichnerContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitBezeichner(FWJParser.BezeichnerContext ctx) { } + + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void visitTerminal(TerminalNode node) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void visitErrorNode(ErrorNode node) { } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseVisitor.java b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseVisitor.java new file mode 100644 index 00000000..c422985f --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJBaseVisitor.java @@ -0,0 +1,118 @@ +package de.dhbwstuttgart.strucTypes4.grammar;// Generated from /home/sebastian/Schreibtisch/FLJava/src/FWJ.g4 by ANTLR 4.6 +import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; + +/** + * This class provides an empty implementation of {@link FWJVisitor}, + * which can be extended to create a visitor which only needs to handle a subset + * of the available methods. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public class FWJBaseVisitor extends AbstractParseTreeVisitor implements FWJVisitor { + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitSourceFile(FWJParser.SourceFileContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitClassX(FWJParser.ClassXContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitFeld(FWJParser.FeldContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitGenerics(FWJParser.GenericsContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitGeneric(FWJParser.GenericContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMethodDecl(FWJParser.MethodDeclContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitReturnExpr(FWJParser.ReturnExprContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExprMCall(FWJParser.ExprMCallContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExprVar(FWJParser.ExprVarContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExprField(FWJParser.ExprFieldContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExprNew(FWJParser.ExprNewContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExpr(FWJParser.ExprContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExprMCallArgs(FWJParser.ExprMCallArgsContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitBezeichner(FWJParser.BezeichnerContext ctx) { return visitChildren(ctx); } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.java b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.java new file mode 100644 index 00000000..dba31e07 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.java @@ -0,0 +1,125 @@ +package de.dhbwstuttgart.strucTypes4.grammar;// Generated from /home/sebastian/Schreibtisch/FLJava/src/FWJ.g4 by ANTLR 4.6 +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) +public class FWJLexer extends Lexer { + static { RuntimeMetaData.checkVersion("4.6", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, + T__9=10, T__10=11, T__11=12, Class=13, Token2=14, Linefeed=15, WS=16; + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + public static final String[] ruleNames = { + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "T__11", "Class", "Token2", "Linefeed", "WS" + }; + + private static final String[] _LITERAL_NAMES = { + null, "'{'", "'}'", "';'", "'<'", "','", "'>'", "'='", "'('", "')'", "'return'", + "'.'", "'new'", "'class'" + }; + private static final String[] _SYMBOLIC_NAMES = { + null, null, null, null, null, null, null, null, null, null, null, null, + null, "Class", "Token2", "Linefeed", "WS" + }; + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + + public FWJLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "FWJ.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + public static final String _serializedATN = + "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\22[\b\1\4\2\t\2\4"+ + "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+ + "\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\3\2\3\2\3"+ + "\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13\3"+ + "\13\3\13\3\13\3\13\3\13\3\13\3\f\3\f\3\r\3\r\3\r\3\r\3\16\3\16\3\16\3"+ + "\16\3\16\3\16\3\17\6\17J\n\17\r\17\16\17K\3\20\5\20O\n\20\3\20\3\20\3"+ + "\20\3\20\3\21\6\21V\n\21\r\21\16\21W\3\21\3\21\2\2\22\3\3\5\4\7\5\t\6"+ + "\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\35\20\37\21!\22\3\2\4"+ + "\6\2\62;C\\aac|\4\2\13\13\"\"]\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t"+ + "\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2"+ + "\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2"+ + "\37\3\2\2\2\2!\3\2\2\2\3#\3\2\2\2\5%\3\2\2\2\7\'\3\2\2\2\t)\3\2\2\2\13"+ + "+\3\2\2\2\r-\3\2\2\2\17/\3\2\2\2\21\61\3\2\2\2\23\63\3\2\2\2\25\65\3\2"+ + "\2\2\27<\3\2\2\2\31>\3\2\2\2\33B\3\2\2\2\35I\3\2\2\2\37N\3\2\2\2!U\3\2"+ + "\2\2#$\7}\2\2$\4\3\2\2\2%&\7\177\2\2&\6\3\2\2\2\'(\7=\2\2(\b\3\2\2\2)"+ + "*\7>\2\2*\n\3\2\2\2+,\7.\2\2,\f\3\2\2\2-.\7@\2\2.\16\3\2\2\2/\60\7?\2"+ + "\2\60\20\3\2\2\2\61\62\7*\2\2\62\22\3\2\2\2\63\64\7+\2\2\64\24\3\2\2\2"+ + "\65\66\7t\2\2\66\67\7g\2\2\678\7v\2\289\7w\2\29:\7t\2\2:;\7p\2\2;\26\3"+ + "\2\2\2<=\7\60\2\2=\30\3\2\2\2>?\7p\2\2?@\7g\2\2@A\7y\2\2A\32\3\2\2\2B"+ + "C\7e\2\2CD\7n\2\2DE\7c\2\2EF\7u\2\2FG\7u\2\2G\34\3\2\2\2HJ\t\2\2\2IH\3"+ + "\2\2\2JK\3\2\2\2KI\3\2\2\2KL\3\2\2\2L\36\3\2\2\2MO\7\17\2\2NM\3\2\2\2"+ + "NO\3\2\2\2OP\3\2\2\2PQ\7\f\2\2QR\3\2\2\2RS\b\20\2\2S \3\2\2\2TV\t\3\2"+ + "\2UT\3\2\2\2VW\3\2\2\2WU\3\2\2\2WX\3\2\2\2XY\3\2\2\2YZ\b\21\2\2Z\"\3\2"+ + "\2\2\6\2KNW\3\b\2\2"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.tokens b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.tokens new file mode 100644 index 00000000..f4208138 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJLexer.tokens @@ -0,0 +1,29 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +Class=13 +Token2=14 +Linefeed=15 +WS=16 +'{'=1 +'}'=2 +';'=3 +'<'=4 +','=5 +'>'=6 +'='=7 +'('=8 +')'=9 +'return'=10 +'.'=11 +'new'=12 +'class'=13 diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJListener.java b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJListener.java new file mode 100644 index 00000000..fc0533cb --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJListener.java @@ -0,0 +1,159 @@ +package de.dhbwstuttgart.strucTypes4.grammar;// Generated from /home/sebastian/Schreibtisch/FLJava/src/FWJ.g4 by ANTLR 4.6 +import org.antlr.v4.runtime.tree.ParseTreeListener; + +/** + * This interface defines a complete listener for a parse tree produced by + * {@link FWJParser}. + */ +public interface FWJListener extends ParseTreeListener { + /** + * Enter a parse tree produced by {@link FWJParser#sourceFile}. + * @param ctx the parse tree + */ + void enterSourceFile(FWJParser.SourceFileContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#sourceFile}. + * @param ctx the parse tree + */ + void exitSourceFile(FWJParser.SourceFileContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#classX}. + * @param ctx the parse tree + */ + void enterClassX(FWJParser.ClassXContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#classX}. + * @param ctx the parse tree + */ + void exitClassX(FWJParser.ClassXContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#feld}. + * @param ctx the parse tree + */ + void enterFeld(FWJParser.FeldContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#feld}. + * @param ctx the parse tree + */ + void exitFeld(FWJParser.FeldContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#generics}. + * @param ctx the parse tree + */ + void enterGenerics(FWJParser.GenericsContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#generics}. + * @param ctx the parse tree + */ + void exitGenerics(FWJParser.GenericsContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#generic}. + * @param ctx the parse tree + */ + void enterGeneric(FWJParser.GenericContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#generic}. + * @param ctx the parse tree + */ + void exitGeneric(FWJParser.GenericContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#methodDecl}. + * @param ctx the parse tree + */ + void enterMethodDecl(FWJParser.MethodDeclContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#methodDecl}. + * @param ctx the parse tree + */ + void exitMethodDecl(FWJParser.MethodDeclContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#methodDeclArgs}. + * @param ctx the parse tree + */ + void enterMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#methodDeclArgs}. + * @param ctx the parse tree + */ + void exitMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#returnExpr}. + * @param ctx the parse tree + */ + void enterReturnExpr(FWJParser.ReturnExprContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#returnExpr}. + * @param ctx the parse tree + */ + void exitReturnExpr(FWJParser.ReturnExprContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#exprMCall}. + * @param ctx the parse tree + */ + void enterExprMCall(FWJParser.ExprMCallContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#exprMCall}. + * @param ctx the parse tree + */ + void exitExprMCall(FWJParser.ExprMCallContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#exprVar}. + * @param ctx the parse tree + */ + void enterExprVar(FWJParser.ExprVarContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#exprVar}. + * @param ctx the parse tree + */ + void exitExprVar(FWJParser.ExprVarContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#exprField}. + * @param ctx the parse tree + */ + void enterExprField(FWJParser.ExprFieldContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#exprField}. + * @param ctx the parse tree + */ + void exitExprField(FWJParser.ExprFieldContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#exprNew}. + * @param ctx the parse tree + */ + void enterExprNew(FWJParser.ExprNewContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#exprNew}. + * @param ctx the parse tree + */ + void exitExprNew(FWJParser.ExprNewContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#expr}. + * @param ctx the parse tree + */ + void enterExpr(FWJParser.ExprContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#expr}. + * @param ctx the parse tree + */ + void exitExpr(FWJParser.ExprContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#exprMCallArgs}. + * @param ctx the parse tree + */ + void enterExprMCallArgs(FWJParser.ExprMCallArgsContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#exprMCallArgs}. + * @param ctx the parse tree + */ + void exitExprMCallArgs(FWJParser.ExprMCallArgsContext ctx); + /** + * Enter a parse tree produced by {@link FWJParser#bezeichner}. + * @param ctx the parse tree + */ + void enterBezeichner(FWJParser.BezeichnerContext ctx); + /** + * Exit a parse tree produced by {@link FWJParser#bezeichner}. + * @param ctx the parse tree + */ + void exitBezeichner(FWJParser.BezeichnerContext ctx); +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJParser.java b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJParser.java new file mode 100644 index 00000000..65e99b89 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJParser.java @@ -0,0 +1,1196 @@ +package de.dhbwstuttgart.strucTypes4.grammar;// Generated from /home/sebastian/Schreibtisch/FLJava/src/FWJ.g4 by ANTLR 4.6 +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) +public class FWJParser extends Parser { + static { RuntimeMetaData.checkVersion("4.6", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, + T__9=10, T__10=11, T__11=12, Class=13, Token2=14, Linefeed=15, WS=16; + public static final int + RULE_sourceFile = 0, RULE_classX = 1, RULE_feld = 2, RULE_generics = 3, + RULE_generic = 4, RULE_methodDecl = 5, RULE_methodDeclArgs = 6, RULE_returnExpr = 7, + RULE_exprMCall = 8, RULE_exprVar = 9, RULE_exprField = 10, RULE_exprNew = 11, + RULE_expr = 12, RULE_exprMCallArgs = 13, RULE_bezeichner = 14; + public static final String[] ruleNames = { + "sourceFile", "classX", "feld", "generics", "generic", "methodDecl", "methodDeclArgs", + "returnExpr", "exprMCall", "exprVar", "exprField", "exprNew", "expr", + "exprMCallArgs", "bezeichner" + }; + + private static final String[] _LITERAL_NAMES = { + null, "'{'", "'}'", "';'", "'<'", "','", "'>'", "'='", "'('", "')'", "'return'", + "'.'", "'new'", "'class'" + }; + private static final String[] _SYMBOLIC_NAMES = { + null, null, null, null, null, null, null, null, null, null, null, null, + null, "Class", "Token2", "Linefeed", "WS" + }; + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { return "FWJ.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public ATN getATN() { return _ATN; } + + public FWJParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + public static class SourceFileContext extends ParserRuleContext { + public List classX() { + return getRuleContexts(ClassXContext.class); + } + public ClassXContext classX(int i) { + return getRuleContext(ClassXContext.class,i); + } + public SourceFileContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_sourceFile; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterSourceFile(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitSourceFile(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitSourceFile(this); + else return visitor.visitChildren(this); + } + } + + public final SourceFileContext sourceFile() throws RecognitionException { + SourceFileContext _localctx = new SourceFileContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_sourceFile); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(31); + _errHandler.sync(this); + _la = _input.LA(1); + do { + { + { + setState(30); + classX(); + } + } + setState(33); + _errHandler.sync(this); + _la = _input.LA(1); + } while ( _la==Class ); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ClassXContext extends ParserRuleContext { + public TerminalNode Class() { return getToken(FWJParser.Class, 0); } + public BezeichnerContext bezeichner() { + return getRuleContext(BezeichnerContext.class,0); + } + public List feld() { + return getRuleContexts(FeldContext.class); + } + public FeldContext feld(int i) { + return getRuleContext(FeldContext.class,i); + } + public List methodDecl() { + return getRuleContexts(MethodDeclContext.class); + } + public MethodDeclContext methodDecl(int i) { + return getRuleContext(MethodDeclContext.class,i); + } + public ClassXContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_classX; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterClassX(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitClassX(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitClassX(this); + else return visitor.visitChildren(this); + } + } + + public final ClassXContext classX() throws RecognitionException { + ClassXContext _localctx = new ClassXContext(_ctx, getState()); + enterRule(_localctx, 2, RULE_classX); + int _la; + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(35); + match(Class); + setState(36); + bezeichner(); + setState(37); + match(T__0); + setState(41); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,1,_ctx); + while ( _alt!=2 && _alt!= ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(38); + feld(); + } + } + } + setState(43); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,1,_ctx); + } + setState(47); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la==Token2) { + { + { + setState(44); + methodDecl(); + } + } + setState(49); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(50); + match(T__1); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class FeldContext extends ParserRuleContext { + public List bezeichner() { + return getRuleContexts(BezeichnerContext.class); + } + public BezeichnerContext bezeichner(int i) { + return getRuleContext(BezeichnerContext.class,i); + } + public FeldContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_feld; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterFeld(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitFeld(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitFeld(this); + else return visitor.visitChildren(this); + } + } + + public final FeldContext feld() throws RecognitionException { + FeldContext _localctx = new FeldContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_feld); + try { + enterOuterAlt(_localctx, 1); + { + setState(52); + bezeichner(); + setState(53); + bezeichner(); + setState(54); + match(T__2); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class GenericsContext extends ParserRuleContext { + public List generic() { + return getRuleContexts(GenericContext.class); + } + public GenericContext generic(int i) { + return getRuleContext(GenericContext.class,i); + } + public GenericsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_generics; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterGenerics(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitGenerics(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitGenerics(this); + else return visitor.visitChildren(this); + } + } + + public final GenericsContext generics() throws RecognitionException { + GenericsContext _localctx = new GenericsContext(_ctx, getState()); + enterRule(_localctx, 6, RULE_generics); + int _la; + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(56); + match(T__3); + setState(69); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,5,_ctx) ) { + case 1: + { + setState(60); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(57); + generic(); + setState(58); + match(T__4); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(62); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,3,_ctx); + } while ( _alt!=2 && _alt!= ATN.INVALID_ALT_NUMBER ); + setState(64); + generic(); + } + break; + case 2: + { + setState(67); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==Token2) { + { + setState(66); + generic(); + } + } + + } + break; + } + setState(71); + match(T__5); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class GenericContext extends ParserRuleContext { + public List bezeichner() { + return getRuleContexts(BezeichnerContext.class); + } + public BezeichnerContext bezeichner(int i) { + return getRuleContext(BezeichnerContext.class,i); + } + public GenericContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_generic; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterGeneric(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitGeneric(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitGeneric(this); + else return visitor.visitChildren(this); + } + } + + public final GenericContext generic() throws RecognitionException { + GenericContext _localctx = new GenericContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_generic); + try { + enterOuterAlt(_localctx, 1); + { + { + setState(73); + bezeichner(); + setState(74); + match(T__6); + setState(75); + bezeichner(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class MethodDeclContext extends ParserRuleContext { + public BezeichnerContext bezeichner() { + return getRuleContext(BezeichnerContext.class,0); + } + public MethodDeclArgsContext methodDeclArgs() { + return getRuleContext(MethodDeclArgsContext.class,0); + } + public ReturnExprContext returnExpr() { + return getRuleContext(ReturnExprContext.class,0); + } + public MethodDeclContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_methodDecl; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterMethodDecl(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitMethodDecl(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitMethodDecl(this); + else return visitor.visitChildren(this); + } + } + + public final MethodDeclContext methodDecl() throws RecognitionException { + MethodDeclContext _localctx = new MethodDeclContext(_ctx, getState()); + enterRule(_localctx, 10, RULE_methodDecl); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(77); + bezeichner(); + setState(78); + match(T__7); + setState(80); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==Token2) { + { + setState(79); + methodDeclArgs(); + } + } + + setState(82); + match(T__8); + setState(83); + match(T__0); + setState(85); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==T__9) { + { + setState(84); + returnExpr(); + } + } + + setState(87); + match(T__1); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class MethodDeclArgsContext extends ParserRuleContext { + public List bezeichner() { + return getRuleContexts(BezeichnerContext.class); + } + public BezeichnerContext bezeichner(int i) { + return getRuleContext(BezeichnerContext.class,i); + } + public MethodDeclArgsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_methodDeclArgs; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterMethodDeclArgs(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitMethodDeclArgs(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitMethodDeclArgs(this); + else return visitor.visitChildren(this); + } + } + + public final MethodDeclArgsContext methodDeclArgs() throws RecognitionException { + MethodDeclArgsContext _localctx = new MethodDeclArgsContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_methodDeclArgs); + try { + int _alt; + setState(99); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,9,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(89); + bezeichner(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(93); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(90); + bezeichner(); + setState(91); + match(T__4); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(95); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,8,_ctx); + } while ( _alt!=2 && _alt!= ATN.INVALID_ALT_NUMBER ); + setState(97); + bezeichner(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ReturnExprContext extends ParserRuleContext { + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public ReturnExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_returnExpr; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterReturnExpr(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitReturnExpr(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitReturnExpr(this); + else return visitor.visitChildren(this); + } + } + + public final ReturnExprContext returnExpr() throws RecognitionException { + ReturnExprContext _localctx = new ReturnExprContext(_ctx, getState()); + enterRule(_localctx, 14, RULE_returnExpr); + try { + enterOuterAlt(_localctx, 1); + { + setState(101); + match(T__9); + setState(102); + expr(0); + setState(103); + match(T__2); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExprMCallContext extends ParserRuleContext { + public BezeichnerContext bezeichner() { + return getRuleContext(BezeichnerContext.class,0); + } + public ExprMCallArgsContext exprMCallArgs() { + return getRuleContext(ExprMCallArgsContext.class,0); + } + public ExprMCallContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_exprMCall; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterExprMCall(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitExprMCall(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitExprMCall(this); + else return visitor.visitChildren(this); + } + } + + public final ExprMCallContext exprMCall() throws RecognitionException { + ExprMCallContext _localctx = new ExprMCallContext(_ctx, getState()); + enterRule(_localctx, 16, RULE_exprMCall); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(105); + bezeichner(); + setState(106); + match(T__7); + setState(108); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << Token2))) != 0)) { + { + setState(107); + exprMCallArgs(); + } + } + + setState(110); + match(T__8); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExprVarContext extends ParserRuleContext { + public BezeichnerContext bezeichner() { + return getRuleContext(BezeichnerContext.class,0); + } + public ExprVarContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_exprVar; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterExprVar(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitExprVar(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitExprVar(this); + else return visitor.visitChildren(this); + } + } + + public final ExprVarContext exprVar() throws RecognitionException { + ExprVarContext _localctx = new ExprVarContext(_ctx, getState()); + enterRule(_localctx, 18, RULE_exprVar); + try { + enterOuterAlt(_localctx, 1); + { + setState(112); + bezeichner(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExprFieldContext extends ParserRuleContext { + public BezeichnerContext bezeichner() { + return getRuleContext(BezeichnerContext.class,0); + } + public ExprFieldContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_exprField; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterExprField(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitExprField(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitExprField(this); + else return visitor.visitChildren(this); + } + } + + public final ExprFieldContext exprField() throws RecognitionException { + ExprFieldContext _localctx = new ExprFieldContext(_ctx, getState()); + enterRule(_localctx, 20, RULE_exprField); + try { + enterOuterAlt(_localctx, 1); + { + setState(114); + match(T__10); + setState(115); + bezeichner(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExprNewContext extends ParserRuleContext { + public BezeichnerContext bezeichner() { + return getRuleContext(BezeichnerContext.class,0); + } + public GenericsContext generics() { + return getRuleContext(GenericsContext.class,0); + } + public ExprMCallArgsContext exprMCallArgs() { + return getRuleContext(ExprMCallArgsContext.class,0); + } + public ExprNewContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_exprNew; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterExprNew(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitExprNew(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitExprNew(this); + else return visitor.visitChildren(this); + } + } + + public final ExprNewContext exprNew() throws RecognitionException { + ExprNewContext _localctx = new ExprNewContext(_ctx, getState()); + enterRule(_localctx, 22, RULE_exprNew); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(117); + match(T__11); + setState(118); + bezeichner(); + setState(120); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==T__3) { + { + setState(119); + generics(); + } + } + + setState(122); + match(T__7); + setState(124); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << Token2))) != 0)) { + { + setState(123); + exprMCallArgs(); + } + } + + setState(126); + match(T__8); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExprContext extends ParserRuleContext { + public ExprVarContext exprVar() { + return getRuleContext(ExprVarContext.class,0); + } + public ExprFieldContext exprField() { + return getRuleContext(ExprFieldContext.class,0); + } + public ExprMCallContext exprMCall() { + return getRuleContext(ExprMCallContext.class,0); + } + public ExprNewContext exprNew() { + return getRuleContext(ExprNewContext.class,0); + } + public List expr() { + return getRuleContexts(ExprContext.class); + } + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class,i); + } + public ExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_expr; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterExpr(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitExpr(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitExpr(this); + else return visitor.visitChildren(this); + } + } + + public final ExprContext expr() throws RecognitionException { + return expr(0); + } + + private ExprContext expr(int _p) throws RecognitionException { + ParserRuleContext _parentctx = _ctx; + int _parentState = getState(); + ExprContext _localctx = new ExprContext(_ctx, _parentState); + ExprContext _prevctx = _localctx; + int _startState = 24; + enterRecursionRule(_localctx, 24, RULE_expr, _p); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(133); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,13,_ctx) ) { + case 1: + { + setState(129); + exprVar(); + } + break; + case 2: + { + setState(130); + exprField(); + } + break; + case 3: + { + setState(131); + exprMCall(); + } + break; + case 4: + { + setState(132); + exprNew(); + } + break; + } + _ctx.stop = _input.LT(-1); + setState(140); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,14,_ctx); + while ( _alt!=2 && _alt!= ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + if ( _parseListeners!=null ) triggerExitRuleEvent(); + _prevctx = _localctx; + { + { + _localctx = new ExprContext(_parentctx, _parentState); + pushNewRecursionContext(_localctx, _startState, RULE_expr); + setState(135); + if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)"); + setState(136); + match(T__10); + setState(137); + expr(5); + } + } + } + setState(142); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,14,_ctx); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + unrollRecursionContexts(_parentctx); + } + return _localctx; + } + + public static class ExprMCallArgsContext extends ParserRuleContext { + public List expr() { + return getRuleContexts(ExprContext.class); + } + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class,i); + } + public ExprMCallArgsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_exprMCallArgs; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterExprMCallArgs(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitExprMCallArgs(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitExprMCallArgs(this); + else return visitor.visitChildren(this); + } + } + + public final ExprMCallArgsContext exprMCallArgs() throws RecognitionException { + ExprMCallArgsContext _localctx = new ExprMCallArgsContext(_ctx, getState()); + enterRule(_localctx, 26, RULE_exprMCallArgs); + try { + int _alt; + setState(153); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,16,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(143); + expr(0); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(147); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(144); + expr(0); + setState(145); + match(T__4); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(149); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,15,_ctx); + } while ( _alt!=2 && _alt!= ATN.INVALID_ALT_NUMBER ); + setState(151); + expr(0); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class BezeichnerContext extends ParserRuleContext { + public TerminalNode Token2() { return getToken(FWJParser.Token2, 0); } + public BezeichnerContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_bezeichner; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).enterBezeichner(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof FWJListener ) ((FWJListener)listener).exitBezeichner(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof FWJVisitor ) return ((FWJVisitor)visitor).visitBezeichner(this); + else return visitor.visitChildren(this); + } + } + + public final BezeichnerContext bezeichner() throws RecognitionException { + BezeichnerContext _localctx = new BezeichnerContext(_ctx, getState()); + enterRule(_localctx, 28, RULE_bezeichner); + try { + enterOuterAlt(_localctx, 1); + { + setState(155); + match(Token2); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { + switch (ruleIndex) { + case 12: + return expr_sempred((ExprContext)_localctx, predIndex); + } + return true; + } + private boolean expr_sempred(ExprContext _localctx, int predIndex) { + switch (predIndex) { + case 0: + return precpred(_ctx, 4); + } + return true; + } + + public static final String _serializedATN = + "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\22\u00a0\4\2\t\2"+ + "\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+ + "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\3\2\6\2\"\n\2\r\2"+ + "\16\2#\3\3\3\3\3\3\3\3\7\3*\n\3\f\3\16\3-\13\3\3\3\7\3\60\n\3\f\3\16\3"+ + "\63\13\3\3\3\3\3\3\4\3\4\3\4\3\4\3\5\3\5\3\5\3\5\6\5?\n\5\r\5\16\5@\3"+ + "\5\3\5\3\5\5\5F\n\5\5\5H\n\5\3\5\3\5\3\6\3\6\3\6\3\6\3\7\3\7\3\7\5\7S"+ + "\n\7\3\7\3\7\3\7\5\7X\n\7\3\7\3\7\3\b\3\b\3\b\3\b\6\b`\n\b\r\b\16\ba\3"+ + "\b\3\b\5\bf\n\b\3\t\3\t\3\t\3\t\3\n\3\n\3\n\5\no\n\n\3\n\3\n\3\13\3\13"+ + "\3\f\3\f\3\f\3\r\3\r\3\r\5\r{\n\r\3\r\3\r\5\r\177\n\r\3\r\3\r\3\16\3\16"+ + "\3\16\3\16\3\16\5\16\u0088\n\16\3\16\3\16\3\16\7\16\u008d\n\16\f\16\16"+ + "\16\u0090\13\16\3\17\3\17\3\17\3\17\6\17\u0096\n\17\r\17\16\17\u0097\3"+ + "\17\3\17\5\17\u009c\n\17\3\20\3\20\3\20\2\3\32\21\2\4\6\b\n\f\16\20\22"+ + "\24\26\30\32\34\36\2\2\u00a3\2!\3\2\2\2\4%\3\2\2\2\6\66\3\2\2\2\b:\3\2"+ + "\2\2\nK\3\2\2\2\fO\3\2\2\2\16e\3\2\2\2\20g\3\2\2\2\22k\3\2\2\2\24r\3\2"+ + "\2\2\26t\3\2\2\2\30w\3\2\2\2\32\u0087\3\2\2\2\34\u009b\3\2\2\2\36\u009d"+ + "\3\2\2\2 \"\5\4\3\2! \3\2\2\2\"#\3\2\2\2#!\3\2\2\2#$\3\2\2\2$\3\3\2\2"+ + "\2%&\7\17\2\2&\'\5\36\20\2\'+\7\3\2\2(*\5\6\4\2)(\3\2\2\2*-\3\2\2\2+)"+ + "\3\2\2\2+,\3\2\2\2,\61\3\2\2\2-+\3\2\2\2.\60\5\f\7\2/.\3\2\2\2\60\63\3"+ + "\2\2\2\61/\3\2\2\2\61\62\3\2\2\2\62\64\3\2\2\2\63\61\3\2\2\2\64\65\7\4"+ + "\2\2\65\5\3\2\2\2\66\67\5\36\20\2\678\5\36\20\289\7\5\2\29\7\3\2\2\2:"+ + "G\7\6\2\2;<\5\n\6\2<=\7\7\2\2=?\3\2\2\2>;\3\2\2\2?@\3\2\2\2@>\3\2\2\2"+ + "@A\3\2\2\2AB\3\2\2\2BC\5\n\6\2CH\3\2\2\2DF\5\n\6\2ED\3\2\2\2EF\3\2\2\2"+ + "FH\3\2\2\2G>\3\2\2\2GE\3\2\2\2HI\3\2\2\2IJ\7\b\2\2J\t\3\2\2\2KL\5\36\20"+ + "\2LM\7\t\2\2MN\5\36\20\2N\13\3\2\2\2OP\5\36\20\2PR\7\n\2\2QS\5\16\b\2"+ + "RQ\3\2\2\2RS\3\2\2\2ST\3\2\2\2TU\7\13\2\2UW\7\3\2\2VX\5\20\t\2WV\3\2\2"+ + "\2WX\3\2\2\2XY\3\2\2\2YZ\7\4\2\2Z\r\3\2\2\2[f\5\36\20\2\\]\5\36\20\2]"+ + "^\7\7\2\2^`\3\2\2\2_\\\3\2\2\2`a\3\2\2\2a_\3\2\2\2ab\3\2\2\2bc\3\2\2\2"+ + "cd\5\36\20\2df\3\2\2\2e[\3\2\2\2e_\3\2\2\2f\17\3\2\2\2gh\7\f\2\2hi\5\32"+ + "\16\2ij\7\5\2\2j\21\3\2\2\2kl\5\36\20\2ln\7\n\2\2mo\5\34\17\2nm\3\2\2"+ + "\2no\3\2\2\2op\3\2\2\2pq\7\13\2\2q\23\3\2\2\2rs\5\36\20\2s\25\3\2\2\2"+ + "tu\7\r\2\2uv\5\36\20\2v\27\3\2\2\2wx\7\16\2\2xz\5\36\20\2y{\5\b\5\2zy"+ + "\3\2\2\2z{\3\2\2\2{|\3\2\2\2|~\7\n\2\2}\177\5\34\17\2~}\3\2\2\2~\177\3"+ + "\2\2\2\177\u0080\3\2\2\2\u0080\u0081\7\13\2\2\u0081\31\3\2\2\2\u0082\u0083"+ + "\b\16\1\2\u0083\u0088\5\24\13\2\u0084\u0088\5\26\f\2\u0085\u0088\5\22"+ + "\n\2\u0086\u0088\5\30\r\2\u0087\u0082\3\2\2\2\u0087\u0084\3\2\2\2\u0087"+ + "\u0085\3\2\2\2\u0087\u0086\3\2\2\2\u0088\u008e\3\2\2\2\u0089\u008a\f\6"+ + "\2\2\u008a\u008b\7\r\2\2\u008b\u008d\5\32\16\7\u008c\u0089\3\2\2\2\u008d"+ + "\u0090\3\2\2\2\u008e\u008c\3\2\2\2\u008e\u008f\3\2\2\2\u008f\33\3\2\2"+ + "\2\u0090\u008e\3\2\2\2\u0091\u009c\5\32\16\2\u0092\u0093\5\32\16\2\u0093"+ + "\u0094\7\7\2\2\u0094\u0096\3\2\2\2\u0095\u0092\3\2\2\2\u0096\u0097\3\2"+ + "\2\2\u0097\u0095\3\2\2\2\u0097\u0098\3\2\2\2\u0098\u0099\3\2\2\2\u0099"+ + "\u009a\5\32\16\2\u009a\u009c\3\2\2\2\u009b\u0091\3\2\2\2\u009b\u0095\3"+ + "\2\2\2\u009c\35\3\2\2\2\u009d\u009e\7\20\2\2\u009e\37\3\2\2\2\23#+\61"+ + "@EGRWaenz~\u0087\u008e\u0097\u009b"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/grammar/FWJVisitor.java b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJVisitor.java new file mode 100644 index 00000000..06207d07 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/grammar/FWJVisitor.java @@ -0,0 +1,102 @@ +package de.dhbwstuttgart.strucTypes4.grammar;// Generated from /home/sebastian/Schreibtisch/FLJava/src/FWJ.g4 by ANTLR 4.6 +import org.antlr.v4.runtime.tree.ParseTreeVisitor; + +/** + * This interface defines a complete generic visitor for a parse tree produced + * by {@link FWJParser}. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public interface FWJVisitor extends ParseTreeVisitor { + /** + * Visit a parse tree produced by {@link FWJParser#sourceFile}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitSourceFile(FWJParser.SourceFileContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#classX}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitClassX(FWJParser.ClassXContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#feld}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFeld(FWJParser.FeldContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#generics}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitGenerics(FWJParser.GenericsContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#generic}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitGeneric(FWJParser.GenericContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#methodDecl}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMethodDecl(FWJParser.MethodDeclContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#methodDeclArgs}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#returnExpr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitReturnExpr(FWJParser.ReturnExprContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#exprMCall}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExprMCall(FWJParser.ExprMCallContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#exprVar}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExprVar(FWJParser.ExprVarContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#exprField}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExprField(FWJParser.ExprFieldContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#exprNew}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExprNew(FWJParser.ExprNewContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExpr(FWJParser.ExprContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#exprMCallArgs}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExprMCallArgs(FWJParser.ExprMCallArgsContext ctx); + /** + * Visit a parse tree produced by {@link FWJParser#bezeichner}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBezeichner(FWJParser.BezeichnerContext ctx); +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/parser/Parser.java b/src/de/dhbwstuttgart/strucTypes4/parser/Parser.java new file mode 100644 index 00000000..e3f171a1 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/parser/Parser.java @@ -0,0 +1,56 @@ +package de.dhbwstuttgart.strucTypes4.parser; + +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.tree.ParseTreeWalker; + +/** + * Created by sebastian on 07.04.17. + */ +/* +public class Parser { + + + + public void parse(String quellcode) { + + ANTLRInputStream inputStream = new ANTLRInputStream(quellcode); + FLJLexer lexer = new FLJLexer(inputStream); + + // Fehler + + + + CommonTokenStream tokens = new CommonTokenStream(lexer); + FLJParser parser = new FLJParser(tokens); + ParserRuleContext tree = parser.l2(); + ParseTreeWalker walker = new ParseTreeWalker(); + + SourceFileWalker sourceFileWalker = new SourceFileWalker(); + + walker.walk(sourceFileWalker,tree); + + String res = sourceFileWalker.sourceFile.toString(); + System.out.println(res); + + + + + + //L2Walker nummerGesamtWalker = new NummerGesamtWalker(laendercode); + //walker.walk(nummerGesamtWalker, tree); + + + + + + //System.out.println(nummerGesamtWalker.toString().replace("\n" , " - ")); + //return new String[]{nummerGesamtWalker.lv, nummerGesamtWalker.ov, nummerGesamtWalker.hn, nummerGesamtWalker.dw}; + + + } + + +} + +*/ + diff --git a/src/de/dhbwstuttgart/strucTypes4/parser/SourceFileWalker.java b/src/de/dhbwstuttgart/strucTypes4/parser/SourceFileWalker.java new file mode 100644 index 00000000..9dcc9956 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/parser/SourceFileWalker.java @@ -0,0 +1,72 @@ +package de.dhbwstuttgart.strucTypes4.parser; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.strucTypes4.syntaxtree.Class; +import de.dhbwstuttgart.strucTypes4.syntaxtree.Field; +import de.dhbwstuttgart.strucTypes4.syntaxtree.Method; +import de.dhbwstuttgart.strucTypes4.syntaxtree.SourceFile; + +/** + * Created by sebastian on 07.04.17. + */ +/* +public class SourceFileWalker extends FWJBaseListener { + + + SourceFile sourceFile = null; + List felder = new ArrayList<>(); + List methods = new ArrayList<>(); + List klassen = new ArrayList<>(); + + + + + + @Override + public void enterL(FLJParser.LContext ctx) { + System.out.println(ctx.ClassName().getText()); + + + super.enterL(ctx); + } + + + @Override + public void enterFeld(FLJParser.FeldContext ctx) { + super.enterFeld(ctx); + + //ToDo: Check einführen + Field field = new Field( ctx.ClassName().getText() , ctx.Var().getText() ); + felder.add(field); + + } + + @Override + public void enterMethod(FLJParser.MethodContext ctx) { + super.enterMethod(ctx); + + + Method method = new Method(ctx.Var().toString() , null, null ,ctx.getText() ); + methods.add(method); + + } + + + @Override + public void exitL(FLJParser.LContext ctx) { + super.exitL(ctx); + Class cl = new Class(ctx.ClassName().getText().toString() , felder,methods); + felder = new ArrayList<>(); + methods = new ArrayList<>(); + klassen.add(cl); + } + + @Override + public void exitL2(FLJParser.L2Context ctx) { + super.exitL2(ctx); + sourceFile = new SourceFile(klassen); + } +} +*/ \ No newline at end of file diff --git a/src/de/dhbwstuttgart/strucTypes4/parserFWJ/Parser.java b/src/de/dhbwstuttgart/strucTypes4/parserFWJ/Parser.java new file mode 100644 index 00000000..bbe476af --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/parserFWJ/Parser.java @@ -0,0 +1,178 @@ +package de.dhbwstuttgart.strucTypes4.parserFWJ; + +import com.sun.org.apache.xpath.internal.Arg; + +import de.dhbwstuttgart.strucTypes4.Algo.*; +import de.dhbwstuttgart.strucTypes4.grammar.FWJLexer; +import de.dhbwstuttgart.strucTypes4.grammar.FWJParser; +import de.dhbwstuttgart.strucTypes4.syntaxtree.*; +import de.dhbwstuttgart.strucTypes4.syntaxtree.Class; +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ParseTreeWalker; + +import java.util.*; + +/** + * Created by sebastian on 07.04.17. + */ + +public class Parser { + + public SourceFile parse(String quellcode) { + + ANTLRInputStream inputStream = new ANTLRInputStream(quellcode); + FWJLexer lexer = new FWJLexer(inputStream); + + + CommonTokenStream tokens = new CommonTokenStream(lexer); + FWJParser parser = new FWJParser(tokens); + ParserRuleContext tree = parser.sourceFile(); + ParseTreeWalker walker = new ParseTreeWalker(); + + SourceFileWalker sourceFileWalker = new SourceFileWalker(); + + walker.walk(sourceFileWalker, tree); + + return sourceFileWalker.getSourceFile(); + } + + + + + + // Testmethode + public ClassTyped parseCode(String quellcode) { + SourceFile sf = parse(quellcode); + Map assumptions = new HashMap<>(); + TI typeinference = new TI(assumptions,sf.getClassList().get(0)); + return typeinference.getResultClassTypedWithInterfaces(); + } + + + public ClassTyped parseCode(String quellcode , Map ass ) { + SourceFile sf = parse(quellcode); + TI typeinference = new TI(ass,sf.getClassList().get(0)); + return typeinference.getResultClassTypedWithInterfaces(); + } + + +} + + + +// - ----------- Ab hier der Type AlgoRythmus + + + +class TI { + + ClassTyped resultClassTypedWithInterfaces; + + public TI (Map ass, Class aClass) { + + Type type = new Type(ass,aClass); + + Construct construct = new Construct(type.resultConstraintSet); + //construct.constructInterfaces(type.resultConstraintSet,type.resultClassTyped ); + List interfaces = construct.getResultInterfaces(); + + //System.out.println(interfaces); + + //Construct construct2 = new Construct(type.resultConstraintSet, type.resultClassTyped); + + //ClassTyped classTypedWithInterfaces = construct2.getResultClassTypedWithInterfaces(); + + + Set generics = new HashSet<>(); + + // Typen der Methoden + List typesArg = new ArrayList<>(); + for (Method m : aClass.getMethoden()) { + for (Argument arg : m.getArgs()) { + typesArg.add(arg.typePlaceHolder); + generics.add(m.getExpression().typePlaceHolder); + } + } + + // Erstellen der Generics - Muss aus den Constraints von den interfaces ausgeführt werden + Set genericsSet = new HashSet<>(); + for (ConstraintAbstract t : construct.getResultConstraints()) { + genericsSet.addAll(t.getAllReceiver()); + } + + + + + // Nur die Arg die tatsälich benutzt werden + for (TPH tph : typesArg) { + if (genericsSet.contains(tph)) { + generics.add(tph); + } + } + + // Generics Ressult + List genericsResult = new ArrayList<>(); + genericsResult.addAll(generics); + + + + //#### Zwischenergebnis + ClassTyped classTyped = new ClassTyped(interfaces, type.resultClassTyped , genericsResult , construct.getResultConstraints()); + System.out.println("__________________________________"); + System.out.println(classTyped.toString()); + System.out.println("__________________________________"); + + + // Solve muss Hier eingefügt werden + + resultClassTypedWithInterfaces = classTyped; + } + + public ClassTyped getResultClassTypedWithInterfaces() { + return resultClassTypedWithInterfaces; + } +} + + + + +class Type { + + Class resultClassTyped; + List resultConstraintSet = new ArrayList<>(); + + public Type(Map ass, Class aClass) { + + // 1. Erstellen der Assumptions für die Klasse + Map fass_mass = aClass.makeAssumptions(); + + // ToDo Vereinigen der Assumptions + fass_mass.putAll(ass); + + + + // 2. Erstellen der classTyped + // Eigentlich die Kombination aus Assumptions, Class TPH und ConstriantSet + resultClassTyped = aClass; + + + // 3. Erstellen des Constraint Sets + for (Method method : aClass.getMethoden()) { + + // AssAll Ass und fass und mass und this:A + // ToDo this:a + Map assMethod = method.makeAssumptions(); + + assMethod.putAll(fass_mass); + resultConstraintSet.addAll(method.typeExpr(assMethod)); + + } + } +} + + + diff --git a/src/de/dhbwstuttgart/strucTypes4/parserFWJ/SourceFileWalker.java b/src/de/dhbwstuttgart/strucTypes4/parserFWJ/SourceFileWalker.java new file mode 100644 index 00000000..a9aa3868 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/parserFWJ/SourceFileWalker.java @@ -0,0 +1,280 @@ +package de.dhbwstuttgart.strucTypes4.parserFWJ; + +import org.antlr.v4.runtime.tree.ParseTreeWalker; + +import de.dhbwstuttgart.strucTypes4.grammar.FWJBaseListener; +import de.dhbwstuttgart.strucTypes4.grammar.FWJParser; +import de.dhbwstuttgart.strucTypes4.syntaxtree.*; +import de.dhbwstuttgart.strucTypes4.syntaxtree.Class; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by sebastian on 07.04.17. + */ + +public class SourceFileWalker extends FWJBaseListener { + + + SourceFile sourceFile = null; + private List felder = new ArrayList<>(); + private List methods = new ArrayList<>(); + private List klassen = new ArrayList<>(); + + private List methodenArgs = new ArrayList<>(); + + + + // Rein Informell + @Override + public void enterClassX(FWJParser.ClassXContext ctx) { + super.enterClassX(ctx); + System.out.println(ctx.getText()); + + } + + // Feldparser + @Override + public void exitFeld(FWJParser.FeldContext ctx) { + super.exitFeld(ctx); + //ToDo momentan nur typ und var + felder.add(new Field(ctx.bezeichner(0).getText() , ctx.bezeichner(1).getText())); + } + + // MethodenParser + @Override + public void exitMethodDecl(FWJParser.MethodDeclContext ctx) { + super.exitMethodDecl(ctx); + // Methode Implementieren + + + List argList = new ArrayList<>(); + + ParseTreeWalker ptl = new ParseTreeWalker(); + + //for (ctx.methodDeclArgs().getToken()) + Method method = new Method(ctx.bezeichner().getText() ,"returnType:", methodenArgs , ExpressAdapter.adapt(ctx.returnExpr().expr())); + methods.add(method); + methodenArgs = new ArrayList<>(); + } + + // Parser für Argumente der Methode + @Override + public void exitMethodDeclArgs(FWJParser.MethodDeclArgsContext ctx) { + super.exitMethodDeclArgs(ctx); + + ParseTreeWalker walker = new ParseTreeWalker(); + walker.walk(new FWJBaseListener(){ + @Override + public void exitBezeichner(FWJParser.BezeichnerContext ctx) { + super.exitBezeichner(ctx); + methodenArgs.add(new Argument(ctx.getText())); + } + } , ctx); + } + + + + // Parser der Return exprression + + + /* + @Override + public void exitReturnExpr(FWJParser.ReturnExprContext ctx) { + super.exitReturnExpr(ctx); + ExpressionAbstract exp = ExpressAdapter.adapt(ctx.expr()); + } + */ + + @Override + public void exitClassX(FWJParser.ClassXContext ctx) { + super.exitClassX(ctx); + // Klasse in SourceFile schreiben + // Variablen löschen + Class cl = new Class(ctx.bezeichner().getText(),felder,methods); + felder = new ArrayList<>(); + methods = new ArrayList<>(); + klassen.add(cl); + } + + + @Override + public void exitSourceFile(FWJParser.SourceFileContext ctx) { + super.exitSourceFile(ctx); + // Parsevorgang beendet + sourceFile = new SourceFile(klassen); + + } + + + public SourceFile getSourceFile() { + return sourceFile; + } +} + + + +// Diese Idee hat nich funktioniert +/* +class ExprWalker2 extends FWJBaseListener { + + + List rtExpressionStore; + + List rtExpression = new ArrayList<>(); + List> mtCallExpressions = new ArrayList<>(); + + + @Override + public void exitExprVar(FWJParser.ExprVarContext ctx) { + super.exitExprVar(ctx); + rtExpression.add(new ExprVar(ctx.bezeichner().getText())); + System.out.println(rtExpression.toString()); + } + + + @Override + public void exitExprField(FWJParser.ExprFieldContext ctx) { + super.exitExprField(ctx); + rtExpression.add(new ExprField(ctx.bezeichner().getText())); + } + + + @Override + public void enterExprMCallArgs(FWJParser.ExprMCallArgsContext ctx) { + super.enterExprMCallArgs(ctx); + rtExpressionStore = rtExpression; + rtExpression = new ArrayList<>(); + } + + @Override + public void exitExprMCallArgs(FWJParser.ExprMCallArgsContext ctx) { + super.exitExprMCallArgs(ctx); + List l = rtExpression; + mtCallExpressions.add(l); + rtExpression = rtExpressionStore; + } + + @Override + public void exitExprMCall(FWJParser.ExprMCallContext ctx) { + super.exitExprMCall(ctx); + + List ex = new ArrayList<>(); + //wenn keine parameter + if (mtCallExpressions.size() != 0) { + ex = mtCallExpressions.get(mtCallExpressions.size() - 1); + } + rtExpression.add(new ExprMCall(ctx.bezeichner().getText(), ex)); + } + + + @Override + public void exitExprNew(FWJParser.ExprNewContext ctx) { + super.exitExprNew(ctx); + System.err.println("Fehler"); + } +} +*/ + +/* Beispiel, wird nicht benötigt : + +class ExprWalker extends FWJBaseListener{ + + List rtExpression = new ArrayList<>(); + + @Override + public void exitExpr(FWJParser.ExprContext ctx) { + super.exitExpr(ctx); + System.out.println("aussere klasse "+ ctx.getText()); + } + + @Override + public void enterExprMCallArgs(FWJParser.ExprMCallArgsContext ctx) { + super.enterExprMCallArgs(ctx); + + ParseTreeWalker walter = new ParseTreeWalker(); + walter.walk(new FWJBaseListener() { + + @Override + public void exitExpr(FWJParser.ExprContext ctx) { + super.exitExpr(ctx); + System.out.println("Innere Klasse: " + ctx.getText()); + } + },ctx ); + } +} +*/ + + + + + + + + + + + +// Parst die Expression und erstellt eine Rekursive Datenstruktur +class ExpressAdapter { + + public static ExpressionAbstract adapt(FWJParser.ExprContext ctx) { + + if (ctx.expr() != null ) { + if (ctx.expr().size() == 1) { + return adapt(ctx.expr(0)); + } + else if (ctx.expr().size() == 2) { + ExpressionAbstract receiver = adapt(ctx.expr(0)); + ExpressionAbstract caller = adapt(ctx.expr(1)); + Expression ex = new Expression(receiver,caller); + return ex; + } + else if (ctx.exprVar() != null) { + return new ExprVar(ctx.exprVar().getText()); + } + else if (ctx.exprField() != null ) { + return new ExprField(ctx.exprField().bezeichner().getText()); + } + else if (ctx.exprMCall() != null) { + List args = new ArrayList<>(); + if (ctx.exprMCall().exprMCallArgs() != null ) { + if (ctx.exprMCall().exprMCallArgs().expr() != null) { + for (FWJParser.ExprContext exp : ctx.exprMCall().exprMCallArgs().expr()) { + args.add(adapt(exp)); + } + } + } + return new ExprMCall(ctx.exprMCall().bezeichner().getText() , args); + } + else if (ctx.exprNew() != null) { + + // Argumente + List args = new ArrayList<>(); + if (ctx.exprNew().exprMCallArgs() != null) { + if (ctx.exprNew().exprMCallArgs().expr() != null) { + for (FWJParser.ExprContext exp : ctx.exprNew().exprMCallArgs().expr()) { + args.add((adapt(exp))); + } + } + } + + //Generics + // Zugriff erfolgt äquivalent zu den Argumenten + Map generics = new HashMap<>(); + if (ctx.exprNew().generics() != null) { + if (ctx.exprNew().generics().generic() != null) { + for (FWJParser.GenericContext genericContext : ctx.exprNew().generics().generic()) { + generics.put(genericContext.bezeichner(0).getText() , genericContext.bezeichner(1).getText()); + } + } + } + return new ExprNew(ctx.exprNew().bezeichner().getText() , generics, args); + } + } + return null; + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Argument.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Argument.java new file mode 100644 index 00000000..1d9d3000 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Argument.java @@ -0,0 +1,36 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +/** + * Created by sebastian on 09.04.17. + */ +public class Argument extends SyntaxNode { + + String name; + + public Argument(String name) { + this.name = name; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String toString() { + return name; + } + + + + public String toCodeTyped() { + return String.format("%s : %s " , name , typePlaceHolder ); + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Class.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Class.java new file mode 100644 index 00000000..2852b178 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Class.java @@ -0,0 +1,104 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 07.04.17. + */ +public class Class extends SyntaxNode{ + + + String name; + List felder; + List methoden; + + + public Class(String name, List felder , List methoden) { + this.name = name; + this.felder = felder; + this.methoden = methoden; + } + + + public Map makeAssumptions() { + + // Name bei Feldern feld, name bei methoden methode() + Map ass = new HashMap<>(); + // felder + for (Field f : felder) { + ass.put(f.getVar_name() , f.typePlaceHolder); + } + + // methoden + for (Method m : methoden) { + ass.put(m.getName()+"()", m.typePlaceHolder ); + } + + // This einfügen + ass.put("this" , typePlaceHolder); + + return ass; + } + + + + public List getFelder() { + return felder; + } + + public void setFelder(List felder) { + this.felder = felder; + } + + public List getMethoden() { + return methoden; + } + + public void setMethoden(List methoden) { + this.methoden = methoden; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + String res = "class " + name + " \n"; + for (Field f : felder) { + res = res.concat(f.toString() + "\n"); + } + + for (Method m : methoden) { + res = res.concat(m.toString() + "\n"); + } + return res; + } + + + + public String toCodeTyped() { + String res = "class " + name + " \n"; + for (Field f : felder) { + res = res.concat(f.toCodeTyped() + "\n"); + } + + for (Method m : methoden) { + res = res.concat(m.toCodeTyped() + "\n"); + } + return res; + } + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ClassTyped.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ClassTyped.java new file mode 100644 index 00000000..2c0d023e --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ClassTyped.java @@ -0,0 +1,90 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.strucTypes4.Algo.ConstraintAbstract; +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class ClassTyped { + + List implementedInterfaces; + Class aClass; + List generics; + List constraints; + + + public ClassTyped(List implementedInterfaces, Class aClass, List generics, List constraints) { + this.implementedInterfaces = implementedInterfaces; + this.aClass = aClass; + this.generics = generics; + this.constraints = constraints; + } + + // Dummy Konstruktor + public ClassTyped(String name) { + this.implementedInterfaces = new ArrayList<>(); + this.aClass = new Class(name,new ArrayList<>(), new ArrayList<>()); + this.generics = new ArrayList<>(); + this.constraints = new ArrayList<>(); + } + + + + @Override + public String toString() { + return String.format( "Class Typed - \n " + + "// Interfaces: \n %s \n " + + "// Generics %s \n " + + "// Constraints %s \n " + + "%s " , implementedInterfaces.toString(), generics.toString() , constraints.toString() , aClass.toString() ); + } + + + public String toCodeTyped() { + return String.format( "Class Code Typed - \n " + + "// Interfaces: \n %s \n " + + "// Generics %s \n " + + "// Constraints %s \n " + + "%s " , implementedInterfaces.toString(), generics.toString() , constraints.toString() , aClass.toCodeTyped() ); + } + + + + + + public List getImplementedInterfaces() { + return implementedInterfaces; + } + + public void setImplementedInterfaces(List implementedInterfaces) { + this.implementedInterfaces = implementedInterfaces; + } + + public Class getaClass() { + return aClass; + } + + public void setaClass(Class aClass) { + this.aClass = aClass; + } + + public List getGenerics() { + return generics; + } + + public void setGenerics(List generics) { + this.generics = generics; + } + + public List getConstraints() { + return constraints; + } + + public void setConstraints(List constraints) { + this.constraints = constraints; + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprField.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprField.java new file mode 100644 index 00000000..a9c9b7bf --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprField.java @@ -0,0 +1,42 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.List; + +import de.dhbwstuttgart.strucTypes4.Algo.ConstraintGleich; + +/** + * Created by sebastian on 07.04.17. + */ +public class ExprField extends ExpressionAbstract { + + String nameField; + + + public List typeExpr( ) { + return null; + } + + + public ExprField(String nameField) { + this.nameField = nameField; + } + + public String getNameField() { + return nameField; + } + + public void setNameField(String nameField) { + this.nameField = nameField; + } + + @Override + public String toString() { + return "." + nameField; + } + + + @Override + public String toCodeTyped() { + return "." + nameField; + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprMCall.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprMCall.java new file mode 100644 index 00000000..e8462d31 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprMCall.java @@ -0,0 +1,116 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.Algo.*; +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHFactory; + +/** + * Created by sebastian on 07.04.17. + */ +public class ExprMCall extends ExpressionAbstract { + + String name; + List args; + + public ExprMCall(String name, List args) { + this.name = name; + this.args = args; + } + + + public List typeExpr (Map ass , TPH receiver , TPH returnType) { + List constraints = new ArrayList<>(); + + + // Receivertyp ist keine TypVariable + if (receiver.getType() != null) { + + Class aclass = receiver.getType().aClass; + + + // Typeexpr Der Argumente der Methode + args.forEach(x -> constraints.addAll( TypeExpr.typeExpr( x,ass,null,null) )); + + + // Methode m-Type für neuen Constraint für argument typen der Methode mt hinzu + + for (Method m : aclass.getMethoden()) { + if (m.getName().equals(name)) { + int i = 0; + for (Argument arg : m.getArgs() ) { + String type = args.get(i).typePlaceHolder.getType().aClass.name; + i++; + constraints.add(new ConstraintSubType(new TPH(type) ,arg.typePlaceHolder )); + } + } + } + + + //constraints.add( new ConstraintMethod(receiver , name, types , returnType , betaTypes )); + return constraints; + + } + // Receivertyp ist TypVariable + else { + + // Typeexpr Der Argumente der Methode + args.forEach(x -> constraints.addAll( TypeExpr.typeExpr( x,ass,null,null) )); + + // Liste mit Typen der Argumente der Methode sammeln + List types = new ArrayList<>(); + args.forEach(x -> types.add(x.typePlaceHolder)); + + // Neue Liste mit neuen Beta - Argumenten erstellen + List betaTypes = new ArrayList<>(); + args.forEach(x -> betaTypes.add( TPHFactory.makeTPH())); + + + // Erstellen der Substyp constraints + for (int i = 0 ; i < types.size() ; i++) { + ConstraintSubType con = new ConstraintSubType(types.get(i) , betaTypes.get(i) ); + constraints.add(con); + } + + constraints.add( new ConstraintMethod(receiver , name, types , returnType , betaTypes )); + return constraints; + + } + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getArgs() { + return args; + } + + public void setArgs(List args) { + this.args = args; + } + + @Override + public String toString() { + return "." + name + "(" + args.toString() +")"; + } + + + @Override + public String toCodeTyped() { + String argsString = ""; + for (ExpressionAbstract a : args) { + argsString = argsString.concat(a.toCodeTyped()); + } + + return String.format(" .%s ( %s )" , name , argsString ); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprNew.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprNew.java new file mode 100644 index 00000000..4bfdb3d1 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprNew.java @@ -0,0 +1,61 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.List; +import java.util.Map; + +/** + * Created by sebastian on 08.04.17. + */ +public class ExprNew extends ExpressionAbstract { + + + String classType; + // key Value + Map generics; + List args; + + public ExprNew(String classType, Map generics, List args) { + this.classType = classType; + this.generics = generics; + this.args = args; + } + + + public String getClassType() { + return classType; + } + + public void setClassType(String classType) { + this.classType = classType; + } + + public Map getGenerics() { + return generics; + } + + public void setGenerics(Map generics) { + this.generics = generics; + } + + public List getArgs() { + return args; + } + + public void setArgs(List args) { + this.args = args; + } + + + public String toString() { + return String.format("new %s< %s >( %s )" , classType.toString(), generics.toString() , args.toString()); + } + + @Override + public String toCodeTyped() { + return String.format("[new %s< %s >( %s )]" , classType.toString(), generics.toString() , args.toString()); + } + + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprVar.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprVar.java new file mode 100644 index 00000000..15d06e63 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExprVar.java @@ -0,0 +1,51 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.Algo.ConstraintAbstract; +import de.dhbwstuttgart.strucTypes4.Algo.ConstraintGleich; +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 07.04.17. + */ +public class ExprVar extends ExpressionAbstract { + + String name; + + + public List typeExpr(Map ass) { + List constriants = new ArrayList<>(); + //ConstraintGleich constraint = new ConstraintGleich(typePlaceHolder,ass.get(name)); + //constriants.add(constraint); + + super.typePlaceHolder = ass.get(name); + System.out.println("TPH:" + super.typePlaceHolder + "name: " + name); + return constriants; + } + + public ExprVar(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + + @Override + public String toCodeTyped() { + return String.format( " %s : %s " , name , typePlaceHolder ); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Expression.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Expression.java new file mode 100644 index 00000000..6ef0e031 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Expression.java @@ -0,0 +1,42 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +/** + * Created by sebastian on 07.04.17. + */ +public class Expression extends ExpressionAbstract { + + ExpressionAbstract receiver; + ExpressionAbstract caller; + + public Expression(ExpressionAbstract receiver, ExpressionAbstract caller) { + this.receiver = receiver; + this.caller = caller; + } + + + public ExpressionAbstract getReceiver() { + return receiver; + } + + public void setReceiver(ExpressionAbstract receiver) { + this.receiver = receiver; + } + + public ExpressionAbstract getCaller() { + return caller; + } + + public void setCaller(ExpressionAbstract caller) { + this.caller = caller; + } + + + // @Override + public String toString() { + return receiver.toString() + caller.toString(); + } + + public String toCodeTyped() { + return String.format(" [[ %s ] %s ]:%s " , receiver.toCodeTyped() , caller.toCodeTyped() , typePlaceHolder ); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExpressionAbstract.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExpressionAbstract.java new file mode 100644 index 00000000..400c0fbe --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/ExpressionAbstract.java @@ -0,0 +1,17 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.List; + +/** + * Created by sebastian on 08.04.17. + */ +public abstract class ExpressionAbstract extends SyntaxNode { + + + public String toCodeTyped() { + return "?"; + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Field.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Field.java new file mode 100644 index 00000000..14376c11 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Field.java @@ -0,0 +1,43 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +/** + * Created by sebastian on 07.04.17. + */ +public class Field extends SyntaxNode { + + private String var_name; + private String type; + + public Field(String type, String var_name) { + this.var_name = var_name; + this.type = type; + } + + public String getVar_name() { + return var_name; + } + + public void setVar_name(String var_name) { + this.var_name = var_name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + + @Override + public String toString() { + return String.format("Feld: %s %s " , type , var_name); + } + + public String toCodeTyped() { + return String.format("Feld %s %s : %s" , type, var_name , this.typePlaceHolder); + } + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/FieldInterface.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/FieldInterface.java new file mode 100644 index 00000000..2fcd240a --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/FieldInterface.java @@ -0,0 +1,39 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class FieldInterface { + + TPH type; + String name; + + public FieldInterface(TPH type, String name) { + this.type = type; + this.name = name; + } + + public TPH getType() { + return type; + } + + public void setType(TPH type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + @Override + public String toString() { + return String.format("%s %s " , type , name ); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Interface.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Interface.java new file mode 100644 index 00000000..e1f69722 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Interface.java @@ -0,0 +1,62 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.List; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + + +/** + * Created by sebastian on 09.04.17. + */ +public class Interface { + + String name_interface; + List fields; + List methods; + List generics; + + + public Interface(String name_interface, List fields, List methods, List generics) { + this.name_interface = name_interface; + this.fields = fields; + this.methods = methods; + this.generics = generics; + } + + public String getName_interface() { + return name_interface; + } + + public void setName_interface(String name_interface) { + this.name_interface = name_interface; + } + + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } + + public List getMethods() { + return methods; + } + + public void setMethods(List methods) { + this.methods = methods; + } + + public List getGenerics() { + return generics; + } + + public void setGenerics(List generics) { + this.generics = generics; + } + + @Override + public String toString() { + return String.format("interface %s < %s > { \n %s \n %s } \n \n " , name_interface , generics, fields.toString() , methods.toString()); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Method.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Method.java new file mode 100644 index 00000000..6995695d --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/Method.java @@ -0,0 +1,93 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.dhbwstuttgart.strucTypes4.Algo.ConstraintAbstract; +import de.dhbwstuttgart.strucTypes4.Algo.TypeExpr; +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 07.04.17. + */ +public class Method extends SyntaxNode { + + private String name; + private String rtype; + private List args; + private ExpressionAbstract expression; + + + public Method(String name, String rtype, List args, ExpressionAbstract expression) { + this.name = name; + this.rtype = rtype; + this.args = args; + this.expression = expression; + } + + + public Map makeAssumptions() { + Map assLokal = new HashMap<>(); + for (Argument arg : args ) { + assLokal.put(arg.getName(), arg.typePlaceHolder); + } + return assLokal; + } + + public List typeExpr(Map ass) { + return TypeExpr.typeExpr(expression,ass,null , null); + } + + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRtype() { + return rtype; + } + + public void setRtype(String rtype) { + this.rtype = rtype; + } + + public List getArgs() { + return args; + } + + public void setArgs(List args) { + this.args = args; + } + + public ExpressionAbstract getExpression() { + return expression; + } + + public void setExpression(ExpressionAbstract expression) { + this.expression = expression; + } + + + public String toString() { + return String.format("Methode: %s ( %s ) { return %s }" , name , args.toString() , expression.toString()); + } + + + public String toCodeTyped() { + + String argsString = ""; + for (Argument argument : args) { + argsString = argsString.concat(argument.toCodeTyped() + " "); + } + return String.format("%s Methode: %s ( %s ) { return %s }" , expression.typePlaceHolder, name , argsString , expression.toCodeTyped() ); + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/MethodInterface.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/MethodInterface.java new file mode 100644 index 00000000..f5a91237 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/MethodInterface.java @@ -0,0 +1,52 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.List; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; + +/** + * Created by sebastian on 09.04.17. + */ +public class MethodInterface { + + String name; + TPH rtType; + List argsTypes; + + + public MethodInterface(String name, TPH rtType, List argsTypes) { + this.name = name; + this.rtType = rtType; + this.argsTypes = argsTypes; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public TPH getRtType() { + return rtType; + } + + public void setRtType(TPH rtType) { + this.rtType = rtType; + } + + public List getArgsTypes() { + return argsTypes; + } + + public void setArgsTypes(List argsTypes) { + this.argsTypes = argsTypes; + } + + @Override + public String toString() { + return String.format(" %s %s ( %s ); " , rtType, name, argsTypes.toString()); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/SourceFile.java new file mode 100644 index 00000000..c4b8421d --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/SourceFile.java @@ -0,0 +1,36 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by sebastian on 07.04.17. + */ +public class SourceFile { + + private List classList = new ArrayList<>(); + + + public SourceFile(List classList) { + this.classList = classList; + } + + public List getClassList() { + return classList; + } + + public void setClassList(List classList) { + this.classList = classList; + } + + @Override + public String toString() { + String s2 = ""; + for (Class cl : classList) { + s2 = s2.concat(cl.toString() + "\n"); + } + + + return s2; + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/syntaxtree/SyntaxNode.java b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/SyntaxNode.java new file mode 100644 index 00000000..f56f12fd --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/syntaxtree/SyntaxNode.java @@ -0,0 +1,19 @@ +package de.dhbwstuttgart.strucTypes4.syntaxtree; + +import de.dhbwstuttgart.strucTypes4.typen.TPH; +import de.dhbwstuttgart.strucTypes4.typen.TPHFactory; + +/** + * Created by sebastian on 07.04.17. + */ +public class SyntaxNode { + + public TPH typePlaceHolder; + + public SyntaxNode() { + typePlaceHolder = TPHFactory.makeTPH(); + } + + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/typen/TPH.java b/src/de/dhbwstuttgart/strucTypes4/typen/TPH.java new file mode 100644 index 00000000..388e851b --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/typen/TPH.java @@ -0,0 +1,61 @@ +package de.dhbwstuttgart.strucTypes4.typen; + +import de.dhbwstuttgart.strucTypes4.syntaxtree.ClassTyped; + +/** + * Created by sebastian on 08.04.17. + */ + +// Ein Typeplaceholder +public class TPH { + String id; + + ClassTyped type; + + // unschön aber ... + public TPH() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public ClassTyped getType() { + return type; + } + + public void setType(ClassTyped type) { + this.type = type; + } + + public TPH(String id) { + this.id = id; + } + + @Override + public String toString() { + return id; + } + + @Override + public boolean equals(Object obj) { + if (obj.getClass().equals(TPH.class)) { + TPH t = (TPH) obj; + if (t.id.equals(id)) { + return true; + } + else { + return false; + } + } + else { + return false; + } + } + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/typen/TPHFactory.java b/src/de/dhbwstuttgart/strucTypes4/typen/TPHFactory.java new file mode 100644 index 00000000..c4e73781 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/typen/TPHFactory.java @@ -0,0 +1,34 @@ +package de.dhbwstuttgart.strucTypes4.typen; + +import de.dhbwstuttgart.strucTypes4.syntaxtree.Interface; + +/** + * Created by sebastian on 08.04.17. + */ +public class TPHFactory { + + // Für Typeplaceholder T + static Integer startwert = 1; + static Integer offset = 0; + + + // Für Typeplaceholder V + static Integer startwertV = 1; + static Integer offsetV = 0; + + + public static TPH makeTPH() { + Integer akt = startwert+offset; + offset = offset +1; + return new TPH("T" + akt.toString()); + } + + + public static TPH makeTPHV() { + Integer akt = startwertV + offsetV; + offsetV = offsetV +1; + return new TPH( "V" + akt.toString()); + } + + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/typen/TPHStore.java b/src/de/dhbwstuttgart/strucTypes4/typen/TPHStore.java new file mode 100644 index 00000000..df347f89 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/typen/TPHStore.java @@ -0,0 +1,11 @@ +package de.dhbwstuttgart.strucTypes4.typen; + +import java.util.List; +import java.util.Map; + +/** + * Created by sebastian on 08.04.17. + */ +public class TPHStore { + public Map> tph; +} diff --git a/src/de/dhbwstuttgart/strucTypes4/typen/TPHV.java b/src/de/dhbwstuttgart/strucTypes4/typen/TPHV.java new file mode 100644 index 00000000..ca276768 --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/typen/TPHV.java @@ -0,0 +1,36 @@ +package de.dhbwstuttgart.strucTypes4.typen; + +/** + * Created by sebastian on 08.04.17. + */ + +// Ein Typeplaceholder +public class TPHV { + String id; + + public TPHV(String id) { + this.id = id; + } + + @Override + public String toString() { + return "V"+id; + } + + @Override + public boolean equals(Object obj) { + if (obj.getClass().equals(TPHV.class)) { + TPHV t = (TPHV) obj; + if (t.id.equals(id)) { + return true; + } + else { + return false; + } + } + else { + return false; + } + } + +} diff --git a/src/de/dhbwstuttgart/strucTypes4/typen/TPHVFactory.java b/src/de/dhbwstuttgart/strucTypes4/typen/TPHVFactory.java new file mode 100644 index 00000000..8f6a15ab --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/typen/TPHVFactory.java @@ -0,0 +1,17 @@ +package de.dhbwstuttgart.strucTypes4.typen; + +/** + * Created by sebastian on 08.04.17. + */ +public class TPHVFactory { + + static Integer startwert = 1; + static Integer offset = 0; + + + public static TPHV makeTPHV() { + Integer akt = startwert+offset; + offset = offset +1; + return new TPHV(akt.toString()); + } +} diff --git a/src/de/dhbwstuttgart/strucTypes4/typen/TPHwithClass.java b/src/de/dhbwstuttgart/strucTypes4/typen/TPHwithClass.java new file mode 100644 index 00000000..a27f4c9f --- /dev/null +++ b/src/de/dhbwstuttgart/strucTypes4/typen/TPHwithClass.java @@ -0,0 +1,18 @@ +package de.dhbwstuttgart.strucTypes4.typen; + +import de.dhbwstuttgart.strucTypes4.syntaxtree.ClassTyped; + +/** + * Created by sebastian on 12.04.17. + */ +public class TPHwithClass extends TPH { + + + public TPHwithClass() { + super.id = "default"; + } + + + public ClassTyped classTyped = null; + +}