32 #ifndef DOXYGEN_SHOULD_SKIP_THIS 42 is_error(is_error), line(line), column(0), msg(msg), filename(
""), code(
"") {
45 ParseError::ParseError(
bool is_error,
46 const std::string& msg,
47 const std::string& filename,
51 line(line), column(col), msg(msg), filename(filename), code(
"") {}
53 ParseError::ParseError(
bool is_error,
54 const std::string& msg,
55 const std::string& filename,
56 const std::string& code,
60 line(line), column(col), msg(msg), filename(filename), code(code) {}
62 ParseError::ParseError(
const ParseError& err) {
63 is_error = err.is_error;
67 filename = err.filename;
71 ParseError ParseError::operator=(
const ParseError& err) {
73 is_error = err.is_error;
77 filename = err.filename;
85 std::string ParseError::toString()
const {
88 if (!filename.empty()) s << filename <<
":";
90 if (line > 0) s << line <<
": ";
92 if (column > 0) s << column <<
" : ";
94 s << (is_error ?
"error" :
"warning") <<
" : " << msg;
100 std::string ParseError::toElegantString()
const {
102 std::ifstream ifs(filename.c_str());
104 for (
Idx i = 0; i < line; i++)
105 std::getline(ifs, code);
108 std::ostringstream s;
110 s << toString() << std::endl << code << std::endl;
112 if (column > 0) s << std::string(column - 1,
' ') <<
"^";
117 ParseError ErrorsContainer::error(
Idx i)
const {
121 GUM_ERROR(OutOfBounds,
"Index out of bound.");
125 ParseError ErrorsContainer::last()
const {
127 return errors[count() - 1];
129 GUM_ERROR(OutOfBounds,
"Index out of bound.");
133 ErrorsContainer::ErrorsContainer() {
138 ErrorsContainer::ErrorsContainer(
const ErrorsContainer& cont) {
139 error_count = cont.error_count;
140 warning_count = cont.warning_count;
142 errors = cont.errors;
146 ErrorsContainer newCont;
148 newCont.error_count = this->error_count + cont.error_count;
149 newCont.warning_count = this->warning_count + cont.warning_count;
150 std::copy(this->errors.begin(), this->errors.end(), newCont.errors.begin());
151 std::copy(cont.errors.begin(), cont.errors.end(), newCont.errors.end());
156 ErrorsContainer ErrorsContainer::operator=(
const ErrorsContainer& cont) {
157 error_count = cont.error_count;
158 warning_count = cont.warning_count;
160 errors = cont.errors;
165 ErrorsContainer ErrorsContainer::operator+=(
const ErrorsContainer& cont) {
166 error_count += cont.error_count;
167 warning_count += cont.warning_count;
169 for (
Idx i = 0; i < cont.count(); i++)
170 errors.push_back(cont.error(i));
175 void ErrorsContainer::simpleErrors(std::ostream& o)
const {
176 if (count() == 0)
return;
178 for (
Idx i = 0; i < count(); i++) {
179 if (error(i).is_error) o << error(i).toString() << std::endl;
183 void ErrorsContainer::simpleErrorsAndWarnings(std::ostream& o)
const {
184 if (count() == 0)
return;
186 for (
Idx i = 0; i < count(); i++)
187 o << error(i).toString() << std::endl;
190 void ErrorsContainer::elegantErrors(std::ostream& o)
const {
191 if (count() == 0)
return;
193 for (
Idx i = 0; i < count(); i++) {
194 if (error(i).is_error) {
195 o << error(i).toElegantString();
201 void ErrorsContainer::elegantErrorsAndWarnings(std::ostream& o)
const {
202 if (count() == 0)
return;
204 for (
Idx i = 0; i < count(); i++) {
205 o << error(i).toElegantString();
212 #endif // DOXYGEN_SHOULD_SKIP_THIS Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
ParseError(bool is_error, const std::string &msg, Idx line)
Class constructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void clear()
Clear all data of the calling expression as if it was constructed.
LpExpr operator+(LpExpr &&lhs, const T2 &rhs)
Overload of operator + between anything ( a scalar, a variable or an expression ) and anything except...
#define GUM_ERROR(type, msg)