From 9d36f7defe05a23afda2e670298124028d832e27 Mon Sep 17 00:00:00 2001 From: willson walter Date: Wed, 15 Nov 2023 14:11:25 +0800 Subject: [PATCH] User How do I use DevChat? DevChat Do you want to write some code or have a question about the project? Simply right-click on your chosen files or code snippets and add them to DevChat. Feel free to ask me anything or let me help you with coding. Don't forget to check out the "+" button on the left of the input to add more context. To see a list of workflows you can run in the context, just type "/". Happy prompting! To get started, here are some of the things that I can do for you: /code: write code based on your prompt /commit_message: compose a commit message based on your code changes /release_note: draft a release note based on your latest commits /ask-code: ask anything about your codebase and get answers from our AI agent You can configure DevChat from Settings. User git diff HEAD /commit_message DevChat Here is a commit message for the diff output: commitmsg Refactor operand to temp and add Operand base class - Rename operand to temp in parser rules and visitor - Add Operand base class - Temp and ImmValue extend Operand instead of Expr - Change method signatures to use Operand instead of Temp - pushEvalOperand - Assign constructor and with method - Update callers of renamed methods --- .../ep18/parser/VMAssemblerBaseListener.java | 4 +- .../ep18/parser/VMAssemblerBaseVisitor.java | 2 +- .../ep18/parser/VMAssemblerListener.java | 8 ++-- .../antlr4/ep18/parser/VMAssemblerParser.java | 48 +++++++++---------- .../ep18/parser/VMAssemblerVisitor.java | 4 +- .../teachfx/antlr4/ep20/ir/expr/ImmValue.java | 2 +- .../ep20/ir/expr/{Temp.java => Operand.java} | 2 +- .../teachfx/antlr4/ep20/ir/expr/VarSlot.java | 2 +- .../teachfx/antlr4/ep20/ir/stmt/Assign.java | 10 ++-- .../antlr4/ep20/pass/ir/CymbolIRBuilder.java | 12 ++--- 10 files changed, 47 insertions(+), 47 deletions(-) rename ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/{Temp.java => Operand.java} (76%) diff --git a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseListener.java b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseListener.java index 1ce65d5..861e93f 100644 --- a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseListener.java +++ b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseListener.java @@ -67,13 +67,13 @@ public class VMAssemblerBaseListener implements VMAssemblerListener { * *

The default implementation does nothing.

*/ - @Override public void enterOperand(VMAssemblerParser.OperandContext ctx) { } + @Override public void enterTemp(VMAssemblerParser.TempContext ctx) { } /** * {@inheritDoc} * *

The default implementation does nothing.

*/ - @Override public void exitOperand(VMAssemblerParser.OperandContext ctx) { } + @Override public void exitTemp(VMAssemblerParser.TempContext ctx) { } /** * {@inheritDoc} * diff --git a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseVisitor.java b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseVisitor.java index 7ff39c0..2cea062 100644 --- a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseVisitor.java +++ b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerBaseVisitor.java @@ -48,7 +48,7 @@ public class VMAssemblerBaseVisitor extends AbstractParseTreeVisitor imple *

The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.

*/ - @Override public T visitOperand(VMAssemblerParser.OperandContext ctx) { return visitChildren(ctx); } + @Override public T visitTemp(VMAssemblerParser.TempContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} * diff --git a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerListener.java b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerListener.java index ae32d2a..79332fc 100644 --- a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerListener.java +++ b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerListener.java @@ -50,15 +50,15 @@ public interface VMAssemblerListener extends ParseTreeListener { */ void exitInstr(VMAssemblerParser.InstrContext ctx); /** - * Enter a parse tree produced by {@link VMAssemblerParser#operand}. + * Enter a parse tree produced by {@link VMAssemblerParser#temp}. * @param ctx the parse tree */ - void enterOperand(VMAssemblerParser.OperandContext ctx); + void enterTemp(VMAssemblerParser.TempContext ctx); /** - * Exit a parse tree produced by {@link VMAssemblerParser#operand}. + * Exit a parse tree produced by {@link VMAssemblerParser#temp}. * @param ctx the parse tree */ - void exitOperand(VMAssemblerParser.OperandContext ctx); + void exitTemp(VMAssemblerParser.TempContext ctx); /** * Enter a parse tree produced by {@link VMAssemblerParser#label}. * @param ctx the parse tree diff --git a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerParser.java b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerParser.java index 485a723..050cba9 100644 --- a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerParser.java +++ b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerParser.java @@ -23,10 +23,10 @@ public class VMAssemblerParser extends Parser { INT=11, CHAR=12, BOOL=13, STRING=14, FLOAT=15, WS=16, NEWLINE=17; public static final int RULE_program = 0, RULE_globals = 1, RULE_functionDeclaration = 2, RULE_instr = 3, - RULE_operand = 4, RULE_label = 5; + RULE_temp = 4, RULE_label = 5; private static String[] makeRuleNames() { return new String[] { - "program", "globals", "functionDeclaration", "instr", "operand", "label" + "program", "globals", "functionDeclaration", "instr", "temp", "label" }; } public static final String[] ruleNames = makeRuleNames(); @@ -349,16 +349,16 @@ public final FunctionDeclarationContext functionDeclaration() throws Recognition @SuppressWarnings("CheckReturnValue") public static class InstrContext extends ParserRuleContext { public Token op; - public OperandContext a; - public OperandContext b; - public OperandContext c; + public TempContext a; + public TempContext b; + public TempContext c; public TerminalNode NEWLINE() { return getToken(VMAssemblerParser.NEWLINE, 0); } public TerminalNode ID() { return getToken(VMAssemblerParser.ID, 0); } - public List operand() { - return getRuleContexts(OperandContext.class); + public List temp() { + return getRuleContexts(TempContext.class); } - public OperandContext operand(int i) { - return getRuleContext(OperandContext.class,i); + public TempContext temp(int i) { + return getRuleContext(TempContext.class,i); } public InstrContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); @@ -401,7 +401,7 @@ public final InstrContext instr() throws RecognitionException { setState(47); ((InstrContext)_localctx).op = match(ID); setState(48); - ((InstrContext)_localctx).a = operand(); + ((InstrContext)_localctx).a = temp(); setState(49); match(NEWLINE); } @@ -412,11 +412,11 @@ public final InstrContext instr() throws RecognitionException { setState(51); ((InstrContext)_localctx).op = match(ID); setState(52); - ((InstrContext)_localctx).a = operand(); + ((InstrContext)_localctx).a = temp(); setState(53); match(T__5); setState(54); - ((InstrContext)_localctx).b = operand(); + ((InstrContext)_localctx).b = temp(); setState(55); match(NEWLINE); } @@ -427,15 +427,15 @@ public final InstrContext instr() throws RecognitionException { setState(57); ((InstrContext)_localctx).op = match(ID); setState(58); - ((InstrContext)_localctx).a = operand(); + ((InstrContext)_localctx).a = temp(); setState(59); match(T__5); setState(60); - ((InstrContext)_localctx).b = operand(); + ((InstrContext)_localctx).b = temp(); setState(61); match(T__5); setState(62); - ((InstrContext)_localctx).c = operand(); + ((InstrContext)_localctx).c = temp(); setState(63); match(NEWLINE); } @@ -454,7 +454,7 @@ public final InstrContext instr() throws RecognitionException { } @SuppressWarnings("CheckReturnValue") - public static class OperandContext extends ParserRuleContext { + public static class TempContext extends ParserRuleContext { public TerminalNode ID() { return getToken(VMAssemblerParser.ID, 0); } public TerminalNode REG() { return getToken(VMAssemblerParser.REG, 0); } public TerminalNode FUNC() { return getToken(VMAssemblerParser.FUNC, 0); } @@ -463,28 +463,28 @@ public static class OperandContext extends ParserRuleContext { public TerminalNode CHAR() { return getToken(VMAssemblerParser.CHAR, 0); } public TerminalNode STRING() { return getToken(VMAssemblerParser.STRING, 0); } public TerminalNode FLOAT() { return getToken(VMAssemblerParser.FLOAT, 0); } - public OperandContext(ParserRuleContext parent, int invokingState) { + public TempContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); } - @Override public int getRuleIndex() { return RULE_operand; } + @Override public int getRuleIndex() { return RULE_temp; } @Override public void enterRule(ParseTreeListener listener) { - if ( listener instanceof VMAssemblerListener ) ((VMAssemblerListener)listener).enterOperand(this); + if ( listener instanceof VMAssemblerListener ) ((VMAssemblerListener)listener).enterTemp(this); } @Override public void exitRule(ParseTreeListener listener) { - if ( listener instanceof VMAssemblerListener ) ((VMAssemblerListener)listener).exitOperand(this); + if ( listener instanceof VMAssemblerListener ) ((VMAssemblerListener)listener).exitTemp(this); } @Override public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof VMAssemblerVisitor ) return ((VMAssemblerVisitor)visitor).visitOperand(this); + if ( visitor instanceof VMAssemblerVisitor ) return ((VMAssemblerVisitor)visitor).visitTemp(this); else return visitor.visitChildren(this); } } - public final OperandContext operand() throws RecognitionException { - OperandContext _localctx = new OperandContext(_ctx, getState()); - enterRule(_localctx, 8, RULE_operand); + public final TempContext temp() throws RecognitionException { + TempContext _localctx = new TempContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_temp); int _la; try { enterOuterAlt(_localctx, 1); diff --git a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerVisitor.java b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerVisitor.java index d676602..35aea4d 100644 --- a/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerVisitor.java +++ b/ep18/src/main/java/org/teachfx/antlr4/ep18/parser/VMAssemblerVisitor.java @@ -37,11 +37,11 @@ public interface VMAssemblerVisitor extends ParseTreeVisitor { */ T visitInstr(VMAssemblerParser.InstrContext ctx); /** - * Visit a parse tree produced by {@link VMAssemblerParser#operand}. + * Visit a parse tree produced by {@link VMAssemblerParser#temp}. * @param ctx the parse tree * @return the visitor result */ - T visitOperand(VMAssemblerParser.OperandContext ctx); + T visitTemp(VMAssemblerParser.TempContext ctx); /** * Visit a parse tree produced by {@link VMAssemblerParser#label}. * @param ctx the parse tree diff --git a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/ImmValue.java b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/ImmValue.java index 88e6ec3..53bad77 100644 --- a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/ImmValue.java +++ b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/ImmValue.java @@ -1,5 +1,5 @@ package org.teachfx.antlr4.ep20.ir.expr; -public abstract class ImmValue extends Temp { +public abstract class ImmValue extends Operand { } diff --git a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/Temp.java b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/Operand.java similarity index 76% rename from ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/Temp.java rename to ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/Operand.java index 6418bea..79e5abb 100644 --- a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/Temp.java +++ b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/Operand.java @@ -2,6 +2,6 @@ import org.teachfx.antlr4.ep20.ir.IRVisitor; -public abstract class Temp extends Expr { +public abstract class Operand extends Expr { abstract public E accept(IRVisitor visitor); } diff --git a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/VarSlot.java b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/VarSlot.java index 5834236..e162c47 100644 --- a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/VarSlot.java +++ b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/expr/VarSlot.java @@ -1,5 +1,5 @@ package org.teachfx.antlr4.ep20.ir.expr; -public abstract class VarSlot extends Temp { +public abstract class VarSlot extends Operand { } diff --git a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/stmt/Assign.java b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/stmt/Assign.java index 5679c3c..2791dfa 100644 --- a/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/stmt/Assign.java +++ b/ep20/src/main/java/org/teachfx/antlr4/ep20/ir/stmt/Assign.java @@ -1,12 +1,12 @@ package org.teachfx.antlr4.ep20.ir.stmt; import org.teachfx.antlr4.ep20.ir.IRVisitor; -import org.teachfx.antlr4.ep20.ir.expr.Temp; +import org.teachfx.antlr4.ep20.ir.expr.Operand; import org.teachfx.antlr4.ep20.ir.expr.VarSlot; public class Assign extends Stmt { protected VarSlot lhs; - protected Temp rhs; + protected Operand rhs; /** * Assign a value to a variable @@ -24,10 +24,10 @@ public static Assign with(VarSlot lhs,VarSlot rhs) { * @param rhs Value to assign * @return Assign object */ - public static Assign with(VarSlot lhs, Temp rhs) { + public static Assign with(VarSlot lhs, Operand rhs) { return new Assign(lhs,rhs); } - public Assign(VarSlot lhs, Temp rhs) { + public Assign(VarSlot lhs, Operand rhs) { this.lhs = lhs; this.rhs = rhs; } @@ -36,7 +36,7 @@ public Assign(VarSlot lhs, Temp rhs) { public VarSlot getLhs() { return lhs; } - public Temp getRhs() { + public Operand getRhs() { return rhs; } diff --git a/ep20/src/main/java/org/teachfx/antlr4/ep20/pass/ir/CymbolIRBuilder.java b/ep20/src/main/java/org/teachfx/antlr4/ep20/pass/ir/CymbolIRBuilder.java index df202ce..89f3684 100644 --- a/ep20/src/main/java/org/teachfx/antlr4/ep20/pass/ir/CymbolIRBuilder.java +++ b/ep20/src/main/java/org/teachfx/antlr4/ep20/pass/ir/CymbolIRBuilder.java @@ -10,7 +10,7 @@ import org.teachfx.antlr4.ep20.ast.expr.*; import org.teachfx.antlr4.ep20.ast.stmt.*; import org.teachfx.antlr4.ep20.ast.type.TypeNode; -import org.teachfx.antlr4.ep20.ir.expr.Temp; +import org.teachfx.antlr4.ep20.ir.expr.Operand; import org.teachfx.antlr4.ep20.pass.cfg.BasicBlock; import org.teachfx.antlr4.ep20.ir.IRNode; import org.teachfx.antlr4.ep20.ir.Prog; @@ -382,24 +382,24 @@ public void popContinueStack() { continueStack.pop(); } static int cnt = 0; - protected VarSlot pushEvalOperand(Temp temp) { + protected VarSlot pushEvalOperand(Operand operand) { if (curNode != null) { logger.info(curNode.toString()); } - if (!(temp instanceof OperandSlot)){ + if (!(operand instanceof OperandSlot)){ cnt++; var assignee = OperandSlot.pushStack(); evalExprStack.push(assignee); - addInstr(Assign.with(assignee, temp)); + addInstr(Assign.with(assignee, operand)); logger.info("-> eval stack %s%n", evalExprStack.toString()); return assignee; } else { logger.info("-> eval stack %s%n", evalExprStack.toString()); - evalExprStack.push((VarSlot) temp); - return (VarSlot) temp; + evalExprStack.push((VarSlot) operand); + return (VarSlot) operand; } }