blob: 6cef821e398ae79609443cbdc7fa93d2ad4ec526 [file] [log] [blame]
Daniel Dunbarf353c8c2009-03-16 06:56:51 +00001//===--- 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 Dunbar5c3c1d72009-03-17 22:47:06 +000014#include <string>
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000015
16namespace clang {
17namespace driver {
18 class PipedJob;
19
20/// InputInfo - Wrapper for information about an input source.
21class InputInfo {
22 union {
23 const char *Filename;
24 PipedJob *Pipe;
25 } Data;
26 bool IsPipe;
27 types::ID Type;
28 const char *BaseInput;
29
30public:
31 InputInfo() {}
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000032 InputInfo(types::ID _Type, const char *_BaseInput)
33 : IsPipe(false), Type(_Type), BaseInput(_BaseInput) {
34 Data.Filename = 0;
35 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000036 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 Dunbar5c3c1d72009-03-17 22:47:06 +000057
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 Dunbarf353c8c2009-03-16 06:56:51 +000068};
69
70} // end namespace driver
71} // end namespace clang
72
73#endif