Spicy
Public Member Functions | List of all members
hilti::Context Class Reference

#include <context.h>

Public Member Functions

 Context (Options options)
 
 ~Context ()
 
const Optionsoptions () const
 
void cacheUnit (const std::shared_ptr< Unit > &unit)
 
std::optional< context::CacheEntrylookupUnit (const ID &id, const std::optional< ID > &scope, const hilti::rt::filesystem::path &extension)
 
std::optional< context::CacheEntrylookupUnit (const hilti::rt::filesystem::path &path, const std::optional< ID > &scope, std::optional< hilti::rt::filesystem::path > ast_extension={})
 
std::optional< context::CacheEntrylookupUnit (const context::CacheIndex &idx, const std::optional< hilti::rt::filesystem::path > &ast_extension={})
 
std::vector< std::weak_ptr< Unit > > lookupDependenciesForUnit (const context::CacheIndex &idx, const hilti::rt::filesystem::path &extension)
 
void dumpUnitCache (const hilti::logging::DebugStream &stream)
 

Detailed Description

Context storing compiler-wide state

Constructor & Destructor Documentation

◆ Context()

Context::Context ( Options  options)
explicit
Parameters
optionsoptions to use for code compilation

◆ ~Context()

Context::~Context ( )

Destructor.

Member Function Documentation

◆ cacheUnit()

void Context::cacheUnit ( const std::shared_ptr< Unit > &  unit)

Caches a code unit inside the context. The cache uses a unit's (ID, path) tuple as the index. Any previously cached unit with the same index tuple will be replaced.

Parameters
unitunit to cache
Returns
the meta data associated with the newly registered module

◆ dumpUnitCache()

void Context::dumpUnitCache ( const hilti::logging::DebugStream stream)

Dumps the current state of the unit cache to a debug stream.

Parameters
streamdebug stream to write to

◆ lookupDependenciesForUnit()

std::vector< std::weak_ptr< Unit > > Context::lookupDependenciesForUnit ( const context::CacheIndex idx,
const hilti::rt::filesystem::path &  extension 
)

Returns all (direct & indirect) dependencies that a module imports. This information will be complete only once all AST have been fully resolved.

Parameters
idxcache index for the module which to return dependencies for
Returns
set of dependencies

◆ lookupUnit() [1/3]

std::optional< CacheEntry > Context::lookupUnit ( const ID id,
const std::optional< ID > &  scope,
const hilti::rt::filesystem::path &  extension 
)

Looks up a previously cached unit by its ID.

Parameters
idmodule ID look up a unit for
scopeimport-from scope associated with the import operation, if any
extensiona file extension expected for the unit, indicating its source language; a cached unit will only be returned if its extension matches
Returns
the cache entry associated with the path if found

◆ lookupUnit() [2/3]

std::optional< CacheEntry > Context::lookupUnit ( const hilti::rt::filesystem::path &  path,
const std::optional< ID > &  scope,
std::optional< hilti::rt::filesystem::path >  ast_extension = {} 
)

Looks up a previously cached unit by its path. It will only return a cached module if its extension matches that of the given path.

Parameters
pathpath to look up a unit for
scopeimport-from scope associated with the path being imported, if any
Returns
the cache entry associated with the path if found

◆ lookupUnit() [3/3]

std::optional< context::CacheEntry > Context::lookupUnit ( const context::CacheIndex idx,
const std::optional< hilti::rt::filesystem::path > &  ast_extension = {} 
)

Looks up a previously cached unit using an existing cache index as the key.

Parameters
idxcache index to look up
Returns
the cache entry associated with the path if found

◆ options()

const Options& hilti::Context::options ( ) const
inline

Returns the context's compiler options.


The documentation for this class was generated from the following files: