Skip to content

Commit a8fcda8

Browse files
committed
citnames: clang flags extended
1 parent f7668a8 commit a8fcda8

File tree

4 files changed

+212
-52
lines changed

4 files changed

+212
-52
lines changed

source/citnames/source/semantic/Parsers.cc

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -197,44 +197,38 @@ namespace cs::semantic {
197197
// try to find if the key has an associated instruction
198198
if (const auto candidate = flags_.lower_bound(key); flags_.end() != candidate) {
199199
// exact matches are preferred in all cases.
200-
if (auto result = check_equal(key, candidate); result) {
200+
if (auto result = check_equal(key, *candidate); result) {
201201
return result;
202202
}
203203
// check if the argument is allowed to stick to the flag
204-
if (auto result = check_partial(key, candidate); result) {
204+
if (auto result = check_partial(key, *candidate); result) {
205205
return result;
206206
}
207-
// check if this is the first element or not.
208-
if (flags_.begin() != candidate) {
209-
const auto previous = std::prev(candidate);
210-
if (auto result = check_partial(key, previous); result) {
211-
return result;
212-
}
213-
}
214207
}
215-
// check if the last element is not the one we are looking for.
216-
// (this is a limitation of `lower_bound` method.)
217-
const auto candidate = std::prev(flags_.end());
218-
if (auto result = check_partial(key, candidate); result) {
219-
return result;
208+
// partial match is less likely to be a few steps away from the lower bound,
209+
// therefore search the whole flag list again.
210+
for (const auto candidate : flags_) {
211+
if (auto result = check_partial(key, candidate); result) {
212+
return result;
213+
}
220214
}
221215
return std::nullopt;
222216
}
223217

224218
std::optional<FlagParser::Match>
225-
FlagParser::check_equal(const std::string_view &key, FlagsByName::const_iterator candidate) {
226-
const auto &flag_definition = candidate->second;
227-
if ((is_exact_match_only(flag_definition.match) || is_prefix_match(flag_definition.match)) && key == candidate->first) {
219+
FlagParser::check_equal(const std::string_view &key, const FlagsByName::value_type &candidate) {
220+
const auto &flag_definition = candidate.second;
221+
if ((is_exact_match_only(flag_definition.match) || is_prefix_match(flag_definition.match)) && key == candidate.first) {
228222
const size_t count = count_of_arguments(flag_definition.match);
229223
return std::make_optional(std::make_tuple(count, flag_definition.type));
230224
}
231225
return std::nullopt;
232226
}
233227

234228
std::optional<FlagParser::Match>
235-
FlagParser::check_partial(const std::string_view &key, FlagsByName::const_iterator candidate) {
236-
const auto &flag_definition = candidate->second;
237-
if (const auto extra = split_extra(candidate->first, key); extra) {
229+
FlagParser::check_partial(const std::string_view &key, const FlagsByName::value_type &candidate) {
230+
const auto &flag_definition = candidate.second;
231+
if (const auto extra = split_extra(candidate.first, key); extra) {
238232
const auto flag_matching = classify_flag_matching(extra.value());
239233
switch (flag_matching) {
240234
case FlagMatch::GLUED:

source/citnames/source/semantic/Parsers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ namespace cs::semantic {
162162
std::optional<Match> lookup(const std::string_view &key) const;
163163

164164
[[nodiscard]]
165-
static std::optional<Match> check_equal(const std::string_view& key, FlagsByName::const_iterator candidate);
165+
static std::optional<Match> check_equal(const std::string_view& key, const FlagsByName::value_type &candidate);
166166

167167
[[nodiscard]]
168-
static std::optional<Match> check_partial(const std::string_view& key, FlagsByName::const_iterator candidate);
168+
static std::optional<Match> check_partial(const std::string_view& key, const FlagsByName::value_type &candidate);
169169

170170
FlagsByName const& flags_;
171171
};

0 commit comments

Comments
 (0)