Index: include/clang/AST/ParentMap.h
===================================================================
--- include/clang/AST/ParentMap.h	(revision 74519)
+++ include/clang/AST/ParentMap.h	(working copy)
@@ -24,6 +24,8 @@
   ParentMap(Stmt* ASTRoot);
   ~ParentMap();
 
+  void addStmt(Stmt* S);     // adds and/or updates the parent/child-relations of the stmt tree of S
+
   Stmt *getParent(Stmt*) const;
   Stmt *getParentIgnoreParens(Stmt *) const;
 
Index: include/clang/AST/PrettyPrinter.h
===================================================================
--- include/clang/AST/PrettyPrinter.h	(revision 74519)
+++ include/clang/AST/PrettyPrinter.h	(working copy)
@@ -27,16 +27,17 @@
 class PrinterHelper {
 public:
   virtual ~PrinterHelper();
-  virtual bool handledStmt(Stmt* E, llvm::raw_ostream& OS) = 0;
+  virtual bool handledStmt(Stmt* E, llvm::raw_ostream& OS, unsigned IndentLevel) = 0;
 };
 
 /// \brief Describes how types, statements, expressions, and
 /// declarations should be printed.
-struct PrintingPolicy {
+class PrintingPolicy {
+public:
   /// \brief Create a default printing policy for C.
   PrintingPolicy(const LangOptions &LO) 
     : Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
-      SuppressTag(false), SuppressTagKind(false), Dump(false) { }
+      SuppressTag(false), SuppressTagKind(false), Dump(false), IndentStyle(KRStyle) { }
 
   /// \brief The number of spaces to use to indent each line.
   unsigned Indentation : 8;
@@ -79,6 +80,10 @@
   /// and pretty-printing involves printing something similar to
   /// source code.
   bool Dump : 1;
+
+  /// \brief Indent style (see wikipedia:"Indent style" for details)
+  enum { KRStyle, /*same as Allman style:*/ ANSIStyle  };
+  unsigned IndentStyle : 1;
 };
 
 } // end namespace clang
Index: include/clang/AST/StmtVisitor.h
===================================================================
--- include/clang/AST/StmtVisitor.h	(revision 74519)
+++ include/clang/AST/StmtVisitor.h	(working copy)
@@ -29,6 +29,8 @@
 template<typename ImplClass, typename RetTy=void>
 class StmtVisitor {
 public:
+  typedef RetTy result_type;
+
   RetTy Visit(Stmt *S) {
     
     // If we have a binary expr, dispatch to the subcode of the binop.  A smart
Index: lib/AST/CFG.cpp
===================================================================
--- lib/AST/CFG.cpp	(revision 74519)
+++ lib/AST/CFG.cpp	(working copy)
@@ -1503,7 +1503,7 @@
   void setBlockID(signed i) { CurrentBlock = i; }
   void setStmtID(unsigned i) { CurrentStmt = i; }
   
-  virtual bool handledStmt(Stmt* Terminator, llvm::raw_ostream& OS) {
+  virtual bool handledStmt(Stmt* Terminator, llvm::raw_ostream& OS, unsigned /*IndentLevel*/) {
     
     StmtMapTy::iterator I = StmtMap.find(Terminator);
 
@@ -1619,7 +1619,7 @@
       
       if (Sub->child_begin() != Sub->child_end()) {
         OS << "({ ... ; ";
-        Helper->handledStmt(*SE->getSubStmt()->body_rbegin(),OS);
+        Helper->handledStmt(*SE->getSubStmt()->body_rbegin(),OS, 0);
         OS << " })\n";
         return;
       }
@@ -1629,7 +1629,7 @@
     if (BinaryOperator* B = dyn_cast<BinaryOperator>(Terminator)) {
       if (B->getOpcode() == BinaryOperator::Comma) {
         OS << "... , ";
-        Helper->handledStmt(B->getRHS(),OS);
+        Helper->handledStmt(B->getRHS(),OS, 0);
         OS << '\n';
         return;
       }          
Index: lib/AST/ParentMap.cpp
===================================================================
--- lib/AST/ParentMap.cpp	(revision 74519)
+++ lib/AST/ParentMap.cpp	(working copy)
@@ -40,6 +40,12 @@
   delete (MapTy*) Impl;
 }
 
+void ParentMap::addStmt(Stmt* S) {
+  if (S) {
+    BuildParentMap(*(MapTy*) Impl, S);
+  }
+}
+
 Stmt* ParentMap::getParent(Stmt* S) const {
   MapTy* M = (MapTy*) Impl;
   MapTy::iterator I = M->find(S);
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp	(revision 74519)
+++ lib/AST/StmtPrinter.cpp	(working copy)
@@ -64,7 +64,8 @@
     void PrintRawDeclStmt(DeclStmt *S);
     void PrintRawIfStmt(IfStmt *If);
     void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
-    
+    void PrintRawANSIStyleStmt(Stmt* Node, bool newLineAtStart = true);
+
     void PrintExpr(Expr *E) {
       if (E)
         Visit(E);
@@ -73,8 +74,8 @@
     }
     
     llvm::raw_ostream &Indent(int Delta = 0) {
-      for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
-        OS << "  ";
+      for (int i = 0, e = IndentLevel+Delta*Policy.Indentation; i < e; ++i)
+        OS << " ";
       return OS;
     }
     
@@ -82,7 +83,7 @@
     void VisitUnaryOffsetOf(UnaryOperator *Node);
     
     void Visit(Stmt* S) {    
-      if (Helper && Helper->handledStmt(S,OS))
+      if (Helper && Helper->handledStmt(S,OS, IndentLevel))
           return;
       else StmtVisitor<StmtPrinter>::Visit(S);
     }
@@ -102,6 +103,26 @@
   Indent() << "<<unknown stmt type>>\n";
 }
 
+void StmtPrinter::PrintRawANSIStyleStmt(Stmt* Node, bool newLineAtStart)
+{
+  assert(Policy.IndentStyle == PrintingPolicy::ANSIStyle);
+  if (newLineAtStart)
+    OS << "\n";
+
+  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node)) {
+    if (Helper == 0 || !Helper->handledStmt(CS, OS, IndentLevel)) {
+      Indent();
+      PrintRawCompoundStmt(CS);
+      OS << "\n";
+    }
+  } else {
+    Indent() << "{\n";
+    PrintStmt(Node);
+    Indent() << "}\n";
+  }
+}
+
+
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
@@ -164,35 +185,49 @@
   PrintStmt(Node->getSubStmt(), 0);
 }
 
+
 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
   OS << "if (";
   PrintExpr(If->getCond());
   OS << ')';
   
-  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
-    OS << ' ';
-    PrintRawCompoundStmt(CS);
-    OS << (If->getElse() ? ' ' : '\n');
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(If->getThen());
+    if (Stmt *Else = If->getElse()) {
+      Indent() << "else";
+      if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
+        OS << ' ';
+        PrintRawIfStmt(ElseIf);
+      } else {
+        PrintRawANSIStyleStmt(Else);
+      }
+    }
   } else {
-    OS << '\n';
-    PrintStmt(If->getThen());
-    if (If->getElse()) Indent();
-  }
-  
-  if (Stmt *Else = If->getElse()) {
-    OS << "else";
-    
-    if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
+    if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
       OS << ' ';
       PrintRawCompoundStmt(CS);
-      OS << '\n';
-    } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
-      OS << ' ';
-      PrintRawIfStmt(ElseIf);
+      OS << (If->getElse() ? ' ' : '\n');
     } else {
       OS << '\n';
-      PrintStmt(If->getElse());
+      PrintStmt(If->getThen());
+      if (If->getElse()) Indent();
     }
+    
+    if (Stmt *Else = If->getElse()) {
+      OS << "else";
+      
+      if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
+        OS << ' ';
+        PrintRawCompoundStmt(CS);
+        OS << '\n';
+      } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
+        OS << ' ';
+        PrintRawIfStmt(ElseIf);
+      } else {
+        OS << '\n';
+        PrintStmt(If->getElse());
+      }
+    }
   }
 }
 
@@ -205,9 +240,11 @@
   Indent() << "switch (";
   PrintExpr(Node->getCond());
   OS << ")";
-  
-  // Pretty print compoundstmt bodies (very common).
-  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(Node->getBody());
+  } else if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+    // Pretty print compoundstmt bodies (very common).
     OS << " ";
     PrintRawCompoundStmt(CS);
     OS << "\n";
@@ -225,12 +262,18 @@
   Indent() << "while (";
   PrintExpr(Node->getCond());
   OS << ")\n";
-  PrintStmt(Node->getBody());
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(Node->getBody(), false);
+  } else {
+    PrintStmt(Node->getBody());
+  }
 }
 
 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
   Indent() << "do ";
-  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(Node->getBody());
+  } else if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
     PrintRawCompoundStmt(CS);
     OS << " ";
   } else {
@@ -264,7 +307,9 @@
   }
   OS << ") ";
   
-  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(Node->getBody());
+  } else if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
     PrintRawCompoundStmt(CS);
     OS << "\n";
   } else {
@@ -282,7 +327,7 @@
   OS << " in ";
   PrintExpr(Node->getCollection());
   OS << ") ";
-  
+
   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
     PrintRawCompoundStmt(CS);
     OS << "\n";
@@ -447,7 +492,11 @@
   else
     OS << "...";
   OS << ") ";
-  PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(Node->getHandlerBlock());
+  } else {
+    PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
+  }
 }
 
 void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
@@ -458,7 +507,11 @@
 
 void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
   Indent() << "try ";
-  PrintRawCompoundStmt(Node->getTryBlock());
+  if (Policy.IndentStyle == PrintingPolicy::ANSIStyle) {
+    PrintRawANSIStyleStmt(Node->getTryBlock());
+  } else {
+    PrintRawCompoundStmt(Node->getTryBlock());
+  }
   for(unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
     OS << " ";
     PrintRawCXXCatchStmt(Node->getHandler(i));
