| ... | @@ -111,7 +111,7 @@ pub fn nameForType(T: type) []const u8 { | ... | @@ -111,7 +111,7 @@ pub fn nameForType(T: type) []const u8 { |
| 111 | if (@typeInfo(T) == .optional) { | 111 | if (@typeInfo(T) == .optional) { |
| 112 | return nameForType2(@typeInfo(T).optional.child); | 112 | return nameForType2(@typeInfo(T).optional.child); |
| 113 | } | 113 | } |
| 114 | return nameForType2(T) ++ " not null"; | 114 | return nameForType2(T) ++ " not null default (" ++ defaultForType(T) ++ ")"; |
| 115 | } | 115 | } |
| 116 | | 116 | |
| 117 | pub fn nameForType2(T: type) []const u8 { | 117 | pub fn nameForType2(T: type) []const u8 { |
| ... | @@ -137,6 +137,28 @@ pub fn nameForType2(T: type) []const u8 { | ... | @@ -137,6 +137,28 @@ pub fn nameForType2(T: type) []const u8 { |
| 137 | @compileError(@typeName(T)); // TODO | 137 | @compileError(@typeName(T)); // TODO |
| 138 | } | 138 | } |
| 139 | | 139 | |
| | 140 | pub fn defaultForType(T: type) []const u8 { |
| | 141 | const info = @typeInfo(T); |
| | 142 | if (info == .bool) { |
| | 143 | return "false"; |
| | 144 | } |
| | 145 | if (info == .@"struct") { |
| | 146 | const sinfo = info.@"struct"; |
| | 147 | if (@hasDecl(T, "BaseType")) return defaultForType(T.BaseType); |
| | 148 | if (sinfo.layout == .@"packed") return defaultForType(sinfo.backing_integer.?); |
| | 149 | } |
| | 150 | if (comptime extras.isZigString(T)) { |
| | 151 | return "''"; |
| | 152 | } |
| | 153 | if (info == .int) { |
| | 154 | return "0"; |
| | 155 | } |
| | 156 | if (info == .@"enum") { |
| | 157 | return defaultForType(T.BaseType); |
| | 158 | } |
| | 159 | @compileError(@typeName(T)); // TODO |
| | 160 | } |
| | 161 | |
| 140 | pub const Pragma = struct { | 162 | pub const Pragma = struct { |
| 141 | pub const TableInfo = struct { | 163 | pub const TableInfo = struct { |
| 142 | cid: u16, | 164 | cid: u16, |