PR4391: Tweak -ast-print output to generate valid output for edge cases

like "int x = + +3;".

llvm-svn: 73356
This commit is contained in:
Eli Friedman 2009-06-14 22:39:26 +00:00
parent 9b4c85ff62
commit 1cf2536d6c
1 changed files with 7 additions and 1 deletions

View File

@ -643,7 +643,8 @@ void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
if (!Node->isPostfix()) {
OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
// Print a space if this is an "identifier operator" like __real.
// Print a space if this is an "identifier operator" like __real, or if
// it might be concatenated incorrectly like '+'.
switch (Node->getOpcode()) {
default: break;
case UnaryOperator::Real:
@ -651,6 +652,11 @@ void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
case UnaryOperator::Extension:
OS << ' ';
break;
case UnaryOperator::Plus:
case UnaryOperator::Minus:
if (isa<UnaryOperator>(Node->getSubExpr()))
OS << ' ';
break;
}
}
PrintExpr(Node->getSubExpr());