diff --git a/src/qmljsc/CMakeLists.txt b/src/qmljsc/CMakeLists.txt index 4030895..2b0575e 100644 --- a/src/qmljsc/CMakeLists.txt +++ b/src/qmljsc/CMakeLists.txt @@ -1,26 +1,26 @@ find_package(Qt5 COMPONENTS Core Qml) set(libqmljsc_srcs compiler.cpp - error.h + error.cpp compilerpipeline.cpp compilerpass.cpp symboltable.cpp module.cpp ir/ir.cpp compilerpasses/parserpass.cpp compilerpasses/prettygeneratorpass.cpp ) add_library(libqmljsc SHARED ${libqmljsc_srcs}) qt5_use_modules(libqmljsc Core Qml) include_directories(${Qt5Qml_PRIVATE_INCLUDE_DIRS}) set(qmljsc_srcs main.cpp ) add_executable(qmljsc ${qmljsc_srcs}) target_link_libraries(qmljsc libqmljsc) diff --git a/src/qmljsc/error.cpp b/src/qmljsc/error.cpp new file mode 100644 index 0000000..09e71c3 --- /dev/null +++ b/src/qmljsc/error.cpp @@ -0,0 +1,34 @@ +/* + * + * Copyright (C) 2015 Anton Kreuzkamp + * + * 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 . + * + */ + +#include "error.h" + +using namespace QmlJSc; + +QDebug operator<<(QDebug dbg, const Error &error) +{ + dbg << error.what(); + + return dbg.space(); +} + +const char *QmlJSc::Error::what() const noexcept +{ + return qPrintable(description()); +} diff --git a/src/qmljsc/error.h b/src/qmljsc/error.h index 514b0e6..1942d88 100644 --- a/src/qmljsc/error.h +++ b/src/qmljsc/error.h @@ -1,94 +1,96 @@ /* * Qml.js Compiler - a QML to JS compiler bringing QML's power to the web. * * Copyright (C) 2015 Jan Marker * * 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 . * */ #ifndef ERROR_H #define ERROR_H #include #include #include #include +#include #include namespace QmlJSc { class Error : public std::exception { public: enum Type { UnknownError, ReadFileError, ParseError, ModuleImportError, - JSEngineError, SymbolLookupError }; Error() : m_type(UnknownError) , m_column(-1) , m_line(-1) , m_reason(0) {} Error(Type type, QString description, Error *reason = 0) : m_type(type) , m_description(description) , m_column(-1) , m_line(-1) , m_reason(reason) {} virtual ~Error() {} Type type() const { return m_type; } void setType(Type type) { m_type = type; } QUrl file() const { return m_file; } void setFile(QUrl file) { m_file = file; } QString description() const { return m_description; } void setDescription(QString description) { m_description = description; } int column() const { return m_column; } void setColumn(int column) { m_column = column; } int line() const { return m_line; } void setLine(int line) { m_line = line; } Error *reason() const { return m_reason.data(); } void setReason(Error *reason) { m_reason.reset(reason); } - virtual const char* what() { return description().toLocal8Bit(); } + virtual const char* what() const noexcept; private: Type m_type; QUrl m_file; QString m_description; int m_column; int m_line; QSharedPointer m_reason; }; } +QDebug operator<<(QDebug dbg, const QmlJSc::Error &error); + Q_DECLARE_METATYPE(QmlJSc::Error); #endif // ERROR_H