Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
967bd91a6e |
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
public class Bug463 {
|
||||||
|
public static and(Boolean a, Boolean b) { return a & b; } // | and ^ behave the same
|
||||||
|
public static or(Boolean a, Boolean b) { return a | b; }
|
||||||
|
public static xor(Boolean a, Boolean b) { return a ^ b; }
|
||||||
|
}
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
import java.lang.Integer;
|
|
||||||
import java.lang.String;
|
|
||||||
|
|
||||||
sealed interface Token permits /*SEMICOLON, COMMA, DOT, ASSIGN, LESSTHEN, GREATERTHAN,
|
|
||||||
LESSEQUALS, GREATEREQUALS, EQUALS, NOTEQUALS, NOT,
|
|
||||||
ADD, SUB, MUL, DIV, */LBRACE, RBRACE, /* LBRACKET , RBRACKET, SBOPEN, SBCLOSE, ABSTRACT,
|
|
||||||
STATIC, PUBLIC, CLASS, INTERFACE,
|
|
||||||
FOR, WHILE, */IF,/*, ELSE, BREAK, SWITCH, CASE, RETURN, VOID, BOOLEAN, JNULL, INT, CHAR,
|
|
||||||
STRING, LONG, */ BOOLEANLITERALTRUE /*, BOOLEANLITERALFALSE,
|
|
||||||
INTLITERAL, LONGLITERAL, FLOATLITERAL, CHARLITERAL, STRINGLITERAL, MEMORYADRESSLITERAL, NAME,
|
|
||||||
WHITESPACE*/ { }
|
|
||||||
|
|
||||||
/*record SEMICOLON() implements Token {}
|
|
||||||
record COMMA () implements Token {}
|
|
||||||
record DOT() implements Token {}
|
|
||||||
record ASSIGN() implements Token {}
|
|
||||||
record LESSTHEN() implements Token {}
|
|
||||||
record GREATERTHAN() implements Token {}
|
|
||||||
record LESSEQUALS() implements Token {}
|
|
||||||
record GREATEREQUALS() implements Token {}
|
|
||||||
record EQUALS() implements Token {}
|
|
||||||
record NOTEQUALS() implements Token {}
|
|
||||||
record NOT() implements Token {}
|
|
||||||
record ADD () implements Token {}
|
|
||||||
record SUB() implements Token {}
|
|
||||||
record MUL() implements Token {}
|
|
||||||
record DIV() implements Token {}*/
|
|
||||||
record LBRACE() implements Token {}
|
|
||||||
record RBRACE() implements Token {}
|
|
||||||
/*
|
|
||||||
record LBRACKET () implements Token {}
|
|
||||||
record RBRACKET() implements Token {}
|
|
||||||
record SBOPEN() implements Token {}
|
|
||||||
record SBCLOSE() implements Token {}
|
|
||||||
record ABSTRACT() implements Token {}
|
|
||||||
record STATIC() implements Token {}
|
|
||||||
record PUBLIC() implements Token {}
|
|
||||||
record CLASS() implements Token {}
|
|
||||||
record INTERFACE() implements Token {}
|
|
||||||
record FOR () implements Token {}
|
|
||||||
record WHILE() implements Token {}*/
|
|
||||||
record IF() implements Token {}
|
|
||||||
/*record ELSE() implements Token {}
|
|
||||||
record BREAK() implements Token {}
|
|
||||||
record SWITCH() implements Token {}
|
|
||||||
record CASE() implements Token {}
|
|
||||||
record RETURN() implements Token {}
|
|
||||||
record VOID() implements Token {}
|
|
||||||
record BOOLEAN() implements Token {}
|
|
||||||
record JNULL() implements Token {}
|
|
||||||
record INT() implements Token {}
|
|
||||||
record CHAR() implements Token {}
|
|
||||||
record STRING() implements Token {}
|
|
||||||
record LONG() implements Token {}
|
|
||||||
*/
|
|
||||||
record BOOLEANLITERALTRUE () implements Token {}
|
|
||||||
/*
|
|
||||||
record BOOLEANLITERALFALSE() implements Token {}
|
|
||||||
record INTLITERAL (Integer i) implements Token {}
|
|
||||||
record LONGLITERAL (String Str) implements Token {}
|
|
||||||
record FLOATLITERAL (String Str) implements Token {}
|
|
||||||
record CHARLITERAL (String Str) implements Token {}
|
|
||||||
record STRINGLITERAL (String Str) implements Token {}
|
|
||||||
record MEMORYADRESSLITERAL (String Str) implements Token {}
|
|
||||||
record NAME (String Str) implements Token {}
|
|
||||||
record WHITESPACE() implements Token {}*/
|
|
||||||
|
|
||||||
public sealed interface List<T> permits Cons, Empty {}
|
|
||||||
|
|
||||||
public record Cons<T>(T a, List<T> l) implements List<T> {}
|
|
||||||
public record Empty<T>() implements List<T> {}
|
|
||||||
|
|
||||||
public class LLParser {
|
|
||||||
|
|
||||||
nach(f, g) {
|
|
||||||
return x -> f.apply(g.apply(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
public stmt (Cons(fst, Cons<Token> rest)) {
|
|
||||||
return switch (fst) {
|
|
||||||
case IF a -> ifThenElsestatement(rest);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public stmt(IF()) { return new IF(); }
|
|
||||||
|
|
||||||
statement (Cons(IF(), rest)) {
|
|
||||||
return ifThenElsestatement(rest);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
ifThenElsestatement (Empty()) {
|
|
||||||
return new Empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
ifThenElsestatement (rest) {
|
|
||||||
return bexpression(rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
bexpression (Cons(LBRACE fst, Cons<Token> rest)) {
|
|
||||||
return switch(rest) {
|
|
||||||
case Cons(BOOLEANLITERALTRUE t, rest2) -> switch (rest2) {
|
|
||||||
case Cons(RBRACE rb, rest3) -> rest3;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -357,6 +357,17 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (binary.operation.equals(BinaryExpr.Operator.AND) || binary.operation.equals(BinaryExpr.Operator.OR) || binary.operation.equals(BinaryExpr.Operator.XOR)) {
|
||||||
|
// Binary operations defined on boolean
|
||||||
|
if (classNames.contains(bool.getName())) {
|
||||||
|
Constraint<Pair> boolOp = new Constraint<>();
|
||||||
|
boolOp.add(new Pair(binary.lexpr.getType(), bool, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
|
boolOp.add(new Pair(binary.rexpr.getType(), bool, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
|
boolOp.add(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
|
numericAdditionOrStringConcatenation.add(boolOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (numericAdditionOrStringConcatenation.isEmpty()) {
|
if (numericAdditionOrStringConcatenation.isEmpty()) {
|
||||||
throw new TypeinferenceException("Kein Typ für " + binary.operation.toString() + " vorhanden", binary.getOffset());
|
throw new TypeinferenceException("Kein Typ für " + binary.operation.toString() + " vorhanden", binary.getOffset());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1365,14 +1365,6 @@ public class TestComplete {
|
|||||||
main.invoke(null, List.of());
|
main.invoke(null, List.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLLParser() throws Exception {
|
|
||||||
ConsoleInterface.logLevel = LogLevel.INFO;
|
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "LLParser.jav");
|
|
||||||
var clazz = classFiles.get("LLParser");
|
|
||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBug122() throws Exception {
|
public void testBug122() throws Exception {
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "Bug122.jav");
|
var classFiles = generateClassFiles(createClassLoader(), "Bug122.jav");
|
||||||
@@ -1814,4 +1806,29 @@ public class TestComplete {
|
|||||||
var bnot = clazz.getDeclaredMethod("not", Integer.class);
|
var bnot = clazz.getDeclaredMethod("not", Integer.class);
|
||||||
assertEquals(-11, bnot.invoke(instance, 10));
|
assertEquals(-11, bnot.invoke(instance, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBug463() throws Exception {
|
||||||
|
var classFiles = generateClassFiles(createClassLoader(), "Bug463.jav");
|
||||||
|
var clazz = classFiles.get("Bug463");
|
||||||
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
var and = clazz.getDeclaredMethod("and", Boolean.class, Boolean.class);
|
||||||
|
assertEquals(true, and.invoke(instance, true, true));
|
||||||
|
assertEquals(false, and.invoke(instance, true, false));
|
||||||
|
assertEquals(false, and.invoke(instance, false, true));
|
||||||
|
assertEquals(false, and.invoke(instance, false, false));
|
||||||
|
|
||||||
|
var or = clazz.getDeclaredMethod("or", Boolean.class, Boolean.class);
|
||||||
|
assertEquals(true, or.invoke(instance, true, true));
|
||||||
|
assertEquals(true, or.invoke(instance, true, false));
|
||||||
|
assertEquals(true, or.invoke(instance, false, true));
|
||||||
|
assertEquals(false, or.invoke(instance, false, false));
|
||||||
|
|
||||||
|
var xor = clazz.getDeclaredMethod("xor", Boolean.class, Boolean.class);
|
||||||
|
assertEquals(false, xor.invoke(instance, true, true));
|
||||||
|
assertEquals(true, xor.invoke(instance, true, false));
|
||||||
|
assertEquals(true, xor.invoke(instance, false, true));
|
||||||
|
assertEquals(false, xor.invoke(instance, false, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user