12#ifndef COMPILER_MACROS_PROCESSOR_HPP
13#define COMPILER_MACROS_PROCESSOR_HPP
20#include <unordered_map>
53 const Node&
ast()
const noexcept;
163 void unify(
const std::unordered_map<std::string, Node>& map,
Node& target,
Node* parent, std::size_t index = 0);
The base class for all MacroExecutors.
Defines tools to handle macro definitions.
AST node used by the parser, optimizer and compiler.
The Chain of Responsibility class for running nodes through MacroExecutors.
The class that initializes the MacroExecutors.
A class that applies macros in a Node.
The class handling the macros definitions and calls, given an AST.
void removeBegin(Node &node, std::size_t &i)
Remove a begin block added by a macro.
void process(Node &node, unsigned depth)
Register macros in scopes and apply them as needed.
void unify(const std::unordered_map< std::string, Node > &map, Node &target, Node *parent, std::size_t index=0)
Unify a target node with a given map symbol => replacement node, recursively.
const Node & ast() const noexcept
Return the modified AST.
MacroExecutorPipeline m_executor_pipeline
void recurApply(Node &node)
Recursively apply macros on a given node.
std::vector< std::string > m_predefined_macros
Already existing macros, non-keywords, non-builtins.
void registerMacro(Node &node)
Registers macros based on their type.
Node evaluate(Node &node, bool is_not_body=false)
Evaluate only the macros.
const Node * findNearestMacro(const std::string &name) const
Find the nearest macro matching a given name.
Node m_ast
The modified AST.
bool isTruthy(const Node &node)
Check if a node can be evaluated to true.
bool hadBegin(const Node &node)
Check if a given node is a list node, and starts with a Begin.
void throwMacroProcessingError(const std::string &message, const Node &node)
Throw a macro processing error.
std::unordered_map< std::string, Node > m_defined_functions
bool isConstEval(const Node &node) const
Check if a node can be evaluated at compile time.
bool isPredefined(const std::string &symbol)
Check if a given symbol is a predefined macro or not.
bool applyMacro(Node &node)
Apply a macro on a given node.
void feed(const Node &ast)
Send the complete AST (after the inclusions and stuff), and work on it.
std::vector< MacroScope > m_macros
Handling macros in a scope fashion.
void registerFuncDef(Node &node)
Registers a function definition node.
unsigned m_debug
The debug level.
void deleteNearestMacro(const std::string &name)
Find the nearest macro matching a given name and delete it.
A node of an Abstract Syntax Tree for ArkScript.