Merge remote-tracking branch 'origin/topic/robin/bump-spicy-raw-pointers'

* origin/topic/robin/bump-spicy-raw-pointers:
  Bump Spicy to latest version reworking AST memory management.
This commit is contained in:
Robin Sommer 2024-03-16 11:14:12 +01:00
commit c6193658a2
No known key found for this signature in database
GPG key ID: 6BEDA4DA6B8B23E3
5 changed files with 63 additions and 66 deletions

@ -1 +1 @@
Subproject commit 173dd7741e52bd32cc6be0962aae40eff0140a3a Subproject commit 7b38bd27fff703f69659b750e3b89ed500340d7c

View file

@ -263,7 +263,7 @@ std::vector<std::pair<TypeInfo, hilti::ID>> Driver::exportedTypes() const {
return result; return result;
} }
void Driver::hookNewASTPreCompilation(const hilti::Plugin& plugin, const std::shared_ptr<hilti::ASTRoot>& root) { void Driver::hookNewASTPreCompilation(const hilti::Plugin& plugin, hilti::ASTRoot* root) {
auto v = VisitorTypes(this, _glue.get(), false); auto v = VisitorTypes(this, _glue.get(), false);
hilti::visitor::visit(v, root, ".spicy"); hilti::visitor::visit(v, root, ".spicy");
@ -281,7 +281,7 @@ void Driver::hookNewASTPreCompilation(const hilti::Plugin& plugin, const std::sh
} }
} }
bool Driver::hookNewASTPostCompilation(const hilti::Plugin& plugin, const std::shared_ptr<hilti::ASTRoot>& root) { bool Driver::hookNewASTPostCompilation(const hilti::Plugin& plugin, hilti::ASTRoot* root) {
if ( plugin.component != "Spicy" ) if ( plugin.component != "Spicy" )
return false; return false;
@ -305,9 +305,7 @@ bool Driver::hookNewASTPostCompilation(const hilti::Plugin& plugin, const std::s
return true; return true;
} }
hilti::Result<hilti::Nothing> Driver::hookCompilationFinished(const std::shared_ptr<hilti::ASTRoot>& root) { hilti::Result<hilti::Nothing> Driver::hookCompilationFinished(hilti::ASTRoot* root) { return _error; }
return _error;
}
void Driver::hookInitRuntime() { ::spicy::rt::init(); } void Driver::hookInitRuntime() { ::spicy::rt::init(); }

View file

@ -31,9 +31,9 @@ namespace zeek::spicy {
class GlueCompiler; class GlueCompiler;
struct TypeInfo { struct TypeInfo {
hilti::ID id; /**< fully-qualified name of the type */ hilti::ID id; /**< fully-qualified name of the type */
hilti::QualifiedTypePtr type; /**< the type itself */ hilti::QualifiedType* type = nullptr; /**< the type itself */
hilti::declaration::Linkage linkage; /**< linkage of of the type's declaration */ hilti::declaration::Linkage linkage; /**< linkage of of the type's declaration */
bool is_resolved = false; /**< true if we are far enough in processing that the type has been fully resolved */ bool is_resolved = false; /**< true if we are far enough in processing that the type has been fully resolved */
hilti::ID module_id; /**< name of module type is defined in */ hilti::ID module_id; /**< name of module type is defined in */
hilti::rt::filesystem::path module_path; /**< path of module that type is defined in */ hilti::rt::filesystem::path module_path; /**< path of module that type is defined in */
@ -175,13 +175,13 @@ protected:
virtual void hookNewType(const TypeInfo& ti) {} virtual void hookNewType(const TypeInfo& ti) {}
/** Overridden from HILTI driver. */ /** Overridden from HILTI driver. */
void hookNewASTPreCompilation(const hilti::Plugin& plugin, const std::shared_ptr<hilti::ASTRoot>& root) override; void hookNewASTPreCompilation(const hilti::Plugin& plugin, hilti::ASTRoot* root) override;
/** Overridden from HILTI driver. */ /** Overridden from HILTI driver. */
bool hookNewASTPostCompilation(const hilti::Plugin& plugin, const std::shared_ptr<hilti::ASTRoot>& root) override; bool hookNewASTPostCompilation(const hilti::Plugin& plugin, hilti::ASTRoot* root) override;
/** Overridden from HILTI driver. */ /** Overridden from HILTI driver. */
hilti::Result<hilti::Nothing> hookCompilationFinished(const std::shared_ptr<hilti::ASTRoot>& root) override; hilti::Result<hilti::Nothing> hookCompilationFinished(hilti::ASTRoot* root) override;
/** Overridden from HILTI driver. */ /** Overridden from HILTI driver. */
void hookInitRuntime() override; void hookInitRuntime() override;

View file

@ -8,14 +8,14 @@
#include <hilti/ast/all.h> #include <hilti/ast/all.h>
#include <hilti/ast/builder/all.h> #include <hilti/ast/builder/all.h>
#include <hilti/ast/builder/builder.h>
#include <hilti/ast/visitor.h>
#include <hilti/base/preprocessor.h> #include <hilti/base/preprocessor.h>
#include <hilti/base/util.h> #include <hilti/base/util.h>
#include <hilti/compiler/unit.h> #include <hilti/compiler/unit.h>
#include <spicy/ast/visitor.h> #include <spicy/ast/visitor.h>
#include "ast/builder/builder.h"
#include "ast/visitor.h"
#include "config.h" #include "config.h"
#include "zeek/spicy/port-range.h" #include "zeek/spicy/port-range.h"
@ -131,7 +131,7 @@ static std::string extract_string(const std::string& chunk, size_t* i) {
return str; return str;
} }
static hilti::UnqualifiedTypePtr extract_type(Builder* builder, const std::string& chunk, size_t* i) { static hilti::UnqualifiedType* extract_type(Builder* builder, const std::string& chunk, size_t* i) {
eat_spaces(chunk, i); eat_spaces(chunk, i);
// We currently only parse Spicy types that can appear in parameters of // We currently only parse Spicy types that can appear in parameters of
@ -147,7 +147,7 @@ static hilti::UnqualifiedTypePtr extract_type(Builder* builder, const std::strin
throw ParseError("mismatching type"); throw ParseError("mismatching type");
} }
static hilti::type::function::ParameterPtr extract_parameter(Builder* builder, const std::string& chunk, size_t* i) { static hilti::type::function::Parameter* extract_parameter(Builder* builder, const std::string& chunk, size_t* i) {
eat_spaces(chunk, i); eat_spaces(chunk, i);
auto id = extract_id(chunk, i); auto id = extract_id(chunk, i);
@ -839,7 +839,7 @@ glue::Event GlueCompiler::parseEvent(const std::string& chunk) {
if ( ! looking_at(chunk, i, ")") ) { if ( ! looking_at(chunk, i, ")") ) {
while ( true ) { while ( true ) {
auto param = extract_parameter(builder(), chunk, &i); auto param = extract_parameter(builder(), chunk, &i);
ev.parameters.push_back(std::move(param)); ev.parameters.push_back(param);
if ( looking_at(chunk, i, ")") ) if ( looking_at(chunk, i, ")") )
break; break;
@ -970,10 +970,10 @@ bool GlueCompiler::compile() {
auto init_module = context()->newModule(builder(), hilti::ID("spicy_init"), ".spicy"); auto init_module = context()->newModule(builder(), hilti::ID("spicy_init"), ".spicy");
auto import_ = builder()->import(hilti::ID("zeek_rt"), ".hlt"); auto import_ = builder()->import(hilti::ID("zeek_rt"), ".hlt");
init_module->add(context(), std::move(import_)); init_module->add(context(), import_);
import_ = builder()->import(hilti::ID("hilti"), ".hlt"); import_ = builder()->import(hilti::ID("hilti"), ".hlt");
init_module->add(context(), std::move(import_)); init_module->add(context(), import_);
auto preinit_body = Builder(context()); auto preinit_body = Builder(context());
@ -1028,7 +1028,7 @@ bool GlueCompiler::compile() {
{builder()->stringMutable(a.name.str()), builder()->id(protocol), {builder()->stringMutable(a.name.str()), builder()->id(protocol),
builder()->vector( builder()->vector(
hilti::util::transform(a.ports, hilti::util::transform(a.ports,
[this](const auto& p) { [this](const auto& p) -> hilti::Expression* {
return builder()->call("zeek_rt::make_port_range", return builder()->call("zeek_rt::make_port_range",
{builder()->port(p.begin), {builder()->port(p.begin),
builder()->port(p.end)}); builder()->port(p.end)});
@ -1101,10 +1101,10 @@ bool GlueCompiler::compile() {
for ( auto&& [id, m] : _spicy_modules ) { for ( auto&& [id, m] : _spicy_modules ) {
// Import runtime module. // Import runtime module.
auto import_ = builder()->import(hilti::ID("zeek_rt"), ".hlt"); auto import_ = builder()->import(hilti::ID("zeek_rt"), ".hlt");
m->spicy_module->add(context(), std::move(import_)); m->spicy_module->add(context(), import_);
import_ = builder()->import(hilti::ID("hilti"), ".hlt"); import_ = builder()->import(hilti::ID("hilti"), ".hlt");
m->spicy_module->add(context(), std::move(import_)); m->spicy_module->add(context(), import_);
// Create a vector of unique parent paths from all EVTs files going into this module. // Create a vector of unique parent paths from all EVTs files going into this module.
auto search_dirs = hilti::util::transform(m->evts, [](auto p) { return p.parent_path(); }); auto search_dirs = hilti::util::transform(m->evts, [](auto p) { return p.parent_path(); });
@ -1114,7 +1114,7 @@ bool GlueCompiler::compile() {
for ( const auto& [module, scope] : _imports ) { for ( const auto& [module, scope] : _imports ) {
auto import_ = builder()->declarationImportedModule(module, std::string(".spicy"), scope); auto import_ = builder()->declarationImportedModule(module, std::string(".spicy"), scope);
import_->as<hilti::declaration::ImportedModule>()->setSearchDirectories(search_dirs_vec); import_->as<hilti::declaration::ImportedModule>()->setSearchDirectories(search_dirs_vec);
m->spicy_module->add(context(), std::move(import_)); m->spicy_module->add(context(), import_);
} }
if ( auto rc = _driver->addInput(m->spicy_module->uid()); ! rc ) { if ( auto rc = _driver->addInput(m->spicy_module->uid()); ! rc ) {
@ -1132,7 +1132,7 @@ bool GlueCompiler::compile() {
builder()->qualifiedType(builder()->typeVoid(), hilti::Constness::Const), {}, builder()->qualifiedType(builder()->typeVoid(), hilti::Constness::Const), {},
preinit_body.block(), hilti::type::function::Flavor::Standard, preinit_body.block(), hilti::type::function::Flavor::Standard,
hilti::declaration::Linkage::PreInit); hilti::declaration::Linkage::PreInit);
init_module->add(context(), std::move(preinit_function)); init_module->add(context(), preinit_function);
} }
if ( auto rc = _driver->addInput(init_module->uid()); ! rc ) { if ( auto rc = _driver->addInput(init_module->uid()); ! rc ) {
@ -1227,8 +1227,8 @@ private:
bool _catch_exception; bool _catch_exception;
}; };
static hilti::Result<hilti::ExpressionPtr> parseArgument(Builder* builder, const std::string& expression, static hilti::Result<hilti::Expression*> parseArgument(Builder* builder, const std::string& expression,
bool catch_exception, const hilti::Meta& meta) { bool catch_exception, const hilti::Meta& meta) {
auto expr = ::spicy::builder::parseExpression(builder, expression, meta); auto expr = ::spicy::builder::parseExpression(builder, expression, meta);
if ( ! expr ) if ( ! expr )
return hilti::result::Error(hilti::util::fmt("error parsing event argument expression '%s'", expression)); return hilti::result::Error(hilti::util::fmt("error parsing event argument expression '%s'", expression));
@ -1250,7 +1250,7 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
SPICY_DEBUG(hilti::util::fmt("Adding Spicy hook '%s' for event %s", ev->hook, ev->name)); SPICY_DEBUG(hilti::util::fmt("Adding Spicy hook '%s' for event %s", ev->hook, ev->name));
auto import_ = builder()->declarationImportedModule(ev->unit_module_id, ev->unit_module_path); auto import_ = builder()->declarationImportedModule(ev->unit_module_id, ev->unit_module_path);
ev->spicy_module->spicy_module->add(context(), std::move(import_)); ev->spicy_module->spicy_module->add(context(), import_);
// Define Zeek-side event handler. // Define Zeek-side event handler.
auto handler_id = hilti::ID(hilti::util::fmt("__zeek_handler_%s", mangled_event_name)); auto handler_id = hilti::ID(hilti::util::fmt("__zeek_handler_%s", mangled_event_name));
@ -1258,7 +1258,7 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
builder()->global(handler_id, builder()->global(handler_id,
builder()->call("zeek_rt::internal_handler", {builder()->stringMutable(ev->name.str())}), builder()->call("zeek_rt::internal_handler", {builder()->stringMutable(ev->name.str())}),
hilti::declaration::Linkage::Private, meta); hilti::declaration::Linkage::Private, meta);
ev->spicy_module->spicy_module->add(context(), std::move(handler)); ev->spicy_module->spicy_module->add(context(), handler);
// Create the hook body that raises the event. // Create the hook body that raises the event.
auto body = Builder(context()); auto body = Builder(context());
@ -1293,7 +1293,7 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
} }
if ( auto expr = parseArgument(builder(), e.expression, true, meta) ) if ( auto expr = parseArgument(builder(), e.expression, true, meta) )
fmt_args.emplace_back(std::move(*expr)); fmt_args.emplace_back(*expr);
else else
// We'll catch and report this below. // We'll catch and report this below.
fmt_args.emplace_back(builder()->stringLiteral("<error>")); fmt_args.emplace_back(builder()->stringLiteral("<error>"));
@ -1302,7 +1302,7 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
std::vector<std::string> fmt_ctrls(fmt_args.size() - 1, "%s"); std::vector<std::string> fmt_ctrls(fmt_args.size() - 1, "%s");
auto fmt_str = hilti::util::fmt("-> event %%s(%s)", hilti::util::join(fmt_ctrls, ", ")); auto fmt_str = hilti::util::fmt("-> event %%s(%s)", hilti::util::join(fmt_ctrls, ", "));
auto msg = builder()->modulo(builder()->stringLiteral(fmt_str), builder()->tuple(fmt_args)); auto msg = builder()->modulo(builder()->stringLiteral(fmt_str), builder()->tuple(fmt_args));
auto call = builder()->call("zeek_rt::debug", {std::move(msg)}); auto call = builder()->call("zeek_rt::debug", {msg});
body.addExpression(call); body.addExpression(call);
} }
@ -1333,7 +1333,7 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
int i = 0; int i = 0;
for ( const auto& e : ev->expression_accessors ) { for ( const auto& e : ev->expression_accessors ) {
hilti::ExpressionPtr val; hilti::Expression* val = nullptr;
if ( e.expression == "$conn" ) if ( e.expression == "$conn" )
val = builder()->call("zeek_rt::current_conn", {}, meta); val = builder()->call("zeek_rt::current_conn", {}, meta);
@ -1356,7 +1356,7 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
} }
auto ztype = builder()->call("zeek_rt::event_arg_type", {handler_expr, builder()->integer(i)}, meta); auto ztype = builder()->call("zeek_rt::event_arg_type", {handler_expr, builder()->integer(i)}, meta);
val = builder()->call("zeek_rt::to_val", {std::move(*expr), ztype}, meta); val = builder()->call("zeek_rt::to_val", {*expr, ztype}, meta);
} }
body.addMemberCall(builder()->id("args"), "push_back", {val}, meta); body.addMemberCall(builder()->id("args"), "push_back", {val}, meta);
@ -1366,9 +1366,9 @@ bool GlueCompiler::CreateSpicyHook(glue::Event* ev) {
body.addCall("zeek_rt::raise_event", {handler_expr, builder()->move(builder()->id("args"))}, meta); body.addCall("zeek_rt::raise_event", {handler_expr, builder()->move(builder()->id("args"))}, meta);
auto attrs = builder()->attributeSet({builder()->attribute("&priority", builder()->integer(ev->priority))}); auto attrs = builder()->attributeSet({builder()->attribute("&priority", builder()->integer(ev->priority))});
auto unit_hook = builder()->declarationHook(ev->parameters, body.block(), ::spicy::Engine::All, {}, meta); auto unit_hook = builder()->declarationHook(ev->parameters, body.block(), ::spicy::Engine::All, attrs, meta);
auto hook_decl = builder()->declarationUnitHook(ev->hook, unit_hook, meta); auto hook_decl = builder()->declarationUnitHook(ev->hook, unit_hook, meta);
ev->spicy_module->spicy_module->add(context(), hilti::DeclarationPtr(hook_decl)); ev->spicy_module->spicy_module->add(context(), hook_decl);
return true; return true;
} }
@ -1387,13 +1387,13 @@ struct VisitorZeekType : spicy::visitor::PreOrder {
Builder* builder; Builder* builder;
GlueCompiler::ZeekTypeCache* cache; GlueCompiler::ZeekTypeCache* cache;
std::vector<hilti::Result<hilti::ExpressionPtr>> results; std::vector<hilti::Result<hilti::Expression*>> results;
std::set<hilti::ID> zeek_types; std::set<hilti::ID> zeek_types;
std::vector<hilti::ID> ids = {}; std::vector<hilti::ID> ids = {};
// Record the resulting Zeek type for the currently processed type (or an error). // Record the resulting Zeek type for the currently processed type (or an error).
void result(hilti::Result<hilti::ExpressionPtr> r) { results.push_back(std::move(r)); } void result(hilti::Result<hilti::Expression*> r) { results.push_back(std::move(r)); }
// Returns current ID, if any. // Returns current ID, if any.
auto id() const { return ids.empty() ? hilti::ID() : ids.back(); } auto id() const { return ids.empty() ? hilti::ID() : ids.back(); }
@ -1406,8 +1406,8 @@ struct VisitorZeekType : spicy::visitor::PreOrder {
return hilti::util::fmt("%s_%s", prefix, hilti::util::replace(id, "::", "_")); return hilti::util::fmt("%s_%s", prefix, hilti::util::replace(id, "::", "_"));
} }
hilti::Result<hilti::ExpressionPtr> create_record_type(const hilti::ID& ns, const hilti::ID& local, hilti::Result<hilti::Expression*> create_record_type(const hilti::ID& ns, const hilti::ID& local,
const hilti::Expressions& fields) { const hilti::Expressions& fields) {
if ( hilti::logger().isEnabled(ZeekPlugin) ) { if ( hilti::logger().isEnabled(ZeekPlugin) ) {
if ( ! fields.empty() ) { if ( ! fields.empty() ) {
SPICY_DEBUG(hilti::util::fmt("Creating Zeek record type %s::%s with fields:", ns, local)); SPICY_DEBUG(hilti::util::fmt("Creating Zeek record type %s::%s with fields:", ns, local));
@ -1430,17 +1430,17 @@ struct VisitorZeekType : spicy::visitor::PreOrder {
{builder->stringMutable(ns.str()), builder->stringMutable(local.str()), tmp}); {builder->stringMutable(ns.str()), builder->stringMutable(local.str()), tmp});
} }
hilti::ExpressionPtr create_record_field(const hilti::ID& id, const hilti::ExpressionPtr& type, bool optional, hilti::Expression* create_record_field(const hilti::ID& id, hilti::Expression* type, bool optional,
bool log) const { bool log) const {
return builder->call("zeek_rt::create_record_field", return builder->call("zeek_rt::create_record_field",
{builder->stringMutable(id.str()), type, builder->bool_(optional), builder->bool_(log)}); {builder->stringMutable(id.str()), type, builder->bool_(optional), builder->bool_(log)});
} }
hilti::Result<hilti::ExpressionPtr> base_type(const char* tag) { hilti::Result<hilti::Expression*> base_type(const char* tag) {
return builder->call("zeek_rt::create_base_type", {builder->id(tag)}); return builder->call("zeek_rt::create_base_type", {builder->id(tag)});
} }
hilti::Result<hilti::ExpressionPtr> createZeekType(const hilti::QualifiedTypePtr& t, hilti::ID id = {}) { hilti::Result<hilti::Expression*> createZeekType(hilti::QualifiedType* t, hilti::ID id = {}) {
if ( ! id ) if ( ! id )
id = t->type()->typeID(); // may still be unset id = t->type()->typeID(); // may still be unset
@ -1488,7 +1488,7 @@ struct VisitorZeekType : spicy::visitor::PreOrder {
void operator()(hilti::type::Bitfield* t) final { void operator()(hilti::type::Bitfield* t) final {
hilti::Expressions fields; hilti::Expressions fields;
for ( const auto& b : t->bits() ) { for ( auto b : t->bits() ) {
if ( auto ztype = createZeekType(b->itemType()) ) if ( auto ztype = createZeekType(b->itemType()) )
fields.emplace_back(create_record_field(b->id(), *ztype, false, false)); fields.emplace_back(create_record_field(b->id(), *ztype, false, false));
else { else {
@ -1532,23 +1532,22 @@ struct VisitorZeekType : spicy::visitor::PreOrder {
assert(id()); assert(id());
auto labels = hilti::rt::transform(t->labels(), [this](const auto& l) { auto labels = hilti::rt::transform(t->labels(), [this](const auto& l) {
return builder->tuple({builder->stringLiteral(l.get()->id().str()), builder->integer(l.get()->value())}); return builder->tuple({builder->stringLiteral(l->id().str()), builder->integer(l->value())});
}); });
auto tmp = auto tmp = builder->addTmp(tmpName("labels", id()),
builder->addTmp(tmpName("labels", id()), builder->typeVector(
builder->typeVector( builder->qualifiedType(builder->typeTuple(hilti::QualifiedTypes{
builder->qualifiedType(builder->typeTuple( builder->qualifiedType(builder->typeString(),
{builder->qualifiedType(builder->typeString(), hilti::Constness::Const),
hilti::Constness::Const), builder->qualifiedType(builder->typeSignedInteger(64),
builder->qualifiedType(builder->typeSignedInteger(64), hilti::Constness::Const)}),
hilti::Constness::Const)}), hilti::Constness::Const)));
hilti::Constness::Const)));
for ( const auto& l : t->labels() ) for ( const auto& l : t->labels() )
builder->addMemberCall(tmp, "push_back", builder->addMemberCall(tmp, "push_back",
{builder->tuple({builder->stringLiteral(l.get()->id().str()), {builder->tuple(
builder->integer(l.get()->value())})}); {builder->stringLiteral(l->id().str()), builder->integer(l->value())})});
result(builder->call("zeek_rt::create_enum_type", {builder->stringMutable(id().namespace_().str()), result(builder->call("zeek_rt::create_enum_type", {builder->stringMutable(id().namespace_().str()),
builder->stringMutable(id().local().str()), tmp})); builder->stringMutable(id().local().str()), tmp}));
@ -1678,7 +1677,7 @@ struct VisitorZeekType : spicy::visitor::PreOrder {
}; };
} // namespace } // namespace
hilti::Result<hilti::Nothing> GlueCompiler::createZeekType(const hilti::QualifiedTypePtr& t, const hilti::ID& id, hilti::Result<hilti::Nothing> GlueCompiler::createZeekType(hilti::QualifiedType* t, const hilti::ID& id,
Builder* builder, GlueCompiler::ZeekTypeCache* cache) const { Builder* builder, GlueCompiler::ZeekTypeCache* cache) const {
builder->addComment(hilti::util::fmt("Creating Zeek type %s", id)); builder->addComment(hilti::util::fmt("Creating Zeek type %s", id));

View file

@ -101,7 +101,7 @@ struct SpicyModule {
std::set<hilti::rt::filesystem::path> evts; /**< EVT files that refer to this module. */ std::set<hilti::rt::filesystem::path> evts; /**< EVT files that refer to this module. */
// Generated code. // Generated code.
hilti::ModulePtr spicy_module; /**< the ``BroHooks_*.spicy`` module. */ hilti::declaration::Module* spicy_module = nullptr; /**< the ``BroHooks_*.spicy`` module. */
}; };
/** Representation of an event parsed from an EVT file. */ /** Representation of an event parsed from an EVT file. */
@ -119,7 +119,7 @@ struct Event {
// Computed information. // Computed information.
hilti::ID hook; /**< The name of the hook triggering the event. */ hilti::ID hook; /**< The name of the hook triggering the event. */
hilti::ID unit; /**< The fully qualified name of the unit type. */ hilti::ID unit; /**< The fully qualified name of the unit type. */
::spicy::type::UnitPtr unit_type; /**< The Spicy type of referenced unit. */ ::spicy::type::Unit* unit_type = nullptr; /**< The Spicy type of referenced unit. */
hilti::ID unit_module_id; /**< The name of the module the referenced unit is defined in. */ hilti::ID unit_module_id; /**< The name of the module the referenced unit is defined in. */
hilti::rt::filesystem::path unit_module_path; /**< The path of the module that the referenced unit is defined in. */ hilti::rt::filesystem::path unit_module_path; /**< The path of the module that the referenced unit is defined in. */
std::shared_ptr<glue::SpicyModule> std::shared_ptr<glue::SpicyModule>
@ -128,8 +128,8 @@ struct Event {
// TODO: The following aren't set yet. // TODO: The following aren't set yet.
// Code generation. // Code generation.
::spicy::type::unit::item::UnitHookPtr spicy_hook; /**< The generated Spicy hook. */ ::spicy::type::unit::item::UnitHook* spicy_hook = nullptr; /**< The generated Spicy hook. */
std::shared_ptr<hilti::declaration::Function> hilti_raise; /**< The generated HILTI raise() function. */ hilti::declaration::Function* hilti_raise = nullptr; /**< The generated HILTI raise() function. */
std::vector<ExpressionAccessor> expression_accessors; /**< One HILTI function per expression to access the value. */ std::vector<ExpressionAccessor> expression_accessors; /**< One HILTI function per expression to access the value. */
}; };
@ -212,21 +212,21 @@ public:
*/ */
ExportedField exportForField(const hilti::ID& zeek_id, const hilti::ID& field_id) const; ExportedField exportForField(const hilti::ID& zeek_id, const hilti::ID& field_id) const;
using ZeekTypeCache = std::map<hilti::ID, hilti::ExpressionPtr>; using ZeekTypeCache = std::map<hilti::ID, hilti::Expression*>;
/** /**
* Generates code to convert a HILTI type to a corresponding Zeek type at * Generates code to convert a HILTI type to a corresponding Zeek type at
* runtime. The code is added to the given body. * runtime. The code is added to the given body.
*/ */
hilti::Result<hilti::Nothing> createZeekType(const hilti::QualifiedTypePtr& t, const hilti::ID& id, hilti::Result<hilti::Nothing> createZeekType(hilti::QualifiedType* t, const hilti::ID& id,
::spicy::Builder* builder, ZeekTypeCache* cache) const; ::spicy::Builder* builder, ZeekTypeCache* cache) const;
/** Return type for `recordField()`. */ /** Return type for `recordField()`. */
struct RecordField { struct RecordField {
hilti::ID id; /**< name of record field */ hilti::ID id; /**< name of record field */
hilti::QualifiedTypePtr type; /**< Spicy-side type object */ hilti::QualifiedType* type = nullptr; /**< Spicy-side type object */
bool is_optional; /**< true if field is optional */ bool is_optional; /**< true if field is optional */
bool is_anonymous; /**< true if field is annymous */ bool is_anonymous; /**< true if field is annymous */
}; };
/** /**