private CppModule ParseCpp(CastXml castXml, CppModule group) { // Run the parser var parser = new CppParser(Logger, castXml) { OutputPath = IntermediateOutputPath }; parser.Initialize(Config); if (Logger.HasErrors) { Logger.Fatal("Initializing parser failed"); } // Run the parser group = parser.Run(group); if (Logger.HasErrors) { Logger.Fatal("Parsing C++ failed."); } else { Logger.Message("Parsing C++ finished"); } // Print statistics PrintStatistics(parser); return(group); }
static void Main(string[] args) { var consoleLogger = new ConsoleLogger(); var logger = new Logger(consoleLogger, consoleLogger); string executablePath = null; // if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // executablePath = Path.GetFullPath("../../../../../bin/CastXML/bin/castxml.exe"); var castXml = new CastXml(logger, new IncludeDirectoryResolver(logger), executablePath); var cppParser = new CppParser(logger, castXml); var config = new ContextConfig() { Id = Path.GetFullPath("test.c"), Process = new string[] { Path.GetFullPath("test.c"), // Path.GetFullPath("test.h"), }.ToList(), Include = new string[] { Path.GetFullPath("test.h"), }.ToList(), Macros = new Dictionary <string, string>() { { "ARRSIZE", "42 * 3" } } }; cppParser.Initialize(config); var module = cppParser.Run(new CppModel.CppModule()); foreach (var inc in module.Includes) { Console.WriteLine(inc.Name); foreach (var struct_ in inc.Structs) { Console.WriteLine(" " + struct_.Name + " " + struct_.Size); foreach (var field in struct_.Fields) { Console.WriteLine(" " + field.Name + " " + field.Offset); } } } Console.WriteLine(JsonConvert.SerializeObject(module, Formatting.Indented, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, TypeNameHandling = TypeNameHandling.All })); foreach (var f in typeof(CastXml).Assembly.GetManifestResourceNames()) { Console.WriteLine(f); } Console.WriteLine(module); Environment.Exit(module is null ? 1 : 0); }
/// <summary> /// Run CodeGenerator /// </summary> public void Run() { log.Info("Starting code generation..."); // Initialize the parser CppParser parser = new CppParser(CastXmlExecutablePath, VcToolsPath); parser.ForceParsing = configHasChanged || forceParsing; parser.Initialize(config); // Run the parser CppModule mainModule = parser.Run(); // Run the code generation process NodeJSGenerator generator = new NodeJSGenerator(config, new DriverOptions(), mainModule); // Setup rules and process code generator.SetupPasses(); generator.ProcessCode(); // Generate wrapper code List <GeneratorOutput> outputs = generator.GenerateCode(); SaveCode(outputs); }
protected CppModule ParseCpp(ConfigFile config, string[] additionalArguments = null) { var loaded = ConfigFile.Load(config, new string[0], Logger); var(filesWithIncludes, filesWithExtensionHeaders) = loaded.GetFilesWithIncludesAndExtensionHeaders(); var configsWithIncludes = new HashSet <ConfigFile>(); foreach (var cfg in loaded.ConfigFilesLoaded) { if (filesWithIncludes.Contains(cfg.Id)) { configsWithIncludes.Add(cfg); } } var cppHeaderGenerator = new CppHeaderGenerator(Logger, true, TestDirectory.FullName); var(updated, _) = cppHeaderGenerator.GenerateCppHeaders(loaded, configsWithIncludes, filesWithExtensionHeaders); var castXml = GetCastXml(loaded); var extensionGenerator = new CppExtensionHeaderGenerator(new MacroManager(castXml)); var skeleton = extensionGenerator.GenerateExtensionHeaders(loaded, TestDirectory.FullName, filesWithExtensionHeaders, updated); var parser = new CppParser(Logger, castXml) { OutputPath = TestDirectory.FullName }; parser.Initialize(loaded); return(parser.Run(skeleton)); }
protected override bool Execute(ConfigFile config) { var resolver = new IncludeDirectoryResolver(SharpGenLogger); resolver.Configure(config); var castXml = new CastXml(SharpGenLogger, resolver, CastXmlExecutablePath) { OutputPath = OutputPath }; // Run the parser var parser = new CppParser(SharpGenLogger, castXml) { OutputPath = OutputPath }; parser.Initialize(config); if (SharpGenLogger.HasErrors) { return(false); } var module = CppModule.Read(PartialCppModuleCache.ItemSpec); // Run the parser var group = parser.Run(module, CastXmlArguments ?? Array.Empty <string>()); if (SharpGenLogger.HasErrors) { return(false); } group.Write(ParsedCppModule.ItemSpec); return(true); }