clang  6.0.0svn
InputInfo.h
Go to the documentation of this file.
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 
10 #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
11 #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
12 
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/Types.h"
15 #include "llvm/Option/Arg.h"
16 #include <cassert>
17 #include <string>
18 
19 namespace clang {
20 namespace driver {
21 
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 
37  union {
38  const char *Filename;
39  const llvm::opt::Arg *InputArg;
40  } Data;
41  Class Kind;
42  const Action* Act;
44  const char *BaseInput;
45 
46  static types::ID GetActionType(const Action *A) {
47  return A != nullptr ? A->getType() : types::TY_Nothing;
48  }
49 
50 public:
51  InputInfo() : InputInfo(nullptr, nullptr) {}
52  InputInfo(const Action *A, const char *_BaseInput)
53  : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
54 
55  InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
56  : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
57  Data.Filename = _Filename;
58  }
59  InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
60  : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
61  Data.Filename = _Filename;
62  }
63 
64  InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
65  const char *_BaseInput)
66  : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
67  Data.InputArg = _InputArg;
68  }
69  InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
70  const char *_BaseInput)
71  : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
72  Data.InputArg = _InputArg;
73  }
74 
75  bool isNothing() const { return Kind == Nothing; }
76  bool isFilename() const { return Kind == Filename; }
77  bool isInputArg() const { return Kind == InputArg; }
78  types::ID getType() const { return Type; }
79  const char *getBaseInput() const { return BaseInput; }
80  /// The action for which this InputInfo was created. May be null.
81  const Action *getAction() const { return Act; }
82  void setAction(const Action *A) { Act = A; }
83 
84  const char *getFilename() const {
85  assert(isFilename() && "Invalid accessor.");
86  return Data.Filename;
87  }
88  const llvm::opt::Arg &getInputArg() const {
89  assert(isInputArg() && "Invalid accessor.");
90  return *Data.InputArg;
91  }
92 
93  /// getAsString - Return a string name for this input, for
94  /// debugging.
95  std::string getAsString() const {
96  if (isFilename())
97  return std::string("\"") + getFilename() + '"';
98  else if (isInputArg())
99  return "(input arg)";
100  else
101  return "(nothing)";
102  }
103 };
104 
105 } // end namespace driver
106 } // end namespace clang
107 
108 #endif
InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg, const char *_BaseInput)
Definition: InputInfo.h:64
const llvm::opt::Arg * InputArg
Definition: InputInfo.h:39
The base class of the type hierarchy.
Definition: Type.h:1353
InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
Definition: InputInfo.h:59
const char * getFilename() const
Definition: InputInfo.h:84
const Action * getAction() const
The action for which this InputInfo was created. May be null.
Definition: InputInfo.h:81
InputInfo(const Action *A, const char *_BaseInput)
Definition: InputInfo.h:52
Action - Represent an abstract compilation step to perform.
Definition: Action.h:45
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
types::ID getType() const
Definition: Action.h:132
void setAction(const Action *A)
Definition: InputInfo.h:82
types::ID getType() const
Definition: InputInfo.h:78
InputInfo(const Action *A, const llvm::opt::Arg *_InputArg, const char *_BaseInput)
Definition: InputInfo.h:69
std::string getAsString() const
getAsString - Return a string name for this input, for debugging.
Definition: InputInfo.h:95
InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
Definition: InputInfo.h:55
bool isInputArg() const
Definition: InputInfo.h:77
Kind
const llvm::opt::Arg & getInputArg() const
Definition: InputInfo.h:88
Dataflow Directional Tag Classes.
bool isNothing() const
Definition: InputInfo.h:75
const char * getBaseInput() const
Definition: InputInfo.h:79
bool isFilename() const
Definition: InputInfo.h:76
const char * Filename
Definition: InputInfo.h:38