Path: blob/main/contrib/llvm-project/llvm/lib/Frontend/Directive/Spelling.cpp
213799 views
//===-------------------------------------------------------------- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Frontend/Directive/Spelling.h"910#include "llvm/ADT/StringRef.h"11#include "llvm/Support/MathExtras.h"1213#include <cassert>1415using namespace llvm;1617static bool Contains(directive::VersionRange V, int P) {18return V.Min <= P && P <= V.Max;19}2021llvm::StringRef llvm::directive::FindName(22llvm::iterator_range<const directive::Spelling *> Range, unsigned Version) {23assert(llvm::isInt<8 * sizeof(int)>(Version) && "Version value out of range");2425int V = Version;26// Do a linear search to find the first Spelling that contains Version.27// The condition "contains(S, Version)" does not partition the list of28// spellings, so std::[lower|upper]_bound cannot be used.29// In practice the list of spellings is expected to be very short, so30// linear search seems appropriate. In general, an interval tree may be31// a better choice, but in this case it may be an overkill.32for (auto &S : Range) {33if (Contains(S.Versions, V))34return S.Name;35}36return StringRef();37}383940