Skip to content

Commit

Permalink
refactor: removing the MacroExecutorPipeline and integrating it direc…
Browse files Browse the repository at this point in the history
…tly inside the MacroProcessor

It was in fact just a class to hold a vector and a single public method
to run a loop and call methods on the objects inside the vector.
  • Loading branch information
SuperFola committed Jul 28, 2024
1 parent 7ec35eb commit ae2d819
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 83 deletions.
55 changes: 0 additions & 55 deletions include/Ark/Compiler/Macros/Pipeline.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions include/Ark/Compiler/Macros/Processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <Ark/Compiler/AST/Node.hpp>
#include <Ark/Compiler/Macros/MacroScope.hpp>
#include <Ark/Compiler/Macros/Pipeline.hpp>
#include <Ark/Compiler/Macros/Executor.hpp>

#include <unordered_map>
#include <string>
Expand Down Expand Up @@ -55,7 +55,7 @@ namespace Ark::internal
unsigned m_debug; ///< The debug level
Node m_ast; ///< The modified AST
std::vector<MacroScope> m_macros; ///< Handling macros in a scope fashion
MacroExecutorPipeline m_executor_pipeline;
std::vector<std::shared_ptr<MacroExecutor>> m_executors;
std::vector<std::string> m_predefined_macros; ///< Already existing macros, non-keywords, non-builtins
std::unordered_map<std::string, Node> m_defined_functions;

Expand Down
21 changes: 0 additions & 21 deletions src/arkreactor/Compiler/Macros/Pipeline.cpp

This file was deleted.

17 changes: 12 additions & 5 deletions src/arkreactor/Compiler/Macros/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ namespace Ark::internal
m_debug(debug)
{
// create executors pipeline
m_executor_pipeline = MacroExecutorPipeline(
{ std::make_shared<SymbolExecutor>(this),
std::make_shared<ConditionalExecutor>(this),
std::make_shared<FunctionExecutor>(this) });
m_executors = { { std::make_shared<SymbolExecutor>(this),
std::make_shared<ConditionalExecutor>(this),
std::make_shared<FunctionExecutor>(this) } };

m_predefined_macros = {
"symcat",
Expand Down Expand Up @@ -205,7 +204,15 @@ namespace Ark::internal
MaxMacroProcessingDepth),
node);

return m_executor_pipeline.applyMacro(node, depth);
for (const auto& executor : m_executors)
{
if (executor->canHandle(node))
{
if (executor->applyMacro(node, depth))
return true;
}
}
return false;
}

void MacroProcessor::unify(const std::unordered_map<std::string, Node>& map, Node& target, Node* parent, const std::size_t index, const std::size_t unify_depth)
Expand Down

0 comments on commit ae2d819

Please sign in to comment.