Skip to content

Commit

Permalink
Fix SynTree.dump2 that is supposed to show a pruned tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mingodad committed Jun 12, 2021
1 parent 5a04a9c commit 2f2beee
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 59 deletions.
8 changes: 5 additions & 3 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,26 +1333,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Parser.frame
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct SynTree {
TArrayList<SynTree*> children;

void dump(int indent=0, bool isLast=false);
void dump2(int maxT, int indent=0, bool isLast=false);
void dump2(int indent=0, bool isLast=false);
};

#endif
Expand Down Expand Up @@ -406,26 +406,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct SynTree {
TArrayList<SynTree*> children;

void dump(int indent=0, bool isLast=false);
void dump2(int maxT, int indent=0, bool isLast=false);
void dump2(int indent=0, bool isLast=false);
};

#endif
Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestAlts_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestAny1_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestAny_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,26 +439,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestCasing_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,26 +377,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestChars_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestComments_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestDel_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,26 +438,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestEps_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,26 +366,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/TestSuite/TestIters_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,26 +389,28 @@ void SynTree::dump(int indent, bool isLast) {
}
}

void SynTree::dump2(int maxT, int indent, bool isLast) {
void SynTree::dump2(int indent, bool isLast) {
int last_idx = children.Count;
int indentPlus = 4;
if(tok->col) {
printIndent(indent);
wprintf(_SC("%s\t%d\t%d\t%d\t%") _SFMT _SC("\n"), ((isLast || (last_idx == 0)) ? "= " : " "), tok->line, tok->col, tok->kind, tok->val);
}
else {
if(last_idx == 1) {
if(((SynTree*)children[0])->tok->kind < maxT) {
if(((SynTree*)children[0])->children.Count == 0) {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
else indentPlus = 0;
}
else {
printIndent(indent);
wprintf(_SC("%d\t%d\t%d\t%") _SFMT _SC("\n"), children.Count, tok->line, tok->kind, tok->val);
}
}
if(last_idx) {
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(maxT, indent+4, idx == last_idx);
for(int idx=0; idx < last_idx; ++idx) ((SynTree*)children[idx])->dump2(indent+indentPlus, idx == last_idx);
}
}

Expand Down
Loading

0 comments on commit 2f2beee

Please sign in to comment.