[VER] 0.3.4-alpha

[FEAT] 异常系统, try/catch/finally
This commit is contained in:
2025-12-30 17:42:41 +08:00
parent 6982f169aa
commit 9f24392034
13 changed files with 857 additions and 470 deletions

View File

@@ -0,0 +1,64 @@
#pragma once
#include <Ast/astBase.hpp>
namespace Fig::Ast
{
class ThrowSt final : public StatementAst
{
public:
Expression value;
ThrowSt()
{
type = AstType::ThrowSt;
}
ThrowSt(Expression _value) :
value(std::move(_value))
{
type = AstType::ThrowSt;
}
};
using Throw = std::shared_ptr<ThrowSt>;
struct Catch
{
FString errVarName;
bool hasType = false;
FString errVarType;
BlockStatement body;
Catch() {}
Catch(FString _errVarName, FString _errVarType, BlockStatement _body) :
errVarName(std::move(_errVarName)), errVarType(std::move(_errVarType)), body(std::move(_body))
{
hasType = true;
}
Catch(FString _errVarName, BlockStatement _body) :
errVarName(std::move(_errVarName)), body(std::move(_body))
{
hasType = false;
}
};
class TrySt final : public StatementAst
{
public:
BlockStatement body;
std::vector<Catch> catches;
BlockStatement finallyBlock = nullptr;
TrySt()
{
type = AstType::TrySt;
}
TrySt(BlockStatement _body, std::vector<Catch> _catches, BlockStatement _finallyBlock) :
body(std::move(_body)), catches(std::move(_catches)), finallyBlock(std::move(_finallyBlock))
{
type = AstType::TrySt;
}
};
using Try = std::shared_ptr<TrySt>;
} // namespace Fig::Ast

View File

@@ -15,6 +15,8 @@
#include <Ast/Expressions/ValueExpr.hpp>
#include <Ast/Expressions/VarExpr.hpp>
#include <Ast/Statements/ControlSt.hpp>
#include <Ast/Statements/ErrorFlow.hpp>
#include <Ast/Statements/VarDef.hpp>
#include <Ast/Statements/WhileSt.hpp>
#include <Ast/Statements/StructDefSt.hpp>
@@ -23,6 +25,5 @@
#include <Ast/Statements/ImportSt.hpp>
#include <Ast/Statements/InterfaceDefSt.hpp>
#include <Ast/Statements/FunctionDefSt.hpp>
#include <Ast/Statements/ControlSt.hpp>
#include <Ast/Statements/ExpressionStmt.hpp>
#include <Ast/Statements/ForSt.hpp>

View File

@@ -60,6 +60,9 @@ namespace Fig::Ast
PackageSt,
ImportSt,
TrySt,
ThrowSt,
};
// static const std::unordered_map<AstType, FString> astTypeToString{
@@ -210,6 +213,7 @@ namespace Fig::Ast
LessEqual, // <=
Greater, // >
GreaterEqual, // >=
Is, // a is b
// 三目
TernaryCond,
@@ -254,6 +258,7 @@ namespace Fig::Ast
Operator::LessEqual,
Operator::Greater,
Operator::GreaterEqual,
Operator::Is,
Operator::BitAnd,
Operator::BitOr,
@@ -297,6 +302,7 @@ namespace Fig::Ast
{TokenType::LessEqual, Operator::LessEqual},
{TokenType::Greater, Operator::Greater},
{TokenType::GreaterEqual, Operator::GreaterEqual},
{TokenType::Is, Operator::Is},
// 三目
{TokenType::Question, Operator::TernaryCond},