InputInfo.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_DRIVER_INPUTINFO_H
  14. #define LLVM_CLANG_DRIVER_INPUTINFO_H
  15. #include "clang/Driver/Action.h"
  16. #include "clang/Driver/Types.h"
  17. #include "llvm/Option/Arg.h"
  18. #include <cassert>
  19. #include <string>
  20. namespace clang {
  21. namespace driver {
  22. /// InputInfo - Wrapper for information about an input source.
  23. class InputInfo {
  24. // FIXME: The distinction between filenames and inputarg here is
  25. // gross; we should probably drop the idea of a "linker
  26. // input". Doing so means tweaking pipelining to still create link
  27. // steps when it sees linker inputs (but not treat them as
  28. // arguments), and making sure that arguments get rendered
  29. // correctly.
  30. enum Class {
  31. Nothing,
  32. Filename,
  33. InputArg,
  34. Pipe
  35. };
  36. union {
  37. const char *Filename;
  38. const llvm::opt::Arg *InputArg;
  39. } Data;
  40. Class Kind;
  41. const Action* Act;
  42. types::ID Type;
  43. const char *BaseInput;
  44. static types::ID GetActionType(const Action *A) {
  45. return A != nullptr ? A->getType() : types::TY_Nothing;
  46. }
  47. public:
  48. InputInfo() : InputInfo(nullptr, nullptr) {}
  49. InputInfo(const Action *A, const char *_BaseInput)
  50. : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
  51. InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
  52. : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
  53. Data.Filename = _Filename;
  54. }
  55. InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
  56. : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
  57. Data.Filename = _Filename;
  58. }
  59. InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
  60. const char *_BaseInput)
  61. : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
  62. Data.InputArg = _InputArg;
  63. }
  64. InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
  65. const char *_BaseInput)
  66. : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
  67. Data.InputArg = _InputArg;
  68. }
  69. bool isNothing() const { return Kind == Nothing; }
  70. bool isFilename() const { return Kind == Filename; }
  71. bool isInputArg() const { return Kind == InputArg; }
  72. types::ID getType() const { return Type; }
  73. const char *getBaseInput() const { return BaseInput; }
  74. /// The action for which this InputInfo was created. May be null.
  75. const Action *getAction() const { return Act; }
  76. void setAction(const Action *A) { Act = A; }
  77. const char *getFilename() const {
  78. assert(isFilename() && "Invalid accessor.");
  79. return Data.Filename;
  80. }
  81. const llvm::opt::Arg &getInputArg() const {
  82. assert(isInputArg() && "Invalid accessor.");
  83. return *Data.InputArg;
  84. }
  85. /// getAsString - Return a string name for this input, for
  86. /// debugging.
  87. std::string getAsString() const {
  88. if (isFilename())
  89. return std::string("\"") + getFilename() + '"';
  90. else if (isInputArg())
  91. return "(input arg)";
  92. else
  93. return "(nothing)";
  94. }
  95. };
  96. } // end namespace driver
  97. } // end namespace clang
  98. #endif
  99. #ifdef __GNUC__
  100. #pragma GCC diagnostic pop
  101. #endif