summaryrefslogtreecommitdiff
path: root/src/bin/eolian_cxx
diff options
context:
space:
mode:
authorSavio Sena <savio@expertisesolutions.com.br>2014-07-21 20:17:44 -0300
committerSavio Sena <savio@expertisesolutions.com.br>2014-07-21 20:17:44 -0300
commit07b75b9997fb6adc4634e6e75191dc8221aae616 (patch)
tree6bbc1aed41561b20eedbe70eaeda03a72873880a /src/bin/eolian_cxx
parent82af4fb19dd6e3cfee2666a2d71fce1df786c833 (diff)
eolian-cxx: Handle C++ keywords in function names.
When function names are C++ keywords append '_' to it.
Diffstat (limited to 'src/bin/eolian_cxx')
-rw-r--r--src/bin/eolian_cxx/eolian_wrappers.hh2
-rw-r--r--src/bin/eolian_cxx/safe_strings.hh34
2 files changed, 35 insertions, 1 deletions
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()
159inline std::string 159inline std::string
160function_name(Eolian_Function const& func) 160function_name(Eolian_Function const& func)
161{ 161{
162 return safe_str(::eolian_function_name_get(&func)); 162 return keyword_avoid(::eolian_function_name_get(&func));
163} 163}
164 164
165inline std::string 165inline 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_,
122 return s; 122 return s;
123} 123}
124 124
125/// @brief Append '_' if @p key is a C++ keyword.
126///
127inline std::string
128keyword_avoid(std::string const& name)
129{
130 if (name == "delete" ||
131 name == "throw" ||
132 name == "break" ||
133 name == "friend" ||
134 name == "goto" ||
135 name == "default" ||
136 name == "new" ||
137 name == "auto" ||
138 name == "do" ||
139 name == "sizeof" ||
140 name == "try" ||
141 name == "this" ||
142 name == "virtual" ||
143 name == "typename" ||
144 name == "template")
145 {
146 return name + "_"; // XXX Warn?
147 }
148 return name;
149}
150
151/// @brief Append '_' if @p key is a C++ keyword.
152///
153inline std::string
154keyword_avoid(const char* name)
155{
156 return keyword_avoid(safe_str(name));
157}
158
125#endif // EOLIAN_CXX_BIN_SAFE_STRINGS_HH 159#endif // EOLIAN_CXX_BIN_SAFE_STRINGS_HH