Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 1 | //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef CLANG_LIB_DRIVER_INPUTINFO_H_ |
| 11 | #define CLANG_LIB_DRIVER_INPUTINFO_H_ |
| 12 | |
| 13 | #include <cassert> |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 14 | #include <string> |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 15 | |
| 16 | namespace clang { |
| 17 | namespace driver { |
| 18 | class PipedJob; |
| 19 | |
| 20 | /// InputInfo - Wrapper for information about an input source. |
| 21 | class InputInfo { |
| 22 | union { |
| 23 | const char *Filename; |
| 24 | PipedJob *Pipe; |
| 25 | } Data; |
| 26 | bool IsPipe; |
| 27 | types::ID Type; |
| 28 | const char *BaseInput; |
| 29 | |
| 30 | public: |
| 31 | InputInfo() {} |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 32 | InputInfo(types::ID _Type, const char *_BaseInput) |
| 33 | : IsPipe(false), Type(_Type), BaseInput(_BaseInput) { |
| 34 | Data.Filename = 0; |
| 35 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 36 | InputInfo(const char *Filename, types::ID _Type, const char *_BaseInput) |
| 37 | : IsPipe(false), Type(_Type), BaseInput(_BaseInput) { |
| 38 | Data.Filename = Filename; |
| 39 | } |
| 40 | InputInfo(PipedJob *Pipe, types::ID _Type, const char *_BaseInput) |
| 41 | : IsPipe(true), Type(_Type), BaseInput(_BaseInput) { |
| 42 | Data.Pipe = Pipe; |
| 43 | } |
| 44 | |
| 45 | bool isPipe() const { return IsPipe; } |
| 46 | types::ID getType() const { return Type; } |
| 47 | const char *getBaseInput() const { return BaseInput; } |
| 48 | |
| 49 | const char *getInputFilename() const { |
| 50 | assert(!isPipe() && "Invalid accessor."); |
| 51 | return Data.Filename; |
| 52 | } |
| 53 | PipedJob &getPipe() const { |
| 54 | assert(isPipe() && "Invalid accessor."); |
| 55 | return *Data.Pipe; |
| 56 | } |
Daniel Dunbar | 5c3c1d7 | 2009-03-17 22:47:06 +0000 | [diff] [blame] | 57 | |
| 58 | /// getAsString - Return a string name for this input, for |
| 59 | /// debugging. |
| 60 | std::string getAsString() const { |
| 61 | if (isPipe()) |
| 62 | return "(pipe)"; |
| 63 | else if (const char *N = getInputFilename()) |
| 64 | return std::string("\"") + N + '"'; |
| 65 | else |
| 66 | return "(nothing)"; |
| 67 | } |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // end namespace driver |
| 71 | } // end namespace clang |
| 72 | |
| 73 | #endif |