OSDN Git Service

[pdb] Make YamlTypeDumperCallbacks reuse *this.
authorZachary Turner <zturner@google.com>
Thu, 8 Sep 2016 18:36:55 +0000 (18:36 +0000)
committerZachary Turner <zturner@google.com>
Thu, 8 Sep 2016 18:36:55 +0000 (18:36 +0000)
Previously we were making new instances of YamlTypeDumperCallbacks
in order to recurse down and serialize / deserialize nested
records such as field lists.  This meant you could not pass
context from a higher operation to a lower operation because
it would be using a new instance of the visitor callback
delegate.

YAMLIO library was updated to support context-sensitive mappings,
so now we can reuse the same instance of the visitor callback
delegate even for nested operations.

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

tools/llvm-pdbdump/CodeViewYaml.cpp
tools/llvm-pdbdump/CodeViewYaml.h

index 4817c59..fd6f194 100644 (file)
@@ -269,29 +269,28 @@ template <> struct ScalarTraits<APSInt> {
   static bool mustQuote(StringRef Scalar) { return false; }
 };
 
-void MappingTraits<CVType>::mapping(IO &IO, CVType &Record) {
+void MappingContextTraits<CVType, YamlTypeDumperCallbacks>::mapping(
+    IO &IO, CVType &Record, YamlTypeDumperCallbacks &Dumper) {
   if (IO.outputting()) {
     codeview::TypeDeserializer Deserializer;
-    codeview::yaml::YamlTypeDumperCallbacks Callbacks(IO);
 
     codeview::TypeVisitorCallbackPipeline Pipeline;
     Pipeline.addCallbackToPipeline(Deserializer);
-    Pipeline.addCallbackToPipeline(Callbacks);
+    Pipeline.addCallbackToPipeline(Dumper);
 
     codeview::CVTypeVisitor Visitor(Pipeline);
     consumeError(Visitor.visitTypeRecord(Record));
   }
 }
 
-void MappingTraits<FieldListRecord>::mapping(IO &IO,
-                                             FieldListRecord &FieldList) {
+void MappingContextTraits<FieldListRecord, YamlTypeDumperCallbacks>::mapping(
+    IO &IO, FieldListRecord &FieldList, YamlTypeDumperCallbacks &Dumper) {
   if (IO.outputting()) {
-    codeview::yaml::YamlTypeDumperCallbacks Callbacks(IO);
     codeview::TypeDeserializer Deserializer;
 
     codeview::TypeVisitorCallbackPipeline Pipeline;
     Pipeline.addCallbackToPipeline(Deserializer);
-    Pipeline.addCallbackToPipeline(Callbacks);
+    Pipeline.addCallbackToPipeline(Dumper);
 
     codeview::CVTypeVisitor Visitor(Pipeline);
     consumeError(Visitor.visitFieldListMemberStream(FieldList.Data));
index ccf7e40..d10ed61 100644 (file)
@@ -57,8 +57,11 @@ template <> struct MappingTraits<codeview::MemberPointerInfo> {
   static void mapping(IO &IO, codeview::MemberPointerInfo &Obj);
 };
 
-template <> struct MappingTraits<codeview::CVType> {
-  static void mapping(IO &IO, codeview::CVType &Obj);
+template <>
+struct MappingContextTraits<codeview::CVType,
+                            codeview::yaml::YamlTypeDumperCallbacks> {
+  static void mapping(IO &IO, codeview::CVType &Obj,
+                      codeview::yaml::YamlTypeDumperCallbacks &Context);
 };
 
 template <> struct ScalarEnumerationTraits<codeview::TypeLeafKind> {
@@ -74,6 +77,13 @@ template <> struct ScalarEnumerationTraits<codeview::TypeLeafKind> {
 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
 #include "llvm/DebugInfo/CodeView/TypeRecords.def"
+
+template <>
+struct MappingContextTraits<codeview::FieldListRecord,
+                            codeview::yaml::YamlTypeDumperCallbacks> {
+  static void mapping(IO &IO, codeview::FieldListRecord &Record,
+                      codeview::yaml::YamlTypeDumperCallbacks &Context);
+};
 }
 }