Function that creates unary operation node that changes sign of value
| 783 | |
| 784 | // Function that creates unary operation node that changes sign of value |
| 785 | void AddNegateNode(const char* pos) |
| 786 | { |
| 787 | CodeInfo::lastKnownStartPos = pos; |
| 788 | if(AddFunctionCallNode(pos, "-", 1, true)) |
| 789 | return; |
| 790 | |
| 791 | // If the last node is a number, we can just change sign of constant |
| 792 | if(CodeInfo::nodeList.back()->nodeType == typeNodeNumber && CodeInfo::nodeList.back()->typeInfo != typeBool) |
| 793 | { |
| 794 | TypeInfo *aType = CodeInfo::nodeList.back()->typeInfo; |
| 795 | NodeZeroOP* Rd = NULL; |
| 796 | if(aType == typeDouble || aType == typeFloat) |
| 797 | Rd = new NodeNumber(-static_cast<NodeNumber*>(CodeInfo::nodeList.back())->GetDouble(), aType); |
| 798 | else if(aType == typeLong) |
| 799 | Rd = new NodeNumber(-static_cast<NodeNumber*>(CodeInfo::nodeList.back())->GetLong(), aType); |
| 800 | else if(aType == typeInt || aType == typeShort || aType == typeChar) |
| 801 | Rd = new NodeNumber(-static_cast<NodeNumber*>(CodeInfo::nodeList.back())->GetInteger(), aType); |
| 802 | else |
| 803 | ThrowError(pos, "addNegNode() ERROR: unknown type %s", aType->name); |
| 804 | |
| 805 | CodeInfo::nodeList.pop_back(); |
| 806 | CodeInfo::nodeList.push_back(Rd); |
| 807 | }else{ |
| 808 | // Otherwise, just create node |
| 809 | CodeInfo::nodeList.push_back(new NodeUnaryOp(cmdNeg)); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | // Function that creates unary operation node for logical NOT |
| 814 | void AddLogNotNode(const char* pos) |
no test coverage detected