Skip to content

Commit

Permalink
[c] Dictionary of dynamic collections.
Browse files Browse the repository at this point in the history
pfusik committed Jan 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0f3ab92 commit 64b90e2
Showing 4 changed files with 64 additions and 108 deletions.
40 changes: 14 additions & 26 deletions GenC.fu
Original file line number Diff line number Diff line change
@@ -782,34 +782,22 @@ public class GenC : GenCCpp
case FuArrayStorageType:
Write("free");
break;
case FuStorageType storage:
switch (storage.Class.Id) {
case FuId.ListClass:
case FuId.StackClass:
Write("(GDestroyNotify) g_array_unref");
break;
case FuId.HashSetClass:
case FuId.DictionaryClass:
Write("(GDestroyNotify) g_hash_table_unref");
break;
case FuId.SortedSetClass:
case FuId.SortedDictionaryClass:
Write("(GDestroyNotify) g_tree_unref");
break;
default:
if (NeedsDestructor(storage.Class)) {
Write("(GDestroyNotify) ");
WriteName(storage.Class);
Write("_Delete"); // TODO: emit
case FuOwningType owning:
if (owning.Class.Id == FuId.None) {
if (type is FuStorageType) {
if (NeedsDestructor(owning.Class)) {
Write("(GDestroyNotify) ");
WriteName(owning.Class);
Write("_Delete"); // TODO: emit
}
else
Write("free");
break;
}
else
Write("free");
break;
}
break;
case FuDynamicPtrType:
this.SharedRelease = true;
Write("FuShared_Release");
else
Write("(GDestroyNotify) ");
WriteDestructMethodName(owning);
break;
default:
Write("NULL");
42 changes: 16 additions & 26 deletions libfut.cpp
Original file line number Diff line number Diff line change
@@ -9666,35 +9666,25 @@ void GenC::writeDictionaryDestroy(const FuType * type)
{
if (dynamic_cast<const FuStringStorageType *>(type) || dynamic_cast<const FuArrayStorageType *>(type))
write("free");
else if (const FuStorageType *storage = dynamic_cast<const FuStorageType *>(type)) {
switch (storage->class_->id) {
case FuId::listClass:
case FuId::stackClass:
write("(GDestroyNotify) g_array_unref");
break;
case FuId::hashSetClass:
case FuId::dictionaryClass:
write("(GDestroyNotify) g_hash_table_unref");
break;
case FuId::sortedSetClass:
case FuId::sortedDictionaryClass:
write("(GDestroyNotify) g_tree_unref");
break;
default:
if (needsDestructor(storage->class_)) {
write("(GDestroyNotify) ");
writeName(storage->class_);
write("_Delete");
else if (const FuOwningType *owning = dynamic_cast<const FuOwningType *>(type))
do {
if (owning->class_->id == FuId::none) {
if (dynamic_cast<const FuStorageType *>(type)) {
if (needsDestructor(owning->class_)) {
write("(GDestroyNotify) ");
writeName(owning->class_);
write("_Delete");
}
else
write("free");
break;
}
}
else
write("free");
break;
write("(GDestroyNotify) ");
writeDestructMethodName(owning);
}
}
else if (dynamic_cast<const FuDynamicPtrType *>(type)) {
this->sharedRelease = true;
write("FuShared_Release");
}
while (false);
else
write("NULL");
}
40 changes: 14 additions & 26 deletions libfut.cs
Original file line number Diff line number Diff line change
@@ -9962,34 +9962,22 @@ void WriteDictionaryDestroy(FuType type)
case FuArrayStorageType:
Write("free");
break;
case FuStorageType storage:
switch (storage.Class.Id) {
case FuId.ListClass:
case FuId.StackClass:
Write("(GDestroyNotify) g_array_unref");
break;
case FuId.HashSetClass:
case FuId.DictionaryClass:
Write("(GDestroyNotify) g_hash_table_unref");
break;
case FuId.SortedSetClass:
case FuId.SortedDictionaryClass:
Write("(GDestroyNotify) g_tree_unref");
break;
default:
if (NeedsDestructor(storage.Class)) {
Write("(GDestroyNotify) ");
WriteName(storage.Class);
Write("_Delete");
case FuOwningType owning:
if (owning.Class.Id == FuId.None) {
if (type is FuStorageType) {
if (NeedsDestructor(owning.Class)) {
Write("(GDestroyNotify) ");
WriteName(owning.Class);
Write("_Delete");
}
else
Write("free");
break;
}
else
Write("free");
break;
}
break;
case FuDynamicPtrType:
this.SharedRelease = true;
Write("FuShared_Release");
else
Write("(GDestroyNotify) ");
WriteDestructMethodName(owning);
break;
default:
Write("NULL");
50 changes: 20 additions & 30 deletions libfut.js
Original file line number Diff line number Diff line change
@@ -10308,40 +10308,30 @@ export class GenC extends GenCCpp

#writeDictionaryDestroy(type)
{
if (type instanceof FuStringStorageType || type instanceof FuArrayStorageType)
this.write("free");
else if (type instanceof FuStorageType) {
const storage = type;
switch (storage.class.id) {
case FuId.LIST_CLASS:
case FuId.STACK_CLASS:
this.write("(GDestroyNotify) g_array_unref");
break;
case FuId.HASH_SET_CLASS:
case FuId.DICTIONARY_CLASS:
this.write("(GDestroyNotify) g_hash_table_unref");
break;
case FuId.SORTED_SET_CLASS:
case FuId.SORTED_DICTIONARY_CLASS:
this.write("(GDestroyNotify) g_tree_unref");
break;
default:
if (GenC.#needsDestructor(storage.class)) {
this.write("(GDestroyNotify) ");
this.writeName(storage.class);
this.write("_Delete");
fuswitch0: {
if (type instanceof FuStringStorageType || type instanceof FuArrayStorageType)
this.write("free");
else if (type instanceof FuOwningType) {
const owning = type;
if (owning.class.id == FuId.NONE) {
if (type instanceof FuStorageType) {
if (GenC.#needsDestructor(owning.class)) {
this.write("(GDestroyNotify) ");
this.writeName(owning.class);
this.write("_Delete");
}
else
this.write("free");
break fuswitch0;
}
}
else
this.write("free");
break;
this.write("(GDestroyNotify) ");
this.#writeDestructMethodName(owning);
}
else
this.write("NULL");
}
else if (type instanceof FuDynamicPtrType) {
this.#sharedRelease = true;
this.write("FuShared_Release");
}
else
this.write("NULL");
}

#writeHashEqual(keyType)

0 comments on commit 64b90e2

Please sign in to comment.