Tools and libraries to glue C/C++ APIs to high-level languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

92 lines
2.9 KiB

using System;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute;
namespace CppSharp.Tests
{
[TypeMap("QFlags")]
public class QFlags : TypeMap
{
public override string CSharpSignature(CSharpTypePrinterContext ctx)
{
TemplateArgument templateArgument =
((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0];
return templateArgument.Type.Type.ToString();
}
public override void CSharpMarshalToNative(MarshalContext ctx)
{
ctx.Return.Write(ctx.Parameter.Name);
}
public override void CSharpMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write(ctx.ReturnVarName);
}
}
public class TestAttributesPass : TranslationUnitPass
{
public override bool VisitFunctionDecl(Function function)
{
if (AlreadyVisited(function) || function.Name != "obsolete")
return false;
var attribute = new Attribute
{
Type = typeof(ObsoleteAttribute),
Value = string.Format("\"{0} is obsolete.\"", function.Name)
};
function.Attributes.Add(attribute);
return base.VisitFunctionDecl(function);
}
}
public class CSharpTempTests : GeneratorTest
{
public CSharpTempTests(GeneratorKind kind)
: base("CSharpTemp", kind)
{
}
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = true;
driver.Options.GenerateCopyConstructors = true;
// To ensure that calls to constructors in conversion operators
// are not ambiguous with multiple inheritance pass enabled.
driver.Options.GenerateConversionOperators = true;
driver.TranslationUnitPasses.AddPass(new TestAttributesPass());
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateDefaultValuesForArguments = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)
{
ctx.SetClassAsValueType("TestCopyConstructorVal");
}
public override void Postprocess(Driver driver, ASTContext ctx)
{
new CaseRenamePass(
RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate,
RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext);
}
public static void Main(string[] args)
{
ConsoleDriver.Run(new CSharpTempTests(GeneratorKind.CSharp));
}
}
}