[VER] 0.3.4-alpha
[FEAT] 异常系统, try/catch/finally
This commit is contained in:
64
src/Ast/Statements/ErrorFlow.hpp
Normal file
64
src/Ast/Statements/ErrorFlow.hpp
Normal 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
|
||||
@@ -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>
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user