Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,14 @@ public void accept(ASTVisitor visitor) {
public static class ArrayIndexExpr extends Expr {
public final Expr array;
public final Expr expr;
public final boolean loading;
public ArrayIndexExpr(Expr array, Expr expr) {
this(array, expr, true);
}
public ArrayIndexExpr(Expr array, Expr expr, boolean loading) {
this.array = array;
this.expr = expr;
this.loading = loading;
}
@Override
public StringBuilder toStr(StringBuilder sb) {
Expand All @@ -398,9 +403,14 @@ public void accept(ASTVisitor visitor) {
public static class FieldExpr extends Expr {
public final Expr object;
public final String fieldName;
public final boolean loading;
public FieldExpr(Expr object, String fieldName) {
this(object, fieldName, true);
}
public FieldExpr(Expr object, String fieldName, boolean loading) {
this.object = object;
this.fieldName = fieldName;
this.loading = loading;
}
@Override
public StringBuilder toStr(StringBuilder sb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,19 @@ private AST.Stmt parseAssign(Lexer lexer) {
testPunctuation(lexer, ";");
if (rhs == null)
return new AST.ExprStmt(lhs);
return new AST.AssignStmt(lhs, rhs);
return new AST.AssignStmt(storing(lhs), rhs);
}

private AST.Expr storing(AST.Expr lhs) {
if (lhs instanceof AST.ArrayIndexExpr arrayIndexExpr &&
arrayIndexExpr.loading) {
return new AST.ArrayIndexExpr(arrayIndexExpr.array, arrayIndexExpr.expr, false);
}
else if (lhs instanceof AST.FieldExpr fieldExpr &&
fieldExpr.loading) {
return new AST.FieldExpr(fieldExpr.object, fieldExpr.fieldName, false);
}
return lhs;
}

private AST.Expr parseBool(Lexer lexer) {
Expand Down
Loading