From 07b75b9997fb6adc4634e6e75191dc8221aae616 Mon Sep 17 00:00:00 2001 From: Savio Sena Date: Mon, 21 Jul 2014 20:17:44 -0300 Subject: [PATCH] eolian-cxx: Handle C++ keywords in function names. When function names are C++ keywords append '_' to it. --- src/bin/eolian_cxx/eolian_wrappers.hh | 2 +- src/bin/eolian_cxx/safe_strings.hh | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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