-
Notifications
You must be signed in to change notification settings - Fork 1
/
TypeDeclaration.cpp
67 lines (56 loc) · 1.01 KB
/
TypeDeclaration.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
#include "TypeDeclaration.h"
bool TypeDeclaration::operator==(const TypeDeclaration &other) const
{
if (isConst() != other.isConst())
{
return false;
}
if (typeName() != other.typeName())
{
return false;
}
if (indirections().size() != other.indirections().size())
{
return false;
}
auto otherIt = other.indirections().begin();
for(Indirection i : indirections())
{
if (i != *(otherIt++))
{
return false;
}
}
return true;
}
std::string TypeDeclaration::spelling() const
{
if (!isValid())
{
return "(invalid)";
}
// Start with the type name
std::string ret(typeName());
// If we're const prepend "const"
// We could append here but it looks weird with pointers
if (isConst())
{
ret = "const " + ret;
}
for(Indirection indirection : indirections())
{
switch(indirection)
{
case Indirection::Pointer:
ret += " *";
break;
case Indirection::ConstPointer:
ret += " const*";
break;
case Indirection::Reference:
ret += " &";
break;
}
}
return ret;
}