mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
JSSpecCompiler: Introduce ControlFlowOperator nodes
This commit is contained in:
parent
81519975c5
commit
67e07fa4e2
3 changed files with 75 additions and 0 deletions
|
@ -80,6 +80,7 @@ protected:
|
||||||
// ```.
|
// ```.
|
||||||
class Statement : public Node { };
|
class Statement : public Node { };
|
||||||
class Expression : public Node { };
|
class Expression : public Node { };
|
||||||
|
class ControlFlowOperator : public Statement { };
|
||||||
|
|
||||||
class ErrorNode : public Expression {
|
class ErrorNode : public Expression {
|
||||||
public:
|
public:
|
||||||
|
@ -96,6 +97,52 @@ protected:
|
||||||
|
|
||||||
inline Tree const error_tree = make_ref_counted<ErrorNode>();
|
inline Tree const error_tree = make_ref_counted<ErrorNode>();
|
||||||
|
|
||||||
|
class ControlFlowFunctionReturn : public ControlFlowOperator {
|
||||||
|
public:
|
||||||
|
ControlFlowFunctionReturn(VariableRef return_value)
|
||||||
|
: m_return_value(move(return_value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VariableRef m_return_value;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dump_tree(StringBuilder& builder) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ControlFlowJump : public ControlFlowOperator {
|
||||||
|
public:
|
||||||
|
ControlFlowJump(BasicBlockRef block)
|
||||||
|
: m_block(block)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BasicBlockRef m_block;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dump_tree(StringBuilder& builder) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
// This should be invalid enough to crash program on use.
|
||||||
|
inline NonnullRefPtr<ControlFlowOperator> const invalid_continuation = make_ref_counted<ControlFlowJump>(nullptr);
|
||||||
|
|
||||||
|
class ControlFlowBranch : public ControlFlowOperator {
|
||||||
|
public:
|
||||||
|
ControlFlowBranch(Tree condition, BasicBlockRef then, BasicBlockRef else_)
|
||||||
|
: m_condition(move(condition))
|
||||||
|
, m_then(then)
|
||||||
|
, m_else(else_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Tree m_condition;
|
||||||
|
BasicBlockRef m_then;
|
||||||
|
BasicBlockRef m_else;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dump_tree(StringBuilder& builder) override;
|
||||||
|
};
|
||||||
|
|
||||||
class MathematicalConstant : public Expression {
|
class MathematicalConstant : public Expression {
|
||||||
public:
|
public:
|
||||||
MathematicalConstant(i64 number)
|
MathematicalConstant(i64 number)
|
||||||
|
@ -249,6 +296,8 @@ protected:
|
||||||
void dump_tree(StringBuilder& builder) override;
|
void dump_tree(StringBuilder& builder) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Although assert might seems a good candidate for ControlFlowOperator, we are not interested in
|
||||||
|
// tracking control flow after a failed assertion.
|
||||||
class AssertExpression : public Expression {
|
class AssertExpression : public Expression {
|
||||||
public:
|
public:
|
||||||
AssertExpression(Tree condition)
|
AssertExpression(Tree condition)
|
||||||
|
|
|
@ -34,6 +34,23 @@ void ErrorNode::dump_tree(StringBuilder& builder)
|
||||||
dump_node(builder, "Error \"{}\"", m_error);
|
dump_node(builder, "Error \"{}\"", m_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControlFlowFunctionReturn::dump_tree(StringBuilder& builder)
|
||||||
|
{
|
||||||
|
dump_node(builder, "ControlFlowFunctionReturn");
|
||||||
|
m_return_value->format_tree(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlFlowJump::dump_tree(StringBuilder& builder)
|
||||||
|
{
|
||||||
|
dump_node(builder, "ControlFlowJump jump={:p}", m_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlFlowBranch::dump_tree(StringBuilder& builder)
|
||||||
|
{
|
||||||
|
dump_node(builder, "ControlFlowBranch true={:p} false={:p}", m_then, m_else);
|
||||||
|
m_condition->format_tree(builder);
|
||||||
|
}
|
||||||
|
|
||||||
void MathematicalConstant::dump_tree(StringBuilder& builder)
|
void MathematicalConstant::dump_tree(StringBuilder& builder)
|
||||||
{
|
{
|
||||||
dump_node(builder, "MathematicalConstant {}", m_number);
|
dump_node(builder, "MathematicalConstant {}", m_number);
|
||||||
|
|
|
@ -21,7 +21,11 @@ using Tree = NonnullRefPtr<Node>;
|
||||||
class Statement;
|
class Statement;
|
||||||
class Expression;
|
class Expression;
|
||||||
class ErrorNode;
|
class ErrorNode;
|
||||||
|
class ControlFlowOperator;
|
||||||
|
|
||||||
|
class ControlFlowFunctionReturn;
|
||||||
|
class ControlFlowJump;
|
||||||
|
class ControlFlowBranch;
|
||||||
class MathematicalConstant;
|
class MathematicalConstant;
|
||||||
class StringLiteral;
|
class StringLiteral;
|
||||||
class BinaryOperation;
|
class BinaryOperation;
|
||||||
|
@ -38,9 +42,14 @@ class RecordDirectListInitialization;
|
||||||
class FunctionCall;
|
class FunctionCall;
|
||||||
class SlotName;
|
class SlotName;
|
||||||
class Variable;
|
class Variable;
|
||||||
|
using VariableRef = NonnullRefPtr<Variable>;
|
||||||
class FunctionPointer;
|
class FunctionPointer;
|
||||||
using FunctionPointerRef = NonnullRefPtr<FunctionPointer>;
|
using FunctionPointerRef = NonnullRefPtr<FunctionPointer>;
|
||||||
|
|
||||||
|
// Compiler/ControlFlowGraph.h
|
||||||
|
class BasicBlock;
|
||||||
|
using BasicBlockRef = BasicBlock*;
|
||||||
|
|
||||||
// Compiler/GenericASTPass.h
|
// Compiler/GenericASTPass.h
|
||||||
class RecursiveASTVisitor;
|
class RecursiveASTVisitor;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue