CppContainerList throws "The item belongs already to a container" when parsing VTK 9.5 headers Body
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu với CppContainerList.Add và Insert, sau đó lần theo CppModelBuilder.GetCppTypeInternal qua CXType_Unexposed và ParseTemplateSpecializedArguments. Tái hiện lỗi bằng cách parse vtkActor.h từ VTK 9.5 với các tùy chọn được nêu. Được xem là hoàn tất khi header được parse mà không xảy ra container ownership exception, đồng thời hành vi đối với duplicate và parent vẫn được bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C#
- Star
- 625
- Fork
- 79
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của xoofx/CppAst.NET
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
xoofx/CppAst.NET#117 ·
-
Parsing .cpp implementation?Đang mởquestion
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
xoofx/CppAst.NET#115 · 3 bình luận ·
-
question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
xoofx/CppAst.NET#95 · 4 bình luận ·
-
NullReferenceException when parsing instantiation of a previously partially specialised templateĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
xoofx/CppAst.NET#77 · 6 bình luận ·
-
bug PR Welcome
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
xoofx/CppAst.NET#73 ·
Tất cả issue của xoofx/CppAst.NET
Issue tương tự
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug github_actions
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
endercodezz/BYDLO#336 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
SubtitleEdit/subtitleedit#16638 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100