Skip to content

Commit 32a300c

Browse files
committed
feat(parser): 优化 QVM指令处理顺序
-首先处理宏定义,确保它们在函数中可用 -其次处理函数定义,支持前向引用 - 最后处理其他语句
1 parent bad6611 commit 32a300c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/com/alibaba/qlexpress4/aparser/QvmInstructionVisitor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,23 @@ public Void visitBlockStatements(BlockStatementsContext blockStatementsContext)
185185
.filter(bs -> !(bs instanceof EmptyStatementContext))
186186
.collect(Collectors.toList());
187187

188-
// First pass: process all function definitions to support forward references
188+
// First pass: process macro definitions to ensure they are available for functions
189+
for (BlockStatementContext child : nonEmptyChildren) {
190+
if (child instanceof MacroStatementContext) {
191+
child.accept(this);
192+
}
193+
}
194+
195+
// Second pass: process all function definitions to support forward references
189196
for (BlockStatementContext child : nonEmptyChildren) {
190197
if (child instanceof FunctionStatementContext) {
191198
child.accept(this);
192199
}
193200
}
194201

195-
// Second pass: process all non-function statements
202+
// Third pass: process all other statements
196203
for (BlockStatementContext child : nonEmptyChildren) {
197-
if (!(child instanceof FunctionStatementContext)) {
204+
if (!(child instanceof FunctionStatementContext) && !(child instanceof MacroStatementContext)) {
198205
if (isPreExpress) {
199206
addInstruction(new PopInstruction(PureErrReporter.INSTANCE));
200207
}

0 commit comments

Comments
 (0)