diff --git a/tests/manual/cplusplus-dump/main.cpp b/tests/manual/cplusplus-dump/main.cpp index f8f246aa0da66a1bac7fd2da0b7584311b2610d0..a15049965c5e07b2b4acf894b8c3814f35612cc2 100644 --- a/tests/manual/cplusplus-dump/main.cpp +++ b/tests/manual/cplusplus-dump/main.cpp @@ -76,6 +76,8 @@ public: out << "digraph AST { ordering=out;" << std::endl; // std::cout << "rankdir = \"LR\";" << std::endl; + + generateTokens(); accept(ast); typedef QPair<QByteArray, QByteArray> Pair; @@ -113,17 +115,35 @@ protected: return name; } + QByteArray terminalId(unsigned token) + { return 't' + QByteArray::number(token); } + void terminal(unsigned token, AST *node) { - static int count = 1; - QByteArray id = 't' + QByteArray::number(count++); - _connections.append(qMakePair(_id[node], id)); - - QByteArray t; - t.append(id); - t.append(" [label = \""); - t.append(spell(token)); - t.append("\" shape=rect]"); - _terminalShapes.append(t); + _connections.append(qMakePair(_id[node], terminalId(token))); + } + + void generateTokens() { + for (unsigned token = 1; token < translationUnit()->tokenCount(); ++token) { + if (translationUnit()->tokenKind(token) == T_EOF_SYMBOL) + break; + + QByteArray t; + + t.append(terminalId(token)); + t.append(" [shape=rect label = \""); + t.append(spell(token)); + t.append("\"]"); + + if (token > 1) { + t.append("; "); + t.append(terminalId(token - 1)); + t.append(" -> "); + t.append(terminalId(token)); + t.append(" [arrowhead=\"vee\" color=\"transparent\"]"); + } + + _terminalShapes.append(t); + } } virtual void nonterminal(AST *ast) {