]> granicus.if.org Git - clang/commitdiff
PR4391: Tweak -ast-print output to generate valid output for edge cases
authorEli Friedman <eli.friedman@gmail.com>
Sun, 14 Jun 2009 22:39:26 +0000 (22:39 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 14 Jun 2009 22:39:26 +0000 (22:39 +0000)
like "int x = + +3;".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73356 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/StmtPrinter.cpp

index 710da6386133e4662ceed09a3cbd28225058bfb3..b300940824de8cfa6a91ab36dc4a9e95d5342e20 100644 (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());