Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:58

0001 //===-- SupportFile.h -------------------------------------------*- 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 LLDB_UTILITY_SUPPORTFILE_H
0010 #define LLDB_UTILITY_SUPPORTFILE_H
0011 
0012 #include "lldb/Utility/Checksum.h"
0013 #include "lldb/Utility/FileSpec.h"
0014 
0015 namespace lldb_private {
0016 
0017 /// Wraps a FileSpec and an optional Checksum. The FileSpec represents either a
0018 /// path to a file or a source file whose contents is known (for example because
0019 /// it can be reconstructed from debug info), but that hasn't been written to a
0020 /// file yet.
0021 class SupportFile {
0022 public:
0023   SupportFile() : m_file_spec(), m_checksum() {}
0024   SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {}
0025   SupportFile(const FileSpec &spec, const Checksum &checksum)
0026       : m_file_spec(spec), m_checksum(checksum) {}
0027 
0028   SupportFile(const SupportFile &other) = delete;
0029   SupportFile(SupportFile &&other) = default;
0030 
0031   virtual ~SupportFile() = default;
0032 
0033   enum SupportFileEquality : uint8_t {
0034     eEqualFileSpec = (1u << 1),
0035     eEqualChecksum = (1u << 2),
0036     eEqualChecksumIfSet = (1u << 3),
0037     eEqualFileSpecAndChecksum = eEqualFileSpec | eEqualChecksum,
0038     eEqualFileSpecAndChecksumIfSet = eEqualFileSpec | eEqualChecksumIfSet,
0039   };
0040 
0041   bool Equal(const SupportFile &other,
0042              SupportFileEquality equality = eEqualFileSpecAndChecksum) const {
0043     assert(!(equality & eEqualChecksum & eEqualChecksumIfSet) &&
0044            "eEqualChecksum and eEqualChecksumIfSet are mutually exclusive");
0045 
0046     if (equality & eEqualFileSpec) {
0047       if (m_file_spec != other.m_file_spec)
0048         return false;
0049     }
0050 
0051     if (equality & eEqualChecksum) {
0052       if (m_checksum != other.m_checksum)
0053         return false;
0054     }
0055 
0056     if (equality & eEqualChecksumIfSet) {
0057       if (m_checksum && other.m_checksum)
0058         if (m_checksum != other.m_checksum)
0059           return false;
0060     }
0061 
0062     return true;
0063   }
0064 
0065   /// Return the file name only. Useful for resolving breakpoints by file name.
0066   const FileSpec &GetSpecOnly() const { return m_file_spec; };
0067 
0068   /// Return the checksum or all zeros if there is none.
0069   const Checksum &GetChecksum() const { return m_checksum; };
0070 
0071   /// Materialize the file to disk and return the path to that temporary file.
0072   virtual const FileSpec &Materialize() { return m_file_spec; }
0073 
0074 protected:
0075   const FileSpec m_file_spec;
0076   const Checksum m_checksum;
0077 };
0078 
0079 } // namespace lldb_private
0080 
0081 #endif // LLDB_UTILITY_SUPPORTFILE_H