-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsli_token.cpp
110 lines (89 loc) · 2.29 KB
/
sli_token.cpp
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
#include "sli_token.h"
#include "sli_type.h"
#include "sli_exceptions.h"
#include "sli_string.h"
namespace sli3
{
Token::operator TokenArray&()
{
if( not is_valid())
throw InvalidToken();
unsigned int id=type_->get_typeid();
if(id==sli3::arraytype or
id==sli3::proceduretype or
id==sli3::litproceduretype)
{
return *data_.array_val;
}
throw TypeMismatch();
}
Token::operator std::string&()
{
require_type(sli3::stringtype);
return *data_.string_val;
}
std::ostream & Token::print(std::ostream &out) const
{
if(type_ != 0)
return type_->print(out,*this);
else
return out << "/nulltoken";
}
std::ostream & Token::pprint(std::ostream &out) const
{
if(type_ != 0)
return type_->pprint(out,*this);
else
return out << "/nulltoken";
}
bool Token::operator==(const Token &t) const
{
if(type_ != t.type_)
return false;
if(!type_)
return true;
return type_->compare(*this,t);
}
bool Token::operator==(int i) const
{
return type_ and type_->get_typeid()==sli3::integertype and data_.long_val==i;
}
bool Token::operator==(unsigned int i) const
{
return type_ and type_->get_typeid()==sli3::integertype and static_cast<unsigned int>(data_.long_val)==i;
}
bool Token::operator==(long l) const
{
return type_ and type_->get_typeid()==sli3::integertype and data_.long_val==l;
}
bool Token::operator==(unsigned long l) const
{
return type_ and type_->get_typeid()==sli3::integertype and static_cast<unsigned long>(data_.long_val)==l;
}
bool Token::operator==(double d) const
{
return type_ and type_->get_typeid()==sli3::integertype and data_.double_val==d;
}
bool Token::operator==(bool b) const
{
return type_ and type_->get_typeid()==sli3::integertype and data_.bool_val==b;
}
bool Token::operator==(Name n) const
{
return type_ and type_->get_typeid()==sli3::nametype and data_.name_val==n.toIndex();
}
bool Token::operator!=(const Token &t) const
{
return not operator==(t);
}
Name Token::get_typename() const
{
if(type_ == 0)
throw InvalidToken();
return type_->get_typename();
}
std::ostream & operator<<(std::ostream &out, const Token &t)
{
return t.print(out);
}
}