Created
May 11, 2015 05:46
-
-
Save genuinelucifer/cf7cc3fb1c249fae1fc6 to your computer and use it in GitHub Desktop.
Complete CS_INTERNAL Implementation and testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/AST/Class.cs b/src/AST/Class.cs | |
index 45b535f..07e1d53 100644 | |
--- a/src/AST/Class.cs | |
+++ b/src/AST/Class.cs | |
@@ -10,7 +10,8 @@ public enum AccessSpecifier | |
{ | |
Private, | |
Protected, | |
- Public | |
+ Public, | |
+ Internal //via the CS_INTERNAL macro (to be implemen | |
} | |
// A C++ access specifier declaration. | |
diff --git a/src/Generator.Tests/Passes/TestPasses.cs b/src/Generator.Tests/Pass | |
index 6a6de8c..c5da516 100644 | |
--- a/src/Generator.Tests/Passes/TestPasses.cs | |
+++ b/src/Generator.Tests/Passes/TestPasses.cs | |
@@ -191,5 +191,16 @@ public void TestCheckAmbiguousFunctionsPass() | |
Assert.IsTrue(constMethodWithParam.GenerationKind == GenerationKind | |
Assert.IsTrue(nonConstMethodWithParam.GenerationKind == GenerationK | |
} | |
+ | |
+ [Test] | |
+ public void TestSetMethodAsInternal() | |
+ { | |
+ var c = AstContext.Class("TestMethodAsInternal"); | |
+ var method = c.Method("beInternal"); | |
+ Assert.IsTrue(method.Access == AccessSpecifier.Public); | |
+ passBuilder.AddPass(new CheckMacroPass()); | |
+ passBuilder.RunPasses(pass => pass.VisitLibrary(AstContext)); | |
+ Assert.IsTrue(method.Access == AccessSpecifier.Internal); | |
+ } | |
} | |
} | |
diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generat | |
index f4f2345..ef0a242 100644 | |
--- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs | |
+++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs | |
@@ -53,6 +53,7 @@ public static string GetAccess(AccessSpecifier accessSpecifier | |
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/Chec | |
index 26f2caa..62ace33 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 | |
/// | |
+ /// 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. | |
/// </summary> | |
@@ -155,6 +159,9 @@ public override bool VisitMethodDecl(Method method) | |
|| e.Text == Prefix + "_EQUALS")) | |
method.ExplicitlyIgnore(); | |
+ if (expansions.Any(e => e.Text == Prefix + "_INTERNAL")) //Flag a m | |
+ method.Access = AccessSpecifier.Internal; | |
+ | |
return base.VisitMethodDecl(method); | |
} | |
diff --git a/tests/Native/Passes.h b/tests/Native/Passes.h | |
index eba7caf..eb3ed03 100644 | |
--- a/tests/Native/Passes.h | |
+++ b/tests/Native/Passes.h | |
@@ -61,3 +61,10 @@ struct TestCheckAmbiguousFunctionsPass | |
int Method(int x); | |
int Method(int x) const; | |
}; | |
+ | |
+ | |
+#define CS_INTERNAL | |
+struct TestMethodAsInternal | |
+{ | |
+ int CS_INTERNAL beInternal(); | |
+}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment