]> granicus.if.org Git - clang/blob - lib/Driver/InputInfo.h
Driver: Add -ccc-print-bindings option (for testing); the Python
[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 <cassert>
14 #include <string>
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() {}
32   InputInfo(types::ID _Type, const char *_BaseInput)
33     : IsPipe(false), Type(_Type), BaseInput(_BaseInput) {
34     Data.Filename = 0;
35   }
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   }
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   }
68 };
69
70 } // end namespace driver
71 } // end namespace clang
72
73 #endif