Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6c59f07f6 | ||
|
|
a5c8d93e4c | ||
|
|
e70f071c63 | ||
|
|
f66499b4fe |
No files matched your search
@@ -0,0 +1,2 @@
|
||||
public class Bug422 {}
|
||||
public class Bug422 {}
|
||||
@@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.Codegen;
|
||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.CompilerException;
|
||||
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||
@@ -171,6 +172,8 @@ public class JavaTXCompiler {
|
||||
|
||||
var numberOfGenerics = decl == null ? 0 : decl.genericTypeVar().size();
|
||||
var className = pkgName + (!pkgName.isEmpty() ? "." : "") + name;
|
||||
if (classRegistry.contains(className))
|
||||
throw new CompilerException("Duplicate class definition: " + className);
|
||||
classRegistry.addName(className, numberOfGenerics);
|
||||
input.add(classRegistry.getName(className));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.dhbwstuttgart.exceptions;
|
||||
|
||||
public class CompilerException extends RuntimeException {
|
||||
public CompilerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -618,7 +618,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
}
|
||||
|
||||
private static TargetExpression generateCall(TargetMethod method, List<TargetLocalVar> params, TargetType classType, boolean isInterface) {
|
||||
private static TargetExpression generateCall(TargetMethod method, List<TargetLocalVar> params, TargetType classType) {
|
||||
var mParams = new ArrayList<TargetExpression>();
|
||||
for (var i = 0; i < params.size(); i++) {
|
||||
var tpe = method.signature().parameters().get(i).pattern().type();
|
||||
@@ -626,11 +626,11 @@ public class ASTToTargetAST {
|
||||
}
|
||||
TargetExpression caseBody = new TargetMethodCall(
|
||||
method.signature().returnType(),
|
||||
method.isStatic() ? new TargetClassName(classType) : new TargetThis(classType),
|
||||
new TargetThis(classType),
|
||||
mParams,
|
||||
classType,
|
||||
method.name(),
|
||||
method.isStatic(), isInterface, method.isPrivate()
|
||||
false, false, method.isPrivate()
|
||||
);
|
||||
if (method.signature().returnType() != null) {
|
||||
caseBody = new TargetReturn(caseBody);
|
||||
@@ -638,11 +638,11 @@ public class ASTToTargetAST {
|
||||
return caseBody;
|
||||
}
|
||||
|
||||
private TargetExpression generatePatternOverloadsRec(int offset, TargetExpression switchExpr, List<TargetLocalVar> params, List<TargetPattern> patterns, List<TargetMethod> methods, TargetType classType, boolean isInterface) {
|
||||
private TargetExpression generatePatternOverloadsRec(int offset, TargetExpression switchExpr, List<TargetLocalVar> params, List<TargetPattern> patterns, List<TargetMethod> methods, TargetType classType) {
|
||||
if (methods.isEmpty()) throw new DebugException("Couldn't find a candidate for switch overloading");
|
||||
if (methods.size() == 1) {
|
||||
var method = methods.getFirst();
|
||||
return generateCall(method, params, classType, isInterface);
|
||||
return generateCall(method, params, classType);
|
||||
}
|
||||
|
||||
var cases = new ArrayList<TargetSwitch.Case>();
|
||||
@@ -691,11 +691,11 @@ public class ASTToTargetAST {
|
||||
}).toList();
|
||||
|
||||
if (candidates.isEmpty()) {
|
||||
var body = new TargetBlock(List.of(generateCall(method, params, classType, isInterface)));
|
||||
var body = new TargetBlock(List.of(generateCall(method, params, classType)));
|
||||
cases.add(new TargetSwitch.Case(List.of(lastPattern), body));
|
||||
} else {
|
||||
//candidates.forEach(m -> Target.logger.info(m.getSignature()));
|
||||
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType, isInterface);
|
||||
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType);
|
||||
var body = new TargetBlock(List.of(caseBody));
|
||||
var case_ = new TargetSwitch.Case(List.of(lastPattern), body);
|
||||
|
||||
@@ -787,7 +787,7 @@ public class ASTToTargetAST {
|
||||
var parameters = resParams.stream().map( p -> new TargetLocalVar(p.pattern().type(), p.pattern().name())).toList();
|
||||
|
||||
var classType = new TargetRefType(clazz.getClassName().toString());
|
||||
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(resParams.getFirst().pattern().type(), resParams.getFirst().pattern().name()), parameters, List.of(), methods, classType, clazz.isInterface());
|
||||
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(resParams.getFirst().pattern().type(), resParams.getFirst().pattern().name()), parameters, List.of(), methods, classType);
|
||||
var block = new TargetBlock(List.of(stmt));
|
||||
|
||||
var generics = new HashSet<>(firstMethod.signature().generics());
|
||||
@@ -870,7 +870,7 @@ public class ASTToTargetAST {
|
||||
|
||||
// Generate dispatch method
|
||||
var classType = new TargetRefType(clazz.getClassName().toString());
|
||||
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType, clazz.isInterface());
|
||||
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType);
|
||||
var block = new TargetBlock(List.of(stmt));
|
||||
|
||||
var bridgeMethod = new TargetMethod(firstMethod.access(), firstMethod.name(), block, group.signature.java, group.signature.tx, firstMethod.base(), null);
|
||||
|
||||
@@ -256,9 +256,9 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
foundMethod = findMethod(receiverName, methodCall.name, signature, converter.compiler).orElseThrow(
|
||||
() -> new DebugException("Method " + methodCall.name + " not found (" + finalSignature + ") on class " + receiverName)
|
||||
);
|
||||
if (foundMethod != null) {
|
||||
signature = foundMethod.getParameterList().getFormalparalist().stream().map(pattern -> converter.convert(pattern.getType(), generics)).toList();
|
||||
}
|
||||
//if (foundMethod != null) {
|
||||
// signature = foundMethod.getParameterList().getFormalparalist().stream().map(pattern -> converter.convert(pattern.getType(), generics)).toList();
|
||||
//}
|
||||
}
|
||||
|
||||
if (!isFunNType) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import de.dhbwstuttgart.bytecode.CodeGenException;
|
||||
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||
import de.dhbwstuttgart.exceptions.CompilerException;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||
@@ -1083,6 +1085,7 @@ public class TestComplete {
|
||||
|
||||
@Test
|
||||
public void testPatternMatchingInterface() throws Exception {
|
||||
ConsoleInterface.logLevel = LogLevel.INFO;
|
||||
var classFiles = generateClassFiles(createClassLoader(), false, "Matcher.jav", "PatternMatchingInterface.jav");
|
||||
var Intf = classFiles.get("Interface");
|
||||
var clazz = classFiles.get("PatternMatchingInterface");
|
||||
@@ -1703,4 +1706,14 @@ public class TestComplete {
|
||||
var clazz = classFiles.get("Bug406");
|
||||
clazz.getDeclaredMethod("main", List.class).invoke(null, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug422() throws Exception {
|
||||
try {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug422.jav");
|
||||
fail("Shouldn't compile!");
|
||||
} catch (CompilerException e) {
|
||||
assertEquals("Duplicate class definition: Bug422", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user