From 9bb528d3920559454a1ce0f8f4ac3ba58b18f6d1 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 3 Apr 2020 13:15:59 -0600 Subject: [PATCH] handle Pos instead of individual file/line/columnrange args --- src/libutil/error.hh | 98 +++++++++++--------------------------------- tests/errors/main.cc | 13 +++--- 2 files changed, 31 insertions(+), 80 deletions(-) diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 1c5d6d13c..57a9944be 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -8,7 +8,6 @@ #include #include "types.hh" -#include namespace nix { @@ -62,19 +61,7 @@ template class AddDescription; template -class AddNixCode; - -template -class AddNixFile; - -template -class AddErrLine; - -template -class AddLineNumber; - -template -class AddColumnRange; +class AddPos; template class AddLOC; @@ -99,11 +86,7 @@ public: // when they are direct descendants (children but not grandchildren). friend AddName; friend AddDescription; - friend AddNixCode; - friend AddNixFile; - friend AddErrLine; - friend AddLineNumber; - friend AddColumnRange; + friend AddPos; friend AddLOC; NixCode& ensureNixCode() @@ -168,44 +151,15 @@ protected: }; template -class AddNixFile : private T +class AddPos : private T { public: - T& nixFile(string filename) + template + T& pos(const P &aPos) { - GetEI().ensureNixCode().nixFile = filename; - return *this; - } -protected: - ErrorInfo& GetEI() - { - return T::GetEI(); - } -}; - -template -class AddLineNumber : private T -{ -public: - T& lineNumber(int lineNumber) - { - GetEI().ensureNixCode().ensureErrLine().lineNumber = lineNumber; - return *this; - } -protected: - ErrorInfo& GetEI() - { - return T::GetEI(); - } -}; - -template -class AddColumnRange : private T -{ -public: - T& columnRange(unsigned int start, unsigned int len) - { - GetEI().ensureNixCode().ensureErrLine().columnRange = { start, len }; + GetEI().ensureNixCode().nixFile = aPos.file; + GetEI().ensureNixCode().ensureErrLine().lineNumber = aPos.line; + GetEI().ensureNixCode().ensureErrLine().columnRange = { .start = aPos.column, .len = 1 }; return *this; } protected: @@ -312,32 +266,28 @@ protected: // error types typedef AddName< -AddDescription< -AddHint< -EIError>>> ProgramError; + AddDescription< + AddHint< + EIError>>> ProgramError; typedef AddName< -AddDescription< -AddHint< -EIWarning>>> ProgramWarning; + AddDescription< + AddHint< + EIWarning>>> ProgramWarning; typedef AddName< -AddDescription< -AddNixFile< -AddLineNumber< -AddColumnRange< -AddLOC< -AddHint< -EIError>>>>>>> NixLangError; + AddDescription< + AddPos< + AddLOC< + AddHint< + EIError>>>>> NixLangError; typedef AddName< -AddDescription< -AddNixFile< -AddLineNumber< -AddColumnRange< -AddLOC< -AddHint< -EIWarning>>>>>>> NixLangWarning; + AddDescription< + AddPos< + AddLOC< + AddHint< + EIWarning>>>>> NixLangWarning; // -------------------------------------------------------- diff --git a/tests/errors/main.cc b/tests/errors/main.cc index be98bd5b8..cd6ca7caf 100644 --- a/tests/errors/main.cc +++ b/tests/errors/main.cc @@ -1,4 +1,5 @@ #include "../../src/libutil/error.hh" +#include "../../src/libexpr/nixexpr.hh" #include #include @@ -58,12 +59,14 @@ int main() // NixLangWarning adds nix file, line number, column range, and the lines of // code where a warning occurred. + + SymbolTable testTable; + auto problem_symbol = testTable.create("problem"); + printErrorInfo(NixLangWarning() .name("warning name") .description("warning description") - .nixFile("myfile.nix") - .lineNumber(40) - .columnRange(13, 7) + .pos(Pos(problem_symbol, 40, 13)) .linesOfCode(std::nullopt, "this is the problem line of code", std::nullopt) @@ -74,9 +77,7 @@ int main() printErrorInfo(NixLangError() .name("error name") .description("error description") - .nixFile("myfile.nix") - .lineNumber(40) - .columnRange(13, 7) + .pos(Pos(problem_symbol, 40, 13)) .linesOfCode(std::optional("previous line of code"), "this is the problem line of code", std::optional("next line of code"))