Spicy
Public Types | Public Attributes | List of all members
hilti::Plugin Struct Reference

#include <plugin.h>

Public Types

template<typename Result , typename... Args>
using Hook = 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 >, Context * > library_paths = nullptr
 
Hook< bool, type_unifier::Unifier *, UnqualifiedType * > unify_type = nullptr
 
Hook< Result< declaration::Module * >, hilti::Builder *, std::istream &, const hilti::rt::filesystem::path & > parse
 
Hook< Ctor *, Builder *, Ctor *, QualifiedType *, bitmask< CoercionStyle > > coerce_ctor = nullptr
 
Hook< QualifiedType *, Builder *, QualifiedType *, QualifiedType *, bitmask< CoercionStyle > > coerce_type = nullptr
 
Hook< void, Builder *, ASTRoot * > ast_init = nullptr
 
Hook< bool, Builder *, ASTRoot * > ast_build_scopes = nullptr
 
Hook< bool, Builder *, Node * > ast_resolve = nullptr
 
Hook< bool, Builder *, ASTRoot * > ast_validate_pre = nullptr
 
Hook< bool, Builder *, ASTRoot * > ast_validate_post = nullptr
 
Hook< bool, Node *, printer::Stream & > ast_print = nullptr
 
Hook< bool, const ID &, printer::Stream & > ast_print_id = nullptr
 
Hook< bool, Builder *, ASTRoot * > ast_transform = nullptr
 

Detailed Description

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 a new language targeting 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.

Member Typedef Documentation

◆ Hook

template<typename Result , typename... Args>
using hilti::Plugin::Hook = Result (*)(Args...)

Helper template to define the type of hook methods.

Member Data Documentation

◆ ast_build_scopes

Hook<bool, Builder*, ASTRoot*> hilti::Plugin::ast_build_scopes = nullptr

Hook called to build the scopes in a module's AST.

Parameters
arg1builder to use
arg2root node of AST; the hook may modify the AST
Returns
true if the hook modified the AST in a substantial way

◆ ast_init

Hook<void, Builder*, ASTRoot*> hilti::Plugin::ast_init = nullptr

Hook called once before any other AST processing takes place.

Parameters
arg1builder to use
arg2root node of AST; the hook may modify the AST

◆ ast_print

Hook<bool, Node*, printer::Stream&> hilti::Plugin::ast_print = nullptr

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.

Parameters
arg1root of AST to print
arg2stream to print to
Returns
true if the hook printed the AST, false to fall back to default

◆ ast_print_id

Hook<bool, const ID&, printer::Stream&> hilti::Plugin::ast_print_id = nullptr

Hook called to output an ID during AST output. The hook gets to choose if it actually wants to print the ID (potentially modified), or fall back to the default printer.

Parameters
arg1ID to print
arg2stream to print the ID to
Returns
true if the hook printed the ID, false to fall back to default

◆ ast_resolve

Hook<bool, Builder*, Node*> hilti::Plugin::ast_resolve = nullptr

Hook called to resolve unknown types and other entities.

Parameters
arg1builder to use
arg2root node of AST; the hook may modify the AST
Returns
true if the hook modified the AST in a substantial way

◆ ast_transform

Hook<bool, Builder*, ASTRoot*> hilti::Plugin::ast_transform = nullptr

Hook called to replace AST nodes of one language (plugin) with nodes of another coming further down in the pipeline.

Parameters
arg1builder to use
arg2root node of AST; the hook may modify the AST
Returns
true if the hook modified the AST in a substantial way

◆ ast_validate_post

Hook<bool, Builder*, ASTRoot*> hilti::Plugin::ast_validate_post = nullptr

Hook called to validate correctness of an AST once fully resolved. Any errors must be reported by setting the nodes' error information.

Parameters
arg1builder to use
arg2root node of AST; the hook may not modify the AST

◆ ast_validate_pre

Hook<bool, Builder*, ASTRoot*> hilti::Plugin::ast_validate_pre = nullptr

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.

Parameters
arg1builder to use
arg2root node of AST; the hook may not modify the AST

◆ coerce_ctor

Hook<Ctor*, Builder*, Ctor*, QualifiedType*, bitmask<CoercionStyle> > hilti::Plugin::coerce_ctor = nullptr

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.

Parameters
arg1builder to use
arg2ctor that needs coercion
arg3target type for ctor
arg4coercion style to use
Returns
new ctor if plugin performed coercion, or nullptr otherwise

◆ coerce_type

Hook<QualifiedType*, Builder*, QualifiedType*, QualifiedType*, bitmask<CoercionStyle> > hilti::Plugin::coerce_type = nullptr

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 QualifiedType*. If so, it must then also provide an apply_coercions hook that will later be called to perform the actual coercion during code generation.

Parameters
arg1builder to use
arg2type that needs coercion
arg3target type for coercion
arg4coercion style to use
Returns
new type if plugin can handle this coercion

◆ component

std::string hilti::Plugin::component

Name of the plugin.

◆ cxx_includes

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.

◆ extension

hilti::rt::filesystem::path hilti::Plugin::extension

Extension for source files that the plugin handles. Must include the leading ..

◆ library_paths

Hook<std::vector<hilti::rt::filesystem::path>, Context*> hilti::Plugin::library_paths = nullptr

Hook called to retrieve paths to search when importing modules that this plugin handles.

Parameters
arg1AST context that's in use
Returns
directories to search

◆ order

int hilti::Plugin::order = 0

Plugins will be executed in numerical order, with lower order numbers executing first.

◆ parse

Hook<Result<declaration::Module*>, hilti::Builder*, std::istream&, const hilti::rt::filesystem::path&> hilti::Plugin::parse
Initial value:
=
nullptr

Hook called to parse input file that this plugin handles.

Parameters
arg1AST builder to use during parsing
arg2input stream to parse
arg3file associated with the input stream
Returns
module AST if parsing succeeded

◆ unify_type

Hook<bool, type_unifier::Unifier*, UnqualifiedType*> hilti::Plugin::unify_type = nullptr

Hook called to compute the unification string for a type. Plugins will be tried successvely until one returns true to indicate it successfully set the type's unification.

Parameters
arg1current unifier instance, which can be used to recurse on other types
arg2type to unify; plugin must call it's setUnififcation() if it handles the type
Returns
true if the plugin handled the type

The documentation for this struct was generated from the following file: