summaryrefslogtreecommitdiff
path: root/json4cpp/tools/generate_natvis
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:42:50 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:42:50 +0300
commit5fad10f89c485cfdc7b99011f07609f8871160d4 (patch)
tree1860b39753b652dfe54d3cbbc80c875f40198d1f /json4cpp/tools/generate_natvis
parent292baed7ac0cf84263263966ed32ed113cae857f (diff)
parent9a737481aed085fd289f82dff1fa8c3c66627a7e (diff)
downloadProject-Tick-5fad10f89c485cfdc7b99011f07609f8871160d4.tar.gz
Project-Tick-5fad10f89c485cfdc7b99011f07609f8871160d4.zip
Add 'json4cpp/' from commit '9a737481aed085fd289f82dff1fa8c3c66627a7e'
git-subtree-dir: json4cpp git-subtree-mainline: 292baed7ac0cf84263263966ed32ed113cae857f git-subtree-split: 9a737481aed085fd289f82dff1fa8c3c66627a7e
Diffstat (limited to 'json4cpp/tools/generate_natvis')
-rw-r--r--json4cpp/tools/generate_natvis/README.md9
-rwxr-xr-xjson4cpp/tools/generate_natvis/generate_natvis.py41
-rw-r--r--json4cpp/tools/generate_natvis/nlohmann_json.natvis.j240
-rw-r--r--json4cpp/tools/generate_natvis/requirements.txt1
4 files changed, 91 insertions, 0 deletions
diff --git a/json4cpp/tools/generate_natvis/README.md b/json4cpp/tools/generate_natvis/README.md
new file mode 100644
index 0000000000..e11f29eecb
--- /dev/null
+++ b/json4cpp/tools/generate_natvis/README.md
@@ -0,0 +1,9 @@
+# generate_natvis.py
+
+Generate the Natvis debugger visualization file for all supported namespace combinations.
+
+## Usage
+
+```shell
+./generate_natvis.py --version X.Y.Z output_directory/
+```
diff --git a/json4cpp/tools/generate_natvis/generate_natvis.py b/json4cpp/tools/generate_natvis/generate_natvis.py
new file mode 100755
index 0000000000..9266050c5d
--- /dev/null
+++ b/json4cpp/tools/generate_natvis/generate_natvis.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+import argparse
+import itertools
+import jinja2
+import os
+import re
+import sys
+
+def semver(v):
+ if not re.fullmatch(r'\d+\.\d+\.\d+', v):
+ raise ValueError
+ return v
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--version', required=True, type=semver, help='Library version number')
+ parser.add_argument('output', help='Output directory for nlohmann_json.natvis')
+ args = parser.parse_args()
+
+ namespaces = ['nlohmann']
+ abi_prefix = 'json_abi'
+ abi_tags = ['_diag', '_ldvcmp']
+ version = '_v' + args.version.replace('.', '_')
+ inline_namespaces = []
+
+ # generate all combinations of inline namespace names
+ for n in range(0, len(abi_tags) + 1):
+ for tags in itertools.combinations(abi_tags, n):
+ ns = abi_prefix + ''.join(tags)
+ inline_namespaces += [ns, ns + version]
+
+ namespaces += [f'{namespaces[0]}::{ns}' for ns in inline_namespaces]
+
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]), autoescape=True, trim_blocks=True,
+ lstrip_blocks=True, keep_trailing_newline=True)
+ template = env.get_template('nlohmann_json.natvis.j2')
+ natvis = template.render(namespaces=namespaces)
+
+ with open(os.path.join(args.output, 'nlohmann_json.natvis'), 'w') as f:
+ f.write(natvis)
diff --git a/json4cpp/tools/generate_natvis/nlohmann_json.natvis.j2 b/json4cpp/tools/generate_natvis/nlohmann_json.natvis.j2
new file mode 100644
index 0000000000..c3eafa54b1
--- /dev/null
+++ b/json4cpp/tools/generate_natvis/nlohmann_json.natvis.j2
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- * * * * * * * * AUTO-GENERATED FILE * * * * * * * * -->
+<!-- Edit ./tools/generate_natvis/nlohmann_json.natvis.j2 -->
+<!-- * * * * * * * * AUTO-GENERATED FILE * * * * * * * * -->
+
+<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
+{% for ns in namespaces %}
+ <!-- Namespace {{ ns }} -->
+ <Type Name="{{ ns }}::basic_json&lt;*&gt;">
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::null">null</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::object">{*(m_data.m_value.object)}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::array">{*(m_data.m_value.array)}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::string">{*(m_data.m_value.string)}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::boolean">{m_data.m_value.boolean}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::number_integer">{m_data.m_value.number_integer}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::number_unsigned">{m_data.m_value.number_unsigned}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::number_float">{m_data.m_value.number_float}</DisplayString>
+ <DisplayString Condition="m_data.m_type == {{ ns }}::detail::value_t::discarded">discarded</DisplayString>
+ <Expand>
+ <ExpandedItem Condition="m_data.m_type == {{ ns }}::detail::value_t::object">
+ *(m_data.m_value.object),view(simple)
+ </ExpandedItem>
+ <ExpandedItem Condition="m_data.m_type == {{ ns }}::detail::value_t::array">
+ *(m_data.m_value.array),view(simple)
+ </ExpandedItem>
+ </Expand>
+ </Type>
+
+ <!-- Skip the pair first/second members in the treeview while traversing a map.
+ Only works in VS 2015 Update 2 and beyond using the new visualization -->
+ <Type Name="std::pair&lt;*, {{ ns }}::basic_json&lt;*&gt;&gt;" IncludeView="MapHelper">
+ <DisplayString>{second}</DisplayString>
+ <Expand>
+ <ExpandedItem>second</ExpandedItem>
+ </Expand>
+ </Type>
+
+{% endfor %}
+</AutoVisualizer>
diff --git a/json4cpp/tools/generate_natvis/requirements.txt b/json4cpp/tools/generate_natvis/requirements.txt
new file mode 100644
index 0000000000..6bbf6aa1d4
--- /dev/null
+++ b/json4cpp/tools/generate_natvis/requirements.txt
@@ -0,0 +1 @@
+jinja2==3.1.6