# Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details.

module hilti {

# Ignore this module for code generation, we just need the declarations.
%skip-implementation;

public type BitOrder = enum { LSB0, MSB0 } &cxxname="hilti::rt::integer::BitOrder";
public type ByteOrder = enum { Little, Big, Network, Host } &cxxname="hilti::rt::ByteOrder";
public type Side = enum { Left, Right, Both } &cxxname="hilti::rt::bytes::Side";
public type AddressFamily = enum { IPv4, IPv6 } &cxxname="hilti::rt::AddressFamily";
public type RealType = enum { IEEE754_Single, IEEE754_Double } &cxxname="hilti::rt::real::Type";
public type Protocol = enum { TCP, UDP, ICMP } &cxxname="hilti::rt::Protocol";
public type Charset = enum { ASCII, UTF8 } &cxxname="hilti::rt::bytes::Charset";
public type DecodeErrorStrategy = enum { IGNORE, REPLACE, STRICT } &cxxname="hilti::rt::bytes::DecodeErrorStrategy";
public type Captures = vector<bytes>;
public type Profiler = __library_type("hilti::rt::Profiler");

public type MatchState = struct {
    method Captures captures(view<stream> data);
} &cxxname="hilti::rt::regexp::MatchState";

public type StreamStatistics = struct {
    uint<64> num_data_bytes;
    uint<64> num_data_chunks;
    uint<64> num_gap_bytes;
    uint<64> num_gap_chunks;
} &cxxname = "hilti::rt::stream::Statistics";

declare public void print(any obj, bool newline = True) &cxxname="hilti::rt::print" &have_prototype;
declare public void printValues(tuple<*> t, bool newline = True) &cxxname="hilti::rt::printValues" &have_prototype;

declare public void debug(string dbg_stream, any obj) &cxxname="hilti::rt::debug::print" &have_prototype;
declare public void debugIndent(string dbg_stream) &cxxname="hilti::rt::debug::indent" &have_prototype;
declare public void debugDedent(string dbg_stream) &cxxname="hilti::rt::debug::dedent" &have_prototype;

declare public time current_time() &cxxname="hilti::rt::time::current_time" &have_prototype;
declare public time mktime(uint<64> y, uint<64> m, uint<64> d, uint<64> H, uint<64> M, uint<64> S) &cxxname="hilti::rt::time::mktime" &have_prototype;

declare public void abort() &cxxname="hilti::rt::abort_with_backtrace" &have_prototype;

declare public optional<Profiler> profiler_start(string name, optional<uint<64>> size = Null) &cxxname="hilti::rt::profiler::start" &have_prototype;
declare public void profiler_stop(optional<Profiler> p, optional<uint<64>> size = Null) &cxxname="hilti::rt::profiler::stop" &have_prototype;

# Base type for all exceptions.
public type Exception = exception &cxxname="hilti::rt::Exception";

# Helper type referring to any C++-side exception.
public type SystemException = [exception : Exception] &cxxname="std::exception";

# Base type for all exception generated by the runtime system. Catching
# this allows to continue after operations triggering runtime errors.
public type RuntimeError = [exception : Exception] &cxxname="hilti::rt::RuntimeError";

# Base class for exceptions which can be recovered.
public type RecoverableFailure = [exception : Exception] &cxxname="hilti::rt::RecoverableFailure";

# Exception raised when attempting to extracting data from a gap.
public type MissingData = [exception : Exception] &cxxname="hilti::rt::MissingData";

# Returns the message associated with an exception.
declare public string exception_what(SystemException excpt) &cxxname="hilti::rt::exception::what" &have_prototype;
declare public string exception_what(RecoverableFailure excpt) &cxxname="hilti::rt::exception::what" &have_prototype;

# Returns the location associated with an exception.
declare public string exception_where(SystemException excpt) &cxxname="hilti::rt::exception::where" &have_prototype;
declare public string exception_where(RecoverableFailure excpt) &cxxname="hilti::rt::exception::where" &have_prototype;
}
