-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.h
57 lines (45 loc) · 1.13 KB
/
type.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
55
56
57
#ifndef __type_h__
#define __type_h__
#include <string>
#include "word.h"
class Type : public Word
{
protected:
/* data */
int _width;
public:
Type(std::string,Tag tag,int width);
~Type();
virtual bool isArray()
{
return false;
}
int width();
static Type * Int(){
static Type *i = new Type("int",BASIC,4);
return i;
}
static Type * Float(){
static Type * i = new Type("float",BASIC,8);
return i;
}
static Type * Bool(){
static Type * i = new Type("bool",BASIC,1);
return i;
}
static Type * Char(){
static Type *i = new Type("char",BASIC,1);
return i;
}
static bool numeric(Type *p){
if(p == Type::Float() || p == Type::Int() || p == Type::Char()) return true;
return false;
}
static Type* max(Type *p1 , Type *p2){
if(!numeric(p1) || !numeric(p2)) return NULL;
else if(p1 == Type::Float() || p2 == Type::Float()) return Type::Float();
else if(p1 == Type::Int() || p2 == Type::Int()) return Type::Int();
else return Type::Char();
}
};
#endif