clang 10.0.0git

OptionUtils.cpp
Go to the documentation of this file.
1 //===--- OptionUtils.cpp - Utilities for command line arguments -----------===//
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 "clang/Basic/Diagnostic.h"
10 #include "clang/Basic/DiagnosticDriver.h"
11 #include "clang/Driver/OptionUtils.h"
12 #include "llvm/Option/ArgList.h"
13
14 using namespace clang;
15 using namespace llvm::opt;
16
17 namespace {
18 template <typename IntTy>
19 IntTy getLastArgIntValueImpl(const ArgList &Args, OptSpecifier Id,
20 IntTy Default, DiagnosticsEngine *Diags,
21 unsigned Base) {
22 IntTy Res = Default;
23 if (Arg *A = Args.getLastArg(Id)) {
24 if (StringRef(A->getValue()).getAsInteger(Base, Res)) {
25 if (Diags)
26 Diags->Report(diag::err_drv_invalid_int_value)
27 << A->getAsString(Args) << A->getValue();
28 }
29 }
30 return Res;
31 }
32 } // namespace
33
34 namespace clang {
35
36 int getLastArgIntValue(const ArgList &Args, OptSpecifier Id, int Default,
37 DiagnosticsEngine *Diags, unsigned Base) {
38 return getLastArgIntValueImpl<int>(Args, Id, Default, Diags, Base);
39 }
40
41 uint64_t getLastArgUInt64Value(const ArgList &Args, OptSpecifier Id,
42 uint64_t Default, DiagnosticsEngine *Diags,
43 unsigned Base) {
44 return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags, Base);
45 }
46
47 } // namespace clang
OptionUtils.h
Base
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1300
clang::getLastArgUInt64Value
uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, uint64_t Default, DiagnosticsEngine *Diags=nullptr, unsigned Base=0)
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Diagnostic.h
Defines the Diagnostic-related interfaces.
llvm::opt
Definition: Action.h:23
Id
int Id
Definition: ASTDiff.cpp:190
clang::getLastArgIntValue
int getLastArgIntValue(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, int Default, DiagnosticsEngine *Diags=nullptr, unsigned Base=0)
Return the value of the last argument as an integer, or a default.
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::StructuralEquivalenceKind::Default
DiagnosticDriver.h