From 71f3f4a688452a91d25026596e7c08846b03bcc3 Mon Sep 17 00:00:00 2001 From: Tristan Carel Date: Fri, 8 Sep 2023 17:18:16 +0200 Subject: [PATCH] revert unwanted changes --- src/codegen/codegen_cpp_visitor.hpp | 17 +---------------- src/utils/string_utils.hpp | 14 +++++++------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index 40de6f5469..5bc2767394 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -190,7 +190,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * - pointer qualifier (e.g. \c \_\_restrict\_\_) * - parameter name (e.g. \c data) * - * \TODO TCAREL: use class instead of std::tuple */ using ParamVector = std::vector>; @@ -301,12 +300,7 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * \return The same string with double-quotes pre- and postfixed */ std::string add_escape_quote(const std::string& text) const { - std::string escaped(text.size() + 2, ' '); - auto it = escaped.begin(); - *it++ = '\"'; - std::copy(text.begin(), text.end(), it); - escaped.back() = '\"'; - return escaped; + return "\"" + text + "\""; } @@ -390,8 +384,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * Name of structure that wraps range variables */ std::string instance_struct() const { - /// TODO TCAREL use copy by hand ~8 times faster - /// use cached value to prevent created the std::string return fmt::format("{}_Instance", info.mod_suffix); } @@ -400,8 +392,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * Name of structure that wraps global variables */ std::string global_struct() const { - /// TODO TCAREL use copy by hand ~8 times faster - /// use cached value to prevent created the std::string return fmt::format("{}_Store", info.mod_suffix); } @@ -410,8 +400,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * Name of the (host-only) global instance of `global_struct` */ std::string global_struct_instance() const { - /// TODO TCAREL use copy by hand ~8 times faster - /// use cached value to prevent created the std::string return info.mod_suffix + "_global"; } @@ -422,8 +410,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * \return The name of the function or procedure postfixed with the model name */ std::string method_name(const std::string& name) const { - /// TODO TCAREL use copy by hand ~8 times faster - /// use cached value to prevent created the std::string return name + "_" + info.mod_suffix; } @@ -507,7 +493,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * Check if a semicolon is required at the end of given statement * \param node The AST Statement node to check * \return \c true if this Statement requires a semicolon - * \TODO TCAREL use const ast::Statement& */ static bool need_semicolon(ast::Statement* node); diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index 0bd292130b..9903ff8924 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -64,24 +64,24 @@ static inline std::string& trim_newline(std::string& s) { /// for printing json, we have to escape double quotes static inline std::string escape_quotes(const std::string& before) { - std::ostringstream oss; + std::string after; for (auto c: before) { switch (c) { case '"': case '\\': - oss << '\\'; + after += '\\'; /// don't break here as we want to append actual character default: - oss << c; + after += c; } } - return oss.str(); + return after; } -/// Split string with given delimiter and returns vector +/// Spilt string with given delimiter and returns vector static inline std::vector split_string(const std::string& text, char delimiter) { std::vector elements; std::stringstream ss(text); @@ -95,12 +95,12 @@ static inline std::vector split_string(const std::string& text, cha } /// Left/Right/Center-aligns string within a field of width "width" -static inline std::string align_text(const std::string& text, int width, text_alignment type) { +static inline std::string align_text(std::string text, int width, text_alignment type) { /// left and right spacing std::string left, right; /// count excess room to pad - const int padding = width - text.size(); + int padding = width - text.size(); if (padding > 0) { if (type == text_alignment::left) {