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...@@ -832,6 +832,8 @@ pub extern fn ZigClangFunctionDecl_hasBody(self: *const ZigClangFunctionDecl) bo
832pub extern fn ZigClangFunctionDecl_getStorageClass(self: *const ZigClangFunctionDecl) ZigClangStorageClass;832pub extern fn ZigClangFunctionDecl_getStorageClass(self: *const ZigClangFunctionDecl) ZigClangStorageClass;
833pub extern fn ZigClangFunctionDecl_getParamDecl(self: *const ZigClangFunctionDecl, i: c_uint) *const struct_ZigClangParmVarDecl;833pub extern fn ZigClangFunctionDecl_getParamDecl(self: *const ZigClangFunctionDecl, i: c_uint) *const struct_ZigClangParmVarDecl;
834pub extern fn ZigClangFunctionDecl_getBody(self: *const ZigClangFunctionDecl) *const struct_ZigClangStmt;834pub 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
836pub extern fn ZigClangBuiltinType_getKind(self: *const struct_ZigClangBuiltinType) ZigClangBuiltinTypeKind;838pub 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 {...@@ -423,7 +423,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
423 .has_body = has_body,423 .has_body = has_body,
424 .storage_class = storage_class,424 .storage_class = storage_class,
425 .is_export = switch (storage_class) {425 .is_export = switch (storage_class) {
426 .None => has_body,426 .None => has_body and !ZigClangFunctionDecl_isInlineSpecified(fn_decl),
427 .Extern, .Static => false,427 .Extern, .Static => false,
428 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),428 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),
429 .Auto => unreachable, // Not legal on functions429 .Auto => unreachable, // Not legal on functions
src/zig_clang.cpp+10
...@@ -1686,6 +1686,16 @@ const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFun...@@ -1686,6 +1686,16 @@ const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFun
1686 return reinterpret_cast<const ZigClangStmt *>(stmt);1686 return reinterpret_cast<const ZigClangStmt *>(stmt);
1687}1687}
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
1689const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *self) {1699const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *self) {
1690 auto casted = reinterpret_cast<const clang::TypedefType *>(self);1700 auto casted = reinterpret_cast<const clang::TypedefType *>(self);
1691 const clang::TypedefNameDecl *name_decl = casted->getDecl();1701 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...@@ -873,6 +873,8 @@ ZIG_EXTERN_C bool ZigClangFunctionDecl_hasBody(const struct ZigClangFunctionDecl
873ZIG_EXTERN_C enum ZigClangStorageClass ZigClangFunctionDecl_getStorageClass(const struct ZigClangFunctionDecl *);873ZIG_EXTERN_C enum ZigClangStorageClass ZigClangFunctionDecl_getStorageClass(const struct ZigClangFunctionDecl *);
874ZIG_EXTERN_C const struct ZigClangParmVarDecl *ZigClangFunctionDecl_getParamDecl(const struct ZigClangFunctionDecl *, unsigned i);874ZIG_EXTERN_C const struct ZigClangParmVarDecl *ZigClangFunctionDecl_getParamDecl(const struct ZigClangFunctionDecl *, unsigned i);
875ZIG_EXTERN_C const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFunctionDecl *);875ZIG_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
877ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl);879ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl);
878ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const struct ZigClangRecordDecl *record_decl);880ZIG_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 {...@@ -2302,4 +2302,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2302 ,2302 ,
2303 \\pub const bar = 4;2303 \\pub const bar = 4;
2304 });2304 });
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 });
2305}2315}