llvm/lldb/source/Utility/FileSpec.cpp

//===-- FileSpec.cpp ------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Stream.h"

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"

#include <algorithm>
#include <optional>
#include <system_error>
#include <vector>

#include <cassert>
#include <climits>
#include <cstdio>
#include <cstring>

usingnamespacelldb;
usingnamespacelldb_private;

namespace {

static constexpr FileSpec::Style GetNativeStyle() {}

bool PathStyleIsPosix(FileSpec::Style style) {}

const char *GetPathSeparators(FileSpec::Style style) {}

char GetPreferredPathSeparator(FileSpec::Style style) {}

void Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::Style style) {}

} // end anonymous namespace

FileSpec::FileSpec() :{}

// Default constructor that can take an optional full path to a file on disk.
FileSpec::FileSpec(llvm::StringRef path, Style style) :{}

FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
    :{}

namespace {
/// Safely get a character at the specified index.
///
/// \param[in] path
///     A full, partial, or relative path to a file.
///
/// \param[in] i
///     An index into path which may or may not be valid.
///
/// \return
///   The character at index \a i if the index is valid, or 0 if
///   the index is not valid.
inline char safeCharAtIndex(const llvm::StringRef &path, size_t i) {}

/// Check if a path needs to be normalized.
///
/// Check if a path needs to be normalized. We currently consider a
/// path to need normalization if any of the following are true
///  - path contains "/./"
///  - path contains "/../"
///  - path contains "//"
///  - path ends with "/"
/// Paths that start with "./" or with "../" are not considered to
/// need normalization since we aren't trying to resolve the path,
/// we are just trying to remove redundant things from the path.
///
/// \param[in] path
///     A full, partial, or relative path to a file.
///
/// \return
///   Returns \b true if the path needs to be normalized.
bool needsNormalization(const llvm::StringRef &path) {}


}

void FileSpec::SetFile(llvm::StringRef pathname) {}

// Update the contents of this object with a new path. The path will be split
// up into a directory and filename and stored as uniqued string values for
// quick comparison and efficient memory usage.
void FileSpec::SetFile(llvm::StringRef pathname, Style style) {}

void FileSpec::SetFile(llvm::StringRef path, const llvm::Triple &triple) {}

// Convert to pointer operator. This allows code to check any FileSpec objects
// to see if they contain anything valid using code such as:
//
//  if (file_spec)
//  {}
operator bool()

// Logical NOT operator. This allows code to check any FileSpec objects to see
// if they are invalid using code such as:
//
//  if (!file_spec)
//  {}
bool FileSpec::operator!() const {}

bool FileSpec::DirectoryEquals(const FileSpec &rhs) const {}

bool FileSpec::FileEquals(const FileSpec &rhs) const {}

// Equal to operator
bool FileSpec::operator==(const FileSpec &rhs) const {}

// Not equal to operator
bool FileSpec::operator!=(const FileSpec &rhs) const {}

// Less than operator
bool FileSpec::operator<(const FileSpec &rhs) const {}

// Dump a FileSpec object to a stream
Stream &lldb_private::operator<<(Stream &s, const FileSpec &f) {}

// Clear this object by releasing both the directory and filename string values
// and making them both the empty string.
void FileSpec::Clear() {}

// Compare two FileSpec objects. If "full" is true, then both the directory and
// the filename must match. If "full" is false, then the directory names for
// "a" and "b" are only compared if they are both non-empty. This allows a
// FileSpec object to only contain a filename and it can match FileSpec objects
// that have matching filenames with different paths.
//
// Return -1 if the "a" is less than "b", 0 if "a" is equal to "b" and "1" if
// "a" is greater than "b".
int FileSpec::Compare(const FileSpec &a, const FileSpec &b, bool full) {}

bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full) {}

bool FileSpec::Match(const FileSpec &pattern, const FileSpec &file) {}

std::optional<FileSpec::Style>
FileSpec::GuessPathStyle(llvm::StringRef absolute_path) {}

// Dump the object to the supplied stream. If the object contains a valid
// directory name, it will be displayed followed by a directory delimiter, and
// the filename.
void FileSpec::Dump(llvm::raw_ostream &s) const {}

FileSpec::Style FileSpec::GetPathStyle() const {}

void FileSpec::SetDirectory(ConstString directory) {}

void FileSpec::SetDirectory(llvm::StringRef directory) {}

void FileSpec::SetFilename(ConstString filename) {}

void FileSpec::SetFilename(llvm::StringRef filename) {}

void FileSpec::ClearFilename() {}

void FileSpec::ClearDirectory() {}

// Extract the directory and path into a fixed buffer. This is needed as the
// directory and path are stored in separate string values.
size_t FileSpec::GetPath(char *path, size_t path_max_len,
                         bool denormalize) const {}

std::string FileSpec::GetPath(bool denormalize) const {}

ConstString FileSpec::GetPathAsConstString(bool denormalize) const {}

void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path,
                       bool denormalize) const {}

llvm::StringRef FileSpec::GetFileNameExtension() const {}

ConstString FileSpec::GetFileNameStrippingExtension() const {}

// Return the size in bytes that this object takes in memory. This returns the
// size in bytes of this object, not any shared string values it may refer to.
size_t FileSpec::MemorySize() const {}

FileSpec
FileSpec::CopyByAppendingPathComponent(llvm::StringRef component) const {}

FileSpec FileSpec::CopyByRemovingLastPathComponent() const {}

void FileSpec::PrependPathComponent(llvm::StringRef component) {}

void FileSpec::PrependPathComponent(const FileSpec &new_path) {}

void FileSpec::AppendPathComponent(llvm::StringRef component) {}

void FileSpec::AppendPathComponent(const FileSpec &new_path) {}

bool FileSpec::RemoveLastPathComponent() {}

std::vector<llvm::StringRef> FileSpec::GetComponents() const {}

/// Returns true if the filespec represents an implementation source
/// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
/// extension).
///
/// \return
///     \b true if the filespec represents an implementation source
///     file, \b false otherwise.
bool FileSpec::IsSourceImplementationFile() const {}

bool FileSpec::IsRelative() const {}

bool FileSpec::IsAbsolute() const {}

void FileSpec::MakeAbsolute(const FileSpec &dir) {}

void llvm::format_provider<FileSpec>::format(const FileSpec &F,
                                             raw_ostream &Stream,
                                             StringRef Style) {}