clang  3.7.0
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/Types.h"
14 #include "llvm/Option/Arg.h"
15 #include <cassert>
16 #include <string>
17 
18 namespace clang {
19 namespace driver {
20 
21 /// InputInfo - Wrapper for information about an input source.
22 class InputInfo {
23  // 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 
36  union {
37  const char *Filename;
38  const llvm::opt::Arg *InputArg;
39  } Data;
40  Class Kind;
42  const char *BaseInput;
43 
44 public:
45  InputInfo() {}
46  InputInfo(types::ID _Type, const char *_BaseInput)
47  : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) {
48  }
49  InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput)
50  : Kind(Filename), Type(_Type), BaseInput(_BaseInput) {
51  Data.Filename = _Filename;
52  }
53  InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type,
54  const char *_BaseInput)
55  : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) {
56  Data.InputArg = _InputArg;
57  }
58 
59  bool isNothing() const { return Kind == Nothing; }
60  bool isFilename() const { return Kind == Filename; }
61  bool isInputArg() const { return Kind == InputArg; }
62  types::ID getType() const { return Type; }
63  const char *getBaseInput() const { return BaseInput; }
64 
65  const char *getFilename() const {
66  assert(isFilename() && "Invalid accessor.");
67  return Data.Filename;
68  }
69  const llvm::opt::Arg &getInputArg() const {
70  assert(isInputArg() && "Invalid accessor.");
71  return *Data.InputArg;
72  }
73 
74  /// getAsString - Return a string name for this input, for
75  /// debugging.
76  std::string getAsString() const {
77  if (isFilename())
78  return std::string("\"") + getFilename() + '"';
79  else if (isInputArg())
80  return "(input arg)";
81  else
82  return "(nothing)";
83  }
84 };
85 
86 } // end namespace driver
87 } // end namespace clang
88 
89 #endif
types::ID getType() const
Definition: InputInfo.h:62
const llvm::opt::Arg * InputArg
Definition: InputInfo.h:38
bool isFilename() const
Definition: InputInfo.h:60
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput)
Definition: InputInfo.h:49
const char * getFilename() const
Definition: InputInfo.h:65
Kind
bool isInputArg() const
Definition: InputInfo.h:61
const llvm::opt::Arg & getInputArg() const
Definition: InputInfo.h:69
std::string getAsString() const
Definition: InputInfo.h:76
InputInfo(types::ID _Type, const char *_BaseInput)
Definition: InputInfo.h:46
bool isNothing() const
Definition: InputInfo.h:59
const char * getBaseInput() const
Definition: InputInfo.h:63
const char * Filename
Definition: InputInfo.h:37
InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type, const char *_BaseInput)
Definition: InputInfo.h:53