summaryrefslogtreecommitdiff
path: root/xsd/xsd
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-09-26 08:17:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-09-26 08:17:55 +0200
commit1c04a24059a9b8e20058e1c4e4d86a1f560d33a8 (patch)
treea8925783914c3629b4af5b7b1ce960b3caffb3a6 /xsd/xsd
parent764f28b67e4989dded24d8826b2a9b0c6f02e1b4 (diff)
Recognize C++11 and C++20 keywords for identifier escaping
Diffstat (limited to 'xsd/xsd')
-rw-r--r--xsd/xsd/cxx/elements.cxx45
1 files changed, 44 insertions, 1 deletions
diff --git a/xsd/xsd/cxx/elements.cxx b/xsd/xsd/cxx/elements.cxx
index e914f9d..02a768e 100644
--- a/xsd/xsd/cxx/elements.cxx
+++ b/xsd/xsd/cxx/elements.cxx
@@ -102,6 +102,36 @@ namespace CXX
L"xor",
L"xor_eq"
};
+
+ // Note: excluding "identifiers with special meaning" in certain contexts
+ // ("final", "override") since they shouldn't cause any issues.
+ //
+ wchar_t const* keywords_cxx11[] = {
+ L"alignas",
+ L"alignof",
+ L"char16_t",
+ L"char32_t",
+ L"constexpr",
+ L"decltype",
+ L"noexcept",
+ L"nullptr",
+ L"static_assert",
+ L"thread_local"
+ };
+
+ // Note: excluding "identifiers with special meaning" in certain contexts
+ // ("import", "module") since they shouldn't cause any issues.
+ //
+ wchar_t const* keywords_cxx20[] = {
+ L"char8_t",
+ L"concept",
+ L"consteval",
+ L"constinit",
+ L"co_await",
+ L"co_return",
+ L"co_yield",
+ L"requires"
+ };
}
// Context
@@ -268,8 +298,21 @@ namespace CXX
// Populate the keyword set.
//
- for (size_t i (0); i < sizeof (keywords) / sizeof (char*); ++i)
+ for (size_t i (0); i < sizeof (keywords) / sizeof (wchar_t*); ++i)
keyword_set_.insert (keywords[i]);
+
+ if (std >= cxx_version::cxx11)
+ {
+ for (size_t i (0); i < sizeof (keywords_cxx11) / sizeof (wchar_t*); ++i)
+ keyword_set_.insert (keywords_cxx11[i]);
+ }
+
+ if (std >= cxx_version::cxx20)
+ {
+ for (size_t i (0); i < sizeof (keywords_cxx20) / sizeof (wchar_t*); ++i)
+ keyword_set_.insert (keywords_cxx20[i]);
+ }
+
}
String Context::