blob: 2a2f4b995d2a62a4ab2dd524f58cc7eeed08e393 [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 {
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000020
21/// InputInfo - Wrapper for information about an input source.
22class InputInfo {
Daniel Dunbar115a7922009-03-19 07:29:38 +000023 // FIXME: The distinction between filenames and inputarg here is
24 // gross; we should probably drop the idea of a "linker
25 // input". Doing so means tweaking pipelining to still create link
26 // steps when it sees linker inputs (but not treat them as
27 // arguments), and making sure that arguments get rendered
28 // correctly.
29 enum Class {
30 Nothing,
31 Filename,
32 InputArg,
33 Pipe
34 };
35
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000036 union {
37 const char *Filename;
Daniel Dunbar115a7922009-03-19 07:29:38 +000038 const Arg *InputArg;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000039 } Data;
Daniel Dunbar115a7922009-03-19 07:29:38 +000040 Class Kind;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000041 types::ID Type;
42 const char *BaseInput;
43
44public:
45 InputInfo() {}
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000046 InputInfo(types::ID _Type, const char *_BaseInput)
Daniel Dunbar115a7922009-03-19 07:29:38 +000047 : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) {
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000048 }
Daniel Dunbar115a7922009-03-19 07:29:38 +000049 InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput)
50 : Kind(Filename), Type(_Type), BaseInput(_BaseInput) {
51 Data.Filename = _Filename;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000052 }
Daniel Dunbar115a7922009-03-19 07:29:38 +000053 InputInfo(const Arg *_InputArg, types::ID _Type, const char *_BaseInput)
54 : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) {
55 Data.InputArg = _InputArg;
56 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000057
Daniel Dunbar115a7922009-03-19 07:29:38 +000058 bool isNothing() const { return Kind == Nothing; }
59 bool isFilename() const { return Kind == Filename; }
60 bool isInputArg() const { return Kind == InputArg; }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000061 types::ID getType() const { return Type; }
62 const char *getBaseInput() const { return BaseInput; }
63
Daniel Dunbar115a7922009-03-19 07:29:38 +000064 const char *getFilename() const {
65 assert(isFilename() && "Invalid accessor.");
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000066 return Data.Filename;
67 }
Daniel Dunbar115a7922009-03-19 07:29:38 +000068 const Arg &getInputArg() const {
69 assert(isInputArg() && "Invalid accessor.");
70 return *Data.InputArg;
71 }
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000072
73 /// getAsString - Return a string name for this input, for
74 /// debugging.
75 std::string getAsString() const {
Daniel Dunbar7c1e4652010-08-02 02:38:21 +000076 if (isFilename())
Daniel Dunbar115a7922009-03-19 07:29:38 +000077 return std::string("\"") + getFilename() + '"';
78 else if (isInputArg())
79 return "(input arg)";
Daniel Dunbar5c3c1d72009-03-17 22:47:06 +000080 else
81 return "(nothing)";
82 }
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000083};
84
85} // end namespace driver
86} // end namespace clang
87
88#endif