| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H |
| 10 | #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H |
| 11 | |
| 12 | #include "clang/Driver/Action.h" |
| 13 | #include "clang/Driver/Types.h" |
| 14 | #include "llvm/Option/Arg.h" |
| 15 | #include <cassert> |
| 16 | #include <string> |
| 17 | |
| 18 | namespace clang { |
| 19 | namespace driver { |
| 20 | |
| 21 | |
| 22 | class InputInfo { |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | enum Class { |
| 30 | Nothing, |
| 31 | Filename, |
| 32 | InputArg, |
| 33 | Pipe |
| 34 | }; |
| 35 | |
| 36 | union { |
| 37 | const char *Filename; |
| 38 | const llvm::opt::Arg *InputArg; |
| 39 | } Data; |
| 40 | Class Kind; |
| 41 | const Action* Act; |
| 42 | types::ID Type; |
| 43 | const char *BaseInput; |
| 44 | |
| 45 | static types::ID GetActionType(const Action *A) { |
| 46 | return A != nullptr ? A->getType() : types::TY_Nothing; |
| 47 | } |
| 48 | |
| 49 | public: |
| 50 | InputInfo() : InputInfo(nullptr, nullptr) {} |
| 51 | InputInfo(const Action *A, const char *_BaseInput) |
| 52 | : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {} |
| 53 | |
| 54 | InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput) |
| 55 | : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) { |
| 56 | Data.Filename = _Filename; |
| 57 | } |
| 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; |
| 61 | } |
| 62 | |
| 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; |
| 67 | } |
| 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; |
| 72 | } |
| 73 | |
| 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 | |
| 80 | const Action *getAction() const { return Act; } |
| 81 | void setAction(const Action *A) { Act = A; } |
| 82 | |
| 83 | const char *getFilename() const { |
| 84 | (0) . __assert_fail ("isFilename() && \"Invalid accessor.\"", "/home/seafit/code_projects/clang_source/clang/lib/Driver/InputInfo.h", 84, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isFilename() && "Invalid accessor."); |
| 85 | return Data.Filename; |
| 86 | } |
| 87 | const llvm::opt::Arg &getInputArg() const { |
| 88 | (0) . __assert_fail ("isInputArg() && \"Invalid accessor.\"", "/home/seafit/code_projects/clang_source/clang/lib/Driver/InputInfo.h", 88, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isInputArg() && "Invalid accessor."); |
| 89 | return *Data.InputArg; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | |
| 94 | std::string getAsString() const { |
| 95 | if (isFilename()) |
| 96 | return std::string("\"") + getFilename() + '"'; |
| 97 | else if (isInputArg()) |
| 98 | return "(input arg)"; |
| 99 | else |
| 100 | return "(nothing)"; |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | #endif |
| 108 | |