From f0ba7c03b5d1637716c6181b4deed03794ac5bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 5 Nov 2018 12:01:16 +0100 Subject: [PATCH] modified: ../../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Bei Int-Literal werden imports beruecksichtigt --- .../typeinference/typeAlgo/TYPEStmt.java | 28 +++++++++++++------ test/bytecode/javFiles/Matrix.jav | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 330127afc..16265b32a 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -4,6 +4,7 @@ import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; +import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; @@ -18,6 +19,7 @@ import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; public class TYPEStmt implements StatementVisitor{ @@ -374,24 +376,34 @@ public class TYPEStmt implements StatementVisitor{ constraintsSet.addUndConstraint(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT)); return; } - if (literal.value instanceof Double) { + if (literal.value instanceof Long) { constraintsSet.addUndConstraint(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT)); return; } if (literal.value instanceof Integer) { //constraintsSet.addUndConstraint(new Pair(literal.getType(),integer, PairOperator.EQUALSDOT)); // /* + HashSet clNames = info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)); Set oderConstraints = new HashSet<>(); Constraint constraint = new Constraint(); constraint.add(new Pair(literal.getType(), integer, PairOperator.EQUALSDOT)); oderConstraints.add(constraint); - constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT)); - oderConstraints.add(constraint); - constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT)); - oderConstraints.add(constraint); - constraintsSet.addOderConstraint(oderConstraints); + if (clNames.stream().filter(x -> x.toString().equals("java.lang.Double")).findAny().isPresent()) { + constraint = new Constraint(); + constraint.add(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT)); + oderConstraints.add(constraint); + } + if (clNames.stream().filter(x -> x.toString().equals("java.lang.Long")).findAny().isPresent()) { + constraint = new Constraint(); + constraint.add(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT)); + oderConstraints.add(constraint); + } + if (clNames.stream().filter(x -> x.toString().equals("java.lang.Float")).findAny().isPresent()) { + constraint = new Constraint(); + constraint.add(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT)); + oderConstraints.add(constraint); + } + constraintsSet.addOderConstraint(oderConstraints); // */ return; } diff --git a/test/bytecode/javFiles/Matrix.jav b/test/bytecode/javFiles/Matrix.jav index 61c601108..bfe523b6a 100644 --- a/test/bytecode/javFiles/Matrix.jav +++ b/test/bytecode/javFiles/Matrix.jav @@ -1,5 +1,6 @@ import java.util.Vector; import java.lang.Integer; +import java.lang.Float; //import java.lang.Byte; import java.lang.Boolean;