Add Visual Studio native visualizers for several Clang types
authorMike Spertus <mike@spertus.com>
Tue, 8 Mar 2016 16:14:23 +0000 (16:14 +0000)
committerMike Spertus <mike@spertus.com>
Tue, 8 Mar 2016 16:14:23 +0000 (16:14 +0000)
This is one of a series of changes to improve the MSVC visualization of Clang types.
This one focuses on Record and SubstTemplateTypeParmType meaning that, for example,
a TemplateArgumentLoc no longer displays incomprehensibly in the locals window as

  {Argument={DeclArg={Kind=1 QT=0x033acb00 D=0xcccccccc {DeclType=???}}...

but instead much more usefully as

  Type template parameter: SubstTemplateTypeParm: {Identifier (("T"))} => Record, {Identifier (("A"))}

Additional types and improvements will be made in subsequent commits

llvm-svn: 262933

clang/utils/clang.natvis

index a0004e9..6ff0123 100644 (file)
@@ -1,18 +1,81 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <!--\r
-Visual Studio 2012 Native Debugging Visualizers for LLVM\r
+Visual Studio Native Debugging Visualizers for LLVM\r
 \r
-Put this file into "%USERPROFILE%\Documents\Visual Studio 2012\Visualizers"\r
+Put this file into "%USERPROFILE%\Documents\Visual Studio 20xx\Visualizers"\r
 or create a symbolic link so it updates automatically.\r
 -->\r
 <AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">\r
   <Type Name="clang::Type">\r
-    <DisplayString Condition="(clang::Type::TypeClass)TypeBits.TC == clang::Type::Builtin">Builtin Type={(clang::BuiltinType::Kind)BuiltinTypeBits.Kind}</DisplayString>\r
-    <DisplayString Condition="(clang::Type::TypeClass)TypeBits.TC == clang::Type::Attributed">Modified Type={((clang::AttributedType*)this)->ModifiedType} Attribute={(clang::AttributedType::Kind)AttributedTypeBits.AttrKind}</DisplayString>\r
-    <DisplayString>Type Class={(clang::Type::TypeClass)TypeBits.TC}</DisplayString>\r
+    <DisplayString IncludeView="BaseOnly">{(clang::Type::TypeClass)TypeBits.TC, en}</DisplayString>\r
+    <DisplayString Condition="TypeBits.TC==clang::Type::TypeClass::Builtin">Builtin Type={*(clang::BuiltinType *)this}</DisplayString>\r
+    <DisplayString Condition="TypeBits.TC==clang::Type::Attributed">Modified Type={((clang::AttributedType*)this)->ModifiedType} Attribute={(clang::AttributedType::Kind)AttributedTypeBits.AttrKind}</DisplayString>\r
+    <DisplayString Condition="TypeBits.TC==clang::Type::TypeClass::SubstTemplateTypeParm">{*(clang::SubstTemplateTypeParmType *)this}</DisplayString>\r
+    <DisplayString Condition="TypeBits.TC==clang::Type::TypeClass::Record">{*(clang::RecordType *)this}</DisplayString>\r
+    <DisplayString>{(clang::Type::TypeClass)TypeBits.TC, en}</DisplayString>\r
+    <Expand>\r
+      <Item Name="TypeClass" IncludeView="BaseOnly">(clang::Type::TypeClass)TypeBits.TC</Item>\r
+      <Item Name="Flags" IncludeView="BaseOnly">TypeBits</Item>\r
+      <Item Name="Canonical" IncludeView="BaseOnly">CanonicalType</Item>\r
+      <ExpandedItem ExcludeView="BaseOnly" Condition="TypeBits.TC==clang::Type::TypeClass::Builtin">*(clang::BuiltinType *)this</ExpandedItem>\r
+      <ExpandedItem ExcludeView="BaseOnly" Condition="TypeBits.TC==clang::Type::TypeClass::SubstTemplateTypeParm">(clang::SubstTemplateTypeParmType *)this</ExpandedItem>\r
+      <ExpandedItem ExcludeView="BaseOnly" Condition="TypeBits.TC==clang::Type::TypeClass::Record">(clang::RecordType *)this</ExpandedItem>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::TagType">\r
+    <DisplayString>{*decl}</DisplayString>\r
+    <Expand>\r
+      <Item Name="decl">decl</Item>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::RecordType">\r
+    <DisplayString>{*(clang::Type *)this, view(BaseOnly)}, {*(clang::TagType *)this}</DisplayString>\r
+    <Expand>\r
+      <Item Name="TagType">*(clang::TagType *)this</Item>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::SubstTemplateTypeParmType">\r
+    <DisplayString>{*(clang::Type *)this, view(BaseOnly)}: {*Replaced} =&gt; {CanonicalType}</DisplayString>\r
+    <Expand>\r
+      <ExpandedItem>*(clang::Type *)this, view(BaseOnly)</ExpandedItem>\r
+      <Item Name="Replaced">*Replaced</Item>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::TemplateTypeParmType">\r
+    <DisplayString>{*TTPDecl}</DisplayString>\r
   </Type>\r
   <Type Name="clang::QualType">\r
-    <DisplayString>{((clang::ExtQualsTypeCommonBase *)(((uintptr_t)Value.Value) &amp; ~(uintptr_t)((1 &lt;&lt; clang::TypeAlignmentInBits) - 1)))-&gt;BaseType}</DisplayString>\r
+    <!-- TODO: Qualifiers. Also, when VS2013 support is deprecated, change 4 to clang::TypeAlignmentInBits (not properly recognized by VS2013) -->\r
+    <DisplayString>{*((clang::ExtQualsTypeCommonBase *)(((uintptr_t)Value.Value) &amp; ~(uintptr_t)((1 &lt;&lt; 4) - 1)))-&gt;BaseType}</DisplayString>\r
+    <Expand>\r
+      <Item Name="BaseType">*((clang::ExtQualsTypeCommonBase *)(((uintptr_t)Value.Value) &amp; ~(uintptr_t)((1 &lt;&lt; 4) - 1)))-&gt;BaseType</Item>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::TemplateArgumentLoc">\r
+    <DisplayString>{Argument}</DisplayString>\r
+    <Expand>\r
+      <ExpandedItem>Argument</ExpandedItem>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::TemplateArgument">\r
+    <DisplayString>{(clang::TemplateArgument::ArgKind)TypeOrValue.Kind,en} template parameter: {*(clang::QualType *)&amp;TypeOrValue.V}</DisplayString>\r
+    <Expand>\r
+      <Item Name="QualType" Condition="Integer.Kind == clang::TemplateArgument::ArgKind::Type">*(clang::QualType *)&amp;TypeOrValue.V</Item>\r
+      <!-- TODO: Other kinds-->\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::BuiltinType">\r
+    <DisplayString>{(clang::BuiltinType::Kind)BuiltinTypeBits.Kind, en}</DisplayString>\r
+    <Expand>\r
+      <Item Name="Kind">(clang::BuiltinType::Kind)BuiltinTypeBits.Kind</Item>\r
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::NamedDecl">\r
+    <DisplayString>{Name}</DisplayString>\r
+  </Type>\r
+  <Type Name="clang::TemplateSpecializationType">\r
+    <DisplayString Condition="(Template.Storage.Val.Val.Value &amp; 3) != 3 &amp;&amp; (Template.Storage.Val.Val.Value &amp; 2) != 2 &amp;&amp; (Template.Storage.Val.Val.Value &amp; 1) != 1">{(clang::TemplateDecl *)((Template.Storage.Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>\r
+    <DisplayString>{Template.Storage}</DisplayString>\r
   </Type>\r
   <Type Name="clang::IdentifierInfo">\r
     <DisplayString Condition="Entry != 0">({((llvm::StringMapEntry&lt;clang::IdentifierInfo *&gt;*)Entry)+1,s})</DisplayString>\r
@@ -32,14 +95,14 @@ or create a symbolic link so it updates automatically.
       <Item Condition="(Ptr &amp; PtrMask) == StoredObjCZeroArgSelector" Name="[ObjC Zero Arg Selector]">*(clang::IdentifierInfo *)(Ptr &amp; ~PtrMask)</Item>\r
       <Item Condition="(Ptr &amp; PtrMask) == StoredObjCOneArgSelector" Name="[ObjC One Arg Selector]">*(clang::IdentifierInfo *)(Ptr &amp; ~PtrMask)</Item>\r
       <Item Condition="(Ptr &amp; PtrMask) == StoredDeclarationNameExtra" Name="[Extra]">(clang::DeclarationNameExtra::ExtraKind)((clang::DeclarationNameExtra *)(Ptr &amp; ~PtrMask))-&gt;ExtraKindOrNumArgs</Item>\r
-    </Expand>
-  </Type>
-  <Type Name="clang::Token">
-    <DisplayString Condition="Kind != clang::tok::identifier">{(clang::tok::TokenKind)Kind}</DisplayString>
-    <DisplayString Condition="Kind == clang::tok::identifier">{{Identifier ({*(clang::IdentifierInfo *)(PtrData)})}}</DisplayString>
-  </Type>
-  <Type Name="clang::DeclSpec">
-    <DisplayString>[{(clang::DeclSpec::SCS)StorageClassSpec}], [{(clang::TypeSpecifierType)TypeSpecType}]</DisplayString>
+    </Expand>\r
+  </Type>\r
+  <Type Name="clang::Token">\r
+    <DisplayString Condition="Kind != clang::tok::identifier">{(clang::tok::TokenKind)Kind,en}</DisplayString>\r
+    <DisplayString Condition="Kind == clang::tok::identifier">{{Identifier ({*(clang::IdentifierInfo *)(PtrData)})}}</DisplayString>\r
+  </Type>\r
+  <Type Name="clang::DeclSpec">\r
+    <DisplayString>[{(clang::DeclSpec::SCS)StorageClassSpec}], [{(clang::TypeSpecifierType)TypeSpecType}]</DisplayString>\r
   </Type>\r
   <Type Name="clang::PragmaHandler">\r
     <DisplayString>{Name,s}</DisplayString>\r
@@ -65,4 +128,10 @@ or create a symbolic link so it updates automatically.
       <Item Name="ParmVarDeclBits">ParmVarDeclBits</Item>\r
     </Expand>\r
   </Type>\r
+  <Type Name="clang::OpaquePtr&lt;*&gt;">\r
+    <DisplayString>{($T1 *)Ptr</DisplayString>\r
+    <Expand>\r
+      <ExpandedItem>($T1 *)Ptr</ExpandedItem>\r
+    </Expand>\r
+  </Type>\r
 </AutoVisualizer>\r