aboutsummaryrefslogtreecommitdiff
path: root/include/cps/AST.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-16 10:04:27 +0000
committer_ov4 <ov4@ov4.org>2026-10-16 10:04:27 +0000
commit45c9d37eb27d204a6202b33cb37e890af0171357 (patch)
treedba23170b16053c5e1ec4bf78efc2a533cb94a4e /include/cps/AST.h
parent522742e9df7fc5ac596ce4aa53d41b31e4f6a030 (diff)
feat(control-flow): implement ordered CASE OF matching
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/AST.h')
-rw-r--r--include/cps/AST.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/cps/AST.h b/include/cps/AST.h
index e3c6bc5..87c9341 100644
--- a/include/cps/AST.h
+++ b/include/cps/AST.h
@@ -168,6 +168,22 @@ public:
const std::vector<std::unique_ptr<ExprAST>> &getExprs() const { return Exprs; }
};
+struct CaseBranch {
+ std::unique_ptr<ExprAST> Lower, Upper; // Null Lower denotes OTHERWISE.
+ std::vector<std::unique_ptr<StmtAST>> Body;
+ int Line;
+};
+
+class CaseStmtAST : public StmtAST {
+ std::string Selector;
+ std::vector<CaseBranch> Branches;
+public:
+ CaseStmtAST(std::string Selector, std::vector<CaseBranch> Branches)
+ : Selector(std::move(Selector)), Branches(std::move(Branches)) {}
+ const std::string &getSelector() const { return Selector; }
+ const std::vector<CaseBranch> &getBranches() const { return Branches; }
+};
+
class IfStmtAST : public StmtAST {
std::unique_ptr<ExprAST> Cond;
std::vector<std::unique_ptr<StmtAST>> ThenStmts;