![]() |
Spicy
|
#include <plugin.h>
Public Types | |
template<typename Result , typename... Args> | |
using | Hook = std::optional< std::function< Result(Args...)> > |
Public Attributes | |
std::string | component |
int | order = 0 |
hilti::rt::filesystem::path | extension |
std::vector< hilti::rt::filesystem::path > | cxx_includes |
Hook< std::vector< hilti::rt::filesystem::path >, std::shared_ptr< hilti::Context > > | library_paths |
Hook< Result< Node >, std::istream &, hilti::rt::filesystem::path > | parse |
Hook< std::optional< Ctor >, Ctor, const Type &, bitmask< CoercionStyle > > | coerce_ctor |
Hook< std::optional< Type >, Type, const Type &, bitmask< CoercionStyle > > | coerce_type |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_build_scopes |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_normalize |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_coerce |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_resolve |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_validate_pre |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_validate_post |
Hook< bool, const Node &, hilti::printer::Stream & > | ast_print |
Hook< bool, std::shared_ptr< hilti::Context >, Node *, Unit * > | ast_transform |
Compiler plugin that implements AST-to-AST translation through a set of passes.
The HILTI compiler itself is the one plugin that's always available. On top of that, further plugins may implement passes as needed to preprocess an AST before it gets to the HILTI plugin. That way, an external plugin can implement support for new language using HILTI as its codegen backend by (1) reading its representation into an AST using its own set of nodes (which may include reusing existing HILTI AST nodes where convenient), (2) implementing the resolution passes to fully resolve that AST (reusing HILTI passes internally where convenient), and (3) finally transforming that AST into a pure HILTI AST consisting only of the HILT nodes.
A plugin implements a set of hook methods that get called by the compilation process at the appropriate times. All hooks should be stateless, apart from changing the AST as appropriate.
using hilti::Plugin::Hook = std::optional<std::function<Result(Args...)> > |
Helper template to define the type of hook methods.
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_build_scopes |
Hook called to build the scopes in a module's AST.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may modify the AST |
arg3 | current unit being compiled |
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_coerce |
Hook called to apply type coersions to the AST.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may modify the AST |
arg3 | current unit being compiled |
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_normalize |
Hook called to prepare an AST before any further stages execute.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may modify the AST |
arg3 | current unit being compiled |
Hook<bool, const Node&, hilti::printer::Stream&> hilti::Plugin::ast_print |
Hook called to print an AST back as source code. The hook gets to choose if it wants to print the node itself, or fall back to the default printer.
arg1 | root of AST to print |
arg2 | stream to print to |
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_resolve |
Hook called to resolve unknown types and other entities.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may modify the AST |
arg3 | current unit being compiled |
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_transform |
Hook called to replace AST nodes of one language (plugin) with nodes of another coming further down in the pipeline.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may modify the AST |
arg3 | current unit being compiled |
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_validate_post |
Hook called to validate correctness of an AST once fully resolved. Any errors must be reported by setting the nodes' error information.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may not modify the AST |
arg3 | current unit being compiled |
Hook<bool, std::shared_ptr<hilti::Context>, Node*, Unit*> hilti::Plugin::ast_validate_pre |
Hook called to validate correctness of an AST before resolving starts (to the degree it can at that time). Any errors must be reported by setting the nodes' error information.
arg1 | compiler context that's in use |
arg2 | root node of AST; the hook may not modify the AST |
arg3 | current unit being compiled |
Hook called to perform coercion of a Ctor
into another of a given target type.
If the plugin knows how to handle the coercion, the hook returns a new Ctor
that's now of the target type.
arg1 | compiler context that's in use |
arg2 | ctor that needs coercion |
arg3 | target type for ctor |
arg4 | coercion style to use |
Hook called to approved coercion of an expression into a different type.
If the plugin knows it can handle the coercion, it returns the resulting coerced Type
. If so, it must then also provide an apply_coercions
hook that will later be called to perform the actual coercion during code generation.
arg1 | compiler context that's in use |
arg2 | type that needs coercion |
arg3 | target type for coercion |
arg4 | coercion style to use |
std::string hilti::Plugin::component |
Name of the plugin.
std::vector<hilti::rt::filesystem::path> hilti::Plugin::cxx_includes |
Additional C++ include files that the plugin needs to have added to generated C++ code.
hilti::rt::filesystem::path hilti::Plugin::extension |
Extension for source files that the plugin handles. Must include the leading .
.
Hook<std::vector<hilti::rt::filesystem::path>, std::shared_ptr<hilti::Context> > hilti::Plugin::library_paths |
Hook called to retrieve paths to search when importing modules that this plugin handles.
arg1 | compiler context that's in use |
int hilti::Plugin::order = 0 |
Plugins will be executed in numerical order, with lower order numbers executing first.
Hook called to parse input file that this plugin handles.
arg1 | compiler context that's in use #param arg2 input stream to parse |
arg3 | file associated with the input stream |