!34 fix: 空函数不生成代码的问题

Merge pull request !34 from zhangxun/bugfix/empty-main-function
This commit is contained in:
Luke 2025-07-10 07:39:33 +00:00 committed by Gitee
commit 565cc79329
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -2,6 +2,7 @@ package org.jcnc.snow.compiler.parser.function;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.ReturnNode;
import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.base.TopLevelParser;
import org.jcnc.snow.compiler.parser.ast.FunctionNode;
@ -72,6 +73,9 @@ public class FunctionParser implements TopLevelParser {
Map<String, SectionDefinition> sections = getSectionDefinitions(parameters, returnType, body);
FlexibleSectionParser.parse(ctx, ts, sections);
if (body.isEmpty() && returnType[0].equals("void")) {
body.add(new ReturnNode(null, new NodeContext(line, column, file)));
}
parseFunctionFooter(ts);