| 8634 | } |
| 8635 | |
| 8636 | BfObjectCreateExpression* BfReducer::CreateObjectCreateExpression(BfAstNode* allocNode, BfAstNode* targetNode) |
| 8637 | { |
| 8638 | auto objectCreateExpr = mAlloc->Alloc<BfObjectCreateExpression>(); |
| 8639 | BfDeferredAstSizedArray<BfExpression*> arguments(objectCreateExpr->mArguments, mAlloc); |
| 8640 | BfDeferredAstSizedArray<BfTokenNode*> commas(objectCreateExpr->mCommas, mAlloc); |
| 8641 | |
| 8642 | BfTypeReference* typeRef = NULL; |
| 8643 | |
| 8644 | if (allocNode != NULL) |
| 8645 | { |
| 8646 | ReplaceNode(allocNode, objectCreateExpr); |
| 8647 | MEMBER_SET(objectCreateExpr, mNewNode, allocNode); |
| 8648 | } |
| 8649 | else |
| 8650 | { |
| 8651 | ReplaceNode(targetNode, objectCreateExpr); |
| 8652 | typeRef = CreateTypeRef(targetNode); |
| 8653 | if (typeRef == NULL) |
| 8654 | return NULL; |
| 8655 | } |
| 8656 | |
| 8657 | auto nextNode = mVisitorPos.GetNext(); |
| 8658 | |
| 8659 | BfTokenNode* tokenNode; |
| 8660 | |
| 8661 | if (typeRef == NULL) |
| 8662 | typeRef = CreateTypeRefAfter(objectCreateExpr); |
| 8663 | if (typeRef == NULL) |
| 8664 | return objectCreateExpr; |
| 8665 | |
| 8666 | bool isArray = false; |
| 8667 | |
| 8668 | if (auto ptrType = BfNodeDynCast<BfPointerTypeRef>(typeRef)) |
| 8669 | { |
| 8670 | if (auto arrayType = BfNodeDynCast<BfArrayTypeRef>(ptrType->mElementType)) |
| 8671 | { |
| 8672 | MEMBER_SET(objectCreateExpr, mStarToken, ptrType->mStarNode); |
| 8673 | typeRef = ptrType->mElementType; |
| 8674 | isArray = true; |
| 8675 | } |
| 8676 | } |
| 8677 | else if (auto arrayType = BfNodeDynCast<BfArrayTypeRef>(typeRef)) |
| 8678 | { |
| 8679 | isArray = true; |
| 8680 | } |
| 8681 | |
| 8682 | MEMBER_SET(objectCreateExpr, mTypeRef, typeRef); |
| 8683 | |
| 8684 | if (auto block = BfNodeDynCast<BfBlock>(mVisitorPos.GetNext())) |
| 8685 | { |
| 8686 | mPassInstance->Warn(0, "Expected '('", block->mOpenBrace); |
| 8687 | |
| 8688 | mVisitorPos.MoveNext(); |
| 8689 | MEMBER_SET(objectCreateExpr, mOpenToken, block->mOpenBrace); |
| 8690 | // |
| 8691 | { |
| 8692 | SetAndRestoreValue<BfVisitorPos> prevVisitorPos(mVisitorPos, BfVisitorPos(block)); |
| 8693 | ReadArguments(objectCreateExpr, objectCreateExpr, &arguments, &commas, BfToken_None, true); |