Forráskód Böngészése

LibJS: Switch AST.{h,cpp} to east const

Ali Mohammad Pur 4 éve
szülő
commit
b47246ec70
2 módosított fájl, 84 hozzáadás és 84 törlés
  1. 18 18
      Userland/Libraries/LibJS/AST.cpp
  2. 66 66
      Userland/Libraries/LibJS/AST.h

+ 18 - 18
Userland/Libraries/LibJS/AST.cpp

@@ -37,7 +37,7 @@ class InterpreterNodeScope {
     AK_MAKE_NONMOVABLE(InterpreterNodeScope);
 
 public:
-    InterpreterNodeScope(Interpreter& interpreter, const ASTNode& node)
+    InterpreterNodeScope(Interpreter& interpreter, ASTNode const& node)
         : m_interpreter(interpreter)
         , m_chain_node { nullptr, node }
     {
@@ -61,7 +61,7 @@ String ASTNode::class_name() const
     return demangle(typeid(*this).name()).substring(4);
 }
 
-static void update_function_name(Value value, const FlyString& name)
+static void update_function_name(Value value, FlyString const& name)
 {
     if (!value.is_function())
         return;
@@ -126,7 +126,7 @@ CallExpression::ThisAndCallee CallExpression::compute_this_and_callee(Interprete
     }
 
     if (is<MemberExpression>(*m_callee)) {
-        auto& member_expression = static_cast<const MemberExpression&>(*m_callee);
+        auto& member_expression = static_cast<MemberExpression const&>(*m_callee);
         Value callee;
         Object* this_value = nullptr;
 
@@ -184,9 +184,9 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
         if (is<Identifier>(*m_callee) || is<MemberExpression>(*m_callee)) {
             String expression_string;
             if (is<Identifier>(*m_callee)) {
-                expression_string = static_cast<const Identifier&>(*m_callee).string();
+                expression_string = static_cast<Identifier const&>(*m_callee).string();
             } else {
-                expression_string = static_cast<const MemberExpression&>(*m_callee).to_string_approximation();
+                expression_string = static_cast<MemberExpression const&>(*m_callee).to_string_approximation();
             }
             vm.throw_exception<TypeError>(global_object, ErrorType::IsNotAEvaluatedFrom, callee.to_string_without_side_effects(), call_type, expression_string);
         } else {
@@ -377,10 +377,10 @@ Value ForStatement::execute(Interpreter& interpreter, GlobalObject& global_objec
 
     RefPtr<BlockStatement> wrapper;
 
-    if (m_init && is<VariableDeclaration>(*m_init) && static_cast<const VariableDeclaration&>(*m_init).declaration_kind() != DeclarationKind::Var) {
+    if (m_init && is<VariableDeclaration>(*m_init) && static_cast<VariableDeclaration const&>(*m_init).declaration_kind() != DeclarationKind::Var) {
         wrapper = create_ast_node<BlockStatement>(source_range());
         NonnullRefPtrVector<VariableDeclaration> decls;
-        decls.append(*static_cast<const VariableDeclaration*>(m_init.ptr()));
+        decls.append(*static_cast<VariableDeclaration const*>(m_init.ptr()));
         wrapper->add_variables(decls);
         interpreter.enter_scope(*wrapper, ScopeType::Block, global_object);
     }
@@ -449,10 +449,10 @@ Value ForStatement::execute(Interpreter& interpreter, GlobalObject& global_objec
     return last_value;
 }
 
-static Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>> variable_from_for_declaration(Interpreter& interpreter, GlobalObject& global_object, const ASTNode& node, RefPtr<BlockStatement> wrapper)
+static Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>> variable_from_for_declaration(Interpreter& interpreter, GlobalObject& global_object, ASTNode const& node, RefPtr<BlockStatement> wrapper)
 {
     if (is<VariableDeclaration>(node)) {
-        auto& variable_declaration = static_cast<const VariableDeclaration&>(node);
+        auto& variable_declaration = static_cast<VariableDeclaration const&>(node);
         VERIFY(!variable_declaration.declarations().is_empty());
         if (variable_declaration.declaration_kind() != DeclarationKind::Var) {
             wrapper = create_ast_node<BlockStatement>(node.source_range());
@@ -463,7 +463,7 @@ static Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>> variabl
     }
 
     if (is<Identifier>(node)) {
-        return NonnullRefPtr(static_cast<const Identifier&>(node));
+        return NonnullRefPtr(static_cast<Identifier const&>(node));
     }
 
     VERIFY_NOT_REACHED();
@@ -1154,7 +1154,7 @@ void BindingPattern::dump(int indent) const
     }
 }
 
-void FunctionNode::dump(int indent, const String& class_name) const
+void FunctionNode::dump(int indent, String const& class_name) const
 {
     print_indent(indent);
     outln("{}{} '{}'", class_name, m_is_generator ? "*" : "", name());
@@ -1167,10 +1167,10 @@ void FunctionNode::dump(int indent, const String& class_name) const
             if (parameter.is_rest)
                 out("...");
             parameter.binding.visit(
-                [&](const FlyString& name) {
+                [&](FlyString const& name) {
                     outln("{}", name);
                 },
-                [&](const BindingPattern& pattern) {
+                [&](BindingPattern const& pattern) {
                     pattern.dump(indent + 2);
                 });
             if (parameter.default_value)
@@ -1589,13 +1589,13 @@ Value VariableDeclaration::execute(Interpreter& interpreter, GlobalObject& globa
             if (interpreter.exception())
                 return {};
             declarator.target().visit(
-                [&](const NonnullRefPtr<Identifier>& id) {
+                [&](NonnullRefPtr<Identifier> const& id) {
                     auto variable_name = id->string();
                     if (is<ClassExpression>(*init))
                         update_function_name(initalizer_result, variable_name);
                     interpreter.vm().set_variable(variable_name, initalizer_result, global_object, true);
                 },
-                [&](const NonnullRefPtr<BindingPattern>& pattern) {
+                [&](NonnullRefPtr<BindingPattern> const& pattern) {
                     interpreter.vm().assign(pattern, initalizer_result, global_object, true);
                 });
         }
@@ -1761,7 +1761,7 @@ PropertyName MemberExpression::computed_property_name(Interpreter& interpreter,
 {
     if (!is_computed()) {
         VERIFY(is<Identifier>(*m_property));
-        return static_cast<const Identifier&>(*m_property).string();
+        return static_cast<Identifier const&>(*m_property).string();
     }
     auto value = m_property->execute(interpreter, global_object);
     if (interpreter.exception())
@@ -1774,11 +1774,11 @@ String MemberExpression::to_string_approximation() const
 {
     String object_string = "<object>";
     if (is<Identifier>(*m_object))
-        object_string = static_cast<const Identifier&>(*m_object).string();
+        object_string = static_cast<Identifier const&>(*m_object).string();
     if (is_computed())
         return String::formatted("{}[<computed>]", object_string);
     VERIFY(is<Identifier>(*m_property));
-    return String::formatted("{}.{}", object_string, static_cast<const Identifier&>(*m_property).string());
+    return String::formatted("{}.{}", object_string, static_cast<Identifier const&>(*m_property).string());
 }
 
 Value MemberExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const

+ 66 - 66
Userland/Libraries/LibJS/AST.h

@@ -40,7 +40,7 @@ public:
     virtual void generate_bytecode(Bytecode::Generator&) const;
     virtual void dump(int indent) const;
 
-    const SourceRange& source_range() const { return m_source_range; }
+    SourceRange const& source_range() const { return m_source_range; }
     SourceRange& source_range() { return m_source_range; }
 
     String class_name() const;
@@ -62,7 +62,7 @@ public:
     {
     }
 
-    const FlyString& label() const { return m_label; }
+    FlyString const& label() const { return m_label; }
     void set_label(FlyString string) { m_label = string; }
 
 protected:
@@ -100,7 +100,7 @@ public:
     virtual void dump(int indent) const override;
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
-    const Expression& expression() const { return m_expression; };
+    Expression const& expression() const { return m_expression; };
 
 private:
     NonnullRefPtr<Expression> m_expression;
@@ -120,15 +120,15 @@ public:
         m_children.append(move(child));
     }
 
-    const NonnullRefPtrVector<Statement>& children() const { return m_children; }
+    NonnullRefPtrVector<Statement> const& children() const { return m_children; }
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
     void add_variables(NonnullRefPtrVector<VariableDeclaration>);
     void add_functions(NonnullRefPtrVector<FunctionDeclaration>);
-    const NonnullRefPtrVector<VariableDeclaration>& variables() const { return m_variables; }
-    const NonnullRefPtrVector<FunctionDeclaration>& functions() const { return m_functions; }
+    NonnullRefPtrVector<VariableDeclaration> const& variables() const { return m_variables; }
+    NonnullRefPtrVector<FunctionDeclaration> const& functions() const { return m_functions; }
 
 protected:
     ScopeNode(SourceRange source_range)
@@ -222,15 +222,15 @@ public:
         bool is_rest { false };
     };
 
-    const FlyString& name() const { return m_name; }
-    const Statement& body() const { return *m_body; }
-    const Vector<Parameter>& parameters() const { return m_parameters; };
+    FlyString const& name() const { return m_name; }
+    Statement const& body() const { return *m_body; }
+    Vector<Parameter> const& parameters() const { return m_parameters; };
     i32 function_length() const { return m_function_length; }
     bool is_strict_mode() const { return m_is_strict_mode; }
     bool is_generator() const { return m_is_generator; }
 
 protected:
-    FunctionNode(const FlyString& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode)
+    FunctionNode(FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode)
         : m_name(name)
         , m_body(move(body))
         , m_parameters(move(parameters))
@@ -241,9 +241,9 @@ protected:
     {
     }
 
-    void dump(int indent, const String& class_name) const;
+    void dump(int indent, String const& class_name) const;
 
-    const NonnullRefPtrVector<VariableDeclaration>& variables() const { return m_variables; }
+    NonnullRefPtrVector<VariableDeclaration> const& variables() const { return m_variables; }
 
 protected:
     void set_name(FlyString name)
@@ -255,7 +255,7 @@ protected:
 private:
     FlyString m_name;
     NonnullRefPtr<Statement> m_body;
-    const Vector<Parameter> m_parameters;
+    Vector<Parameter> const m_parameters;
     NonnullRefPtrVector<VariableDeclaration> m_variables;
     const i32 m_function_length;
     bool m_is_generator;
@@ -268,7 +268,7 @@ class FunctionDeclaration final
 public:
     static bool must_have_name() { return true; }
 
-    FunctionDeclaration(SourceRange source_range, const FlyString& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode = false)
+    FunctionDeclaration(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode = false)
         : Declaration(move(source_range))
         , FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode)
     {
@@ -285,7 +285,7 @@ class FunctionExpression final
 public:
     static bool must_have_name() { return false; }
 
-    FunctionExpression(SourceRange source_range, const FlyString& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode, bool is_arrow_function = false)
+    FunctionExpression(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode, bool is_arrow_function = false)
         : Expression(source_range)
         , FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode)
         , m_is_arrow_function(is_arrow_function)
@@ -329,7 +329,7 @@ public:
     {
     }
 
-    const Expression* argument() const { return m_argument; }
+    Expression const* argument() const { return m_argument; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -347,7 +347,7 @@ public:
     {
     }
 
-    const Expression* argument() const { return m_argument; }
+    Expression const* argument() const { return m_argument; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -367,9 +367,9 @@ public:
     {
     }
 
-    const Expression& predicate() const { return *m_predicate; }
-    const Statement& consequent() const { return *m_consequent; }
-    const Statement* alternate() const { return m_alternate; }
+    Expression const& predicate() const { return *m_predicate; }
+    Statement const& consequent() const { return *m_consequent; }
+    Statement const* alternate() const { return m_alternate; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -390,8 +390,8 @@ public:
     {
     }
 
-    const Expression& test() const { return *m_test; }
-    const Statement& body() const { return *m_body; }
+    Expression const& test() const { return *m_test; }
+    Statement const& body() const { return *m_body; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -411,8 +411,8 @@ public:
     {
     }
 
-    const Expression& test() const { return *m_test; }
-    const Statement& body() const { return *m_body; }
+    Expression const& test() const { return *m_test; }
+    Statement const& body() const { return *m_body; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -432,8 +432,8 @@ public:
     {
     }
 
-    const Expression& object() const { return *m_object; }
-    const Statement& body() const { return *m_body; }
+    Expression const& object() const { return *m_object; }
+    Statement const& body() const { return *m_body; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -454,10 +454,10 @@ public:
     {
     }
 
-    const ASTNode* init() const { return m_init; }
-    const Expression* test() const { return m_test; }
-    const Expression* update() const { return m_update; }
-    const Statement& body() const { return *m_body; }
+    ASTNode const* init() const { return m_init; }
+    Expression const* test() const { return m_test; }
+    Expression const* update() const { return m_update; }
+    Statement const& body() const { return *m_body; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -480,9 +480,9 @@ public:
     {
     }
 
-    const ASTNode& lhs() const { return *m_lhs; }
-    const Expression& rhs() const { return *m_rhs; }
-    const Statement& body() const { return *m_body; }
+    ASTNode const& lhs() const { return *m_lhs; }
+    Expression const& rhs() const { return *m_rhs; }
+    Statement const& body() const { return *m_body; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -503,9 +503,9 @@ public:
     {
     }
 
-    const ASTNode& lhs() const { return *m_lhs; }
-    const Expression& rhs() const { return *m_rhs; }
-    const Statement& body() const { return *m_body; }
+    ASTNode const& lhs() const { return *m_lhs; }
+    Expression const& rhs() const { return *m_rhs; }
+    Statement const& body() const { return *m_body; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -733,8 +733,8 @@ public:
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
 
-    const String& pattern() const { return m_pattern; }
-    const String& flags() const { return m_flags; }
+    String const& pattern() const { return m_pattern; }
+    String const& flags() const { return m_flags; }
 
 private:
     String m_pattern;
@@ -743,13 +743,13 @@ private:
 
 class Identifier final : public Expression {
 public:
-    explicit Identifier(SourceRange source_range, const FlyString& string)
+    explicit Identifier(SourceRange source_range, FlyString const& string)
         : Expression(move(source_range))
         , m_string(string)
     {
     }
 
-    const FlyString& string() const { return m_string; }
+    FlyString const& string() const { return m_string; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -777,7 +777,7 @@ public:
     {
     }
 
-    const Expression& key() const { return *m_key; }
+    Expression const& key() const { return *m_key; }
     Kind kind() const { return m_kind; }
     bool is_static() const { return m_is_static; }
 
@@ -891,7 +891,7 @@ private:
     ThisAndCallee compute_this_and_callee(Interpreter&, GlobalObject&) const;
 
     NonnullRefPtr<Expression> m_callee;
-    const Vector<Argument> m_arguments;
+    Vector<Argument> const m_arguments;
 };
 
 class NewExpression final : public CallExpression {
@@ -995,7 +995,7 @@ public:
     }
 
     auto& target() const { return m_target; }
-    const Expression* init() const { return m_init; }
+    Expression const* init() const { return m_init; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -1020,7 +1020,7 @@ public:
     virtual void dump(int indent) const override;
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
-    const NonnullRefPtrVector<VariableDeclarator>& declarations() const { return m_declarations; }
+    NonnullRefPtrVector<VariableDeclarator> const& declarations() const { return m_declarations; }
 
 private:
     DeclarationKind m_declaration_kind;
@@ -1045,8 +1045,8 @@ public:
     {
     }
 
-    const Expression& key() const { return m_key; }
-    const Expression& value() const
+    Expression const& key() const { return m_key; }
+    Expression const& value() const
     {
         VERIFY(m_value);
         return *m_value;
@@ -1089,7 +1089,7 @@ public:
     {
     }
 
-    const Vector<RefPtr<Expression>>& elements() const { return m_elements; }
+    Vector<RefPtr<Expression>> const& elements() const { return m_elements; }
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void dump(int indent) const override;
@@ -1118,12 +1118,12 @@ public:
     virtual void dump(int indent) const override;
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
-    const NonnullRefPtrVector<Expression>& expressions() const { return m_expressions; }
-    const NonnullRefPtrVector<Expression>& raw_strings() const { return m_raw_strings; }
+    NonnullRefPtrVector<Expression> const& expressions() const { return m_expressions; }
+    NonnullRefPtrVector<Expression> const& raw_strings() const { return m_raw_strings; }
 
 private:
-    const NonnullRefPtrVector<Expression> m_expressions;
-    const NonnullRefPtrVector<Expression> m_raw_strings;
+    NonnullRefPtrVector<Expression> const m_expressions;
+    NonnullRefPtrVector<Expression> const m_raw_strings;
 };
 
 class TaggedTemplateLiteral final : public Expression {
@@ -1140,8 +1140,8 @@ public:
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
 private:
-    const NonnullRefPtr<Expression> m_tag;
-    const NonnullRefPtr<TemplateLiteral> m_template_literal;
+    NonnullRefPtr<Expression> const m_tag;
+    NonnullRefPtr<TemplateLiteral> const m_template_literal;
 };
 
 class MemberExpression final : public Expression {
@@ -1160,8 +1160,8 @@ public:
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
     bool is_computed() const { return m_computed; }
-    const Expression& object() const { return *m_object; }
-    const Expression& property() const { return *m_property; }
+    Expression const& object() const { return *m_object; }
+    Expression const& property() const { return *m_property; }
 
     PropertyName computed_property_name(Interpreter&, GlobalObject&) const;
 
@@ -1215,15 +1215,15 @@ private:
 
 class CatchClause final : public ASTNode {
 public:
-    CatchClause(SourceRange source_range, const FlyString& parameter, NonnullRefPtr<BlockStatement> body)
+    CatchClause(SourceRange source_range, FlyString const& parameter, NonnullRefPtr<BlockStatement> body)
         : ASTNode(move(source_range))
         , m_parameter(parameter)
         , m_body(move(body))
     {
     }
 
-    const FlyString& parameter() const { return m_parameter; }
-    const BlockStatement& body() const { return m_body; }
+    FlyString const& parameter() const { return m_parameter; }
+    BlockStatement const& body() const { return m_body; }
 
     virtual void dump(int indent) const override;
     virtual Value execute(Interpreter&, GlobalObject&) const override;
@@ -1243,9 +1243,9 @@ public:
     {
     }
 
-    const BlockStatement& block() const { return m_block; }
-    const CatchClause* handler() const { return m_handler; }
-    const BlockStatement* finalizer() const { return m_finalizer; }
+    BlockStatement const& block() const { return m_block; }
+    CatchClause const* handler() const { return m_handler; }
+    BlockStatement const* finalizer() const { return m_finalizer; }
 
     virtual void dump(int indent) const override;
     virtual Value execute(Interpreter&, GlobalObject&) const override;
@@ -1265,7 +1265,7 @@ public:
     {
     }
 
-    const Expression& argument() const { return m_argument; }
+    Expression const& argument() const { return m_argument; }
 
     virtual void dump(int indent) const override;
     virtual Value execute(Interpreter&, GlobalObject&) const override;
@@ -1284,8 +1284,8 @@ public:
     {
     }
 
-    const Expression* test() const { return m_test; }
-    const NonnullRefPtrVector<Statement>& consequent() const { return m_consequent; }
+    Expression const* test() const { return m_test; }
+    NonnullRefPtrVector<Statement> const& consequent() const { return m_consequent; }
 
     virtual void dump(int indent) const override;
     virtual Value execute(Interpreter&, GlobalObject&) const override;
@@ -1322,7 +1322,7 @@ public:
 
     virtual Value execute(Interpreter&, GlobalObject&) const override;
 
-    const FlyString& target_label() const { return m_target_label; }
+    FlyString const& target_label() const { return m_target_label; }
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
 private:
@@ -1340,7 +1340,7 @@ public:
     virtual Value execute(Interpreter&, GlobalObject&) const override;
     virtual void generate_bytecode(Bytecode::Generator&) const override;
 
-    const FlyString& target_label() const { return m_target_label; }
+    FlyString const& target_label() const { return m_target_label; }
 
 private:
     FlyString m_target_label;