AST: improved AST printout when --verbose is used

This commit is contained in:
Daniel Marjamäki 2014-02-24 17:22:29 +01:00
parent 8dd7f02e45
commit acf5723bdd
3 changed files with 36 additions and 4 deletions

View File

@ -1201,7 +1201,7 @@ std::string Token::expressionString() const
}
void Token::printAst() const
void Token::printAst(bool verbose) const
{
bool title = false;
@ -1211,6 +1211,9 @@ void Token::printAst() const
if (!title)
std::cout << "\n\n##AST" << std::endl;
title = true;
if (verbose)
std::cout << tok->astTop()->astStringVerbose(0,0) << std::endl;
else
std::cout << tok->astTop()->astString(" ") << std::endl;
print = false;
if (tok->str() == "(")
@ -1221,6 +1224,33 @@ void Token::printAst() const
}
}
static std::string indent(const unsigned int indent1, const unsigned int indent2)
{
std::string ret(indent1,' ');
for (unsigned int i = indent1; i < indent2; i += 2)
ret += "| ";
return ret;
}
std::string Token::astStringVerbose(const unsigned int indent1, const unsigned int indent2) const
{
std::string ret = _str + "\n";
if (_astOperand1) {
unsigned int i1 = indent1, i2 = indent2 + 2;
if (indent1==indent2 && !_astOperand2)
i1 += 2;
ret += indent(indent1,indent2) + (_astOperand2 ? "|-" : "`-") + _astOperand1->astStringVerbose(i1,i2);
}
if (_astOperand2) {
unsigned int i1 = indent1, i2 = indent2 + 2;
if (indent1==indent2)
i1 += 2;
ret += indent(indent1,indent2) + "`-" + _astOperand2->astStringVerbose(i1,i2);
}
return ret;
}
void Token::printValueFlow() const
{
int line = -1;

View File

@ -721,9 +721,11 @@ public:
return ret + sep + _str;
}
std::string astStringVerbose(const unsigned int indent1, const unsigned int indent2) const;
std::string expressionString() const;
void printAst() const;
void printAst(bool verbose) const;
void printValueFlow() const;
};

View File

@ -3652,7 +3652,7 @@ bool Tokenizer::simplifyTokenList2()
if (_settings->_verbose)
_symbolDatabase->printOut("Symbol database");
list.front()->printAst();
list.front()->printAst(_settings->_verbose);
list.front()->printValueFlow();
}