| 1765 | } |
| 1766 | |
| 1767 | FunctionPtr generateTupleFinalizer ( const LineInfo & at, const TypeDeclPtr & tupleType ) { |
| 1768 | DAS_ASSERT(tupleType->isTuple() && "can only finalize tuple"); |
| 1769 | auto fn = new Function(); |
| 1770 | fn->privateFunction = true; |
| 1771 | fn->generated = true; |
| 1772 | fn->name = "finalize"; |
| 1773 | fn->at = fn->atDecl = at; |
| 1774 | fn->result = new TypeDecl(Type::tVoid); |
| 1775 | auto arg0 = new Variable(); |
| 1776 | arg0->at = at; |
| 1777 | arg0->name = "__this"; |
| 1778 | arg0->type = new TypeDecl(*tupleType); |
| 1779 | arg0->type->constant = false; |
| 1780 | arg0->type->ref = false; |
| 1781 | arg0->type->isExplicit = true; |
| 1782 | fn->arguments.push_back(arg0); |
| 1783 | auto block = new ExprBlock(); |
| 1784 | block->at = at; |
| 1785 | bool needUnsafe = false; |
| 1786 | for ( size_t argi=0, argis=tupleType->argTypes.size(); argi!=argis; ++argi ) { |
| 1787 | if ( !tupleType->argTypes[argi]->constant && tupleType->argTypes[argi]->needDelete() ) { |
| 1788 | if ( tupleType->isPointer() && tupleType->firstType && tupleType->firstType->constant ) continue; |
| 1789 | string argn = "_" + to_string(argi); |
| 1790 | auto lv = new ExprVar(at, "__this"); |
| 1791 | auto lf = new ExprField(at, lv, argn); |
| 1792 | auto cl = new ExprDelete(at, lf); |
| 1793 | cl->alwaysSafe = true; |
| 1794 | block->list.push_back(cl); |
| 1795 | if ( tupleType->argTypes[argi]->isPointer() ) { |
| 1796 | needUnsafe = true; |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | auto mz = new ExprMemZero(at, "memzero"); |
| 1801 | auto lvar = new ExprVar(at, "__this"); |
| 1802 | mz->arguments.push_back(lvar); |
| 1803 | block->list.push_back(mz); |
| 1804 | fn->body = block; |
| 1805 | if ( needUnsafe ) { |
| 1806 | wrapInUnsafe(fn); |
| 1807 | } |
| 1808 | verifyGenerated(fn->body); |
| 1809 | return fn; |
| 1810 | } |
| 1811 | |
| 1812 | FunctionPtr makeCloneVariant ( const LineInfo & at, const TypeDeclPtr & variantType, bool fromConst ) { |
| 1813 | DAS_ASSERT(variantType->isVariant() && "can only clone variant"); |
no test coverage detected