1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Jason Nguyen <jason.nguyen@monash.edu>
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <minizinc/flatten_internal.hh>
#include <minizinc/warning.hh>
namespace MiniZinc {
void Warning::print(std::ostream& os, bool werror) const {
os << (werror ? "Error" : "Warning") << ": " << _msg << "\n";
if (_stack != nullptr && !_stack->empty()) {
_stack->print(os);
} else if (!_loc.filename().empty()) {
os << _loc << "\n";
}
}
void Warning::json(std::ostream& os, bool werror) const {
os << "{\"type\": \"";
if (werror) {
os << "error\", \"what\": \"";
}
os << "warning\", ";
if (!_loc.filename().empty()) {
os << "\"location\": " << _loc.toJSON() << ", ";
}
if (_stack != nullptr && !_stack->empty()) {
os << "\"stack\": ";
_stack->json(os);
os << ", ";
}
os << "\"message\": \"" << Printer::escapeStringLit(_msg) << "\"}" << std::endl;
}
} // namespace MiniZinc
|