From 77faad2fc23da4891ffa1d516b32dd259ac6f4a0 Mon Sep 17 00:00:00 2001 From: JaDogg Date: Sun, 19 May 2024 13:08:43 +0100 Subject: [PATCH] style: format code --- compiler/src/ast/ast_printer.cpp | 3 +-- compiler/src/ast/ast_vis.cpp | 9 +++---- compiler/src/builtins/builtins.cpp | 4 ++-- .../compiler/entry_struct_func_compiler.cpp | 24 +++++++++++-------- compiler/src/compiler/slot_matcher.h | 18 +++++++++----- compiler/src/compiler/to_c_compiler.h | 3 ++- compiler/src/compiler/type_checker.h | 8 ++++--- compiler/src/utilities/cpp_util.h | 2 +- compiler/src/utilities/error_printer.cpp | 22 ++++++++++------- compiler/src/utilities/ykdatatype.cpp | 2 +- compiler/src/utilities/ykdatatype.h | 1 - compiler/src/yaksha_lisp/yaksha_lisp.cpp | 11 ++++----- 12 files changed, 60 insertions(+), 47 deletions(-) diff --git a/compiler/src/ast/ast_printer.cpp b/compiler/src/ast/ast_printer.cpp index 928f72ce..c82f279f 100644 --- a/compiler/src/ast/ast_printer.cpp +++ b/compiler/src/ast/ast_printer.cpp @@ -101,8 +101,7 @@ void ast_printer::visit_let_stmt(let_stmt *obj) { text_ << ")"; } void ast_printer::visit_assign_expr(assign_expr *obj) { - text_ << "(" - << "assign " << obj->name_->token_ << " "; + text_ << "(" << "assign " << obj->name_->token_ << " "; obj->right_->accept(this); text_ << ")"; } diff --git a/compiler/src/ast/ast_vis.cpp b/compiler/src/ast/ast_vis.cpp index 2843f8f8..f49d054d 100644 --- a/compiler/src/ast/ast_vis.cpp +++ b/compiler/src/ast/ast_vis.cpp @@ -315,8 +315,7 @@ void ast_vis::visit_ccode_stmt(ccode_stmt *obj) { text_ << "
"
         << ::string_utils::html_escape(
                string_utils::unescape(obj->code_str_->token_))
-        << "
" - << "
"; + << "" << "
"; end_block(); } void ast_vis::visit_import_stmt(import_stmt *obj) { @@ -348,8 +347,7 @@ void ast_vis::visit_nativeconst_stmt(nativeconst_stmt *obj) { text_ << "
"
           << ::string_utils::html_escape(
                  string_utils::unescape(obj->code_str_->token_))
-          << "
" - << "
"; + << "" << "
"; end_block(); } end_block(); @@ -359,8 +357,7 @@ void ast_vis::visit_runtimefeature_stmt(runtimefeature_stmt *obj) { text_ << "
"
         << ::string_utils::html_escape(
                string_utils::unescape(obj->feature_->token_))
-        << "
" - << "
"; + << "" << "
"; end_block(); } void ast_vis::visit_foreach_stmt(foreach_stmt *obj) { diff --git a/compiler/src/builtins/builtins.cpp b/compiler/src/builtins/builtins.cpp index b026a0b7..25b152ce 100644 --- a/compiler/src/builtins/builtins.cpp +++ b/compiler/src/builtins/builtins.cpp @@ -1268,7 +1268,6 @@ struct builtin_iif : builtin { const std::string &filepath, slot_matcher *dt_slot_matcher) override { std::stringstream message{}; auto o = ykobject(dt_pool); - if (args.size() != 3) { o.string_val_ = "iif() builtin expects 3 arguments"; } else if (!(args[0].datatype_->const_unwrap()->is_bool())) { @@ -1287,7 +1286,8 @@ struct builtin_iif : builtin { o.datatype_ = dt_pool->create("sr"); } if (args[1].is_a_function()) { - auto datatype_for_function = dt_slot_matcher->function_to_datatype_or_null(args[1]); + auto datatype_for_function = + dt_slot_matcher->function_to_datatype_or_null(args[1]); if (datatype_for_function != nullptr) { o.datatype_ = datatype_for_function; } else { diff --git a/compiler/src/compiler/entry_struct_func_compiler.cpp b/compiler/src/compiler/entry_struct_func_compiler.cpp index 6689c8a8..c6614d57 100644 --- a/compiler/src/compiler/entry_struct_func_compiler.cpp +++ b/compiler/src/compiler/entry_struct_func_compiler.cpp @@ -49,9 +49,8 @@ const std::vector> REPLACEMENTS = { using namespace yaksha; entry_struct_func_compiler::entry_struct_func_compiler(ykdt_pool *pool) : pool_(pool), counter_(0), counter_bin_data_(0), autogen_bin_data_(), - bin_data_(), name_improvements_(), errors_(), - structure_pool_(), structures_(), - reverse_name_improvements_() {} + bin_data_(), name_improvements_(), errors_(), structure_pool_(), + structures_(), reverse_name_improvements_() {} std::string entry_struct_func_compiler::compile(ykdatatype *entry_dt, datatype_compiler *dtc) { std::string repr = entry_dt->as_string(); @@ -69,7 +68,8 @@ std::string entry_struct_func_compiler::compile(ykdatatype *entry_dt, d->a_ = pool_->create("str"); d->b_ = entry_dt->args_[0]; } else { - errors_.emplace_back("Invalid entry datatype: " + entry_dt->as_string_simplified(), nullptr); + errors_.emplace_back( + "Invalid entry datatype: " + entry_dt->as_string_simplified(), nullptr); return "<><>"; } std::stringstream code{}; @@ -122,15 +122,15 @@ void entry_struct_func_compiler::compile_structures(std::stringstream &target) { if (!it->permanent_mark_) { bool cycle = this->visit(it, topo_sorted_types); if (cycle) { - errors_.emplace_back("Cycle detected in structure: " + it->dt_->as_string_simplified(), nullptr); + errors_.emplace_back("Cycle detected in structure: " + + it->dt_->as_string_simplified(), + nullptr); return; } } } // Forward declarations of classes - for (auto *it : sorted) { - target << it->prefixed_full_name_ << ";\n"; - } + for (auto *it : sorted) { target << it->prefixed_full_name_ << ";\n"; } // Topologically sorted structures for (auto *it : topo_sorted_types) { target << it->code_; } // Classes @@ -212,7 +212,9 @@ entry_struct_func_compiler::compile_function_dt(ykdatatype *function_dt, code << dtc->convert_dt(d->b_->args_[0], datatype_location::STRUCT, "", "") << " "; } else { - errors_.emplace_back("Invalid function output datatype: " + d->b_->as_string_simplified(), nullptr); + errors_.emplace_back("Invalid function output datatype: " + + d->b_->as_string_simplified(), + nullptr); code << "<><>"; } std::string name = @@ -320,7 +322,9 @@ entry_struct_func_compiler::compile_fixed_array(ykdatatype *fixed_array_dt, fixed_array_dt->args_.size() != 2 || fixed_array_dt->args_[0]->is_sm_entry() || fixed_array_dt->args_[1]->is_m_entry()) { - errors_.emplace_back("Invalid fixed array datatype: " + fixed_array_dt->as_string_simplified(), nullptr); + errors_.emplace_back("Invalid fixed array datatype: " + + fixed_array_dt->as_string_simplified(), + nullptr); return "<><>"; } // -- convert diff --git a/compiler/src/compiler/slot_matcher.h b/compiler/src/compiler/slot_matcher.h index 964a51ba..bc4d367f 100644 --- a/compiler/src/compiler/slot_matcher.h +++ b/compiler/src/compiler/slot_matcher.h @@ -52,9 +52,11 @@ namespace yaksha { */ struct slot_matcher : function_datatype_extractor { ~slot_matcher() override = default; - - virtual type_match_result slot_match_with_result(ykdatatype *datatype, const ykobject &provided_arg) = 0; - virtual type_match_result rvalue_match(const ykobject& left_side, const ykobject& right_side) = 0; + virtual type_match_result + slot_match_with_result(ykdatatype *datatype, + const ykobject &provided_arg) = 0; + virtual type_match_result rvalue_match(const ykobject &left_side, + const ykobject &right_side) = 0; /** * Match given two data types, taking auto-casting into account * @param required_datatype datatype that we require (LHS) @@ -62,9 +64,13 @@ namespace yaksha { * @param primitive_or_obj true if provided data is a primitive/object, false otherwise * @return type_match_result struct */ - virtual type_match_result type_match(ykdatatype* required_datatype, ykdatatype* provided_datatype, bool primitive_or_obj) = 0; - virtual bool is_identical_type(ykdatatype* required_datatype, ykdatatype* provided_datatype) = 0; - virtual bool is_not_identical_type(ykdatatype* required_datatype, ykdatatype* provided_datatype) = 0; + virtual type_match_result type_match(ykdatatype *required_datatype, + ykdatatype *provided_datatype, + bool primitive_or_obj) = 0; + virtual bool is_identical_type(ykdatatype *required_datatype, + ykdatatype *provided_datatype) = 0; + virtual bool is_not_identical_type(ykdatatype *required_datatype, + ykdatatype *provided_datatype) = 0; }; }// namespace yaksha #endif diff --git a/compiler/src/compiler/to_c_compiler.h b/compiler/src/compiler/to_c_compiler.h index aab909aa..6a897213 100644 --- a/compiler/src/compiler/to_c_compiler.h +++ b/compiler/src/compiler/to_c_compiler.h @@ -133,7 +133,8 @@ namespace yaksha { const std::pair &rhs, const ykdatatype *rhs_datatype, const ykdatatype *lhs_datatype) override; - [[nodiscard]] std::string wrap_in_paren(const std::string &code) const override; + [[nodiscard]] std::string + wrap_in_paren(const std::string &code) const override; void visit_cfor_stmt(cfor_stmt *obj) override; void visit_enum_stmt(enum_stmt *obj) override; void visit_union_stmt(union_stmt *obj) override; diff --git a/compiler/src/compiler/type_checker.h b/compiler/src/compiler/type_checker.h index f30b4093..fcd5e9da 100644 --- a/compiler/src/compiler/type_checker.h +++ b/compiler/src/compiler/type_checker.h @@ -48,7 +48,6 @@ #include "return_checker.h" #include "utilities/ykobject.h" namespace yaksha { - struct type_checker : expr_visitor, stmt_visitor, slot_matcher { explicit type_checker(std::string filepath, codefiles *cf, def_class_visitor *dcv, ykdt_pool *pool, @@ -61,8 +60,11 @@ namespace yaksha { type_match_result type_match(ykdatatype *required_datatype, ykdatatype *provided_datatype, bool primitive_or_obj) override; - type_match_result slot_match_with_result(ykdatatype *datatype, const ykobject &provided_arg) override; - type_match_result rvalue_match(const ykobject& left_side, const ykobject& right_side) override; + type_match_result + slot_match_with_result(ykdatatype *datatype, + const ykobject &provided_arg) override; + type_match_result rvalue_match(const ykobject &left_side, + const ykobject &right_side) override; ykdatatype *function_to_datatype_or_null(const ykobject &arg) override; void check(const std::vector &statements); void visit_assign_expr(assign_expr *obj) override; diff --git a/compiler/src/utilities/cpp_util.h b/compiler/src/utilities/cpp_util.h index ebed4aad..8dd53ff4 100644 --- a/compiler/src/utilities/cpp_util.h +++ b/compiler/src/utilities/cpp_util.h @@ -216,7 +216,7 @@ namespace yaksha { static inline void intentionally_ignored(const T &) {} // Reference: https://codereview.stackexchange.com/a/238646/47826 static inline std::size_t levenshtein_distance(const std::string &string_a, - const std::string &string_b) { + const std::string &string_b) { const auto size_a = string_a.size(); const auto size_b = string_b.size(); std::vector distances(size_b + 1); diff --git a/compiler/src/utilities/error_printer.cpp b/compiler/src/utilities/error_printer.cpp index c777ccdb..6711dbaf 100644 --- a/compiler/src/utilities/error_printer.cpp +++ b/compiler/src/utilities/error_printer.cpp @@ -85,21 +85,27 @@ namespace yaksha::errors { } } } - std::string - error_printer::errors_to_json_lines(const std::vector &errors) { + std::string error_printer::errors_to_json_lines( + const std::vector &errors) { std::stringstream ss{}; for (auto &err : errors) { ss << "{"; if (err.token_set_) { - ss << "\"file\":\"" << string_utils::escape_json(err.tok_.file_) << "\","; - auto relative_file = std::filesystem::relative(err.tok_.file_, "./").string(); - ss << "\"relative_file\":\"" << string_utils::escape_json(relative_file) << "\","; + ss << "\"file\":\"" << string_utils::escape_json(err.tok_.file_) + << "\","; + auto relative_file = + std::filesystem::relative(err.tok_.file_, "./").string(); + ss << "\"relative_file\":\"" << string_utils::escape_json(relative_file) + << "\","; ss << "\"line\":" << err.tok_.line_ + 1 << ","; ss << "\"pos\":" << err.tok_.pos_ << ","; - ss << "\"message\":\"" << string_utils::escape_json(err.message_) << "\","; - ss << "\"token\":\"" << string_utils::escape_json(err.tok_.original_) << "\""; + ss << "\"message\":\"" << string_utils::escape_json(err.message_) + << "\","; + ss << "\"token\":\"" << string_utils::escape_json(err.tok_.original_) + << "\""; } else { - ss << "\"message\":\"" << string_utils::escape_json(err.message_) << "\""; + ss << "\"message\":\"" << string_utils::escape_json(err.message_) + << "\""; } ss << "}\n"; } diff --git a/compiler/src/utilities/ykdatatype.cpp b/compiler/src/utilities/ykdatatype.cpp index c44a5a64..a118cee2 100644 --- a/compiler/src/utilities/ykdatatype.cpp +++ b/compiler/src/utilities/ykdatatype.cpp @@ -306,7 +306,7 @@ bool ykdatatype::is_dimension() const { return !is_primitive() && builtin_type_ == ykbuiltin::DIMENSION; } bool yaksha::internal_is_identical_type(ykdatatype *required_datatype, - ykdatatype *provided_datatype) { + ykdatatype *provided_datatype) { if (required_datatype != nullptr && provided_datatype != nullptr) { if (required_datatype->is_primitive() && provided_datatype->is_primitive()) { diff --git a/compiler/src/utilities/ykdatatype.h b/compiler/src/utilities/ykdatatype.h index b8a1580d..49040f27 100644 --- a/compiler/src/utilities/ykdatatype.h +++ b/compiler/src/utilities/ykdatatype.h @@ -101,7 +101,6 @@ namespace yaksha { bool lhs_mutates, bool assignment); [[nodiscard]] std::string as_string() const; [[nodiscard]] std::string as_string_simplified() const; - // meta type [[nodiscard]] bool is_c_primitive() const; [[nodiscard]] bool is_primitive() const; diff --git a/compiler/src/yaksha_lisp/yaksha_lisp.cpp b/compiler/src/yaksha_lisp/yaksha_lisp.cpp index e0056c36..df62c191 100644 --- a/compiler/src/yaksha_lisp/yaksha_lisp.cpp +++ b/compiler/src/yaksha_lisp/yaksha_lisp.cpp @@ -454,12 +454,11 @@ yaksha_lisp_value *yaksha_envmap::get(const std::string &symbol) { #ifdef YAKSHA_LISP_EVAL_DEBUG_IS_PRINTED auto v = get_internal(symbol); if (v == nullptr) { - std::cout << indent_ << ">>> " - << "env(" << this << ")." << symbol << " -> " + std::cout << indent_ << ">>> " << "env(" << this << ")." << symbol << " -> " << "NULL" << std::endl; } else { - std::cout << indent_ << ">>> " - << "env(" << this << ")." << symbol << " -> " << v << std::endl; + std::cout << indent_ << ">>> " << "env(" << this << ")." << symbol << " -> " + << v << std::endl; } return v; #else @@ -476,8 +475,8 @@ void yaksha_envmap::set(const std::string &symbol, yaksha_lisp_value *value, } LOG_COMP("not locked can try setting to this env"); #ifdef YAKSHA_LISP_EVAL_DEBUG_IS_PRINTED - std::cout << indent_ << ">>> " - << "env(" << this << ")." << symbol << " = " << value << std::endl; + std::cout << indent_ << ">>> " << "env(" << this << ")." << symbol << " = " + << value << std::endl; #endif // Define if not defined // Do not define in closure, only in current env