| 701 | // Node that sets value to the variable |
| 702 | |
| 703 | NodeVariableSet::NodeVariableSet(TypeInfo* targetType, bool firstDefinition, bool swapNodes) |
| 704 | { |
| 705 | assert(targetType); |
| 706 | typeInfo = targetType->subType; |
| 707 | |
| 708 | if(swapNodes) |
| 709 | second = TakeLastNode(); |
| 710 | |
| 711 | // Address of the target variable |
| 712 | first = TakeLastNode(); |
| 713 | assert(first->typeInfo->refLevel != 0); |
| 714 | |
| 715 | if(!swapNodes) |
| 716 | second = TakeLastNode(); |
| 717 | |
| 718 | if(typeInfo->arrLevel < 2 && typeInfo->refLevel == 0 && second->nodeType == typeNodeNumber && !second->typeInfo->firstVariable) |
| 719 | static_cast<NodeNumber*>(second)->ConvertTo(typeInfo); |
| 720 | |
| 721 | // If this is the first array definition and value is array sub-type, we set it to all array elements |
| 722 | arrSetAll = (firstDefinition && typeInfo->arrLevel == 1 && typeInfo->arrSize != TypeInfo::UNSIZED_ARRAY && second->typeInfo->arrLevel == 0 && second->typeInfo->refLevel == 0 && typeInfo->subType->type != TypeInfo::TYPE_COMPLEX && second->typeInfo->type != TypeInfo::TYPE_COMPLEX); |
| 723 | |
| 724 | if(second->typeInfo == typeVoid) |
| 725 | ThrowError(CodeInfo::lastKnownStartPos, "ERROR: cannot convert from void to %s", typeInfo->GetFullTypeName()); |
| 726 | if(typeInfo == typeVoid) |
| 727 | ThrowError(CodeInfo::lastKnownStartPos, "ERROR: cannot convert from %s to void", second->typeInfo->GetFullTypeName()); |
| 728 | |
| 729 | // If types don't match |
| 730 | if(second->typeInfo != typeInfo) |
| 731 | { |
| 732 | // If it is not built-in basic types or if pointers point to different types |
| 733 | if(typeInfo->type == TypeInfo::TYPE_COMPLEX || second->typeInfo->type == TypeInfo::TYPE_COMPLEX || typeInfo->subType != second->typeInfo->subType |
| 734 | || typeInfo->firstVariable || second->typeInfo->firstVariable) |
| 735 | { |
| 736 | if(!(typeInfo->arrLevel != 0 && second->typeInfo->arrLevel == 0 && arrSetAll)) |
| 737 | ThrowError(CodeInfo::lastKnownStartPos, "ERROR: cannot convert '%s' to '%s'", second->typeInfo->GetFullTypeName(), typeInfo->GetFullTypeName()); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | absAddress = true; |
| 742 | knownAddress = false; |
| 743 | addrShift = 0; |
| 744 | |
| 745 | if(first->nodeType == typeNodeGetAddress) |
| 746 | { |
| 747 | absAddress = static_cast<NodeGetAddress*>(first)->IsAbsoluteAddress(); |
| 748 | addrShift = static_cast<NodeGetAddress*>(first)->varAddress; |
| 749 | knownAddress = true; |
| 750 | } |
| 751 | #ifndef NULLC_ENABLE_C_TRANSLATION |
| 752 | if(first->nodeType == typeNodeShiftAddress) |
| 753 | { |
| 754 | addrShift = static_cast<NodeShiftAddress*>(first)->memberShift; |
| 755 | first = static_cast<NodeShiftAddress*>(first)->first; |
| 756 | } |
| 757 | if(first->nodeType == typeNodeArrayIndex && static_cast<NodeArrayIndex*>(first)->knownShift) |
| 758 | { |
| 759 | addrShift = static_cast<NodeArrayIndex*>(first)->shiftValue; |
| 760 | first = static_cast<NodeArrayIndex*>(first)->first; |
nothing calls this directly
no test coverage detected