clang API Documentation
00001 //===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H 00011 #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H 00012 00013 #include "clang/Driver/Types.h" 00014 #include "llvm/Option/Arg.h" 00015 #include <cassert> 00016 #include <string> 00017 00018 namespace clang { 00019 namespace driver { 00020 00021 /// InputInfo - Wrapper for information about an input source. 00022 class InputInfo { 00023 // FIXME: The distinction between filenames and inputarg here is 00024 // gross; we should probably drop the idea of a "linker 00025 // input". Doing so means tweaking pipelining to still create link 00026 // steps when it sees linker inputs (but not treat them as 00027 // arguments), and making sure that arguments get rendered 00028 // correctly. 00029 enum Class { 00030 Nothing, 00031 Filename, 00032 InputArg, 00033 Pipe 00034 }; 00035 00036 union { 00037 const char *Filename; 00038 const llvm::opt::Arg *InputArg; 00039 } Data; 00040 Class Kind; 00041 types::ID Type; 00042 const char *BaseInput; 00043 00044 public: 00045 InputInfo() {} 00046 InputInfo(types::ID _Type, const char *_BaseInput) 00047 : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { 00048 } 00049 InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) 00050 : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { 00051 Data.Filename = _Filename; 00052 } 00053 InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type, 00054 const char *_BaseInput) 00055 : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { 00056 Data.InputArg = _InputArg; 00057 } 00058 00059 bool isNothing() const { return Kind == Nothing; } 00060 bool isFilename() const { return Kind == Filename; } 00061 bool isInputArg() const { return Kind == InputArg; } 00062 types::ID getType() const { return Type; } 00063 const char *getBaseInput() const { return BaseInput; } 00064 00065 const char *getFilename() const { 00066 assert(isFilename() && "Invalid accessor."); 00067 return Data.Filename; 00068 } 00069 const llvm::opt::Arg &getInputArg() const { 00070 assert(isInputArg() && "Invalid accessor."); 00071 return *Data.InputArg; 00072 } 00073 00074 /// getAsString - Return a string name for this input, for 00075 /// debugging. 00076 std::string getAsString() const { 00077 if (isFilename()) 00078 return std::string("\"") + getFilename() + '"'; 00079 else if (isInputArg()) 00080 return "(input arg)"; 00081 else 00082 return "(nothing)"; 00083 } 00084 }; 00085 00086 } // end namespace driver 00087 } // end namespace clang 00088 00089 #endif