Path: blob/main/contrib/llvm-project/clang/lib/Driver/OptionUtils.cpp
35234 views
//===--- OptionUtils.cpp - Utilities for command line arguments -----------===//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 "clang/Basic/Diagnostic.h"9#include "clang/Basic/DiagnosticDriver.h"10#include "clang/Driver/OptionUtils.h"11#include "llvm/Option/ArgList.h"1213using namespace clang;14using namespace llvm::opt;1516namespace {17template <typename IntTy>18IntTy getLastArgIntValueImpl(const ArgList &Args, OptSpecifier Id,19IntTy Default, DiagnosticsEngine *Diags,20unsigned Base) {21IntTy Res = Default;22if (Arg *A = Args.getLastArg(Id)) {23if (StringRef(A->getValue()).getAsInteger(Base, Res)) {24if (Diags)25Diags->Report(diag::err_drv_invalid_int_value)26<< A->getAsString(Args) << A->getValue();27}28}29return Res;30}31} // namespace3233namespace clang {3435int getLastArgIntValue(const ArgList &Args, OptSpecifier Id, int Default,36DiagnosticsEngine *Diags, unsigned Base) {37return getLastArgIntValueImpl<int>(Args, Id, Default, Diags, Base);38}3940uint64_t getLastArgUInt64Value(const ArgList &Args, OptSpecifier Id,41uint64_t Default, DiagnosticsEngine *Diags,42unsigned Base) {43return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags, Base);44}4546} // namespace clang474849