-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathType.h
More file actions
46 lines (37 loc) · 972 Bytes
/
Type.h
File metadata and controls
46 lines (37 loc) · 972 Bytes
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
/**
* @file Type.h
* @brief Declaration of the Type class and type constants.
*/
#ifndef TYPE_H_
#define TYPE_H_
#include <iostream> /// TEMP
#include <string>
using namespace std;
/**
* The type of an expression: integer, real, or ill-typed.
*
* Types can be compared using == and !=.
*/
class Type {
public:
const static Type INTEGER; /// Integer type
const static Type REAL; /// Real (floating-point) type
const static Type ERROR; /// Denotes an ill-typed expression
bool IsError() const {
return *this == Type::ERROR;
}
friend ostream &operator<<(ostream &out, const Type &type) {
return out << type.name;
}
bool operator==(const Type &that) const {
return this->name == that.name; // Nominal comparison for simplicity
}
bool operator!=(const Type &that) const {
return !(*this == that);
}
private:
explicit Type(const char *n) : name(n) { }
virtual ~Type() { }
const char *name;
};
#endif // TYPE_H_