-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathType.h
140 lines (119 loc) · 3.19 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Copyright 2010 by Benjamin J. Land (a.k.a. BenLand100)
*
* This file is part of CPascal.
*
* CPascal 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.
*
* CPascal 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 CPascal. If not, see <http://www.gnu.org/licenses/>.
*/
class Type;
class Array;
class Pointer;
class Record;
class Meth;
#ifndef _TYPE_H
#define _TYPE_H
#define TYPE_NIL -1
#define TYPE_STRING 0
#define TYPE_INTEGER 1
#define TYPE_REAL 2
#define TYPE_BOOLEAN 3
#define TYPE_CHAR 4
#define TYPE_REF 5
#define TYPE_RECORD 6
#define TYPE_ARRAY 7
#define TYPE_POINTER 8
#define TYPE_METH 9
#include <string>
#include <map>
#include <vector>
#include <list>
#include "Variable.h"
class Method;
class Type {
public:
static std::map<std::string,Type*>* alltypes();
static Type* getNil();
static Type* getString();
static Type* getInteger();
static Type* getReal();
static Type* getBoolean();
static Type* getChar();
static Record* getRecordType(std::list<Variable*> fields);
static Array* getBoundArrayType(Type* element, int from, int to);
static Array* getDynamicArrayType(Type* element);
static Pointer* getPointerType(Type* type);
static Meth* getMethodType(Method* meth);
static Type* getType(int name);
const int type;
const std::string descr;
virtual bool instanceOf(Type* type);
virtual int sizeOf();
protected:
Type(std::string descr, int type);
private:
Type(int name); //only for reserved types
};
class Meth : public Type {
friend class Type;
public:
const Method* meth;
bool instanceOf(Type* type);
int sizeOf();
protected:
Meth(std::string descr, Method* meth);
};
class RefType : public Type {
friend class Type;
public:
const int name;
bool instanceOf(Type* type);
int sizeOf();
protected:
RefType(std::string descr, int name);
};
class Array : public Type {
friend class Type;
public:
const bool dynamic;
Type* element;
const int from;
const int to;
bool instanceOf(Type* type);
int sizeOf();
protected:
Array(std::string descr, Type* element, int from, int to);
Array(std::string descr, Type* element);
};
class Pointer : public Type {
friend class Type;
public:
Type* pointsTo;
bool instanceOf(Type* type);
int sizeOf(std::map<int,Type*> &typemap);
protected:
Pointer(std::string descr, Type* pointsTo);
};
class Record : public Type {
friend class Type;
public:
std::vector<Type*> slots;
bool instanceOf(Type* type);
int sizeOf();
int getNameSlot(int name);
protected:
std::map<int,int> namemap;
int size;
Record(std::string descr, std::list<Variable*>& fields);
};
#endif /* _TYPE_H */