From b4ab4406fa3bf7344260365f72de7856563506d4 Mon Sep 17 00:00:00 2001 From: ouczbs Date: Sat, 15 Jun 2024 16:31:37 +0800 Subject: [PATCH] cppast bugfix --- src/CppAst.md | 47 +++++++++++++++++++++++++++++++++++ src/CppAst/CppModelBuilder.cs | 10 ++++---- src/CppAst/CppParser.cs | 2 +- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/CppAst.md diff --git a/src/CppAst.md b/src/CppAst.md new file mode 100644 index 0000000..7989026 --- /dev/null +++ b/src/CppAst.md @@ -0,0 +1,47 @@ +# CppParser + +```c# +if (skipProcessing && false) +{ + compilation.Diagnostics.Warning($"Compilation aborted due to one or more errors listed above.", new CppSourceLocation(rootFileName, 0, 1, 1)); +} +else +{ + translationUnit.Cursor.VisitChildren(builder.VisitTranslationUnit, clientData: default); +} +``` + +# CppModelBuilder + +```c# +//Debug.WriteLine($"[Warning]template argument in class:{cppClass.FullName} with type: {arg.kind} do not handle right now!"); +cppClass.TemplateSpecializedArguments.Add(new CppTemplateArgument(tempParams[(int)i], arg.ToString())); + + + +//WarningUnhandled(cursor, parent); +break; + + + +if (!string.IsNullOrEmpty(errorMessage)) +{ + var element = (CppElement)attrContainer; + //throw new Exception($"handle meta not right, detail: `{errorMessage}, location: `{element.Span}`"); +} + +AppendToMetaAttributes(attrContainer.MetaAttributes.MetaList, metaAttr); + + + +// TODO: this is not yet supported +//RootCompilation.Diagnostics.Warning($"Dependent sized arrays `{CXUtil.GetTypeSpelling(type)}` from `{CXUtil.GetCursorSpelling(parent)}` is not supported", GetSourceLocation(parent.Location)); +var elementType = GetCppType(type.ArrayElementType.Declaration, type.ArrayElementType, parent, data); +return new CppArrayType(elementType, (int)type.ArraySize); + + + +//WarningUnhandled(cursor, parent, type); +return new CppUnexposedType(CXUtil.GetTypeSpelling(type)) { SizeOf = (int)type.SizeOf }; +``` + diff --git a/src/CppAst/CppModelBuilder.cs b/src/CppAst/CppModelBuilder.cs index dca8a06..18178ea 100644 --- a/src/CppAst/CppModelBuilder.cs +++ b/src/CppAst/CppModelBuilder.cs @@ -220,7 +220,7 @@ namespace CppAst break; default: { - Debug.WriteLine($"[Warning]template argument in class:{cppClass.FullName} with type: {arg.kind} do not handle right now!"); + //Debug.WriteLine($"[Warning]template argument in class:{cppClass.FullName} with type: {arg.kind} do not handle right now!"); cppClass.TemplateSpecializedArguments.Add(new CppTemplateArgument(tempParams[(int)i], arg.ToString())); } break; @@ -428,7 +428,7 @@ namespace CppAst // Don't emit warning break; default: - WarningUnhandled(cursor, parent); + //WarningUnhandled(cursor, parent); break; } @@ -1613,7 +1613,7 @@ namespace CppAst if (!string.IsNullOrEmpty(errorMessage)) { var element = (CppElement)attrContainer; - throw new Exception($"handle meta not right, detail: `{errorMessage}, location: `{element.Span}`"); + //throw new Exception($"handle meta not right, detail: `{errorMessage}, location: `{element.Span}`"); } AppendToMetaAttributes(attrContainer.MetaAttributes.MetaList, metaAttr); @@ -1902,7 +1902,7 @@ namespace CppAst case CXTypeKind.CXType_DependentSizedArray: { // TODO: this is not yet supported - RootCompilation.Diagnostics.Warning($"Dependent sized arrays `{CXUtil.GetTypeSpelling(type)}` from `{CXUtil.GetCursorSpelling(parent)}` is not supported", GetSourceLocation(parent.Location)); + //RootCompilation.Diagnostics.Warning($"Dependent sized arrays `{CXUtil.GetTypeSpelling(type)}` from `{CXUtil.GetCursorSpelling(parent)}` is not supported", GetSourceLocation(parent.Location)); var elementType = GetCppType(type.ArrayElementType.Declaration, type.ArrayElementType, parent, data); return new CppArrayType(elementType, (int)type.ArraySize); } @@ -1933,7 +1933,7 @@ namespace CppAst default: { - WarningUnhandled(cursor, parent, type); + //WarningUnhandled(cursor, parent, type); return new CppUnexposedType(CXUtil.GetTypeSpelling(type)) { SizeOf = (int)type.SizeOf }; } } diff --git a/src/CppAst/CppParser.cs b/src/CppAst/CppParser.cs index 744c615..6a3b5cc 100644 --- a/src/CppAst/CppParser.cs +++ b/src/CppAst/CppParser.cs @@ -211,7 +211,7 @@ namespace CppAst } } - if (skipProcessing) + if (skipProcessing && false) { compilation.Diagnostics.Warning($"Compilation aborted due to one or more errors listed above.", new CppSourceLocation(rootFileName, 0, 1, 1)); }