Skip to content

Commit ba357af

Browse files
authored
Store keywords in a StringMap (#10)
1 parent 7909712 commit ba357af

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

lldb/source/ValueObject/DILLexer.cpp

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,31 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "lldb/ValueObject/DILLexer.h"
15+
#include "llvm/ADT/StringMap.h"
1516

1617
namespace lldb_private {
1718

1819
namespace dil {
1920

21+
const llvm::StringMap<dil::TokenKind> Keywords = {
22+
{"bool", dil::TokenKind::kw_bool},
23+
{"char", dil::TokenKind::kw_char},
24+
{"double", dil::TokenKind::kw_double},
25+
{"dynamic_cast", dil::TokenKind::kw_dynamic_cast},
26+
{"false", dil::TokenKind::kw_false},
27+
{"float", dil::TokenKind::kw_float},
28+
{"int", dil::TokenKind::kw_int},
29+
{"long", dil::TokenKind::kw_long},
30+
{"nullptr", dil::TokenKind::kw_nullptr},
31+
{"reinterpret_cast", dil::TokenKind::kw_reinterpret_cast},
32+
{"short", dil::TokenKind::kw_short},
33+
{"signed", dil::TokenKind::kw_signed},
34+
{"static_cast", dil::TokenKind::kw_static_cast},
35+
{"this", dil::TokenKind::kw_this},
36+
{"true", dil::TokenKind::kw_true},
37+
{"unsigned", dil::TokenKind::kw_unsigned},
38+
};
39+
2040
const std::string DILToken::getTokenName(dil::TokenKind kind) {
2141
std::string retval;
2242
switch (kind){
@@ -193,38 +213,9 @@ bool DILLexer::Lex(DILToken &result, bool look_ahead) {
193213
} else if (Is_Word(start, length)) {
194214
dil::TokenKind kind;
195215
std::string word = m_expr.substr(position, length);
196-
if (word == "bool")
197-
kind = dil::TokenKind::kw_bool;
198-
else if (word == "char")
199-
kind = dil::TokenKind::kw_char;
200-
else if (word == "double")
201-
kind = dil::TokenKind::kw_double;
202-
else if (word == "dynamic_cast")
203-
kind = dil::TokenKind::kw_dynamic_cast;
204-
else if (word == "false")
205-
kind = dil::TokenKind::kw_false;
206-
else if (word == "float")
207-
kind = dil::TokenKind::kw_float;
208-
else if (word == "int")
209-
kind = dil::TokenKind::kw_int;
210-
else if (word == "long")
211-
kind = dil::TokenKind::kw_long;
212-
else if (word == "nullptr")
213-
kind = dil::TokenKind::kw_nullptr;
214-
else if (word == "reinterpret_cast")
215-
kind = dil::TokenKind::kw_reinterpret_cast;
216-
else if (word == "short")
217-
kind = dil::TokenKind::kw_short;
218-
else if (word == "signed")
219-
kind = dil::TokenKind::kw_signed;
220-
else if (word == "static_cast")
221-
kind = dil::TokenKind::kw_static_cast;
222-
else if (word == "this")
223-
kind = dil::TokenKind::kw_this;
224-
else if (word == "true")
225-
kind = dil::TokenKind::kw_true;
226-
else if (word == "unsigned")
227-
kind = dil::TokenKind::kw_unsigned;
216+
auto iter = Keywords.find(word);
217+
if (iter != Keywords.end())
218+
kind = iter->second;
228219
else
229220
kind = dil::TokenKind::identifier;
230221
UpdateLexedTokens(result, kind, word, position,

0 commit comments

Comments
 (0)