feat: 增加了analyzer, compiler不再分析并且报错, 只生产 bytecode, analyzer作为前端结束最后一道防线检查代码,同时引入一个简单的LSP
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include <Core/SourceLocations.hpp>
|
||||
#include <Deps/Deps.hpp>
|
||||
|
||||
#include <Sema/Type.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Fig
|
||||
@@ -49,6 +51,10 @@ namespace Fig
|
||||
|
||||
struct Expr : public AstNode
|
||||
{
|
||||
TypeTag resolvedType = TypeTag::Any;
|
||||
// TODO: 可选的常量折叠
|
||||
// 拓展 isConstExpr和 constValue槽位
|
||||
|
||||
Expr()
|
||||
{
|
||||
type = AstType::Expr;
|
||||
|
||||
@@ -16,6 +16,10 @@ namespace Fig
|
||||
{
|
||||
String name;
|
||||
|
||||
// Analyzer槽位,存储具体深度
|
||||
int resolvedDepth = -1; // 代表未解析
|
||||
bool isGlobal = false; // 是否全局/对外公开 (isPublic)
|
||||
|
||||
IdentiExpr()
|
||||
{
|
||||
type = AstType::IdentiExpr;
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace Fig
|
||||
|
||||
IndexExpr(Expr *_base, Expr *_index) : base(_base), index(_index)
|
||||
{
|
||||
type = AstType::IndexExpr;
|
||||
location = base->location;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Fig
|
||||
{
|
||||
String name;
|
||||
Expr *typeSpecifier;
|
||||
bool isInfer; // 是否用了 := 类型推断
|
||||
Expr *initExpr;
|
||||
|
||||
VarDecl()
|
||||
@@ -23,9 +24,10 @@ namespace Fig
|
||||
type = AstType::VarDecl;
|
||||
}
|
||||
|
||||
VarDecl(bool _isPublic, String _name, Expr *_typeSpecifier, Expr *_initExpr, SourceLocation _location) :
|
||||
VarDecl(bool _isPublic, String _name, Expr *_typeSpecifier, bool _isInfer, Expr *_initExpr, SourceLocation _location) :
|
||||
name(std::move(_name)),
|
||||
typeSpecifier(_typeSpecifier),
|
||||
isInfer(_isInfer),
|
||||
initExpr(_initExpr) // location 指向关键字 var/const位置
|
||||
{
|
||||
type = AstType::VarDecl;
|
||||
|
||||
Reference in New Issue
Block a user