text: //===--- FileTypes.cpp - Input & output formats used by the tools ---------===//
  //
  // This source file is part of the Swift.org open source project
  //
  // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
  // Licensed under Apache License v2.0 with Runtime Library Exception
  //
  // See https://swift.org/LICENSE.txt for license information
  // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
  //
  //===----------------------------------------------------------------------===//
  
  #include "swift/Basic/FileTypes.h"
  
  #include "swift/Strings.h"
  #include "llvm/ADT/STLExtras.h"
  #include "llvm/ADT/StringSwitch.h"
  #include "llvm/Support/ErrorHandling.h"
  
  using namespace swift;
  using namespace swift::file_types;
  
  namespace {
  struct TypeInfo {
    const char *Name;
    const char *Flags;
    const char *Extension;
  };
  } // end anonymous namespace
  
  static const TypeInfo TypeInfos[] = {
  #define TYPE(NAME, ID, EXTENSION, FLAGS) \
    { NAME, FLAGS, EXTENSION },
  #include "swift/Basic/FileTypes.def"
  };
  
  static const TypeInfo &getInfo(unsigned Id) {
    assert(Id >= 0 && Id < TY_INVALID && "Invalid Type ID.");
    return TypeInfos[Id];
  }
  
  StringRef file_types::getTypeName(ID Id) { return getInfo(Id).Name; }
  
  StringRef file_types::getExtension(ID Id) {
    return getInfo(Id).Extension;
  }
  
  ID file_types::lookupTypeForExtension(StringRef Ext) {
    if (Ext.empty())
      return TY_INVALID;
    assert(Ext.front() == '.' && "not a file extension");
    return llvm::StringSwitch<file_types::ID>(Ext.drop_front())
  #define TYPE(NAME, ID, EXTENSION, FLAGS) \
             .Case(EXTENSION, TY_##ID)
  #include "swift/Basic/FileTypes.def"
        .Default(TY_INVALID);
  }
  
  ID file_types::lookupTypeForName(StringRef Name) {
    return llvm::StringSwitch<file_types::ID>(Name)
  #define TYPE(NAME, ID, EXTENSION, FLAGS) \
             .Case(NAME, TY_##ID)
  #include "swift/Basic/FileTypes.def"
        .Default(TY_INVALID);
  }
  
  bool file_types::isTextual(ID Id) {
    switch (Id) {
    case file_types::TY_Swift:
    case file_types::TY_SIL:
    case file_types::TY_Dependencies:
    case file_types::TY_Assembly:
    case file_types::TY_ASTDump:
    case file_types::TY_RawSIL:
    case file_types::TY_LLVM_IR:
    case file_types::TY_ObjCHeader:
    case file_types::TY_AutolinkFile:
    case file_types::TY_ImportedModules:
    case file_types::TY_TBD:
    case file_types::TY_ModuleTrace:
    case file_types::TY_YAMLOptRecord:
    case file_types::TY_SwiftModuleInterfaceFile:
    case file_types::TY_PrivateSwiftModuleInterfaceFile:
    case file_types::TY_SwiftOverlayFile:
    case file_types::TY_JSONDependencies:
      return true;
    case file_types::TY_Image:
    case file_types::TY_Object:
    case file_types::TY_dSYM:
    case file_types::TY_PCH:
    case file_types::TY_SIB:
    case file_types::TY_RawSIB:
    case file_types::TY_SwiftModuleFile:
    case file_types::TY_SwiftModuleDocFile:
    case file_types::TY_SwiftSourceInfoFile:
    case file_types::TY_SwiftCrossImportDir:
    case file_types::TY_LLVM_BC:
    case file_types::TY_SerializedDiagnostics:
    case file_types::TY_ClangModuleFile:
    case file_types::TY_SwiftDeps:
    case file_types::TY_SwiftRanges:
    case file_types::TY_CompiledSource:
    case file_types::TY_Nothing:
    case file_types::TY_Remapping:
    case file_types::TY_IndexData:
    case file_types::TY_BitstreamOptRecord:
      return false;
    case file_types::TY_INVALID:
      llvm_unreachable("Invalid type ID.");
    }
  
    // Work around MSVC warning: not all control paths return a value
    llvm_unreachable("All switch cases are covered");
  }
  
  bool file_types::isAfterLLVM(ID Id) {
    switch (Id) {
    case file_types::TY_Assembly:
    case file_types::TY_LLVM_IR:
    case file_types::TY_LLVM_BC:
    case file_types::TY_Object:
      return true;
    case file_types::TY_Swift:
    case file_types::TY_PCH:
    case file_types::TY_ImportedModules:
    case file_types::TY_TBD:
    case file_types::TY_SIL:
    case file_types::TY_Dependencies:
    case file_types::TY_ASTDump:
    case file_types::TY_RawSIL:
    case file_types::TY_ObjCHeader:
    case file_types::TY_AutolinkFile:
    case file_types::TY_Image:
    case file_types::TY_dSYM:
    case file_types::TY_SIB:
    case file_types::TY_RawSIB:
    case file_types::TY_SwiftModuleFile:
    case file_types::TY_SwiftModuleDocFile:
    case file_types::TY_SwiftSourceInfoFile:
    case file_types::TY_SwiftCrossImportDir:
    case file_types::TY_SwiftOverlayFile:
    case file_types::TY_SerializedDiagnostics:
    case file_types::TY_ClangModuleFile:
    case file_types::TY_SwiftDeps:
    case file_types::TY_SwiftRanges:
    case file_types::TY_CompiledSource:
    case file_types::TY_Nothing:
    case file_types::TY_Remapping:
    case file_types::TY_IndexData:
    case file_types::TY_ModuleTrace:
    case file_types::TY_YAMLOptRecord:
    case file_types::TY_BitstreamOptRecord:
    case file_types::TY_SwiftModuleInterfaceFile:
    case file_types::TY_PrivateSwiftModuleInterfaceFile:
    case file_types::TY_JSONDependencies:
      return false;
    case file_types::TY_INVALID:
      llvm_unreachable("Invalid type ID.");
    }
  
    // Work around MSVC warning: not all control paths return a value
    llvm_unreachable("All switch cases are covered");
  }
  
  bool file_types::isPartOfSwiftCompilation(ID Id) {
    switch (Id) {
    case file_types::TY_Swift:
    case file_types::TY_SIL:
    case file_types::TY_RawSIL:
    case file_types::TY_SIB:
    case file_types::TY_RawSIB:
      return true;
    case file_types::TY_Assembly:
    case file_types::TY_LLVM_IR:
    case file_types::TY_LLVM_BC:
    case file_types::TY_Object:
    case file_types::TY_Dependencies:
    case file_types::TY_ObjCHeader:
    case file_types::TY_AutolinkFile:
    case file_types::TY_PCH:
    case file_types::TY_ImportedModules:
    case file_types::TY_TBD:
    case file_types::TY_Image:
    case file_types::TY_dSYM:
    case file_types::TY_SwiftModuleFile:
    case file_types::TY_SwiftModuleDocFile:
    case file_types::TY_SwiftModuleInterfaceFile:
    case file_types::TY_PrivateSwiftModuleInterfaceFile:
    case file_types::TY_SwiftSourceInfoFile:
    case file_types::TY_SwiftCrossImportDir:
    case file_types::TY_SwiftOverlayFile:
    case file_types::TY_SerializedDiagnostics:
    case file_types::TY_ClangModuleFile:
    case file_types::TY_SwiftDeps:
    case file_types::TY_SwiftRanges:
    case file_types::TY_CompiledSource:
    case file_types::TY_Nothing:
    case file_types::TY_ASTDump:
    case file_types::TY_Remapping:
    case file_types::TY_IndexData:
    case file_types::TY_ModuleTrace:
    case file_types::TY_YAMLOptRecord:
    case file_types::TY_BitstreamOptRecord:
    case file_types::TY_JSONDependencies:
      return false;
    case file_types::TY_INVALID:
      llvm_unreachable("Invalid type ID.");
    }
  
    // Work around MSVC warning: not all control paths return a value
    llvm_unreachable("All switch cases are covered");
  }
  