![]() |
chigraph
master
Systems programming language written for beginners in LLVM
|
The result object, used for identifiying errors with good diagnostics. More...
#include <chi/Support/Result.hpp>
Classes | |
struct | ScopedContext |
A helper object for contexts that should be removed at the end of a scope. More... | |
Public Member Functions | |
Result () | |
Default constructor; defaults to success. | |
int | addContext (const nlohmann::json &data) |
Add some json that will ALWAYS be merged with entries that are added and when results are added to this Result. More... | |
void | addEntry (const char *ec, const char *overview, nlohmann::json data) |
Add a entry to the result, either a warning or an error. More... | |
ScopedContext | addScopedContext (const nlohmann::json &data) |
Add a context with a scope Example usage: chi::Result res; res.contextJson(); // returns {} { res.contextJson(); // returns {"module": "lang"} } res.contextJson(); // returns {} . More... | |
nlohmann::json | contextJson () const |
Get the JSON associated with the context that's been added. More... | |
std::string | dump () const |
Dump to a pretty-printed error message. More... | |
operator bool () const | |
Success test. More... | |
bool | operator! () const |
!Success test More... | |
void | removeContext (int id) |
Removes a previously added context. More... | |
bool | success () const |
Success test. More... | |
Public Attributes | |
bool | mSuccess = true |
If it's successful. | |
nlohmann::json | result_json |
The result JSON. | |
Related Functions | |
(Note that these are not member functions.) | |
Result operators | |
Result | operator+ (const Result &lhs, const Result &rhs) |
Append two Result objects. More... | |
Result & | operator+= (Result &lhs, const Result &rhs) |
Append one result to an existing one. More... | |
std::ostream & | operator<< (std::ostream &lhs, const Result &rhs) |
Stream operator. More... | |
The result object, used for identifiying errors with good diagnostics.
If you want to construct a default result object, just call the default constructor:
res
is the most common name for an error object, prefer it to other names.
When constructed, results are successful by default:
When an error, warning, or just some event that requries logging needs to be added to the result object, call Result::addEntry
:
note the W
at the beginning of the error code, this is important. If it's an W
, it's considered an warning and the result will still be considered successful:
If that leading character to the error code is an 'E', then it's considered an error
And the result is not successful anymore:
If you're calling another operation that emits a Result object, then there's an easy to integrate that result object: the opeartor+=
In order to have good parsing of errors, some standards are good. If you are trying to represent this data in your error, use these standards so it can be parsed later on and presented to the user in a nice way
Name in JSON | Description |
---|---|
Node ID | The ID of the node that errored |
Not every error in chigraph is documented and tested. Errors with numbers are tested and possibly documented. EUKN errors are just undocumented errors.
Result objects store a json object that represents the error metadata. It's an array, each being an object containing three objects:
errorcode
: The errorcode. This is an identifier representng the error: a character followed by a number. The value of the character changes the behaviour:
E
: it's an error and sets success
to false.W
: it's a warningI
: it's just infoIf it's anything else, that it will cause an assertion
overview
: A simple string representing the generics of the problem. It shouldn't differ from error to error, if you need to include specifics use the data
elementdata
: Extra metadata for the error, including context and how the error occured. Definition at line 72 of file Result.hpp.
int chi::Result::addContext | ( | const nlohmann::json & | data | ) |
Add some json that will ALWAYS be merged with entries that are added and when results are added to this Result.
data | The json to merge with every entry |
Definition at line 84 of file Result.cpp.
Referenced by addScopedContext(), and Result().
void chi::Result::addEntry | ( | const char * | ec, |
const char * | overview, | ||
nlohmann::json | data | ||
) |
Add a entry to the result, either a warning or an error.
ec | The error/warning code. If it starts with E, then it is an error and success is set to false, if it starts with a W it's a warning and success can stay true if it is still true. |
overview | Basic overview of the error, this shouldn't change based on the instance of the error |
data | The detailed description this instance of the error. |
data.is_object() == true
Definition at line 52 of file Result.cpp.
References contextJson(), mSuccess, and result_json.
Referenced by chi::Subprocess::closeStdIn(), chi::compileCToLLVM(), chi::Context::compileModule(), chi::connectData(), chi::connectExec(), chi::createGraphFunctionDeclarationFromJson(), chi::GraphModule::createNodeTypeFromCCode(), chi::disconnectData(), chi::disconnectExec(), chi::FunctionCompiler::initialize(), chi::GraphFunction::insertNode(), chi::interpretLLVMIR(), chi::interpretLLVMIRAsMain(), chi::jsonToGraphFunction(), chi::jsonToGraphModule(), chi::jsonToGraphStruct(), chi::Context::nodeTypeFromModule(), chi::LangModule::nodeTypeFromName(), chi::GraphModule::nodeTypeFromName(), chi::parseBitcodeFile(), chi::Debugger::pause(), chi::Debugger::processContinue(), chi::Subprocess::pushToStdIn(), Result(), chi::GraphModule::saveToDisk(), chi::Debugger::setBreakpoint(), chi::Debugger::start(), chi::Subprocess::start(), chi::Debugger::terminate(), chi::Context::typeFromModule(), chi::validateFunctionConnectionsAreTwoWay(), chi::validateFunctionEntryType(), chi::validateFunctionExecOutputs(), chi::validateFunctionExitTypes(), and chi::validateFunctionMainSignature().
|
inline |
Add a context with a scope Example usage:
.
data | The data to add to each entry |
Definition at line 123 of file Result.hpp.
References addContext(), contextJson(), and removeContext().
Referenced by chi::Context::addModuleFromJson(), chi::compileCToLLVM(), chi::Context::compileModule(), chi::FunctionCompiler::initialize(), chi::jsonToGraphModule(), chi::Context::loadModule(), chi::validateFunctionConnectionsAreTwoWay(), chi::validateFunctionExecOutputs(), and chi::validateFunctionNodeInputs().
nlohmann::json chi::Result::contextJson | ( | ) | const |
Get the JSON associated with the context that's been added.
Definition at line 95 of file Result.cpp.
Referenced by addEntry(), addScopedContext(), operator+(), and operator+=().
std::string chi::Result::dump | ( | ) | const |
Dump to a pretty-printed error message.
Definition at line 65 of file Result.cpp.
References result_json.
Referenced by operator!(), and operator<<().
|
inlineexplicit |
Success test.
Definition at line 137 of file Result.hpp.
References success().
|
inline |
!Success test
Definition at line 145 of file Result.hpp.
References dump(), and success().
void chi::Result::removeContext | ( | int | id | ) |
Removes a previously added context.
id | The ID for the context added with addContext |
Definition at line 93 of file Result.cpp.
Referenced by addScopedContext(), and chi::Result::ScopedContext::~ScopedContext().
|
inline |
Success test.
Definition at line 141 of file Result.hpp.
References mSuccess.
Referenced by operator bool(), operator!(), operator+(), and operator+=().
Append two Result objects.
Both of the contexts are merged. The entires in lhs have the rhs context applied to them, and viceversa as well
Definition at line 106 of file Result.cpp.
References contextJson(), mSuccess, result_json, and success().
Append one result to an existing one.
Both of the contexts are merged. The entires in lhs have the rhs context applied to them, and viceversa as well
lhs | The existing Result to add to |
rhs | The (usually temporary) result to be added into lhs. |
Definition at line 127 of file Result.cpp.
References contextJson(), mSuccess, result_json, and success().
|
related |
Stream operator.
lhs | The stream |
rhs | The Result to print to lhs |
Definition at line 187 of file Result.hpp.
References dump().