File: warning.cpp

package info (click to toggle)
minizinc 2.9.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,620 kB
  • sloc: cpp: 74,682; ansic: 8,541; python: 3,322; sh: 79; makefile: 13
file content (43 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download | duplicates (2)
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