translate-c-2 bug fixes

- fix use of undefined value
- fix parenexprclass result not being suppressed
- add an error and a TODO for access of an anonymous field
master
Vexu 2019-12-29 18:37:00 +02:00
parent 621629e20d
commit 55348c9b93
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 7 additions and 4 deletions

View File

@ -95,7 +95,7 @@ export fn stage2_translate_c(
args_end: [*]?[*]const u8, args_end: [*]?[*]const u8,
resources_path: [*:0]const u8, resources_path: [*:0]const u8,
) Error { ) Error {
var errors: []translate_c.ClangErrMsg = undefined; var errors = @as([*]translate_c.ClangErrMsg, undefined)[0..0];
out_ast.* = translate_c.translate(std.heap.c_allocator, args_begin, args_end, &errors, resources_path) catch |err| switch (err) { out_ast.* = translate_c.translate(std.heap.c_allocator, args_begin, args_end, &errors, resources_path) catch |err| switch (err) {
error.SemanticAnalyzeFail => { error.SemanticAnalyzeFail => {
out_errors_ptr.* = errors.ptr; out_errors_ptr.* = errors.ptr;

View File

@ -853,15 +853,15 @@ fn transStmt(
.ReturnStmtClass => return transReturnStmt(rp, scope, @ptrCast(*const ZigClangReturnStmt, stmt)), .ReturnStmtClass => return transReturnStmt(rp, scope, @ptrCast(*const ZigClangReturnStmt, stmt)),
.StringLiteralClass => return transStringLiteral(rp, scope, @ptrCast(*const ZigClangStringLiteral, stmt), result_used), .StringLiteralClass => return transStringLiteral(rp, scope, @ptrCast(*const ZigClangStringLiteral, stmt), result_used),
.ParenExprClass => { .ParenExprClass => {
const expr = try transExpr(rp, scope, ZigClangParenExpr_getSubExpr(@ptrCast(*const ZigClangParenExpr, stmt)), result_used, lrvalue); const expr = try transExpr(rp, scope, ZigClangParenExpr_getSubExpr(@ptrCast(*const ZigClangParenExpr, stmt)), .used, lrvalue);
if (expr.id == .GroupedExpression) return expr; if (expr.id == .GroupedExpression) return maybeSuppressResult(rp, scope, result_used, expr);
const node = try rp.c.a().create(ast.Node.GroupedExpression); const node = try rp.c.a().create(ast.Node.GroupedExpression);
node.* = .{ node.* = .{
.lparen = try appendToken(rp.c, .LParen, "("), .lparen = try appendToken(rp.c, .LParen, "("),
.expr = expr, .expr = expr,
.rparen = try appendToken(rp.c, .RParen, ")"), .rparen = try appendToken(rp.c, .RParen, ")"),
}; };
return &node.base; return maybeSuppressResult(rp, scope, result_used, &node.base);
}, },
.InitListExprClass => return transInitListExpr(rp, scope, @ptrCast(*const ZigClangInitListExpr, stmt), result_used), .InitListExprClass => return transInitListExpr(rp, scope, @ptrCast(*const ZigClangInitListExpr, stmt), result_used),
.ImplicitValueInitExprClass => return transImplicitValueInitExpr(rp, scope, @ptrCast(*const ZigClangExpr, stmt), result_used), .ImplicitValueInitExprClass => return transImplicitValueInitExpr(rp, scope, @ptrCast(*const ZigClangExpr, stmt), result_used),
@ -2098,6 +2098,9 @@ fn transMemberExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangMemberE
} }
const name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, ZigClangMemberExpr_getMemberDecl(stmt)))); const name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, ZigClangMemberExpr_getMemberDecl(stmt))));
if (name.len == 0) {
return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO access of anonymous field", .{});
}
const node = try transCreateNodeFieldAccess(rp.c, container_node, name); const node = try transCreateNodeFieldAccess(rp.c, container_node, name);
return maybeSuppressResult(rp, scope, result_used, node); return maybeSuppressResult(rp, scope, result_used, node);
} }