]> granicus.if.org Git - clang/blob - lib/Driver/InputInfo.h
Driver: ConstructJob also needs to know the destination (where to put
[clang] / lib / Driver / InputInfo.h
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 "clang/Driver/Types.h"
14
15 #include <cassert>
16 #include <string>
17
18 namespace clang {
19 namespace driver {
20   class PipedJob;
21
22 /// InputInfo - Wrapper for information about an input source.
23 class InputInfo {
24   union {
25     const char *Filename;
26     PipedJob *Pipe;
27   } Data;
28   bool IsPipe;
29   types::ID Type;
30   const char *BaseInput;
31
32 public:
33   InputInfo() {}
34   InputInfo(types::ID _Type, const char *_BaseInput)
35     : IsPipe(false), Type(_Type), BaseInput(_BaseInput) {
36     Data.Filename = 0;
37   }
38   InputInfo(const char *Filename, types::ID _Type, const char *_BaseInput)
39     : IsPipe(false), Type(_Type), BaseInput(_BaseInput) {
40     Data.Filename = Filename;
41   }
42   InputInfo(PipedJob *Pipe, types::ID _Type, const char *_BaseInput)
43     : IsPipe(true), Type(_Type), BaseInput(_BaseInput) {
44     Data.Pipe = Pipe;
45   }
46
47   bool isPipe() const { return IsPipe; }
48   types::ID getType() const { return Type; }
49   const char *getBaseInput() const { return BaseInput; }
50
51   const char *getInputFilename() const {
52     assert(!isPipe() && "Invalid accessor.");
53     return Data.Filename;
54   }
55   PipedJob &getPipe() const {
56     assert(isPipe() && "Invalid accessor.");
57     return *Data.Pipe;
58   }
59
60   /// getAsString - Return a string name for this input, for
61   /// debugging.
62   std::string getAsString() const {
63     if (isPipe())
64       return "(pipe)";
65     else if (const char *N = getInputFilename())
66       return std::string("\"") + N + '"';
67     else
68       return "(nothing)";
69   }
70 };
71
72 } // end namespace driver
73 } // end namespace clang
74
75 #endif