This commit is contained in:
Victorious3 2022-08-26 17:21:23 +02:00
parent b0c1d5d96d
commit 5503f3723c
3 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,5 @@
package de.dhbwstuttgart.target.bytecode; package de.dhbwstuttgart.target.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.target.tree.*; import de.dhbwstuttgart.target.tree.*;
import de.dhbwstuttgart.target.tree.expression.*; import de.dhbwstuttgart.target.tree.expression.*;
import de.dhbwstuttgart.target.tree.type.*; import de.dhbwstuttgart.target.tree.type.*;
@ -751,7 +750,7 @@ public class Codegen {
private void generate(State state, TargetExpression expr) { private void generate(State state, TargetExpression expr) {
var mv = state.mv; var mv = state.mv;
switch (expr) { switch (expr) {
case TargetClassName className: case TargetClassName ignored:
break; // NOP break; // NOP
case TargetBlock block: { case TargetBlock block: {
var localCounter = state.localCounter; var localCounter = state.localCounter;

View File

@ -345,6 +345,8 @@ public class ASTToTargetAST {
for (var pair : oldInput) { for (var pair : oldInput) {
if (!referenced.contains(pair.getLeft())) { if (!referenced.contains(pair.getLeft())) {
input.remove(pair); input.remove(pair);
if (pair instanceof PairTPHsmallerTPH ptph)
equality.put(ptph.left, ptph.right);
for (var pair2 : oldInput) { for (var pair2 : oldInput) {
if (pair2.getRight().equals(pair.getLeft())) { if (pair2.getRight().equals(pair.getLeft())) {
input.remove(pair2); input.remove(pair2);
@ -565,7 +567,7 @@ public class ASTToTargetAST {
Set<TargetGeneric> convert(Set<ResultPair<?, ?>> result) { Set<TargetGeneric> convert(Set<ResultPair<?, ?>> result) {
return result.stream().map(p -> { return result.stream().map(p -> {
if (p instanceof PairTPHsmallerTPH pair) { if (p instanceof PairTPHsmallerTPH pair) {
return new TargetGeneric(pair.left.getName(), new TargetGenericType(pair.right.getName())); return new TargetGeneric(pair.left.getName(), convert(pair.right));
} else if (p instanceof PairTPHequalRefTypeOrWildcardType pair) { } else if (p instanceof PairTPHequalRefTypeOrWildcardType pair) {
return new TargetGeneric(pair.left.getName(), convert(pair.right)); return new TargetGeneric(pair.left.getName(), convert(pair.right));
} else { } else {
@ -576,13 +578,14 @@ public class ASTToTargetAST {
public TargetClass convert(ClassOrInterface input) { public TargetClass convert(ClassOrInterface input) {
currentClass = input; currentClass = input;
var generics = sigma.generics(input);
TargetBlock fieldInitializer = null; TargetBlock fieldInitializer = null;
if (input.getfieldInitializations().isPresent()) if (input.getfieldInitializations().isPresent())
fieldInitializer = convert(input.getfieldInitializations().get().block); fieldInitializer = convert(input.getfieldInitializations().get().block);
TargetBlock finalFieldInitializer = fieldInitializer; TargetBlock finalFieldInitializer = fieldInitializer;
return new TargetClass(input.getModifiers(), input.getClassName().toString(), convert(input.getSuperClass()), return new TargetClass(input.getModifiers(), input.getClassName().toString(), convert(input.getSuperClass()),
convert(sigma.generics(input)), convert(generics),
input.getSuperInterfaces().stream().map(this::convert).toList(), input.getSuperInterfaces().stream().map(this::convert).toList(),
input.getConstructors().stream().map(constructor -> this.convert(constructor, finalFieldInitializer)).flatMap(List::stream).toList(), input.getConstructors().stream().map(constructor -> this.convert(constructor, finalFieldInitializer)).flatMap(List::stream).toList(),
input.getFieldDecl().stream().map(this::convert).toList(), input.getFieldDecl().stream().map(this::convert).toList(),

View File

@ -79,7 +79,7 @@ public class StatementToTargetExpression implements StatementVisitor {
}); });
result = new TargetLambdaExpression( result = new TargetLambdaExpression(
new TargetFunNType(parameters.size(), parameters.stream().map(MethodParameter::type).toList()), converter.convert(lambdaExpression.getType()),
captures, parameters, converter.convert(lambdaExpression.getReturnType()), converter.convert(lambdaExpression.methodBody) captures, parameters, converter.convert(lambdaExpression.getReturnType()), converter.convert(lambdaExpression.methodBody)
); );
} }