fixed nested IDs showing this. along their name

This commit is contained in:
laurenz 2024-05-08 23:54:52 +02:00
parent 871447b9df
commit 379bfe7201
2 changed files with 24 additions and 4 deletions

View File

@ -15,6 +15,26 @@ import java.io.IOException;
*/ */
public class Compiler { public class Compiler {
public static void main(String[] args) {
generateAST("""
public class ClassWithConstructorWithParameters {
int x;
public ClassWithConstructorWithParameters(int startValue, int repetitions) {
this.x = startValue;
while (repetitions > 0) {
int innerRepetitions;
innerRepetitions = this.x;
while (innerRepetitions > 0) {
this.x = this.x * this.x;
innerRepetitions -= 1;
}
repetitions -= 1;
}
}
}
""");
}
public static Class generateAST(String fromSource) { public static Class generateAST(String fromSource) {
CharStream input = CharStreams.fromString(fromSource); CharStream input = CharStreams.fromString(fromSource);
DecafLexer lexer = new DecafLexer(input); DecafLexer lexer = new DecafLexer(input);
@ -63,7 +83,7 @@ public class Compiler {
CodeGenUtils.writeClassfile(bytes, classname); CodeGenUtils.writeClassfile(bytes, classname);
} }
public static void main(String[] args) { // public static void main(String[] args) {
generateByteCodeFileFromFile("src/main/resources/JavaTestfiles/ClassWithConstructor.java", "ClassWithConstructor"); // generateByteCodeFileFromFile("src/main/resources/JavaTestfiles/ClassWithConstructor.java", "ClassWithConstructor");
} // }
} }

View File

@ -49,7 +49,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
List<DecafParser.RecipientContext> recipientList = ctx.fieldVarAccess().recipient(); List<DecafParser.RecipientContext> recipientList = ctx.fieldVarAccess().recipient();
recipient = generateRecursiveOwnerChain(recipientList, null); recipient = generateRecursiveOwnerChain(recipientList, null);
} }
return new FieldVarAccess(isField, recipient, ctx.getText()); return new FieldVarAccess(isField, recipient, ctx.fieldVarAccess().id().IDENTIFIER().getText());
} }
public static Expression generateConstant(DecafParser.LiteralContext ctx) { public static Expression generateConstant(DecafParser.LiteralContext ctx) {