diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-11 15:09:21 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-11 15:09:21 +0100 |
commit | 4048ee8150cad5253fd6f0245c9a357484eac3f2 (patch) | |
tree | 2434df63c0766d6c2f8f8294af9104697f4abae2 /src/error.h | |
parent | 7206f6d1249da0dd8e879d0c0b26185fc6ef89d9 (diff) | |
download | sciteco-4048ee8150cad5253fd6f0245c9a357484eac3f2.tar.gz |
refactored SciTECO runtime errors: moved from parser.cpp to error.cpp
* the GError expection has been renamed to GlibError, to avoid
nameclashes when working from the SciTECO namespace
Diffstat (limited to 'src/error.h')
-rw-r--r-- | src/error.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/src/error.h b/src/error.h new file mode 100644 index 0000000..2786929 --- /dev/null +++ b/src/error.h @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2012-2014 Robin Haberkorn + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __ERROR_H +#define __ERROR_H + +#include <exception> +#include <typeinfo> + +#include <glib.h> +#include <glib/gprintf.h> + +#include "sciteco.h" + +namespace SciTECO { + +/* thrown as exception, executed at cmdline macro level */ +class ReplaceCmdline { +public: + gchar *new_cmdline; + gint pos; + + ReplaceCmdline(); +}; + +class Error { + gchar *description; + GSList *frames; + +public: + gint pos; + gint line, column; + + class Frame { + public: + gint pos; + gint line, column; + + virtual Frame *copy() const = 0; + virtual ~Frame() {} + + virtual void display(gint nr) = 0; + }; + + class QRegFrame : public Frame { + gchar *name; + + public: + QRegFrame(const gchar *_name) + : name(g_strdup(_name)) {} + + Frame *copy() const; + + ~QRegFrame() + { + g_free(name); + } + + void display(gint nr); + }; + + class FileFrame : public Frame { + gchar *name; + + public: + FileFrame(const gchar *_name) + : name(g_strdup(_name)) {} + + Frame *copy() const; + + ~FileFrame() + { + g_free(name); + } + + void display(gint nr); + }; + + class ToplevelFrame : public Frame { + public: + Frame *copy() const; + + void display(gint nr); + }; + + Error(const gchar *fmt, ...) G_GNUC_PRINTF(2, 3); + Error(const Error &inst); + ~Error(); + + void add_frame(Frame *frame); + + void display_short(void); + void display_full(void); +}; + +class StdError : public Error { +public: + StdError(const gchar *type, const std::exception &error) + : Error("%s: %s", type, error.what()) {} + StdError(const std::exception &error) + : Error("%s: %s", typeid(error).name(), error.what()) {} +}; + +class GlibError : public Error { +public: + GlibError(const GError *gerror) + : Error("%s", gerror->message) {} +}; + +class SyntaxError : public Error { +public: + SyntaxError(gchar chr) + : Error("Syntax error \"%c\" (%d)", chr, chr) {} +}; + +class ArgExpectedError : public Error { +public: + ArgExpectedError(const gchar *cmd) + : Error("Argument expected for <%s>", cmd) {} + ArgExpectedError(gchar cmd) + : Error("Argument expected for <%c>", cmd) {} +}; + +class MoveError : public Error { +public: + MoveError(const gchar *cmd) + : Error("Attempt to move pointer off page with <%s>", + cmd) {} + MoveError(gchar cmd) + : Error("Attempt to move pointer off page with <%c>", + cmd) {} +}; + +class RangeError : public Error { +public: + RangeError(const gchar *cmd) + : Error("Invalid range specified for <%s>", cmd) {} + RangeError(gchar cmd) + : Error("Invalid range specified for <%c>", cmd) {} +}; + +class InvalidQRegError : public Error { +public: + InvalidQRegError(const gchar *name, bool local = false) + : Error("Invalid Q-Register \"%s%s\"", + local ? "." : "", name) {} + InvalidQRegError(gchar name, bool local = false) + : Error("Invalid Q-Register \"%s%c\"", + local ? "." : "", name) {} +}; + +} /* namespace SciTECO */ + +#endif |