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