|
1 | | -using System.Text.Json; |
2 | | -using System.Text.Json.Serialization; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
3 | 5 | using System.Text.RegularExpressions; |
4 | 6 |
|
5 | | -namespace HeaderParser; |
6 | | - |
7 | | -class Program |
8 | | -{ |
9 | | - static int Main(string[] args) |
10 | | - { |
11 | | - if (args.Length < 2) |
12 | | - { |
13 | | - Console.Error.WriteLine("Usage: HeaderParser <include-dir> <output-json>"); |
14 | | - Console.Error.WriteLine("Example: HeaderParser secp256k1/include Secp256k1.Net/Generated/secp256k1-api.json"); |
15 | | - return 1; |
16 | | - } |
17 | | - |
18 | | - var includeDir = args[0]; |
19 | | - var outputPath = args[1]; |
20 | | - |
21 | | - if (!Directory.Exists(includeDir)) |
22 | | - { |
23 | | - Console.Error.WriteLine($"Error: Include directory not found: {includeDir}"); |
24 | | - return 1; |
25 | | - } |
26 | | - |
27 | | - var parser = new Secp256k1HeaderParser(); |
28 | | - var api = parser.ParseDirectory(includeDir); |
29 | | - |
30 | | - var options = new JsonSerializerOptions |
31 | | - { |
32 | | - WriteIndented = true, |
33 | | - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, |
34 | | - PropertyNamingPolicy = JsonNamingPolicy.CamelCase |
35 | | - }; |
36 | | - |
37 | | - var json = JsonSerializer.Serialize(api, options); |
38 | | - |
39 | | - var outputDir = Path.GetDirectoryName(outputPath); |
40 | | - if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir)) |
41 | | - { |
42 | | - Directory.CreateDirectory(outputDir); |
43 | | - } |
44 | | - |
45 | | - File.WriteAllText(outputPath, json); |
46 | | - |
47 | | - Console.WriteLine($"Generated {outputPath}"); |
48 | | - Console.WriteLine($" Functions: {api.Functions.Count}"); |
49 | | - Console.WriteLine($" Structs: {api.Structs.Count}"); |
50 | | - Console.WriteLine($" Function pointer types: {api.FunctionPointerTypes.Count}"); |
51 | | - Console.WriteLine($" Constants: {api.Constants.Count}"); |
52 | | - Console.WriteLine($" Global pointers: {api.GlobalPointers.Count}"); |
53 | | - |
54 | | - return 0; |
55 | | - } |
56 | | -} |
57 | | - |
58 | | -public class Secp256k1Api |
59 | | -{ |
60 | | - public string Version { get; set; } = "0.7.0"; |
61 | | - public string GeneratedAt { get; set; } = DateTime.UtcNow.ToString("O"); |
62 | | - public List<string> Headers { get; set; } = new(); |
63 | | - public List<StructDef> Structs { get; set; } = new(); |
64 | | - public List<FunctionPointerType> FunctionPointerTypes { get; set; } = new(); |
65 | | - public List<FunctionDef> Functions { get; set; } = new(); |
66 | | - public List<ConstantDef> Constants { get; set; } = new(); |
67 | | - public List<GlobalPointer> GlobalPointers { get; set; } = new(); |
68 | | -} |
69 | | - |
70 | | -public class StructDef |
71 | | -{ |
72 | | - public string Name { get; set; } = ""; |
73 | | - public int Size { get; set; } |
74 | | - public string? Description { get; set; } |
75 | | -} |
76 | | - |
77 | | -public class FunctionPointerType |
78 | | -{ |
79 | | - public string Name { get; set; } = ""; |
80 | | - public string ReturnType { get; set; } = ""; |
81 | | - public List<ParameterDef> Parameters { get; set; } = new(); |
82 | | - public string? Description { get; set; } |
83 | | -} |
84 | | - |
85 | | -public class FunctionDef |
86 | | -{ |
87 | | - public string Name { get; set; } = ""; |
88 | | - public string ReturnType { get; set; } = ""; |
89 | | - public bool WarnUnusedResult { get; set; } |
90 | | - public bool Deprecated { get; set; } |
91 | | - public string? DeprecatedMessage { get; set; } |
92 | | - public List<ParameterDef> Parameters { get; set; } = new(); |
93 | | - public string? Description { get; set; } |
94 | | - public string? ReturnDescription { get; set; } |
95 | | - public string? SourceHeader { get; set; } |
96 | | -} |
97 | | - |
98 | | -public class ParameterDef |
99 | | -{ |
100 | | - public string Name { get; set; } = ""; |
101 | | - public string Type { get; set; } = ""; |
102 | | - public string? Direction { get; set; } |
103 | | - public bool Nonnull { get; set; } |
104 | | - public string? Description { get; set; } |
105 | | -} |
106 | | - |
107 | | -public class ConstantDef |
108 | | -{ |
109 | | - public string Name { get; set; } = ""; |
110 | | - public string Value { get; set; } = ""; |
111 | | - public long? NumericValue { get; set; } |
112 | | - public string? Description { get; set; } |
113 | | -} |
114 | | - |
115 | | -public class GlobalPointer |
116 | | -{ |
117 | | - public string Name { get; set; } = ""; |
118 | | - public string Type { get; set; } = ""; |
119 | | - public bool IsConst { get; set; } |
120 | | - public string? Description { get; set; } |
121 | | -} |
| 7 | +namespace Secp256k1Net.InteropGen; |
122 | 8 |
|
123 | 9 | public partial class Secp256k1HeaderParser |
124 | 10 | { |
|
0 commit comments