InputInfo.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
  10. #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
  11. #include "clang/Driver/Types.h"
  12. #include "llvm/Option/Arg.h"
  13. #include <cassert>
  14. #include <string>
  15. namespace clang {
  16. namespace driver {
  17. /// InputInfo - Wrapper for information about an input source.
  18. class InputInfo {
  19. // FIXME: The distinction between filenames and inputarg here is
  20. // gross; we should probably drop the idea of a "linker
  21. // input". Doing so means tweaking pipelining to still create link
  22. // steps when it sees linker inputs (but not treat them as
  23. // arguments), and making sure that arguments get rendered
  24. // correctly.
  25. enum Class {
  26. Nothing,
  27. Filename,
  28. InputArg,
  29. Pipe
  30. };
  31. union {
  32. const char *Filename;
  33. const llvm::opt::Arg *InputArg;
  34. } Data;
  35. Class Kind;
  36. types::ID Type;
  37. const char *BaseInput;
  38. public:
  39. InputInfo() {}
  40. InputInfo(types::ID _Type, const char *_BaseInput)
  41. : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) {
  42. }
  43. InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput)
  44. : Kind(Filename), Type(_Type), BaseInput(_BaseInput) {
  45. Data.Filename = _Filename;
  46. }
  47. InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type,
  48. const char *_BaseInput)
  49. : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) {
  50. Data.InputArg = _InputArg;
  51. }
  52. bool isNothing() const { return Kind == Nothing; }
  53. bool isFilename() const { return Kind == Filename; }
  54. bool isInputArg() const { return Kind == InputArg; }
  55. types::ID getType() const { return Type; }
  56. const char *getBaseInput() const { return BaseInput; }
  57. const char *getFilename() const {
  58. assert(isFilename() && "Invalid accessor.");
  59. return Data.Filename;
  60. }
  61. const llvm::opt::Arg &getInputArg() const {
  62. assert(isInputArg() && "Invalid accessor.");
  63. return *Data.InputArg;
  64. }
  65. /// getAsString - Return a string name for this input, for
  66. /// debugging.
  67. std::string getAsString() const {
  68. if (isFilename())
  69. return std::string("\"") + getFilename() + '"';
  70. else if (isInputArg())
  71. return "(input arg)";
  72. else
  73. return "(nothing)";
  74. }
  75. };
  76. } // end namespace driver
  77. } // end namespace clang
  78. #endif