feat: 增加了analyzer, compiler不再分析并且报错, 只生产 bytecode, analyzer作为前端结束最后一道防线检查代码,同时引入一个简单的LSP

This commit is contained in:
2026-02-23 19:57:28 +08:00
parent 852dd27836
commit b7bb889676
28 changed files with 26665 additions and 3153 deletions

70
src/Sema/Analyzer.hpp Normal file
View File

@@ -0,0 +1,70 @@
/*!
@file src/Sema/Analyzer.hpp
@brief 前端类型检查器定义
@author PuqiAR (im@puqiar.top)
@date 2026-02-23
*/
#pragma once
#include <Sema/Environment.hpp>
#include <Sema/Type.hpp>
#include <Ast/Ast.hpp>
#include <Deps/Deps.hpp>
namespace Fig
{
class Analyzer
{
private:
Environment env;
SourceManager &manager;
SourceLocation makeSourceLocation(AstNode *ast, std::source_location loc = std::source_location::current())
{
return SourceLocation(
ast->location.sp,
ast->location.fileName,
"[internal analyzer]",
loc.function_name()
);
}
bool isValidLvalue(Expr *expr)
{
if (expr->type == AstType::IdentiExpr)
{
return true;
}
if (expr->type == AstType::InfixExpr)
{
InfixExpr *infix = static_cast<InfixExpr *>(expr);
if (infix->op == BinaryOperator::MemberAccess)
{
return true;
}
}
if (expr->type == AstType::IndexExpr)
{
return true;
}
return false;
}
Result<void, Error> analyzeVarDecl(VarDecl *);
Result<void, Error> analyzeIfStmt(IfStmt *);
Result<void, Error> analyzeIdentiExpr(IdentiExpr *);
Result<void, Error> analyzeInfixExpr(InfixExpr *);
Result<void, Error> analyzeStmt(Stmt *);
Result<void, Error> analyzeExpr(Expr *);
public:
Result<void, Error> Analyze(Program *);
Analyzer(SourceManager &_manager) : manager(_manager) {}
};
}; // namespace Fig