11#ifndef COMPILER_MACROS_PROCESSOR_HPP
12#define COMPILER_MACROS_PROCESSOR_HPP
19#include <unordered_map>
46 void process(
const Node& ast)
override;
53 [[nodiscard]]
const Node& ast()
const noexcept override;
71 [[nodiscard]] std::optional<Node> lookupDefinedFunction(
const std::string& name)
const;
79 [[nodiscard]]
const Node* findNearestMacro(
const std::string& name)
const;
86 void deleteNearestMacro(
const std::string& name);
95 static bool isBeginNode(
const Node& node);
103 static void removeBegin(
Node& node, std::size_t i);
112 [[nodiscard]]
bool isConstEval(
const Node& node)
const;
120 void handleMacroNode(
Node& node);
127 void registerFuncDef(
const Node& node);
136 void processNode(
Node& node,
unsigned depth,
bool is_processing_namespace =
false);
146 bool applyMacro(
Node& node,
unsigned depth);
156 void checkMacroArgCountEq(
const Node& node, std::size_t expected,
const std::string& name,
const std::string& kind =
"");
166 void checkMacroArgCountGe(
const Node& node, std::size_t expected,
const std::string& name,
const std::string& kind =
"");
176 Node evaluate(
Node& node,
unsigned depth,
bool is_not_body =
false);
185 bool isTruthy(
const Node& node);
193 [[noreturn]]
void throwMacroProcessingError(
const std::string& message,
const Node& node)
const;
Defines tools to handle macro definitions.
AST node used by the parser, optimizer and compiler.
Interface for a compiler pass (take in an AST, output an AST)
A class that applies macros in a Node.
The class handling the macros definitions and calls, given an AST.
std::shared_ptr< MacroExecutor > m_conditional_executor
std::vector< Node > m_macros_being_applied
Stack of macros being applied. The last one is the current one we are working on.
Node m_ast
The modified AST.
std::unordered_map< std::string, Node > m_defined_functions
std::vector< std::shared_ptr< MacroExecutor > > m_executors
std::vector< MacroScope > m_macros
Handling macros in a scope fashion.
A node of an Abstract Syntax Tree for ArkScript.
An interface to describe compiler passes.