Files
MY_COMPILER/midend/visit/VisitorBlock.java
2025-12-10 17:58:17 +08:00

36 lines
1.2 KiB
Java

package midend.visit;
import java.util.ArrayList;
import frontend.ast.block.Block;
import frontend.ast.block.BlockItem;
import frontend.ast.block.Stmt;
import frontend.ast.decl.Decl;
import midend.symbol.SymbolManager;
public class VisitorBlock {
public static void visitBlock(Block block) {
if (!block.isFuncBlock()) {
SymbolManager.nextTable();
}
// System.out.println("(block)now table: " + SymbolManager.getCurrentTableId());
// System.out.println("bsequence: " + SymbolManager.getCurrentSequence());//TODO:debug
ArrayList<BlockItem> blockItems = block.getBlockItems();
for (BlockItem blockItem : blockItems) {
visitBlockItem(blockItem);
}
if (!block.isFuncBlock()) {
SymbolManager.nextTable();
}
// System.out.println("(block)now table: " + SymbolManager.getCurrentTableId());//TODO:debug
}
public static void visitBlockItem(BlockItem blockItem) {
if (blockItem.getChild(0) instanceof Decl) {
VisitorDecl.visitDecl((Decl) blockItem.getChild(0));
} else {
VisitorStmt.visitStmt((Stmt) blockItem.getChild(0));
}
}
}