浏览代码

[Support] Teach YAMLIO about polymorphic types

Add support for "polymorphic" types to YAMLIO.

PolymorphicTraits can dynamically switch between other traits (Scalar, Map, or
Sequence). When inputting, the PolymorphicTraits type is told which type to
become, and when outputting the PolymorphicTraits type is asked which type it
currently is.

Also add support for TaggedScalarTraits to allow dynamically differentiating
between multiple scalar types using YAML tags.

Serialize empty maps as "{}" and empty sequences as "[]", so that types
are preserved when round-tripping PolymorphicTraits. This change has
equivalent semantics, but may break e.g. tests which compare output
verbatim.

Differential Revision: https://reviews.llvm.org/D48144

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346884 91177308-0d34-0410-b5e6-96231b3b80d8
Scott Linder 6 年之前
父节点
当前提交
52daf3b92d
共有 2 个文件被更改,包括 4 次插入4 次删除
  1. 2 2
      unittests/Tooling/DiagnosticsYamlTest.cpp
  2. 2 2
      unittests/Tooling/RefactoringActionRulesTest.cpp

+ 2 - 2
unittests/Tooling/DiagnosticsYamlTest.cpp

@@ -82,7 +82,7 @@ TEST(DiagnosticsYamlTest, serializesDiagnostics) {
             "    Message:         'message #3'\n"
             "    Message:         'message #3'\n"
             "    FileOffset:      72\n"
             "    FileOffset:      72\n"
             "    FilePath:        'path/to/source2.cpp'\n"
             "    FilePath:        'path/to/source2.cpp'\n"
-            "    Replacements:    \n"
+            "    Replacements:    []\n"
             "...\n",
             "...\n",
             YamlContentStream.str());
             YamlContentStream.str());
 }
 }
@@ -113,7 +113,7 @@ TEST(DiagnosticsYamlTest, deserializesDiagnostics) {
                             "    Message:         'message #3'\n"
                             "    Message:         'message #3'\n"
                             "    FileOffset:      98\n"
                             "    FileOffset:      98\n"
                             "    FilePath:        path/to/source.cpp\n"
                             "    FilePath:        path/to/source.cpp\n"
-                            "    Replacements:    \n"
+                            "    Replacements:    []\n"
                             "...\n";
                             "...\n";
   TranslationUnitDiagnostics TUDActual;
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);
   yaml::Input YAML(YamlContent);

+ 2 - 2
unittests/Tooling/RefactoringActionRulesTest.cpp

@@ -117,8 +117,8 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
                  "Key:             'input.cpp:30'\n"
                  "Key:             'input.cpp:30'\n"
                  "FilePath:        input.cpp\n"
                  "FilePath:        input.cpp\n"
                  "Error:           ''\n"
                  "Error:           ''\n"
-                 "InsertedHeaders: \n"
-                 "RemovedHeaders:  \n"
+                 "InsertedHeaders: []\n"
+                 "RemovedHeaders:  []\n"
                  "Replacements:    \n" // Extra whitespace here!
                  "Replacements:    \n" // Extra whitespace here!
                  "  - FilePath:        input.cpp\n"
                  "  - FilePath:        input.cpp\n"
                  "    Offset:          30\n"
                  "    Offset:          30\n"