aboutsummaryrefslogtreecommitdiff
path: root/src/zig_clang.cpp
diff options
context:
space:
mode:
authorEvan Haas <evan@lagerdata.com>2021-05-18 21:59:45 -0700
committerVeikka Tuominen <git@vexu.eu>2021-05-19 12:12:18 +0300
commit1273bc277f7274683db5041d8b41d91903e3045e (patch)
tree11735aca89cbdb87ad30410763271ecfee8d902c /src/zig_clang.cpp
parent28a89b9ebc471fa65815c8061dce979d25f3e499 (diff)
downloadzig-1273bc277f7274683db5041d8b41d91903e3045e.tar.gz
zig-1273bc277f7274683db5041d8b41d91903e3045e.zip
translate-c: add support for __cleanup__ attribute
Use a `defer` statement to implement the C __cleanup__ attribute. See https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
Diffstat (limited to 'src/zig_clang.cpp')
-rw-r--r--src/zig_clang.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/zig_clang.cpp b/src/zig_clang.cpp
index bf6e09d8c0..de29c3cda7 100644
--- a/src/zig_clang.cpp
+++ b/src/zig_clang.cpp
@@ -1784,6 +1784,14 @@ unsigned ZigClangVarDecl_getAlignedAttribute(const struct ZigClangVarDecl *self,
return 0;
}
+const struct ZigClangFunctionDecl *ZigClangVarDecl_getCleanupAttribute(const struct ZigClangVarDecl *self) {
+ auto casted_self = reinterpret_cast<const clang::VarDecl *>(self);
+ if (const clang::CleanupAttr *CA = casted_self->getAttr<clang::CleanupAttr>()) {
+ return reinterpret_cast<const ZigClangFunctionDecl *>(CA->getFunctionDecl());
+ }
+ return nullptr;
+}
+
unsigned ZigClangFieldDecl_getAlignedAttribute(const struct ZigClangFieldDecl *self, const ZigClangASTContext* ctx) {
auto casted_self = reinterpret_cast<const clang::FieldDecl *>(self);
auto casted_ctx = const_cast<clang::ASTContext *>(reinterpret_cast<const clang::ASTContext *>(ctx));