[C++] Sanitize operation ids. (#6664)

* [C++] Sanitize operation ids.

* [C++] Handle reserved words in `toOperationId`.

* [C++] Re-order reserved words alphabetically.

* [C++] Add missing reserved words.
This commit is contained in:
François Rosé 2017-10-17 17:14:34 +02:00 committed by wing328
parent 27850d9596
commit be3e33f472

View File

@ -17,77 +17,90 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
*/
setReservedWordsLowerCase(
Arrays.asList(
"alignas",
"alignof",
"and",
"and_eq",
"asm",
"auto",
"bitand",
"bitor",
"bool",
"break",
"case",
"catch",
"char",
"char16_t",
"char32_t",
"class",
"compl",
"concept",
"const",
"constexpr",
"const_cast",
"continue",
"decltype",
"default",
"delete",
"do",
"double",
"dynamic_cast",
"else",
"enum",
"explicit",
"export",
"extern",
"false",
"float",
"for",
"friend",
"goto",
"if",
"inline",
"int",
"long",
"mutable",
"namespace",
"new",
"noexcept",
"not",
"not_eq",
"nullptr",
"operator",
"or",
"or_eq",
"private",
"protected",
"public",
"register",
"reinterpret_cast",
"requires",
"return",
"short",
"signed",
"sizeof",
"static",
"static_assert",
"static_cast",
"struct",
"switch",
"typedef",
"union",
"unsigned",
"void",
"volatile",
"while",
"asm",
"bool",
"catch",
"class",
"const_cast",
"delete",
"dynamic_cast",
"explicit",
"false",
"friend",
"inline",
"mutable",
"namespace",
"new",
"operator",
"private",
"public",
"protected",
"reinterpret_cast",
"static_cast",
"template",
"this",
"thread_local",
"throw",
"true",
"try",
"typedef",
"typeid",
"typename",
"union",
"unsigned",
"using",
"virtual",
"void",
"volatile",
"wchar_t",
"and",
"and_eq",
"bitand",
"bitor",
"compl",
"not",
"not_eq",
"or",
"or_eq",
"while",
"xor",
"xor_eq")
);
@ -127,6 +140,15 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
return sanitizeName("_" + name);
}
@Override
public String toOperationId(String operationId) {
if (isReservedWord(operationId)) {
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + escapeReservedWord(operationId));
return escapeReservedWord(operationId);
}
return sanitizeName(super.toOperationId(operationId));
}
@Override
public String toParamName(String name) {
return sanitizeName(super.toParamName(name));