diff --git a/src/AST/Class.cs b/src/AST/Class.cs index 45b535f5..e6129619 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -10,7 +10,8 @@ namespace CppSharp.AST { Private, Protected, - Public + Public, + Internal } // A C++ access specifier declaration. diff --git a/src/Generator.Tests/Passes/TestPasses.cs b/src/Generator.Tests/Passes/TestPasses.cs index 6a6de8c0..d9cb4189 100644 --- a/src/Generator.Tests/Passes/TestPasses.cs +++ b/src/Generator.Tests/Passes/TestPasses.cs @@ -191,5 +191,16 @@ namespace CppSharp.Generator.Tests.Passes Assert.IsTrue(constMethodWithParam.GenerationKind == GenerationKind.None); Assert.IsTrue(nonConstMethodWithParam.GenerationKind == GenerationKind.Generate); } + + [Test] + public void TestSetMethodAsInternal() + { + var c = AstContext.Class("TestMethodAsInternal"); + var method = c.Method("beInternal"); + Assert.AreEqual(method.Access , AccessSpecifier.Public); + passBuilder.AddPass(new CheckMacroPass()); + passBuilder.RunPasses(pass => pass.VisitLibrary(AstContext)); + Assert.AreEqual(method.Access , AccessSpecifier.Internal); + } } } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index f4f23459..ef0a2424 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -53,6 +53,7 @@ namespace CppSharp.Generators.CSharp switch (accessSpecifier) { case AccessSpecifier.Private: + case AccessSpecifier.Internal: return "internal "; case AccessSpecifier.Protected: return "protected "; diff --git a/src/Generator/Passes/CheckMacrosPass.cs b/src/Generator/Passes/CheckMacrosPass.cs index 26f2caa9..1946c30f 100644 --- a/src/Generator/Passes/CheckMacrosPass.cs +++ b/src/Generator/Passes/CheckMacrosPass.cs @@ -42,6 +42,10 @@ namespace CppSharp.Passes /// CS_CONSTRAINT(TYPE [, TYPE]*) (templates) /// Used to define constraint of generated generic type or generic method. /// + /// CS_INTERNAL (methods) + /// Used to flag a method as internal to an assembly. So, it is + /// not accessible outside that assembly. + /// /// There isn't a standardized header provided by CppSharp so you will /// have to define these on your own. /// @@ -155,6 +159,9 @@ namespace CppSharp.Passes || e.Text == Prefix + "_EQUALS")) method.ExplicitlyIgnore(); + if (expansions.Any(e => e.Text == Prefix + "_INTERNAL")) + method.Access = AccessSpecifier.Internal; + return base.VisitMethodDecl(method); } diff --git a/tests/Native/Passes.h b/tests/Native/Passes.h index eba7caf1..ee46e57c 100644 --- a/tests/Native/Passes.h +++ b/tests/Native/Passes.h @@ -61,3 +61,9 @@ struct TestCheckAmbiguousFunctionsPass int Method(int x); int Method(int x) const; }; + +#define CS_INTERNAL +struct TestMethodAsInternal +{ + int CS_INTERNAL beInternal(); +};