mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:07:44 +00:00
JSSpecCompiler: Refactor CompilerPass
to accept TranslationUnitRef
This commit is contained in:
parent
24682f5dcf
commit
61fa00d46c
8 changed files with 48 additions and 13 deletions
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Compiler/CompilerPass.h"
|
||||
#include "Function.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
void IntraproceduralCompilerPass::run()
|
||||
{
|
||||
for (auto const& function : m_translation_unit->function_definitions) {
|
||||
m_function = function;
|
||||
process_function();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -15,8 +15,8 @@ namespace JSSpecCompiler {
|
|||
|
||||
class CompilerPass {
|
||||
public:
|
||||
CompilerPass(FunctionDefinitionRef function)
|
||||
: m_function(function)
|
||||
CompilerPass(TranslationUnitRef translation_unit)
|
||||
: m_translation_unit(translation_unit)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,21 @@ public:
|
|||
virtual void run() = 0;
|
||||
|
||||
protected:
|
||||
TranslationUnitRef m_translation_unit;
|
||||
};
|
||||
|
||||
class IntraproceduralCompilerPass : public CompilerPass {
|
||||
public:
|
||||
IntraproceduralCompilerPass(TranslationUnitRef translation_unit)
|
||||
: CompilerPass(translation_unit)
|
||||
{
|
||||
}
|
||||
|
||||
void run() override final;
|
||||
|
||||
protected:
|
||||
virtual void process_function() = 0;
|
||||
|
||||
FunctionDefinitionRef m_function;
|
||||
};
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ RecursionDecision RecursiveASTVisitor::recurse(Tree root, NodeSubtreePointer& po
|
|||
return RecursionDecision::Continue;
|
||||
}
|
||||
|
||||
void GenericASTPass::run()
|
||||
void GenericASTPass::process_function()
|
||||
{
|
||||
run_in_subtree(m_function->m_ast);
|
||||
}
|
||||
|
|
|
@ -33,15 +33,13 @@ private:
|
|||
};
|
||||
|
||||
class GenericASTPass
|
||||
: public CompilerPass
|
||||
: public IntraproceduralCompilerPass
|
||||
, protected RecursiveASTVisitor {
|
||||
public:
|
||||
GenericASTPass(FunctionDefinitionRef function)
|
||||
: CompilerPass(function)
|
||||
{
|
||||
}
|
||||
using IntraproceduralCompilerPass::IntraproceduralCompilerPass;
|
||||
|
||||
void run() override;
|
||||
protected:
|
||||
void process_function() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue