1193326Sed//===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed 10193326Sed#ifndef CLANG_LIB_DRIVER_INPUTINFO_H_ 11193326Sed#define CLANG_LIB_DRIVER_INPUTINFO_H_ 12193326Sed 13249423Sdim#include "clang/Driver/Arg.h" 14193326Sed#include "clang/Driver/Types.h" 15193326Sed#include <cassert> 16193326Sed#include <string> 17193326Sed 18193326Sednamespace clang { 19193326Sednamespace driver { 20193326Sed 21193326Sed/// InputInfo - Wrapper for information about an input source. 22193326Sedclass InputInfo { 23193326Sed // FIXME: The distinction between filenames and inputarg here is 24193326Sed // gross; we should probably drop the idea of a "linker 25193326Sed // input". Doing so means tweaking pipelining to still create link 26193326Sed // steps when it sees linker inputs (but not treat them as 27193326Sed // arguments), and making sure that arguments get rendered 28193326Sed // correctly. 29193326Sed enum Class { 30193326Sed Nothing, 31193326Sed Filename, 32193326Sed InputArg, 33193326Sed Pipe 34193326Sed }; 35193326Sed 36193326Sed union { 37193326Sed const char *Filename; 38193326Sed const Arg *InputArg; 39193326Sed } Data; 40193326Sed Class Kind; 41193326Sed types::ID Type; 42193326Sed const char *BaseInput; 43193326Sed 44193326Sedpublic: 45193326Sed InputInfo() {} 46193326Sed InputInfo(types::ID _Type, const char *_BaseInput) 47193326Sed : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { 48193326Sed } 49193326Sed InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) 50193326Sed : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { 51193326Sed Data.Filename = _Filename; 52193326Sed } 53193326Sed InputInfo(const Arg *_InputArg, types::ID _Type, const char *_BaseInput) 54193326Sed : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { 55193326Sed Data.InputArg = _InputArg; 56193326Sed } 57193326Sed 58193326Sed bool isNothing() const { return Kind == Nothing; } 59193326Sed bool isFilename() const { return Kind == Filename; } 60193326Sed bool isInputArg() const { return Kind == InputArg; } 61193326Sed types::ID getType() const { return Type; } 62193326Sed const char *getBaseInput() const { return BaseInput; } 63193326Sed 64193326Sed const char *getFilename() const { 65193326Sed assert(isFilename() && "Invalid accessor."); 66193326Sed return Data.Filename; 67193326Sed } 68193326Sed const Arg &getInputArg() const { 69193326Sed assert(isInputArg() && "Invalid accessor."); 70193326Sed return *Data.InputArg; 71193326Sed } 72193326Sed 73193326Sed /// getAsString - Return a string name for this input, for 74193326Sed /// debugging. 75193326Sed std::string getAsString() const { 76212904Sdim if (isFilename()) 77193326Sed return std::string("\"") + getFilename() + '"'; 78193326Sed else if (isInputArg()) 79193326Sed return "(input arg)"; 80193326Sed else 81193326Sed return "(nothing)"; 82193326Sed } 83193326Sed}; 84193326Sed 85193326Sed} // end namespace driver 86193326Sed} // end namespace clang 87193326Sed 88193326Sed#endif 89