Bug fixes für Tests in 'parser'
This commit is contained in:
parent
aeb4b18069
commit
78a898db37
@ -96,7 +96,7 @@ public class CompilationEnvironment {
|
|||||||
File dir = new File(forSourceFile.getAbsoluteFile().getParent());
|
File dir = new File(forSourceFile.getAbsoluteFile().getParent());
|
||||||
String dirPath = dir.toString() + "/";
|
String dirPath = dir.toString() + "/";
|
||||||
if (packageName.length() > 0)
|
if (packageName.length() > 0)
|
||||||
dirPath = dirPath.substring(0, dirPath.length() - packageName.length());
|
dirPath = dirPath.substring(0, dirPath.length() - packageName.length() - 1);
|
||||||
String path = dirPath;
|
String path = dirPath;
|
||||||
ArrayList<File> defaultPath = Lists.newArrayList(new File(path));
|
ArrayList<File> defaultPath = Lists.newArrayList(new File(path));
|
||||||
classLoader = new DirectoryClassLoader(defaultPath, classLoader);
|
classLoader = new DirectoryClassLoader(defaultPath, classLoader);
|
||||||
|
@ -51,7 +51,6 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser.PrefixexpressionContext;
|
|||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryClassrefContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryClassrefContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryExpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryExpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryIdentifierContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryIdentifierContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryInvocationContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryLiteralContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryLiteralContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimarySuperContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimarySuperContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryThisContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryThisContext;
|
||||||
@ -65,7 +64,6 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser.StringLiteralContext;
|
|||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchexpressionstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchexpressionstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SynchronizedstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SynchronizedstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TextBlockContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ThrowstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ThrowstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchblockContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchblockContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchresourceContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchresourceContext;
|
||||||
@ -394,7 +392,13 @@ public class StatementGenerator {
|
|||||||
} else {
|
} else {
|
||||||
type = TypeGenerator.convert(declaration.typeType(), reg, generics);
|
type = TypeGenerator.convert(declaration.typeType(), reg, generics);
|
||||||
}
|
}
|
||||||
|
if (Objects.isNull(declaration.variableDeclarators())) {
|
||||||
|
Token offset = declaration.identifier().getStart();
|
||||||
|
ret.add(new Assign(new AssignToLocal(new LocalVar(declaration.identifier().getText(), type, offset)),
|
||||||
|
convert(declaration.expression()), offset));
|
||||||
|
} else {
|
||||||
ret.addAll(generateLocalVariableAssignments(declaration.variableDeclarators().variableDeclarator(), type));
|
ret.addAll(generateLocalVariableAssignments(declaration.variableDeclarators().variableDeclarator(), type));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,20 +828,11 @@ public class StatementGenerator {
|
|||||||
|
|
||||||
private Expression convert(Java17Parser.CastexpressionContext castexpr) {
|
private Expression convert(Java17Parser.CastexpressionContext castexpr) {
|
||||||
ExpressionContext expr = castexpr.expression();
|
ExpressionContext expr = castexpr.expression();
|
||||||
Expression exprast = null;
|
if (expr instanceof PrefixexpressionContext pfe) {
|
||||||
if (expr instanceof LambdaexpressionContext) {
|
|
||||||
exprast = convert(expr);
|
|
||||||
} else if (expr instanceof PrefixexpressionContext pfe) {
|
|
||||||
if (!pfe.prefix.equals("~") && !pfe.prefix.equals("!")) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else {
|
|
||||||
exprast = convert(expr);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
return new CastExpr(TypeGenerator.convert(castexpr.typeType(0), reg, generics), exprast,
|
return new CastExpr(TypeGenerator.convert(castexpr.typeType(0), reg, generics), convert(expr),
|
||||||
castexpr.getStart());
|
expr.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java17Parser.PrimaryContext primary) {
|
private Expression convert(Java17Parser.PrimaryContext primary) {
|
||||||
|
@ -172,7 +172,7 @@ public class SyntaxTreeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ClassOrInterface convertClass(Java17Parser.ClassDeclarationContext ctx, int modifiers) {
|
private ClassOrInterface convertClass(Java17Parser.ClassDeclarationContext ctx, int modifiers) {
|
||||||
String className = this.pkgName.length() > 0 ? this.pkgName + "." : "" + ctx.identifier().getText();
|
String className = this.pkgName.length() > 0 ? this.pkgName + "." : ctx.identifier().getText();
|
||||||
JavaClassName name = reg.getName(className); // Holt den Package Namen mit dazu
|
JavaClassName name = reg.getName(className); // Holt den Package Namen mit dazu
|
||||||
if (!name.toString().equals(className)) { // Kommt die Klasse schon in einem anderen Package vor?
|
if (!name.toString().equals(className)) { // Kommt die Klasse schon in einem anderen Package vor?
|
||||||
throw new TypeinferenceException(
|
throw new TypeinferenceException(
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
class CastTest{
|
class CastTest{
|
||||||
void methode(){
|
void methode(){
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
|
||||||
class FieldInitializationTest{
|
class FieldInitializationTest{
|
||||||
f;
|
f;
|
||||||
void m(){
|
void m(){
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package test;
|
package parser;
|
||||||
|
|
||||||
class Test<Typ>{
|
class Test<Typ>{
|
||||||
Typ a;
|
Typ a;
|
||||||
|
@ -41,12 +41,14 @@ public class GeneralParserTest {
|
|||||||
filenames.add("ExtendsTest.jav");
|
filenames.add("ExtendsTest.jav");
|
||||||
filenames.add("PackageNameTest.jav");
|
filenames.add("PackageNameTest.jav");
|
||||||
filenames.add("AntlrTest.jav");
|
filenames.add("AntlrTest.jav");
|
||||||
|
filenames.add("Java17Rules.jav");
|
||||||
try {
|
try {
|
||||||
for (String filename : filenames) {
|
for (String filename : filenames) {
|
||||||
System.out.println(filename);
|
System.out.println(filename);
|
||||||
new JavaTXCompiler(new File(rootDirectory + filename));
|
new JavaTXCompiler(new File(rootDirectory + filename));
|
||||||
}
|
}
|
||||||
//new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
// new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory +
|
||||||
|
// s)).collect(Collectors.toList()));
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
|
Loading…
Reference in New Issue
Block a user