handle Pos instead of individual file/line/columnrange args
This commit is contained in:
parent
7b7801d3f0
commit
9bb528d392
|
@ -8,7 +8,6 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include <boost/format.hpp>
|
|
||||||
|
|
||||||
namespace nix
|
namespace nix
|
||||||
{
|
{
|
||||||
|
@ -62,19 +61,7 @@ template <class T>
|
||||||
class AddDescription;
|
class AddDescription;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class AddNixCode;
|
class AddPos;
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class AddNixFile;
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class AddErrLine;
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class AddLineNumber;
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class AddColumnRange;
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class AddLOC;
|
class AddLOC;
|
||||||
|
@ -99,11 +86,7 @@ public:
|
||||||
// when they are direct descendants (children but not grandchildren).
|
// when they are direct descendants (children but not grandchildren).
|
||||||
friend AddName<ErrorInfo>;
|
friend AddName<ErrorInfo>;
|
||||||
friend AddDescription<ErrorInfo>;
|
friend AddDescription<ErrorInfo>;
|
||||||
friend AddNixCode<ErrorInfo>;
|
friend AddPos<ErrorInfo>;
|
||||||
friend AddNixFile<ErrorInfo>;
|
|
||||||
friend AddErrLine<ErrorInfo>;
|
|
||||||
friend AddLineNumber<ErrorInfo>;
|
|
||||||
friend AddColumnRange<ErrorInfo>;
|
|
||||||
friend AddLOC<ErrorInfo>;
|
friend AddLOC<ErrorInfo>;
|
||||||
|
|
||||||
NixCode& ensureNixCode()
|
NixCode& ensureNixCode()
|
||||||
|
@ -168,44 +151,15 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class AddNixFile : private T
|
class AddPos : private T
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
T& nixFile(string filename)
|
template <class P>
|
||||||
|
T& pos(const P &aPos)
|
||||||
{
|
{
|
||||||
GetEI().ensureNixCode().nixFile = filename;
|
GetEI().ensureNixCode().nixFile = aPos.file;
|
||||||
return *this;
|
GetEI().ensureNixCode().ensureErrLine().lineNumber = aPos.line;
|
||||||
}
|
GetEI().ensureNixCode().ensureErrLine().columnRange = { .start = aPos.column, .len = 1 };
|
||||||
protected:
|
|
||||||
ErrorInfo& GetEI()
|
|
||||||
{
|
|
||||||
return T::GetEI();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class AddLineNumber : private T
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
T& lineNumber(int lineNumber)
|
|
||||||
{
|
|
||||||
GetEI().ensureNixCode().ensureErrLine().lineNumber = lineNumber;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
ErrorInfo& GetEI()
|
|
||||||
{
|
|
||||||
return T::GetEI();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class AddColumnRange : private T
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
T& columnRange(unsigned int start, unsigned int len)
|
|
||||||
{
|
|
||||||
GetEI().ensureNixCode().ensureErrLine().columnRange = { start, len };
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
@ -323,21 +277,17 @@ EIWarning>>> ProgramWarning;
|
||||||
|
|
||||||
typedef AddName<
|
typedef AddName<
|
||||||
AddDescription<
|
AddDescription<
|
||||||
AddNixFile<
|
AddPos<
|
||||||
AddLineNumber<
|
|
||||||
AddColumnRange<
|
|
||||||
AddLOC<
|
AddLOC<
|
||||||
AddHint<
|
AddHint<
|
||||||
EIError>>>>>>> NixLangError;
|
EIError>>>>> NixLangError;
|
||||||
|
|
||||||
typedef AddName<
|
typedef AddName<
|
||||||
AddDescription<
|
AddDescription<
|
||||||
AddNixFile<
|
AddPos<
|
||||||
AddLineNumber<
|
|
||||||
AddColumnRange<
|
|
||||||
AddLOC<
|
AddLOC<
|
||||||
AddHint<
|
AddHint<
|
||||||
EIWarning>>>>>>> NixLangWarning;
|
EIWarning>>>>> NixLangWarning;
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "../../src/libutil/error.hh"
|
#include "../../src/libutil/error.hh"
|
||||||
|
#include "../../src/libexpr/nixexpr.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -58,12 +59,14 @@ int main()
|
||||||
|
|
||||||
// NixLangWarning adds nix file, line number, column range, and the lines of
|
// NixLangWarning adds nix file, line number, column range, and the lines of
|
||||||
// code where a warning occurred.
|
// code where a warning occurred.
|
||||||
|
|
||||||
|
SymbolTable testTable;
|
||||||
|
auto problem_symbol = testTable.create("problem");
|
||||||
|
|
||||||
printErrorInfo(NixLangWarning()
|
printErrorInfo(NixLangWarning()
|
||||||
.name("warning name")
|
.name("warning name")
|
||||||
.description("warning description")
|
.description("warning description")
|
||||||
.nixFile("myfile.nix")
|
.pos(Pos(problem_symbol, 40, 13))
|
||||||
.lineNumber(40)
|
|
||||||
.columnRange(13, 7)
|
|
||||||
.linesOfCode(std::nullopt,
|
.linesOfCode(std::nullopt,
|
||||||
"this is the problem line of code",
|
"this is the problem line of code",
|
||||||
std::nullopt)
|
std::nullopt)
|
||||||
|
@ -74,9 +77,7 @@ int main()
|
||||||
printErrorInfo(NixLangError()
|
printErrorInfo(NixLangError()
|
||||||
.name("error name")
|
.name("error name")
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.nixFile("myfile.nix")
|
.pos(Pos(problem_symbol, 40, 13))
|
||||||
.lineNumber(40)
|
|
||||||
.columnRange(13, 7)
|
|
||||||
.linesOfCode(std::optional("previous line of code"),
|
.linesOfCode(std::optional("previous line of code"),
|
||||||
"this is the problem line of code",
|
"this is the problem line of code",
|
||||||
std::optional("next line of code"))
|
std::optional("next line of code"))
|
||||||
|
|
Loading…
Reference in a new issue