forked from JavaTX/JavaCompilerCore
Compare commits
3 Commits
strucTypes
...
strucTypes
Author | SHA1 | Date | |
---|---|---|---|
|
277a360c65 | ||
|
fd1a434037 | ||
|
2f6680354f |
.gitignore
.idea
src
control
de
dhbwstuttgart
core
parser
ClassNotFoundException.javaInvalidClassNameException.javaJavaTXParser.javaRunParser.java
SyntaxTreeGenerator
antlr
strucTypes4
algo
ConstraintField.javaConstraintMethod.javaConstraintSubType.javaConstraintSubTypeInterface.javaConstruct2.javaMappingAltNeu.javaTypeExpr.java
parserFWJ
syntaxtree
Class.javaExprMCall.javaExprVar.javaFieldInterface.javaInterface.javaMethod.javaMethodInterface.java
typeVars
strucTypes5
NeueKlassen
algo
assumptions
AssumptionArgument.javaAssumptionClass.javaAssumptionFactory.javaAssumptionMap.javaChangeTypeVars.java
ausgabe
constraints
ConstraintAbstract.javaConstraintInterface.javaConstraintShouldEqual.javaConstraintSubType.javaConstraintSubTypeGeneric.javaConstraintSubstitution.javaConvertConstraints.javaInterfaceForConstraint.java
factoryForSyntaxtree
interfaceTemplates
solve
typeVars
strucTypes6
syntaxtree
ClassOrInterface.javaMethod.javaSyntaxTreeNode.javaTypeScope.java
factory
statement
Binary.javaCastExpr.javaForStmt.javaInstVar.javaInstanceOf.javaLambdaExpression.javaLocalVarBunchDeclaration.javaLocalVarDecl.javaMethodCall.javaNewArray.javaNewClass.javaPostIncExpr.javaReturn.javaSuper.javaThis.javaThisCall.javaUnaryExpr.javaUnaryPlus.javaWhileStmt.java
type
typedeployment
typeinference
test
4
.gitignore
vendored
4
.gitignore
vendored
@@ -10,7 +10,3 @@ bin
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
|
||||
# Git Ignore für Idea Workspace
|
||||
/.idea
|
1793
.idea/workspace.xml
generated
Normal file
1793
.idea/workspace.xml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.Method;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -19,7 +19,7 @@ import java.util.Map;
|
||||
public class Start {
|
||||
|
||||
|
||||
Map<String, RefTypeOrTPHOrWildcardOrGeneric> assumptionsGlobal = new HashMap<>();
|
||||
Map<String, TypeVarAbstract> assumptionsGlobal = new HashMap<>();
|
||||
List<Class> results = new ArrayList<>();
|
||||
|
||||
|
||||
|
@@ -1,13 +1,10 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
@@ -24,11 +21,7 @@ public class JavaTXCompiler {
|
||||
|
||||
private List<SourceFile> sourceFiles = new ArrayList<>();
|
||||
|
||||
public List<TypeInsertPoint> getTypeInserts(File forSourceFile){
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResultSet typeInference(){
|
||||
public void typeInference(){
|
||||
ConstraintSet cons = new ConstraintSet();
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();
|
||||
for(SourceFile sf : sourceFiles){
|
||||
@@ -41,7 +34,6 @@ public class JavaTXCompiler {
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for(List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()){
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for(Constraint<UnifyPair> constraint : xCons){
|
||||
@@ -51,10 +43,10 @@ public class JavaTXCompiler {
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println(result);
|
||||
results.addAll(result);
|
||||
}
|
||||
return new ResultSet(results);
|
||||
|
||||
}
|
||||
|
||||
public void parse(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
sourceFiles.add(new JavaTXParser().parse(sourceFile));
|
||||
}
|
||||
|
@@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
public class ClassNotFoundException extends Exception{
|
||||
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
public class InvalidClassNameException extends Exception{
|
||||
|
||||
}
|
@@ -33,7 +33,6 @@ public class JavaTXParser {
|
||||
}
|
||||
//TODO: Wieso muss man das händisch anhängen?
|
||||
ret.add("java.lang.Object");
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -17,11 +17,22 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
public class RunTXParser{
|
||||
public class RunParser{
|
||||
public static void main(String[] args){
|
||||
try{
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
SourceFile f = parser.parse(new File(args[0]));
|
||||
File file = new File(args[0]);
|
||||
Scanner sc = new Scanner(file);
|
||||
String inputString = sc.nextLine();
|
||||
while(sc.hasNextLine()) inputString = inputString + sc.nextLine() + "\n";
|
||||
InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
|
||||
ANTLRInputStream input = new ANTLRInputStream(stream);
|
||||
Java8Lexer lexer = new Java8Lexer(input);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
Java8Parser parser = new Java8Parser(tokens);
|
||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry(new ArrayList<>()));
|
||||
generator.setImports(tree);
|
||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
String pkgName = f.getPkgName();
|
||||
System.out.println("package: " + pkgName);
|
||||
System.out.println("Imports:");
|
||||
@@ -43,12 +54,12 @@ public class RunTXParser{
|
||||
catch(java.util.NoSuchElementException e){
|
||||
System.out.println("Error: Source seems to be empty.");
|
||||
}
|
||||
catch(ClassNotFoundException e){
|
||||
System.out.println("Class not found.");
|
||||
}
|
||||
catch(FileNotFoundException e){
|
||||
System.out.println("File not found.");
|
||||
}
|
||||
catch(InvalidClassNameException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(IOException e){
|
||||
System.out.println("An exception occured which is on our TODO list.");
|
||||
e.printStackTrace();
|
@@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
@@ -15,6 +14,7 @@ import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
@@ -33,7 +33,37 @@ public class StatementGenerator {
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
public ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
|
||||
|
||||
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass) {
|
||||
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
||||
String name = header.methodDeclarator().Identifier().getText();
|
||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), methodDeclarationContext.methodHeader().getStart());
|
||||
if(methodDeclarationContext.methodHeader().typeParameters() != null){
|
||||
gtvDeclarations = TypeGenerator.convert(methodDeclarationContext.methodHeader().typeParameters(), parentClass, name,reg, generics);
|
||||
}
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||
if(header.result() != null){
|
||||
if(header.result().unannType() != null){
|
||||
retType = TypeGenerator.convert(header.result().unannType(), reg, generics);
|
||||
}
|
||||
else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart());
|
||||
}else{
|
||||
retType = TypePlaceholder.fresh(header.getStart());
|
||||
}
|
||||
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
|
||||
ParameterList parameterList = convert(header.methodDeclarator().formalParameterList());
|
||||
Block block = null;
|
||||
if(methodDeclarationContext.methodBody().block() == null){
|
||||
if(! Modifier.isAbstract(modifiers)){
|
||||
//TODO: Error! Abstrakte Methode ohne abstrakt Keyword
|
||||
}
|
||||
}else{
|
||||
block = this.convert(methodDeclarationContext.methodBody().block());
|
||||
}
|
||||
return new Method(name, retType, modifiers, parameterList,block, gtvDeclarations, methodDeclarationContext.getStart());
|
||||
}
|
||||
|
||||
private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
|
||||
List<FormalParameter> ret = new ArrayList<>();
|
||||
List<Java8Parser.FormalParameterContext> fps = new ArrayList<>();
|
||||
if(formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
|
||||
@@ -62,7 +92,7 @@ public class StatementGenerator {
|
||||
}
|
||||
|
||||
/*
|
||||
* StatementGeneration:
|
||||
* StatementGeneration:
|
||||
*/
|
||||
|
||||
private Statement convert(Java8Parser.StatementContext stmt) {
|
||||
@@ -204,7 +234,7 @@ public class StatementGenerator {
|
||||
}else throw new NotImplementedException();
|
||||
|
||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
||||
MethodCall ret = new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -234,9 +264,8 @@ public class StatementGenerator {
|
||||
//Check for localVar:
|
||||
if(localVars.contains(expression)){
|
||||
return new LocalVar(expression, offset);
|
||||
}else{
|
||||
//throw new NotImplementedException();
|
||||
//Dann Muss es ein Feld sein!
|
||||
}else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
return generateFieldVarOrClassname(expression, offset);
|
||||
@@ -666,7 +695,7 @@ public class StatementGenerator {
|
||||
}else {
|
||||
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
|
||||
String methodName = ctxt.Identifier().toString();
|
||||
return new MethodCall(TypePlaceholder.fresh(e.getStart()), new Receiver(expr), methodName, convert(ctxt.argumentList()), e.getStart());
|
||||
return new MethodCall(new Receiver(expr), methodName, convert(ctxt.argumentList()), e.getStart());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,33 +712,13 @@ public class StatementGenerator {
|
||||
return convert(expression.methodInvocation_lfno_primary());
|
||||
}else if(expression.classInstanceCreationExpression_lfno_primary() != null) {
|
||||
return convert(expression.classInstanceCreationExpression_lfno_primary());
|
||||
}else if(expression.getText().equals("this")) {
|
||||
return new This(expression.getStart());
|
||||
}else if(expression.fieldAccess_lfno_primary() != null){
|
||||
return convert(expression.fieldAccess_lfno_primary());
|
||||
}else if(expression.methodReference_lfno_primary() != null){
|
||||
throw new NotImplementedException();
|
||||
}else if(expression.typeName() != null){
|
||||
throw new NotImplementedException();
|
||||
}else if(expression.unannPrimitiveType() != null){
|
||||
throw new NotImplementedException();
|
||||
}else if(expression.arrayAccess_lfno_primary() != null){
|
||||
throw new NotImplementedException();
|
||||
}else if(expression.fieldAccess_lfno_primary() != null){
|
||||
throw new NotImplementedException();
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
private Expression convert(Java8Parser.FieldAccess_lfno_primaryContext fieldAccess_lfno_primaryContext) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private Expression convert(Java8Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
|
||||
if(newExpression.expressionName()!= null)throw new NotImplementedException();
|
||||
if(newExpression.typeArgumentsOrDiamond()!= null)throw new NotImplementedException();
|
||||
if(newExpression.typeArguments()!= null)throw new NotImplementedException();
|
||||
|
||||
TerminalNode identifier = newExpression.Identifier(0);
|
||||
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),identifier.getSymbol(),reg,generics);
|
||||
@@ -767,41 +776,12 @@ public class StatementGenerator {
|
||||
}
|
||||
|
||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
||||
MethodCall ret = new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Expression convert(Java8Parser.LambdaExpressionContext expression) {
|
||||
Java8Parser.LambdaParametersContext lambdaParams = expression.lambdaParameters();
|
||||
ParameterList params;
|
||||
if(lambdaParams.Identifier() != null){
|
||||
List<FormalParameter> parameterList = new ArrayList<>();
|
||||
parameterList.add(new FormalParameter(lambdaParams.Identifier().getText(),
|
||||
TypePlaceholder.fresh(lambdaParams.getStart()), lambdaParams.getStart()));
|
||||
params = new ParameterList(parameterList, lambdaParams.getStart());
|
||||
}else if(lambdaParams.formalParameterList() != null){
|
||||
params = convert(lambdaParams.formalParameterList());
|
||||
//}else if( lambdaParams.inferredFormalParameterList != null){
|
||||
}else {
|
||||
params = new ParameterList(new ArrayList<>(), expression.getStart());
|
||||
}
|
||||
|
||||
Block block;
|
||||
if(expression.lambdaBody().expression() != null){
|
||||
List<Statement> statements = new ArrayList<>();
|
||||
statements.add(new Return(convert(expression.lambdaBody().expression()),
|
||||
expression.lambdaBody().expression().getStart()));
|
||||
block = new Block(statements, expression.lambdaBody().getStart());
|
||||
}else{
|
||||
block = convert(expression.lambdaBody().block());
|
||||
}
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type
|
||||
params.getFormalparalist().forEach(formalParameter -> //Für jeden Parameter einen TPH anfügen:
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
|
||||
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
||||
//RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
||||
//funNParams, expression.getStart());
|
||||
return new LambdaExpression(lambdaType, params, block, expression.getStart());
|
||||
private static Expression convert(Java8Parser.LambdaExpressionContext expression) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||
import de.dhbwstuttgart.parser.InvalidClassNameException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.PackageCrawler;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
@@ -18,7 +18,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.internal.dynalink.support.TypeConverterFactory;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
@@ -26,6 +25,7 @@ public class SyntaxTreeGenerator{
|
||||
private JavaClassRegistry reg;
|
||||
private String pkgName = "";
|
||||
List<JavaClassName> imports = new ArrayList();
|
||||
private GenericsRegistry generics = new GenericsRegistry();
|
||||
|
||||
public SyntaxTreeGenerator(JavaClassRegistry reg){
|
||||
this.reg = reg;
|
||||
@@ -53,13 +53,11 @@ public class SyntaxTreeGenerator{
|
||||
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
||||
}
|
||||
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||
//this.reg.add(tp.Identifier().toString());
|
||||
}
|
||||
}
|
||||
*/
|
||||
this.reg.add(nameString);
|
||||
}
|
||||
}
|
||||
@@ -71,14 +69,12 @@ public class SyntaxTreeGenerator{
|
||||
else{
|
||||
nameString = typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
||||
}
|
||||
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
||||
//Die Generic TypeParameter Definitionen ebenfalls an die JavaClassName-Registry anfügen:
|
||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||
this.reg.add(tp.Identifier().toString());
|
||||
}
|
||||
}
|
||||
*/
|
||||
this.reg.add(nameString);
|
||||
}
|
||||
}
|
||||
@@ -113,7 +109,7 @@ public class SyntaxTreeGenerator{
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setImports(Java8Parser.CompilationUnitContext ctx) throws ClassNotFoundException {
|
||||
public void setImports(Java8Parser.CompilationUnitContext ctx) throws InvalidClassNameException {
|
||||
List<JavaClassName> newImports = new ArrayList();
|
||||
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
||||
if(importDeclCtx.singleTypeImportDeclaration() != null){
|
||||
@@ -132,7 +128,7 @@ public class SyntaxTreeGenerator{
|
||||
this.imports.addAll(newImports);
|
||||
}
|
||||
|
||||
private JavaClassName convertSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx) throws ClassNotFoundException{
|
||||
private JavaClassName convertSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx) throws InvalidClassNameException{
|
||||
String typeName = convertTypeName(ctx.typeName());
|
||||
String packageName = getPackageFromClass(typeName);
|
||||
List<JavaClassName> classes = PackageCrawler.getClassNames(packageName);
|
||||
@@ -142,7 +138,7 @@ public class SyntaxTreeGenerator{
|
||||
return ret;
|
||||
}
|
||||
else{
|
||||
throw new ClassNotFoundException();
|
||||
throw new InvalidClassNameException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,10 +164,9 @@ public class SyntaxTreeGenerator{
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx) throws ClassNotFoundException{
|
||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||
List<ClassOrInterface> classes = new ArrayList<>();
|
||||
this.getNames(ctx);
|
||||
this.setImports(ctx);
|
||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||
ClassOrInterface newClass;
|
||||
if(typeDecl.classDeclaration() != null){
|
||||
@@ -185,60 +180,6 @@ public class SyntaxTreeGenerator{
|
||||
return new SourceFile(this.pkgName, classes, this.imports);
|
||||
}
|
||||
|
||||
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, GenericsRegistry generics) {
|
||||
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
||||
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
|
||||
GenericsRegistry localGenerics = createGenerics(methodDeclarationContext.methodHeader().typeParameters(),
|
||||
parentClass, header.methodDeclarator().Identifier().getText());
|
||||
localGenerics.putAll(generics);
|
||||
return convert(modifiers, header, methodDeclarationContext.methodBody(),parentClass, localGenerics);
|
||||
}
|
||||
|
||||
public Method convert(Java8Parser.InterfaceMethodDeclarationContext ctx, JavaClassName parentClass, GenericsRegistry generics) {
|
||||
Java8Parser.MethodHeaderContext header = ctx.methodHeader();
|
||||
int modifiers = SyntaxTreeGenerator.convertInterfaceModifier(ctx.interfaceMethodModifier());
|
||||
|
||||
GenericsRegistry localGenerics = createGenerics(header.typeParameters(), parentClass, header.methodDeclarator().Identifier().getText());
|
||||
localGenerics.putAll(generics);
|
||||
|
||||
return convert(modifiers, header, ctx.methodBody(),parentClass, localGenerics);
|
||||
}
|
||||
|
||||
private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body,
|
||||
JavaClassName parentClass, GenericsRegistry localGenerics) {
|
||||
|
||||
StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics);
|
||||
|
||||
String name = header.methodDeclarator().Identifier().getText();
|
||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart());
|
||||
if(header.typeParameters() != null){
|
||||
gtvDeclarations = TypeGenerator.convert(header.typeParameters(), parentClass, name,reg, localGenerics);
|
||||
}
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||
if(header.result() != null){
|
||||
if(header.result().unannType() != null){
|
||||
retType = TypeGenerator.convert(header.result().unannType(), reg, localGenerics);
|
||||
}
|
||||
else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart());
|
||||
}else{
|
||||
retType = TypePlaceholder.fresh(header.getStart());
|
||||
}
|
||||
ParameterList parameterList = stmtGen.convert(header.methodDeclarator().formalParameterList());
|
||||
Block block = null;
|
||||
if(body.block() == null){
|
||||
if(! Modifier.isAbstract(modifiers)){
|
||||
//TODO: Error! Abstrakte Methode ohne abstrakt Keyword
|
||||
}
|
||||
}else{
|
||||
block = stmtGen.convert(body.block());
|
||||
}
|
||||
if(parentClass.equals(new JavaClassName(name))){
|
||||
return new Constructor(name, retType, modifiers, parameterList, block, gtvDeclarations, header.getStart());
|
||||
}else{
|
||||
return new Method(name, retType, modifiers, parameterList,block, gtvDeclarations, header.getStart());
|
||||
}
|
||||
}
|
||||
|
||||
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
|
||||
ClassOrInterface newClass;
|
||||
if(ctx.normalClassDeclaration() != null){
|
||||
@@ -259,27 +200,11 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
}
|
||||
JavaClassName name = reg.getName(ctx.Identifier().getText());
|
||||
GenericsRegistry generics = createGenerics(ctx.typeParameters(), name, "");
|
||||
Token offset = ctx.getStart();
|
||||
GenericDeclarationList genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
||||
List<Field> fielddecl = convertFields(ctx.classBody(), generics);
|
||||
List<Method> methods = convertMethods(ctx.classBody(), name, generics);
|
||||
List<Constructor> konstruktoren = new ArrayList<>();
|
||||
for(int i = 0; i<methods.size();i++){
|
||||
Method m = methods.get(i);
|
||||
if(m instanceof Constructor){
|
||||
methods.remove(i);
|
||||
konstruktoren.add((Constructor) m);
|
||||
}
|
||||
}
|
||||
if(konstruktoren.size()<1){//Standardkonstruktor anfügen:
|
||||
konstruktoren.add(
|
||||
generateStandardConstructor(
|
||||
ctx.Identifier().getText(),
|
||||
genericClassParameters, offset)
|
||||
);
|
||||
}
|
||||
List<Field> fielddecl = convertFields(ctx.classBody());
|
||||
List<Method> methods = convertMethods(ctx.classBody(), name);
|
||||
|
||||
Token offset = ctx.getStart();
|
||||
RefType superClass ;
|
||||
if(ctx.superclass() != null){
|
||||
superClass = convert(ctx.superclass());
|
||||
@@ -287,39 +212,15 @@ public class SyntaxTreeGenerator{
|
||||
superClass = new RefType(new JavaClassName("java.lang.Object"), new NullToken());
|
||||
}
|
||||
Boolean isInterface = false;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = convert(ctx.superinterfaces(), generics);
|
||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass,
|
||||
isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
|
||||
if(ctx == null)return new ArrayList<>();
|
||||
return convert(ctx.interfaceTypeList(), generics);
|
||||
}
|
||||
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
|
||||
for(Java8Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){
|
||||
ret.add(TypeGenerator.convert(interfaceType.classType(), reg, generics));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Constructor generateStandardConstructor(String className, GenericDeclarationList classGenerics, Token offset){
|
||||
RefType classType = ClassOrInterface.generateTypeOfClass(reg.getName(className), classGenerics, offset);
|
||||
int modifiers = 0;
|
||||
ParameterList params = new ParameterList(new ArrayList<>(), offset);
|
||||
//TODO: Konstruktor muss Felder initialisieren:
|
||||
Block block = new Block(new ArrayList<>(), offset);
|
||||
return new Constructor(className, classType, modifiers, params, block, classGenerics, offset);
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = null;
|
||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
private RefType convert(Java8Parser.SuperclassContext superclass) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private List<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext,
|
||||
JavaClassName parentClass, GenericsRegistry generics) {
|
||||
private List<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext, JavaClassName parentClass) {
|
||||
List<Method> ret = new ArrayList<>();
|
||||
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
|
||||
if(classMember.classMemberDeclaration() != null){
|
||||
@@ -327,21 +228,21 @@ public class SyntaxTreeGenerator{
|
||||
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
||||
//Do nothing!
|
||||
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
||||
|
||||
ret.add(this.convert(classMemberDeclarationContext.methodDeclaration(), parentClass, generics));
|
||||
StatementGenerator stmtGen = new StatementGenerator(reg, generics);
|
||||
ret.add(stmtGen.convert(classMemberDeclarationContext.methodDeclaration(), parentClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<Field> convertFields(Java8Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
|
||||
private List<Field> convertFields(Java8Parser.ClassBodyContext classBodyContext) {
|
||||
List<Field> ret = new ArrayList<>();
|
||||
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
|
||||
if(classMember.classMemberDeclaration() != null){
|
||||
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
|
||||
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
||||
ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration(), generics));
|
||||
ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration()));
|
||||
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
||||
//Do nothing!
|
||||
}
|
||||
@@ -358,15 +259,7 @@ public class SyntaxTreeGenerator{
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int convertInterfaceModifier(List<Java8Parser.InterfaceMethodModifierContext> methodModifierContexts) {
|
||||
int ret = 0;
|
||||
for(Java8Parser.InterfaceMethodModifierContext mod : methodModifierContexts){
|
||||
if(mod.annotation() == null)convertModifier(mod.getText());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<? extends Field> convert(Java8Parser.FieldDeclarationContext fieldDeclarationContext, GenericsRegistry generics) {
|
||||
private List<? extends Field> convert(Java8Parser.FieldDeclarationContext fieldDeclarationContext) {
|
||||
List<Field> ret = new ArrayList<>();
|
||||
int modifiers = 0;
|
||||
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
|
||||
@@ -397,7 +290,6 @@ public class SyntaxTreeGenerator{
|
||||
// Initialize a field by creating implicit constructor.
|
||||
private void initializeField(Java8Parser.FieldDeclarationContext ctx){
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static int convertModifier(String modifier){
|
||||
@@ -416,7 +308,7 @@ public class SyntaxTreeGenerator{
|
||||
modifiers.put(Modifier.toString(Modifier.INTERFACE), Modifier.INTERFACE);
|
||||
int ret = 0;
|
||||
for(String m : modifiers.keySet()){
|
||||
if(modifier.contains(m))ret+=modifiers.get(m);
|
||||
if(modifier.startsWith(m))ret+=modifiers.get(m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -430,86 +322,13 @@ public class SyntaxTreeGenerator{
|
||||
if(ctx.annotation() != null)return 0;
|
||||
return convertModifier(ctx.getText());
|
||||
}
|
||||
|
||||
private int convert(Java8Parser.InterfaceModifierContext ctx) {
|
||||
if(ctx.annotation() != null)return 0;
|
||||
return convertModifier(ctx.getText());
|
||||
}
|
||||
|
||||
private ClassOrInterface convertEnum(Java8Parser.EnumDeclarationContext ctx){
|
||||
return null;
|
||||
}
|
||||
|
||||
private ClassOrInterface convertInterface(Java8Parser.InterfaceDeclarationContext ctx){
|
||||
if(ctx.normalInterfaceDeclaration() != null){
|
||||
return convertNormal(ctx.normalInterfaceDeclaration());
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ClassOrInterface convertNormal(Java8Parser.NormalInterfaceDeclarationContext ctx) {
|
||||
int modifiers = 0;
|
||||
if(ctx.interfaceModifier() != null){
|
||||
for( Java8Parser.InterfaceModifierContext mod : ctx.interfaceModifier()){
|
||||
int newModifier = convert(mod);
|
||||
modifiers += newModifier;
|
||||
}
|
||||
}
|
||||
JavaClassName name = reg.getName(ctx.Identifier().getText());
|
||||
|
||||
GenericsRegistry generics = createGenerics(ctx.typeParameters(), name, "");
|
||||
|
||||
List<Field> fields = convertFields(ctx.interfaceBody());
|
||||
List<Method> methods = convertMethods(ctx.interfaceBody(), name, generics);
|
||||
|
||||
GenericDeclarationList genericParams = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
||||
RefType superClass = new ASTFactory(reg).createObjectClass().getType();
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
|
||||
|
||||
return new ClassOrInterface(modifiers, name, fields, methods, new ArrayList<>(),
|
||||
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
|
||||
}
|
||||
|
||||
private GenericsRegistry createGenerics(Java8Parser.TypeParametersContext ctx, JavaClassName parentClass, String parentMethod) {
|
||||
GenericsRegistry ret = new GenericsRegistry();
|
||||
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
||||
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
|
||||
if(extendsInterfacesContext == null)return new ArrayList<>();
|
||||
return convert(extendsInterfacesContext.interfaceTypeList(), generics);
|
||||
}
|
||||
|
||||
private List<Method> convertMethods(Java8Parser.InterfaceBodyContext interfaceBodyContext,
|
||||
JavaClassName parentClass, GenericsRegistry generics) {
|
||||
List<Method> ret = new ArrayList<>();
|
||||
for(Java8Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
|
||||
if(member.interfaceMethodDeclaration() != null){
|
||||
ret.add(this.convert(member.interfaceMethodDeclaration(), parentClass, generics));
|
||||
//new Method(name, type, modifier, params, null, genericDecls, member.interfaceMethodDeclaration().getStart());
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<Field> convertFields(Java8Parser.InterfaceBodyContext interfaceBodyContext) {
|
||||
List<Field> ret = new ArrayList<>();
|
||||
for(Java8Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
|
||||
if(member.constantDeclaration() != null){
|
||||
//TODO: Erstelle hier ein Feld!
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
@@ -8,7 +7,6 @@ import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@@ -17,6 +15,7 @@ import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -24,23 +23,8 @@ import java.util.List;
|
||||
public class TypeGenerator {
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
String name;
|
||||
if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
|
||||
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
|
||||
}
|
||||
Java8Parser.TypeArgumentsContext arguments;
|
||||
if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){
|
||||
name = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
|
||||
arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
|
||||
}else{// if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
|
||||
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().getText();
|
||||
arguments = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
|
||||
}
|
||||
if(arguments == null){
|
||||
return convertTypeName(name,unannClassOrInterfaceTypeContext.getStart(), reg, generics);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
String name = unannClassOrInterfaceTypeContext.getText();
|
||||
return convertTypeName(name,unannClassOrInterfaceTypeContext.getStart(), reg, generics);
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
|
||||
@@ -94,11 +78,6 @@ public class TypeGenerator {
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(String name, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
|
||||
return convertTypeName(name, null, offset, reg, generics);
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(
|
||||
String name, Java8Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
|
||||
if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein:
|
||||
if(generics.keySet().contains(name)){
|
||||
return new GenericRefType(new GenericTypeName(generics.get(name),name), offset);
|
||||
@@ -106,28 +85,7 @@ public class TypeGenerator {
|
||||
throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",offset);
|
||||
}
|
||||
}
|
||||
if(typeArguments == null){
|
||||
return new RefType(reg.getName(name), offset);
|
||||
}else{
|
||||
return new RefType(reg.getName(name), convert(typeArguments, reg, generics), offset);
|
||||
}
|
||||
return new RefType(reg.getName(name), offset);
|
||||
}
|
||||
|
||||
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.TypeArgumentsContext typeArguments,
|
||||
JavaClassRegistry reg, GenericsRegistry generics){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
|
||||
for(Java8Parser.TypeArgumentContext arg : typeArguments.typeArgumentList().typeArgument()){
|
||||
if(arg.wildcard() != null){
|
||||
throw new NotImplementedException();
|
||||
}else{
|
||||
ret.add(convert(arg.referenceType(), reg, generics));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassTypeContext ctx, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
if(ctx.classOrInterfaceType() != null)throw new NotImplementedException();
|
||||
return convertTypeName(ctx.Identifier().getText(), ctx.typeArguments(), ctx.getStart(), reg, generics);
|
||||
}
|
||||
}
|
||||
|
@@ -352,7 +352,7 @@ variableDeclaratorList
|
||||
;
|
||||
|
||||
variableDeclarator
|
||||
: variableDeclaratorId ('=' variableInitializer)? //auskommentiert, weil variablenDecklaration sonst nicht eindeutig
|
||||
: variableDeclaratorId //('=' variableInitializer)? //auskommentiert, weil variablenDecklaration sonst nicht eindeutig
|
||||
;
|
||||
|
||||
variableDeclaratorId
|
||||
@@ -1011,17 +1011,17 @@ primaryNoNewArray_lf_primary_lfno_arrayAccess_lf_primary
|
||||
;
|
||||
|
||||
primaryNoNewArray_lfno_primary
|
||||
: literal //done
|
||||
: literal
|
||||
| typeName ('[' ']')* '.' 'class'
|
||||
| unannPrimitiveType ('[' ']')* '.' 'class'
|
||||
| 'void' '.' 'class'
|
||||
| 'this'
|
||||
| typeName '.' 'this'
|
||||
| '(' expression ')' //done
|
||||
| classInstanceCreationExpression_lfno_primary //done
|
||||
| '(' expression ')'
|
||||
| classInstanceCreationExpression_lfno_primary
|
||||
| fieldAccess_lfno_primary
|
||||
| arrayAccess_lfno_primary
|
||||
| methodInvocation_lfno_primary //done
|
||||
| methodInvocation_lfno_primary
|
||||
| methodReference_lfno_primary
|
||||
;
|
||||
|
||||
@@ -1180,7 +1180,7 @@ lambdaExpression
|
||||
lambdaParameters
|
||||
: Identifier
|
||||
| '(' formalParameterList? ')'
|
||||
//| '(' inferredFormalParameterList ')'
|
||||
| '(' inferredFormalParameterList ')'
|
||||
;
|
||||
|
||||
inferredFormalParameterList
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Generated from /home/janulrich/Development/intellijworkspace/JavaCompilerCore/src/de/dhbwstuttgart/parser/antlr/Java8.g4 by ANTLR 4.5.1
|
||||
// Generated from Java8.g4 by ANTLR 4.5.3
|
||||
package de.dhbwstuttgart.parser.antlr;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
@@ -11,7 +11,7 @@ import org.antlr.v4.runtime.misc.*;
|
||||
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
||||
public class Java8Lexer extends Lexer {
|
||||
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
|
||||
static { RuntimeMetaData.checkVersion("4.5.3", RuntimeMetaData.VERSION); }
|
||||
|
||||
protected static final DFA[] _decisionToDFA;
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,27 @@
|
||||
package de.dhbwstuttgart.strucTypes4.algo;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 09.04.17.
|
||||
*/
|
||||
public class ConstraintField extends ConstraintAbstract {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiver;
|
||||
TypeVarAbstract receiver;
|
||||
String nameField;
|
||||
RefTypeOrTPHOrWildcardOrGeneric caller;
|
||||
TypeVarAbstract caller;
|
||||
|
||||
public ConstraintField(RefTypeOrTPHOrWildcardOrGeneric receiver, String nameField, RefTypeOrTPHOrWildcardOrGeneric caller) {
|
||||
public ConstraintField(TypeVarAbstract receiver, String nameField, TypeVarAbstract caller) {
|
||||
this.receiver = receiver;
|
||||
this.nameField = nameField;
|
||||
this.caller = caller;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiver() {
|
||||
public TypeVarAbstract getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public void setReceiver(RefTypeOrTPHOrWildcardOrGeneric receiver) {
|
||||
public void setReceiver(TypeVarAbstract receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ public class ConstraintField extends ConstraintAbstract {
|
||||
this.nameField = nameField;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getCaller() {
|
||||
public TypeVarAbstract getCaller() {
|
||||
return caller;
|
||||
}
|
||||
|
||||
public void setCaller(RefTypeOrTPHOrWildcardOrGeneric caller) {
|
||||
public void setCaller(TypeVarAbstract caller) {
|
||||
this.caller = caller;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package de.dhbwstuttgart.strucTypes4.algo;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,13 +9,13 @@ import java.util.List;
|
||||
*/
|
||||
public class ConstraintMethod extends ConstraintAbstract {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiver;
|
||||
TypeVarAbstract receiver;
|
||||
String methodName;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes;
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> argsBetaTypes;
|
||||
List<TypeVarAbstract> argsTypes;
|
||||
TypeVarAbstract returnType;
|
||||
List<TypeVarAbstract> argsBetaTypes;
|
||||
|
||||
public ConstraintMethod(RefTypeOrTPHOrWildcardOrGeneric receiver, String methodName, List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes, RefTypeOrTPHOrWildcardOrGeneric returnType, List<RefTypeOrTPHOrWildcardOrGeneric> argsBetaTypes) {
|
||||
public ConstraintMethod(TypeVarAbstract receiver, String methodName, List<TypeVarAbstract> argsTypes, TypeVarAbstract returnType, List<TypeVarAbstract> argsBetaTypes) {
|
||||
this.receiver = receiver;
|
||||
this.methodName = methodName;
|
||||
this.argsTypes = argsTypes;
|
||||
@@ -24,11 +24,11 @@ public class ConstraintMethod extends ConstraintAbstract {
|
||||
}
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiver() {
|
||||
public TypeVarAbstract getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public void setReceiver(RefTypeOrTPHOrWildcardOrGeneric receiver) {
|
||||
public void setReceiver(TypeVarAbstract receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
@@ -40,27 +40,27 @@ public class ConstraintMethod extends ConstraintAbstract {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsTypes() {
|
||||
public List<TypeVarAbstract> getArgsTypes() {
|
||||
return argsTypes;
|
||||
}
|
||||
|
||||
public void setArgsTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
|
||||
public void setArgsTypes(List<TypeVarAbstract> argsTypes) {
|
||||
this.argsTypes = argsTypes;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
public TypeVarAbstract getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public void setReturnType(RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||
public void setReturnType(TypeVarAbstract returnType) {
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsBetaTypes() {
|
||||
public List<TypeVarAbstract> getArgsBetaTypes() {
|
||||
return argsBetaTypes;
|
||||
}
|
||||
|
||||
public void setArgsBetaTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsBetaTypes) {
|
||||
public void setArgsBetaTypes(List<TypeVarAbstract> argsBetaTypes) {
|
||||
this.argsBetaTypes = argsBetaTypes;
|
||||
}
|
||||
|
||||
|
@@ -1,16 +1,16 @@
|
||||
package de.dhbwstuttgart.strucTypes4.algo;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 09.04.17.
|
||||
*/
|
||||
public class ConstraintSubType extends ConstraintAbstract {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeKleiner;
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeGroeßer;
|
||||
TypeVarAbstract typeKleiner;
|
||||
TypeVarAbstract typeGroeßer;
|
||||
|
||||
public ConstraintSubType(RefTypeOrTPHOrWildcardOrGeneric typeKleiner, RefTypeOrTPHOrWildcardOrGeneric typeGroeßer) {
|
||||
public ConstraintSubType(TypeVarAbstract typeKleiner, TypeVarAbstract typeGroeßer) {
|
||||
this.typeKleiner = typeKleiner;
|
||||
this.typeGroeßer = typeGroeßer;
|
||||
}
|
||||
@@ -19,19 +19,19 @@ public class ConstraintSubType extends ConstraintAbstract {
|
||||
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getTypeKleiner() {
|
||||
public TypeVarAbstract getTypeKleiner() {
|
||||
return typeKleiner;
|
||||
}
|
||||
|
||||
public void setTypeKleiner(RefTypeOrTPHOrWildcardOrGeneric typeKleiner) {
|
||||
public void setTypeKleiner(TypeVarAbstract typeKleiner) {
|
||||
this.typeKleiner = typeKleiner;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getTypeGroeßer() {
|
||||
public TypeVarAbstract getTypeGroeßer() {
|
||||
return typeGroeßer;
|
||||
}
|
||||
|
||||
public void setTypeGroeßer(RefTypeOrTPHOrWildcardOrGeneric typeGroeßer) {
|
||||
public void setTypeGroeßer(TypeVarAbstract typeGroeßer) {
|
||||
this.typeGroeßer = typeGroeßer;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes4.algo;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,11 +10,11 @@ import java.util.List;
|
||||
*/
|
||||
public class ConstraintSubTypeInterface extends ConstraintAbstract{
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric kleiner;
|
||||
RefTypeOrTPHOrWildcardOrGeneric strucType;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> generics;
|
||||
TypeVarAbstract kleiner;
|
||||
TypeVarAbstract strucType;
|
||||
List<TypeVarAbstract> generics;
|
||||
|
||||
public ConstraintSubTypeInterface(RefTypeOrTPHOrWildcardOrGeneric kleiner, RefTypeOrTPHOrWildcardOrGeneric strucType, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public ConstraintSubTypeInterface(TypeVarAbstract kleiner, TypeVarAbstract strucType, List<TypeVarAbstract> generics) {
|
||||
this.kleiner = kleiner;
|
||||
this.strucType = strucType;
|
||||
this.generics = generics;
|
||||
|
@@ -25,7 +25,7 @@ public class Construct2 {
|
||||
List<Interface> interfaceList = new ArrayList<>();
|
||||
|
||||
// Sammeln der Constriants
|
||||
Map<RefTypeOrTPHOrWildcardOrGeneric,List<ConstraintAbstract>> sortetConstr = sortiereConstraints(constraints);
|
||||
Map<TypeVarAbstract,List<ConstraintAbstract>> sortetConstr = sortiereConstraints(constraints);
|
||||
|
||||
|
||||
// Erstellen der Interfaces
|
||||
@@ -41,8 +41,8 @@ public class Construct2 {
|
||||
for (ConstraintAbstract constraint : constraints) {
|
||||
if (constraint.getClass().equals(ConstraintSubType.class)) {
|
||||
ConstraintSubType constraintSubType = (ConstraintSubType) constraint;
|
||||
RefTypeOrTPHOrWildcardOrGeneric kleiner = mapAN.getNeu(constraintSubType.getTypeKleiner());
|
||||
RefTypeOrTPHOrWildcardOrGeneric groeßer = mapAN.getNeu(constraintSubType.getTypeGroeßer());
|
||||
TypeVarAbstract kleiner = mapAN.getNeu(constraintSubType.getTypeKleiner());
|
||||
TypeVarAbstract groeßer = mapAN.getNeu(constraintSubType.getTypeGroeßer());
|
||||
ConstraintSubType cNeu = new ConstraintSubType(kleiner,groeßer);
|
||||
constraintsNeu.add(cNeu);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class Construct2 {
|
||||
|
||||
|
||||
// Erstelle constraints + Interfaces für den strukturellen Typen
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric typeVar : sortetConstr.keySet()) {
|
||||
for (TypeVarAbstract typeVar : sortetConstr.keySet()) {
|
||||
ConstructInterfaceForType2 constructInterfaceForType2 = new ConstructInterfaceForType2(sortetConstr.get(typeVar),typeVar,mapAN.getNeu(typeVar) , mapAN);
|
||||
interfaceList.add(constructInterfaceForType2.getResultInterface());
|
||||
constraintsNeu.addAll(constructInterfaceForType2.getResultConstraints());
|
||||
@@ -75,13 +75,13 @@ public class Construct2 {
|
||||
|
||||
|
||||
// Sortieren der Constriants nach Strukturellem Typ
|
||||
private Map<RefTypeOrTPHOrWildcardOrGeneric,List<ConstraintAbstract>> sortiereConstraints(List<ConstraintAbstract> constraints) {
|
||||
private Map<TypeVarAbstract,List<ConstraintAbstract>> sortiereConstraints(List<ConstraintAbstract> constraints) {
|
||||
|
||||
Map<RefTypeOrTPHOrWildcardOrGeneric,List<ConstraintAbstract>> constraintMap = new ConcurrentHashMap<>();
|
||||
Map<TypeVarAbstract,List<ConstraintAbstract>> constraintMap = new ConcurrentHashMap<>();
|
||||
|
||||
for (ConstraintAbstract con : constraints) {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiver = null;
|
||||
TypeVarAbstract receiver = null;
|
||||
|
||||
// Suche den Receiver der Metohde oder des Feldes
|
||||
if (con.getClass().equals(ConstraintMethod.class)) {
|
||||
@@ -118,14 +118,14 @@ class ConstructInterfaceForType2 {
|
||||
private List<ConstraintAbstract> resultConstraints;
|
||||
|
||||
|
||||
public ConstructInterfaceForType2(List<ConstraintAbstract> constraints , RefTypeOrTPHOrWildcardOrGeneric receiverAlt , RefTypeOrTPHOrWildcardOrGeneric receiverNeu , MappingAltNeu altNeu) {
|
||||
public ConstructInterfaceForType2(List<ConstraintAbstract> constraints , TypeVarAbstract receiverAlt , TypeVarAbstract receiverNeu , MappingAltNeu altNeu) {
|
||||
|
||||
|
||||
resultConstraints = new ArrayList<>();
|
||||
|
||||
List<FieldInterface> fields = new ArrayList<>();
|
||||
List<MethodInterface> methods = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> genericsInterface = new ArrayList<>();
|
||||
List<TypeVarAbstract> genericsInterface = new ArrayList<>();
|
||||
|
||||
|
||||
// Erstelle Felder sowie Methoden des Interfaces
|
||||
@@ -142,10 +142,10 @@ class ConstructInterfaceForType2 {
|
||||
// Erstelle Methoden
|
||||
if (constraint.getClass().equals(ConstraintMethod.class)) {
|
||||
ConstraintMethod constraintMethod = (ConstraintMethod) constraint;
|
||||
RefTypeOrTPHOrWildcardOrGeneric rtType = TypeVarFactory.makeTypeVar();
|
||||
TypeVarAbstract rtType = TypeVarFactory.makeTypeVar();
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> neueArgsTV = new ArrayList<>();
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tv : constraintMethod.getArgsTypes()) {
|
||||
List<TypeVarAbstract> neueArgsTV = new ArrayList<>();
|
||||
for (TypeVarAbstract tv : constraintMethod.getArgsTypes()) {
|
||||
neueArgsTV.add(TypeVarFactory.makeTypeVar());
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package de.dhbwstuttgart.strucTypes4.algo;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -12,10 +12,10 @@ import java.util.List;
|
||||
public class MappingAltNeu {
|
||||
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> altList = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> neuList = new ArrayList<>();
|
||||
List<TypeVarAbstract> altList = new ArrayList<>();
|
||||
List<TypeVarAbstract> neuList = new ArrayList<>();
|
||||
|
||||
public void addTypeVar(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public void addTypeVar(TypeVarAbstract alt, TypeVarAbstract neu) {
|
||||
altList.add(alt);
|
||||
|
||||
// Versuch bereits bekannte Typen mitzunehmen
|
||||
@@ -28,7 +28,7 @@ public class MappingAltNeu {
|
||||
}
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getNeu (RefTypeOrTPHOrWildcardOrGeneric altTypeVar) {
|
||||
public TypeVarAbstract getNeu (TypeVarAbstract altTypeVar) {
|
||||
|
||||
// Wenn typ bereits bekannt ist
|
||||
if (altTypeVar.getClass().equals(TypeVarType.class)) {
|
||||
|
@@ -2,7 +2,7 @@ package de.dhbwstuttgart.strucTypes4.algo;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.*;
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class TypeExpr {
|
||||
|
||||
public static List<ConstraintAbstract> typeExpr(ExpressionAbstract exp, Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass , RefTypeOrTPHOrWildcardOrGeneric rec , RefTypeOrTPHOrWildcardOrGeneric returnType , TypeVarStore typeVarStore) {
|
||||
public static List<ConstraintAbstract> typeExpr(ExpressionAbstract exp, Map<String, TypeVarAbstract> ass , TypeVarAbstract rec , TypeVarAbstract returnType , TypeVarStore typeVarStore) {
|
||||
|
||||
if (exp.getClass().equals(ExprVar.class )) {
|
||||
ExprVar exprVar = (ExprVar) exp;
|
||||
@@ -38,8 +38,8 @@ public class TypeExpr {
|
||||
// Reihenfolge wichtig wg Rekursiven aufrufen und TypVariablen !!!
|
||||
constraints.addAll(typeExpr(expression.getReceiver(), ass, null ,null , typeVarStore));
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric tvReceiver = typeVarStore.storeTPH(expression.getReceiver().getTypePlaceHolder());
|
||||
RefTypeOrTPHOrWildcardOrGeneric tvThis = typeVarStore.storeTPH(expression.getTypePlaceHolder());
|
||||
TypeVarAbstract tvReceiver = typeVarStore.storeTPH(expression.getReceiver().getTypePlaceHolder());
|
||||
TypeVarAbstract tvThis = typeVarStore.storeTPH(expression.getTypePlaceHolder());
|
||||
constraints.addAll(typeExpr(expression.getCaller(),ass, tvReceiver , tvThis , typeVarStore));
|
||||
return constraints;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class TypeExpr {
|
||||
String klassenname = exprNew.getClassType();
|
||||
String assumptionKey = "$" + klassenname;
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric tv = ass.get(assumptionKey);
|
||||
TypeVarAbstract tv = ass.get(assumptionKey);
|
||||
Class typeClass = ((TypeVarType) tv).getTypeClass();
|
||||
|
||||
typeVarStore.addTuple(new TypeVarType(typeClass) , exprNew.getTypePlaceHolder());
|
||||
@@ -66,7 +66,7 @@ public class TypeExpr {
|
||||
//constriants.forEach((ConstraintAbstract cs) -> cs.replace(new TPH(gen) , new TPH(generic.get(gen)) ));
|
||||
String typeVar = key;
|
||||
String klasse = generic.get(key);
|
||||
RefTypeOrTPHOrWildcardOrGeneric klasseType = ass.get("$" + klasse);
|
||||
TypeVarAbstract klasseType = ass.get("$" + klasse);
|
||||
TypeVarType klasseTypeCast = (TypeVarType) klasseType;
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,7 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.*;
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Parser {
|
||||
|
||||
|
||||
// Quellcode wird geparst. Evtl. bekannte Klassen müssen über die Assumptions mitgegeben werden
|
||||
public Class parseCode(String quellcode , Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass ) {
|
||||
public Class parseCode(String quellcode , Map<String,TypeVarAbstract> ass ) {
|
||||
SourceFile sf = parse(quellcode);
|
||||
TI typeinference = new TI(ass,sf.getClassList().get(0));
|
||||
return typeinference.getResultClassTypedWithInterfaces();
|
||||
@@ -59,7 +59,7 @@ class TI {
|
||||
|
||||
Class resultClassTypedWithInterfaces;
|
||||
|
||||
public TI (Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass, Class aClass) {
|
||||
public TI (Map<String,TypeVarAbstract> ass, Class aClass) {
|
||||
|
||||
Type type = new Type(ass,aClass);
|
||||
|
||||
@@ -114,10 +114,10 @@ class Type {
|
||||
Class resultClassTyped;
|
||||
List<ConstraintAbstract> resultConstraintSet = new ArrayList<>();
|
||||
|
||||
public Type(Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass, Class aClass) {
|
||||
public Type(Map<String,TypeVarAbstract> ass, Class aClass) {
|
||||
|
||||
// 1. Erstellen der Assumptions für die Klasse
|
||||
Map<String, RefTypeOrTPHOrWildcardOrGeneric> fass_mass = aClass.makeAssumptions();
|
||||
Map<String, TypeVarAbstract> fass_mass = aClass.makeAssumptions();
|
||||
|
||||
// ToDo Vereinigen der Assumptions
|
||||
fass_mass.putAll(ass);
|
||||
@@ -134,7 +134,7 @@ class Type {
|
||||
|
||||
// AssAll Ass und fass und mass und this:A
|
||||
// ToDo this:a
|
||||
Map<String,RefTypeOrTPHOrWildcardOrGeneric> assMethod = method.makeAssumptions(aClass.typeVarStore);
|
||||
Map<String,TypeVarAbstract> assMethod = method.makeAssumptions(aClass.typeVarStore);
|
||||
|
||||
assMethod.putAll(fass_mass);
|
||||
resultConstraintSet.addAll(method.typeExpr(assMethod , aClass.typeVarStore));
|
||||
|
@@ -2,7 +2,7 @@ package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVar;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -32,24 +32,24 @@ public class Class extends SyntaxNode{
|
||||
}
|
||||
|
||||
|
||||
public Map<String,RefTypeOrTPHOrWildcardOrGeneric> makeAssumptions() {
|
||||
public Map<String,TypeVarAbstract> makeAssumptions() {
|
||||
|
||||
// Name bei Feldern feld, name bei methoden methode()
|
||||
Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass = new HashMap<>();
|
||||
Map<String, TypeVarAbstract> ass = new HashMap<>();
|
||||
// felder
|
||||
for (Field f : felder) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(f.getTypePlaceHolder());
|
||||
TypeVarAbstract tv = typeVarStore.storeTPH(f.getTypePlaceHolder());
|
||||
ass.put(f.getVar_name() , tv);
|
||||
}
|
||||
|
||||
// methoden
|
||||
for (Method m : methoden) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(m.getTypePlaceHolder());
|
||||
TypeVarAbstract tv = typeVarStore.storeTPH(m.getTypePlaceHolder());
|
||||
ass.put(m.getName()+"()", tv);
|
||||
}
|
||||
|
||||
// This einfügen
|
||||
RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(getTypePlaceHolder());
|
||||
TypeVarAbstract tv = typeVarStore.storeTPH(getTypePlaceHolder());
|
||||
ass.put("this" , tv);
|
||||
|
||||
return ass;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.algo.*;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarType;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ExprMCall extends ExpressionAbstract {
|
||||
}
|
||||
|
||||
|
||||
public List<ConstraintAbstract> typeExpr (Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass , RefTypeOrTPHOrWildcardOrGeneric receiver , RefTypeOrTPHOrWildcardOrGeneric returnType, TypeVarStore typeVarStore) {
|
||||
public List<ConstraintAbstract> typeExpr (Map<String, TypeVarAbstract> ass , TypeVarAbstract receiver , TypeVarAbstract returnType, TypeVarStore typeVarStore) {
|
||||
List<ConstraintAbstract> constraints = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ExprMCall extends ExpressionAbstract {
|
||||
|
||||
List<Argument> arguments = m.getArgs();
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> typeVars = new ArrayList<>();
|
||||
List<TypeVarAbstract> typeVars = new ArrayList<>();
|
||||
// Ermitteln der TypeVars der alten Klasse
|
||||
for (Argument argument : arguments ) {
|
||||
typeVars.add(c.getTypeVarStore().getTypeVarByTPH(argument.getTypePlaceHolder()));
|
||||
@@ -51,8 +51,8 @@ public class ExprMCall extends ExpressionAbstract {
|
||||
|
||||
// Hinzufügen von Constraints
|
||||
for (int i = 0; i < args.size() ; i++) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tvInNewKlasse = typeVars.get(i);
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeInAktKlasse = typeVarStore.getTypeVarByTPH(args.get(i).getTypePlaceHolder());
|
||||
TypeVarAbstract tvInNewKlasse = typeVars.get(i);
|
||||
TypeVarAbstract typeInAktKlasse = typeVarStore.getTypeVarByTPH(args.get(i).getTypePlaceHolder());
|
||||
constraints.add(new ConstraintSubType(tvInNewKlasse , typeInAktKlasse));
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ public class ExprMCall extends ExpressionAbstract {
|
||||
args.forEach(x -> constraints.addAll( TypeExpr.typeExpr( x,ass,null,null,typeVarStore) ));
|
||||
|
||||
// Liste mit Typen der Argumente der Methode sammeln
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> types = new ArrayList<>();
|
||||
List<TypeVarAbstract> types = new ArrayList<>();
|
||||
args.forEach(x -> types.add(typeVarStore.getTypeVarByTPH(x.getTypePlaceHolder())));
|
||||
|
||||
// Neue Liste mit neuen Beta - Argumenten erstellen
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> betaTypes = new ArrayList<>();
|
||||
List<TypeVarAbstract> betaTypes = new ArrayList<>();
|
||||
args.forEach(x -> betaTypes.add( typeVarStore.makeFreshTypeVar() ));
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,10 +16,10 @@ public class ExprVar extends ExpressionAbstract {
|
||||
String name;
|
||||
|
||||
|
||||
public List<ConstraintAbstract> typeExpr(Map<String, RefTypeOrTPHOrWildcardOrGeneric> ass, TypeVarStore typeVarStore) {
|
||||
public List<ConstraintAbstract> typeExpr(Map<String, TypeVarAbstract> ass, TypeVarStore typeVarStore) {
|
||||
List<ConstraintAbstract> constriants = new ArrayList<>();
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric tv = ass.get(name);
|
||||
TypeVarAbstract tv = ass.get(name);
|
||||
typeVarStore.addTuple(tv,getTypePlaceHolder());
|
||||
return constriants;
|
||||
}
|
||||
|
@@ -1,26 +1,26 @@
|
||||
package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 09.04.17.
|
||||
*/
|
||||
public class FieldInterface {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric type;
|
||||
TypeVarAbstract type;
|
||||
String name;
|
||||
|
||||
public FieldInterface(RefTypeOrTPHOrWildcardOrGeneric type, String name) {
|
||||
public FieldInterface(TypeVarAbstract type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getType() {
|
||||
public TypeVarAbstract getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
public void setType(TypeVarAbstract type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,13 +11,13 @@ import java.util.List;
|
||||
*/
|
||||
public class Interface {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric strucType;
|
||||
TypeVarAbstract strucType;
|
||||
List<FieldInterface> fields;
|
||||
List<MethodInterface> methods;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> generics;
|
||||
List<TypeVarAbstract> generics;
|
||||
|
||||
|
||||
public Interface(RefTypeOrTPHOrWildcardOrGeneric strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public Interface(TypeVarAbstract strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<TypeVarAbstract> generics) {
|
||||
this.strucType = strucType;
|
||||
this.fields = fields;
|
||||
this.methods = methods;
|
||||
@@ -40,11 +40,11 @@ public class Interface {
|
||||
this.methods = methods;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getGenerics() {
|
||||
public List<TypeVarAbstract> getGenerics() {
|
||||
return generics;
|
||||
}
|
||||
|
||||
public void setGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public void setGenerics(List<TypeVarAbstract> generics) {
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.algo.TypeExpr;
|
||||
import de.dhbwstuttgart.strucTypes4.typePlaceHolder.TPH;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -29,16 +29,16 @@ public class Method extends SyntaxNode {
|
||||
}
|
||||
|
||||
|
||||
public Map<String, RefTypeOrTPHOrWildcardOrGeneric> makeAssumptions(TypeVarStore typeVarStore) {
|
||||
Map<String, RefTypeOrTPHOrWildcardOrGeneric> assLokal = new HashMap<>();
|
||||
public Map<String, TypeVarAbstract> makeAssumptions(TypeVarStore typeVarStore) {
|
||||
Map<String, TypeVarAbstract> assLokal = new HashMap<>();
|
||||
for (Argument arg : args ) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tv = typeVarStore.storeTPH(arg.getTypePlaceHolder());
|
||||
TypeVarAbstract tv = typeVarStore.storeTPH(arg.getTypePlaceHolder());
|
||||
assLokal.put(arg.getName(), tv );
|
||||
}
|
||||
return assLokal;
|
||||
}
|
||||
|
||||
public List<ConstraintAbstract> typeExpr(Map<String,RefTypeOrTPHOrWildcardOrGeneric> ass, TypeVarStore typeVarStore) {
|
||||
public List<ConstraintAbstract> typeExpr(Map<String,TypeVarAbstract> ass, TypeVarStore typeVarStore) {
|
||||
return TypeExpr.typeExpr(expression,ass,null , null , typeVarStore);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package de.dhbwstuttgart.strucTypes4.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,11 +10,11 @@ import java.util.List;
|
||||
public class MethodInterface {
|
||||
|
||||
String name;
|
||||
RefTypeOrTPHOrWildcardOrGeneric rtType;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes;
|
||||
TypeVarAbstract rtType;
|
||||
List<TypeVarAbstract> argsTypes;
|
||||
|
||||
|
||||
public MethodInterface(String name, RefTypeOrTPHOrWildcardOrGeneric rtType, List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
|
||||
public MethodInterface(String name, TypeVarAbstract rtType, List<TypeVarAbstract> argsTypes) {
|
||||
this.name = name;
|
||||
this.rtType = rtType;
|
||||
this.argsTypes = argsTypes;
|
||||
@@ -29,19 +29,19 @@ public class MethodInterface {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getRtType() {
|
||||
public TypeVarAbstract getRtType() {
|
||||
return rtType;
|
||||
}
|
||||
|
||||
public void setRtType(RefTypeOrTPHOrWildcardOrGeneric rtType) {
|
||||
public void setRtType(TypeVarAbstract rtType) {
|
||||
this.rtType = rtType;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsTypes() {
|
||||
public List<TypeVarAbstract> getArgsTypes() {
|
||||
return argsTypes;
|
||||
}
|
||||
|
||||
public void setArgsTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
|
||||
public void setArgsTypes(List<TypeVarAbstract> argsTypes) {
|
||||
this.argsTypes = argsTypes;
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes4.typeVars;
|
||||
/**
|
||||
* Created by sebastian on 14.04.17.
|
||||
*/
|
||||
public class TypeVar extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
public class TypeVar extends TypeVarAbstract {
|
||||
|
||||
private String id;
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes4.typeVars;
|
||||
/**
|
||||
* Created by sebastian on 14.04.17.
|
||||
*/
|
||||
public abstract class RefTypeOrTPHOrWildcardOrGeneric {
|
||||
public abstract class TypeVarAbstract {
|
||||
|
||||
|
||||
|
@@ -14,11 +14,11 @@ import java.util.List;
|
||||
public class TypeVarStore {
|
||||
|
||||
|
||||
private HashMap<RefTypeOrTPHOrWildcardOrGeneric, List<TPH>> map = new HashMap<>();
|
||||
private HashMap<TypeVarAbstract, List<TPH>> map = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric storeTPH(TPH tph) {
|
||||
public TypeVarAbstract storeTPH(TPH tph) {
|
||||
|
||||
if (getTypeVarByTPH(tph) == null) {
|
||||
TypeVar tvNeu = TypeVarFactory.makeTypeVar();
|
||||
@@ -31,7 +31,7 @@ public class TypeVarStore {
|
||||
}
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric makeFreshTypeVar() {
|
||||
public TypeVarAbstract makeFreshTypeVar() {
|
||||
TypeVar neu = TypeVarFactory.makeTypeVar();
|
||||
List<TPH> tphList = new ArrayList<>();
|
||||
map.put(neu,tphList);
|
||||
@@ -40,7 +40,7 @@ public class TypeVarStore {
|
||||
|
||||
|
||||
|
||||
public void addTuple(RefTypeOrTPHOrWildcardOrGeneric tv, TPH tph) {
|
||||
public void addTuple(TypeVarAbstract tv, TPH tph) {
|
||||
|
||||
|
||||
// TypVar bereits vorhandne
|
||||
@@ -65,13 +65,13 @@ public class TypeVarStore {
|
||||
}
|
||||
|
||||
|
||||
public List<TPH> getTPHByTypeVar(RefTypeOrTPHOrWildcardOrGeneric tv) {
|
||||
public List<TPH> getTPHByTypeVar(TypeVarAbstract tv) {
|
||||
return map.get(tv);
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getTypeVarByTPH(TPH tph) {
|
||||
public TypeVarAbstract getTypeVarByTPH(TPH tph) {
|
||||
// TPH ist bereits einer TypVar zugeordnet
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric typeVar : map.keySet()) {
|
||||
for (TypeVarAbstract typeVar : map.keySet()) {
|
||||
if (map.get(typeVar).contains(tph)) {
|
||||
return typeVar;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class TypeVarStore {
|
||||
public TypeVarStore freshVariables() {
|
||||
TypeVarStore typeVarStore = new TypeVarStore();
|
||||
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
|
||||
for (TypeVarAbstract tvarOld : map.keySet()) {
|
||||
TypeVar tvNew = TypeVarFactory.makeTypeVar();
|
||||
typeVarStore.map.put(tvNew,map.get(tvarOld));
|
||||
}
|
||||
@@ -101,11 +101,11 @@ public class TypeVarStore {
|
||||
TypeVarStore typeVarStore = new TypeVarStore();
|
||||
|
||||
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
|
||||
for (TypeVarAbstract tvarOld : map.keySet()) {
|
||||
|
||||
// Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt.
|
||||
if (tvarOld.getClass().equals(TypeVarType.class)) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tvNew = tvarOld;
|
||||
TypeVarAbstract tvNew = tvarOld;
|
||||
typeVarStore.map.put(tvNew,map.get(tvarOld));
|
||||
mappingAltNeu.addTypeVar(tvarOld,tvNew);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class TypeVarStore {
|
||||
|
||||
|
||||
|
||||
public boolean replaceTypeVar(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public boolean replaceTypeVar(TypeVarAbstract old, TypeVarAbstract neu) {
|
||||
|
||||
if (map.containsKey(old)) {
|
||||
List<TPH> tphList = map.get(old);
|
||||
@@ -139,7 +139,7 @@ public class TypeVarStore {
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "--- TypeVarStore ---\n";
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tvar : map.keySet() ) {
|
||||
for (TypeVarAbstract tvar : map.keySet() ) {
|
||||
res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n";
|
||||
}
|
||||
return String.format(res);
|
||||
|
@@ -6,7 +6,7 @@ import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
|
||||
/**
|
||||
* Created by sebastian on 14.04.17.
|
||||
*/
|
||||
public class TypeVarType extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
public class TypeVarType extends TypeVarAbstract {
|
||||
|
||||
|
||||
private Class typeClass;
|
||||
|
@@ -1,100 +0,0 @@
|
||||
package de.dhbwstuttgart.strucTypes5.NeueKlassen;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 06.05.17.
|
||||
*/
|
||||
public class ConstructInterfaces {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//ClassOrInterface cl = makeInterface( );
|
||||
//System.out.println(cl);
|
||||
List<String> nameArguments = new ArrayList<>();
|
||||
nameArguments.add("x");
|
||||
nameArguments.add("y");
|
||||
Method m = makeMethodForInterface("mt" , nameArguments);
|
||||
makeMethodForInterface("add" , nameArguments );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static ClassOrInterface makeInterface(String nameInterface, List<String> arguments) {
|
||||
|
||||
|
||||
// Initialisierie alles
|
||||
int modifiers = 0;
|
||||
JavaClassName name = new JavaClassName(nameInterface);
|
||||
List< Field > fielddecl = new ArrayList<>();
|
||||
List< Method > methods = new ArrayList<>();
|
||||
List< Constructor > constructors = new ArrayList<>();
|
||||
|
||||
List<GenericTypeVar> genericTypeVars = new ArrayList<>();
|
||||
GenericDeclarationList genericClassParameters = new GenericDeclarationList(genericTypeVars, new NullToken());
|
||||
RefTypeOrTPHOrWildcardOrGeneric superClass = null;
|
||||
Boolean isInterface = true;
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = new ArrayList<>();
|
||||
|
||||
ClassOrInterface newInterface = new ClassOrInterface(modifiers, name, fielddecl,methods,constructors,
|
||||
genericClassParameters, superClass , isInterface , implementedInterfaces, new NullToken());
|
||||
|
||||
// Füge noch die benötigten Infos ein
|
||||
List<String> nameArguments = new ArrayList<>();
|
||||
nameArguments.add("x");
|
||||
nameArguments.add("y");
|
||||
Method m = makeMethodForInterface("mt" , nameArguments);
|
||||
|
||||
makeMethodForInterface("add" , nameArguments );
|
||||
|
||||
methods.add( makeMethodForInterface("add" , nameArguments));
|
||||
|
||||
return newInterface;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Method makeMethodForInterface(String name , List<String> namesArgruments ) {
|
||||
|
||||
String methodName = name;
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = null;
|
||||
int modifiers = 0;
|
||||
|
||||
List<FormalParameter> formalParameters = new ArrayList<>();
|
||||
// Generate Formalparameter
|
||||
for (String nameArgument : namesArgruments ) {
|
||||
// bounds
|
||||
// Todo parent Class
|
||||
GenericContext context = new GenericContext(new JavaClassName("xx") , "xx");
|
||||
|
||||
GenericTypeName typeName = new GenericTypeName( context,name);
|
||||
GenericRefType typeVar = new GenericRefType(typeName, new NullToken());
|
||||
formalParameters.add(new FormalParameter(name,typeVar , new NullToken() ));
|
||||
}
|
||||
|
||||
|
||||
ParameterList parameterList = new ParameterList(formalParameters,new NullToken());
|
||||
Block block = null;
|
||||
List<GenericTypeVar> genericDeclarations = new ArrayList<>();
|
||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(genericDeclarations ,new NullToken());
|
||||
Token offset = new NullToken();
|
||||
|
||||
return new Method(methodName ,returnType , 0 , parameterList ,block , gtvDeclarations, offset);
|
||||
}
|
||||
}
|
@@ -155,6 +155,7 @@ public class Construct {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Konstruktor:
|
||||
// public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, GenericDeclarationList genericClassParameters,
|
||||
// RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildca
|
||||
@@ -166,10 +167,8 @@ public class Construct {
|
||||
Boolean isInterface = true;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> implementetInterfaces = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
// return newInterface = new ClassOrInterface(modifers, name, fields,methods, genericClassParameters, superClass , isInterface, implementetInterfaces ,new NullToken());
|
||||
return null;
|
||||
ClassOrInterface newInterface = new ClassOrInterface(modifers, name, fields,methods, genericClassParameters, superClass , isInterface, implementetInterfaces ,new NullToken());
|
||||
return newInterface;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -12,7 +12,7 @@ import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface;
|
||||
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.MethodInterface;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.*;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -107,8 +107,8 @@ public class ConstructInterfaceTemplates {
|
||||
|
||||
List<FieldInterface> fields = new ArrayList<>();
|
||||
List<MethodInterface> methods = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> genericsForConstraint = new ArrayList<>();
|
||||
List<TypeVarAbstract> generics = new ArrayList<>();
|
||||
List<TypeVarAbstract> genericsForConstraint = new ArrayList<>();
|
||||
|
||||
|
||||
for (ConstraintAbstract constraint : constraintSet) {
|
||||
@@ -127,7 +127,7 @@ public class ConstructInterfaceTemplates {
|
||||
}
|
||||
|
||||
// Erstelle Generic für neuen Typvariablen für das Interface
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> args = new ArrayList<>();
|
||||
List<TypeVarAbstract> args = new ArrayList<>();
|
||||
for (TypeVar tv : cm.getArgumentTypes()) {
|
||||
TypeVar generic = typeVarStore.makeFreshTypeVar();
|
||||
args.add(generic);
|
||||
@@ -151,8 +151,8 @@ public class ConstructInterfaceTemplates {
|
||||
TypeVar neuerTypeReveiver = (TypeVar) mappingAltNeu.getNeu(receiver);
|
||||
InterfaceForConstraint interfaceForConstraint = new InterfaceForConstraint(receiver, genericsForConstraint);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric tSub = neuerTypeReveiver;
|
||||
RefTypeOrTPHOrWildcardOrGeneric tSuper = TypeVarFactory.makeTypeVar(interfaceForConstraint);
|
||||
TypeVarAbstract tSub = neuerTypeReveiver;
|
||||
TypeVarAbstract tSuper = TypeVarFactory.makeTypeVar(interfaceForConstraint);
|
||||
|
||||
ConstraintSubType newConstraint = new ConstraintSubType(tSub, tSuper);
|
||||
remainingConstraints.add(newConstraint);
|
||||
|
@@ -11,12 +11,11 @@ import de.dhbwstuttgart.strucTypes5.constraints.OldConstraints;
|
||||
import de.dhbwstuttgart.strucTypes5.solve.Rules;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -54,20 +53,12 @@ public class TI {
|
||||
ConstructInterfaceTemplates constructInterfaceTemplates = new ConstructInterfaceTemplates(cl, tp.getTypeVarStore(), type.constraintList , tp.getMappingAltNeu());
|
||||
System.out.println("Generierte Interfaces");
|
||||
System.out.println(constructInterfaceTemplates.interfaceList);
|
||||
//ToDo -> Interfaces umwandeln
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("Generierte Constraints");
|
||||
System.out.println(constructInterfaceTemplates.remainingConstraints);
|
||||
// ToDo -> constraints umwandeln
|
||||
|
||||
|
||||
|
||||
// Generiere Generics für die Klasse
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
|
||||
List<TypeVarAbstract> generics = new ArrayList<>();
|
||||
for (Method m : cl.getMethods()) {
|
||||
generics.add(tp.getTypeVarStore().getTypeVarByTPH(m.getType()));
|
||||
for (FormalParameter fp : m.getParameterList().getFormalparalist()) {
|
||||
@@ -105,6 +96,8 @@ public class TI {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------- Das Ergebnis aus Solve wird in die Assumptions gespeichert zu weiteren Verwendung ------------------------
|
||||
|
||||
|
||||
@@ -127,6 +120,9 @@ public class TI {
|
||||
System.out.println(newResultConstraints);
|
||||
this.resultConstraints = newResultConstraints;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -147,8 +143,6 @@ public class TI {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<ConstraintAbstract> bearbeiteConstraints(List<ConstraintAbstract> constraints , TypeVarStore typeVarStore) {
|
||||
|
||||
List<ConstraintAbstract> newResultConstraints = new ArrayList<>();
|
||||
@@ -157,12 +151,12 @@ public class TI {
|
||||
if (rc instanceof ConstraintSubType) {
|
||||
ConstraintSubType cSub = (ConstraintSubType) rc;
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric tSubNeu = null;
|
||||
RefTypeOrTPHOrWildcardOrGeneric tSuperNeu = null;
|
||||
TypeVarAbstract tSubNeu = null;
|
||||
TypeVarAbstract tSuperNeu = null;
|
||||
|
||||
// Check for Klasse
|
||||
RefTypeOrTPHOrWildcardOrGeneric tSub = cSub.getSubtype();
|
||||
RefTypeOrTPHOrWildcardOrGeneric tSuper = cSub.getSuperType();
|
||||
TypeVarAbstract tSub = cSub.getSubtype();
|
||||
TypeVarAbstract tSuper = cSub.getSuperType();
|
||||
|
||||
if (tSub instanceof TypeVar) {
|
||||
tSubNeu = typeVarStore.isType((TypeVar) tSub);
|
||||
|
@@ -7,7 +7,7 @@ import de.dhbwstuttgart.strucTypes5.assumptions.ChangeTypeVars;
|
||||
import de.dhbwstuttgart.strucTypes5.ausgabe.Class2String;
|
||||
import de.dhbwstuttgart.strucTypes5.constraints.*;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
@@ -16,7 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
|
||||
import javax.swing.plaf.nimbus.State;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TypeExpr {
|
||||
Return rt = (Return) method.get_Block().getStatements().get(0);
|
||||
|
||||
// Adds the Relation TypVariable Method == TypVariable Return Expression
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeVarMethod = typeVarStore.getTypeVarByTPH(method.getType());
|
||||
TypeVarAbstract typeVarMethod = typeVarStore.getTypeVarByTPH(method.getType());
|
||||
typeVarStore.addTuple(typeVarMethod, rt.getType());
|
||||
|
||||
|
||||
@@ -69,10 +69,7 @@ public class TypeExpr {
|
||||
LocalVar localVar = (LocalVar) expression;
|
||||
// Erstellung keines Constriants
|
||||
// Lediglich eintrag in TypeVarStore
|
||||
// Todo Problem TypeVar Expression != TypeVar Methode.
|
||||
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeVar = assumptionMap.getVarAssumption(localVar.get_expression());
|
||||
TypeVarAbstract typeVar = assumptionMap.getVarAssumption(localVar.get_expression());
|
||||
typeVarStore.addTuple(typeVar,localVar.getType());
|
||||
List<ConstraintAbstract> result = new ArrayList<>();
|
||||
return result;
|
||||
@@ -87,12 +84,6 @@ public class TypeExpr {
|
||||
else if (expression instanceof MethodCall) {
|
||||
MethodCall methodCall = (MethodCall) expression;
|
||||
|
||||
// Return aufgrund von Refactoring
|
||||
if (expression instanceof NewClass) {
|
||||
return walkNewClass((NewClass) expression);
|
||||
}
|
||||
|
||||
|
||||
// Call of non-Abstract Field do not add constraints
|
||||
if (methodCall.get_Receiver().getType() instanceof RefType) {
|
||||
List<ConstraintAbstract> result = typeExpression(methodCall.get_Receiver());
|
||||
@@ -139,34 +130,19 @@ public class TypeExpr {
|
||||
List<ConstraintAbstract> result = typeExpression(receiver.get_Expression());
|
||||
return result;
|
||||
}
|
||||
|
||||
else if (expression instanceof NewClass) {
|
||||
NewClass newClass = (NewClass) expression;
|
||||
/*
|
||||
@ veraltet -> kann seit big refactoring so nicht mehr geparst werden
|
||||
Stattdessen wird dies jetzt in Method Call verarbeitet, weil dort die new Methode aufläuft
|
||||
*/
|
||||
return null;
|
||||
|
||||
}
|
||||
else {
|
||||
System.err.println("Fehler unbekannt");
|
||||
System.out.println(expression);
|
||||
List<ConstraintAbstract> noResult = new ArrayList<>();
|
||||
return noResult;
|
||||
}
|
||||
}
|
||||
// Argumente
|
||||
List<ConstraintAbstract> result = new ArrayList<>();
|
||||
|
||||
// TypeExpr für die Argumente
|
||||
for (Expression arg : newClass.getArgumentList().getArguments()) {
|
||||
result.addAll(typeExpression(arg));
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
public List<ConstraintAbstract> walkNewClass(NewClass newClass) {
|
||||
|
||||
// Argumente
|
||||
List<ConstraintAbstract> result = new ArrayList<>();
|
||||
|
||||
// TypeExpr für die Argumente
|
||||
for (Expression arg : newClass.getArgumentList().getArguments()) {
|
||||
result.addAll(typeExpression(arg));
|
||||
}
|
||||
|
||||
/*
|
||||
Information:
|
||||
@@ -175,30 +151,35 @@ public class TypeExpr {
|
||||
Diese können dann verwendet werden.
|
||||
*/
|
||||
|
||||
//Versuche Informationen zu laden
|
||||
AssumptionClass assumptionClass = assumptionMap.getClassAssumption(newClass.getType().toString());
|
||||
if (assumptionClass != null) {
|
||||
|
||||
ChangeTypeVars changeTypeVars = new ChangeTypeVars();
|
||||
assumptionClass = changeTypeVars.change(assumptionClass);
|
||||
assumptionMap.putClass(assumptionClass);
|
||||
//Versuche Informationen zu laden
|
||||
AssumptionClass assumptionClass = assumptionMap.getClassAssumption(newClass.getType().toString());
|
||||
if (assumptionClass != null) {
|
||||
|
||||
ChangeTypeVars changeTypeVars = new ChangeTypeVars();
|
||||
assumptionClass = changeTypeVars.change(assumptionClass);
|
||||
assumptionMap.putClass(assumptionClass);
|
||||
|
||||
OldConstraints oldConstraints= new OldConstraints(assumptionClass.getConstraints());
|
||||
result.add(oldConstraints);
|
||||
|
||||
System.out.println("-----------------KlassenAssumption ------");
|
||||
System.out.println(assumptionClass.getTypeVarStore().toString());
|
||||
Class2String class2String = new Class2String();
|
||||
System.out.println(class2String.generateStringTypeVars(assumptionClass.getCl(), assumptionClass.getTypeVarStore()));
|
||||
System.out.println("-----------------------");
|
||||
|
||||
//ChangeTypeVars changeTypeVars = new ChangeTypeVars();
|
||||
//AssumptionClass assumptionClass1 = changeTypeVars.change(assumptionClass);
|
||||
|
||||
// ToDO Problem mit den neuen Typvariablen da die infos nochmals geladen werden beim Method call !!!
|
||||
// (Das einige logische wäre bereits davor die TypVariablen zu tauschen -> So steht es ja eigentlich auf im Skript
|
||||
//assumptionMap.putClass(assumptionClass1);
|
||||
}
|
||||
|
||||
OldConstraints oldConstraints= new OldConstraints(assumptionClass.getConstraints());
|
||||
result.add(oldConstraints);
|
||||
|
||||
System.out.println("-----------------KlassenAssumption ------");
|
||||
System.out.println(assumptionClass.getTypeVarStore().toString());
|
||||
Class2String class2String = new Class2String();
|
||||
System.out.println(class2String.generateStringTypeVars(assumptionClass.getCl(), assumptionClass.getTypeVarStore()));
|
||||
System.out.println("-----------------------");
|
||||
|
||||
//ChangeTypeVars changeTypeVars = new ChangeTypeVars();
|
||||
//AssumptionClass assumptionClass1 = changeTypeVars.change(assumptionClass);
|
||||
|
||||
// ToDO Problem mit den neuen Typvariablen da die infos nochmals geladen werden beim Method call !!!
|
||||
// (Das einige logische wäre bereits davor die TypVariablen zu tauschen -> So steht es ja eigentlich auf im Skript
|
||||
//assumptionMap.putClass(assumptionClass1);
|
||||
}
|
||||
|
||||
/*
|
||||
//Versuche Informationen zu laden
|
||||
@@ -220,13 +201,19 @@ public class TypeExpr {
|
||||
}
|
||||
*/
|
||||
|
||||
typeVarStore.addTuple(TypeVarFactory.makeTypeVar() , newClass.getType());
|
||||
return result;
|
||||
|
||||
typeVarStore.addTuple(TypeVarFactory.makeTypeVar() , newClass.getType());
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
System.err.println("Fehler unbekannt");
|
||||
System.out.println(expression);
|
||||
List<ConstraintAbstract> noResult = new ArrayList<>();
|
||||
return noResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<ConstraintAbstract> getResultConstraints() {
|
||||
return resultConstraints;
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package de.dhbwstuttgart.strucTypes5.assumptions;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 20.04.17. *
|
||||
@@ -13,9 +11,9 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
public class AssumptionArgument extends AssumptionAbstract {
|
||||
|
||||
private String nameOfArgument;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric typeOfArgument;
|
||||
private TypeVarAbstract typeOfArgument;
|
||||
|
||||
public AssumptionArgument(String nameOfArgument, RefTypeOrTPHOrWildcardOrGeneric typeOfArgument) {
|
||||
public AssumptionArgument(String nameOfArgument, TypeVarAbstract typeOfArgument) {
|
||||
this.nameOfArgument = nameOfArgument;
|
||||
this.typeOfArgument = typeOfArgument;
|
||||
}
|
||||
@@ -29,11 +27,11 @@ public class AssumptionArgument extends AssumptionAbstract {
|
||||
this.nameOfArgument = nameOfArgument;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getTypeOfArgument() {
|
||||
public TypeVarAbstract getTypeOfArgument() {
|
||||
return typeOfArgument;
|
||||
}
|
||||
|
||||
public void setTypeOfArgument(RefTypeOrTPHOrWildcardOrGeneric typeOfArgument) {
|
||||
public void setTypeOfArgument(TypeVarAbstract typeOfArgument) {
|
||||
this.typeOfArgument = typeOfArgument;
|
||||
}
|
||||
|
||||
|
@@ -4,10 +4,9 @@ package de.dhbwstuttgart.strucTypes5.assumptions;
|
||||
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.interfaceTemplates.Interface;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,15 +20,14 @@ public class AssumptionClass extends AssumptionAbstract {
|
||||
private TypeVarStore typeVarStore;
|
||||
private AssumptionMap assumptionMap;
|
||||
private List<ConstraintAbstract> constraints;
|
||||
//CLASSORINTERFACE umwandeln
|
||||
private List<Interface> generatedinterfaces;
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> genericsForClass;
|
||||
private List<TypeVarAbstract> genericsForClass;
|
||||
|
||||
public AssumptionClass() {
|
||||
|
||||
}
|
||||
|
||||
public AssumptionClass(ClassOrInterface cl, TypeVarStore typeVarStore, AssumptionMap assumptionMap, List<ConstraintAbstract> constraints, List<Interface> generatedinterfaces, List<RefTypeOrTPHOrWildcardOrGeneric> genericsForClass) {
|
||||
public AssumptionClass(ClassOrInterface cl, TypeVarStore typeVarStore, AssumptionMap assumptionMap, List<ConstraintAbstract> constraints, List<Interface> generatedinterfaces, List<TypeVarAbstract> genericsForClass) {
|
||||
this.cl = cl;
|
||||
this.typeVarStore = typeVarStore;
|
||||
this.assumptionMap = assumptionMap;
|
||||
@@ -79,11 +77,11 @@ public class AssumptionClass extends AssumptionAbstract {
|
||||
this.generatedinterfaces = generatedinterfaces;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getGenericsForClass() {
|
||||
public List<TypeVarAbstract> getGenericsForClass() {
|
||||
return genericsForClass;
|
||||
}
|
||||
|
||||
public void setGenericsForClass(List<RefTypeOrTPHOrWildcardOrGeneric> genericsForClass) {
|
||||
public void setGenericsForClass(List<TypeVarAbstract> genericsForClass) {
|
||||
this.genericsForClass = genericsForClass;
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,12 @@
|
||||
package de.dhbwstuttgart.strucTypes5.assumptions;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -57,7 +56,7 @@ public class AssumptionFactory {
|
||||
|
||||
|
||||
public static AssumptionArgument makeArgumentAssumption(FormalParameter formalParameter , TypeVarStore typeVarStore) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeVar = typeVarStore.storeTPH(formalParameter.getType());
|
||||
TypeVarAbstract typeVar = typeVarStore.storeTPH(formalParameter.getType());
|
||||
return new AssumptionArgument(formalParameter.getName(), typeVar);
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes5.assumptions;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -56,7 +55,7 @@ public class AssumptionMap {
|
||||
}
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getVarAssumption(String name) {
|
||||
public TypeVarAbstract getVarAssumption(String name) {
|
||||
// gibt lokale Var zurück. wenn nicht vorhanden gloable. wenn nicht vorhanden null
|
||||
|
||||
if (argAss.containsKey(name)) {
|
||||
@@ -78,7 +77,7 @@ public class AssumptionMap {
|
||||
return true;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getThisVar(String name) {
|
||||
public TypeVarAbstract getThisVar(String name) {
|
||||
return fass.get(name).getTypeVar();
|
||||
}
|
||||
|
||||
|
@@ -6,8 +6,7 @@ import de.dhbwstuttgart.strucTypes5.constraints.ConstraintSubType;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.MappingAltNeu;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.ResultTuple;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -39,11 +38,11 @@ public class ChangeTypeVars {
|
||||
if (c instanceof ConstraintSubType) {
|
||||
ConstraintSubType csub = (ConstraintSubType) c;
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric tsub = csub.getSubtype();
|
||||
RefTypeOrTPHOrWildcardOrGeneric tsuper = csub.getSuperType();
|
||||
TypeVarAbstract tsub = csub.getSubtype();
|
||||
TypeVarAbstract tsuper = csub.getSuperType();
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric newTSub = mappingAltNeu.getNeu(tsub);
|
||||
RefTypeOrTPHOrWildcardOrGeneric newTsuper = mappingAltNeu.getNeu(tsuper);
|
||||
TypeVarAbstract newTSub = mappingAltNeu.getNeu(tsub);
|
||||
TypeVarAbstract newTsuper = mappingAltNeu.getNeu(tsuper);
|
||||
|
||||
ConstraintSubType newC = new ConstraintSubType(newTSub , newTsuper);
|
||||
newConstraints.add(newC);
|
||||
@@ -60,8 +59,8 @@ public class ChangeTypeVars {
|
||||
|
||||
|
||||
// Tausche Generics aus
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> genericsneu = new ArrayList<>();
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tv : oldAssClass.getGenericsForClass()) {
|
||||
List<TypeVarAbstract> genericsneu = new ArrayList<>();
|
||||
for (TypeVarAbstract tv : oldAssClass.getGenericsForClass()) {
|
||||
if (tv instanceof TypeVar) {
|
||||
TypeVar genericNeu = (TypeVar) mappingAltNeu.getNeu(tv);
|
||||
genericsneu.add(genericNeu);
|
||||
|
@@ -133,13 +133,6 @@ public class Class2String {
|
||||
}
|
||||
else if (expression instanceof MethodCall) {
|
||||
MethodCall methodCall = (MethodCall) expression;
|
||||
|
||||
if (methodCall instanceof NewClass) {
|
||||
return generateExpressionNewClass((NewClass) methodCall);
|
||||
}
|
||||
|
||||
|
||||
|
||||
String receiverString = generateExpressionString(methodCall.get_Receiver());
|
||||
|
||||
String arguments = "";
|
||||
@@ -154,8 +147,14 @@ public class Class2String {
|
||||
return generateExpressionString(receiver.get_Expression());
|
||||
}
|
||||
else if (expression instanceof NewClass) {
|
||||
NewClass newClass = (NewClass) expression;
|
||||
|
||||
return "XXX";
|
||||
String arguments = "";
|
||||
for (Expression arg : newClass.getArgumentList().getArguments()) {
|
||||
String expArg = generateExpressionString(arg);
|
||||
arguments = arguments.concat(expArg + ",");
|
||||
}
|
||||
return String.format("[new %s( %s ): %s ]" , newClass.getType() , arguments , newClass.getType() );
|
||||
}
|
||||
else {
|
||||
return "Expression nicht bekannt";
|
||||
@@ -197,16 +196,6 @@ public class Class2String {
|
||||
}
|
||||
|
||||
|
||||
private String generateExpressionNewClass( NewClass newClass ) {
|
||||
String arguments = "";
|
||||
for (Expression arg : newClass.getArgumentList().getArguments()) {
|
||||
String expArg = generateExpressionString(arg);
|
||||
arguments = arguments.concat(expArg + ",");
|
||||
}
|
||||
return String.format("[new %s( %s ): %s ]" , newClass.getType() , arguments , newClass.getType() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,21 +1,20 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 20.04.17.
|
||||
*/
|
||||
public abstract class ConstraintAbstract {
|
||||
|
||||
public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric helpChange(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu, RefTypeOrTPHOrWildcardOrGeneric inFrage) {
|
||||
public static TypeVarAbstract helpChange(TypeVarAbstract old, TypeVarAbstract neu, TypeVarAbstract inFrage) {
|
||||
if (inFrage instanceof TypeVarInterface) {
|
||||
((TypeVarInterface) inFrage).getInterfaceForConstraint().replaceTypeVarAbstract(old,neu);
|
||||
return inFrage;
|
||||
@@ -26,7 +25,7 @@ public abstract class ConstraintAbstract {
|
||||
}
|
||||
|
||||
|
||||
public static boolean helpChange2(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu, RefTypeOrTPHOrWildcardOrGeneric inFrage) {
|
||||
public static boolean helpChange2(TypeVarAbstract old, TypeVarAbstract neu, TypeVarAbstract inFrage) {
|
||||
if (inFrage instanceof TypeVarInterface) {
|
||||
ConstraintAbstract.helpChange(old,neu,inFrage);
|
||||
return true;
|
||||
|
@@ -1,35 +1,34 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 02.05.17.
|
||||
*/
|
||||
public class ConstraintInterface extends ConstraintAbstract {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric SubType;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric SuperType;
|
||||
private TypeVarAbstract SubType;
|
||||
private TypeVarAbstract SuperType;
|
||||
|
||||
public ConstraintInterface(RefTypeOrTPHOrWildcardOrGeneric subType, RefTypeOrTPHOrWildcardOrGeneric superType) {
|
||||
public ConstraintInterface(TypeVarAbstract subType, TypeVarAbstract superType) {
|
||||
SubType = subType;
|
||||
SuperType = superType;
|
||||
}
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSubType() {
|
||||
public TypeVarAbstract getSubType() {
|
||||
return SubType;
|
||||
}
|
||||
|
||||
public void setSubType(RefTypeOrTPHOrWildcardOrGeneric subType) {
|
||||
public void setSubType(TypeVarAbstract subType) {
|
||||
SubType = subType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSuperType() {
|
||||
public TypeVarAbstract getSuperType() {
|
||||
return SuperType;
|
||||
}
|
||||
|
||||
public void setSuperType(RefTypeOrTPHOrWildcardOrGeneric superType) {
|
||||
public void setSuperType(TypeVarAbstract superType) {
|
||||
SuperType = superType;
|
||||
}
|
||||
|
||||
|
@@ -1,25 +1,24 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 01.05.17.
|
||||
*/
|
||||
public class ConstraintShouldEqual extends ConstraintAbstract{
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric t1;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric t2;
|
||||
private TypeVarAbstract t1;
|
||||
private TypeVarAbstract t2;
|
||||
|
||||
public ConstraintShouldEqual(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2) {
|
||||
public ConstraintShouldEqual(TypeVarAbstract t1, TypeVarAbstract t2) {
|
||||
this.t1 = t1;
|
||||
this.t2 = t2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) {
|
||||
if (t1.equals(alt)) {
|
||||
t1 = ConstraintAbstract.helpChange(alt,neu,t1);
|
||||
}
|
||||
@@ -31,19 +30,19 @@ public class ConstraintShouldEqual extends ConstraintAbstract{
|
||||
return true;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getT1() {
|
||||
public TypeVarAbstract getT1() {
|
||||
return t1;
|
||||
}
|
||||
|
||||
public void setT1(RefTypeOrTPHOrWildcardOrGeneric t1) {
|
||||
public void setT1(TypeVarAbstract t1) {
|
||||
this.t1 = t1;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getT2() {
|
||||
public TypeVarAbstract getT2() {
|
||||
return t2;
|
||||
}
|
||||
|
||||
public void setT2(RefTypeOrTPHOrWildcardOrGeneric t2) {
|
||||
public void setT2(TypeVarAbstract t2) {
|
||||
this.t2 = t2;
|
||||
}
|
||||
|
||||
|
@@ -2,8 +2,7 @@ package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 20.04.17.
|
||||
@@ -14,17 +13,17 @@ public class ConstraintSubType extends ConstraintAbstract{
|
||||
// TODO Hier muss ich mir das noch überlegen wie es geht. Evtl ist eine TypeVarType nicht notwenidg
|
||||
// Eine Typvariable kann TypVar sein, ein Typ kann auch eine TypVar sein , ein Interface kann was sein ?
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric subtype;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric superType;
|
||||
private TypeVarAbstract subtype;
|
||||
private TypeVarAbstract superType;
|
||||
|
||||
public ConstraintSubType(RefTypeOrTPHOrWildcardOrGeneric subtype, RefTypeOrTPHOrWildcardOrGeneric superType) {
|
||||
public ConstraintSubType(TypeVarAbstract subtype, TypeVarAbstract superType) {
|
||||
this.subtype = subtype;
|
||||
this.superType = superType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) {
|
||||
if (subtype.equals(alt)) {
|
||||
subtype = ConstraintAbstract.helpChange(alt,neu,subtype);
|
||||
}
|
||||
@@ -37,19 +36,19 @@ public class ConstraintSubType extends ConstraintAbstract{
|
||||
}
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSubtype() {
|
||||
public TypeVarAbstract getSubtype() {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
public void setSubtype(RefTypeOrTPHOrWildcardOrGeneric subtype) {
|
||||
public void setSubtype(TypeVarAbstract subtype) {
|
||||
this.subtype = subtype;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSuperType() {
|
||||
public TypeVarAbstract getSuperType() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
public void setSuperType(RefTypeOrTPHOrWildcardOrGeneric superType) {
|
||||
public void setSuperType(TypeVarAbstract superType) {
|
||||
this.superType = superType;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,40 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 20.04.17.
|
||||
*/
|
||||
public class ConstraintSubTypeGeneric<T1, T2> extends ConstraintAbstract {
|
||||
|
||||
private T1 subType;
|
||||
private T2 superType;
|
||||
|
||||
|
||||
public ConstraintSubTypeGeneric(T1 subType, T2 superType) {
|
||||
this.subType = subType;
|
||||
this.superType = superType;
|
||||
}
|
||||
|
||||
|
||||
public T1 getSubType() {
|
||||
return subType;
|
||||
}
|
||||
|
||||
public void setSubType(T1 subType) {
|
||||
this.subType = subType;
|
||||
}
|
||||
|
||||
public T2 getSuperType() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
public void setSuperType(T2 superType) {
|
||||
this.superType = superType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ConstraintSubTypeG( %s <* %s )" , subType , superType);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,34 +1,33 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 01.05.17.
|
||||
*/
|
||||
public class ConstraintSubstitution extends ConstraintAbstract {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric t1;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric t2;
|
||||
private TypeVarAbstract t1;
|
||||
private TypeVarAbstract t2;
|
||||
|
||||
public ConstraintSubstitution(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2) {
|
||||
public ConstraintSubstitution(TypeVarAbstract t1, TypeVarAbstract t2) {
|
||||
this.t1 = t1;
|
||||
this.t2 = t2;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getT1() {
|
||||
public TypeVarAbstract getT1() {
|
||||
return t1;
|
||||
}
|
||||
|
||||
public void setT1(RefTypeOrTPHOrWildcardOrGeneric t1) {
|
||||
public void setT1(TypeVarAbstract t1) {
|
||||
this.t1 = t1;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getT2() {
|
||||
public TypeVarAbstract getT2() {
|
||||
return t2;
|
||||
}
|
||||
|
||||
public void setT2(RefTypeOrTPHOrWildcardOrGeneric t2) {
|
||||
public void setT2(TypeVarAbstract t2) {
|
||||
this.t2 = t2;
|
||||
}
|
||||
|
||||
|
@@ -1,52 +0,0 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 08.05.17.
|
||||
*/
|
||||
public class ConvertConstraints {
|
||||
|
||||
|
||||
public static ConstraintSet<Constraint> convert(List<ConstraintAbstract> constraints) {
|
||||
|
||||
ConstraintSet<Constraint> constraintSet = new ConstraintSet<>();
|
||||
|
||||
for (ConstraintAbstract constraint : constraints) {
|
||||
if (constraint instanceof ConstraintSubType) {
|
||||
constraintSet.addUndConstraint(convertConstraintSubType((ConstraintSubType) constraint));
|
||||
}
|
||||
}
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static Constraint<UnifyPair> convertConstraintSubType(ConstraintSubType css) {
|
||||
|
||||
UnifyType t1 = UnifyTypeFactory.convert(css.getSubtype());
|
||||
UnifyType t2 = UnifyTypeFactory.convert(css.getSuperType());
|
||||
|
||||
UnifyPair pair = UnifyTypeFactory.generateSmallerPair(t1,t2);
|
||||
|
||||
Constraint<UnifyPair> constraint = new Constraint<>();
|
||||
constraint.add(pair);
|
||||
|
||||
return constraint;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
package de.dhbwstuttgart.strucTypes5.constraints;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.algo.Type;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -12,21 +11,21 @@ import java.util.List;
|
||||
*/
|
||||
public class InterfaceForConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric strucType;
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> generics;
|
||||
private TypeVarAbstract strucType;
|
||||
private List<TypeVarAbstract> generics;
|
||||
|
||||
|
||||
public InterfaceForConstraint(RefTypeOrTPHOrWildcardOrGeneric strucType, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public InterfaceForConstraint(TypeVarAbstract strucType, List<TypeVarAbstract> generics) {
|
||||
this.strucType = strucType;
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
|
||||
public boolean replaceTypeVarAbstract(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public boolean replaceTypeVarAbstract(TypeVarAbstract alt, TypeVarAbstract neu) {
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> genericsneu = new ArrayList<>();
|
||||
List<TypeVarAbstract> genericsneu = new ArrayList<>();
|
||||
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tv : generics) {
|
||||
for (TypeVarAbstract tv : generics) {
|
||||
if (tv.equals(alt)) {
|
||||
genericsneu.add(neu);
|
||||
}
|
||||
@@ -34,25 +33,26 @@ public class InterfaceForConstraint {
|
||||
genericsneu.add(tv);
|
||||
}
|
||||
}
|
||||
|
||||
generics = genericsneu;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getStrucType() {
|
||||
public TypeVarAbstract getStrucType() {
|
||||
return strucType;
|
||||
}
|
||||
|
||||
public void setStrucType(RefTypeOrTPHOrWildcardOrGeneric strucType) {
|
||||
public void setStrucType(TypeVarAbstract strucType) {
|
||||
this.strucType = strucType;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getGenerics() {
|
||||
public List<TypeVarAbstract> getGenerics() {
|
||||
return generics;
|
||||
}
|
||||
|
||||
public void setGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public void setGenerics(List<TypeVarAbstract> generics) {
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
|
@@ -33,4 +33,12 @@ public class FactoryForElementes {
|
||||
GenericRefType genericRefType = new GenericRefType( genericTypeName , new NullToken());
|
||||
return genericRefType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,27 +1,26 @@
|
||||
package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
|
||||
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 09.04.17.
|
||||
*/
|
||||
public class FieldInterface {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric type;
|
||||
TypeVarAbstract type;
|
||||
String name;
|
||||
|
||||
public FieldInterface(RefTypeOrTPHOrWildcardOrGeneric type, String name) {
|
||||
public FieldInterface(TypeVarAbstract type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getType() {
|
||||
public TypeVarAbstract getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
public void setType(TypeVarAbstract type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@@ -3,8 +3,7 @@ package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
|
||||
|
||||
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,13 +13,13 @@ import java.util.List;
|
||||
*/
|
||||
public class Interface {
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric strucType;
|
||||
TypeVarAbstract strucType;
|
||||
List<FieldInterface> fields;
|
||||
List<MethodInterface> methods;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> generics;
|
||||
List<TypeVarAbstract> generics;
|
||||
|
||||
|
||||
public Interface(RefTypeOrTPHOrWildcardOrGeneric strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public Interface(TypeVarAbstract strucType, List<FieldInterface> fields, List<MethodInterface> methods, List<TypeVarAbstract> generics) {
|
||||
this.strucType = strucType;
|
||||
this.fields = fields;
|
||||
this.methods = methods;
|
||||
@@ -43,20 +42,17 @@ public class Interface {
|
||||
this.methods = methods;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getGenerics() {
|
||||
public List<TypeVarAbstract> getGenerics() {
|
||||
return generics;
|
||||
}
|
||||
|
||||
public void setGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> generics) {
|
||||
public void setGenerics(List<TypeVarAbstract> generics) {
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = String.format("interface %s < %s > { \n %s \n %s } \n \n " , strucType , generics, fields.toString() , methods.toString());
|
||||
res = res.replace("[" , "");
|
||||
res = res.replace("]" , "");
|
||||
return res;
|
||||
return String.format("interface %s < %s > { \n %s \n %s } \n \n " , strucType , generics, fields.toString() , methods.toString());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2,8 +2,7 @@ package de.dhbwstuttgart.strucTypes5.interfaceTemplates;
|
||||
|
||||
|
||||
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,11 +12,11 @@ import java.util.List;
|
||||
public class MethodInterface {
|
||||
|
||||
String name;
|
||||
RefTypeOrTPHOrWildcardOrGeneric rtType;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes;
|
||||
TypeVarAbstract rtType;
|
||||
List<TypeVarAbstract> argsTypes;
|
||||
|
||||
|
||||
public MethodInterface(String name, RefTypeOrTPHOrWildcardOrGeneric rtType, List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
|
||||
public MethodInterface(String name, TypeVarAbstract rtType, List<TypeVarAbstract> argsTypes) {
|
||||
this.name = name;
|
||||
this.rtType = rtType;
|
||||
this.argsTypes = argsTypes;
|
||||
@@ -32,19 +31,19 @@ public class MethodInterface {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getRtType() {
|
||||
public TypeVarAbstract getRtType() {
|
||||
return rtType;
|
||||
}
|
||||
|
||||
public void setRtType(RefTypeOrTPHOrWildcardOrGeneric rtType) {
|
||||
public void setRtType(TypeVarAbstract rtType) {
|
||||
this.rtType = rtType;
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgsTypes() {
|
||||
public List<TypeVarAbstract> getArgsTypes() {
|
||||
return argsTypes;
|
||||
}
|
||||
|
||||
public void setArgsTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argsTypes) {
|
||||
public void setArgsTypes(List<TypeVarAbstract> argsTypes) {
|
||||
this.argsTypes = argsTypes;
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,7 @@ public class Ruler {
|
||||
public void rule() {
|
||||
//System.out.println("StartConstraints: " + constraintList);
|
||||
Help.print("StartConstraints" , constraintList);
|
||||
substitutionList = ruleAll(constraintList,substitutionList);
|
||||
substitutionList = ruleAll(constraintList,substitutionList);
|
||||
Help.print("Aktuelle Substitutionen: " ,substitutionList);
|
||||
Help.print("Aktuelle Constriants: " , constraintList);
|
||||
|
||||
|
@@ -5,10 +5,9 @@ package de.dhbwstuttgart.strucTypes5.solve;
|
||||
import de.dhbwstuttgart.strucTypes5.algo.Type;
|
||||
import de.dhbwstuttgart.strucTypes5.constraints.*;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
|
||||
//import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarInterface;
|
||||
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
|
||||
|
||||
@@ -79,8 +78,8 @@ public class Rules {
|
||||
for (ConstraintAbstract cs : constraints) {
|
||||
if (cs instanceof ConstraintShouldEqual) {
|
||||
ConstraintShouldEqual csse = (ConstraintShouldEqual) cs;
|
||||
RefTypeOrTPHOrWildcardOrGeneric theta = csse.getT1();
|
||||
RefTypeOrTPHOrWildcardOrGeneric typeVar = csse.getT2();
|
||||
TypeVarAbstract theta = csse.getT1();
|
||||
TypeVarAbstract typeVar = csse.getT2();
|
||||
if (theta instanceof TypeVarRefType && typeVar instanceof TypeVar) {
|
||||
csse.setT1(typeVar);
|
||||
csse.setT2(theta);
|
||||
@@ -101,8 +100,8 @@ public class Rules {
|
||||
public void subst(List<ConstraintAbstract> constraints) {
|
||||
for (ConstraintAbstract cs : constraints) {
|
||||
if (cs instanceof ConstraintShouldEqual) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric t1 = ((ConstraintShouldEqual) cs).getT1();
|
||||
RefTypeOrTPHOrWildcardOrGeneric t2 = ((ConstraintShouldEqual) cs).getT2();
|
||||
TypeVarAbstract t1 = ((ConstraintShouldEqual) cs).getT1();
|
||||
TypeVarAbstract t2 = ((ConstraintShouldEqual) cs).getT2();
|
||||
|
||||
if (t1 instanceof TypeVar) {
|
||||
if (t2 instanceof TypeVarRefType || t2 instanceof TypeVarInterface) {
|
||||
@@ -133,7 +132,7 @@ public class Rules {
|
||||
|
||||
|
||||
|
||||
public void replaceAll(List<ConstraintAbstract> constraints , RefTypeOrTPHOrWildcardOrGeneric alt , RefTypeOrTPHOrWildcardOrGeneric neu ) {
|
||||
public void replaceAll(List<ConstraintAbstract> constraints , TypeVarAbstract alt , TypeVarAbstract neu ) {
|
||||
|
||||
System.out.println(String.format("Replace All: %s -> %s" , alt , neu ));
|
||||
for (ConstraintAbstract cs : constraints) {
|
||||
@@ -145,6 +144,9 @@ public class Rules {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ToDo Not implemented
|
||||
public void reduce(List<ConstraintAbstract> constraints) {
|
||||
for (ConstraintAbstract cs : constraints) {
|
||||
@@ -155,7 +157,7 @@ public class Rules {
|
||||
|
||||
/*
|
||||
|
||||
//
|
||||
// Todo wer sagt dass man nicht irgendwo in der mitte anfängt
|
||||
public void reflect(List<ConstraintAbstract> constriants) {
|
||||
for (ConstraintAbstract cs : constriants) {
|
||||
if (cs instanceof ConstraintSubType) {
|
||||
@@ -241,10 +243,10 @@ public class Rules {
|
||||
ConstraintSubType css = (ConstraintSubType) cs;
|
||||
if (css.getSubtype() instanceof TypeVarRefType && css.getSuperType() instanceof TypeVar) {
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> reflect = reflectNext(constraints, css.getSubtype(), (TypeVar) css.getSuperType());
|
||||
List<TypeVarAbstract> reflect = reflectNext(constraints, css.getSubtype(), (TypeVar) css.getSuperType());
|
||||
if (reflect != null) {
|
||||
System.out.println("Reflect für " + reflect + css.getSubtype());
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tv : reflect) {
|
||||
for (TypeVarAbstract tv : reflect) {
|
||||
substitutions.add(new ConstraintSubstitution(tv , css.getSubtype()));
|
||||
// Todo Unsauber wg
|
||||
constraints.remove(cs);
|
||||
@@ -257,20 +259,20 @@ public class Rules {
|
||||
}
|
||||
}
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> reflectNext(List<ConstraintAbstract> constraints , RefTypeOrTPHOrWildcardOrGeneric startValue ,TypeVar nextPoint) {
|
||||
public List<TypeVarAbstract> reflectNext(List<ConstraintAbstract> constraints , TypeVarAbstract startValue ,TypeVar nextPoint) {
|
||||
|
||||
ConstraintSubType next = next(nextPoint,constraints);
|
||||
|
||||
if (next != null) {
|
||||
|
||||
if (next.getSuperType().equals(startValue)) {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> result = new ArrayList<>();
|
||||
List<TypeVarAbstract> result = new ArrayList<>();
|
||||
result.add(next.getSubtype());
|
||||
constraints.remove(next); // ?? Sauber?
|
||||
return result;
|
||||
}
|
||||
else if (next.getSuperType() instanceof TypeVar ) {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> result = reflectNext(constraints,startValue,(TypeVar) next.getSuperType());
|
||||
List<TypeVarAbstract> result = reflectNext(constraints,startValue,(TypeVar) next.getSuperType());
|
||||
if (result != null) {
|
||||
result.add(next.getSubtype());
|
||||
constraints.remove(next); // ? Sauber
|
||||
@@ -319,8 +321,8 @@ public class Rules {
|
||||
|
||||
// Erstelle neue Constraints
|
||||
for (int i = 0 ; i < if1.getGenerics().size() ; i++) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tnX = if1.getGenerics().get(i);
|
||||
RefTypeOrTPHOrWildcardOrGeneric tnY = if2.getGenerics().get(i);
|
||||
TypeVarAbstract tnX = if1.getGenerics().get(i);
|
||||
TypeVarAbstract tnY = if2.getGenerics().get(i);
|
||||
|
||||
// Ergebnis an ConstraintList
|
||||
constraints.add(new ConstraintShouldEqual(tnX,tnY));
|
||||
@@ -356,48 +358,13 @@ public class Rules {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sucht aus den geladen Interfaces das benötigte herraus.
|
||||
*
|
||||
*
|
||||
* @param tvSub Subtype des Constraints
|
||||
* @param tvSuper Gesuchtes Interface aus dem Constraint mit dem Objekt "Interface for Constraint".
|
||||
* @return gibt den Constraint für den das gefundene Interface zurück.
|
||||
*/
|
||||
private ConstraintInterface sucheInterface( RefTypeOrTPHOrWildcardOrGeneric tvSub , RefTypeOrTPHOrWildcardOrGeneric tvSuper ) {
|
||||
private ConstraintInterface sucheInterface( TypeVarAbstract tvSub , TypeVarAbstract tvSuper ) {
|
||||
|
||||
for (ConstraintInterface cs : constraintInterfaces) {
|
||||
|
||||
String nameStart = null;
|
||||
String nameStartIF = null;
|
||||
|
||||
String nameVglStart = null;
|
||||
String nameVglIf = null;
|
||||
|
||||
|
||||
nameStart = tvSub.toString();
|
||||
|
||||
if (tvSuper instanceof TypeVarInterface) {
|
||||
nameStartIF = ((TypeVarInterface) tvSuper).getInterfaceForConstraint().getStrucType().toString();
|
||||
if ( cs.getSubType().equalsForUnify(tvSub) && cs.getSuperType().equalsForUnify(tvSuper) ) {
|
||||
return cs;
|
||||
}
|
||||
|
||||
nameVglStart = cs.getSubType().toString();
|
||||
|
||||
|
||||
if (cs.getSuperType() instanceof TypeVarInterface) {
|
||||
nameVglIf = ((TypeVarInterface) cs.getSuperType()).getInterfaceForConstraint().getStrucType().toString();
|
||||
}
|
||||
|
||||
|
||||
if (nameStart != null && nameStartIF != null && nameVglStart != null && nameVglIf != null ) {
|
||||
if (nameStart.equals(nameVglStart) && nameStartIF.equals(nameVglIf)) {
|
||||
return cs;
|
||||
}
|
||||
}
|
||||
//System.out.println(String.format("Vergleiche: %s ==? %s und %s ==? %s " , nameStart, nameVglStart , nameStartIF , nameVglIf));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -441,7 +408,7 @@ public class Rules {
|
||||
}
|
||||
|
||||
|
||||
public List<ConstraintAbstract> adapt2Next(RefTypeOrTPHOrWildcardOrGeneric start , RefTypeOrTPHOrWildcardOrGeneric last , List<ConstraintAbstract> constraints, List<ConstraintAbstract> newConstraints) {
|
||||
public List<ConstraintAbstract> adapt2Next(TypeVarAbstract start , TypeVarAbstract last , List<ConstraintAbstract> constraints, List<ConstraintAbstract> newConstraints) {
|
||||
|
||||
for (ConstraintAbstract cs : constraints) {
|
||||
|
||||
@@ -466,8 +433,8 @@ public class Rules {
|
||||
TypeVarInterface iFGiven = (TypeVarInterface) constraintInterface.getSuperType();
|
||||
TypeVarInterface iFthis = (TypeVarInterface) css.getSuperType();
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> iFGivenGenerics = iFGiven.getInterfaceForConstraint().getGenerics();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> iFthisGenerics = iFthis.getInterfaceForConstraint().getGenerics();
|
||||
List<TypeVarAbstract> iFGivenGenerics = iFGiven.getInterfaceForConstraint().getGenerics();
|
||||
List<TypeVarAbstract> iFthisGenerics = iFthis.getInterfaceForConstraint().getGenerics();
|
||||
|
||||
if (iFGivenGenerics.size() == iFthisGenerics.size()) {
|
||||
for (int i = 0 ; i < iFGivenGenerics.size() ; i++ ) {
|
||||
@@ -477,7 +444,10 @@ public class Rules {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
constraintsToRemove.add(css);
|
||||
return constraintsToRemove;
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package de.dhbwstuttgart.strucTypes5.typeVars;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -13,10 +12,10 @@ import java.util.List;
|
||||
public class MappingAltNeu {
|
||||
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> altList = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> neuList = new ArrayList<>();
|
||||
List<TypeVarAbstract> altList = new ArrayList<>();
|
||||
List<TypeVarAbstract> neuList = new ArrayList<>();
|
||||
|
||||
public void addTypeVar(RefTypeOrTPHOrWildcardOrGeneric alt, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public void addTypeVar(TypeVarAbstract alt, TypeVarAbstract neu) {
|
||||
altList.add(alt);
|
||||
|
||||
// Versuch bereits bekannte Typen mitzunehmen
|
||||
@@ -29,7 +28,7 @@ public class MappingAltNeu {
|
||||
}
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getNeu (RefTypeOrTPHOrWildcardOrGeneric altTypeVar) {
|
||||
public TypeVarAbstract getNeu (TypeVarAbstract altTypeVar) {
|
||||
|
||||
// Wenn der Typ bereits bekannt ist gebe ihn zurück
|
||||
if (altTypeVar instanceof TypeVarRefType) {
|
||||
@@ -37,10 +36,10 @@ public class MappingAltNeu {
|
||||
}
|
||||
else if (altTypeVar instanceof TypeVarInterface) {
|
||||
TypeVarInterface strucType = (TypeVarInterface) altTypeVar;
|
||||
RefTypeOrTPHOrWildcardOrGeneric name = strucType.getInterfaceForConstraint().getStrucType();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> neueGenerics = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> alteGenerics = strucType.getInterfaceForConstraint().getGenerics();
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tv : alteGenerics) {
|
||||
TypeVarAbstract name = strucType.getInterfaceForConstraint().getStrucType();
|
||||
List<TypeVarAbstract> neueGenerics = new ArrayList<>();
|
||||
List<TypeVarAbstract> alteGenerics = strucType.getInterfaceForConstraint().getGenerics();
|
||||
for (TypeVarAbstract tv : alteGenerics) {
|
||||
neueGenerics.add(this.getNeu(tv));
|
||||
}
|
||||
|
||||
|
@@ -1,31 +1,27 @@
|
||||
package de.dhbwstuttgart.strucTypes5.typeVars;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 14.04.17.
|
||||
*/
|
||||
public class TypeVar extends TypePlaceholder {
|
||||
public class TypeVar extends TypeVarAbstract {
|
||||
|
||||
//private String id;
|
||||
private String id;
|
||||
|
||||
public TypeVar(String id) {
|
||||
super(id);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("TVar_%s" , this.getName());
|
||||
return String.format("TVar_%s" , id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj.getClass().equals(TypeVar.class)) {
|
||||
TypeVar t = (TypeVar) obj;
|
||||
if (t.getName().equals(this.getName())) {
|
||||
if (t.id.equals(id)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@@ -0,0 +1,17 @@
|
||||
package de.dhbwstuttgart.strucTypes5.typeVars;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 14.04.17.
|
||||
*/
|
||||
public abstract class TypeVarAbstract {
|
||||
|
||||
public boolean equalsForUnify(TypeVarAbstract tv) {
|
||||
if (tv.equals(this)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -37,8 +37,4 @@ public class TypeVarFactory {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package de.dhbwstuttgart.strucTypes5.typeVars;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes5.constraints.InterfaceForConstraint;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/** LOESCHEN
|
||||
/**
|
||||
* Created by sebastian on 30.04.17.
|
||||
*/
|
||||
public class TypeVarInterface extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
public class TypeVarInterface extends TypeVarAbstract {
|
||||
|
||||
|
||||
private InterfaceForConstraint interfaceForConstraint;
|
||||
@@ -41,7 +40,7 @@ public class TypeVarInterface extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
|
||||
|
||||
// Equal_for_Unify
|
||||
public boolean equalsForUnify(RefTypeOrTPHOrWildcardOrGeneric tv) {
|
||||
public boolean equalsForUnify(TypeVarAbstract tv) {
|
||||
|
||||
if (tv instanceof TypeVarInterface) {
|
||||
String name = ((TypeVarInterface) tv).getInterfaceForConstraint().getStrucType().toString();
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package de.dhbwstuttgart.strucTypes5.typeVars;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/**LOESCHEN
|
||||
/**
|
||||
* Created by sebastian on 30.04.17.
|
||||
*/
|
||||
public class TypeVarRefType extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
public class TypeVarRefType extends TypeVarAbstract {
|
||||
|
||||
private RefType refType;
|
||||
|
||||
@@ -42,8 +41,7 @@ public class TypeVarRefType extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
|
||||
TypeVarRefType that = (TypeVarRefType) o;
|
||||
|
||||
if (that.getRefType().getName().toString().equals(this.getRefType().getName().toString())) {
|
||||
System.out.println(that.getRefType().getName().toString() + " ==? " + this.getRefType().getName().toString());
|
||||
if (that.toString().equals(this.toString())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@@ -14,11 +14,11 @@ import java.util.List;
|
||||
public class TypeVarStore {
|
||||
|
||||
|
||||
private HashMap<RefTypeOrTPHOrWildcardOrGeneric, List<RefTypeOrTPHOrWildcardOrGeneric>> map = new HashMap<>();
|
||||
private HashMap<TypeVarAbstract, List<RefTypeOrTPHOrWildcardOrGeneric>> map = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric storeTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
|
||||
public TypeVarAbstract storeTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
|
||||
|
||||
if (getTypeVarByTPH(tph) == null) {
|
||||
TypeVar tvNeu = TypeVarFactory.makeTypeVar();
|
||||
@@ -41,7 +41,7 @@ public class TypeVarStore {
|
||||
|
||||
|
||||
|
||||
public void addTuple(RefTypeOrTPHOrWildcardOrGeneric tv, RefTypeOrTPHOrWildcardOrGeneric tph) {
|
||||
public void addTuple(TypeVarAbstract tv, RefTypeOrTPHOrWildcardOrGeneric tph) {
|
||||
|
||||
|
||||
// TypVar bereits vorhandne
|
||||
@@ -66,13 +66,13 @@ public class TypeVarStore {
|
||||
}
|
||||
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getTPHByTypeVar(RefTypeOrTPHOrWildcardOrGeneric tv) {
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getTPHByTypeVar(TypeVarAbstract tv) {
|
||||
return map.get(tv);
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getTypeVarByTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
|
||||
public TypeVarAbstract getTypeVarByTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
|
||||
// TPH ist bereits einer TypVar zugeordnet
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric typeVar : map.keySet()) {
|
||||
for (TypeVarAbstract typeVar : map.keySet()) {
|
||||
if (map.get(typeVar).contains(tph)) {
|
||||
return typeVar;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class TypeVarStore {
|
||||
public TypeVarStore freshVariables() {
|
||||
TypeVarStore typeVarStore = new TypeVarStore();
|
||||
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
|
||||
for (TypeVarAbstract tvarOld : map.keySet()) {
|
||||
TypeVar tvNew = TypeVarFactory.makeTypeVar();
|
||||
typeVarStore.map.put(tvNew,map.get(tvarOld));
|
||||
}
|
||||
@@ -103,11 +103,11 @@ public class TypeVarStore {
|
||||
TypeVarStore typeVarStore = new TypeVarStore();
|
||||
|
||||
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tvarOld : map.keySet()) {
|
||||
for (TypeVarAbstract tvarOld : map.keySet()) {
|
||||
|
||||
// Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt.
|
||||
if (tvarOld instanceof TypeVarType) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric tvNew = tvarOld;
|
||||
TypeVarAbstract tvNew = tvarOld;
|
||||
typeVarStore.map.put(tvNew,map.get(tvarOld));
|
||||
mappingAltNeu.addTypeVar(tvarOld,tvNew);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class TypeVarStore {
|
||||
|
||||
|
||||
|
||||
public boolean replaceTypeVar(RefTypeOrTPHOrWildcardOrGeneric old, RefTypeOrTPHOrWildcardOrGeneric neu) {
|
||||
public boolean replaceTypeVar(TypeVarAbstract old, TypeVarAbstract neu) {
|
||||
|
||||
if (map.containsKey(old)) {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(old);
|
||||
@@ -137,7 +137,7 @@ public class TypeVarStore {
|
||||
}
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric isType(TypeVar testVar) {
|
||||
public TypeVarAbstract isType(TypeVar testVar) {
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(testVar);
|
||||
if (tphList == null) {
|
||||
@@ -160,7 +160,7 @@ public class TypeVarStore {
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "--- TypeVarStore ---\n";
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric tvar : map.keySet() ) {
|
||||
for (TypeVarAbstract tvar : map.keySet() ) {
|
||||
res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n";
|
||||
}
|
||||
return String.format(res);
|
||||
|
@@ -2,12 +2,11 @@ package de.dhbwstuttgart.strucTypes5.typeVars;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/**LOESCHEN
|
||||
/**
|
||||
* Created by sebastian on 14.04.17.
|
||||
*/
|
||||
public class TypeVarType extends RefTypeOrTPHOrWildcardOrGeneric {
|
||||
public class TypeVarType extends TypeVarAbstract {
|
||||
|
||||
|
||||
private Class typeClass;
|
||||
|
@@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.strucTypes6;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 11.05.17.
|
||||
*/
|
||||
public class Main {
|
||||
}
|
@@ -4,7 +4,6 @@ import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@@ -25,9 +24,8 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
||||
private RefTypeOrTPHOrWildcardOrGeneric superClass;
|
||||
protected boolean isInterface;
|
||||
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
|
||||
private List<Constructor> constructors;
|
||||
|
||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||
|
||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, GenericDeclarationList genericClassParameters,
|
||||
RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
this.modifiers = modifiers;
|
||||
@@ -49,7 +47,6 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
||||
this.implementedInterfaces = implementedInterfaces;
|
||||
}
|
||||
this.methods = methods;
|
||||
this.constructors = constructors;
|
||||
}
|
||||
|
||||
// Gets class name
|
||||
@@ -82,22 +79,14 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
||||
}
|
||||
|
||||
public RefType getType() {
|
||||
return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset());
|
||||
}
|
||||
|
||||
public static RefType generateTypeOfClass(JavaClassName name, GenericDeclarationList genericsOfClass ,Token offset){
|
||||
return new RefType(name, offset);
|
||||
return new RefType(this.getClassName(), this.getOffset());
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSuperClass() {
|
||||
return superClass;
|
||||
}
|
||||
|
||||
public GenericDeclarationList getGenerics() {
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
return this.genericClassParameters;
|
||||
}
|
||||
|
||||
public List<? extends Method> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
}
|
||||
|
@@ -5,8 +5,11 @@ import java.util.ArrayList;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
@@ -20,7 +23,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class Method extends Field implements IItemWithOffset, TypeScope
|
||||
public class Method extends Field implements IItemWithOffset
|
||||
{
|
||||
private Block block;
|
||||
private ParameterList parameterlist = new ParameterList(new ArrayList<>(), new NullToken());
|
||||
@@ -59,9 +62,4 @@ public class Method extends Field implements IItemWithOffset, TypeScope
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
return generics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return this.getType();
|
||||
}
|
||||
}
|
||||
|
@@ -11,10 +11,6 @@ import org.antlr.v4.runtime.misc.Pair;
|
||||
public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
private final Token offset;
|
||||
|
||||
public SyntaxTreeNode() {
|
||||
super();
|
||||
offset = null;
|
||||
}
|
||||
public SyntaxTreeNode(Token offset){
|
||||
this.offset = offset;
|
||||
}
|
||||
|
@@ -1,10 +0,0 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
|
||||
public interface TypeScope {
|
||||
Iterable<? extends GenericTypeVar> getGenerics();
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric getReturnType();
|
||||
}
|
@@ -35,9 +35,8 @@ public class ASTFactory {
|
||||
public ClassOrInterface createClass(java.lang.Class jreClass){
|
||||
JavaClassName name = names.getName(jreClass.getName());
|
||||
List<Method> methoden = new ArrayList<>();
|
||||
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||
konstruktoren.add(createConstructor(constructor, jreClass));
|
||||
methoden.add(createConstructor(constructor, jreClass));
|
||||
}
|
||||
for(java.lang.reflect.Method method : jreClass.getMethods()){
|
||||
methoden.add(createMethod(method, jreClass));
|
||||
@@ -59,8 +58,7 @@ public class ASTFactory {
|
||||
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
|
||||
|
||||
Token offset = new NullToken(); //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
||||
|
||||
return new ClassOrInterface(modifier, name, felder, methoden, konstruktoren, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset);
|
||||
return new ClassOrInterface(modifier, name, felder, methoden, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
private de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) {
|
||||
|
@@ -99,8 +99,7 @@ public class UnifyTypeFactory {
|
||||
}
|
||||
|
||||
public static UnifyType convert(GenericRefType t){
|
||||
throw new NotImplementedException();
|
||||
//return new PlaceholderType(TypePlaceholder.fresh(t.getOffset()).getName());
|
||||
return new PlaceholderType(TypePlaceholder.fresh(t.getOffset()).getName());
|
||||
}
|
||||
|
||||
public static UnifyType convert(WildcardType t){
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.operator.Operator;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
// neu von Felix
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
public class CastExpr extends Expression
|
||||
|
@@ -1,9 +1,10 @@
|
||||
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class ForStmt extends Statement
|
||||
{
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
public class InstVar extends Expression
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
public class InstanceOf extends BinaryExpr
|
||||
|
@@ -1,55 +1,37 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author A10023 - Andreas Stadelmeier
|
||||
* Momentan erweitert LambdaExpression noch Expr und erbt dadurch auch von ExprStatement ist also auch ein Statement
|
||||
*
|
||||
* LambdaExpression Aufbau:
|
||||
* ( ParameterList ) -> { methodBody };
|
||||
* ( ParameterList ) -> { method_body };
|
||||
*/
|
||||
public class LambdaExpression extends Expression implements TypeScope {
|
||||
private Block methodBody;
|
||||
public class LambdaExpression extends Expression{
|
||||
|
||||
|
||||
/**
|
||||
* Wird bei der TYPE Methode gesetzt. Speichert den errechneten Typ des LambdaAusdrucks
|
||||
*/
|
||||
private FunN lambdaType;
|
||||
|
||||
private Block method_body;
|
||||
private ParameterList params;
|
||||
|
||||
public LambdaExpression(RefTypeOrTPHOrWildcardOrGeneric type, ParameterList params, Block methodBody,Token offset) {
|
||||
super(type,offset);
|
||||
this.methodBody = methodBody;
|
||||
this.params = params;
|
||||
public LambdaExpression(int offset, int variableLength) {
|
||||
super(null,null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||
TypeInferenceBlockInformation lambdaScope = new TypeInferenceBlockInformation(info, this);
|
||||
ConstraintSet ret = methodBody.getConstraints(lambdaScope);
|
||||
throw new NotImplementedException();
|
||||
//return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
//Lambda-Ausdrücke haben keine Generics
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
//RefType type = (RefType) this.getType();
|
||||
//return type.getParaList().get(0);
|
||||
return methodBody.getType();
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class LocalVarDecl extends Statement
|
||||
{
|
||||
|
@@ -1,24 +1,18 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class MethodCall extends Statement
|
||||
@@ -27,8 +21,8 @@ public class MethodCall extends Statement
|
||||
private Receiver receiver;
|
||||
private ArgumentList arglist;
|
||||
|
||||
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, Token offset){
|
||||
super(retType,offset);
|
||||
public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, Token offset){
|
||||
super(TypePlaceholder.fresh(offset),offset);
|
||||
this.arglist = argumentList;
|
||||
this.name = methodName;
|
||||
this.receiver = receiver;
|
||||
@@ -55,11 +49,21 @@ public class MethodCall extends Statement
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||
ConstraintSet ret = receiver.getConstraints(info);
|
||||
ret.addAll(this.getArgumentListConstraints(info));
|
||||
ret.addAll(receiver.getConstraints(info));
|
||||
for(int i = 0;i<arglist.getArguments().size();i++){
|
||||
ret.addAll(arglist.getArguments().get(i).getConstraints(info));
|
||||
}
|
||||
//Overloading:
|
||||
Set<Constraint> methodConstraints = new HashSet<>();
|
||||
for(MethodAssumption m : this.getMethods(name, arglist, info)){
|
||||
methodConstraints.add(generateConstraint(m, info));
|
||||
for(MethodAssumption m : info.getMethods(name, arglist)){
|
||||
Constraint methodConstraint = new Constraint();
|
||||
methodConstraint.add(ConstraintsFactory.createPair(receiver.getType(), m.getReceiverType(), PairOperator.SMALLERDOT, info));
|
||||
methodConstraint.add(ConstraintsFactory.createPair(m.getReturnType(), this.getType(), PairOperator.SMALLERDOT, info));
|
||||
for(int i = 0;i<arglist.getArguments().size();i++){
|
||||
methodConstraint.add(ConstraintsFactory.createPair(m.getArgTypes().get(i),
|
||||
arglist.getArguments().get(i).getType(), PairOperator.SMALLERDOT, info));
|
||||
}
|
||||
methodConstraints.add(methodConstraint);
|
||||
}
|
||||
if(methodConstraints.size()<1){
|
||||
throw new TypeinferenceException("Methode "+name+" ist nicht vorhanden!",getOffset());
|
||||
@@ -67,57 +71,4 @@ public class MethodCall extends Statement
|
||||
ret.addOderConstraint(methodConstraints);
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected Constraint<Pair> generateConstraint(MethodAssumption forMethod, TypeInferenceBlockInformation info){
|
||||
Constraint methodConstraint = new Constraint();
|
||||
methodConstraint.add(ConstraintsFactory.createPair(receiver.getType(), forMethod.getReceiverType(), PairOperator.SMALLERDOT, info));
|
||||
methodConstraint.add(ConstraintsFactory.createPair(forMethod.getReturnType(), this.getType(), PairOperator.SMALLERDOT, info));
|
||||
methodConstraint.addAll(generateParameterConstraints(forMethod, info));
|
||||
return methodConstraint;
|
||||
}
|
||||
|
||||
protected Set<Pair> generateParameterConstraints(MethodAssumption forMethod, TypeInferenceBlockInformation info) {
|
||||
Set<Pair> ret = new HashSet<>();
|
||||
for(int i = 0;i<arglist.getArguments().size();i++){
|
||||
ret.add(ConstraintsFactory.createPair(forMethod.getArgTypes().get(i),
|
||||
arglist.getArguments().get(i).getType(), PairOperator.SMALLERDOT, info));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public List<MethodAssumption> getMethods(String name, ArgumentList arglist, TypeInferenceBlockInformation info) {
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||
for(Method m : cl.getMethods()){
|
||||
if(m.getName().equals(name) &&
|
||||
m.getParameterList().getFormalparalist().size() == arglist.getArguments().size()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getType());
|
||||
|
||||
ret.add(new MethodAssumption(cl.getType(), retType, convertParams(m.getParameterList(),info)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected List<RefTypeOrTPHOrWildcardOrGeneric> convertParams(ParameterList parameterList, TypeInferenceBlockInformation info){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(FormalParameter fp : parameterList.getFormalparalist()){
|
||||
params.add(info.checkGTV(fp.getType()));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public ArgumentList getArgumentList() {
|
||||
return arglist;
|
||||
}
|
||||
|
||||
public ConstraintSet getArgumentListConstraints(TypeInferenceBlockInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
for(int i = 0;i<arglist.getArguments().size();i++){
|
||||
ret.addAll(arglist.getArguments().get(i).getConstraints(info));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
public class NewArray extends Expression
|
||||
|
@@ -1,28 +1,25 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
public class NewClass extends MethodCall
|
||||
public class NewClass extends Statement
|
||||
{
|
||||
public NewClass(int offset,int variableLength)
|
||||
{
|
||||
super(null,null);
|
||||
}
|
||||
|
||||
private ArgumentList arglist;
|
||||
private boolean isStatement = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newClass Typ der Instanzierten Klasse
|
||||
@@ -30,49 +27,19 @@ public class NewClass extends MethodCall
|
||||
* @param start
|
||||
*/
|
||||
public NewClass(RefType newClass, ArgumentList args, Token start) {
|
||||
super(newClass, new Receiver(new EmptyStmt(start)), "new "+newClass.getName().toString(), args, start);
|
||||
super(newClass, start);
|
||||
this.arglist = args;
|
||||
}
|
||||
|
||||
public List<MethodAssumption> getConstructors(TypeInferenceBlockInformation info, RefType ofType, ArgumentList argList){
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||
if(cl.getClassName().equals(ofType.getName())){
|
||||
for(Method m : cl.getConstructors()){
|
||||
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
||||
ret.add(new MethodAssumption(ofType, ofType, convertParams(m.getParameterList(), info)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
public ArgumentList getArgumentList()
|
||||
{
|
||||
return this.arglist;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Constraint<Pair> generateConstraint(MethodAssumption forMethod, TypeInferenceBlockInformation info){
|
||||
Constraint methodConstraint = new Constraint();
|
||||
methodConstraint.add(ConstraintsFactory.createPair(forMethod.getReturnType(), this.getType(), PairOperator.SMALLERDOT, info));
|
||||
methodConstraint.addAll(generateParameterConstraints(forMethod, info));
|
||||
return methodConstraint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MethodAssumption> getMethods(String name, ArgumentList arglist, TypeInferenceBlockInformation info) {
|
||||
return getConstructors(info, (RefType) this.getType(), arglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
ret.addAll(this.getArgumentListConstraints(info));
|
||||
//Overloading:
|
||||
Set<Constraint> methodConstraints = new HashSet<>();
|
||||
for(MethodAssumption m : this.getConstructors(info, (RefType) this.getType(), this.getArgumentList())){
|
||||
methodConstraints.add(generateConstraint(m, info));
|
||||
}
|
||||
if(methodConstraints.size()<1){
|
||||
throw new TypeinferenceException("Konstruktor in Klasse "+this.getType().toString()+" ist nicht vorhanden!",getOffset());
|
||||
}
|
||||
ret.addOderConstraint(methodConstraints);
|
||||
return ret;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,8 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
||||
public class PostIncExpr extends UnaryExpr
|
||||
|
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@@ -20,7 +21,7 @@ public class Return extends Statement
|
||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||
ConstraintSet ret = retexpr.getConstraints(info);
|
||||
ret.addUndConstraint(ConstraintsFactory.createPair(
|
||||
this.getType(),info.getCurrentTypeScope().getReturnType(), info));
|
||||
this.getType(),info.getCurrentMethod().getType(), info));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class Super extends Expression
|
||||
{
|
||||
|
@@ -11,7 +11,7 @@ import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.atn.SemanticContext;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class This extends Expression
|
||||
{
|
||||
|
@@ -8,7 +8,7 @@ public class ThisCall extends MethodCall
|
||||
{
|
||||
public ThisCall(Receiver receiver, ArgumentList arglist, int offset)
|
||||
{
|
||||
super(null, null, null, null, null);
|
||||
super(null, null, null, null);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,6 @@ public abstract class UnaryExpr extends MethodCall
|
||||
|
||||
public UnaryExpr(Token offset)
|
||||
{
|
||||
super(null,null,null,null,null);
|
||||
super(null,null,null,null);
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class UnaryPlus extends Expression
|
||||
{
|
||||
|
@@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class WhileStmt extends Statement
|
||||
{
|
||||
|
@@ -65,7 +65,6 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
* Author: Jrg Buerle<br/>
|
||||
* @return
|
||||
*/
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj instanceof RefType){
|
||||
@@ -101,24 +100,5 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Methode zur Fehlersuche
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof RefType) {
|
||||
RefType r = (RefType) o;
|
||||
if (r.getName().equals(this.getName())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,9 +4,6 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
|
||||
public RefTypeOrTPHOrWildcardOrGeneric(){
|
||||
super();
|
||||
}
|
||||
public RefTypeOrTPHOrWildcardOrGeneric(Token offset) {
|
||||
super(offset);
|
||||
}
|
||||
|
@@ -18,17 +18,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
|
||||
private static Hashtable<String, TypePlaceholder> m_TypePlaceholdersRegistry = new Hashtable<String, TypePlaceholder>();
|
||||
|
||||
final String name;
|
||||
private final String name;
|
||||
|
||||
|
||||
/**
|
||||
* Protected Konstruktor - nur noetig für TypVar
|
||||
* <br>Author: Martin Pluemicke
|
||||
*/
|
||||
protected TypePlaceholder(String name)
|
||||
{
|
||||
super(null);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Privater Konstruktor - Eine TypePlaceholder-Variable wird �ber die
|
||||
|
@@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.typedeployment;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class TypeInsertPoint {
|
||||
Token point;
|
||||
private String insertString;
|
||||
|
||||
public TypeInsertPoint(Token point, String toInsert){
|
||||
this.point = point;
|
||||
this.insertString = toInsert;
|
||||
}
|
||||
|
||||
public String insert(String intoSource){
|
||||
return new StringBuilder(intoSource).insert(point.getStartIndex(), insertString).toString();
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ResultSet {
|
||||
public ResultSet(Set<Set<UnifyPair>> results){
|
||||
|
||||
}
|
||||
}
|
@@ -1,60 +1,25 @@
|
||||
package de.dhbwstuttgart.typeinference.assumptions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
||||
private TypeScope methodContext;
|
||||
private Method methodContext;
|
||||
private ClassOrInterface currentClass;
|
||||
|
||||
public TypeInferenceBlockInformation(Set<ClassOrInterface> availableClasses,
|
||||
ClassOrInterface currentClass, TypeScope methodContext) {
|
||||
public TypeInferenceBlockInformation(Set<ClassOrInterface> availableClasses, ClassOrInterface currentClass, Method methodContext) {
|
||||
super(availableClasses);
|
||||
this.methodContext = methodContext;
|
||||
this.currentClass = currentClass;
|
||||
}
|
||||
public TypeInferenceBlockInformation(TypeInferenceBlockInformation oldScope, TypeScope newScope) {
|
||||
this(oldScope.getAvailableClasses(), oldScope.currentClass, oldScope.methodContext);
|
||||
methodContext = new TypeScopeContainer(methodContext, newScope);
|
||||
}
|
||||
|
||||
public ClassOrInterface getCurrentClass() {
|
||||
return currentClass;
|
||||
}
|
||||
public TypeScope getCurrentTypeScope() {
|
||||
public Method getCurrentMethod() {
|
||||
return methodContext;
|
||||
}
|
||||
|
||||
private class TypeScopeContainer implements TypeScope{
|
||||
ArrayList<TypeScope> scopes = new ArrayList<>();
|
||||
Stack<RefTypeOrTPHOrWildcardOrGeneric> types = new Stack<>();
|
||||
public TypeScopeContainer(TypeScope scope1, TypeScope scope2){
|
||||
scopes.add(scope1);
|
||||
scopes.add(scope2);
|
||||
types.push(scope1.getReturnType());
|
||||
types.push(scope2.getReturnType());
|
||||
}
|
||||
public void add(TypeScope scope){
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
return Iterables.concat(scopes.stream().
|
||||
map(TypeScope::getGenerics).collect(Collectors.toList()).toArray(new Iterable[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return types.peek();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,14 +2,14 @@ package de.dhbwstuttgart.typeinference.assumptions;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,7 +32,7 @@ public class TypeInferenceInformation {
|
||||
classes = availableClasses;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric checkGTV(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||
private RefTypeOrTPHOrWildcardOrGeneric checkGTV(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||
if(type instanceof GenericRefType){
|
||||
return TypePlaceholder.fresh(new NullToken());
|
||||
}else{
|
||||
@@ -40,6 +40,25 @@ public class TypeInferenceInformation {
|
||||
}
|
||||
}
|
||||
|
||||
public List<MethodAssumption> getMethods(String name, ArgumentList arglist) {
|
||||
List<MethodAssumption> ret = new ArrayList<>();
|
||||
for(ClassOrInterface cl : classes){
|
||||
for(Method m : cl.getMethods()){
|
||||
if(m.getName().equals(name) &&
|
||||
m.getParameterList().getFormalparalist().size() == arglist.getArguments().size()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = checkGTV(m.getType());
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(FormalParameter fp : m.getParameterList().getFormalparalist()){
|
||||
params.add(checkGTV(fp.getType()));
|
||||
}
|
||||
ret.add(new MethodAssumption(cl.getType(), retType, params));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<FieldAssumption> getFields(String name){
|
||||
List<FieldAssumption> ret = new ArrayList<>();
|
||||
for(ClassOrInterface cl : classes){
|
||||
|
@@ -9,6 +9,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ConstraintsFactory {
|
||||
@@ -23,7 +24,15 @@ public class ConstraintsFactory {
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric checkGeneric(RefTypeOrTPHOrWildcardOrGeneric type, TypeInferenceBlockInformation info){
|
||||
if(type instanceof GenericRefType){
|
||||
for(GenericTypeVar genericTypeVar : info.getCurrentTypeScope().getGenerics()){
|
||||
List<GenericTypeVar> genericsInContext = new ArrayList<>();
|
||||
for(GenericTypeVar genericTypeVar : info.getCurrentClass().getGenerics()){
|
||||
genericsInContext.add(genericTypeVar);
|
||||
}
|
||||
if(info.getCurrentMethod() != null)for(GenericTypeVar genericTypeVar : info.getCurrentMethod().getGenerics()){
|
||||
genericsInContext.add(genericTypeVar);
|
||||
}
|
||||
|
||||
for(GenericTypeVar genericTypeVar : genericsInContext){
|
||||
if(genericTypeVar.getName().equals(((GenericRefType)type).getName())){
|
||||
return new RefType(((GenericRefType)type).getName(),type.getOffset());
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user