Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ private void VisitVarDecl(VarDecl varDecl)
var nativeName = GetCursorName(varDecl);
if (nativeName.StartsWith("ClangSharpMacro_", StringComparison.Ordinal))
{
type = varDecl.Init.Type;
nativeName = nativeName["ClangSharpMacro_".Length..];
isMacroDefinitionRecord = true;

if (varDecl.Init is null)
{
AddDiagnostic(DiagnosticLevel.Warning, $"Macro definition '{nativeName}' could not be resolved to a supported expression. Generated bindings may be incomplete.", varDecl);
return;
}

type = varDecl.Init.Type;
}

var accessSpecifier = GetAccessSpecifier(varDecl, matchStar: false);
Expand All @@ -61,8 +68,9 @@ private void VisitVarDecl(VarDecl varDecl)
return;
}
}
else if (IsStmtAsWritten<RecoveryExpr>(varDecl.Init, out var recoveryExpr, removeParens: true))
else if (IsStmtAsWritten<RecoveryExpr>(varDecl.Init, out _, removeParens: true))
{
AddDiagnostic(DiagnosticLevel.Warning, $"Macro definition '{nativeName}' could not be resolved to a supported expression. Generated bindings may be incomplete.", varDecl);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion sources/ClangSharp/Cursors/Decls/VarDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private protected unsafe VarDecl(CXCursor handle, CXCursorKind expectedCursorKin

private static unsafe VarDecl InstantiatedFromStaticDataMemberFactory(VarDecl self) => self.TranslationUnit.GetOrCreate<VarDecl>(self.Handle.InstantiatedFromMember);

private static unsafe Expr InitFactory(VarDecl self) => self.TranslationUnit.GetOrCreate<Expr>(self.Handle.InitExpr);
private static unsafe Expr InitFactory(VarDecl self) => (self.TranslationUnit.GetOrCreate<Stmt>(self.Handle.InitExpr) as Expr)!;

private static unsafe VarDecl DefinitionFactory(VarDecl self) => self.TranslationUnit.GetOrCreate<VarDecl>(self.Handle.Definition);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public abstract class VarDeclarationTest : PInvokeGeneratorTest
[Test]
public Task ConditionalDefineConstTest() => ConditionalDefineConstTestImpl();

[Test]
public Task UndefinedFunctionLikeMacroTest() => UndefinedFunctionLikeMacroTestImpl();

protected abstract Task BasicTestImpl(string nativeType, string expectedManagedType);

protected abstract Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType);
Expand Down Expand Up @@ -121,4 +124,6 @@ public abstract class VarDeclarationTest : PInvokeGeneratorTest
protected abstract Task MultidimensionlArrayTestImpl();

protected abstract Task ConditionalDefineConstTestImpl();

protected abstract Task UndefinedFunctionLikeMacroTestImpl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,14 @@ public static partial class Methods

return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,14 @@ public static partial class Methods

return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,14 @@ public static partial class Methods

return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,14 @@ public static partial class Methods

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,14 @@ public static partial class Methods

return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,14 @@ public static partial class Methods

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,14 @@ public static partial class Methods

return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,14 @@ public static partial class Methods

return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,14 @@ protected override Task ConditionalDefineConstTestImpl()

return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}

protected override Task UndefinedFunctionLikeMacroTestImpl()
{
var inputContents = @"#define ADDRESS_IN_USE TESTRESULT_FROM_WIN32(10048)";

var expectedOutputContents = "";
var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Macro definition 'ADDRESS_IN_USE' could not be resolved to a supported expression. Generated bindings may be incomplete.", "Line 2, Column 12 in ClangUnsavedFile.h") };

return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics);
}
}
Loading