/// <exception cref="ArgumentNullException">Schema cannot be null.</exception> /// <exception cref="NotSupportedException">Schema does not support code generation.</exception> /// <exception cref="SchemaException">Schema validation failed.</exception> public HppGenerator(T cppSchema, out List <String> warnings) { if (cppSchema is null) { throw new ArgumentNullException(nameof(cppSchema)); } cppSchema.Invalidate(this.ReservedNames, out warnings); this.validatedSchema = cppSchema; this.definitionBuilders = new List <CodeBuilder>(); foreach (var x in cppSchema.Definitions) { var generator = HppGeneratorFactory.MakeGenerator(x, out var moreWarnings); this.definitionBuilders.AddRange(generator.Make()); warnings.AddRange(moreWarnings); } // foreach (...) } // HppGenerator(...)
static Int32 Main(String[] args) { if (args is null || args.Length == 0) { Console.WriteLine("Path to schema or containing folder missing."); return(1); } // if (...) #if RELEASE try { #endif var jsonSchemaPaths = Program.Unpack(args); if (jsonSchemaPaths is null) { return(2); } var jsonSchemaTexts = Program.Read(jsonSchemaPaths); if (jsonSchemaTexts is null) { return(3); } var hppPaths = new List <String>(jsonSchemaTexts.Length); var hppCodes = new List <String>(jsonSchemaTexts.Length); for (var i = 0; i < jsonSchemaTexts.Length; ++i) { var text = jsonSchemaTexts[i]; var jsonSchema = JsonSchema.Parse(text); jsonSchema.SchemaFileName = System.IO.Path.GetFileName(jsonSchemaPaths[i]); if (jsonSchema.HppTargetPath is null) { System.Console.WriteLine($"Skipping {jsonSchema.SchemaFileName}: target path is null."); continue; } // if (...) if (jsonSchema.HasFlag(HppGeneratorOptions.Ignore)) { System.Console.WriteLine($"Skipping {jsonSchema.SchemaFileName}: ignore flag encountered."); continue; } // if (...) var cppSchema = jsonSchema.ToCppType(); if (!cppSchema.DoesSupportCodeGeneration) { System.Console.WriteLine($"Skipping {jsonSchema.SchemaFileName}: code generation are supported."); continue; } // if (...) System.Console.Write($"Parsing {jsonSchema.SchemaFileName}..."); var generator = HppGeneratorFactory.MakeGenerator(cppSchema, out var warnings); var code = generator.ToString(); if (code is null) { throw new ApplicationException(); // Should never happen. } if (warnings.Count == 0) { System.Console.WriteLine(" succeded."); } else { System.Console.WriteLine(" succeded with the following warnings:"); foreach (var x in warnings) { System.Console.Write("-- "); System.Console.WriteLine(x); } // foreach (...) } // if (...) hppPaths.Add(System.IO.Path.Combine( System.IO.Path.GetDirectoryName(jsonSchemaPaths[i]), jsonSchema.HppTargetPath)); hppCodes.Add(code); } // foreach (...) if (!Program.TryWrite(hppPaths, hppCodes)) { return(4); } #if RELEASE } // try catch (Exception ex) { System.Console.WriteLine(ex); return(1729); } // catch (...) #endif return(0); } // Main(...)