-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.h
75 lines (54 loc) · 2.04 KB
/
environment.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
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
#include <map>
#include <deque>
#include <list>
#include <algorithm>
#include <vector>
#include "vartype.h"
class Identifier;
class Value;
class TypeDefAST;
class Environment
{
public:
Environment():polymorphic_types_in_statement(0), execution_inside_pattern(false){ displayed_values = 0; }
void addActivationFrame();
void removeActivationFrame();
void addIdentifierToBeTypeDeduced(Identifier identifier, bool rec = false, Type startingType = Type());
void setIdentifierType(Identifier identifier, Type newType);
void resetIdentifierType(Identifier identifier, Type newType);
Type getIdentifierType(Identifier identifier);
Type getNewPolymorphicType();
void reset_polymorphic_types();
int polymorphic_types_in_statement;
void addValue(Identifier identifier, Value* value);
Value* getValue(Identifier identifier);
bool valueExists(Identifier identifier);
int displayed_values;
void printNewValues();
std::list< std::pair<Identifier, Type> > identifier_types;
// pointers used so values stored could be polymorphic
std::list< Identifier > identifiers_stack;
std::map< Identifier, std::list<Value*> > variables;
std::map< Identifier, Type > type_constructors;
void addTypes(std::vector<TypeDefAST*> type_defs);
void addType(TypeDefAST* type_def);
Type getType(Identifier identifier);
void cleanupAfterStatement();
/** type relations part **/
Type followRelations(Type type, int depth = 0);
void addFunctionCallRelations(Type function_type, Type argument_applied, Type result_expected);
void addRelation(Type from, Type to);
void checkForCircularReferences();
void clearRelations();
Type renumeratedToSmallest(Type type);
Type renumeratedToUnique(Type type);
std::string relationsToString();
bool execution_inside_pattern;
private:
Type doRenumerations(Type type, std::map<Type, Type>& renumerations);
std::map<Type, Type> type_relations;
};
#include "ast.h"
#endif // ENVIRONMENT_H