CppContainerList throws "The item belongs already to a container" when parsing VTK 9.5 headers Body
まだ誰も着手していません。
評価
調査の方向性
CppContainerList.Add と Insert から始め、CXType_Unexposed と ParseTemplateSpecializedArguments を通じて CppModelBuilder.GetCppTypeInternal を追跡します。示されているオプションで VTK 9.5 の vtkActor.h をパースして失敗を再現します。コンテナの ownership exception なしでヘッダーをパースでき、重複と parent の動作も引き続きカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
When parsing VTK 9.5 headers with CppParser.ParseFile, an ArgumentException is thrown:
System.ArgumentException: The item belongs already to a container
at CppAst.CppContainerList`1.Add(TElement item)
at CppAst.CppContainerList`1.AddRange(IEnumerable`1 collection)
at CppAst.CppModelBuilder.GetCppTypeInternal(CXCursor cursor, CXType type, CXCursor parent, Void* data)
Reproduction
var options = new CppParserOptions();
options.ConfigureForWindowsMsvc(CppTargetCpu.X86_64, CppVisualStudioVersion.VS2022);
options.IncludeFolders.Add(@"C:\Program Files\VTK\include\vtk-9.5");
var compilation = CppParser.ParseFile(@"C:\Program Files\VTK\include\vtk-9.5\vtkActor.h", options);
Environment: VTK 9.5 headers, CppAst 0.25.0, ClangSharp 21.1.8.3, Windows x64.
Root Cause
The problem is in CppContainerList<T>.Add() — it enforces strict single-parent ownership:
public void Add(TElement item)
{
if (item.Parent != null)
throw new ArgumentException("The item belongs already to a container");
...
}
During GetCppTypeInternal → CXType_Unexposed handling, ParseTemplateSpecializedArguments resolves template arguments that return type instances already belonging to a container (e.g., a CppClass that was added to compilation.Classes). When these same instances are added to CppUnexposedType.TemplateParameters via AddRange, the strict check fails.
The stack trace consistently points to:
GetCppTypeInternal → VisitElaboratedDecl → GetCppType → GetCppTypeInternal → VisitFunctionDecl → CppContainerList.AddRange
Suggested Fix
Relax Add and Insert to allow re-parenting. Skip duplicates in the same container, otherwise allow the element to move:
public void Add(TElement item)
{
if (item.Parent == Container)
return; // Already in this container
item.Parent = Container;
_elements.Add(item);
}
public void Insert(int index, TElement item)
{
if (item.Parent == Container)
return; // Already in this container
item.Parent = Container;
_elements.Insert(index, item);
}
This is the same approach taken by XML DOM implementations — a node can be moved from one parent to another without error.
- 主要言語
- C#
- スター
- 623
- フォーク
- 79
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
xoofx/CppAst.NET のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
xoofx/CppAst.NET#117 ·
-
question
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
xoofx/CppAst.NET#115 · コメント 3 件 ·
-
question
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
xoofx/CppAst.NET#95 · コメント 4 件 ·
-
NullReferenceException when parsing instantiation of a previously partially specialised templateオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
xoofx/CppAst.NET#77 · コメント 6 件 ·
-
bug PR Welcome
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
xoofx/CppAst.NET#73 ·
xoofx/CppAst.NET の issue をすべて見る
似ている issue
-
documentation
難易度 1/5 1〜3時間 初心者へのやさしさ 62/100
-
bug misleading tooling trivial
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Docs example projects pinned to a literal library version instead of 3.*対応中かも @DaveSkender が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
facioquo/stock-indicators-dotnet#2372 ·
メンテナーはふだん 1 日以内に返信
-
[Docs] officecli-docx SKILL.md still describes `\n` as a soft line break after #262対応中かも @giprime が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Facepunch/sbox-public#12097 ·
メンテナーはふだん 2 日以内に返信