1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 3 /* 4 * Main authors: 5 * Guido Tack <guido.tack@monash.edu> 6 */ 7 8 /* This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 11 12 #pragma once 13 14 #include <minizinc/ast.hh> 15 #include <minizinc/exception.hh> 16 #include <minizinc/model.hh> 17 18 #include <string> 19 20 namespace MiniZinc { 21 22 class SyntaxError : public Exception { 23 protected: 24 Location _loc; 25 26 public: SyntaxError(const Location & loc,const std::string & msg)27 SyntaxError(const Location& loc, const std::string& msg) : Exception(msg), _loc(loc) {} ~SyntaxError()28 ~SyntaxError() throw() override {} what() const29 const char* what() const throw() override { return "MiniZinc: syntax error"; } loc() const30 const Location& loc() const { return _loc; } 31 }; 32 33 class LocationException : public Exception { 34 protected: 35 Location _loc; 36 37 public: 38 LocationException(EnvI& env, const Location& loc, const std::string& msg); ~LocationException()39 ~LocationException() throw() override {} loc() const40 const Location& loc() const { return _loc; } 41 }; 42 43 class TypeError : public LocationException { 44 public: TypeError(EnvI & env,const Location & loc,const std::string & msg)45 TypeError(EnvI& env, const Location& loc, const std::string& msg) 46 : LocationException(env, loc, msg) {} ~TypeError()47 ~TypeError() throw() override {} what() const48 const char* what() const throw() override { return "MiniZinc: type error"; } 49 }; 50 51 class EvalError : public LocationException { 52 public: EvalError(EnvI & env,const Location & loc,const std::string & msg)53 EvalError(EnvI& env, const Location& loc, const std::string& msg) 54 : LocationException(env, loc, msg) {} EvalError(EnvI & env,const Location & loc,const std::string & msg,const ASTString & name)55 EvalError(EnvI& env, const Location& loc, const std::string& msg, const ASTString& name) 56 : LocationException(env, loc, "") { 57 std::ostringstream ss; 58 ss << msg << " '" << name << "'"; 59 _msg = ss.str(); 60 } ~EvalError()61 ~EvalError() throw() override {} what() const62 const char* what() const throw() override { return "MiniZinc: evaluation error"; } 63 }; 64 65 class ModelInconsistent : public LocationException { 66 public: ModelInconsistent(EnvI & env,const Location & loc,const std::string & msg="")67 ModelInconsistent(EnvI& env, const Location& loc, const std::string& msg = "") 68 : LocationException(env, loc, 69 "model inconsistency detected" + (msg.empty() ? msg : ": ") + msg) {} ~ModelInconsistent()70 ~ModelInconsistent() throw() override {} what() const71 const char* what() const throw() override { return "MiniZinc: warning"; } 72 }; 73 74 class ResultUndefinedError : public LocationException { 75 public: 76 ResultUndefinedError(EnvI& env, const Location& loc, const std::string& msg); ~ResultUndefinedError()77 ~ResultUndefinedError() throw() override {} what() const78 const char* what() const throw() override { 79 return "MiniZinc: result of evaluation is undefined"; 80 } 81 }; 82 83 } // namespace MiniZinc 84