1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 14:51:16 +02:00

Remove std::string alias (for real this time)

Also use std::string_view in a few more places.
This commit is contained in:
Eelco Dolstra 2022-02-25 16:00:00 +01:00
parent 14b38d0887
commit df552ff53e
110 changed files with 773 additions and 681 deletions

View file

@ -61,16 +61,16 @@ typedef enum {
// the lines of code surrounding an error.
struct LinesOfCode {
std::optional<string> prevLineOfCode;
std::optional<string> errLineOfCode;
std::optional<string> nextLineOfCode;
std::optional<std::string> prevLineOfCode;
std::optional<std::string> errLineOfCode;
std::optional<std::string> nextLineOfCode;
};
// ErrPos indicates the location of an error in a nix file.
struct ErrPos {
int line = 0;
int column = 0;
string file;
std::string file;
FileOrigin origin;
operator bool() const
@ -80,7 +80,7 @@ struct ErrPos {
// convert from the Pos struct, found in libexpr.
template <class P>
ErrPos& operator=(const P &pos)
ErrPos & operator=(const P & pos)
{
origin = pos.origin;
line = pos.line;
@ -94,7 +94,7 @@ struct ErrPos {
}
template <class P>
ErrPos(const P &p)
ErrPos(const P & p)
{
*this = p;
}
@ -107,15 +107,15 @@ struct Trace {
struct ErrorInfo {
Verbosity level;
string name; // FIXME: rename
std::string name; // FIXME: rename
hintformat msg;
std::optional<ErrPos> errPos;
std::list<Trace> traces;
static std::optional<string> programName;
static std::optional<std::string> programName;
};
std::ostream& showErrorInfo(std::ostream &out, const ErrorInfo &einfo, bool showTrace);
std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool showTrace);
/* BaseError should generally not be caught, as it has Interrupted as
a subclass. Catch Error instead. */
@ -124,8 +124,8 @@ class BaseError : public std::exception
protected:
mutable ErrorInfo err;
mutable std::optional<string> what_;
const string& calcWhat() const;
mutable std::optional<std::string> what_;
const std::string & calcWhat() const;
public:
unsigned int status = 1; // exit status
@ -162,11 +162,11 @@ public:
const char * what() const noexcept override { return calcWhat().c_str(); }
#endif
const string & msg() const { return calcWhat(); }
const std::string & msg() const { return calcWhat(); }
const ErrorInfo & info() const { calcWhat(); return err; }
template<typename... Args>
BaseError & addTrace(std::optional<ErrPos> e, const string &fs, const Args & ... args)
BaseError & addTrace(std::optional<ErrPos> e, const std::string & fs, const Args & ... args)
{
return addTrace(e, hintfmt(fs, args...));
}