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
|
#ifndef PCC_TYPEMANAGER_H
#define PCC_TYPEMANAGER_H
#include <map>
#include <memory>
#include <utility>
#include <vector>
#include "Type.hh"
namespace pcc {
enum class BuiltinType { BOOLEAN, CHAR, INTEGER, REAL, STRING, BUILTIN_NUMBER };
class TypeManager {
public:
TypeManager();
std::shared_ptr<Type> GetBuiltinType(BuiltinType type);
// binary operators may change type
std::pair<std::shared_ptr<Type>, Value>
CreateOperation(BinaryOperator op, std::shared_ptr<Type> LeftType,
std::shared_ptr<Type> RightType, Value left,
Value right, Context* context);
// unary operators never change type
Value CreateOperation(UnaryOperator op, std::shared_ptr<Type> type, Value v,
Context* context);
Value CreateCast(std::shared_ptr<Type> DstType,
std::shared_ptr<Type> SrcType, Value v, Context* context);
std::shared_ptr<FunctionType>
CreateFunctionType(std::shared_ptr<Type> ReturnType,
std::vector<std::shared_ptr<Type>> ArgTypes);
private:
std::vector<std::shared_ptr<Type>> builtins_;
std::vector<std::shared_ptr<Type>> types_;
// if we are porting to some 64-bit machines, we can change these types to
// 64-bit type, in order to make pointers behave correctly
std::shared_ptr<Type> PointerDifferenceType_;
std::shared_ptr<Type> PointerIndexType_;
};
} // namespace pcc
#endif // !PCC_TYPEMANAGER_H
|