82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
|
|
using CommandLine;
|
|||
|
|
using CppAst;
|
|||
|
|
namespace refl
|
|||
|
|
{
|
|||
|
|
[Verb("build",HelpText = "Generate custom code based on the parsed AST.")]
|
|||
|
|
internal class CmdBuildOption
|
|||
|
|
{
|
|||
|
|
[Value(0, MetaName = "", Required = true, Min = 2, HelpText = "Input file(s) for parsing.")]
|
|||
|
|
public IEnumerable<string> InputFiles { get; set; }
|
|||
|
|
|
|||
|
|
[Option('o', "output", Required = false, HelpText = "Output file for generated code.")]
|
|||
|
|
public string OutputFile { get; set; }
|
|||
|
|
|
|||
|
|
[Option('t', "type", Required = false, HelpText = "Type of code to generate.")]
|
|||
|
|
public string CodeType { get; set; }
|
|||
|
|
|
|||
|
|
[Option('l', "link", Required = false, HelpText = "link to the include dir")]
|
|||
|
|
public string Link { get; set; }
|
|||
|
|
|
|||
|
|
[Option('d', "define", Required = false, HelpText = "define a macro on the command line")]
|
|||
|
|
public string Define { get; set; }
|
|||
|
|
|
|||
|
|
[Option('n', "namespace", Required = false, HelpText = "Namespace for generated code.")]
|
|||
|
|
public string Namespace { get; set; }
|
|||
|
|
|
|||
|
|
[Option('h', "help", HelpText = "Display this help message.")]
|
|||
|
|
public bool Help { get; set; }
|
|||
|
|
|
|||
|
|
static CppParserOptions MakeParserOptions(CmdBuildOption opt)
|
|||
|
|
{
|
|||
|
|
var parse = new CppParserOptions
|
|||
|
|
{
|
|||
|
|
AdditionalArguments = { "-std=c++20" },
|
|||
|
|
ParseTokenAttributes = true,
|
|||
|
|
};
|
|||
|
|
if (!string.IsNullOrWhiteSpace(opt.Define))
|
|||
|
|
{
|
|||
|
|
var defines = opt.Define.Split(";");
|
|||
|
|
foreach (var def in defines)
|
|||
|
|
{
|
|||
|
|
parse.Defines.Add(def);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrWhiteSpace(opt.Link))
|
|||
|
|
{
|
|||
|
|
var links = opt.Link.Split(";");
|
|||
|
|
foreach (var ink in links)
|
|||
|
|
{
|
|||
|
|
parse.IncludeFolders.Add(ink);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return parse;
|
|||
|
|
}
|
|||
|
|
public static int CMD_CheckBuildOption(CmdBuildOption opt)
|
|||
|
|
{
|
|||
|
|
var parse_opt = MakeParserOptions(opt);
|
|||
|
|
var compilation = CppAst.CppParser.ParseFiles(opt.InputFiles.Skip(1).ToList(), parse_opt);
|
|||
|
|
// Print diagnostic messages
|
|||
|
|
foreach (var message in compilation.Diagnostics.Messages)
|
|||
|
|
if(message.Type.Equals(CppLogMessageType.Error))
|
|||
|
|
Console.WriteLine(message);
|
|||
|
|
|
|||
|
|
// Print all enums
|
|||
|
|
foreach (var cppEnum in compilation.Enums)
|
|||
|
|
Console.WriteLine(cppEnum);
|
|||
|
|
|
|||
|
|
// Print all functions
|
|||
|
|
foreach (var cppFunction in compilation.Functions)
|
|||
|
|
Console.WriteLine(cppFunction);
|
|||
|
|
|
|||
|
|
// Print all classes, structs
|
|||
|
|
foreach (var cppClass in compilation.Classes)
|
|||
|
|
Console.WriteLine(cppClass);
|
|||
|
|
|
|||
|
|
// Print all typedefs
|
|||
|
|
foreach (var cppTypedef in compilation.Typedefs)
|
|||
|
|
Console.WriteLine(cppTypedef);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|