![]() |
Spicy
|
#include <unit.h>
Public Types | |
enum | ASTState { Modified, NotModified } |
Public Member Functions | |
~Unit () | |
NodeRef | moduleRef () const |
Node & | module () |
const auto & | cacheIndex () |
const auto & | id () const |
const auto & | path () const |
const auto & | extension () const |
void | setExtension (const hilti::rt::filesystem::path &ext) |
void | resetAST () |
Result< Nothing > | buildASTScopes (const Plugin &plugin) |
Result< ASTState > | resolveAST (const Plugin &plugin) |
bool | validateASTPre (const Plugin &plugin) |
bool | validateASTPost (const Plugin &plugin) |
Result< Nothing > | transformAST (const Plugin &plugin) |
Result< Nothing > | codegen () |
Result< Nothing > | print (std::ostream &out) const |
Result< Nothing > | createPrototypes (std::ostream &out) |
Result< CxxCode > | cxxCode () const |
std::vector< std::weak_ptr< Unit > > | dependencies (bool recursive=false) const |
void | clearDependencies () |
bool | addDependency (const std::shared_ptr< Unit > &unit) |
Result< linker::MetaData > | linkerMetaData () const |
bool | isCompiledHILTI () const |
bool | requiresCompilation () |
void | setRequiresCompilation () |
bool | isResolved () |
void | setResolved (bool resolved) |
std::shared_ptr< Context > | context () const |
const Options & | options () const |
Static Public Member Functions | |
static Result< std::shared_ptr< Unit > > | fromSource (const std::shared_ptr< Context > &context, const hilti::rt::filesystem::path &path, std::optional< hilti::rt::filesystem::path > process_extension={}) |
static std::shared_ptr< Unit > | fromModule (const std::shared_ptr< Context > &context, hilti::Module module, hilti::rt::filesystem::path extension) |
static Result< std::shared_ptr< Unit > > | fromImport (const std::shared_ptr< Context > &context, const ID &id, const hilti::rt::filesystem::path &parse_extension, const hilti::rt::filesystem::path &process_extension, std::optional< ID > scope, std::vector< hilti::rt::filesystem::path > search_dirs) |
static Result< std::shared_ptr< Unit > > | fromCache (const std::shared_ptr< Context > &context, const hilti::ID &id, const hilti::rt::filesystem::path &extension) |
static Result< std::shared_ptr< Unit > > | fromCache (const std::shared_ptr< Context > &context, const hilti::rt::filesystem::path &path) |
static Result< std::shared_ptr< Unit > > | fromCXX (std::shared_ptr< Context > context, detail::cxx::Unit cxx, const hilti::rt::filesystem::path &path="") |
static Result< std::shared_ptr< Unit > > | link (const std::shared_ptr< Context > &context, const std::vector< linker::MetaData > &mds) |
static std::pair< bool, std::optional< linker::MetaData > > | readLinkerMetaData (std::istream &input, const hilti::rt::filesystem::path &path="<input stream>") |
Container for a single HILTI code module. For each HILTI source file, one compiler unit gets instantiated. That unit then drives the process to compile the module AST into C++ code. While that's in progress, the unit maintains state about the process, such as a list of dependencies this unit requires.
Unit::~Unit | ( | ) |
Destructor.
bool Unit::addDependency | ( | const std::shared_ptr< Unit > & | unit | ) |
Register a dependency on another unit for the current one.
unit | the unit this one depends on |
Runs a plugin's scope-building phase on the unit's AST.
plugin | plugin to execute |
|
inline |
Returns the index to use when storing the unit inside the context's unit cache.
|
inline |
Removes any dependencies registered for the unit so far.
Triggers generation of C++ code from the compiled AST.
|
inline |
Returns the compiler context in use.
Prints out C++ prototypes that host applications can use to interface with the generated C++ code. Must be called only after compile()
was successful.
out | stream to print the code to |
Returns the generated C++ code. Must be called only after compile()
was successful.
std::vector< std::weak_ptr< Unit > > Unit::dependencies | ( | bool | recursive = false | ) | const |
Returns the list of dependencies registered for the unit so far.
recursive | if true, return the transitive closure of all dependent units, vs just direct dependencies of the current unit |
|
inline |
Returns the file extension associated with the unit's code. This extension determines which plugin the unit's AST will be processed with. Note that this does not necessarily match the extension of module's source path.
|
static |
Factory method that instantiates a unit from an existing HILTI module already cached by the global context.
context | global compiler context |
id | ID of the cached module |
extension | file extension to limit cache hits to |
|
static |
Factory method that instantiates a unit from an existing HILTI module already cached by the global context.
context | global compiler context |
path | path of the cached module |
|
static |
Factory method that instantiates a unit from existing C++ source code that's to compiled.
context | global compiler context |
path | path associated with the C++ code, if any |
|
static |
Factory method that instantiates a unit for an import
statement, performing the search for the right source file first.
This method also caches the module with the global context. Note that the module's ID or path should usually not exist with the context yet.
context | global compiler context |
id | ID of the module to be imported |
parse_extension | file extension indicating how to parse the module's source file |
ast_extension | extension indicating which plugin to use for processing the AST; this will usually match parse_extension , but doesn't need to. |
|
static |
Factory method that instantiates a unit from an existing HILTI AST.
This method also caches the module with the global context. Note that the module's ID or path should usually not exist with the context yet. If it does, this one will replace the existing version.
context | global compiler context |
module | AST of the module |
extension | extension indicating which plugin to use for processing the AST |
|
static |
Factory method that instantiates a unit from an existing source file that it will parse.
This method also caches the module with the global context. Note that the module's ID or path should usually not exist with the context yet.
context | global compiler context |
path | path to parse the module from |
ast_extension | extension indicating which plugin to use for processing the AST; if not given, this will be taken from the filename |
|
inline |
Returns the ID of the unit's module.
|
inline |
Returns true if this unit has been compiled from HILTI source. This is usually the case, but we also represent HILTI's linker output as a unit and there's no corresponding HILTI source code for that.
|
inline |
Returns true if the unit has been marked as fully resolved, so that no further AST processing is needed.
|
static |
Entry point for the HILTI linker, The linker combines meta data from several compiled HILTI modules and creates an additional unit from it, with its C++ code representing logic the HILTI runtime library will draw upon.
context | compiler context to use |
mds | set of meta data from modules to be linked together |
|
inline |
Returns the unit's meta data for the internal HILTI linker.
|
inline |
Returns the root node of the module AST's. Must only be called if isCompiledHilti()
returns true.
|
inline |
Returns a reference to the root node of the module AST's.
|
inline |
Returns the compiler options in use.
|
inline |
Returns the path associated with the unit's module.
Prints out a HILTI module by recreating its code from the internal AST. Must be called only after compile()
was successful.
out | stream to print the code to |
|
static |
Reads linker meta from a file. This expects the file to contain linker meta somewhere inside a appropriately marked block bracketed by C-style comments. When printing the generated C++ code for a compiled HILTI module, it will include that block. In other words, you can just save the C++ and reread the meta data with this method.
input | stream to read from |
path | file associated with the stream, for logging and error reporting |
bool Unit::requiresCompilation | ( | ) |
Returns true if the AST has been determined to contain code that needs to be compiled as its own C++ module, rather than just declaration for other units.
void Unit::resetAST | ( | ) |
Clears any scopes and errors accumulated inside the unit's AST.
Runs a plugin's resolver phase on the unit's AST.
plugin | plugin to execute |
|
inline |
Set a file extension associagted with the unit's code. By default, the extension is set when a AST module is being created, for example from the file it's being parsed from. This method can explicitly override the extension to have the AST processed by a different plugin.
ext | new extension |
|
inline |
Explicily marks the unit as requiring compilation down to C++, overriding any automatic determination.
|
inline |
Sets the resolver state for the unit.
resolved | true to mark the module as fully resolved, so that no further AST processing is needed |
Runs a plugin's transformation phase on the unit's AST.
plugin | plugin to execute |
bool Unit::validateASTPost | ( | const Plugin & | plugin | ) |
Runs a plugin's validation phase on the unit's AST after resolving.
plugin | plugin to execute |
bool Unit::validateASTPre | ( | const Plugin & | plugin | ) |
Runs a plugin's validation phase on the unit's AST before resolving.
plugin | plugin to execute |