40 std::string name = node.
constList()[1].
string();
43 parent.
list().erase(parent.
list().begin() + idx);
49 int i =
static_cast<int>(node.
constList().size());
51 for (
auto it = node.
list().rbegin(); it != node.
list().rend(); ++it)
55 if (it->constList().size() > 0 && it->constList()[0].nodeType() ==
NodeType::Keyword)
57 Keyword kw = it->constList()[0].keyword();
77 std::string name = node.
string();
85 for (std::size_t i = 0, end = node.
constList().size(); i != end; ++i)
Optimizes a given ArkScript AST.
OptimizerError thrown by the AST optimizer.
A node of an Abstract Syntax Tree for ArkScript.
NodeType nodeType() const noexcept
Return the node type.
const std::string & string() const noexcept
Return the string held by the value (if the node type allows it)
const std::vector< Node > & constList() const noexcept
Return the list of sub-nodes held by the node.
std::vector< Node > & list() noexcept
Return the list of sub-nodes held by the node.
void feed(const Node &ast)
Send the AST to the optimizer, then run the different optimization strategies on it.
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.
const Node & ast() const noexcept
Returns the modified AST.
Optimizer(uint16_t options) noexcept
Construct a new Optimizer.
void countOccurences(Node &node)
Count the occurences of each symbol in the AST, recursively.
void runOnGlobalScopeVars(Node &node, const std::function< void(Node &, Node &, int)> &func)
Run a given functor on the global scope symbols.
std::unordered_map< std::string, unsigned > m_sym_appearances
std::string makeNodeBasedErrorCtx(const std::string &message, const Node &node)
Construct an error message based on a given node.
Keyword
The different keywords available.
constexpr uint16_t FeatureRemoveUnusedVars