authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-01 20:54:17-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-01 20:54:17-05:00
log88c5e2a96e09270a2ec3045639e7cab3712f5291
tree2027db8ab217cf5063719e1536dda49884c1621f
parent5ba143e7e3418719cc3c4acba9c9bfeea9803e57
signature Commit is signed but in an unrecognized format.

translate-c: don't export inline functions


5 files changed, 25 insertions(+), 1 deletions(-)

src-self-hosted/clang.zig+2
......@@ -832,6 +832,8 @@ pub extern fn ZigClangFunctionDecl_hasBody(self: *const ZigClangFunctionDecl) bo
832832pub extern fn ZigClangFunctionDecl_getStorageClass(self: *const ZigClangFunctionDecl) ZigClangStorageClass;
833833pub extern fn ZigClangFunctionDecl_getParamDecl(self: *const ZigClangFunctionDecl, i: c_uint) *const struct_ZigClangParmVarDecl;
834834pub extern fn ZigClangFunctionDecl_getBody(self: *const ZigClangFunctionDecl) *const struct_ZigClangStmt;
835pub extern fn ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(self: *const ZigClangFunctionDecl) bool;
836pub extern fn ZigClangFunctionDecl_isInlineSpecified(self: *const ZigClangFunctionDecl) bool;
835837
836838pub extern fn ZigClangBuiltinType_getKind(self: *const struct_ZigClangBuiltinType) ZigClangBuiltinTypeKind;
837839
src-self-hosted/translate_c.zig+1-1
......@@ -423,7 +423,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
423423 .has_body = has_body,
424424 .storage_class = storage_class,
425425 .is_export = switch (storage_class) {
426 .None => has_body,
426 .None => has_body and !ZigClangFunctionDecl_isInlineSpecified(fn_decl),
427427 .Extern, .Static => false,
428428 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),
429429 .Auto => unreachable, // Not legal on functions
src/zig_clang.cpp+10
......@@ -1686,6 +1686,16 @@ const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFun
16861686 return reinterpret_cast<const ZigClangStmt *>(stmt);
16871687}
16881688
1689bool ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(const struct ZigClangFunctionDecl *self) {
1690 auto casted = reinterpret_cast<const clang::FunctionDecl *>(self);
1691 return casted->doesDeclarationForceExternallyVisibleDefinition();
1692}
1693
1694bool ZigClangFunctionDecl_isInlineSpecified(const struct ZigClangFunctionDecl *self) {
1695 auto casted = reinterpret_cast<const clang::FunctionDecl *>(self);
1696 return casted->isInlineSpecified();
1697}
1698
16891699const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *self) {
16901700 auto casted = reinterpret_cast<const clang::TypedefType *>(self);
16911701 const clang::TypedefNameDecl *name_decl = casted->getDecl();
src/zig_clang.h+2
......@@ -873,6 +873,8 @@ ZIG_EXTERN_C bool ZigClangFunctionDecl_hasBody(const struct ZigClangFunctionDecl
873873ZIG_EXTERN_C enum ZigClangStorageClass ZigClangFunctionDecl_getStorageClass(const struct ZigClangFunctionDecl *);
874874ZIG_EXTERN_C const struct ZigClangParmVarDecl *ZigClangFunctionDecl_getParamDecl(const struct ZigClangFunctionDecl *, unsigned i);
875875ZIG_EXTERN_C const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFunctionDecl *);
876ZIG_EXTERN_C bool ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(const struct ZigClangFunctionDecl *);
877ZIG_EXTERN_C bool ZigClangFunctionDecl_isInlineSpecified(const struct ZigClangFunctionDecl *);
876878
877879ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl);
878880ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const struct ZigClangRecordDecl *record_decl);
test/translate_c.zig+10
......@@ -2302,4 +2302,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23022302 ,
23032303 \\pub const bar = 4;
23042304 });
2305
2306 cases.add("don't export inline functions",
2307 \\inline void a(void) {}
2308 \\static void b(void) {}
2309 \\void c(void) {}
2310 , &[_][]const u8{
2311 \\pub fn a() void {}
2312 \\pub fn b() void {}
2313 \\pub export fn c() void {}
2314 });
23052315}