• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #include "google/protobuf/compiler/hpb/keywords.h"
9 
10 #include <new>
11 #include <string>
12 
13 #include "absl/container/flat_hash_set.h"
14 #include "absl/strings/str_cat.h"
15 #include "absl/strings/string_view.h"
16 
17 namespace google::protobuf::hpb_generator {
18 
19 static const absl::string_view kKeywordList[] = {
20     //
21     "NULL",
22     "alignas",
23     "alignof",
24     "and",
25     "and_eq",
26     "asm",
27     "auto",
28     "bitand",
29     "bitor",
30     "bool",
31     "break",
32     "case",
33     "catch",
34     "char",
35     "class",
36     "compl",
37     "const",
38     "constexpr",
39     "const_cast",
40     "continue",
41     "decltype",
42     "default",
43     "delete",
44     "do",
45     "double",
46     "dynamic_cast",
47     "else",
48     "enum",
49     "explicit",
50     "export",
51     "extern",
52     "false",
53     "float",
54     "for",
55     "friend",
56     "goto",
57     "if",
58     "inline",
59     "int",
60     "long",
61     "mutable",
62     "namespace",
63     "new",
64     "noexcept",
65     "not",
66     "not_eq",
67     "nullptr",
68     "operator",
69     "or",
70     "or_eq",
71     "private",
72     "protected",
73     "public",
74     "register",
75     "reinterpret_cast",
76     "return",
77     "short",
78     "signed",
79     "sizeof",
80     "static",
81     "static_assert",
82     "static_cast",
83     "struct",
84     "switch",
85     "template",
86     "this",
87     "thread_local",
88     "throw",
89     "true",
90     "try",
91     "typedef",
92     "typeid",
93     "typename",
94     "union",
95     "unsigned",
96     "using",
97     "virtual",
98     "void",
99     "volatile",
100     "wchar_t",
101     "while",
102     "xor",
103     "xor_eq",
104     "char8_t",
105     "char16_t",
106     "char32_t",
107     "concept",
108     "consteval",
109     "constinit",
110     "co_await",
111     "co_return",
112     "co_yield",
113     "requires",
114 };
115 
MakeKeywordsMap()116 static absl::flat_hash_set<std::string>* MakeKeywordsMap() {
117   auto* result = new absl::flat_hash_set<std::string>();
118   for (const auto keyword : kKeywordList) {
119     result->emplace(keyword);
120   }
121   return result;
122 }
123 
124 static absl::flat_hash_set<std::string>& kKeywords = *MakeKeywordsMap();
125 
ResolveKeywordConflict(absl::string_view name)126 std::string ResolveKeywordConflict(absl::string_view name) {
127   if (kKeywords.count(name) > 0) {
128     return absl::StrCat(name, "_");
129   }
130   return std::string(name);
131 }
132 
133 }  // namespace protobuf
134 }  // namespace google::hpb_generator
135