cppast bugfix

This commit is contained in:
ouczbs 2024-06-15 16:31:37 +08:00
parent 8471e5b5c9
commit b4ab4406fa
3 changed files with 53 additions and 6 deletions

47
src/CppAst.md Normal file
View File

@ -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 };
```

View File

@ -220,7 +220,7 @@ namespace CppAst
break; break;
default: 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())); cppClass.TemplateSpecializedArguments.Add(new CppTemplateArgument(tempParams[(int)i], arg.ToString()));
} }
break; break;
@ -428,7 +428,7 @@ namespace CppAst
// Don't emit warning // Don't emit warning
break; break;
default: default:
WarningUnhandled(cursor, parent); //WarningUnhandled(cursor, parent);
break; break;
} }
@ -1613,7 +1613,7 @@ namespace CppAst
if (!string.IsNullOrEmpty(errorMessage)) if (!string.IsNullOrEmpty(errorMessage))
{ {
var element = (CppElement)attrContainer; 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); AppendToMetaAttributes(attrContainer.MetaAttributes.MetaList, metaAttr);
@ -1902,7 +1902,7 @@ namespace CppAst
case CXTypeKind.CXType_DependentSizedArray: case CXTypeKind.CXType_DependentSizedArray:
{ {
// TODO: this is not yet supported // 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); var elementType = GetCppType(type.ArrayElementType.Declaration, type.ArrayElementType, parent, data);
return new CppArrayType(elementType, (int)type.ArraySize); return new CppArrayType(elementType, (int)type.ArraySize);
} }
@ -1933,7 +1933,7 @@ namespace CppAst
default: default:
{ {
WarningUnhandled(cursor, parent, type); //WarningUnhandled(cursor, parent, type);
return new CppUnexposedType(CXUtil.GetTypeSpelling(type)) { SizeOf = (int)type.SizeOf }; return new CppUnexposedType(CXUtil.GetTypeSpelling(type)) { SizeOf = (int)type.SizeOf };
} }
} }

View File

@ -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)); compilation.Diagnostics.Warning($"Compilation aborted due to one or more errors listed above.", new CppSourceLocation(rootFileName, 0, 1, 1));
} }