1 //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_DRIVER_INPUTINFO_H
10 #define LLVM_CLANG_DRIVER_INPUTINFO_H
12 #include "clang/Driver/Action.h"
13 #include "clang/Driver/Types.h"
14 #include "llvm/Option/Arg.h"
21 /// InputInfo - Wrapper for information about an input source.
23 // FIXME: The distinction between filenames and inputarg here is
24 // gross; we should probably drop the idea of a "linker
25 // input". Doing so means tweaking pipelining to still create link
26 // steps when it sees linker inputs (but not treat them as
27 // arguments), and making sure that arguments get rendered
38 const llvm::opt::Arg *InputArg;
43 const char *BaseInput;
45 static types::ID GetActionType(const Action *A) {
46 return A != nullptr ? A->getType() : types::TY_Nothing;
50 InputInfo() : InputInfo(nullptr, nullptr) {}
51 InputInfo(const Action *A, const char *_BaseInput)
52 : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
54 InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
55 : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
56 Data.Filename = _Filename;
58 InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
59 : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
60 Data.Filename = _Filename;
63 InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
64 const char *_BaseInput)
65 : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
66 Data.InputArg = _InputArg;
68 InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
69 const char *_BaseInput)
70 : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
71 Data.InputArg = _InputArg;
74 bool isNothing() const { return Kind == Nothing; }
75 bool isFilename() const { return Kind == Filename; }
76 bool isInputArg() const { return Kind == InputArg; }
77 types::ID getType() const { return Type; }
78 const char *getBaseInput() const { return BaseInput; }
79 /// The action for which this InputInfo was created. May be null.
80 const Action *getAction() const { return Act; }
81 void setAction(const Action *A) { Act = A; }
83 const char *getFilename() const {
84 assert(isFilename() && "Invalid accessor.");
87 const llvm::opt::Arg &getInputArg() const {
88 assert(isInputArg() && "Invalid accessor.");
89 return *Data.InputArg;
92 /// getAsString - Return a string name for this input, for
94 std::string getAsString() const {
96 return std::string("\"") + getFilename() + '"';
97 else if (isInputArg())
104 } // end namespace driver
105 } // end namespace clang