Move errors: types.h -> errors.h
This commit is contained in:
parent
ea11ec2944
commit
5fed47367d
@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include "include/utils.h"
|
||||
#include "include/errors.h"
|
||||
#include "include/analysis.h"
|
||||
|
||||
bool bool_castable(AnalysisResult type) {
|
||||
|
@ -1,3 +1,6 @@
|
||||
#ifndef DEF_ERRORS_H
|
||||
#define DEF_ERRORS_H
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
@ -7,3 +10,89 @@ using namespace std;
|
||||
* Display the line of code associated with an error, and highlight the associated part
|
||||
*/
|
||||
void print_error_position(vector<string> history, CodePosition pos);
|
||||
|
||||
|
||||
/**
|
||||
* Errors
|
||||
*/
|
||||
enum class ErrorType {
|
||||
// Generic
|
||||
NotImplemented,
|
||||
|
||||
// Lexing
|
||||
UnknownToken,
|
||||
IntegerTooLarge,
|
||||
|
||||
// Parsing
|
||||
EmptyInput,
|
||||
InvalidSyntax,
|
||||
ExceptedLParen,
|
||||
ExpectedRParen,
|
||||
ExpectedRCurlyBracket,
|
||||
ExpectedSemicolon,
|
||||
DependentDeclaration,
|
||||
|
||||
// Analysis
|
||||
UnknownType,
|
||||
TypeNotCastable,
|
||||
TypesNotComparable,
|
||||
ExpectedIntegralType,
|
||||
ExpectedArithmeticType,
|
||||
|
||||
// Runtime
|
||||
DivisionByZero,
|
||||
ModuloByZero,
|
||||
UnknownIdentifier,
|
||||
AlreadyDefinedIdentifier,
|
||||
UninitializedIdentifier,
|
||||
BreakNotWithinLoop,
|
||||
ContinueNotWithinLoop,
|
||||
};
|
||||
|
||||
using ErrorData = variant<monostate, string>;
|
||||
|
||||
class UserError : public exception {
|
||||
public:
|
||||
explicit UserError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: pos(pos), type(type), data(data) {}
|
||||
|
||||
const char* what() const noexcept override {
|
||||
return "User error occurred.";
|
||||
}
|
||||
|
||||
const CodePosition pos;
|
||||
const ErrorType type;
|
||||
const ErrorData data;
|
||||
};
|
||||
|
||||
class SyntaxError : public UserError {
|
||||
public:
|
||||
explicit SyntaxError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: UserError(type, pos, data) {}
|
||||
};
|
||||
|
||||
class TypeError : public UserError {
|
||||
public:
|
||||
explicit TypeError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: UserError(type, pos, data) {}
|
||||
};
|
||||
|
||||
class RuntimeError : public UserError {
|
||||
public:
|
||||
explicit RuntimeError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: UserError(type, pos, data) {}
|
||||
};
|
||||
|
||||
class InternalError : public exception {
|
||||
public:
|
||||
explicit InternalError(CodePosition pos = {})
|
||||
: pos(pos) {}
|
||||
|
||||
const char* what() const noexcept override {
|
||||
return "Internal error occurred.";
|
||||
}
|
||||
|
||||
const CodePosition pos;
|
||||
};
|
||||
|
||||
#endif
|
@ -5,6 +5,7 @@
|
||||
#include <stdexcept>
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "errors.h"
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <variant>
|
||||
#include <stdexcept>
|
||||
#include "tokenize.h"
|
||||
#include "errors.h"
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
|
@ -188,87 +188,4 @@ struct Scope {
|
||||
ScopeType type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Errors
|
||||
*/
|
||||
enum class ErrorType {
|
||||
// Generic
|
||||
NotImplemented,
|
||||
|
||||
// Lexing
|
||||
UnknownToken,
|
||||
IntegerTooLarge,
|
||||
|
||||
// Parsing
|
||||
EmptyInput,
|
||||
InvalidSyntax,
|
||||
ExceptedLParen,
|
||||
ExpectedRParen,
|
||||
ExpectedRCurlyBracket,
|
||||
ExpectedSemicolon,
|
||||
DependentDeclaration,
|
||||
|
||||
// Analysis
|
||||
UnknownType,
|
||||
TypeNotCastable,
|
||||
TypesNotComparable,
|
||||
ExpectedIntegralType,
|
||||
ExpectedArithmeticType,
|
||||
|
||||
// Runtime
|
||||
DivisionByZero,
|
||||
ModuloByZero,
|
||||
UnknownIdentifier,
|
||||
AlreadyDefinedIdentifier,
|
||||
UninitializedIdentifier,
|
||||
BreakNotWithinLoop,
|
||||
ContinueNotWithinLoop,
|
||||
};
|
||||
|
||||
using ErrorData = variant<monostate, string>;
|
||||
|
||||
class UserError : public exception {
|
||||
public:
|
||||
explicit UserError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: pos(pos), type(type), data(data) {}
|
||||
|
||||
const char* what() const noexcept override {
|
||||
return "User error occurred.";
|
||||
}
|
||||
|
||||
const CodePosition pos;
|
||||
const ErrorType type;
|
||||
const ErrorData data;
|
||||
};
|
||||
|
||||
class SyntaxError : public UserError {
|
||||
public:
|
||||
explicit SyntaxError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: UserError(type, pos, data) {}
|
||||
};
|
||||
|
||||
class TypeError : public UserError {
|
||||
public:
|
||||
explicit TypeError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: UserError(type, pos, data) {}
|
||||
};
|
||||
|
||||
class RuntimeError : public UserError {
|
||||
public:
|
||||
explicit RuntimeError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||
: UserError(type, pos, data) {}
|
||||
};
|
||||
|
||||
class InternalError : public exception {
|
||||
public:
|
||||
explicit InternalError(CodePosition pos = {})
|
||||
: pos(pos) {}
|
||||
|
||||
const char* what() const noexcept override {
|
||||
return "Internal error occurred.";
|
||||
}
|
||||
|
||||
const CodePosition pos;
|
||||
};
|
||||
|
||||
#endif
|
@ -2,6 +2,7 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "include/errors.h"
|
||||
#include "include/tokenize.h"
|
||||
using namespace std;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user