/// one invalid Path which is the empty path. The class should never allow any
/// other syntactically invalid non-empty path name to be assigned. Empty
/// paths are required in order to indicate an error result. If the path is
- /// empty, the is_valid operation will return false. All operations will fail
- /// if is_valid is false. Operations that change the path will either return
+ /// empty, the isValid operation will return false. All operations will fail
+ /// if isValid is false. Operations that change the path will either return
/// false if it would cause a syntactically invalid path name (in which case
/// the Path object is left unchanged) or throw an std::string exception
/// indicating the error.
/// the program. However, if the path is not valid, the Path object will
/// be set to an empty string and an exception will be thrown.
/// @throws std::string if the path string is not legal.
- /// @param unvalidated_path The path to verify and assign.
+ /// @param unverified_path The path to verify and assign.
/// @brief Construct a Path from a string.
explicit Path(std::string unverified_path);
/// @returns true iff the path name is syntactically legal for the
/// host operating system.
/// @brief Determine if a path is syntactically valid or not.
- bool is_valid() const;
+ bool isValid() const;
/// This function determines if the contents of the path name are
/// empty. That is, the path has a zero length.
/// @returns true iff the path is empty.
/// @brief Determines if the path name is empty (invalid).
- bool is_empty() const { return path.empty(); }
+ bool isEmpty() const { return path.empty(); }
/// This function determines if the path name in this object is intended
/// to reference a legal file name (as opposed to a directory name). This
/// determines if the syntax of the path represents a file name or not.
/// @returns true if this path name references a file.
/// @brief Determines if the path name references a file.
- bool is_file() const;
+ bool isFile() const;
/// This function determines if the path name in this object is intended
/// to reference a legal directory name (as opposed to a file name). This
/// not.
/// @returns true if the path name references a directory
/// @brief Determines if the path name references a directory.
- bool is_directory() const;
+ bool isDirectory() const;
/// This function determines if the path name in this object references
/// the root (top level directory) of the file system. The details of what
/// will do the necessary checking.
/// @returns true iff the path name references the root directory.
/// @brief Determines if the path references the root directory.
- bool is_root_directory() const;
+ bool isRootDirectory() const;
/// This function opens the file associated with the path name provided by
/// the Path object and reads its magic number. If the magic number at the
/// cases (file not found, file not accessible, etc.) it returns false.
/// @returns true if the magic number of the file matches \p magic.
/// @brief Determine if file has a specific magic number
- bool has_magic_number(const std::string& magic) const;
+ bool hasMagicNumber(const std::string& magic) const;
/// This function determines if the path name in the object references an
/// archive file by looking at its magic number.
/// @returns true if the file starts with the magic number for an archive
/// file.
/// @brief Determine if the path references an archive file.
- bool is_archive() const;
+ bool isArchive() const;
/// This function determines if the path name in the object references an
/// LLVM Bytecode file by looking at its magic number.
/// @returns true if the file starts with the magic number for LLVM
/// bytecode files.
/// @brief Determine if the path references a bytecode file.
- bool is_bytecode_file() const;
+ bool isBytecodeFile() const;
/// This function determines if the path name references an existing file
- /// or directory in the file system. Unlike is_file and is_directory, this
+ /// or directory in the file system. Unlike isFile and isDirectory, this
/// function actually checks for the existence of the file or directory.
/// @returns true if the pathname references an existing file.
/// @brief Determines if the path is a file or directory in
bool exists() const;
/// This function determines if the path name references a readable file
- /// or directory in the file system. Unlike is_file and is_directory, this
+ /// or directory in the file system. Unlike isFile and isDirectory, this
/// function actually checks for the existence and readability (by the
/// current program) of the file or directory.
/// @returns true if the pathname references a readable file.
bool readable() const;
/// This function determines if the path name references a writable file
- /// or directory in the file system. Unlike is_file and is_directory, this
+ /// or directory in the file system. Unlike isFile and isDirectory, this
/// function actually checks for the existence and writability (by the
/// current program) of the file or directory.
/// @returns true if the pathname references a writable file.
bool writable() const;
/// This function determines if the path name references an executable
- /// file in the file system. Unlike is_file and is_directory, this
+ /// file in the file system. Unlike isFile and isDirectory, this
/// function actually checks for the existence and executability (by
/// the current program) of the file.
/// @returns true if the pathname references an executable file.
std::string get() const { return path; }
/// This function returns the last component of the path name. If the
- /// is_directory() function would return true then this returns the name
- /// of the last directory in the path. If the is_file() function would
+ /// isDirectory() function would return true then this returns the name
+ /// of the last directory in the path. If the isFile() function would
/// return true then this function returns the name of the file without
/// any of the preceding directories.
/// @returns std::string containing the last component of the path name.
/// @returns std::string containing the basename of the path
/// @throws nothing
/// @brief Get the base name of the path
- std::string get_basename() const;
+ std::string getBasename() const;
/// @returns a c string containing the path name.
/// @brief Returns the path as a C string.
/// @param unverified_path The path to be set in Path object.
/// @throws nothing
/// @brief Set a full path from a std::string
- bool set_directory(const std::string& unverified_path);
+ bool setDirectory(const std::string& unverified_path);
/// This method attempts to set the Path object to \p unverified_path
/// and interpret the name as a file name. The \p unverified_path
/// @param unverified_path The path to be set in Path object.
/// @throws nothing
/// @brief Set a full path from a std::string
- bool set_file(const std::string& unverified_path);
+ bool setFile(const std::string& unverified_path);
/// The \p dirname is added to the end of the Path if it is a legal
/// directory name for the operating system. The precondition for this
/// function is that the Path must reference a directory name (i.e.
- /// is_directory() returns true).
+ /// isDirectory() returns true).
/// @param dirname A string providing the directory name to
/// be added to the end of the path.
/// @returns false if the directory name could not be added
/// @throws nothing
/// @brief Adds the name of a directory to a Path.
- bool append_directory( const std::string& dirname );
+ bool appendDirectory( const std::string& dirname );
/// One directory component is removed from the Path name. The Path must
- /// refer to a non-root directory name (i.e. is_directory() returns true
- /// but is_root_directory() returns false). Upon exit, the Path will
+ /// refer to a non-root directory name (i.e. isDirectory() returns true
+ /// but isRootDirectory() returns false). Upon exit, the Path will
/// refer to the directory above it.
/// @throws nothing
/// @returns false if the directory name could not be removed.
/// @brief Removes the last directory component of the Path.
- bool elide_directory();
+ bool elideDirectory();
/// The \p filename is added to the end of the Path if it is a legal
/// directory name for the operating system. The precondition for this
/// function is that the Path reference a directory name (i.e.
- /// is_directory() returns true).
+ /// isDirectory() returns true).
/// @throws nothing
/// @returns false if the file name could not be added.
/// @brief Appends the name of a file.
- bool append_file( const std::string& filename );
+ bool appendFile( const std::string& filename );
/// One file component is removed from the Path name. The Path must
- /// refer to a file (i.e. is_file() returns true). Upon exit,
+ /// refer to a file (i.e. isFile() returns true). Upon exit,
/// the Path will refer to the directory above it.
/// @throws nothing
/// @returns false if the file name could not be removed
/// @brief Removes the last file component of the path.
- bool elide_file();
+ bool elideFile();
/// A period and the \p suffix are appended to the end of the pathname.
/// The precondition for this function is that the Path reference a file
- /// name (i.e. is_file() returns true). If the Path is not a file, no
+ /// name (i.e. isFile() returns true). If the Path is not a file, no
/// action is taken and the function returns false. If the path would
/// become invalid for the host operating system, false is returned.
/// @returns false if the suffix could not be added, true if it was.
/// @throws nothing
/// @brief Adds a period and the \p suffix to the end of the pathname.
- bool append_suffix(const std::string& suffix);
+ bool appendSuffix(const std::string& suffix);
/// The suffix of the filename is removed. The suffix begins with and
/// includes the last . character in the filename after the last directory
/// @returns false if there was no suffix to remove, true otherwise.
/// @throws nothing
/// @brief Remove the suffix from a path name.
- bool elide_suffix();
+ bool elideSuffix();
/// This method attempts to create a directory in the file system with the
/// same name as the Path object. The \p create_parents parameter controls
/// components other than the last one (the "parents") are created or not.
/// @throws std::string if an error occurs.
/// @brief Create the directory this Path refers to.
- bool create_directory( bool create_parents = false );
+ bool createDirectory( bool create_parents = false );
/// This method attempts to create a file in the file system with the same
/// name as the Path object. The intermediate directories must all exist
- /// at the time this method is called. Use create_directories to
+ /// at the time this method is called. Use createDirectories to
/// accomplish that. The created file will be empty upon return from this
/// function.
/// @returns false if the Path does not reference a file, true otherwise.
/// @throws std::string if an error occurs.
/// @brief Create the file this Path refers to.
- bool create_file();
+ bool createFile();
/// This method attempts to destroy the directory named by the last in
/// the Path name. If \p remove_contents is false, an attempt will be
/// otherwise.
/// @throws std::string if there is an error.
/// @brief Removes the file or directory from the filesystem.
- bool destroy_directory( bool destroy_contents = false );
+ bool destroyDirectory( bool destroy_contents = false );
/// This method attempts to destroy the file named by the last item in the
/// Path name.
/// @returns false if the Path does not refer to a file, true otherwise.
/// @throws std::string if there is an error.
/// @brief Destroy the file this Path refers to.
- bool destroy_file();
+ bool destroyFile();
/// @}
/// @name Data
// If the source library's module id is in the dependent library list of the
// destination library, remove it since that module is now linked in.
sys::Path modId;
- modId.set_file(Src->getModuleIdentifier());
- if (!modId.is_empty())
- Dest->removeLibrary(modId.get_basename());
+ modId.setFile(Src->getModuleIdentifier());
+ if (!modId.isEmpty())
+ Dest->removeLibrary(modId.getBasename());
return false;
}
//===----------------------------------------------------------------------===//
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
if (path.length() >= MAXPATHLEN)
if (!mkdir(TmpName, S_IRWXU))
ThrowErrno(std::string(TmpName) + ": Can't create temporary directory");
Path result;
- result.set_directory(TmpName);
- assert(result.is_valid() && "mkdtemp didn't create a valid pathname!");
+ result.setDirectory(TmpName);
+ assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
return result;
}
using namespace sys;
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
char pathname[MAXPATHLEN];
if (0 == pathname)
ThrowErrno(std::string("Can't create temporary directory name"));
Path result;
- result.set_directory(pathname);
+ result.setDirectory(pathname);
free(pathname);
- assert(result.is_valid() && "tempnam didn't create a valid pathname!");
+ assert(result.isValid() && "tempnam didn't create a valid pathname!");
if (0 != mkdir(result.c_str(), S_IRWXU))
ThrowErrno(result.get() + ": Can't create temporary directory");
return result;
using namespace sys;
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
if (path.length() >= MAXPATHLEN)
if (0 == mkdtemp(pathname))
ThrowErrno(std::string(pathname) + ": Can't create temporary directory");
Path result;
- result.set_directory(pathname);
- assert(result.is_valid() && "mkdtemp didn't create a valid pathname!");
+ result.setDirectory(pathname);
+ assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
return result;
}
using namespace sys;
bool
-Path::is_valid() const {
+Path::isvalid() const {
if (path.empty())
return false;
char pathname[MAXPATHLEN];
if (0 == mkdtemp(pathname))
ThrowErrno(std::string(pathname) + ": Can't create temporary directory");
Path result;
- result.set_directory(pathname);
- assert(result.is_valid() && "mkdtemp didn't create a valid pathname!");
+ result.setDirectory(pathname);
+ assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
return result;
}
using namespace sys;
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
char pathname[MAXPATHLEN];
if (0 == mkdtemp(pathname))
ThrowErrno(std::string(pathname) + ": Can't create temporary directory");
Path result;
- result.set_directory(pathname);
- assert(result.is_valid() && "mkdtemp didn't create a valid pathname!");
+ result.setDirectory(pathname);
+ assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
return result;
}
using namespace sys;
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
char pathname[MAXPATHLEN];
if (0 == mkdtemp(pathname))
ThrowErrno(std::string(pathname) + ": Can't create temporary directory");
Path result;
- result.set_directory(pathname);
- assert(result.is_valid() && "mkdtemp didn't create a valid pathname!");
+ result.setDirectory(pathname);
+ assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
return result;
}
using namespace sys;
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
char pathname[MAXPATHLEN];
if (0 == pathname)
ThrowErrno(std::string("Can't create temporary directory name"));
Path result;
- result.set_directory(pathname);
+ result.setDirectory(pathname);
free(pathname);
- assert(result.is_valid() && "tempnam didn't create a valid pathname!");
+ assert(result.isValid() && "tempnam didn't create a valid pathname!");
if (0 != mkdir(result.c_str(), S_IRWXU))
ThrowErrno(result.get() + ": Can't create temporary directory");
return result;
{
if (unverified_path.empty())
return;
- if (this->is_valid())
+ if (this->isValid())
return;
// oops, not valid.
path.clear();
Path
Path::GetRootDirectory() {
Path result;
- result.set_directory("/");
+ result.setDirectory("/");
return result;
}
static inline bool IsLibrary(Path& path, const std::string& basename) {
- if (path.append_file(std::string("lib") + basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ if (path.appendFile(std::string("lib") + basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
- } else if (path.elide_file() && path.append_file(basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ } else if (path.elideFile() && path.appendFile(basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
}
path.clear();
// Try the paths provided
for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
E = LibPaths.end(); I != E; ++I ) {
- if (result.set_directory(*I) && IsLibrary(result,basename))
+ if (result.setDirectory(*I) && IsLibrary(result,basename))
return result;
}
// Try the LLVM lib directory in the LLVM install area
- if (result.set_directory(LLVM_LIBDIR) && IsLibrary(result,basename))
+ if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename))
return result;
// Try /usr/lib
- if (result.set_directory("/usr/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename))
return result;
// Try /lib
- if (result.set_directory("/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/lib/") && IsLibrary(result,basename))
return result;
// Can't find it, give up and return invalid path.
Path
Path::GetLLVMConfigDir() {
Path result;
- if (result.set_directory(LLVM_ETCDIR))
+ if (result.setDirectory(LLVM_ETCDIR))
return result;
return GetLLVMDefaultConfigDir();
}
const char* home = getenv("HOME");
if (home) {
Path result;
- if (result.set_directory(home))
+ if (result.setDirectory(home))
return result;
}
return GetRootDirectory();
}
bool
-Path::is_file() const {
- return (is_valid() && path[path.length()-1] != '/');
+Path::isFile() const {
+ return (isValid() && path[path.length()-1] != '/');
}
bool
-Path::is_directory() const {
- return (is_valid() && path[path.length()-1] == '/');
+Path::isDirectory() const {
+ return (isValid() && path[path.length()-1] == '/');
}
std::string
-Path::get_basename() const {
+Path::getBasename() const {
// Find the last slash
size_t slash = path.rfind('/');
if (slash == std::string::npos)
return path.substr(slash, path.rfind('.'));
}
-bool Path::has_magic_number(const std::string &Magic) const {
+bool Path::hasMagicNumber(const std::string &Magic) const {
size_t len = Magic.size();
char buf[ 1 + len];
std::ifstream f(path.c_str());
}
bool
-Path::is_bytecode_file() const {
+Path::isBytecodeFile() const {
if (readable()) {
- return has_magic_number("llvm");
+ return hasMagicNumber("llvm");
}
return false;
}
bool
-Path::is_archive() const {
+Path::isArchive() const {
if (readable()) {
- return has_magic_number("!<arch>\012");
+ return hasMagicNumber("!<arch>\012");
}
return false;
}
}
bool
-Path::set_directory(const std::string& a_path) {
+Path::setDirectory(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
size_t last = a_path.size() -1;
if (last != 0 && a_path[last] != '/')
path += '/';
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::set_file(const std::string& a_path) {
+Path::setFile(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
while (last > 0 && a_path[last] == '/')
last--;
path.erase(last+1);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::append_directory(const std::string& dir) {
- if (is_file())
+Path::appendDirectory(const std::string& dir) {
+ if (isFile())
return false;
Path save(*this);
path += dir;
path += "/";
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_directory() {
- if (is_file())
+Path::elideDirectory() {
+ if (isFile())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == 0 || slashpos == std::string::npos)
}
bool
-Path::append_file(const std::string& file) {
- if (!is_directory())
+Path::appendFile(const std::string& file) {
+ if (!isDirectory())
return false;
Path save(*this);
path += file;
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_file() {
- if (is_directory())
+Path::elideFile() {
+ if (isDirectory())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == std::string::npos)
}
bool
-Path::append_suffix(const std::string& suffix) {
- if (is_directory())
+Path::appendSuffix(const std::string& suffix) {
+ if (isDirectory())
return false;
Path save(*this);
path.append(".");
path.append(suffix);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_suffix() {
- if (is_directory()) return false;
+Path::elideSuffix() {
+ if (isDirectory()) return false;
size_t dotpos = path.rfind('.',path.size());
size_t slashpos = path.rfind('/',path.size());
if (slashpos != std::string::npos && dotpos != std::string::npos &&
bool
-Path::create_directory( bool create_parents) {
+Path::createDirectory( bool create_parents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// Get a writeable copy of the path name
char pathname[MAXPATHLEN];
}
bool
-Path::create_file() {
+Path::createFile() {
// Make sure we're dealing with a file
- if (!is_file()) return false;
+ if (!isFile()) return false;
// Create the file
int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR);
}
bool
-Path::destroy_directory(bool remove_contents) {
+Path::destroyDirectory(bool remove_contents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// If it doesn't exist, we're done.
if (!exists()) return true;
}
bool
-Path::destroy_file() {
- if (!is_file()) return false;
+Path::destroyFile() {
+ if (!isFile()) return false;
if (0 != unlink(path.c_str()))
ThrowErrno(std::string(path.c_str()) + ": Can't destroy file");
return true;
{
if (unverified_path.empty())
return;
- if (this->is_valid())
+ if (this->isValid())
return;
// oops, not valid.
path.clear();
Path
Path::GetRootDirectory() {
Path result;
- result.set_directory("/");
+ result.setDirectory("/");
return result;
}
static inline bool IsLibrary(Path& path, const std::string& basename) {
- if (path.append_file(std::string("lib") + basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ if (path.appendFile(std::string("lib") + basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
- } else if (path.elide_file() && path.append_file(basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ } else if (path.elideFile() && path.appendFile(basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
}
path.clear();
// Try the paths provided
for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
E = LibPaths.end(); I != E; ++I ) {
- if (result.set_directory(*I) && IsLibrary(result,basename))
+ if (result.setDirectory(*I) && IsLibrary(result,basename))
return result;
}
// Try the LLVM lib directory in the LLVM install area
- if (result.set_directory(LLVM_LIBDIR) && IsLibrary(result,basename))
+ if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename))
return result;
// Try /usr/lib
- if (result.set_directory("/usr/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename))
return result;
// Try /lib
- if (result.set_directory("/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/lib/") && IsLibrary(result,basename))
return result;
// Can't find it, give up and return invalid path.
Path
Path::GetLLVMConfigDir() {
Path result;
- if (result.set_directory(LLVM_ETCDIR))
+ if (result.setDirectory(LLVM_ETCDIR))
return result;
return GetLLVMDefaultConfigDir();
}
const char* home = getenv("HOME");
if (home) {
Path result;
- if (result.set_directory(home))
+ if (result.setDirectory(home))
return result;
}
return GetRootDirectory();
}
bool
-Path::is_file() const {
- return (is_valid() && path[path.length()-1] != '/');
+Path::isFile() const {
+ return (isValid() && path[path.length()-1] != '/');
}
bool
-Path::is_directory() const {
- return (is_valid() && path[path.length()-1] == '/');
+Path::isDirectory() const {
+ return (isValid() && path[path.length()-1] == '/');
}
std::string
-Path::get_basename() const {
+Path::getBasename() const {
// Find the last slash
size_t slash = path.rfind('/');
if (slash == std::string::npos)
return path.substr(slash, path.rfind('.'));
}
-bool Path::has_magic_number(const std::string &Magic) const {
+bool Path::hasMagicNumber(const std::string &Magic) const {
size_t len = Magic.size();
char buf[ 1 + len];
std::ifstream f(path.c_str());
}
bool
-Path::is_bytecode_file() const {
+Path::isBytecodeFile() const {
if (readable()) {
- return has_magic_number("llvm");
+ return hasMagicNumber("llvm");
}
return false;
}
bool
-Path::is_archive() const {
+Path::isArchive() const {
if (readable()) {
- return has_magic_number("!<arch>\012");
+ return hasMagicNumber("!<arch>\012");
}
return false;
}
}
bool
-Path::set_directory(const std::string& a_path) {
+Path::setDirectory(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
size_t last = a_path.size() -1;
if (last != 0 && a_path[last] != '/')
path += '/';
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::set_file(const std::string& a_path) {
+Path::setFile(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
while (last > 0 && a_path[last] == '/')
last--;
path.erase(last+1);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::append_directory(const std::string& dir) {
- if (is_file())
+Path::appendDirectory(const std::string& dir) {
+ if (isFile())
return false;
Path save(*this);
path += dir;
path += "/";
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_directory() {
- if (is_file())
+Path::elideDirectory() {
+ if (isFile())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == 0 || slashpos == std::string::npos)
}
bool
-Path::append_file(const std::string& file) {
- if (!is_directory())
+Path::appendFile(const std::string& file) {
+ if (!isDirectory())
return false;
Path save(*this);
path += file;
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_file() {
- if (is_directory())
+Path::elideFile() {
+ if (isDirectory())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == std::string::npos)
}
bool
-Path::append_suffix(const std::string& suffix) {
- if (is_directory())
+Path::appendSuffix(const std::string& suffix) {
+ if (isDirectory())
return false;
Path save(*this);
path.append(".");
path.append(suffix);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_suffix() {
- if (is_directory()) return false;
+Path::elideSuffix() {
+ if (isDirectory()) return false;
size_t dotpos = path.rfind('.',path.size());
size_t slashpos = path.rfind('/',path.size());
if (slashpos != std::string::npos && dotpos != std::string::npos &&
bool
-Path::create_directory( bool create_parents) {
+Path::createDirectory( bool create_parents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// Get a writeable copy of the path name
char pathname[MAXPATHLEN];
}
bool
-Path::create_file() {
+Path::createFile() {
// Make sure we're dealing with a file
- if (!is_file()) return false;
+ if (!isFile()) return false;
// Create the file
int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR);
}
bool
-Path::destroy_directory(bool remove_contents) {
+Path::destroyDirectory(bool remove_contents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// If it doesn't exist, we're done.
if (!exists()) return true;
}
bool
-Path::destroy_file() {
- if (!is_file()) return false;
+Path::destroyFile() {
+ if (!isFile()) return false;
if (0 != unlink(path.c_str()))
ThrowErrno(std::string(path.c_str()) + ": Can't destroy file");
return true;
if (progName.length() == 0) // no program
return Path();
Path temp;
- if (!temp.set_file(progName)) // invalid name
+ if (!temp.setFile(progName)) // invalid name
return Path();
if (temp.executable()) // already executable as is
return temp;
// Check to see if this first directory contains the executable...
Path FilePath;
- if (FilePath.set_directory(std::string(PathStr,Colon))) {
- FilePath.append_file(progName);
+ if (FilePath.setDirectory(std::string(PathStr,Colon))) {
+ FilePath.appendFile(progName);
if (FilePath.executable())
return FilePath; // Found the executable!
}
if (progName.length() == 0) // no program
return Path();
Path temp;
- if (!temp.set_file(progName)) // invalid name
+ if (!temp.setFile(progName)) // invalid name
return Path();
if (temp.executable()) // already executable as is
return temp;
// Check to see if this first directory contains the executable...
Path FilePath;
- if (FilePath.set_directory(std::string(PathStr,Colon))) {
- FilePath.append_file(progName);
+ if (FilePath.setDirectory(std::string(PathStr,Colon))) {
+ FilePath.appendFile(progName);
if (FilePath.executable())
return FilePath; // Found the executable!
}
if (DirectoriesToRemove != 0)
while (!DirectoriesToRemove->empty()) {
- DirectoriesToRemove->back().destroy_directory(true);
+ DirectoriesToRemove->back().destroyDirectory(true);
DirectoriesToRemove->pop_back();
}
// RemoveDirectoryOnSignal - The public API
void sys::RemoveDirectoryOnSignal(const llvm::sys::Path& path) {
- if (!path.is_directory())
+ if (!path.isDirectory())
return;
if (DirectoriesToRemove == 0)
if (DirectoriesToRemove != 0)
while (!DirectoriesToRemove->empty()) {
- DirectoriesToRemove->back().destroy_directory(true);
+ DirectoriesToRemove->back().destroyDirectory(true);
DirectoriesToRemove->pop_back();
}
// RemoveDirectoryOnSignal - The public API
void sys::RemoveDirectoryOnSignal(const llvm::sys::Path& path) {
- if (!path.is_directory())
+ if (!path.isDirectory())
return;
if (DirectoriesToRemove == 0)
namespace sys {
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
throw std::string("Can't determine temporary directory");
Path result;
- result.set_directory(pathname);
+ result.setDirectory(pathname);
// Append a subdirectory passed on our process id so multiple LLVMs don't
// step on each other's toes.
sprintf(pathname, "LLVM_%u", GetCurrentProcessId());
- result.append_directory(pathname);
+ result.appendDirectory(pathname);
// If there's a directory left over from a previous LLVM execution that
// happened to have the same process id, get rid of it.
- result.destroy_directory(true);
+ result.destroyDirectory(true);
// And finally (re-)create the empty directory.
- result.create_directory(false);
+ result.createDirectory(false);
TempDirectory = new Path(result);
return *TempDirectory;
}
FlipBackSlashes(path);
if (unverified_path.empty())
return;
- if (this->is_valid())
+ if (this->isValid())
return;
// oops, not valid.
path.clear();
Path
Path::GetRootDirectory() {
Path result;
- result.set_directory("/");
+ result.setDirectory("/");
return result;
}
}
static inline bool IsLibrary(Path& path, const std::string& basename) {
- if (path.append_file(std::string("lib") + basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ if (path.appendFile(std::string("lib") + basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
- } else if (path.elide_file() && path.append_file(basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ } else if (path.elideFile() && path.appendFile(basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
}
path.clear();
// Try the paths provided
for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
E = LibPaths.end(); I != E; ++I ) {
- if (result.set_directory(*I) && IsLibrary(result,basename))
+ if (result.setDirectory(*I) && IsLibrary(result,basename))
return result;
}
// Try the LLVM lib directory in the LLVM install area
- //if (result.set_directory(LLVM_LIBDIR) && IsLibrary(result,basename))
+ //if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename))
// return result;
// Try /usr/lib
- if (result.set_directory("/usr/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename))
return result;
// Try /lib
- if (result.set_directory("/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/lib/") && IsLibrary(result,basename))
return result;
// Can't find it, give up and return invalid path.
const char* home = getenv("HOME");
if (home) {
Path result;
- if (result.set_directory(home))
+ if (result.setDirectory(home))
return result;
}
return GetRootDirectory();
// FIXME: the above set of functions don't map to Windows very well.
bool
-Path::is_file() const {
- return (is_valid() && path[path.length()-1] != '/');
+Path::isFile() const {
+ return (isValid() && path[path.length()-1] != '/');
}
bool
-Path::is_directory() const {
- return (is_valid() && path[path.length()-1] == '/');
+Path::isDirectory() const {
+ return (isValid() && path[path.length()-1] == '/');
}
std::string
-Path::get_basename() const {
+Path::getBasename() const {
// Find the last slash
size_t slash = path.rfind('/');
if (slash == std::string::npos)
return path.substr(slash, path.rfind('.'));
}
-bool Path::has_magic_number(const std::string &Magic) const {
+bool Path::hasMagicNumber(const std::string &Magic) const {
size_t len = Magic.size();
char *buf = reinterpret_cast<char *>(_alloca(len+1));
std::ifstream f(path.c_str());
}
bool
-Path::is_bytecode_file() const {
+Path::isBytecodeFile() const {
if (readable()) {
- return has_magic_number("llvm");
+ return hasMagicNumber("llvm");
}
return false;
}
bool
-Path::is_archive() const {
+Path::isArchive() const {
if (readable()) {
- return has_magic_number("!<arch>\012");
+ return hasMagicNumber("!<arch>\012");
}
return false;
}
}
bool
-Path::set_directory(const std::string& a_path) {
+Path::setDirectory(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
size_t last = a_path.size() -1;
if (last != 0 && a_path[last] != '/')
path += '/';
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::set_file(const std::string& a_path) {
+Path::setFile(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
while (last > 0 && a_path[last] == '/')
last--;
path.erase(last+1);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::append_directory(const std::string& dir) {
- if (is_file())
+Path::appendDirectory(const std::string& dir) {
+ if (isFile())
return false;
Path save(*this);
path += dir;
path += "/";
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_directory() {
- if (is_file())
+Path::elideDirectory() {
+ if (isFile())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == 0 || slashpos == std::string::npos)
}
bool
-Path::append_file(const std::string& file) {
- if (!is_directory())
+Path::appendFile(const std::string& file) {
+ if (!isDirectory())
return false;
Path save(*this);
path += file;
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_file() {
- if (is_directory())
+Path::elideFile() {
+ if (isDirectory())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == std::string::npos)
}
bool
-Path::append_suffix(const std::string& suffix) {
- if (is_directory())
+Path::appendSuffix(const std::string& suffix) {
+ if (isDirectory())
return false;
Path save(*this);
path.append(".");
path.append(suffix);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_suffix() {
- if (is_directory()) return false;
+Path::elideSuffix() {
+ if (isDirectory()) return false;
size_t dotpos = path.rfind('.',path.size());
size_t slashpos = path.rfind('/',path.size());
if (slashpos != std::string::npos && dotpos != std::string::npos &&
bool
-Path::create_directory( bool create_parents) {
+Path::createDirectory( bool create_parents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// Get a writeable copy of the path name
char *pathname = reinterpret_cast<char *>(_alloca(path.length()+1));
}
bool
-Path::create_file() {
+Path::createFile() {
// Make sure we're dealing with a file
- if (!is_file()) return false;
+ if (!isFile()) return false;
// Create the file
HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
}
bool
-Path::destroy_directory(bool remove_contents) {
+Path::destroyDirectory(bool remove_contents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// If it doesn't exist, we're done.
if (!exists()) return true;
}
bool
-Path::destroy_file() {
- if (!is_file()) return false;
+Path::destroyFile() {
+ if (!isFile()) return false;
DWORD attr = GetFileAttributes(path.c_str());
namespace sys {
bool
-Path::is_valid() const {
+Path::isValid() const {
if (path.empty())
return false;
throw std::string("Can't determine temporary directory");
Path result;
- result.set_directory(pathname);
+ result.setDirectory(pathname);
// Append a subdirectory passed on our process id so multiple LLVMs don't
// step on each other's toes.
sprintf(pathname, "LLVM_%u", GetCurrentProcessId());
- result.append_directory(pathname);
+ result.appendDirectory(pathname);
// If there's a directory left over from a previous LLVM execution that
// happened to have the same process id, get rid of it.
- result.destroy_directory(true);
+ result.destroyDirectory(true);
// And finally (re-)create the empty directory.
- result.create_directory(false);
+ result.createDirectory(false);
TempDirectory = new Path(result);
return *TempDirectory;
}
FlipBackSlashes(path);
if (unverified_path.empty())
return;
- if (this->is_valid())
+ if (this->isValid())
return;
// oops, not valid.
path.clear();
Path
Path::GetRootDirectory() {
Path result;
- result.set_directory("/");
+ result.setDirectory("/");
return result;
}
}
static inline bool IsLibrary(Path& path, const std::string& basename) {
- if (path.append_file(std::string("lib") + basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ if (path.appendFile(std::string("lib") + basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
- } else if (path.elide_file() && path.append_file(basename)) {
- if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ } else if (path.elideFile() && path.appendFile(basename)) {
+ if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
return true;
- else if (path.elide_suffix() && path.append_suffix("bc") && path.readable())
+ else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
return true;
}
path.clear();
// Try the paths provided
for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
E = LibPaths.end(); I != E; ++I ) {
- if (result.set_directory(*I) && IsLibrary(result,basename))
+ if (result.setDirectory(*I) && IsLibrary(result,basename))
return result;
}
// Try the LLVM lib directory in the LLVM install area
- //if (result.set_directory(LLVM_LIBDIR) && IsLibrary(result,basename))
+ //if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename))
// return result;
// Try /usr/lib
- if (result.set_directory("/usr/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename))
return result;
// Try /lib
- if (result.set_directory("/lib/") && IsLibrary(result,basename))
+ if (result.setDirectory("/lib/") && IsLibrary(result,basename))
return result;
// Can't find it, give up and return invalid path.
const char* home = getenv("HOME");
if (home) {
Path result;
- if (result.set_directory(home))
+ if (result.setDirectory(home))
return result;
}
return GetRootDirectory();
// FIXME: the above set of functions don't map to Windows very well.
bool
-Path::is_file() const {
- return (is_valid() && path[path.length()-1] != '/');
+Path::isFile() const {
+ return (isValid() && path[path.length()-1] != '/');
}
bool
-Path::is_directory() const {
- return (is_valid() && path[path.length()-1] == '/');
+Path::isDirectory() const {
+ return (isValid() && path[path.length()-1] == '/');
}
std::string
-Path::get_basename() const {
+Path::getBasename() const {
// Find the last slash
size_t slash = path.rfind('/');
if (slash == std::string::npos)
return path.substr(slash, path.rfind('.'));
}
-bool Path::has_magic_number(const std::string &Magic) const {
+bool Path::hasMagicNumber(const std::string &Magic) const {
size_t len = Magic.size();
char *buf = reinterpret_cast<char *>(_alloca(len+1));
std::ifstream f(path.c_str());
}
bool
-Path::is_bytecode_file() const {
+Path::isBytecodeFile() const {
if (readable()) {
- return has_magic_number("llvm");
+ return hasMagicNumber("llvm");
}
return false;
}
bool
-Path::is_archive() const {
+Path::isArchive() const {
if (readable()) {
- return has_magic_number("!<arch>\012");
+ return hasMagicNumber("!<arch>\012");
}
return false;
}
}
bool
-Path::set_directory(const std::string& a_path) {
+Path::setDirectory(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
size_t last = a_path.size() -1;
if (last != 0 && a_path[last] != '/')
path += '/';
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::set_file(const std::string& a_path) {
+Path::setFile(const std::string& a_path) {
if (a_path.size() == 0)
return false;
Path save(*this);
while (last > 0 && a_path[last] == '/')
last--;
path.erase(last+1);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::append_directory(const std::string& dir) {
- if (is_file())
+Path::appendDirectory(const std::string& dir) {
+ if (isFile())
return false;
Path save(*this);
path += dir;
path += "/";
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_directory() {
- if (is_file())
+Path::elideDirectory() {
+ if (isFile())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == 0 || slashpos == std::string::npos)
}
bool
-Path::append_file(const std::string& file) {
- if (!is_directory())
+Path::appendFile(const std::string& file) {
+ if (!isDirectory())
return false;
Path save(*this);
path += file;
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_file() {
- if (is_directory())
+Path::elideFile() {
+ if (isDirectory())
return false;
size_t slashpos = path.rfind('/',path.size());
if (slashpos == std::string::npos)
}
bool
-Path::append_suffix(const std::string& suffix) {
- if (is_directory())
+Path::appendSuffix(const std::string& suffix) {
+ if (isDirectory())
return false;
Path save(*this);
path.append(".");
path.append(suffix);
- if (!is_valid()) {
+ if (!isValid()) {
path = save.path;
return false;
}
}
bool
-Path::elide_suffix() {
- if (is_directory()) return false;
+Path::elideSuffix() {
+ if (isDirectory()) return false;
size_t dotpos = path.rfind('.',path.size());
size_t slashpos = path.rfind('/',path.size());
if (slashpos != std::string::npos && dotpos != std::string::npos &&
bool
-Path::create_directory( bool create_parents) {
+Path::createDirectory( bool create_parents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// Get a writeable copy of the path name
char *pathname = reinterpret_cast<char *>(_alloca(path.length()+1));
}
bool
-Path::create_file() {
+Path::createFile() {
// Make sure we're dealing with a file
- if (!is_file()) return false;
+ if (!isFile()) return false;
// Create the file
HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
}
bool
-Path::destroy_directory(bool remove_contents) {
+Path::destroyDirectory(bool remove_contents) {
// Make sure we're dealing with a directory
- if (!is_directory()) return false;
+ if (!isDirectory()) return false;
// If it doesn't exist, we're done.
if (!exists()) return true;
}
bool
-Path::destroy_file() {
- if (!is_file()) return false;
+Path::destroyFile() {
+ if (!isFile()) return false;
DWORD attr = GetFileAttributes(path.c_str());
if (progName.length() == 0) // no program
return Path();
Path temp;
- if (!temp.set_file(progName)) // invalid name
+ if (!temp.setFile(progName)) // invalid name
return Path();
if (temp.executable()) // already executable as is
return temp;
if (progName.length() == 0) // no program
return Path();
Path temp;
- if (!temp.set_file(progName)) // invalid name
+ if (!temp.setFile(progName)) // invalid name
return Path();
if (temp.executable()) // already executable as is
return temp;
if (CleanupExecuted)
throw std::string("Process terminating -- cannot register for removal");
- if (path.is_directory()) {
+ if (path.isDirectory()) {
if (DirectoriesToRemove == NULL)
DirectoriesToRemove = new std::vector<sys::Path>;
if (FilesToRemove != NULL)
while (!FilesToRemove->empty()) {
try {
- FilesToRemove->back().destroy_file();
+ FilesToRemove->back().destroyFile();
} catch (...) {
}
FilesToRemove->pop_back();
if (DirectoriesToRemove != NULL)
while (!DirectoriesToRemove->empty()) {
try {
- DirectoriesToRemove->back().destroy_directory(true);
+ DirectoriesToRemove->back().destroyDirectory(true);
} catch (...) {
}
DirectoriesToRemove->pop_back();
if (CleanupExecuted)
throw std::string("Process terminating -- cannot register for removal");
- if (path.is_directory()) {
+ if (path.isDirectory()) {
if (DirectoriesToRemove == NULL)
DirectoriesToRemove = new std::vector<sys::Path>;
if (FilesToRemove != NULL)
while (!FilesToRemove->empty()) {
try {
- FilesToRemove->back().destroy_file();
+ FilesToRemove->back().destroyFile();
} catch (...) {
}
FilesToRemove->pop_back();
if (DirectoriesToRemove != NULL)
while (!DirectoriesToRemove->empty()) {
try {
- DirectoriesToRemove->back().destroy_directory(true);
+ DirectoriesToRemove->back().destroyDirectory(true);
} catch (...) {
}
DirectoriesToRemove->pop_back();
// If the source library's module id is in the dependent library list of the
// destination library, remove it since that module is now linked in.
sys::Path modId;
- modId.set_file(Src->getModuleIdentifier());
- if (!modId.is_empty())
- Dest->removeLibrary(modId.get_basename());
+ modId.setFile(Src->getModuleIdentifier());
+ if (!modId.isEmpty())
+ Dest->removeLibrary(modId.getBasename());
return false;
}
bool SharedObjectOnly) {
// Determine if the pathname can be found as it stands.
sys::Path FilePath;
- if (FilePath.set_file(Filename) && FilePath.readable())
+ if (FilePath.setFile(Filename) && FilePath.readable())
return Filename;
// Ask the System Path object to locate the library. This ensures that
//
static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
sys::Path Filename;
- if (!Filename.set_file(FN)) {
+ if (!Filename.setFile(FN)) {
std::cerr << "Invalid file name: '" << FN << "'\n";
return std::auto_ptr<Module>();
}
StringVector::const_iterator E = paths.end();
while (I != E) {
sys::Path tmp;
- tmp.set_directory(*I);
+ tmp.setDirectory(*I);
IncludePaths.push_back(tmp);
++I;
}
StringVector::const_iterator E = paths.end();
while (I != E) {
sys::Path tmp;
- tmp.set_directory(*I);
+ tmp.setDirectory(*I);
LibraryPaths.push_back(tmp);
++I;
}
LibraryPaths.push_back(libPath);
}
+ virtual void addToolPath( const sys::Path& toolPath ) {
+ ToolPaths.push_back(toolPath);
+ }
+
virtual void setfPassThrough(const StringVector& fOpts) {
fOptions = fOpts;
}
void cleanup() {
if (!isSet(KEEP_TEMPS_FLAG)) {
- if (TempDir.is_directory() && TempDir.writable())
- TempDir.destroy_directory(/*remove_contents=*/true);
+ if (TempDir.isDirectory() && TempDir.writable())
+ TempDir.destroyDirectory(/*remove_contents=*/true);
} else {
std::cout << "Temporary files are in " << TempDir.get() << "\n";
}
sys::Path MakeTempFile(const std::string& basename,
const std::string& suffix ) {
sys::Path result(TempDir);
- if (!result.append_file(basename))
+ if (!result.appendFile(basename))
throw basename + ": can't use this file name";
- if (!result.append_suffix(suffix))
+ if (!result.appendSuffix(suffix))
throw suffix + ": can't use this file suffix";
return result;
}
if (!isSet(DRY_RUN_FLAG)) {
sys::Path progpath = sys::Program::FindProgramByName(
action->program.get());
- if (progpath.is_empty())
+ if (progpath.isEmpty())
throw std::string("Can't find program '"+progpath.get()+"'");
else if (progpath.executable())
action->program = progpath;
const sys::Path& dir,
bool native = false) {
sys::Path fullpath(dir);
- fullpath.append_file(link_item);
+ fullpath.appendFile(link_item);
if (native) {
- fullpath.append_suffix("a");
+ fullpath.appendSuffix("a");
} else {
- fullpath.append_suffix("bc");
+ fullpath.appendSuffix("bc");
if (fullpath.readable())
return fullpath;
- fullpath.elide_suffix();
- fullpath.append_suffix("o");
+ fullpath.elideSuffix();
+ fullpath.appendSuffix("o");
if (fullpath.readable())
return fullpath;
fullpath = dir;
- fullpath.append_file(std::string("lib") + link_item);
- fullpath.append_suffix("a");
+ fullpath.appendFile(std::string("lib") + link_item);
+ fullpath.appendSuffix("a");
if (fullpath.readable())
return fullpath;
- fullpath.elide_suffix();
- fullpath.append_suffix("so");
+ fullpath.elideSuffix();
+ fullpath.appendSuffix("so");
if (fullpath.readable())
return fullpath;
}
// on the command line.
PathVector::iterator PI = LibraryPaths.begin();
PathVector::iterator PE = LibraryPaths.end();
- while (PI != PE && fullpath.is_empty()) {
+ while (PI != PE && fullpath.isEmpty()) {
fullpath = GetPathForLinkageItem(link_item.get(),*PI);
++PI;
}
// If we didn't find the file in any of the library search paths
// so we have to bail. No where else to look.
- if (fullpath.is_empty()) {
+ if (fullpath.isEmpty()) {
err =
std::string("Can't find linkage item '") + link_item.get() + "'";
return false;
set.insert(fullpath);
// If its an LLVM bytecode file ...
- if (fullpath.is_bytecode_file()) {
+ if (fullpath.isBytecodeFile()) {
// Process the dependent libraries recursively
Module::LibraryListType modlibs;
if (GetBytecodeDependentLibraries(fullpath.get(),modlibs)) {
// If they are asking for linking and didn't provide an output
// file then its an error (no way for us to "make up" a meaningful
// file name based on the various linker input files).
- if (finalPhase == LINKING && Output.is_empty())
+ if (finalPhase == LINKING && Output.isEmpty())
throw std::string(
"An output file name must be specified for linker output");
// If they are not asking for linking, provided an output file and
// there is more than one input file, its an error
- if (finalPhase != LINKING && !Output.is_empty() && InpList.size() > 1)
+ if (finalPhase != LINKING && !Output.isEmpty() && InpList.size() > 1)
throw std::string("An output file name cannot be specified ") +
"with more than one input file name when not linking";
// Initialize the input and output files
sys::Path InFile(I->first);
- sys::Path OutFile(I->first.get_basename());
+ sys::Path OutFile(I->first.getBasename());
// PRE-PROCESSING PHASE
Action& action = cd->PreProcessor;
// Get the preprocessing action, if needed, or error if appropriate
- if (!action.program.is_empty()) {
+ if (!action.program.isEmpty()) {
if (action.isSet(REQUIRED_FLAG) || finalPhase == PREPROCESSING) {
if (finalPhase == PREPROCESSING) {
- OutFile.append_suffix("E");
+ OutFile.appendSuffix("E");
actions.push_back(GetAction(cd,InFile,OutFile,PREPROCESSING));
} else {
- sys::Path TempFile(MakeTempFile(I->first.get_basename(),"E"));
+ sys::Path TempFile(MakeTempFile(I->first.getBasename(),"E"));
actions.push_back(GetAction(cd,InFile,TempFile,
PREPROCESSING));
InFile = TempFile;
action = cd->Translator;
// Get the translation action, if needed, or error if appropriate
- if (!action.program.is_empty()) {
+ if (!action.program.isEmpty()) {
if (action.isSet(REQUIRED_FLAG) || finalPhase == TRANSLATION) {
if (finalPhase == TRANSLATION) {
- OutFile.append_suffix("o");
+ OutFile.appendSuffix("o");
actions.push_back(GetAction(cd,InFile,OutFile,TRANSLATION));
} else {
- sys::Path TempFile(MakeTempFile(I->first.get_basename(),"trans"));
+ sys::Path TempFile(MakeTempFile(I->first.getBasename(),"trans"));
actions.push_back(GetAction(cd,InFile,TempFile,TRANSLATION));
InFile = TempFile;
}
/// The output of the translator is an LLVM Assembly program
/// We need to translate it to bytecode
Action* action = new Action();
- action->program.set_file("llvm-as");
+ action->program.setFile("llvm-as");
action->args.push_back(InFile.get());
action->args.push_back("-o");
- InFile.append_suffix("bc");
+ InFile.appendSuffix("bc");
action->args.push_back(InFile.get());
actions.push_back(action);
}
// Get the optimization action, if needed, or error if appropriate
if (!isSet(EMIT_RAW_FLAG)) {
- if (!action.program.is_empty()) {
+ if (!action.program.isEmpty()) {
if (action.isSet(REQUIRED_FLAG) || finalPhase == OPTIMIZATION) {
if (finalPhase == OPTIMIZATION) {
- OutFile.append_suffix("o");
+ OutFile.appendSuffix("o");
actions.push_back(GetAction(cd,InFile,OutFile,OPTIMIZATION));
} else {
- sys::Path TempFile(MakeTempFile(I->first.get_basename(),"opt"));
+ sys::Path TempFile(MakeTempFile(I->first.getBasename(),"opt"));
actions.push_back(GetAction(cd,InFile,TempFile,OPTIMIZATION));
InFile = TempFile;
}
/// The output of the optimizer is an LLVM Assembly program
/// We need to translate it to bytecode with llvm-as
Action* action = new Action();
- action->program.set_file("llvm-as");
+ action->program.setFile("llvm-as");
action->args.push_back(InFile.get());
action->args.push_back("-f");
action->args.push_back("-o");
- InFile.append_suffix("bc");
+ InFile.appendSuffix("bc");
action->args.push_back(InFile.get());
actions.push_back(action);
}
if (isSet(EMIT_NATIVE_FLAG)) {
// Use llc to get the native assembly file
Action* action = new Action();
- action->program.set_file("llc");
+ action->program.setFile("llc");
action->args.push_back(InFile.get());
action->args.push_back("-f");
action->args.push_back("-o");
- OutFile.append_suffix("s");
+ OutFile.appendSuffix("s");
action->args.push_back(OutFile.get());
} else {
// Just convert back to llvm assembly with llvm-dis
Action* action = new Action();
- action->program.set_file("llvm-dis");
+ action->program.setFile("llvm-dis");
action->args.push_back(InFile.get());
action->args.push_back("-f");
action->args.push_back("-o");
- OutFile.append_suffix("ll");
+ OutFile.appendSuffix("ll");
action->args.push_back(OutFile.get());
actions.push_back(action);
}
// Set up the linking action with llvm-ld
Action* link = new Action();
- link->program.set_file("llvm-ld");
+ link->program.setFile("llvm-ld");
// Add in the optimization level requested
switch (optLevel) {
std::string machine; ///< Target machine name
PathVector LibraryPaths; ///< -L options
PathVector IncludePaths; ///< -I options
+ PathVector ToolPaths; ///< -B options
StringVector Defines; ///< -D options
sys::Path TempDir; ///< Name of the temporary directory.
StringTable AdditionalArgs; ///< The -Txyz options
/// @brief Set the output machine name.
virtual void setOutputMachine(const std::string& machineName) = 0;
- /// @brief Set Preprocessor specific options
+ /// @brief Set the options for a given phase.
virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0;
/// @brief Set Library Paths
/// @brief Set Library Paths
virtual void setLibraryPaths(const StringVector& paths) = 0;
- /// @brief Set the list of library paths to be searched for
- /// libraries.
+ /// @brief Add a path to the list of library paths
virtual void addLibraryPath( const sys::Path& libPath ) = 0;
+ /// @brief Add a path to the list of paths in which to find tools
+ virtual void addToolPath( const sys::Path& toolPath) = 0;
+
/// @brief Set the list of -f options to be passed through
virtual void setfPassThrough(const StringVector& fOpts) = 0;
action.args.clear();
} else {
if (token == STRING || token == OPTION) {
- action.program.set_file(ConfigLexerState.StringVal);
+ action.program.setFile(ConfigLexerState.StringVal);
} else {
error("Expecting a program name");
}
LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
CompilerDriver::ConfigData* result = 0;
sys::Path confFile;
- if (configDir.is_empty()) {
+ if (configDir.isEmpty()) {
// Try the environment variable
const char* conf = getenv("LLVM_CONFIG_DIR");
if (conf) {
- confFile.set_directory(conf);
- confFile.append_file(ftype);
+ confFile.setDirectory(conf);
+ confFile.appendFile(ftype);
if (!confFile.readable())
throw std::string("Configuration file for '") + ftype +
"' is not available.";
} else {
// Try the user's home directory
confFile = sys::Path::GetUserHomeDirectory();
- if (!confFile.is_empty()) {
- confFile.append_directory(".llvm");
- confFile.append_directory("etc");
- confFile.append_file(ftype);
+ if (!confFile.isEmpty()) {
+ confFile.appendDirectory(".llvm");
+ confFile.appendDirectory("etc");
+ confFile.appendFile(ftype);
if (!confFile.readable())
confFile.clear();
}
- if (!confFile.is_empty()) {
+ if (!confFile.isEmpty()) {
// Okay, try the LLVM installation directory
confFile = sys::Path::GetLLVMConfigDir();
- confFile.append_file(ftype);
+ confFile.appendFile(ftype);
if (!confFile.readable()) {
// Okay, try the "standard" place
confFile = sys::Path::GetLLVMDefaultConfigDir();
- confFile.append_file(ftype);
+ confFile.appendFile(ftype);
if (!confFile.readable()) {
throw std::string("Configuration file for '") + ftype +
"' is not available.";
}
} else {
confFile = configDir;
- confFile.append_file(ftype);
+ confFile.appendFile(ftype);
if (!confFile.readable())
throw std::string("Configuration file for '") + ftype +
"' is not available.";
cl::desc("Pass through -W options to compiler tools"),
cl::value_desc("warnings category"));
+cl::list<std::string> BOpt("B", cl::ZeroOrMore, cl::Prefix,
+ cl::desc("Indicate where llvmc sub-tools are installed"),
+ cl::value_desc("directory path containing bin and lib directories"));
+
//===------------------------------------------------------------------------===
//=== INPUT OPTIONS
//===------------------------------------------------------------------------===