2024-04-18 22:17:22 +08:00
|
|
|
|
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.")]
|
2024-04-21 21:44:53 +08:00
|
|
|
|
public IEnumerable<string>? InputFiles { get; set; }
|
2024-04-18 22:17:22 +08:00
|
|
|
|
|
|
|
|
|
|
[Option('o', "output", Required = false, HelpText = "Output file for generated code.")]
|
2024-04-21 21:44:53 +08:00
|
|
|
|
public string OutputFile { get; set; } = "";
|
2024-04-18 22:17:22 +08:00
|
|
|
|
|
|
|
|
|
|
[Option('t', "type", Required = false, HelpText = "Type of code to generate.")]
|
2024-04-21 21:44:53 +08:00
|
|
|
|
public string CodeType { get; set; } = "";
|
2024-04-18 22:17:22 +08:00
|
|
|
|
|
|
|
|
|
|
[Option('l', "link", Required = false, HelpText = "link to the include dir")]
|
2024-04-21 21:44:53 +08:00
|
|
|
|
public string Link { get; set; } = "";
|
2024-04-18 22:17:22 +08:00
|
|
|
|
|
|
|
|
|
|
[Option('d', "define", Required = false, HelpText = "define a macro on the command line")]
|
2024-04-21 21:44:53 +08:00
|
|
|
|
public string Define { get; set; } = "";
|
2024-04-18 22:17:22 +08:00
|
|
|
|
|
|
|
|
|
|
[Option('h', "help", HelpText = "Display this help message.")]
|
2024-04-21 21:44:53 +08:00
|
|
|
|
public bool Help { get; set; } = false;
|
2024-04-18 22:17:22 +08:00
|
|
|
|
|
|
|
|
|
|
static CppParserOptions MakeParserOptions(CmdBuildOption opt)
|
|
|
|
|
|
{
|
|
|
|
|
|
var parse = new CppParserOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
AdditionalArguments = { "-std=c++20" },
|
2024-04-19 22:23:40 +08:00
|
|
|
|
//ParseTokenAttributes = true,
|
|
|
|
|
|
//ParseCommentAttribute = true,
|
2024-04-18 22:17:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2024-04-21 21:44:53 +08:00
|
|
|
|
if(opt.InputFiles == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-04-18 22:17:22 +08:00
|
|
|
|
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);
|
2024-04-21 21:44:53 +08:00
|
|
|
|
var module = ModuleMeta.ParseCompileInfo(compilation);
|
|
|
|
|
|
ClassMetaGen.GenNameMeta();
|
|
|
|
|
|
ClassMetaGen.GenCppMeta(module);
|
2024-04-18 22:17:22 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|