Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:52

0001 //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_DRIVER_INPUTINFO_H
0010 #define LLVM_CLANG_DRIVER_INPUTINFO_H
0011 
0012 #include "clang/Driver/Action.h"
0013 #include "clang/Driver/Types.h"
0014 #include "llvm/Option/Arg.h"
0015 #include <cassert>
0016 #include <string>
0017 
0018 namespace clang {
0019 namespace driver {
0020 
0021 /// InputInfo - Wrapper for information about an input source.
0022 class InputInfo {
0023   // FIXME: The distinction between filenames and inputarg here is
0024   // gross; we should probably drop the idea of a "linker
0025   // input". Doing so means tweaking pipelining to still create link
0026   // steps when it sees linker inputs (but not treat them as
0027   // arguments), and making sure that arguments get rendered
0028   // correctly.
0029   enum Class {
0030     Nothing,
0031     Filename,
0032     InputArg,
0033     Pipe
0034   };
0035 
0036   union {
0037     const char *Filename;
0038     const llvm::opt::Arg *InputArg;
0039   } Data;
0040   Class Kind;
0041   const Action* Act;
0042   types::ID Type;
0043   const char *BaseInput;
0044 
0045   static types::ID GetActionType(const Action *A) {
0046     return A != nullptr ? A->getType() : types::TY_Nothing;
0047   }
0048 
0049 public:
0050   InputInfo() : InputInfo(nullptr, nullptr) {}
0051   InputInfo(const Action *A, const char *_BaseInput)
0052       : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {}
0053 
0054   InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput)
0055       : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
0056     Data.Filename = _Filename;
0057   }
0058   InputInfo(const Action *A, const char *_Filename, const char *_BaseInput)
0059       : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
0060     Data.Filename = _Filename;
0061   }
0062 
0063   InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg,
0064             const char *_BaseInput)
0065       : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) {
0066     Data.InputArg = _InputArg;
0067   }
0068   InputInfo(const Action *A, const llvm::opt::Arg *_InputArg,
0069             const char *_BaseInput)
0070       : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {
0071     Data.InputArg = _InputArg;
0072   }
0073 
0074   bool isNothing() const { return Kind == Nothing; }
0075   bool isFilename() const { return Kind == Filename; }
0076   bool isInputArg() const { return Kind == InputArg; }
0077   types::ID getType() const { return Type; }
0078   const char *getBaseInput() const { return BaseInput; }
0079   /// The action for which this InputInfo was created.  May be null.
0080   const Action *getAction() const { return Act; }
0081   void setAction(const Action *A) { Act = A; }
0082 
0083   const char *getFilename() const {
0084     assert(isFilename() && "Invalid accessor.");
0085     return Data.Filename;
0086   }
0087   const llvm::opt::Arg &getInputArg() const {
0088     assert(isInputArg() && "Invalid accessor.");
0089     return *Data.InputArg;
0090   }
0091 
0092   /// getAsString - Return a string name for this input, for
0093   /// debugging.
0094   std::string getAsString() const {
0095     if (isFilename())
0096       return std::string("\"") + getFilename() + '"';
0097     else if (isInputArg())
0098       return "(input arg)";
0099     else
0100       return "(nothing)";
0101   }
0102 };
0103 
0104 } // end namespace driver
0105 } // end namespace clang
0106 
0107 #endif