authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-14 19:23:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-14 19:23:31-04:00
log5a57610039b6150557b159fe9a8eb30088455dba
tree0d4f0c5c55554dacd1521bc64fbdfa2b366a0955
parente93a05b6e4a6e66012a24d61d7653e7002e62196
signaturelock-open Commit is signed but in an unrecognized format.

clean up code now that #769 is implemented


3 files changed, 11 insertions(+), 22 deletions(-)

src-self-hosted/stage1.zig+1-2
...@@ -90,8 +90,7 @@ export fn stage2_translate_c(...@@ -90,8 +90,7 @@ export fn stage2_translate_c(
90 .import => translate_c.Mode.import,90 .import => translate_c.Mode.import,
91 .translate => translate_c.Mode.translate,91 .translate => translate_c.Mode.translate,
92 }, &errors, resources_path) catch |err| switch (err) {92 }, &errors, resources_path) catch |err| switch (err) {
93 // TODO after https://github.com/ziglang/zig/issues/769 we can remove error.UnsupportedType93 error.SemanticAnalyzeFail => {
94 error.SemanticAnalyzeFail, error.UnsupportedType => {
95 out_errors_ptr.* = errors.ptr;94 out_errors_ptr.* = errors.ptr;
96 out_errors_len.* = errors.len;95 out_errors_len.* = errors.len;
97 return Error.CCompileErrors;96 return Error.CCompileErrors;
src-self-hosted/translate_c.zig+9-14
...@@ -18,14 +18,9 @@ const CallingConvention = builtin.TypeInfo.CallingConvention;...@@ -18,14 +18,9 @@ const CallingConvention = builtin.TypeInfo.CallingConvention;
1818
19pub const ClangErrMsg = Stage2ErrorMsg;19pub const ClangErrMsg = Stage2ErrorMsg;
2020
21pub const Error = error{21pub const Error = error{OutOfMemory};
22 OutOfMemory,22const TypeError = Error || error{UnsupportedType};
23 UnsupportedType,23const TransError = Error || error{UnsupportedTranslation};
24};
25pub const TransError = error{
26 OutOfMemory,
27 UnsupportedTranslation,
28};
2924
30const DeclTable = std.HashMap(usize, void, addrHash, addrEql);25const DeclTable = std.HashMap(usize, void, addrHash, addrEql);
3126
...@@ -276,7 +271,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -276,7 +271,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
276 error.UnsupportedType => {271 error.UnsupportedType => {
277 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");272 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");
278 },273 },
279 error.OutOfMemory => return error.OutOfMemory,274 error.OutOfMemory => |e| return e,
280 };275 };
281 },276 },
282 .FunctionNoProto => blk: {277 .FunctionNoProto => blk: {
...@@ -285,7 +280,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -285,7 +280,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
285 error.UnsupportedType => {280 error.UnsupportedType => {
286 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");281 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");
287 },282 },
288 error.OutOfMemory => return error.OutOfMemory,283 error.OutOfMemory => |e| return e,
289 };284 };
290 },285 },
291 else => unreachable,286 else => unreachable,
...@@ -299,7 +294,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -299,7 +294,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
299 // actual function definition with body294 // actual function definition with body
300 const body_stmt = ZigClangFunctionDecl_getBody(fn_decl);295 const body_stmt = ZigClangFunctionDecl_getBody(fn_decl);
301 const result = transStmt(rp, scope, body_stmt, .unused, .r_value) catch |err| switch (err) {296 const result = transStmt(rp, scope, body_stmt, .unused, .r_value) catch |err| switch (err) {
302 error.OutOfMemory => return error.OutOfMemory,297 error.OutOfMemory => |e| return e,
303 error.UnsupportedTranslation => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function"),298 error.UnsupportedTranslation => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function"),
304 };299 };
305 assert(result.node.id == ast.Node.Id.Block);300 assert(result.node.id == ast.Node.Id.Block);
...@@ -377,7 +372,7 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: *ast.Node) !void {...@@ -377,7 +372,7 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: *ast.Node) !void {
377 try c.tree.root_node.decls.push(decl_node);372 try c.tree.root_node.decls.push(decl_node);
378}373}
379374
380fn transQualType(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigClangSourceLocation) Error!*ast.Node {375fn transQualType(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigClangSourceLocation) TypeError!*ast.Node {
381 return transType(rp, ZigClangQualType_getTypePtr(qt), source_loc);376 return transType(rp, ZigClangQualType_getTypePtr(qt), source_loc);
382}377}
383378
...@@ -405,7 +400,7 @@ fn makeRestorePoint(c: *Context) RestorePoint {...@@ -405,7 +400,7 @@ fn makeRestorePoint(c: *Context) RestorePoint {
405 };400 };
406}401}
407402
408fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSourceLocation) Error!*ast.Node {403fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSourceLocation) TypeError!*ast.Node {
409 switch (ZigClangType_getTypeClass(ty)) {404 switch (ZigClangType_getTypeClass(ty)) {
410 .Builtin => {405 .Builtin => {
411 const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty);406 const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty);
...@@ -535,7 +530,7 @@ fn finishTransFnProto(...@@ -535,7 +530,7 @@ fn finishTransFnProto(
535 try emitWarning(rp.c, source_loc, "unsupported function proto return type");530 try emitWarning(rp.c, source_loc, "unsupported function proto return type");
536 return err;531 return err;
537 },532 },
538 error.OutOfMemory => return error.OutOfMemory,533 error.OutOfMemory => |e| return e,
539 };534 };
540 }535 }
541 }536 }
std/event/fs.zig+1-6
...@@ -961,12 +961,7 @@ pub fn Watch(comptime V: type) type {...@@ -961,12 +961,7 @@ pub fn Watch(comptime V: type) type {
961 } else |err| switch (err) {961 } else |err| switch (err) {
962 error.EventNotFound => unreachable,962 error.EventNotFound => unreachable,
963 error.ProcessNotFound => unreachable,963 error.ProcessNotFound => unreachable,
964 error.AccessDenied, error.SystemResources => {964 error.AccessDenied, error.SystemResources => |casted_err| {
965 // TODO https://github.com/ziglang/zig/issues/769
966 const casted_err = @errSetCast(error{
967 AccessDenied,
968 SystemResources,
969 }, err);
970 await (async self.channel.put(casted_err) catch unreachable);965 await (async self.channel.put(casted_err) catch unreachable);
971 },966 },
972 }967 }