-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception.h
54 lines (50 loc) · 1.14 KB
/
exception.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _EXCEPTION_H_
#define _EXCEPTION_H_
#include "util.h"
#include <string>
#include <iostream>
#include <sstream>
class Exception {
public:
Exception(std::string error, std::string code)
{
this->error = replace(error, "\n", "\n\t");
this->code = code;
this->line = -1;
}
void setLine(int line)
{
this->line = line;
}
void printError()
{
std::stringstream strstream;
strstream << "line " << line << ":";
std::string lstr = strstream.str();
lstr = dump(strstream);
strstream.clear();
strstream << code << "\n";
std::string cstr = dump(strstream);
strstream.clear();
std::cerr << ((line != -1)?lstr:"") << ((code != "")?cstr:"") << "error:"
<< error << std::endl;
}
std::string getError()const
{
return error;
}
Exception(){}
~Exception(){}
static std::string ion;//illegal operation name
static std::string irn;//illegal register name
static std::string is;//illegal shamt
static std::string ii;//illegal immediate
static std::string it;//illegal target
static std::string ge;//grammar error
static std::string iud;//invalid use of dump
private:
std::string error;
std::string code;
int line;
};
#endif