From: Eli Friedman Date: Sun, 14 Jun 2009 22:39:26 +0000 (+0000) Subject: PR4391: Tweak -ast-print output to generate valid output for edge cases X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7df71ac778e5918883c826fdb3fff7d0feffc677;p=clang PR4391: Tweak -ast-print output to generate valid output for edge cases like "int x = + +3;". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73356 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 710da63861..b300940824 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -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(Node->getSubExpr())) + OS << ' '; + break; } } PrintExpr(Node->getSubExpr());