Integrate callconv into translate-c-2
This commit is contained in:
parent
271fc6a247
commit
0ec64d4c0c
@ -1377,14 +1377,14 @@ fn renderExpression(
|
||||
}
|
||||
|
||||
if (fn_proto.callconv_expr) |callconv_expr| {
|
||||
const section_rparen = tree.nextToken(callconv_expr.lastToken());
|
||||
const section_lparen = tree.prevToken(callconv_expr.firstToken());
|
||||
const section_kw = tree.prevToken(section_lparen);
|
||||
const callconv_rparen = tree.nextToken(callconv_expr.lastToken());
|
||||
const callconv_lparen = tree.prevToken(callconv_expr.firstToken());
|
||||
const callconv_kw = tree.prevToken(callconv_lparen);
|
||||
|
||||
try renderToken(tree, stream, section_kw, indent, start_col, Space.None); // section
|
||||
try renderToken(tree, stream, section_lparen, indent, start_col, Space.None); // (
|
||||
try renderToken(tree, stream, callconv_kw, indent, start_col, Space.None); // section
|
||||
try renderToken(tree, stream, callconv_lparen, indent, start_col, Space.None); // (
|
||||
try renderExpression(allocator, stream, tree, indent, start_col, callconv_expr, Space.None);
|
||||
try renderToken(tree, stream, section_rparen, indent, start_col, Space.Space); // )
|
||||
try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // )
|
||||
} else if (cc_rewrite_str) |str| {
|
||||
try stream.write("callconv(");
|
||||
try stream.write(mem.toSliceConst(u8, str));
|
||||
|
@ -3973,6 +3973,10 @@ fn transCC(
|
||||
switch (clang_cc) {
|
||||
.C => return CallingConvention.C,
|
||||
.X86StdCall => return CallingConvention.Stdcall,
|
||||
.X86FastCall => return CallingConvention.Fastcall,
|
||||
.X86VectorCall, .AArch64VectorCall => return CallingConvention.Vectorcall,
|
||||
.AAPCS => return CallingConvention.AAPCS,
|
||||
.AAPCS_VFP => return CallingConvention.AAPCSVFP,
|
||||
else => return revertAndWarn(
|
||||
rp,
|
||||
error.UnsupportedType,
|
||||
@ -4028,7 +4032,6 @@ fn finishTransFnProto(
|
||||
|
||||
// pub extern fn name(...) T
|
||||
const pub_tok = if (is_pub) try appendToken(rp.c, .Keyword_pub, "pub") else null;
|
||||
const cc_tok = if (cc == .Stdcall) try appendToken(rp.c, .Keyword_stdcallcc, "stdcallcc") else null;
|
||||
const extern_export_inline_tok = if (is_export)
|
||||
try appendToken(rp.c, .Keyword_export, "export")
|
||||
else if (cc == .C and is_extern)
|
||||
@ -4101,6 +4104,14 @@ fn finishTransFnProto(
|
||||
|
||||
const rparen_tok = try appendToken(rp.c, .RParen, ")");
|
||||
|
||||
const callconv_expr = if (cc == .C and is_extern) null else blk: {
|
||||
_ = try appendToken(rp.c, .Keyword_callconv, "callconv");
|
||||
_ = try appendToken(rp.c, .LParen, "(");
|
||||
const expr = try transCreateNodeEnumLiteral(rp.c, @tagName(cc));
|
||||
_ = try appendToken(rp.c, .RParen, ")");
|
||||
break :blk expr;
|
||||
};
|
||||
|
||||
const return_type_node = blk: {
|
||||
if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) {
|
||||
break :blk try transCreateNodeIdentifier(rp.c, "noreturn");
|
||||
@ -4131,12 +4142,12 @@ fn finishTransFnProto(
|
||||
.return_type = .{ .Explicit = return_type_node },
|
||||
.var_args_token = null, // TODO this field is broken in the AST data model
|
||||
.extern_export_inline_token = extern_export_inline_tok,
|
||||
.cc_token = cc_tok,
|
||||
.cc_token = null,
|
||||
.body_node = null,
|
||||
.lib_name = null,
|
||||
.align_expr = null,
|
||||
.section_expr = null,
|
||||
.callconv_expr = null,
|
||||
.callconv_expr = callconv_expr,
|
||||
};
|
||||
return fn_proto;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user