"this patch properly addresses escaping < and > which might appear
(e.g. for C++ operators) in the xml dump.

I also re-enabled the unit test for ast-print-xml (or so I think)
at least, make test didn't fail..."

patch by Sebastien Binet!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103671 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Frontend/DocumentXML.h b/include/clang/Frontend/DocumentXML.h
index 5227c12..73d8921 100644
--- a/include/clang/Frontend/DocumentXML.h
+++ b/include/clang/Frontend/DocumentXML.h
@@ -146,12 +146,23 @@
 //---------------------------------------------------------
 template<class T>
 inline void DocumentXML::addAttribute(const char* pName, const T& value) {
-  Out << ' ' << pName << "=\"" << value << "\"";
+  std::string repr;
+  {
+    llvm::raw_string_ostream buf(repr);
+    buf << value;
+    buf.flush();
+  }
+  
+  Out << ' ' << pName << "=\"" 
+      << DocumentXML::escapeString(repr.c_str(), repr.size())
+      << "\"";
 }
 
 //---------------------------------------------------------
 inline void DocumentXML::addPtrAttribute(const char* pName, const char* text) {
-  Out << ' ' << pName << "=\"" << text << "\"";
+  Out << ' ' << pName << "=\"" 
+      << DocumentXML::escapeString(text, strlen(text))
+      << "\"";
 }
 
 //---------------------------------------------------------
diff --git a/lib/Frontend/DeclXML.cpp b/lib/Frontend/DeclXML.cpp
index 3ae25f9..97a7f55 100644
--- a/lib/Frontend/DeclXML.cpp
+++ b/lib/Frontend/DeclXML.cpp
@@ -49,7 +49,8 @@
     addSubNodes(cast<RecordDecl>(RD));
 
     if (RD->isDefinition()) {
-      Doc.addAttribute("num_bases", RD->getNumBases());
+      // FIXME: This breaks XML generation
+      //Doc.addAttribute("num_bases", RD->getNumBases());
 
       for (CXXRecordDecl::base_class_iterator 
              base = RD->bases_begin(),
diff --git a/test/Coverage/ast-printing.cpp b/test/Coverage/ast-printing.cpp
index 1a75fb4..0de5642 100644
--- a/test/Coverage/ast-printing.cpp
+++ b/test/Coverage/ast-printing.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only %s
 // RUN: %clang_cc1 -ast-print %s
 // RUN: %clang_cc1 -ast-dump %s
-// FIXME: %clang_cc1 -ast-print-xml -o %t %s
+// RUN: %clang_cc1 -ast-print-xml -o %t %s
 // RUN: %clang_cc1 -print-decl-contexts %s
 // RUN: %clang_cc1 -fdump-record-layouts %s