| 1723 | } |
| 1724 | |
| 1725 | FunctionPtr makeCloneTuple ( const LineInfo & at, const TypeDeclPtr & tupleType, bool fromConst ) { |
| 1726 | DAS_ASSERT(tupleType->isTuple() && "can only clone tuple"); |
| 1727 | auto fn = new Function(); |
| 1728 | fn->generated = true; |
| 1729 | fn->safeImplicit = true; |
| 1730 | fn->privateFunction = true; |
| 1731 | fn->name = "clone"; |
| 1732 | fn->at = fn->atDecl = at; |
| 1733 | fn->result = new TypeDecl(Type::tVoid); |
| 1734 | auto arg0 = new Variable(); |
| 1735 | arg0->at = at; |
| 1736 | arg0->name = "dest"; |
| 1737 | arg0->type = new TypeDecl(*tupleType); |
| 1738 | arg0->type->constant = false; |
| 1739 | arg0->type->explicitConst = false; |
| 1740 | arg0->type->ref = false; |
| 1741 | fn->arguments.push_back(arg0); |
| 1742 | auto arg1 = new Variable(); |
| 1743 | arg1->at = at; |
| 1744 | arg1->name = "src"; |
| 1745 | arg1->type = new TypeDecl(*tupleType); |
| 1746 | arg1->type->constant = fromConst; |
| 1747 | arg1->type->explicitConst = true; |
| 1748 | arg1->type->ref = false; |
| 1749 | arg1->type->implicit = true; |
| 1750 | fn->arguments.push_back(arg1); |
| 1751 | auto block = new ExprBlock(); |
| 1752 | block->at = at; |
| 1753 | for ( size_t argi=0, argis=tupleType->argTypes.size(); argi!=argis; ++argi ) { |
| 1754 | string argn = "_" + to_string(argi); |
| 1755 | auto lv = new ExprVar(at, "dest"); |
| 1756 | auto lf = new ExprField(at, lv, argn); |
| 1757 | auto rv = new ExprVar(at, "src"); |
| 1758 | auto rf = new ExprField(at, rv, argn); |
| 1759 | auto cl = new ExprClone(at, lf, rf); |
| 1760 | block->list.push_back(cl); |
| 1761 | } |
| 1762 | fn->body = block; |
| 1763 | verifyGenerated(fn->body); |
| 1764 | return fn; |
| 1765 | } |
| 1766 | |
| 1767 | FunctionPtr generateTupleFinalizer ( const LineInfo & at, const TypeDeclPtr & tupleType ) { |
| 1768 | DAS_ASSERT(tupleType->isTuple() && "can only finalize tuple"); |