-
Notifications
You must be signed in to change notification settings - Fork 1
/
LblTree.cpp
100 lines (87 loc) · 3.2 KB
/
LblTree.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
#include "LblTree.h"
using namespace llvm;
namespace clang {
namespace diff {
namespace {
const char *TAB_STRING_ = " ";
const char *ROOT_STRING_ = "*---+";
const char *BRANCH_STRING_ = "+---+";
const char *OPEN_BRACKET_ = "{";
const char *CLOSE_BRACKET_ = "}";
const char *ID_SEPARATOR_ = ":";
}
LblTree::LblTree(std::string* label, int treeID)
: TreeID(treeID), NodeID(NO_NODE), Label(label), TmpData(nullptr) { }
LblTree::LblTree()
: LblTree(nullptr, NO_TREE_ID) { }
void LblTree::prettyPrint() {
prettyPrint(false);
}
void LblTree::prettyPrint(bool printTmpData) {
for (auto i = 0; i < getLevel(); i++) {
::java::lang::System::out()->print(TAB_STRING_);
}
if(!isRoot()) {
::java::lang::System::out()->print(BRANCH_STRING_);
} else {
if(getTreeID() != NO_TREE_ID) {
::java::lang::System::out()->println(::java::lang::StringBuilder().append(u"treeID: "_j)->append(getTreeID())->toString());
}
::java::lang::System::out()->print(ROOT_STRING_);
}
::java::lang::System::out()->print(::java::lang::StringBuilder().append(u" '"_j)->append(this->getLabel())
->append(u"' "_j)->toString());
if(printTmpData) {
::java::lang::System::out()->println(getTmpData());
} else {
::java::lang::System::out()->println();
}
for (auto *e = children(); e->hasMoreElements(); ) {
(java_cast< LblTree* >(java_cast< ::java::lang::Object* >(e->nextElement())))->prettyPrint(printTmpData);
}
}
int LblTree::getNodeCount()
{
auto sum = 1;
for (auto *e = children(); e->hasMoreElements(); ) {
sum += (java_cast< LblTree* >(java_cast< ::java::lang::Object* >(e->nextElement())))->getNodeCount();
}
return sum;
}
LblTree* LblTree::fromString(::java::lang::String* s)
{
clinit();
auto treeID = FormatUtilities::getTreeID(s);
s = s->substring(s->indexOf(OPEN_BRACKET_), s->lastIndexOf(CLOSE_BRACKET_) + 1);
auto node = new LblTree(FormatUtilities::getRoot(s), treeID);
auto c = FormatUtilities::getChildren(s);
for (auto i = 0; i < c->size(); i++) {
node->add(fromString(java_cast< ::java::lang::String* >(java_cast< ::java::lang::Object* >(c->elementAt(i)))));
}
return node;
}
std::string LblTree::toString()
{
auto res = ::java::lang::StringBuilder().append(OPEN_BRACKET_)->append(getLabel())->toString();
if((getTreeID() >= 0) && (isRoot())) {
res = ::java::lang::StringBuilder().append(getTreeID())->append(ID_SEPARATOR_)
->append(res)->toString();
}
for (auto *e = children(); e->hasMoreElements(); ) {
res = ::java::lang::StringBuilder(res).append((java_cast< LblTree* >(java_cast< ::java::lang::Object* >(e->nextElement())))->toString())->toString();
}
res = ::java::lang::StringBuilder(res).append(CLOSE_BRACKET_)->toString();
return res;
}
int LblTree::compareTo(::java::lang::Object* o)
{
return getLabel()->compareTo((java_cast< LblTree* >(o))->getLabel());
}
void LblTree::clearTmpData()
{
for (auto *e = breadthFirstEnumeration(); e->hasMoreElements(); ) {
(java_cast< LblTree* >(java_cast< ::java::lang::Object* >(e->nextElement())))->setTmpData(nullptr);
}
}
} // namespace query
} // namespace clang