// Copyright (c) 2020-now by the Zeek Project. See LICENSE for details. #pragma once #include #include #include #include #include #include namespace hilti::ctor { /** AST node for a `exception` ctor. */ class Exception : public Ctor { public: auto value() const { return child(1); } auto location() const { return childTryAs(2); } QualifiedType* type() const final { return child(0); } /** Constructs a exception value of a given type. */ static auto create(ASTContext* ctx, UnqualifiedType* type, Expression* value, const Meta& meta = {}) { return ctx->make(ctx, {QualifiedType::create(ctx, type, Constness::Const, meta), value, nullptr}, meta); } static auto create(ASTContext* ctx, UnqualifiedType* type, Expression* value, Expression* location, const Meta& meta = {}) { return ctx->make(ctx, {QualifiedType::create(ctx, type, Constness::Const, meta), value, location}, meta); } protected: Exception(ASTContext* ctx, Nodes children, Meta meta) : Ctor(ctx, NodeTags, std::move(children), std::move(meta)) {} HILTI_NODE_1(ctor::Exception, Ctor, final); }; } // namespace hilti::ctor