Skip to content

Commit

Permalink
Change
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Aug 24, 2023
1 parent b838cdb commit 4bfad63
Show file tree
Hide file tree
Showing 5 changed files with 1,936 additions and 24 deletions.
2 changes: 2 additions & 0 deletions changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Bug fixes:
- Ensure reverse mappers are created when flattening tuple/record literals.
This resolves certain errors during output processing in models using these
types.
- Fix problem where certain strings in exceptions might be garbage collected
before they are output (:bugref:`725`).

.. _v2.7.6:

Expand Down
59 changes: 35 additions & 24 deletions include/minizinc/astexception.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,24 @@

#include <minizinc/ast.hh>
#include <minizinc/exception.hh>
#include <minizinc/gc.hh>
#include <minizinc/model.hh>
#include <minizinc/stackdump.hh>

#include <string>

namespace MiniZinc {

class SyntaxError : public Exception {
class CyclicIncludeError : public Exception, public GCMarker {
protected:
Location _loc;
std::string _currentLine;
std::vector<ASTString> _includeStack;

public:
SyntaxError(const Location& loc, const std::string& msg) : Exception(msg) {}
SyntaxError(const Location& loc, std::string currentLine, std::vector<ASTString> includeStack,
const std::string& msg)
: Exception(msg),
_loc(loc),
_currentLine(std::move(currentLine)),
_includeStack(std::move(includeStack)) {}
~SyntaxError() throw() override {}
const char* what() const throw() override { return "syntax error"; }
const Location& loc() const { return _loc; }

void print(std::ostream& os) const override;
void json(std::ostream& os) const override;
};

class CyclicIncludeError : public Exception {
protected:
Location _loc;
std::vector<ASTString> _cycle;

void mark() override {
for (auto s : _cycle) {
s.mark();
}
}

public:
CyclicIncludeError(std::vector<ASTString> cycle) : Exception(""), _cycle(std::move(cycle)) {}
~CyclicIncludeError() throw() override {}
Expand All @@ -68,6 +52,7 @@ protected:
}

public:
LocationException(const Location& loc, const std::string& msg);
LocationException(EnvI& env, const Location& loc, const std::string& msg);
~LocationException() throw() override {}
const Location& loc() const { return _loc; }
Expand All @@ -79,6 +64,32 @@ public:
void json(std::ostream& os) const override;
};

class SyntaxError : public LocationException {
protected:
std::string _currentLine;
std::vector<ASTString> _includeStack;

void mark() override {
LocationException::mark();
for (auto s : _includeStack) {
s.mark();
}
}

public:
SyntaxError(const Location& loc, const std::string& msg) : LocationException(loc, msg) {}
SyntaxError(const Location& loc, std::string currentLine, std::vector<ASTString> includeStack,
const std::string& msg)
: LocationException(loc, msg),
_currentLine(std::move(currentLine)),
_includeStack(std::move(includeStack)) {}
~SyntaxError() throw() override {}
const char* what() const throw() override { return "syntax error"; }

void print(std::ostream& os) const override;
void json(std::ostream& os) const override;
};

class IncludeError : public LocationException {
public:
IncludeError(EnvI& env, const Location& loc, const std::string& msg)
Expand Down
1 change: 1 addition & 0 deletions include/minizinc/stackdump.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Expression;
class StackDump {
public:
StackDump(EnvI& env);
StackDump() {}
void print(std::ostream& os) const;
void json(std::ostream& os) const;
bool empty() const { return _stack.empty(); }
Expand Down
3 changes: 3 additions & 0 deletions lib/astexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ void CyclicIncludeError::json(std::ostream& os) const {
LocationException::LocationException(EnvI& env, const Location& loc, const std::string& msg)
: Exception(msg), _stack(env), _loc(loc) {}

LocationException::LocationException(const Location& loc, const std::string& msg)
: Exception(msg), _loc(loc) {}

void LocationException::print(std::ostream& os) const {
Exception::print(os);
if (_dumpStack) {
Expand Down

0 comments on commit 4bfad63

Please sign in to comment.