mirror of
https://github.com/tstack/lnav.git
synced 2024-10-04 00:31:31 +03:00
[prql] use cxx for rust ffi stuff
This commit is contained in:
parent
1025e466a2
commit
2cb227e14f
@ -182,6 +182,7 @@ The following software packages are required to build lnav:
|
||||
- libcurl - The cURL library for downloading files from URLs. Version 7.23.0 or higher is required.
|
||||
- libarchive - The libarchive library for opening archive files, like zip/tgz.
|
||||
- wireshark - The 'tshark' program is used to interpret pcap files.
|
||||
- cargo/rust - The Rust language is used to build the PRQL compiler.
|
||||
|
||||
#### Build
|
||||
|
||||
|
@ -66,6 +66,7 @@ parts:
|
||||
"$SNAPCRAFT_STAGE"/scriptlets/selective-checkout --debug --force-snapshot
|
||||
build-packages:
|
||||
- build-essential
|
||||
- cargo
|
||||
- libarchive-dev
|
||||
- libcurl4-gnutls-dev
|
||||
- libpcre2-dev
|
||||
@ -75,6 +76,7 @@ parts:
|
||||
- zlib1g-dev
|
||||
- libbz2-dev
|
||||
- libgpm-dev
|
||||
- rustc
|
||||
stage-packages:
|
||||
- zlib1g
|
||||
- git-core
|
||||
|
@ -130,7 +130,7 @@ function(bin2c)
|
||||
DEPENDS bin2c "${FILE_TO_LINK}")
|
||||
endfunction(bin2c)
|
||||
|
||||
foreach (FILE_TO_LINK animals.json ansi-palette.json css-color-names.json diseases.json emojis.json xml-entities.json xterm-palette.json help.txt help.md init.sql prelude.prql words.json)
|
||||
foreach (FILE_TO_LINK animals.json ansi-palette.json css-color-names.json diseases.json emojis.json xml-entities.json xterm-palette.json help.txt help.md init.sql words.json)
|
||||
string(REPLACE "." "-" DST_FILE "${FILE_TO_LINK}")
|
||||
add_custom_command(
|
||||
OUTPUT "${DST_FILE}.h" "${DST_FILE}.cc"
|
||||
|
@ -43,6 +43,7 @@ default-formats.cc: $(BIN2C_PATH) $(FORMAT_FILES)
|
||||
$(BIN2C_V)$(BIN2C_PATH) -n lnav_format_json default-formats $(FORMAT_FILES)
|
||||
|
||||
include keymaps/keymaps.am
|
||||
include prql/prql.am
|
||||
include themes/themes.am
|
||||
|
||||
CONFIG_FILES = \
|
||||
@ -54,6 +55,9 @@ CONFIG_FILES = \
|
||||
default-config.cc: $(BIN2C_PATH) $(CONFIG_FILES)
|
||||
$(BIN2C_V)$(BIN2C_PATH) -n lnav_config_json default-config $(CONFIG_FILES)
|
||||
|
||||
prql-modules.cc: $(BIN2C_PATH) $(PRQL_FILES)
|
||||
$(BIN2C_V)$(BIN2C_PATH) -n lnav_prql_modules prql-modules $(PRQL_FILES)
|
||||
|
||||
include scripts/scripts.am
|
||||
|
||||
builtin-scripts.cc: $(BIN2C_PATH) $(BUILTIN_LNAVSCRIPTS)
|
||||
@ -107,7 +111,7 @@ LNAV_BUILT_FILES = \
|
||||
words-json.cc \
|
||||
help-md.cc \
|
||||
init-sql.cc \
|
||||
prelude-prql.cc \
|
||||
prql-modules.cc \
|
||||
time_fmts.cc \
|
||||
xml-entities-json.cc \
|
||||
xterm-palette-json.cc
|
||||
@ -123,7 +127,7 @@ RUST_DEPS_CPPFLAGS = -I$(srcdir)/third-party/prqlc-c -DHAVE_RUST_DEPS=1
|
||||
PRQLC_DIR = third-party/prqlc-c/target
|
||||
RUST_DEPS_LIBS = $(PRQLC_DIR)/release/libprqlc_c.a
|
||||
|
||||
$(RUST_DEPS_LIBS): $(srcdir)/third-party/prqlc-c/src/lib.rs
|
||||
$(RUST_DEPS_LIBS): $(srcdir)/third-party/prqlc-c/src/lib.rs $(srcdir)/third-party/prqlc-c/Cargo.toml
|
||||
mkdir -p $(PRQLC_DIR)
|
||||
env CARGO_TARGET_DIR=third-party/prqlc-c/target $(CARGO_CMD) build --manifest-path \
|
||||
$(srcdir)/third-party/prqlc-c/Cargo.toml --package prqlc-c --release
|
||||
@ -197,6 +201,7 @@ dist_noinst_DATA = \
|
||||
$(BUILTIN_SHSCRIPTS) \
|
||||
$(CONFIG_FILES) \
|
||||
$(FORMAT_FILES) \
|
||||
$(PRQL_FILES) \
|
||||
words.json \
|
||||
xml-entities.json \
|
||||
xterm-palette.json
|
||||
@ -205,6 +210,7 @@ noinst_HEADERS = \
|
||||
third-party/md4c/md4c.h \
|
||||
third-party/prqlc-c/prqlc.h \
|
||||
third-party/prqlc-c/prqlc.hpp \
|
||||
third-party/prqlc-c/prqlc.cxx.hh \
|
||||
third-party/rapidyaml/ryml_all.hpp \
|
||||
all_logs_vtab.hh \
|
||||
archive_manager.hh \
|
||||
@ -300,7 +306,6 @@ noinst_HEADERS = \
|
||||
piper.looper.cfg.hh \
|
||||
plain_text_source.hh \
|
||||
pollable.hh \
|
||||
prelude.prql \
|
||||
pretty_printer.hh \
|
||||
preview_status_source.hh \
|
||||
ptimec.hh \
|
||||
@ -404,6 +409,7 @@ THIRD_PARTY_SRCS = \
|
||||
third-party/doctest-root/doctest/doctest.h \
|
||||
third-party/intervaltree/IntervalTree.h \
|
||||
third-party/md4c/md4c.c \
|
||||
third-party/prqlc-c/prqlc.cxx.cc \
|
||||
third-party/robin_hood/robin_hood.h \
|
||||
third-party/sqlite/ext/dbdump.c \
|
||||
third-party/sqlite/ext/series.c
|
||||
@ -576,7 +582,7 @@ DISTCLEANFILES = \
|
||||
words-json.h \
|
||||
help-md.h \
|
||||
init-sql.h \
|
||||
prelude-prql.h \
|
||||
prql-modules.h \
|
||||
time_fmts.h \
|
||||
xml-entities-json.h \
|
||||
xterm-palette-json.h \
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include "lnav_config.hh"
|
||||
#include "lnav_util.hh"
|
||||
#include "log_format_loader.hh"
|
||||
#include "prelude-prql.h"
|
||||
#include "prql-modules.h"
|
||||
#include "readline_highlighters.hh"
|
||||
#include "service_tags.hh"
|
||||
#include "shlex.hh"
|
||||
@ -56,7 +56,7 @@
|
||||
#include "vtab_module.hh"
|
||||
|
||||
#ifdef HAVE_RUST_DEPS
|
||||
# include "prqlc.hpp"
|
||||
# include "prqlc.cxx.hh"
|
||||
#endif
|
||||
|
||||
using namespace lnav::roles::literals;
|
||||
@ -269,15 +269,17 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
|
||||
#if HAVE_RUST_DEPS
|
||||
auto opts = prqlc::Options{true, "sql.sqlite", true};
|
||||
|
||||
auto full_prql = fmt::format(FMT_STRING("{}\n{}{}"),
|
||||
prelude_prql.to_string_fragment(),
|
||||
sqlite_extension_prql,
|
||||
stmt_str);
|
||||
auto cr = prqlc::compile(full_prql.c_str(), &opts);
|
||||
|
||||
for (size_t lpc = 0; lpc < cr.messages_len; lpc++) {
|
||||
const auto& msg = cr.messages[lpc];
|
||||
auto tree = sqlite_extension_prql;
|
||||
for (const auto& mod : lnav_prql_modules) {
|
||||
tree.emplace_back(prqlc::SourceTreeElement{
|
||||
mod.get_name(),
|
||||
mod.to_string_fragment().to_string(),
|
||||
});
|
||||
}
|
||||
tree.emplace_back(prqlc::SourceTreeElement{"", stmt_str});
|
||||
auto cr = prqlc::compile_tree(tree, opts);
|
||||
|
||||
for (const auto& msg : cr.messages) {
|
||||
if (msg.kind != prqlc::MessageKind::Error) {
|
||||
continue;
|
||||
}
|
||||
@ -287,19 +289,17 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
|
||||
auto um
|
||||
= lnav::console::user_message::error(
|
||||
attr_line_t("unable to compile PRQL: ").append(stmt_al))
|
||||
.with_reason(msg.reason);
|
||||
if (msg.display && *msg.display) {
|
||||
um.with_note(*msg.display);
|
||||
.with_reason((std::string) msg.reason);
|
||||
if (!msg.display.empty()) {
|
||||
um.with_note((std::string) msg.display);
|
||||
}
|
||||
if (msg.hint && *msg.hint) {
|
||||
um.with_help(*msg.hint);
|
||||
for (const auto& hint : msg.hints) {
|
||||
um.with_help(hint.data());
|
||||
break;
|
||||
}
|
||||
return Err(um);
|
||||
}
|
||||
if (cr.output && cr.output[0]) {
|
||||
stmt_str = cr.output;
|
||||
}
|
||||
prqlc::result_destroy(cr);
|
||||
stmt_str = (std::string) cr.output;
|
||||
#else
|
||||
auto um = lnav::console::user_message::error(
|
||||
attr_line_t("PRQL is not supported in this build"));
|
||||
|
17
src/lnav.cc
17
src/lnav.cc
@ -3290,6 +3290,23 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
|
||||
log_info(" %s", file_iter->first.c_str());
|
||||
}
|
||||
|
||||
if (!(lnav_data.ld_flags & LNF_HEADLESS)
|
||||
&& verbosity == verbosity_t::quiet && load_stdin
|
||||
&& lnav_data.ld_active_files.fc_file_names.size() == 1)
|
||||
{
|
||||
rescan_files(true);
|
||||
gather_pipers();
|
||||
rebuild_indexes(ui_clock::now() + 10ms);
|
||||
if (lnav_data.ld_child_pollers.empty()) {
|
||||
if (lnav_data.ld_active_files.fc_files.empty()
|
||||
|| lnav_data.ld_active_files.fc_files[0]->size() < 24)
|
||||
{
|
||||
lnav_data.ld_flags |= LNF_HEADLESS;
|
||||
verbosity = verbosity_t::standard;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lnav_data.ld_flags & LNF_HEADLESS) {
|
||||
std::vector<
|
||||
std::pair<Result<std::string, lnav::console::user_message>,
|
||||
|
@ -256,19 +256,23 @@ install_from_git(const std::string& repo)
|
||||
}
|
||||
|
||||
auto finished_child = std::move(git_cmd).wait_for_child();
|
||||
|
||||
if (!finished_child.was_normal_exit() || finished_child.exit_status() != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ghc::filesystem::is_directory(local_formats_path)
|
||||
|| ghc::filesystem::is_directory(local_configs_path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!ghc::filesystem::is_directory(local_staging_path)) {
|
||||
auto um
|
||||
= lnav::console::user_message::error(
|
||||
attr_line_t("failed to install git repo: ")
|
||||
.append(lnav::roles::file(repo)))
|
||||
.with_reason(
|
||||
attr_line_t("git failed to create the local directory")
|
||||
attr_line_t("git failed to create the local directory ")
|
||||
.append(
|
||||
lnav::roles::file(local_staging_path.string())));
|
||||
lnav::console::print(stderr, um);
|
||||
|
@ -1237,7 +1237,7 @@ logfile_sub_source::rebuild_index(
|
||||
void
|
||||
logfile_sub_source::text_update_marks(vis_bookmarks& bm)
|
||||
{
|
||||
logfile* last_file;
|
||||
logfile* last_file = nullptr;
|
||||
vis_line_t vl;
|
||||
|
||||
bm[&BM_WARNINGS].clear();
|
||||
|
4
src/prql/prql.am
Normal file
4
src/prql/prql.am
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
PRQL_FILES = \
|
||||
$(srcdir)/%reldir%/stats.prql \
|
||||
$()
|
@ -1,5 +1,3 @@
|
||||
let json_each = func input -> s"SELECT * FROM json_each({input})"
|
||||
|
||||
let count_by = func column rel <relation> -> <relation> (
|
||||
rel
|
||||
group {column} (aggregate {total = count this})
|
@ -47,7 +47,7 @@ int sqlite3_series_init(sqlite3* db,
|
||||
const sqlite3_api_routines* pApi);
|
||||
}
|
||||
|
||||
std::string sqlite_extension_prql;
|
||||
rust::Vec<prqlc::SourceTreeElement> sqlite_extension_prql;
|
||||
|
||||
namespace lnav {
|
||||
namespace sql {
|
||||
@ -209,7 +209,16 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
|
||||
}
|
||||
|
||||
if (sqlite_extension_prql.empty()) {
|
||||
phier.to_string(sqlite_extension_prql);
|
||||
require(phier.ph_declarations.empty());
|
||||
for (const auto& mod_pair : phier.ph_modules) {
|
||||
std::string content;
|
||||
|
||||
mod_pair.second.to_string(content);
|
||||
sqlite_extension_prql.emplace_back(prqlc::SourceTreeElement{
|
||||
fmt::format(FMT_STRING("{}.prql"), mod_pair.first),
|
||||
content,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static help_text builtin_funcs[] = {
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "help_text.hh"
|
||||
#include "prqlc.cxx.hh"
|
||||
|
||||
struct FuncDef {
|
||||
const char* zName{nullptr};
|
||||
@ -95,7 +96,7 @@ extern sqlite_registration_func_t sqlite_registration_funcs[];
|
||||
|
||||
int register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs);
|
||||
|
||||
extern std::string sqlite_extension_prql;
|
||||
extern rust::Vec<prqlc::SourceTreeElement> sqlite_extension_prql;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
73
src/third-party/prqlc-c/Cargo.lock
generated
vendored
73
src/third-party/prqlc-c/Cargo.lock
generated
vendored
@ -309,6 +309,16 @@ dependencies = [
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
|
||||
dependencies = [
|
||||
"termcolor",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-eyre"
|
||||
version = "0.6.2"
|
||||
@ -394,6 +404,50 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff4dc7287237dd438b926a81a1a5605dad33d286870e5eee2db17bf2bcd9e92a"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cxxbridge-flags",
|
||||
"cxxbridge-macro",
|
||||
"link-cplusplus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx-build"
|
||||
version = "1.0.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f47c6c8ad7c1a10d3ef0fe3ff6733f4db0d78f08ef0b13121543163ef327058b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"scratch",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-flags"
|
||||
version = "1.0.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "701a1ac7a697e249cdd8dc026d7a7dafbfd0dbcd8bd24ec55889f2bc13dd6287"
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-macro"
|
||||
version = "1.0.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b404f596046b0bb2d903a9c786b875a126261b52b7c3a64bbb66382c41c771df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.10.0"
|
||||
@ -647,6 +701,15 @@ version = "0.2.153"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.13"
|
||||
@ -828,9 +891,9 @@ dependencies = [
|
||||
name = "prqlc-c"
|
||||
version = "0.11.3"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"cxx",
|
||||
"cxx-build",
|
||||
"prqlc",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -942,6 +1005,12 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scratch"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.22"
|
||||
|
6
src/third-party/prqlc-c/Cargo.toml
vendored
6
src/third-party/prqlc-c/Cargo.toml
vendored
@ -20,9 +20,11 @@ test = false
|
||||
doc = false
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.153"
|
||||
prqlc = { git = "https://github.com/PRQL/prql.git" }
|
||||
serde_json = "1.0.114"
|
||||
cxx = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
cxx-build = "1.0"
|
||||
|
||||
[package.metadata.release]
|
||||
tag-name = "{{version}}"
|
||||
|
891
src/third-party/prqlc-c/prqlc.cxx.cc
vendored
Normal file
891
src/third-party/prqlc-c/prqlc.cxx.cc
vendored
Normal file
@ -0,0 +1,891 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <new>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace rust {
|
||||
inline namespace cxxbridge1 {
|
||||
// #include "rust/cxx.h"
|
||||
|
||||
#ifndef CXXBRIDGE1_PANIC
|
||||
#define CXXBRIDGE1_PANIC
|
||||
template <typename Exception>
|
||||
void panic [[noreturn]] (const char *msg);
|
||||
#endif // CXXBRIDGE1_PANIC
|
||||
|
||||
struct unsafe_bitcopy_t;
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
class impl;
|
||||
} // namespace
|
||||
|
||||
class Opaque;
|
||||
|
||||
template <typename T>
|
||||
::std::size_t size_of();
|
||||
template <typename T>
|
||||
::std::size_t align_of();
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_STRING
|
||||
#define CXXBRIDGE1_RUST_STRING
|
||||
class String final {
|
||||
public:
|
||||
String() noexcept;
|
||||
String(const String &) noexcept;
|
||||
String(String &&) noexcept;
|
||||
~String() noexcept;
|
||||
|
||||
String(const std::string &);
|
||||
String(const char *);
|
||||
String(const char *, std::size_t);
|
||||
String(const char16_t *);
|
||||
String(const char16_t *, std::size_t);
|
||||
|
||||
static String lossy(const std::string &) noexcept;
|
||||
static String lossy(const char *) noexcept;
|
||||
static String lossy(const char *, std::size_t) noexcept;
|
||||
static String lossy(const char16_t *) noexcept;
|
||||
static String lossy(const char16_t *, std::size_t) noexcept;
|
||||
|
||||
String &operator=(const String &) &noexcept;
|
||||
String &operator=(String &&) &noexcept;
|
||||
|
||||
explicit operator std::string() const;
|
||||
|
||||
const char *data() const noexcept;
|
||||
std::size_t size() const noexcept;
|
||||
std::size_t length() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
const char *c_str() noexcept;
|
||||
|
||||
std::size_t capacity() const noexcept;
|
||||
void reserve(size_t new_cap) noexcept;
|
||||
|
||||
using iterator = char *;
|
||||
iterator begin() noexcept;
|
||||
iterator end() noexcept;
|
||||
|
||||
using const_iterator = const char *;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const_iterator cbegin() const noexcept;
|
||||
const_iterator cend() const noexcept;
|
||||
|
||||
bool operator==(const String &) const noexcept;
|
||||
bool operator!=(const String &) const noexcept;
|
||||
bool operator<(const String &) const noexcept;
|
||||
bool operator<=(const String &) const noexcept;
|
||||
bool operator>(const String &) const noexcept;
|
||||
bool operator>=(const String &) const noexcept;
|
||||
|
||||
void swap(String &) noexcept;
|
||||
|
||||
String(unsafe_bitcopy_t, const String &) noexcept;
|
||||
|
||||
private:
|
||||
struct lossy_t;
|
||||
String(lossy_t, const char *, std::size_t) noexcept;
|
||||
String(lossy_t, const char16_t *, std::size_t) noexcept;
|
||||
friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); }
|
||||
|
||||
std::array<std::uintptr_t, 3> repr;
|
||||
};
|
||||
#endif // CXXBRIDGE1_RUST_STRING
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_SLICE
|
||||
#define CXXBRIDGE1_RUST_SLICE
|
||||
namespace detail {
|
||||
template <bool>
|
||||
struct copy_assignable_if {};
|
||||
|
||||
template <>
|
||||
struct copy_assignable_if<false> {
|
||||
copy_assignable_if() noexcept = default;
|
||||
copy_assignable_if(const copy_assignable_if &) noexcept = default;
|
||||
copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete;
|
||||
copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
class Slice final
|
||||
: private detail::copy_assignable_if<std::is_const<T>::value> {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
Slice() noexcept;
|
||||
Slice(T *, std::size_t count) noexcept;
|
||||
|
||||
Slice &operator=(const Slice<T> &) &noexcept = default;
|
||||
Slice &operator=(Slice<T> &&) &noexcept = default;
|
||||
|
||||
T *data() const noexcept;
|
||||
std::size_t size() const noexcept;
|
||||
std::size_t length() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
T &operator[](std::size_t n) const noexcept;
|
||||
T &at(std::size_t n) const;
|
||||
T &front() const noexcept;
|
||||
T &back() const noexcept;
|
||||
|
||||
Slice(const Slice<T> &) noexcept = default;
|
||||
~Slice() noexcept = default;
|
||||
|
||||
class iterator;
|
||||
iterator begin() const noexcept;
|
||||
iterator end() const noexcept;
|
||||
|
||||
void swap(Slice &) noexcept;
|
||||
|
||||
private:
|
||||
class uninit;
|
||||
Slice(uninit) noexcept;
|
||||
friend impl<Slice>;
|
||||
friend void sliceInit(void *, const void *, std::size_t) noexcept;
|
||||
friend void *slicePtr(const void *) noexcept;
|
||||
friend std::size_t sliceLen(const void *) noexcept;
|
||||
|
||||
std::array<std::uintptr_t, 2> repr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Slice<T>::iterator final {
|
||||
public:
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = typename std::add_pointer<T>::type;
|
||||
using reference = typename std::add_lvalue_reference<T>::type;
|
||||
|
||||
reference operator*() const noexcept;
|
||||
pointer operator->() const noexcept;
|
||||
reference operator[](difference_type) const noexcept;
|
||||
|
||||
iterator &operator++() noexcept;
|
||||
iterator operator++(int) noexcept;
|
||||
iterator &operator--() noexcept;
|
||||
iterator operator--(int) noexcept;
|
||||
|
||||
iterator &operator+=(difference_type) noexcept;
|
||||
iterator &operator-=(difference_type) noexcept;
|
||||
iterator operator+(difference_type) const noexcept;
|
||||
iterator operator-(difference_type) const noexcept;
|
||||
difference_type operator-(const iterator &) const noexcept;
|
||||
|
||||
bool operator==(const iterator &) const noexcept;
|
||||
bool operator!=(const iterator &) const noexcept;
|
||||
bool operator<(const iterator &) const noexcept;
|
||||
bool operator<=(const iterator &) const noexcept;
|
||||
bool operator>(const iterator &) const noexcept;
|
||||
bool operator>=(const iterator &) const noexcept;
|
||||
|
||||
private:
|
||||
friend class Slice;
|
||||
void *pos;
|
||||
std::size_t stride;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Slice<T>::Slice() noexcept {
|
||||
sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Slice<T>::Slice(T *s, std::size_t count) noexcept {
|
||||
assert(s != nullptr || count == 0);
|
||||
sliceInit(this,
|
||||
s == nullptr && count == 0
|
||||
? reinterpret_cast<void *>(align_of<T>())
|
||||
: const_cast<typename std::remove_const<T>::type *>(s),
|
||||
count);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *Slice<T>::data() const noexcept {
|
||||
return reinterpret_cast<T *>(slicePtr(this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t Slice<T>::size() const noexcept {
|
||||
return sliceLen(this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t Slice<T>::length() const noexcept {
|
||||
return this->size();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::empty() const noexcept {
|
||||
return this->size() == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::operator[](std::size_t n) const noexcept {
|
||||
assert(n < this->size());
|
||||
auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n;
|
||||
return *reinterpret_cast<T *>(ptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::at(std::size_t n) const {
|
||||
if (n >= this->size()) {
|
||||
panic<std::out_of_range>("rust::Slice index out of range");
|
||||
}
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::front() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::back() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[this->size() - 1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::reference
|
||||
Slice<T>::iterator::operator*() const noexcept {
|
||||
return *static_cast<T *>(this->pos);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::pointer
|
||||
Slice<T>::iterator::operator->() const noexcept {
|
||||
return static_cast<T *>(this->pos);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::reference Slice<T>::iterator::operator[](
|
||||
typename Slice<T>::iterator::difference_type n) const noexcept {
|
||||
auto ptr = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return *reinterpret_cast<T *>(ptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) + this->stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept {
|
||||
auto ret = iterator(*this);
|
||||
this->pos = static_cast<char *>(this->pos) + this->stride;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) - this->stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept {
|
||||
auto ret = iterator(*this);
|
||||
this->pos = static_cast<char *>(this->pos) - this->stride;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator+=(
|
||||
typename Slice<T>::iterator::difference_type n) noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator-=(
|
||||
typename Slice<T>::iterator::difference_type n) noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) - this->stride * n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator+(
|
||||
typename Slice<T>::iterator::difference_type n) const noexcept {
|
||||
auto ret = iterator(*this);
|
||||
ret.pos = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator-(
|
||||
typename Slice<T>::iterator::difference_type n) const noexcept {
|
||||
auto ret = iterator(*this);
|
||||
ret.pos = static_cast<char *>(this->pos) - this->stride * n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::difference_type
|
||||
Slice<T>::iterator::operator-(const iterator &other) const noexcept {
|
||||
auto diff = std::distance(static_cast<char *>(other.pos),
|
||||
static_cast<char *>(this->pos));
|
||||
return diff / static_cast<typename Slice<T>::iterator::difference_type>(
|
||||
this->stride);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator==(const iterator &other) const noexcept {
|
||||
return this->pos == other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept {
|
||||
return this->pos != other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator<(const iterator &other) const noexcept {
|
||||
return this->pos < other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept {
|
||||
return this->pos <= other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator>(const iterator &other) const noexcept {
|
||||
return this->pos > other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept {
|
||||
return this->pos >= other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::begin() const noexcept {
|
||||
iterator it;
|
||||
it.pos = slicePtr(this);
|
||||
it.stride = size_of<T>();
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::end() const noexcept {
|
||||
iterator it = this->begin();
|
||||
it.pos = static_cast<char *>(it.pos) + it.stride * this->size();
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Slice<T>::swap(Slice &rhs) noexcept {
|
||||
std::swap(*this, rhs);
|
||||
}
|
||||
#endif // CXXBRIDGE1_RUST_SLICE
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_BITCOPY_T
|
||||
#define CXXBRIDGE1_RUST_BITCOPY_T
|
||||
struct unsafe_bitcopy_t final {
|
||||
explicit unsafe_bitcopy_t() = default;
|
||||
};
|
||||
#endif // CXXBRIDGE1_RUST_BITCOPY_T
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_VEC
|
||||
#define CXXBRIDGE1_RUST_VEC
|
||||
template <typename T>
|
||||
class Vec final {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
Vec() noexcept;
|
||||
Vec(std::initializer_list<T>);
|
||||
Vec(const Vec &);
|
||||
Vec(Vec &&) noexcept;
|
||||
~Vec() noexcept;
|
||||
|
||||
Vec &operator=(Vec &&) &noexcept;
|
||||
Vec &operator=(const Vec &) &;
|
||||
|
||||
std::size_t size() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
const T *data() const noexcept;
|
||||
T *data() noexcept;
|
||||
std::size_t capacity() const noexcept;
|
||||
|
||||
const T &operator[](std::size_t n) const noexcept;
|
||||
const T &at(std::size_t n) const;
|
||||
const T &front() const noexcept;
|
||||
const T &back() const noexcept;
|
||||
|
||||
T &operator[](std::size_t n) noexcept;
|
||||
T &at(std::size_t n);
|
||||
T &front() noexcept;
|
||||
T &back() noexcept;
|
||||
|
||||
void reserve(std::size_t new_cap);
|
||||
void push_back(const T &value);
|
||||
void push_back(T &&value);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&...args);
|
||||
void truncate(std::size_t len);
|
||||
void clear();
|
||||
|
||||
using iterator = typename Slice<T>::iterator;
|
||||
iterator begin() noexcept;
|
||||
iterator end() noexcept;
|
||||
|
||||
using const_iterator = typename Slice<const T>::iterator;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const_iterator cbegin() const noexcept;
|
||||
const_iterator cend() const noexcept;
|
||||
|
||||
void swap(Vec &) noexcept;
|
||||
|
||||
Vec(unsafe_bitcopy_t, const Vec &) noexcept;
|
||||
|
||||
private:
|
||||
void reserve_total(std::size_t new_cap) noexcept;
|
||||
void set_len(std::size_t len) noexcept;
|
||||
void drop() noexcept;
|
||||
|
||||
friend void swap(Vec &lhs, Vec &rhs) noexcept { lhs.swap(rhs); }
|
||||
|
||||
std::array<std::uintptr_t, 3> repr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(std::initializer_list<T> init) : Vec{} {
|
||||
this->reserve_total(init.size());
|
||||
std::move(init.begin(), init.end(), std::back_inserter(*this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(const Vec &other) : Vec() {
|
||||
this->reserve_total(other.size());
|
||||
std::copy(other.begin(), other.end(), std::back_inserter(*this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(Vec &&other) noexcept : repr(other.repr) {
|
||||
new (&other) Vec();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::~Vec() noexcept {
|
||||
this->drop();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T> &Vec<T>::operator=(Vec &&other) &noexcept {
|
||||
this->drop();
|
||||
this->repr = other.repr;
|
||||
new (&other) Vec();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T> &Vec<T>::operator=(const Vec &other) & {
|
||||
if (this != &other) {
|
||||
this->drop();
|
||||
new (this) Vec(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Vec<T>::empty() const noexcept {
|
||||
return this->size() == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *Vec<T>::data() noexcept {
|
||||
return const_cast<T *>(const_cast<const Vec<T> *>(this)->data());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::operator[](std::size_t n) const noexcept {
|
||||
assert(n < this->size());
|
||||
auto data = reinterpret_cast<const char *>(this->data());
|
||||
return *reinterpret_cast<const T *>(data + n * size_of<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::at(std::size_t n) const {
|
||||
if (n >= this->size()) {
|
||||
panic<std::out_of_range>("rust::Vec index out of range");
|
||||
}
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::front() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::back() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[this->size() - 1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::operator[](std::size_t n) noexcept {
|
||||
assert(n < this->size());
|
||||
auto data = reinterpret_cast<char *>(this->data());
|
||||
return *reinterpret_cast<T *>(data + n * size_of<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::at(std::size_t n) {
|
||||
if (n >= this->size()) {
|
||||
panic<std::out_of_range>("rust::Vec index out of range");
|
||||
}
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::front() noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::back() noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[this->size() - 1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::reserve(std::size_t new_cap) {
|
||||
this->reserve_total(new_cap);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::push_back(const T &value) {
|
||||
this->emplace_back(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::push_back(T &&value) {
|
||||
this->emplace_back(std::move(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename... Args>
|
||||
void Vec<T>::emplace_back(Args &&...args) {
|
||||
auto size = this->size();
|
||||
this->reserve_total(size + 1);
|
||||
::new (reinterpret_cast<T *>(reinterpret_cast<char *>(this->data()) +
|
||||
size * size_of<T>()))
|
||||
T(std::forward<Args>(args)...);
|
||||
this->set_len(size + 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::clear() {
|
||||
this->truncate(0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator Vec<T>::begin() noexcept {
|
||||
return Slice<T>(this->data(), this->size()).begin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator Vec<T>::end() noexcept {
|
||||
return Slice<T>(this->data(), this->size()).end();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::begin() const noexcept {
|
||||
return this->cbegin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::end() const noexcept {
|
||||
return this->cend();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::cbegin() const noexcept {
|
||||
return Slice<const T>(this->data(), this->size()).begin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::cend() const noexcept {
|
||||
return Slice<const T>(this->data(), this->size()).end();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::swap(Vec &rhs) noexcept {
|
||||
using std::swap;
|
||||
swap(this->repr, rhs.repr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) {}
|
||||
#endif // CXXBRIDGE1_RUST_VEC
|
||||
|
||||
#ifndef CXXBRIDGE1_IS_COMPLETE
|
||||
#define CXXBRIDGE1_IS_COMPLETE
|
||||
namespace detail {
|
||||
namespace {
|
||||
template <typename T, typename = std::size_t>
|
||||
struct is_complete : std::false_type {};
|
||||
template <typename T>
|
||||
struct is_complete<T, decltype(sizeof(T))> : std::true_type {};
|
||||
} // namespace
|
||||
} // namespace detail
|
||||
#endif // CXXBRIDGE1_IS_COMPLETE
|
||||
|
||||
#ifndef CXXBRIDGE1_LAYOUT
|
||||
#define CXXBRIDGE1_LAYOUT
|
||||
class layout {
|
||||
template <typename T>
|
||||
friend std::size_t size_of();
|
||||
template <typename T>
|
||||
friend std::size_t align_of();
|
||||
template <typename T>
|
||||
static typename std::enable_if<std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_size_of() {
|
||||
return T::layout::size();
|
||||
}
|
||||
template <typename T>
|
||||
static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_size_of() {
|
||||
return sizeof(T);
|
||||
}
|
||||
template <typename T>
|
||||
static
|
||||
typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
|
||||
size_of() {
|
||||
return do_size_of<T>();
|
||||
}
|
||||
template <typename T>
|
||||
static typename std::enable_if<std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_align_of() {
|
||||
return T::layout::align();
|
||||
}
|
||||
template <typename T>
|
||||
static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_align_of() {
|
||||
return alignof(T);
|
||||
}
|
||||
template <typename T>
|
||||
static
|
||||
typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
|
||||
align_of() {
|
||||
return do_align_of<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::size_t size_of() {
|
||||
return layout::size_of<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t align_of() {
|
||||
return layout::align_of<T>();
|
||||
}
|
||||
#endif // CXXBRIDGE1_LAYOUT
|
||||
|
||||
namespace detail {
|
||||
template <typename T, typename = void *>
|
||||
struct operator_new {
|
||||
void *operator()(::std::size_t sz) { return ::operator new(sz); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct operator_new<T, decltype(T::operator new(sizeof(T)))> {
|
||||
void *operator()(::std::size_t sz) { return T::operator new(sz); }
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
union MaybeUninit {
|
||||
T value;
|
||||
void *operator new(::std::size_t sz) { return detail::operator_new<T>{}(sz); }
|
||||
MaybeUninit() {}
|
||||
~MaybeUninit() {}
|
||||
};
|
||||
} // namespace cxxbridge1
|
||||
} // namespace rust
|
||||
|
||||
namespace prqlc {
|
||||
struct Options;
|
||||
struct SourceTreeElement;
|
||||
enum class MessageKind : ::std::uint8_t;
|
||||
struct Message;
|
||||
struct CompileResult2;
|
||||
}
|
||||
|
||||
namespace prqlc {
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$Options
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$Options
|
||||
struct Options final {
|
||||
bool format;
|
||||
::rust::String target;
|
||||
bool signature_comment;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$Options
|
||||
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$SourceTreeElement
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$SourceTreeElement
|
||||
struct SourceTreeElement final {
|
||||
::rust::String path;
|
||||
::rust::String content;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$SourceTreeElement
|
||||
|
||||
#ifndef CXXBRIDGE1_ENUM_prqlc$MessageKind
|
||||
#define CXXBRIDGE1_ENUM_prqlc$MessageKind
|
||||
enum class MessageKind : ::std::uint8_t {
|
||||
Error = 0,
|
||||
Warning = 1,
|
||||
Lint = 2,
|
||||
};
|
||||
#endif // CXXBRIDGE1_ENUM_prqlc$MessageKind
|
||||
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$Message
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$Message
|
||||
struct Message final {
|
||||
::prqlc::MessageKind kind;
|
||||
::rust::String code;
|
||||
::rust::String reason;
|
||||
::rust::Vec<::rust::String> hints;
|
||||
::rust::String display;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$Message
|
||||
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$CompileResult2
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$CompileResult2
|
||||
struct CompileResult2 final {
|
||||
::rust::String output;
|
||||
::rust::Vec<::prqlc::Message> messages;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$CompileResult2
|
||||
|
||||
extern "C" {
|
||||
void prqlc$cxxbridge1$compile_tree(::rust::Vec<::prqlc::SourceTreeElement> const &tree, ::prqlc::Options const &options, ::prqlc::CompileResult2 *return$) noexcept;
|
||||
} // extern "C"
|
||||
|
||||
::prqlc::CompileResult2 compile_tree(::rust::Vec<::prqlc::SourceTreeElement> const &tree, ::prqlc::Options const &options) noexcept {
|
||||
::rust::MaybeUninit<::prqlc::CompileResult2> return$;
|
||||
prqlc$cxxbridge1$compile_tree(tree, options, &return$.value);
|
||||
return ::std::move(return$.value);
|
||||
}
|
||||
} // namespace prqlc
|
||||
|
||||
extern "C" {
|
||||
void cxxbridge1$rust_vec$prqlc$Message$new(::rust::Vec<::prqlc::Message> const *ptr) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$Message$drop(::rust::Vec<::prqlc::Message> *ptr) noexcept;
|
||||
::std::size_t cxxbridge1$rust_vec$prqlc$Message$len(::rust::Vec<::prqlc::Message> const *ptr) noexcept;
|
||||
::std::size_t cxxbridge1$rust_vec$prqlc$Message$capacity(::rust::Vec<::prqlc::Message> const *ptr) noexcept;
|
||||
::prqlc::Message const *cxxbridge1$rust_vec$prqlc$Message$data(::rust::Vec<::prqlc::Message> const *ptr) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$Message$reserve_total(::rust::Vec<::prqlc::Message> *ptr, ::std::size_t new_cap) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$Message$set_len(::rust::Vec<::prqlc::Message> *ptr, ::std::size_t len) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$Message$truncate(::rust::Vec<::prqlc::Message> *ptr, ::std::size_t len) noexcept;
|
||||
|
||||
void cxxbridge1$rust_vec$prqlc$SourceTreeElement$new(::rust::Vec<::prqlc::SourceTreeElement> const *ptr) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$SourceTreeElement$drop(::rust::Vec<::prqlc::SourceTreeElement> *ptr) noexcept;
|
||||
::std::size_t cxxbridge1$rust_vec$prqlc$SourceTreeElement$len(::rust::Vec<::prqlc::SourceTreeElement> const *ptr) noexcept;
|
||||
::std::size_t cxxbridge1$rust_vec$prqlc$SourceTreeElement$capacity(::rust::Vec<::prqlc::SourceTreeElement> const *ptr) noexcept;
|
||||
::prqlc::SourceTreeElement const *cxxbridge1$rust_vec$prqlc$SourceTreeElement$data(::rust::Vec<::prqlc::SourceTreeElement> const *ptr) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$SourceTreeElement$reserve_total(::rust::Vec<::prqlc::SourceTreeElement> *ptr, ::std::size_t new_cap) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$SourceTreeElement$set_len(::rust::Vec<::prqlc::SourceTreeElement> *ptr, ::std::size_t len) noexcept;
|
||||
void cxxbridge1$rust_vec$prqlc$SourceTreeElement$truncate(::rust::Vec<::prqlc::SourceTreeElement> *ptr, ::std::size_t len) noexcept;
|
||||
} // extern "C"
|
||||
|
||||
namespace rust {
|
||||
inline namespace cxxbridge1 {
|
||||
template <>
|
||||
Vec<::prqlc::Message>::Vec() noexcept {
|
||||
cxxbridge1$rust_vec$prqlc$Message$new(this);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::Message>::drop() noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$drop(this);
|
||||
}
|
||||
template <>
|
||||
::std::size_t Vec<::prqlc::Message>::size() const noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$len(this);
|
||||
}
|
||||
template <>
|
||||
::std::size_t Vec<::prqlc::Message>::capacity() const noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$capacity(this);
|
||||
}
|
||||
template <>
|
||||
::prqlc::Message const *Vec<::prqlc::Message>::data() const noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$data(this);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::Message>::reserve_total(::std::size_t new_cap) noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$reserve_total(this, new_cap);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::Message>::set_len(::std::size_t len) noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$set_len(this, len);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::Message>::truncate(::std::size_t len) {
|
||||
return cxxbridge1$rust_vec$prqlc$Message$truncate(this, len);
|
||||
}
|
||||
template <>
|
||||
Vec<::prqlc::SourceTreeElement>::Vec() noexcept {
|
||||
cxxbridge1$rust_vec$prqlc$SourceTreeElement$new(this);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::SourceTreeElement>::drop() noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$drop(this);
|
||||
}
|
||||
template <>
|
||||
::std::size_t Vec<::prqlc::SourceTreeElement>::size() const noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$len(this);
|
||||
}
|
||||
template <>
|
||||
::std::size_t Vec<::prqlc::SourceTreeElement>::capacity() const noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$capacity(this);
|
||||
}
|
||||
template <>
|
||||
::prqlc::SourceTreeElement const *Vec<::prqlc::SourceTreeElement>::data() const noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$data(this);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::SourceTreeElement>::reserve_total(::std::size_t new_cap) noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$reserve_total(this, new_cap);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::SourceTreeElement>::set_len(::std::size_t len) noexcept {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$set_len(this, len);
|
||||
}
|
||||
template <>
|
||||
void Vec<::prqlc::SourceTreeElement>::truncate(::std::size_t len) {
|
||||
return cxxbridge1$rust_vec$prqlc$SourceTreeElement$truncate(this, len);
|
||||
}
|
||||
} // namespace cxxbridge1
|
||||
} // namespace rust
|
775
src/third-party/prqlc-c/prqlc.cxx.hh
vendored
Normal file
775
src/third-party/prqlc-c/prqlc.cxx.hh
vendored
Normal file
@ -0,0 +1,775 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <new>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace rust {
|
||||
inline namespace cxxbridge1 {
|
||||
// #include "rust/cxx.h"
|
||||
|
||||
#ifndef CXXBRIDGE1_PANIC
|
||||
#define CXXBRIDGE1_PANIC
|
||||
template <typename Exception>
|
||||
void panic [[noreturn]] (const char *msg);
|
||||
#endif // CXXBRIDGE1_PANIC
|
||||
|
||||
struct unsafe_bitcopy_t;
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
class impl;
|
||||
} // namespace
|
||||
|
||||
class Opaque;
|
||||
|
||||
template <typename T>
|
||||
::std::size_t size_of();
|
||||
template <typename T>
|
||||
::std::size_t align_of();
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_STRING
|
||||
#define CXXBRIDGE1_RUST_STRING
|
||||
class String final {
|
||||
public:
|
||||
String() noexcept;
|
||||
String(const String &) noexcept;
|
||||
String(String &&) noexcept;
|
||||
~String() noexcept;
|
||||
|
||||
String(const std::string &);
|
||||
String(const char *);
|
||||
String(const char *, std::size_t);
|
||||
String(const char16_t *);
|
||||
String(const char16_t *, std::size_t);
|
||||
|
||||
static String lossy(const std::string &) noexcept;
|
||||
static String lossy(const char *) noexcept;
|
||||
static String lossy(const char *, std::size_t) noexcept;
|
||||
static String lossy(const char16_t *) noexcept;
|
||||
static String lossy(const char16_t *, std::size_t) noexcept;
|
||||
|
||||
String &operator=(const String &) &noexcept;
|
||||
String &operator=(String &&) &noexcept;
|
||||
|
||||
explicit operator std::string() const;
|
||||
|
||||
const char *data() const noexcept;
|
||||
std::size_t size() const noexcept;
|
||||
std::size_t length() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
const char *c_str() noexcept;
|
||||
|
||||
std::size_t capacity() const noexcept;
|
||||
void reserve(size_t new_cap) noexcept;
|
||||
|
||||
using iterator = char *;
|
||||
iterator begin() noexcept;
|
||||
iterator end() noexcept;
|
||||
|
||||
using const_iterator = const char *;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const_iterator cbegin() const noexcept;
|
||||
const_iterator cend() const noexcept;
|
||||
|
||||
bool operator==(const String &) const noexcept;
|
||||
bool operator!=(const String &) const noexcept;
|
||||
bool operator<(const String &) const noexcept;
|
||||
bool operator<=(const String &) const noexcept;
|
||||
bool operator>(const String &) const noexcept;
|
||||
bool operator>=(const String &) const noexcept;
|
||||
|
||||
void swap(String &) noexcept;
|
||||
|
||||
String(unsafe_bitcopy_t, const String &) noexcept;
|
||||
|
||||
private:
|
||||
struct lossy_t;
|
||||
String(lossy_t, const char *, std::size_t) noexcept;
|
||||
String(lossy_t, const char16_t *, std::size_t) noexcept;
|
||||
friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); }
|
||||
|
||||
std::array<std::uintptr_t, 3> repr;
|
||||
};
|
||||
#endif // CXXBRIDGE1_RUST_STRING
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_SLICE
|
||||
#define CXXBRIDGE1_RUST_SLICE
|
||||
namespace detail {
|
||||
template <bool>
|
||||
struct copy_assignable_if {};
|
||||
|
||||
template <>
|
||||
struct copy_assignable_if<false> {
|
||||
copy_assignable_if() noexcept = default;
|
||||
copy_assignable_if(const copy_assignable_if &) noexcept = default;
|
||||
copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete;
|
||||
copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
class Slice final
|
||||
: private detail::copy_assignable_if<std::is_const<T>::value> {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
Slice() noexcept;
|
||||
Slice(T *, std::size_t count) noexcept;
|
||||
|
||||
Slice &operator=(const Slice<T> &) &noexcept = default;
|
||||
Slice &operator=(Slice<T> &&) &noexcept = default;
|
||||
|
||||
T *data() const noexcept;
|
||||
std::size_t size() const noexcept;
|
||||
std::size_t length() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
T &operator[](std::size_t n) const noexcept;
|
||||
T &at(std::size_t n) const;
|
||||
T &front() const noexcept;
|
||||
T &back() const noexcept;
|
||||
|
||||
Slice(const Slice<T> &) noexcept = default;
|
||||
~Slice() noexcept = default;
|
||||
|
||||
class iterator;
|
||||
iterator begin() const noexcept;
|
||||
iterator end() const noexcept;
|
||||
|
||||
void swap(Slice &) noexcept;
|
||||
|
||||
private:
|
||||
class uninit;
|
||||
Slice(uninit) noexcept;
|
||||
friend impl<Slice>;
|
||||
friend void sliceInit(void *, const void *, std::size_t) noexcept;
|
||||
friend void *slicePtr(const void *) noexcept;
|
||||
friend std::size_t sliceLen(const void *) noexcept;
|
||||
|
||||
std::array<std::uintptr_t, 2> repr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Slice<T>::iterator final {
|
||||
public:
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = typename std::add_pointer<T>::type;
|
||||
using reference = typename std::add_lvalue_reference<T>::type;
|
||||
|
||||
reference operator*() const noexcept;
|
||||
pointer operator->() const noexcept;
|
||||
reference operator[](difference_type) const noexcept;
|
||||
|
||||
iterator &operator++() noexcept;
|
||||
iterator operator++(int) noexcept;
|
||||
iterator &operator--() noexcept;
|
||||
iterator operator--(int) noexcept;
|
||||
|
||||
iterator &operator+=(difference_type) noexcept;
|
||||
iterator &operator-=(difference_type) noexcept;
|
||||
iterator operator+(difference_type) const noexcept;
|
||||
iterator operator-(difference_type) const noexcept;
|
||||
difference_type operator-(const iterator &) const noexcept;
|
||||
|
||||
bool operator==(const iterator &) const noexcept;
|
||||
bool operator!=(const iterator &) const noexcept;
|
||||
bool operator<(const iterator &) const noexcept;
|
||||
bool operator<=(const iterator &) const noexcept;
|
||||
bool operator>(const iterator &) const noexcept;
|
||||
bool operator>=(const iterator &) const noexcept;
|
||||
|
||||
private:
|
||||
friend class Slice;
|
||||
void *pos;
|
||||
std::size_t stride;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Slice<T>::Slice() noexcept {
|
||||
sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Slice<T>::Slice(T *s, std::size_t count) noexcept {
|
||||
assert(s != nullptr || count == 0);
|
||||
sliceInit(this,
|
||||
s == nullptr && count == 0
|
||||
? reinterpret_cast<void *>(align_of<T>())
|
||||
: const_cast<typename std::remove_const<T>::type *>(s),
|
||||
count);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *Slice<T>::data() const noexcept {
|
||||
return reinterpret_cast<T *>(slicePtr(this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t Slice<T>::size() const noexcept {
|
||||
return sliceLen(this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t Slice<T>::length() const noexcept {
|
||||
return this->size();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::empty() const noexcept {
|
||||
return this->size() == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::operator[](std::size_t n) const noexcept {
|
||||
assert(n < this->size());
|
||||
auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n;
|
||||
return *reinterpret_cast<T *>(ptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::at(std::size_t n) const {
|
||||
if (n >= this->size()) {
|
||||
panic<std::out_of_range>("rust::Slice index out of range");
|
||||
}
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::front() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Slice<T>::back() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[this->size() - 1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::reference
|
||||
Slice<T>::iterator::operator*() const noexcept {
|
||||
return *static_cast<T *>(this->pos);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::pointer
|
||||
Slice<T>::iterator::operator->() const noexcept {
|
||||
return static_cast<T *>(this->pos);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::reference Slice<T>::iterator::operator[](
|
||||
typename Slice<T>::iterator::difference_type n) const noexcept {
|
||||
auto ptr = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return *reinterpret_cast<T *>(ptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) + this->stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept {
|
||||
auto ret = iterator(*this);
|
||||
this->pos = static_cast<char *>(this->pos) + this->stride;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) - this->stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept {
|
||||
auto ret = iterator(*this);
|
||||
this->pos = static_cast<char *>(this->pos) - this->stride;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator+=(
|
||||
typename Slice<T>::iterator::difference_type n) noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator &Slice<T>::iterator::operator-=(
|
||||
typename Slice<T>::iterator::difference_type n) noexcept {
|
||||
this->pos = static_cast<char *>(this->pos) - this->stride * n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator+(
|
||||
typename Slice<T>::iterator::difference_type n) const noexcept {
|
||||
auto ret = iterator(*this);
|
||||
ret.pos = static_cast<char *>(this->pos) + this->stride * n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::iterator::operator-(
|
||||
typename Slice<T>::iterator::difference_type n) const noexcept {
|
||||
auto ret = iterator(*this);
|
||||
ret.pos = static_cast<char *>(this->pos) - this->stride * n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator::difference_type
|
||||
Slice<T>::iterator::operator-(const iterator &other) const noexcept {
|
||||
auto diff = std::distance(static_cast<char *>(other.pos),
|
||||
static_cast<char *>(this->pos));
|
||||
return diff / static_cast<typename Slice<T>::iterator::difference_type>(
|
||||
this->stride);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator==(const iterator &other) const noexcept {
|
||||
return this->pos == other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept {
|
||||
return this->pos != other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator<(const iterator &other) const noexcept {
|
||||
return this->pos < other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept {
|
||||
return this->pos <= other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator>(const iterator &other) const noexcept {
|
||||
return this->pos > other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept {
|
||||
return this->pos >= other.pos;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::begin() const noexcept {
|
||||
iterator it;
|
||||
it.pos = slicePtr(this);
|
||||
it.stride = size_of<T>();
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Slice<T>::iterator Slice<T>::end() const noexcept {
|
||||
iterator it = this->begin();
|
||||
it.pos = static_cast<char *>(it.pos) + it.stride * this->size();
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Slice<T>::swap(Slice &rhs) noexcept {
|
||||
std::swap(*this, rhs);
|
||||
}
|
||||
#endif // CXXBRIDGE1_RUST_SLICE
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_BITCOPY_T
|
||||
#define CXXBRIDGE1_RUST_BITCOPY_T
|
||||
struct unsafe_bitcopy_t final {
|
||||
explicit unsafe_bitcopy_t() = default;
|
||||
};
|
||||
#endif // CXXBRIDGE1_RUST_BITCOPY_T
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_VEC
|
||||
#define CXXBRIDGE1_RUST_VEC
|
||||
template <typename T>
|
||||
class Vec final {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
Vec() noexcept;
|
||||
Vec(std::initializer_list<T>);
|
||||
Vec(const Vec &);
|
||||
Vec(Vec &&) noexcept;
|
||||
~Vec() noexcept;
|
||||
|
||||
Vec &operator=(Vec &&) &noexcept;
|
||||
Vec &operator=(const Vec &) &;
|
||||
|
||||
std::size_t size() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
const T *data() const noexcept;
|
||||
T *data() noexcept;
|
||||
std::size_t capacity() const noexcept;
|
||||
|
||||
const T &operator[](std::size_t n) const noexcept;
|
||||
const T &at(std::size_t n) const;
|
||||
const T &front() const noexcept;
|
||||
const T &back() const noexcept;
|
||||
|
||||
T &operator[](std::size_t n) noexcept;
|
||||
T &at(std::size_t n);
|
||||
T &front() noexcept;
|
||||
T &back() noexcept;
|
||||
|
||||
void reserve(std::size_t new_cap);
|
||||
void push_back(const T &value);
|
||||
void push_back(T &&value);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&...args);
|
||||
void truncate(std::size_t len);
|
||||
void clear();
|
||||
|
||||
using iterator = typename Slice<T>::iterator;
|
||||
iterator begin() noexcept;
|
||||
iterator end() noexcept;
|
||||
|
||||
using const_iterator = typename Slice<const T>::iterator;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const_iterator cbegin() const noexcept;
|
||||
const_iterator cend() const noexcept;
|
||||
|
||||
void swap(Vec &) noexcept;
|
||||
|
||||
Vec(unsafe_bitcopy_t, const Vec &) noexcept;
|
||||
|
||||
private:
|
||||
void reserve_total(std::size_t new_cap) noexcept;
|
||||
void set_len(std::size_t len) noexcept;
|
||||
void drop() noexcept;
|
||||
|
||||
friend void swap(Vec &lhs, Vec &rhs) noexcept { lhs.swap(rhs); }
|
||||
|
||||
std::array<std::uintptr_t, 3> repr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(std::initializer_list<T> init) : Vec{} {
|
||||
this->reserve_total(init.size());
|
||||
std::move(init.begin(), init.end(), std::back_inserter(*this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(const Vec &other) : Vec() {
|
||||
this->reserve_total(other.size());
|
||||
std::copy(other.begin(), other.end(), std::back_inserter(*this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(Vec &&other) noexcept : repr(other.repr) {
|
||||
new (&other) Vec();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::~Vec() noexcept {
|
||||
this->drop();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T> &Vec<T>::operator=(Vec &&other) &noexcept {
|
||||
this->drop();
|
||||
this->repr = other.repr;
|
||||
new (&other) Vec();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T> &Vec<T>::operator=(const Vec &other) & {
|
||||
if (this != &other) {
|
||||
this->drop();
|
||||
new (this) Vec(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Vec<T>::empty() const noexcept {
|
||||
return this->size() == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *Vec<T>::data() noexcept {
|
||||
return const_cast<T *>(const_cast<const Vec<T> *>(this)->data());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::operator[](std::size_t n) const noexcept {
|
||||
assert(n < this->size());
|
||||
auto data = reinterpret_cast<const char *>(this->data());
|
||||
return *reinterpret_cast<const T *>(data + n * size_of<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::at(std::size_t n) const {
|
||||
if (n >= this->size()) {
|
||||
panic<std::out_of_range>("rust::Vec index out of range");
|
||||
}
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::front() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &Vec<T>::back() const noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[this->size() - 1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::operator[](std::size_t n) noexcept {
|
||||
assert(n < this->size());
|
||||
auto data = reinterpret_cast<char *>(this->data());
|
||||
return *reinterpret_cast<T *>(data + n * size_of<T>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::at(std::size_t n) {
|
||||
if (n >= this->size()) {
|
||||
panic<std::out_of_range>("rust::Vec index out of range");
|
||||
}
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::front() noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &Vec<T>::back() noexcept {
|
||||
assert(!this->empty());
|
||||
return (*this)[this->size() - 1];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::reserve(std::size_t new_cap) {
|
||||
this->reserve_total(new_cap);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::push_back(const T &value) {
|
||||
this->emplace_back(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::push_back(T &&value) {
|
||||
this->emplace_back(std::move(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename... Args>
|
||||
void Vec<T>::emplace_back(Args &&...args) {
|
||||
auto size = this->size();
|
||||
this->reserve_total(size + 1);
|
||||
::new (reinterpret_cast<T *>(reinterpret_cast<char *>(this->data()) +
|
||||
size * size_of<T>()))
|
||||
T(std::forward<Args>(args)...);
|
||||
this->set_len(size + 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::clear() {
|
||||
this->truncate(0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator Vec<T>::begin() noexcept {
|
||||
return Slice<T>(this->data(), this->size()).begin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::iterator Vec<T>::end() noexcept {
|
||||
return Slice<T>(this->data(), this->size()).end();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::begin() const noexcept {
|
||||
return this->cbegin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::end() const noexcept {
|
||||
return this->cend();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::cbegin() const noexcept {
|
||||
return Slice<const T>(this->data(), this->size()).begin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename Vec<T>::const_iterator Vec<T>::cend() const noexcept {
|
||||
return Slice<const T>(this->data(), this->size()).end();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vec<T>::swap(Vec &rhs) noexcept {
|
||||
using std::swap;
|
||||
swap(this->repr, rhs.repr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Vec<T>::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) {}
|
||||
#endif // CXXBRIDGE1_RUST_VEC
|
||||
|
||||
#ifndef CXXBRIDGE1_IS_COMPLETE
|
||||
#define CXXBRIDGE1_IS_COMPLETE
|
||||
namespace detail {
|
||||
namespace {
|
||||
template <typename T, typename = std::size_t>
|
||||
struct is_complete : std::false_type {};
|
||||
template <typename T>
|
||||
struct is_complete<T, decltype(sizeof(T))> : std::true_type {};
|
||||
} // namespace
|
||||
} // namespace detail
|
||||
#endif // CXXBRIDGE1_IS_COMPLETE
|
||||
|
||||
#ifndef CXXBRIDGE1_LAYOUT
|
||||
#define CXXBRIDGE1_LAYOUT
|
||||
class layout {
|
||||
template <typename T>
|
||||
friend std::size_t size_of();
|
||||
template <typename T>
|
||||
friend std::size_t align_of();
|
||||
template <typename T>
|
||||
static typename std::enable_if<std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_size_of() {
|
||||
return T::layout::size();
|
||||
}
|
||||
template <typename T>
|
||||
static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_size_of() {
|
||||
return sizeof(T);
|
||||
}
|
||||
template <typename T>
|
||||
static
|
||||
typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
|
||||
size_of() {
|
||||
return do_size_of<T>();
|
||||
}
|
||||
template <typename T>
|
||||
static typename std::enable_if<std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_align_of() {
|
||||
return T::layout::align();
|
||||
}
|
||||
template <typename T>
|
||||
static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
|
||||
std::size_t>::type
|
||||
do_align_of() {
|
||||
return alignof(T);
|
||||
}
|
||||
template <typename T>
|
||||
static
|
||||
typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
|
||||
align_of() {
|
||||
return do_align_of<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::size_t size_of() {
|
||||
return layout::size_of<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t align_of() {
|
||||
return layout::align_of<T>();
|
||||
}
|
||||
#endif // CXXBRIDGE1_LAYOUT
|
||||
} // namespace cxxbridge1
|
||||
} // namespace rust
|
||||
|
||||
namespace prqlc {
|
||||
struct Options;
|
||||
struct SourceTreeElement;
|
||||
enum class MessageKind : ::std::uint8_t;
|
||||
struct Message;
|
||||
struct CompileResult2;
|
||||
}
|
||||
|
||||
namespace prqlc {
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$Options
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$Options
|
||||
struct Options final {
|
||||
bool format;
|
||||
::rust::String target;
|
||||
bool signature_comment;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$Options
|
||||
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$SourceTreeElement
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$SourceTreeElement
|
||||
struct SourceTreeElement final {
|
||||
::rust::String path;
|
||||
::rust::String content;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$SourceTreeElement
|
||||
|
||||
#ifndef CXXBRIDGE1_ENUM_prqlc$MessageKind
|
||||
#define CXXBRIDGE1_ENUM_prqlc$MessageKind
|
||||
enum class MessageKind : ::std::uint8_t {
|
||||
Error = 0,
|
||||
Warning = 1,
|
||||
Lint = 2,
|
||||
};
|
||||
#endif // CXXBRIDGE1_ENUM_prqlc$MessageKind
|
||||
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$Message
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$Message
|
||||
struct Message final {
|
||||
::prqlc::MessageKind kind;
|
||||
::rust::String code;
|
||||
::rust::String reason;
|
||||
::rust::Vec<::rust::String> hints;
|
||||
::rust::String display;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$Message
|
||||
|
||||
#ifndef CXXBRIDGE1_STRUCT_prqlc$CompileResult2
|
||||
#define CXXBRIDGE1_STRUCT_prqlc$CompileResult2
|
||||
struct CompileResult2 final {
|
||||
::rust::String output;
|
||||
::rust::Vec<::prqlc::Message> messages;
|
||||
|
||||
using IsRelocatable = ::std::true_type;
|
||||
};
|
||||
#endif // CXXBRIDGE1_STRUCT_prqlc$CompileResult2
|
||||
|
||||
::prqlc::CompileResult2 compile_tree(::rust::Vec<::prqlc::SourceTreeElement> const &tree, ::prqlc::Options const &options) noexcept;
|
||||
} // namespace prqlc
|
424
src/third-party/prqlc-c/src/lib.rs
vendored
424
src/third-party/prqlc-c/src/lib.rs
vendored
@ -1,346 +1,126 @@
|
||||
#![cfg(not(target_family = "wasm"))]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use libc::{c_char, size_t};
|
||||
use prqlc::{ErrorMessage, ErrorMessages};
|
||||
use prqlc::Target;
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::CString;
|
||||
use prqlc::{ErrorMessage, ErrorMessages};
|
||||
use std::panic;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Compile a PRQL string into a SQL string.
|
||||
///
|
||||
/// This is a wrapper for: `prql_to_pl`, `pl_to_rq` and `rq_to_sql` without converting to JSON
|
||||
/// between each of the functions.
|
||||
///
|
||||
/// See `Options` struct for available compilation options.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function assumes zero-terminated input strings.
|
||||
/// Calling code is responsible for freeing memory allocated for `CompileResult`
|
||||
/// by calling `result_destroy`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn compile(
|
||||
prql_query: *const c_char,
|
||||
options: *const Options,
|
||||
) -> CompileResult {
|
||||
let prql_query: String = c_str_to_string(prql_query);
|
||||
#[cxx::bridge(namespace = "prqlc")]
|
||||
mod ffi {
|
||||
struct Options {
|
||||
pub format: bool,
|
||||
pub target: String,
|
||||
pub signature_comment: bool,
|
||||
}
|
||||
|
||||
let options = options.as_ref().map(convert_options).transpose();
|
||||
struct SourceTreeElement {
|
||||
pub path: String,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
let result = options
|
||||
.and_then(|opts| {
|
||||
panic::catch_unwind(|| {
|
||||
Ok(prql_query.as_str())
|
||||
.and_then(prqlc::prql_to_pl)
|
||||
.and_then(prqlc::pl_to_rq)
|
||||
.and_then(|rq| prqlc::rq_to_sql(rq, &opts.unwrap_or_default()))
|
||||
}).map_err(|p| ErrorMessages {
|
||||
inner: vec![ErrorMessage {
|
||||
kind: prqlc::MessageKind::Error,
|
||||
code: None,
|
||||
reason: format!("internal error: {:#?}", p),
|
||||
hints: vec![],
|
||||
span: None,
|
||||
display: None,
|
||||
location: None,
|
||||
}]
|
||||
})?
|
||||
enum MessageKind {
|
||||
Error,
|
||||
Warning,
|
||||
Lint,
|
||||
}
|
||||
|
||||
struct Message {
|
||||
pub kind: MessageKind,
|
||||
pub code: String,
|
||||
pub reason: String,
|
||||
pub hints: Vec<String>,
|
||||
pub display: String,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct CompileResult2 {
|
||||
pub output: String,
|
||||
pub messages: Vec<Message>,
|
||||
}
|
||||
|
||||
extern "Rust" {
|
||||
fn compile_tree(tree: &Vec<SourceTreeElement>, options: &Options) -> CompileResult2;
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&ffi::Options> for prqlc::Options {
|
||||
type Error = ErrorMessages;
|
||||
|
||||
fn try_from(value: &ffi::Options) -> Result<Self, Self::Error> {
|
||||
Ok(prqlc::Options {
|
||||
format: value.format,
|
||||
target: Target::from_str(value.target.as_str()).map_err(prqlc::ErrorMessages::from)?,
|
||||
signature_comment: value.signature_comment,
|
||||
color: false,
|
||||
})
|
||||
.map_err(|e| e.composed(&prql_query.into()));
|
||||
|
||||
result_into_c_str(result)
|
||||
}
|
||||
|
||||
/// Build PL AST from a PRQL string. PL in documented in the
|
||||
/// [prqlc Rust crate](https://docs.rs/prqlc/latest/prqlc/ir/pl).
|
||||
///
|
||||
/// Takes PRQL source buffer and writes PL serialized as JSON to `out` buffer.
|
||||
///
|
||||
/// Returns 0 on success and a negative number -1 on failure.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function assumes zero-terminated input strings.
|
||||
/// Calling code is responsible for freeing memory allocated for `CompileResult`
|
||||
/// by calling `result_destroy`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn prql_to_pl(prql_query: *const c_char) -> CompileResult {
|
||||
let prql_query: String = c_str_to_string(prql_query);
|
||||
|
||||
let result = Ok(prql_query.as_str())
|
||||
.and_then(prqlc::prql_to_pl)
|
||||
.and_then(|x| prqlc::json::from_pl(&x));
|
||||
result_into_c_str(result)
|
||||
}
|
||||
|
||||
/// Finds variable references, validates functions calls, determines frames and converts PL to RQ.
|
||||
/// PL and RQ are documented in the
|
||||
/// [prqlc Rust crate](https://docs.rs/prqlc/latest/prqlc/ast).
|
||||
///
|
||||
/// Takes PL serialized as JSON buffer and writes RQ serialized as JSON to `out` buffer.
|
||||
///
|
||||
/// Returns 0 on success and a negative number -1 on failure.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function assumes zero-terminated input strings.
|
||||
/// Calling code is responsible for freeing memory allocated for `CompileResult`
|
||||
/// by calling `result_destroy`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pl_to_rq(pl_json: *const c_char) -> CompileResult {
|
||||
let pl_json: String = c_str_to_string(pl_json);
|
||||
|
||||
let result = Ok(pl_json.as_str())
|
||||
.and_then(prqlc::json::to_pl)
|
||||
.and_then(prqlc::pl_to_rq)
|
||||
.and_then(|x| prqlc::json::from_rq(&x));
|
||||
result_into_c_str(result)
|
||||
}
|
||||
|
||||
/// Convert RQ AST into an SQL string. RQ is documented in the
|
||||
/// [prqlc Rust crate](https://docs.rs/prqlc/latest/prqlc/ir/rq).
|
||||
///
|
||||
/// Takes RQ serialized as JSON buffer and writes SQL source to `out` buffer.
|
||||
///
|
||||
/// Returns 0 on success and a negative number -1 on failure.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function assumes zero-terminated input strings.
|
||||
/// Calling code is responsible for freeing memory allocated for `CompileResult`
|
||||
/// by calling `result_destroy`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn rq_to_sql(
|
||||
rq_json: *const c_char,
|
||||
options: *const Options,
|
||||
) -> CompileResult {
|
||||
let rq_json: String = c_str_to_string(rq_json);
|
||||
|
||||
let options = options.as_ref().map(convert_options).transpose();
|
||||
|
||||
let result = options.and_then(|options| {
|
||||
Ok(rq_json.as_str())
|
||||
.and_then(prqlc::json::to_rq)
|
||||
.and_then(|x| prqlc::rq_to_sql(x, &options.unwrap_or_default()))
|
||||
});
|
||||
result_into_c_str(result)
|
||||
}
|
||||
|
||||
/// Compilation options
|
||||
#[repr(C)]
|
||||
pub struct Options {
|
||||
/// Pass generated SQL string trough a formatter that splits it
|
||||
/// into multiple lines and prettifies indentation and spacing.
|
||||
///
|
||||
/// Defaults to true.
|
||||
pub format: bool,
|
||||
|
||||
/// Target and dialect to compile to.
|
||||
///
|
||||
/// Defaults to `sql.any`, which uses `target` argument from the query header to determine
|
||||
/// the SQL dialect.
|
||||
pub target: *mut c_char,
|
||||
|
||||
/// Emits the compiler signature as a comment after generated SQL
|
||||
///
|
||||
/// Defaults to true.
|
||||
pub signature_comment: bool,
|
||||
}
|
||||
|
||||
/// Result of compilation.
|
||||
#[repr(C)]
|
||||
pub struct CompileResult {
|
||||
pub output: *const libc::c_char,
|
||||
pub messages: *const Message,
|
||||
pub messages_len: size_t,
|
||||
}
|
||||
|
||||
/// Compile message kind. Currently only Error is implemented.
|
||||
#[repr(C)]
|
||||
pub enum MessageKind {
|
||||
Error,
|
||||
Warning,
|
||||
Lint,
|
||||
}
|
||||
|
||||
/// Compile result message.
|
||||
///
|
||||
/// Calling code is responsible for freeing all memory allocated
|
||||
/// for fields as well as strings.
|
||||
// Make sure to keep in sync with prqlc::ErrorMessage
|
||||
#[repr(C)]
|
||||
pub struct Message {
|
||||
/// Message kind. Currently only Error is implemented.
|
||||
pub kind: MessageKind,
|
||||
/// Machine-readable identifier of the error
|
||||
pub code: *const *const libc::c_char,
|
||||
/// Plain text of the error
|
||||
pub reason: *const libc::c_char,
|
||||
/// A list of suggestions of how to fix the error
|
||||
pub hint: *const *const libc::c_char,
|
||||
/// Character offset of error origin within a source file
|
||||
pub span: *const Span,
|
||||
|
||||
/// Annotated code, containing cause and hints.
|
||||
pub display: *const *const libc::c_char,
|
||||
/// Line and column number of error origin within a source file
|
||||
pub location: *const SourceLocation,
|
||||
}
|
||||
|
||||
/// Identifier of a location in source.
|
||||
/// Contains offsets in terms of chars.
|
||||
// Make sure to keep in sync with prqlc::Span
|
||||
#[repr(C)]
|
||||
pub struct Span {
|
||||
pub start: size_t,
|
||||
pub end: size_t,
|
||||
}
|
||||
|
||||
/// Location within a source file.
|
||||
// Make sure to keep in sync with prqlc::SourceLocation
|
||||
#[repr(C)]
|
||||
pub struct SourceLocation {
|
||||
pub start_line: size_t,
|
||||
pub start_col: size_t,
|
||||
|
||||
pub end_line: size_t,
|
||||
pub end_col: size_t,
|
||||
}
|
||||
|
||||
/// Destroy a `CompileResult` once you are done with it.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function expects to be called exactly once after the call of any the functions
|
||||
/// that return `CompileResult`. No fields should be freed manually.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn result_destroy(res: CompileResult) {
|
||||
// This is required because we are allocating memory for
|
||||
// strings, vectors and options.
|
||||
// For strings and vectors this is required, but options may be
|
||||
// able to live entirely within the struct, instead of the heap.
|
||||
|
||||
for i in 0..res.messages_len {
|
||||
let e = &*res.messages.add(i);
|
||||
|
||||
if !e.code.is_null() {
|
||||
drop(CString::from_raw(*e.code as *mut libc::c_char));
|
||||
drop(Box::from_raw(e.code as *mut *const libc::c_char));
|
||||
}
|
||||
drop(CString::from_raw(e.reason as *mut libc::c_char));
|
||||
if !e.hint.is_null() {
|
||||
drop(CString::from_raw(*e.hint as *mut libc::c_char));
|
||||
drop(Box::from_raw(e.hint as *mut *const libc::c_char));
|
||||
}
|
||||
if !e.span.is_null() {
|
||||
drop(Box::from_raw(e.span as *mut Span));
|
||||
}
|
||||
if !e.display.is_null() {
|
||||
drop(CString::from_raw(*e.display as *mut libc::c_char));
|
||||
drop(Box::from_raw(e.display as *mut *const libc::c_char));
|
||||
}
|
||||
if !e.location.is_null() {
|
||||
drop(Box::from_raw(e.location as *mut SourceLocation));
|
||||
}
|
||||
}
|
||||
drop(Vec::from_raw_parts(
|
||||
res.messages as *mut i8,
|
||||
res.messages_len,
|
||||
res.messages_len,
|
||||
));
|
||||
drop(CString::from_raw(res.output as *mut libc::c_char));
|
||||
}
|
||||
|
||||
unsafe fn result_into_c_str(result: Result<String, ErrorMessages>) -> CompileResult {
|
||||
match result {
|
||||
Ok(output) => CompileResult {
|
||||
output: convert_string(output),
|
||||
messages: ::std::ptr::null_mut(),
|
||||
messages_len: 0,
|
||||
},
|
||||
Err(err) => {
|
||||
let mut errors = Vec::with_capacity(err.inner.len());
|
||||
errors.extend(err.inner.into_iter().map(|e| Message {
|
||||
kind: MessageKind::Error,
|
||||
code: option_to_ptr(e.code.map(convert_string)),
|
||||
reason: convert_string(e.reason),
|
||||
hint: option_to_ptr(if e.hints.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(convert_string(e.hints.join("\n")))
|
||||
}),
|
||||
span: option_to_ptr(e.span.map(convert_span)),
|
||||
display: option_to_ptr(e.display.map(convert_string)),
|
||||
location: option_to_ptr(e.location.map(convert_source_location)),
|
||||
}));
|
||||
CompileResult {
|
||||
output: CString::default().into_raw(),
|
||||
messages_len: errors.len(),
|
||||
messages: errors.leak().as_ptr(),
|
||||
}
|
||||
impl From<prqlc::MessageKind> for ffi::MessageKind {
|
||||
fn from(value: prqlc::MessageKind) -> Self {
|
||||
match value {
|
||||
prqlc::MessageKind::Error => ffi::MessageKind::Error,
|
||||
prqlc::MessageKind::Warning => ffi::MessageKind::Warning,
|
||||
prqlc::MessageKind::Lint => ffi::MessageKind::Lint,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocates the value on the heap and returns a pointer to it.
|
||||
/// If the input is None, it returns null pointer.
|
||||
fn option_to_ptr<T>(o: Option<T>) -> *const T {
|
||||
match o {
|
||||
Some(x) => {
|
||||
let b = Box::new(x);
|
||||
Box::into_raw(b)
|
||||
impl From<ErrorMessage> for ffi::Message {
|
||||
fn from(value: ErrorMessage) -> Self {
|
||||
ffi::Message {
|
||||
kind: value.kind.into(),
|
||||
code: value.code.unwrap_or(String::new()),
|
||||
reason: value.reason,
|
||||
hints: value.hints,
|
||||
display: value.display.unwrap_or(String::new()),
|
||||
}
|
||||
None => ::std::ptr::null(),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_string(x: String) -> *const libc::c_char {
|
||||
CString::new(x).unwrap_or_default().into_raw()
|
||||
}
|
||||
fn compile_tree_int(
|
||||
tree: &Vec<ffi::SourceTreeElement>,
|
||||
options: &ffi::Options,
|
||||
) -> Result<String, ErrorMessages> {
|
||||
let tree = prqlc::SourceTree::new(
|
||||
tree.iter()
|
||||
.map(|ste| (PathBuf::from(ste.path.clone()), ste.content.clone())),
|
||||
None,
|
||||
);
|
||||
|
||||
fn convert_span(x: prqlc::Span) -> Span {
|
||||
Span {
|
||||
start: x.start,
|
||||
end: x.end,
|
||||
}
|
||||
}
|
||||
let options: prqlc::Options = options.try_into()?;
|
||||
|
||||
fn convert_source_location(x: prqlc::SourceLocation) -> SourceLocation {
|
||||
SourceLocation {
|
||||
start_line: x.start.0,
|
||||
start_col: x.start.1,
|
||||
end_line: x.end.0,
|
||||
end_col: x.end.1,
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn c_str_to_string(c_str: *const c_char) -> String {
|
||||
// inefficient, but simple
|
||||
CStr::from_ptr(c_str).to_string_lossy().into_owned()
|
||||
}
|
||||
|
||||
fn convert_options(o: &Options) -> Result<prqlc::Options, prqlc::ErrorMessages> {
|
||||
let target = if !o.target.is_null() {
|
||||
Some(unsafe { c_str_to_string(o.target) })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let target = target
|
||||
.as_deref()
|
||||
.filter(|x| !x.is_empty())
|
||||
.unwrap_or("sql.any");
|
||||
|
||||
let target = Target::from_str(target).map_err(prqlc::ErrorMessages::from)?;
|
||||
|
||||
Ok(prqlc::Options {
|
||||
format: o.format,
|
||||
target,
|
||||
signature_comment: o.signature_comment,
|
||||
// TODO: add support for this
|
||||
color: false,
|
||||
panic::catch_unwind(|| {
|
||||
Ok(prqlc::prql_to_pl_tree(&tree)
|
||||
.and_then(prqlc::pl_to_rq)
|
||||
.map_err(|e: ErrorMessages| ErrorMessages::from(e).composed(&tree))
|
||||
.and_then(|rq| prqlc::rq_to_sql(rq, &options))?)
|
||||
.map_err(|e: ErrorMessages| ErrorMessages::from(e).composed(&tree))
|
||||
})
|
||||
.map_err(|p| {
|
||||
ErrorMessages::from(ErrorMessage {
|
||||
kind: prqlc::MessageKind::Error,
|
||||
code: None,
|
||||
reason: format!("internal error: {:#?}", p),
|
||||
hints: vec![],
|
||||
span: None,
|
||||
display: None,
|
||||
location: None,
|
||||
})
|
||||
})?
|
||||
}
|
||||
|
||||
pub fn compile_tree(
|
||||
tree: &Vec<ffi::SourceTreeElement>,
|
||||
options: &ffi::Options,
|
||||
) -> ffi::CompileResult2 {
|
||||
let mut retval = ffi::CompileResult2::default();
|
||||
|
||||
match compile_tree_int(tree, options) {
|
||||
Ok(output) => retval.output = output,
|
||||
Err(errors) => retval.messages = errors.inner.into_iter().map(|x| x.into()).collect(),
|
||||
}
|
||||
|
||||
retval
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
|
||||
AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
|
||||
|
||||
if HAVE_CARGO
|
||||
RUST_DEPS_CPPFLAGS = -I$(srcdir)/third-party/prqlc-c -DHAVE_RUST_DEPS=1
|
||||
RUST_DEPS_CPPFLAGS = -I$(top_srcdir)/src/third-party/prqlc-c -DHAVE_RUST_DEPS=1
|
||||
PRQLC_DIR = ../src/third-party/prqlc-c/target
|
||||
RUST_DEPS_LIBS = $(PRQLC_DIR)/release/libprqlc_c.a
|
||||
else
|
||||
|
@ -1,10 +1,10 @@
|
||||
[1m[31m✘ error[0m: unable to compile PRQL: [1m[36mfrom[0m db.access_log | [1m[36mtake[0m abc
|
||||
[1m[31mreason[0m: `take` expected int or range, but found this.access_log.abc
|
||||
[36m =[0m [36mnote[0m: Error:
|
||||
╭─[:62:27]
|
||||
│
|
||||
62 │ from db.access_log | take abc
|
||||
│ ─┬─
|
||||
│ ╰─── `take` expected int or range, but found this.access_log.abc
|
||||
────╯
|
||||
╭─[:1:27]
|
||||
│
|
||||
1 │ from db.access_log | take abc
|
||||
│ ─┬─
|
||||
│ ╰─── `take` expected int or range, but found this.access_log.abc
|
||||
───╯
|
||||
|
||||
|
@ -218,6 +218,8 @@ The following software packages are required to build lnav:
|
||||
archive files, like zip/tgz.
|
||||
[33m•[0m wireshark - The [35m'tshark'[0m program is used to interpret
|
||||
pcap files.
|
||||
[33m•[0m cargo/rust - The Rust language is used to build the
|
||||
PRQL compiler.
|
||||
|
||||
[4mBuild[0m
|
||||
|
||||
|
@ -161,6 +161,8 @@ The following software packages are required to build lnav:
|
||||
archive files, like zip/tgz.
|
||||
[33m•[0m wireshark - The [35m'tshark'[0m program is used to interpret
|
||||
pcap files.
|
||||
[33m•[0m cargo/rust - The Rust language is used to build the
|
||||
PRQL compiler.
|
||||
|
||||
[4mBuild[0m
|
||||
|
||||
|
@ -161,6 +161,8 @@ The following software packages are required to build lnav:
|
||||
archive files, like zip/tgz.
|
||||
[33m•[0m wireshark - The [35m'tshark'[0m program is used to interpret
|
||||
pcap files.
|
||||
[33m•[0m cargo/rust - The Rust language is used to build the
|
||||
PRQL compiler.
|
||||
|
||||
[4mBuild[0m
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user