2020-03-22 18:25:47 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
#include <string>
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::optional;
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
enum ErrLevel
|
|
|
|
{ elWarning
|
|
|
|
, elError
|
|
|
|
};
|
|
|
|
|
|
|
|
class ColumnRange {
|
|
|
|
public:
|
|
|
|
unsigned int start;
|
|
|
|
unsigned int len;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ErrLine {
|
|
|
|
public:
|
|
|
|
int lineNumber;
|
|
|
|
optional<ColumnRange> columnRange;
|
|
|
|
optional<string> prevLineOfCode;
|
|
|
|
string errLineOfCode;
|
|
|
|
optional<string> nextLineOfCode;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NixCode {
|
|
|
|
public:
|
|
|
|
optional<string> nixFile;
|
|
|
|
optional<ErrLine> errLine;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorInfo {
|
|
|
|
public:
|
|
|
|
ErrLevel level;
|
2020-03-24 15:18:23 +00:00
|
|
|
string name;
|
2020-03-22 18:25:47 +00:00
|
|
|
string description;
|
2020-03-24 15:18:23 +00:00
|
|
|
string program;
|
2020-03-22 18:25:47 +00:00
|
|
|
optional<NixCode> nixCode;
|
|
|
|
string hint;
|
2020-03-24 15:18:23 +00:00
|
|
|
ErrorInfo& GetEI() { return *this; }
|
2020-03-22 18:25:47 +00:00
|
|
|
};
|
|
|
|
|
2020-03-24 15:18:23 +00:00
|
|
|
template <class T>
|
|
|
|
class AddName : private T
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
T& name(const std::string &name){
|
|
|
|
GetEI().name = name;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
ErrorInfo& GetEI() { return T::GetEI(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class AddDescription : private T
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
T& description(const std::string &description){
|
|
|
|
GetEI().description = description;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
ErrorInfo& GetEI() { return T::GetEI(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef AddName<AddDescription<ErrorInfo>> StandardError;
|
|
|
|
|
2020-03-22 18:25:47 +00:00
|
|
|
string showErrLine(ErrLine &errLine);
|
|
|
|
|
|
|
|
void print_code_lines(string &prefix, NixCode &nix_code);
|
|
|
|
|
|
|
|
void print_error(ErrorInfo &einfo);
|
|
|
|
}
|
|
|
|
|