forked from CoatiSoftware/Sourcetrail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.cpp
More file actions
191 lines (165 loc) · 3.67 KB
/
Copy pathEdge.cpp
File metadata and controls
191 lines (165 loc) · 3.67 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "Edge.h"
#include <sstream>
#include "Node.h"
#include "TokenComponentAggregation.h"
#include "logging.h"
#include "utilityString.h"
int Edge::typeToInt(EdgeType type)
{
return type;
}
Edge::EdgeType Edge::intToType(int value)
{
switch (value)
{
case EDGE_MEMBER:
return EDGE_MEMBER;
case EDGE_TYPE_USAGE:
return EDGE_TYPE_USAGE;
case EDGE_USAGE:
return EDGE_USAGE;
case EDGE_CALL:
return EDGE_CALL;
case EDGE_INHERITANCE:
return EDGE_INHERITANCE;
case EDGE_OVERRIDE:
return EDGE_OVERRIDE;
case EDGE_TYPE_ARGUMENT:
return EDGE_TYPE_ARGUMENT;
case EDGE_TEMPLATE_SPECIALIZATION:
return EDGE_TEMPLATE_SPECIALIZATION;
case EDGE_INCLUDE:
return EDGE_INCLUDE;
case EDGE_IMPORT:
return EDGE_IMPORT;
case EDGE_AGGREGATION:
return EDGE_AGGREGATION;
case EDGE_MACRO_USAGE:
return EDGE_MACRO_USAGE;
case EDGE_ANNOTATION_USAGE:
return EDGE_ANNOTATION_USAGE;
}
return EDGE_UNDEFINED;
}
Edge::Edge(Id id, EdgeType type, Node* from, Node* to)
: Token(id), m_type(type), m_from(from), m_to(to)
{
m_from->addEdge(this);
m_to->addEdge(this);
}
Edge::Edge(const Edge& other, Node* from, Node* to)
: Token(other), m_type(other.m_type), m_from(from), m_to(to)
{
m_from->addEdge(this);
m_to->addEdge(this);
if (m_from == other.m_from || m_to == other.m_to || m_from->getId() != other.m_from->getId() ||
m_to->getId() != other.m_to->getId())
{
LOG_ERROR("Nodes are not plain copies.");
}
}
Edge::~Edge()
{
m_from->removeEdge(this);
m_to->removeEdge(this);
}
Edge::EdgeType Edge::getType() const
{
return m_type;
}
bool Edge::isType(TypeMask mask) const
{
return (m_type & mask) > 0;
}
Node* Edge::getFrom() const
{
return m_from;
}
Node* Edge::getTo() const
{
return m_to;
}
std::wstring Edge::getName() const
{
return getReadableTypeString() + L":" + getFrom()->getFullName() + L"->" + getTo()->getFullName();
}
bool Edge::isNode() const
{
return false;
}
bool Edge::isEdge() const
{
return true;
}
std::wstring Edge::getUnderscoredTypeString(EdgeType type)
{
return utility::replace(utility::replace(getReadableTypeString(type), L"-", L"_"), L" ", L"_");
}
std::wstring Edge::getReadableTypeString(EdgeType type)
{
switch (type)
{
case EDGE_UNDEFINED:
return L"undefined";
case EDGE_MEMBER:
return L"child";
case EDGE_TYPE_USAGE:
return L"type use";
case EDGE_USAGE:
return L"use";
case EDGE_CALL:
return L"call";
case EDGE_INHERITANCE:
return L"inheritance";
case EDGE_OVERRIDE:
return L"override";
case EDGE_TYPE_ARGUMENT:
return L"type argument";
case EDGE_TEMPLATE_SPECIALIZATION:
return L"template specialization";
case EDGE_INCLUDE:
return L"include";
case EDGE_IMPORT:
return L"import";
case EDGE_AGGREGATION:
return L"aggregation";
case EDGE_MACRO_USAGE:
return L"macro use";
case EDGE_ANNOTATION_USAGE:
return L"annotation use";
}
return L"";
}
Edge::EdgeType Edge::getTypeForReadableTypeString(const std::wstring& str)
{
for (TypeMask mask = 1; mask <= EDGE_MAX_VALUE; mask *= 2)
{
EdgeType type = intToType(mask);
if (getReadableTypeString(type) == str)
{
return type;
}
}
return EDGE_UNDEFINED;
}
std::wstring Edge::getReadableTypeString() const
{
return getReadableTypeString(m_type);
}
std::wstring Edge::getAsString() const
{
std::wstringstream str;
str << L"[" << getId() << L"] " << getReadableTypeString();
str << L": \"" << m_from->getName() << L"\" -> \"" + m_to->getName() << L"\"";
TokenComponentAggregation* aggregation = getComponent<TokenComponentAggregation>();
if (aggregation)
{
str << L" " << aggregation->getAggregationCount();
}
return str.str();
}
std::wostream& operator<<(std::wostream& ostream, const Edge& edge)
{
ostream << edge.getAsString();
return ostream;
}