| 6712 | } |
| 6713 | |
| 6714 | int asCCompiler::PerformAssignment(asCExprValue *lvalue, asCExprValue *rvalue, asCByteCode *bc, asCScriptNode *node) |
| 6715 | { |
| 6716 | if( lvalue->dataType.IsReadOnly() ) |
| 6717 | { |
| 6718 | Error(TXT_REF_IS_READ_ONLY, node); |
| 6719 | return -1; |
| 6720 | } |
| 6721 | |
| 6722 | if( lvalue->dataType.IsPrimitive() ) |
| 6723 | { |
| 6724 | if( lvalue->isVariable ) |
| 6725 | { |
| 6726 | // Copy the value between the variables directly |
| 6727 | if( lvalue->dataType.GetSizeInMemoryDWords() == 1 ) |
| 6728 | bc->InstrW_W(asBC_CpyVtoV4, lvalue->stackOffset, rvalue->stackOffset); |
| 6729 | else |
| 6730 | bc->InstrW_W(asBC_CpyVtoV8, lvalue->stackOffset, rvalue->stackOffset); |
| 6731 | |
| 6732 | // Mark variable as initialized |
| 6733 | sVariable *v = variables->GetVariableByOffset(lvalue->stackOffset); |
| 6734 | if( v ) v->isInitialized = true; |
| 6735 | } |
| 6736 | else if( lvalue->dataType.IsReference() ) |
| 6737 | { |
| 6738 | // Copy the value of the variable to the reference in the register |
| 6739 | int s = lvalue->dataType.GetSizeInMemoryBytes(); |
| 6740 | if( s == 1 ) |
| 6741 | bc->InstrSHORT(asBC_WRTV1, (short)rvalue->stackOffset); |
| 6742 | else if( s == 2 ) |
| 6743 | bc->InstrSHORT(asBC_WRTV2, (short)rvalue->stackOffset); |
| 6744 | else if( s == 4 ) |
| 6745 | bc->InstrSHORT(asBC_WRTV4, (short)rvalue->stackOffset); |
| 6746 | else if( s == 8 ) |
| 6747 | bc->InstrSHORT(asBC_WRTV8, (short)rvalue->stackOffset); |
| 6748 | } |
| 6749 | else |
| 6750 | { |
| 6751 | Error(TXT_NOT_VALID_LVALUE, node); |
| 6752 | return -1; |
| 6753 | } |
| 6754 | } |
| 6755 | else if( !lvalue->isExplicitHandle ) |
| 6756 | { |
| 6757 | asCExprContext ctx(engine); |
| 6758 | ctx.type = *lvalue; |
| 6759 | Dereference(&ctx, true); |
| 6760 | *lvalue = ctx.type; |
| 6761 | bc->AddCode(&ctx.bc); |
| 6762 | |
| 6763 | asSTypeBehaviour *beh = lvalue->dataType.GetBehaviour(); |
| 6764 | if( beh && beh->copy && beh->copy != engine->scriptTypeBehaviours.beh.copy ) |
| 6765 | { |
| 6766 | asCExprContext res(engine); |
| 6767 | PerformFunctionCall(beh->copy, &res, false, 0, CastToObjectType(lvalue->dataType.GetTypeInfo())); |
| 6768 | |
| 6769 | bc->AddCode(&res.bc); |
| 6770 | *lvalue = res.type; |
| 6771 | } |
nothing calls this directly
no test coverage detected