| 1 | //===-------------------------------------------------------------- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/Frontend/Directive/Spelling.h" |
| 10 | |
| 11 | #include "llvm/ADT/StringRef.h" |
| 12 | #include "llvm/Frontend/Directive/Version.h" |
| 13 | |
| 14 | #include <cassert> |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | llvm::StringRef llvm::directive::FindName( |
| 19 | llvm::iterator_range<const directive::Spelling *> Range, |
| 20 | directive::Version Ver) { |
| 21 | // Do a linear search to find the first Spelling that contains Version. |
| 22 | // The condition "contains(S, Version)" does not partition the list of |
| 23 | // spellings, so std::[lower|upper]_bound cannot be used. |
| 24 | // In practice the list of spellings is expected to be very short, so |
| 25 | // linear search seems appropriate. In general, an interval tree may be |
| 26 | // a better choice, but in this case it may be an overkill. |
| 27 | for (auto &S : Range) { |
| 28 | if (S.Versions.contains(V: Ver)) |
| 29 | return S.Name; |
| 30 | } |
| 31 | return StringRef(); |
| 32 | } |
| 33 | |