r206443 - When writing YAML in libclang, use yaml::escape instead of write_escaped

Ben Langmuir blangmuir at apple.com
Wed Apr 16 20:31:02 PDT 2014


Author: benlangmuir
Date: Wed Apr 16 22:31:02 2014
New Revision: 206443

URL: http://llvm.org/viewvc/llvm-project?rev=206443&view=rev
Log:
When writing YAML in libclang, use yaml::escape instead of write_escaped

The YAMLParser has its own escaped string representation, and does not
handle octal escape sequences. When writing the virtual file system to a
YAML file, use yaml::escape().

Modified:
    cfe/trunk/tools/libclang/BuildSystem.cpp
    cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/tools/libclang/BuildSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/BuildSystem.cpp?rev=206443&r1=206442&r2=206443&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/BuildSystem.cpp (original)
+++ cfe/trunk/tools/libclang/BuildSystem.cpp Wed Apr 16 22:31:02 2014
@@ -19,6 +19,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TimeValue.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/YAMLParser.h"
 
 using namespace clang;
 using namespace llvm::sys;
@@ -147,10 +148,9 @@ private:
       OS.indent(Indent) << "{\n";
       Indent += 2;
       OS.indent(Indent) << "'type': 'file',\n";
-      OS.indent(Indent) << "'name': \"";
-      OS.write_escaped(VName) << "\",\n";
-      OS.indent(Indent) << "'external-contents': \"";
-      OS.write_escaped(Entry.RPath) << "\"\n";
+      OS.indent(Indent) << "'name': \"" << llvm::yaml::escape(VName) << "\",\n";
+      OS.indent(Indent) << "'external-contents': \""
+                        << llvm::yaml::escape(Entry.RPath) << "\"\n";
       Indent -= 2;
       OS.indent(Indent) << '}';
       if (Entries.empty()) {

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=206443&r1=206442&r2=206443&view=diff
==============================================================================
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Wed Apr 16 22:31:02 2014
@@ -85,6 +85,27 @@ TEST(libclang, VirtualFileOverlay) {
     T.map("/path/virtual/foo.h", "/real/foo.h");
   }
   {
+    const char *contents =
+    "{\n"
+    "  'version': 0,\n"
+    "  'roots': [\n"
+    "    {\n"
+    "      'type': 'directory',\n"
+    "      'name': \"/path/virtual\",\n"
+    "      'contents': [\n"
+    "        {\n"
+    "          'type': 'file',\n"
+    "          'name': \"\\u2602.h\",\n"
+    "          'external-contents': \"/real/\\u2602.h\"\n"
+    "        }\n"
+    "      ]\n"
+    "    }\n"
+    "  ]\n"
+    "}\n";
+    TestVFO T(contents);
+    T.map("/path/virtual/☂.h", "/real/☂.h");
+  }
+  {
     TestVFO T(NULL);
     T.mapError("/path/./virtual/../foo.h", "/real/foo.h",
                CXError_InvalidArguments);





More information about the cfe-commits mailing list