Skip to content

Commit 39dce85

Browse files
author
Daniel Kroening
committed
added source_locationt::full_path()
1 parent 70b98fe commit 39dce85

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/util/source_location.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ void source_locationt::merge(const source_locationt &from)
7171
}
7272
}
7373

74+
/// Get a path to the file, including working directory.
75+
/// \return Full path unless the file name is empty or refers
76+
/// to a built-in, in which case {} is returned.
77+
optionalt<std::string> source_locationt::full_path() const
78+
{
79+
const auto file = id2string(get_file());
80+
81+
if(file.empty() || is_built_in(file))
82+
return {};
83+
84+
return concat_dir_file(id2string(get_working_directory()), file);
85+
}
86+
7487
std::ostream &operator << (
7588
std::ostream &out,
7689
const source_locationt &source_location)

src/util/source_location.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include "invariant.h"
1414
#include "irep.h"
15+
#include "optional.h"
1516
#include "prefix.h"
1617

1718
#include <string>
@@ -185,6 +186,8 @@ class source_locationt:public irept
185186
return static_cast<const source_locationt &>(get_nil_irep());
186187
}
187188

189+
optionalt<std::string> full_path() const;
190+
188191
protected:
189192
std::string as_string(bool print_cwd) const;
190193
};

0 commit comments

Comments
 (0)