mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: rename JS::DeclarationType => JS::DeclarationKind
Many other parsers call it with this name. Also Type can be confusing in this context since the DeclarationType is not the type (number, string, etc.) of the variables that are being declared by the VariableDeclaration.
This commit is contained in:
parent
44f8161166
commit
38dfd04633
Notes:
sideshowbarker
2024-07-19 07:48:48 +09:00
Author: https://github.com/emanuele6 Commit: https://github.com/SerenityOS/serenity/commit/38dfd046332 Pull-request: https://github.com/SerenityOS/serenity/pull/1697
6 changed files with 37 additions and 37 deletions
|
@ -202,7 +202,7 @@ Value ForStatement::execute(Interpreter& interpreter) const
|
|||
{
|
||||
RefPtr<BlockStatement> wrapper;
|
||||
|
||||
if (m_init && m_init->is_variable_declaration() && static_cast<const VariableDeclaration*>(m_init.ptr())->declaration_type() != DeclarationType::Var) {
|
||||
if (m_init && m_init->is_variable_declaration() && static_cast<const VariableDeclaration*>(m_init.ptr())->declaration_kind() != DeclarationKind::Var) {
|
||||
wrapper = create_ast_node<BlockStatement>();
|
||||
interpreter.enter_scope(*wrapper, {}, ScopeType::Block);
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ void UpdateExpression::dump(int indent) const
|
|||
Value VariableDeclaration::execute(Interpreter& interpreter) const
|
||||
{
|
||||
for (auto& declarator : m_declarations) {
|
||||
interpreter.declare_variable(declarator.id().string(), m_declaration_type);
|
||||
interpreter.declare_variable(declarator.id().string(), m_declaration_kind);
|
||||
if (auto* init = declarator.init()) {
|
||||
auto initalizer_result = init->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
|
@ -818,22 +818,22 @@ Value VariableDeclarator::execute(Interpreter&) const
|
|||
|
||||
void VariableDeclaration::dump(int indent) const
|
||||
{
|
||||
const char* declaration_type_string = nullptr;
|
||||
switch (m_declaration_type) {
|
||||
case DeclarationType::Let:
|
||||
declaration_type_string = "Let";
|
||||
const char* declaration_kind_string = nullptr;
|
||||
switch (m_declaration_kind) {
|
||||
case DeclarationKind::Let:
|
||||
declaration_kind_string = "Let";
|
||||
break;
|
||||
case DeclarationType::Var:
|
||||
declaration_type_string = "Var";
|
||||
case DeclarationKind::Var:
|
||||
declaration_kind_string = "Var";
|
||||
break;
|
||||
case DeclarationType::Const:
|
||||
declaration_type_string = "Const";
|
||||
case DeclarationKind::Const:
|
||||
declaration_kind_string = "Const";
|
||||
break;
|
||||
}
|
||||
|
||||
ASTNode::dump(indent);
|
||||
print_indent(indent + 1);
|
||||
printf("%s\n", declaration_type_string);
|
||||
printf("%s\n", declaration_kind_string);
|
||||
|
||||
for (auto& declarator : m_declarations)
|
||||
declarator.dump(indent + 1);
|
||||
|
|
|
@ -591,7 +591,7 @@ private:
|
|||
bool m_prefixed;
|
||||
};
|
||||
|
||||
enum class DeclarationType {
|
||||
enum class DeclarationKind {
|
||||
Var,
|
||||
Let,
|
||||
Const,
|
||||
|
@ -620,14 +620,14 @@ private:
|
|||
|
||||
class VariableDeclaration : public Declaration {
|
||||
public:
|
||||
VariableDeclaration(DeclarationType declaration_type, NonnullRefPtrVector<VariableDeclarator> declarations)
|
||||
: m_declaration_type(declaration_type)
|
||||
VariableDeclaration(DeclarationKind declaration_kind, NonnullRefPtrVector<VariableDeclarator> declarations)
|
||||
: m_declaration_kind(declaration_kind)
|
||||
, m_declarations(move(declarations))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool is_variable_declaration() const override { return true; }
|
||||
DeclarationType declaration_type() const { return m_declaration_type; }
|
||||
DeclarationKind declaration_kind() const { return m_declaration_kind; }
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
@ -635,7 +635,7 @@ public:
|
|||
private:
|
||||
virtual const char* class_name() const override { return "VariableDeclaration"; }
|
||||
|
||||
DeclarationType m_declaration_type;
|
||||
DeclarationKind m_declaration_kind;
|
||||
NonnullRefPtrVector<VariableDeclarator> m_declarations;
|
||||
};
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class ScopeNode;
|
|||
class Shape;
|
||||
class Statement;
|
||||
class Value;
|
||||
enum class DeclarationType;
|
||||
enum class DeclarationKind;
|
||||
|
||||
struct Argument;
|
||||
|
||||
|
|
|
@ -90,11 +90,11 @@ Value Interpreter::run(const Statement& statement, ArgumentVector arguments, Sco
|
|||
|
||||
void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector arguments, ScopeType scope_type)
|
||||
{
|
||||
HashMap<FlyString, Variable> scope_variables_with_declaration_type;
|
||||
HashMap<FlyString, Variable> scope_variables_with_declaration_kind;
|
||||
for (auto& argument : arguments) {
|
||||
scope_variables_with_declaration_type.set(argument.name, { argument.value, DeclarationType::Var });
|
||||
scope_variables_with_declaration_kind.set(argument.name, { argument.value, DeclarationKind::Var });
|
||||
}
|
||||
m_scope_stack.append({ scope_type, scope_node, move(scope_variables_with_declaration_type) });
|
||||
m_scope_stack.append({ scope_type, scope_node, move(scope_variables_with_declaration_kind) });
|
||||
}
|
||||
|
||||
void Interpreter::exit_scope(const ScopeNode& scope_node)
|
||||
|
@ -110,29 +110,29 @@ void Interpreter::exit_scope(const ScopeNode& scope_node)
|
|||
m_unwind_until = ScopeType::None;
|
||||
}
|
||||
|
||||
void Interpreter::declare_variable(const FlyString& name, DeclarationType declaration_type)
|
||||
void Interpreter::declare_variable(const FlyString& name, DeclarationKind declaration_kind)
|
||||
{
|
||||
switch (declaration_type) {
|
||||
case DeclarationType::Var:
|
||||
switch (declaration_kind) {
|
||||
case DeclarationKind::Var:
|
||||
for (ssize_t i = m_scope_stack.size() - 1; i >= 0; --i) {
|
||||
auto& scope = m_scope_stack.at(i);
|
||||
if (scope.type == ScopeType::Function) {
|
||||
if (scope.variables.get(name).has_value() && scope.variables.get(name).value().declaration_type != DeclarationType::Var)
|
||||
if (scope.variables.get(name).has_value() && scope.variables.get(name).value().declaration_kind != DeclarationKind::Var)
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
scope.variables.set(move(name), { js_undefined(), declaration_type });
|
||||
scope.variables.set(move(name), { js_undefined(), declaration_kind });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
global_object().put(move(name), js_undefined());
|
||||
break;
|
||||
case DeclarationType::Let:
|
||||
case DeclarationType::Const:
|
||||
case DeclarationKind::Let:
|
||||
case DeclarationKind::Const:
|
||||
if (m_scope_stack.last().variables.get(name).has_value())
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
m_scope_stack.last().variables.set(move(name), { js_undefined(), declaration_type });
|
||||
m_scope_stack.last().variables.set(move(name), { js_undefined(), declaration_kind });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -144,10 +144,10 @@ void Interpreter::set_variable(const FlyString& name, Value value, bool first_as
|
|||
|
||||
auto possible_match = scope.variables.get(name);
|
||||
if (possible_match.has_value()) {
|
||||
if (!first_assignment && possible_match.value().declaration_type == DeclarationType::Const)
|
||||
if (!first_assignment && possible_match.value().declaration_kind == DeclarationKind::Const)
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
scope.variables.set(move(name), { move(value), possible_match.value().declaration_type });
|
||||
scope.variables.set(move(name), { move(value), possible_match.value().declaration_kind });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ enum class ScopeType {
|
|||
|
||||
struct Variable {
|
||||
Value value;
|
||||
DeclarationType declaration_type;
|
||||
DeclarationKind declaration_kind;
|
||||
};
|
||||
|
||||
struct ScopeFrame {
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
|
||||
Optional<Value> get_variable(const FlyString& name);
|
||||
void set_variable(const FlyString& name, Value, bool first_assignment = false);
|
||||
void declare_variable(const FlyString& name, DeclarationType);
|
||||
void declare_variable(const FlyString& name, DeclarationKind);
|
||||
|
||||
void gather_roots(Badge<Heap>, HashTable<Cell*>&);
|
||||
|
||||
|
|
|
@ -658,19 +658,19 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node()
|
|||
|
||||
NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration()
|
||||
{
|
||||
DeclarationType declaration_type;
|
||||
DeclarationKind declaration_kind;
|
||||
|
||||
switch (m_parser_state.m_current_token.type()) {
|
||||
case TokenType::Var:
|
||||
declaration_type = DeclarationType::Var;
|
||||
declaration_kind = DeclarationKind::Var;
|
||||
consume(TokenType::Var);
|
||||
break;
|
||||
case TokenType::Let:
|
||||
declaration_type = DeclarationType::Let;
|
||||
declaration_kind = DeclarationKind::Let;
|
||||
consume(TokenType::Let);
|
||||
break;
|
||||
case TokenType::Const:
|
||||
declaration_type = DeclarationType::Const;
|
||||
declaration_kind = DeclarationKind::Const;
|
||||
consume(TokenType::Const);
|
||||
break;
|
||||
default:
|
||||
|
@ -692,7 +692,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration()
|
|||
}
|
||||
break;
|
||||
}
|
||||
return create_ast_node<VariableDeclaration>(declaration_type, move(declarations));
|
||||
return create_ast_node<VariableDeclaration>(declaration_kind, move(declarations));
|
||||
}
|
||||
|
||||
NonnullRefPtr<ThrowStatement> Parser::parse_throw_statement()
|
||||
|
|
Loading…
Reference in a new issue