Skip to content

Commit

Permalink
revert unwanted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan0x committed Sep 8, 2023
1 parent e078f48 commit 71f3f4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
17 changes: 1 addition & 16 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<std::string, std::string, std::string, std::string>>;

Expand Down Expand Up @@ -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 + "\"";
}


Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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";
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions src/utils/string_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> split_string(const std::string& text, char delimiter) {
std::vector<std::string> elements;
std::stringstream ss(text);
Expand All @@ -95,12 +95,12 @@ static inline std::vector<std::string> 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) {
Expand Down

0 comments on commit 71f3f4a

Please sign in to comment.