6 Pass(
"Optimizer", debug), m_ast()
43 for (
auto& child : node.
list())
52 const auto keyword = node.
constList().front().keyword();
53 const auto condition = node.
constList()[1];
56 if (condition.nodeType() ==
NodeType::Symbol && condition.string() ==
"false")
63 const auto back = node.
constList().back();
78 for (
auto& child : node.
list())
87 for (
auto& child : node.
list())
89 if (child.nodeType() ==
NodeType::List && !child.constList().empty() &&
92 const Keyword kw = child.constList()[0].keyword();
105 const std::string name = child.constList()[1].string();
Optimizes a given ArkScript AST.
void trace(const char *fmt, Args &&... args)
Write a trace level log using fmtlib.
void debug(const char *fmt, Args &&... args)
Write a debug level log using fmtlib.
void traceStart(std::string &&trace_name)
A node of an Abstract Syntax Tree for ArkScript.
NodeType nodeType() const noexcept
Return the node type.
bool isListLike() const noexcept
Check if the node is a list like node.
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.
Namespace & arkNamespace() noexcept
Return the namespace held by the value (if the node type allows it)
std::ostream & debugPrint(std::ostream &os) const noexcept
Print a node to an output stream with added type annotations.
std::vector< Node > & list() noexcept
Return the list of sub-nodes held by the node.
Optimizer(unsigned debug) noexcept
Construct a new Optimizer.
void pruneUnusedGlobalVariables(Node &node)
Remove unused global variables from the AST.
const Node & ast() const noexcept override
Returns the modified AST.
void countAndPruneDeadCode(Node &node)
Count the occurrences of each symbol in the AST, recursively, and prune if false/true,...
std::unordered_map< std::string, unsigned > m_sym_appearances
void process(const Node &ast) override
Send the AST to the optimizer, then run the different optimization strategies on it.
An interface to describe compiler passes.
Keyword
The different keywords available.
std::shared_ptr< Node > ast