ArkScript
A small, fast, functional and scripting language for video games
|
The ArkScript AST optimizer. More...
#include <Optimizer.hpp>
Public Member Functions | |
Optimizer (uint16_t options) noexcept | |
Construct a new Optimizer. | |
void | feed (const Node &ast) |
Send the AST to the optimizer, then run the different optimization strategies on it. | |
const Node & | ast () const noexcept |
Returns the modified AST. | |
Private Member Functions | |
void | throwOptimizerError (const std::string &message, const Node &node) |
Generate a fancy error message. | |
void | remove_unused () |
Iterate over the AST and remove unused top level functions and constants. | |
void | runOnGlobalScopeVars (Node &node, const std::function< void(Node &, Node &, int)> &func) |
Run a given functor on the global scope symbols. | |
void | countOccurences (Node &node) |
Count the occurences of each symbol in the AST, recursively. | |
Private Attributes | |
Node | m_ast |
uint16_t | m_options |
std::unordered_map< std::string, unsigned > | m_sym_appearances |
The ArkScript AST optimizer.
Definition at line 31 of file Optimizer.hpp.
|
explicitnoexcept |
Construct a new Optimizer.
Definition at line 5 of file Optimizer.cpp.
|
noexcept |
Returns the modified AST.
Definition at line 17 of file Optimizer.cpp.
References m_ast.
Referenced by Ark::Compiler::compile(), Ark::JsonCompiler::compile(), and feed().
|
private |
Count the occurences of each symbol in the AST, recursively.
node |
Definition at line 73 of file Optimizer.cpp.
References Ark::internal::Capture, Ark::internal::Node::constList(), countOccurences(), Ark::internal::Node::list(), Ark::internal::List, m_sym_appearances, Ark::internal::Node::nodeType(), Ark::internal::Node::string(), and Ark::internal::Symbol.
Referenced by countOccurences(), and remove_unused().
void Ark::internal::Optimizer::feed | ( | const Node & | ast | ) |
Send the AST to the optimizer, then run the different optimization strategies on it.
ast |
Definition at line 9 of file Optimizer.cpp.
References ast(), Ark::FeatureRemoveUnusedVars, m_ast, m_options, and remove_unused().
Referenced by Ark::Compiler::feed(), and Ark::JsonCompiler::feed().
|
private |
Iterate over the AST and remove unused top level functions and constants.
Definition at line 27 of file Optimizer.cpp.
References Ark::internal::Node::constList(), countOccurences(), Ark::internal::Node::list(), Ark::internal::List, m_ast, m_sym_appearances, Ark::internal::Node::nodeType(), and runOnGlobalScopeVars().
Referenced by feed().
|
private |
Run a given functor on the global scope symbols.
node | |
func |
Definition at line 47 of file Optimizer.cpp.
References Ark::internal::Begin, Ark::internal::Node::constList(), Ark::internal::Keyword, Ark::internal::Let, Ark::internal::Node::list(), Ark::internal::Mut, and runOnGlobalScopeVars().
Referenced by remove_unused(), and runOnGlobalScopeVars().
|
private |
Generate a fancy error message.
message | |
node |
Definition at line 22 of file Optimizer.cpp.
References Ark::internal::makeNodeBasedErrorCtx().
|
private |
Definition at line 55 of file Optimizer.hpp.
Referenced by ast(), feed(), and remove_unused().
|
private |
Definition at line 56 of file Optimizer.hpp.
Referenced by feed().
|
private |
Definition at line 57 of file Optimizer.hpp.
Referenced by countOccurences(), and remove_unused().