Bug fixes für Tests in 'parser'

This commit is contained in:
luca9913 2023-03-20 03:03:37 +01:00
parent aeb4b18069
commit 78a898db37
7 changed files with 26 additions and 25 deletions

View File

@ -96,7 +96,7 @@ public class CompilationEnvironment {
File dir = new File(forSourceFile.getAbsoluteFile().getParent());
String dirPath = dir.toString() + "/";
if (packageName.length() > 0)
dirPath = dirPath.substring(0, dirPath.length() - packageName.length());
dirPath = dirPath.substring(0, dirPath.length() - packageName.length() - 1);
String path = dirPath;
ArrayList<File> defaultPath = Lists.newArrayList(new File(path));
classLoader = new DirectoryClassLoader(defaultPath, classLoader);

View File

@ -51,7 +51,6 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser.PrefixexpressionContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryClassrefContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryExpressionContext;
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.PrimarySuperContext;
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.SwitchstmtContext;
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.TrycatchblockContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchresourceContext;
@ -292,9 +290,9 @@ public class StatementGenerator {
private RefType convert(Java17Parser.CreatedNameContext createdname) {
Java17Parser.TypeArgumentsContext genericArgs = null;
genericArgs = null;
if(createdname.typeArgumentsOrDiamond() != null)
if (createdname.typeArgumentsOrDiamond() != null)
genericArgs = createdname.typeArgumentsOrDiamond().typeArguments();
if(genericArgs != null){
if (genericArgs != null) {
throw new NotImplementedException();
}
IdentifierContext identifier = createdname.identifier();
@ -394,7 +392,13 @@ public class StatementGenerator {
} else {
type = TypeGenerator.convert(declaration.typeType(), reg, generics);
}
ret.addAll(generateLocalVariableAssignments(declaration.variableDeclarators().variableDeclarator(), type));
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));
}
return ret;
}
@ -824,20 +828,11 @@ public class StatementGenerator {
private Expression convert(Java17Parser.CastexpressionContext castexpr) {
ExpressionContext expr = castexpr.expression();
Expression exprast = null;
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 {
if (expr instanceof PrefixexpressionContext pfe) {
throw new NotImplementedException();
}
return new CastExpr(TypeGenerator.convert(castexpr.typeType(0), reg, generics), exprast,
castexpr.getStart());
return new CastExpr(TypeGenerator.convert(castexpr.typeType(0), reg, generics), convert(expr),
expr.getStart());
}
private Expression convert(Java17Parser.PrimaryContext primary) {

View File

@ -172,7 +172,7 @@ public class SyntaxTreeGenerator {
}
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
if (!name.toString().equals(className)) { // Kommt die Klasse schon in einem anderen Package vor?
throw new TypeinferenceException(

View File

@ -1,3 +1,5 @@
import java.lang.Object;
import java.lang.String;
class CastTest{
void methode(){

View File

@ -1,3 +1,5 @@
import java.lang.String;
class FieldInitializationTest{
f;
void m(){

View File

@ -1,4 +1,4 @@
package test;
package parser;
class Test<Typ>{
Typ a;

View File

@ -31,22 +31,24 @@ public class GeneralParserTest {
filenames.add("ImportTest.jav");
filenames.add("CastTest.jav");
filenames.add("StatementsTest.jav");
//filenames.add("Methods.jav");
// filenames.add("Methods.jav");
filenames.add("ImportTestGeneric.jav");
filenames.add("CastTest.jav");
//filenames.add("BoundedParameter.jav");
//filenames.add("GenericFieldVarTest.jav");
// filenames.add("BoundedParameter.jav");
// filenames.add("GenericFieldVarTest.jav");
filenames.add("FieldVarTest.jav");
filenames.add("StructuralTypes.jav");
filenames.add("ExtendsTest.jav");
filenames.add("PackageNameTest.jav");
filenames.add("AntlrTest.jav");
filenames.add("Java17Rules.jav");
try {
for(String filename : filenames){
for (String filename : filenames) {
System.out.println(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) {
exc.printStackTrace();
fail();