1 //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
11 #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/Types.h"
15 #include "llvm/Option/Arg.h"
22 /// InputInfo - Wrapper for information about an input source.
24 // FIXME: The distinction between filenames and inputarg here is
25 // gross; we should probably drop the idea of a "linker
26 // input". Doing so means tweaking pipelining to still create link
27 // steps when it sees linker inputs (but not treat them as
28 // arguments), and making sure that arguments get rendered
39 const llvm::opt::Arg *InputArg;
44 const char *BaseInput;
46 static types::ID GetActionType(const Action *A) {
47 return A != nullptr ? A->getType() : types::TY_Nothing;
51 InputInfo() : InputInfo(nullptr, nullptr) {}
52 InputInfo(const Action *A, const char *_BaseInput)
53 : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
55 InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
56 : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
57 Data.Filename = _Filename;
59 InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
60 : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
61 Data.Filename = _Filename;
64 InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
65 const char *_BaseInput)
66 : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
67 Data.InputArg = _InputArg;
69 InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
70 const char *_BaseInput)
71 : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
72 Data.InputArg = _InputArg;
75 bool isNothing() const { return Kind == Nothing; }
76 bool isFilename() const { return Kind == Filename; }
77 bool isInputArg() const { return Kind == InputArg; }
78 types::ID getType() const { return Type; }
79 const char *getBaseInput() const { return BaseInput; }
80 /// The action for which this InputInfo was created. May be null.
81 const Action *getAction() const { return Act; }
82 void setAction(const Action *A) { Act = A; }
84 const char *getFilename() const {
85 assert(isFilename() && "Invalid accessor.");
88 const llvm::opt::Arg &getInputArg() const {
89 assert(isInputArg() && "Invalid accessor.");
90 return *Data.InputArg;
93 /// getAsString - Return a string name for this input, for
95 std::string getAsString() const {
97 return std::string("\"") + getFilename() + '"';
98 else if (isInputArg())
105 } // end namespace driver
106 } // end namespace clang