aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Option/Arg.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Option/Arg.h')
-rw-r--r--include/llvm/Option/Arg.h31
1 files changed, 25 insertions, 6 deletions
diff --git a/include/llvm/Option/Arg.h b/include/llvm/Option/Arg.h
index d0086bb6d611..22e2bcf06a6e 100644
--- a/include/llvm/Option/Arg.h
+++ b/include/llvm/Option/Arg.h
@@ -1,9 +1,8 @@
//===- Arg.h - Parsed Argument Classes --------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
@@ -59,6 +58,11 @@ private:
/// The argument values, as C strings.
SmallVector<const char *, 2> Values;
+ /// If this arg was created through an alias, this is the original alias arg.
+ /// For example, *this might be "-finput-charset=utf-8" and Alias might
+ /// point to an arg representing "/source-charset:utf-8".
+ std::unique_ptr<Arg> Alias;
+
public:
Arg(const Option Opt, StringRef Spelling, unsigned Index,
const Arg *BaseArg = nullptr);
@@ -71,7 +75,15 @@ public:
~Arg();
const Option &getOption() const { return Opt; }
+
+ /// Returns the used prefix and name of the option:
+ /// For `--foo=bar`, returns `--foo=`.
+ /// This is often the wrong function to call:
+ /// * Use `getValue()` to get `bar`.
+ /// * Use `getAsString()` to get a string suitable for printing an Arg in
+ /// a diagnostic.
StringRef getSpelling() const { return Spelling; }
+
unsigned getIndex() const { return Index; }
/// Return the base argument which generated this arg.
@@ -83,6 +95,11 @@ public:
}
void setBaseArg(const Arg *BaseArg) { this->BaseArg = BaseArg; }
+ /// Args are converted to their unaliased form. For args that originally
+ /// came from an alias, this returns the alias the arg was produced from.
+ const Arg* getAlias() const { return Alias.get(); }
+ void setAlias(std::unique_ptr<Arg> Alias) { this->Alias = std::move(Alias); }
+
bool getOwnsValues() const { return OwnsValues; }
void setOwnsValues(bool Value) const { OwnsValues = Value; }
@@ -120,8 +137,10 @@ public:
void print(raw_ostream &O) const;
void dump() const;
- /// Return a formatted version of the argument and
- /// its values, for debugging and diagnostics.
+ /// Return a formatted version of the argument and its values, for
+ /// diagnostics. Since this is for diagnostics, if this Arg was produced
+ /// through an alias, this returns the string representation of the alias
+ /// that the user wrote.
std::string getAsString(const ArgList &Args) const;
};