Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary out-of-scope file promotion when the cursor results in no declaration #172

Open
PathogenDavid opened this issue Feb 27, 2021 · 1 comment
Labels
Area-Translation Issues concerning the translation from libclang into Biohazrd Bug Concept-OutputFriendliness Issues concerning the friendliness of using the Biohazrd output

Comments

@PathogenDavid
Copy link
Member

Out-of-scope file promotion happens eagerly in TranslationUnitParser.CreateDeclarations:

https://github.com/InfectedLibraries/Biohazrd/blob/99a504b77c076651ade931aa168ce7359adc0a4a/Biohazrd/TranslationUnitParser.cs#L251-L253

An unfortunate side-effect of this is if the cursor results in no translated declarations, the file is still promoted and the warning is still emitted.

This was discovered with this workaround (see #171 for some background.)

@PathogenDavid PathogenDavid added Bug Area-Translation Issues concerning the translation from libclang into Biohazrd Concept-OutputFriendliness Issues concerning the friendliness of using the Biohazrd output labels Feb 27, 2021
@PathogenDavid
Copy link
Member Author

Repro test for ScopeTests:

        [Fact]
        [RelatedIssue("https://github.com/InfectedLibraries/Biohazrd/issues/172")]
        public void OutOfScopeIgnoredDeclarationInsideInScopeDeclarationIsNotInScope()
        {
            TranslatedLibraryBuilder builder = new();
            builder.AddFile(new SourceFile("A.h")
            {
                Contents = "struct __declspec(dllexport) MyStruct;",
                IsInScope = false,
                IndexDirectly = false
            });

            builder.AddFile(new SourceFile("B.h")
            {
                Contents = @"
#include ""A.h""

struct MyStruct
{
    int x;
};
"
            });

            TranslatedLibrary library = builder.Create();

            Assert.Empty(library.ParsingDiagnostics);
            Assert.Single(library.Files);
            Assert.Single(library.Declarations);
            Assert.Equal("MyStruct", library.Declarations[0].Name);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Translation Issues concerning the translation from libclang into Biohazrd Bug Concept-OutputFriendliness Issues concerning the friendliness of using the Biohazrd output
Projects
None yet
Development

No branches or pull requests

1 participant