-
Notifications
You must be signed in to change notification settings - Fork 0
/
term.hpp
104 lines (85 loc) · 2.58 KB
/
term.hpp
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
#ifndef TERM_HPP__
#define TERM_HPP__
class Substitution;
#define MAX_SUBS_DEPTH 10
enum TermType
{
TT_CONSTANT,
TT_VARIABLE,
TT_FUNCTION,
};
class Term;
typedef std::tr1::shared_ptr< Term > TermP;
class Term
{
public:
virtual ~Term();
/**
* Determine the TermType of this Term.
* \return The TermType associated with this Term.
*/
virtual TermType GetType() const = 0;
virtual TermP AfterSubstitution( const Substitution & p_sSub,
unsigned int p_iDepth ) const = 0;
/**
* Print this Term to a string.
* \return A string representation of this Term.
*/
virtual std::string ToStr() const = 0;
/**
* Print this Term to a string, ignoring typing information.
* \return A string representation of this Term, without typing.
*/
virtual std::string ToStrNoTyping() const = 0;
/**
* Determine whether or not this Term is equal to another.
* \param p_Other IN The Term to which this should be compared.
* \return True if they are equal, otherwise false.
*/
virtual bool Equal( const Term & p_Other ) const = 0;
/**
* Determine whether or not this Term has an associated type.
* This refers to the semantics of the Term, not which TermType it is.
* \return Whether or not the Term has an associated type.
*/
virtual bool HasTyping() const
{
return false;
}
/**
* Get the type associated with this Term.
* This refers to the semantics of the Term, not which TermType it is.
* If Term::HasTyping() returns false, this will throw E_NOT_IMPLEMENTED.
* \return The type associated with this Term.
*/
virtual std::string GetTyping() const
{
throw Exception( E_NOT_IMPLEMENTED,
"Attempt to read typing information from a non-typed term.",
__FILE__,
__LINE__ );
}
/**
* Get the index into the global StringTable for the type associated with
* this Term.
* This refers to the semantics of the Term, not which TermType it is.
* If Term::HasTyping() returns false, this will throw E_NOT_IMPLEMENTED.
* \return The index of the type associated with this Term.
*/
virtual unsigned int GetTypingStrTableIndex() const
{
throw Exception( E_NOT_IMPLEMENTED,
"Attempt to read typing information from a non-typed term.",
__FILE__,
__LINE__ );
}
virtual size_t GetMemSizeMin() const = 0;
virtual size_t GetMemSizeMax() const = 0;
protected:
TermP GetThis() const;
private:
std::tr1::weak_ptr< Term > m_pThis;
friend class TermTable;
};
bool operator==( const Term & p_First, const Term & p_Second );
#endif//TERM_HPP__