Skip to content

Commit

Permalink
Add new property modes to the CLI driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Sep 3, 2024
1 parent b04bf1d commit 63ca51a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/CLI/CLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using CppSharp.Generators;
using CppSharp.Passes;
using Mono.Options;

namespace CppSharp
Expand Down Expand Up @@ -34,6 +35,7 @@ static bool ParseCommandLineArgs(string[] args, List<string> errorMessages, ref
optionSet.Add("p=|platform=", "the {PLATFORM} that the generated code will target: 'win', 'osx' or 'linux' or 'emscripten'", p => { GetDestinationPlatform(p, errorMessages); });
optionSet.Add("a=|arch=", "the {ARCHITECTURE} that the generated code will target: 'x86' or 'x64' or 'wasm32' or 'wasm64'", a => { GetDestinationArchitecture(a, errorMessages); });
optionSet.Add("prefix=", "sets a string prefix to the names of generated files", a => { options.Prefix = a; });
optionSet.Add("property=", "the property detection mode to use: 'all', 'none' or 'keywords' or 'heuristics'", p => { GetPropertyMode(p, errorMessages); });

optionSet.Add("exceptions", "enables support for C++ exceptions in the parser", v => { options.EnableExceptions = true; });
optionSet.Add("rtti", "enables support for C++ RTTI in the parser", v => { options.EnableRTTI = true; });
Expand Down Expand Up @@ -269,6 +271,27 @@ public static void GetDestinationArchitecture(string architecture, List<string>
Defaulting to {options.Architecture}");
}

static void GetPropertyMode(string mode, List<string> errorMessages)
{
switch (mode.ToLower())
{
case "all":
options.PropertyMode = PropertyDetectionMode.All;
return;
case "none":
options.PropertyMode = PropertyDetectionMode.None;
return;
case "dictionary":
options.PropertyMode = PropertyDetectionMode.Dictionary;
return;
case "keywords":
options.PropertyMode = PropertyDetectionMode.Keywords;
return;
}

errorMessages.Add($"Unknown property detection mode: {mode}. Defaulting to {options.PropertyMode}");
}

static void PrintErrorMessages(List<string> errorMessages)
{
foreach (string m in errorMessages)
Expand Down
1 change: 1 addition & 0 deletions src/CLI/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void Setup(Driver driver)

var driverOptions = driver.Options;
driverOptions.GeneratorKind = options.Kind;
driverOptions.PropertyDetectionMode = options.PropertyMode;
var module = driverOptions.AddModule(options.OutputFileName);

if (!string.IsNullOrEmpty(options.InputLibraryName))
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Options

public GeneratorKind Kind { get; set; } = GeneratorKind.CSharp;

public PropertyDetectionMode PropertyMode = PropertyDetectionMode.Keywords;
public PropertyDetectionMode PropertyMode { get; set; } = PropertyDetectionMode.Keywords;

public bool CheckSymbols { get; set; }

Expand Down

0 comments on commit 63ca51a

Please sign in to comment.