annotate clang/lib/Driver/InputInfo.h @ 221:79ff65ed7e25

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