// Copyright (c) 2020-now by the Zeek Project. See LICENSE for details. #pragma once #include #include #include #include #include #include #include #include namespace hilti::statement { namespace try_ { /** AST node for a `catch` block. */ class Catch final : public Node { public: auto parameter() const { return child(0); } auto body() const { return child(1); } static auto create(ASTContext* ctx, hilti::Declaration* param, Statement* body, Meta meta = {}) { return ctx->make(ctx, {param, body}, std::move(meta)); } static auto create(ASTContext* ctx, Statement* body, Meta meta = {}) { return ctx->make(ctx, {nullptr, body}, std::move(meta)); } protected: Catch(ASTContext* ctx, Nodes children, Meta meta = {}) : Node(ctx, NodeTags, std::move(children), std::move(meta)) { if ( child(0) && ! child(0)->isA() ) logger().internalError("'catch' first child must be parameter"); } std::string _dump() const final; HILTI_NODE_0(statement::try_::Catch, final); }; using Catches = NodeVector; } // namespace try_ /** AST node for a `try` statement. */ class Try : public Statement { public: auto body() const { return child(0); } auto catches() const { return children(1, {}); } void addCatch(ASTContext* ctx, try_::Catch* c) { addChild(ctx, c); } static auto create(ASTContext* ctx, Statement* body, const try_::Catches& catches, Meta meta = {}) { return ctx->make(ctx, node::flatten(body, catches), std::move(meta)); } protected: Try(ASTContext* ctx, Nodes children, Meta meta) : Statement(ctx, NodeTags, std::move(children), std::move(meta)) {} HILTI_NODE_1(statement::Try, Statement, final); }; } // namespace hilti::statement