blob: 617e70365dd6df824531f57f77dc92d473ed33e2 [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
Daniel Dunbar871adcf2009-03-18 07:06:02 +000013#include "clang/Driver/Types.h"
14
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000015#include <cassert>
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000016#include <string>
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000017
18namespace clang {
19namespace driver {
20 class PipedJob;
21
22/// InputInfo - Wrapper for information about an input source.
23class InputInfo {
24 union {
25 const char *Filename;
26 PipedJob *Pipe;
27 } Data;
28 bool IsPipe;
29 types::ID Type;
30 const char *BaseInput;
31
32public:
33 InputInfo() {}
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000034 InputInfo(types::ID _Type, const char *_BaseInput)
35 : IsPipe(false), Type(_Type), BaseInput(_BaseInput) {
36 Data.Filename = 0;
37 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000038 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 }
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000059
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 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000070};
71
72} // end namespace driver
73} // end namespace clang
74
75#endif