diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh index 1b26a35dc2..0d1fc39114 100644 --- a/src/bin/eolian_cxx/eolian_wrappers.hh +++ b/src/bin/eolian_cxx/eolian_wrappers.hh @@ -159,7 +159,7 @@ class_list_all() inline std::string function_name(Eolian_Function const& func) { - return safe_str(::eolian_function_name_get(&func)); + return keyword_avoid(::eolian_function_name_get(&func)); } inline std::string diff --git a/src/bin/eolian_cxx/safe_strings.hh b/src/bin/eolian_cxx/safe_strings.hh index d9a906984e..d06692121b 100644 --- a/src/bin/eolian_cxx/safe_strings.hh +++ b/src/bin/eolian_cxx/safe_strings.hh @@ -122,4 +122,38 @@ find_replace(std::string const& s_, return s; } +/// @brief Append '_' if @p key is a C++ keyword. +/// +inline std::string +keyword_avoid(std::string const& name) +{ + if (name == "delete" || + name == "throw" || + name == "break" || + name == "friend" || + name == "goto" || + name == "default" || + name == "new" || + name == "auto" || + name == "do" || + name == "sizeof" || + name == "try" || + name == "this" || + name == "virtual" || + name == "typename" || + name == "template") + { + return name + "_"; // XXX Warn? + } + return name; +} + +/// @brief Append '_' if @p key is a C++ keyword. +/// +inline std::string +keyword_avoid(const char* name) +{ + return keyword_avoid(safe_str(name)); +} + #endif // EOLIAN_CXX_BIN_SAFE_STRINGS_HH