MCPcopy Create free account
hub / github.com/WheretIB/nullc / AddNegateNode

Function AddNegateNode

NULLC/Callbacks.cpp:785–811  ·  view source on GitHub ↗

Function that creates unary operation node that changes sign of value

Source from the content-addressed store, hash-verified

783
784// Function that creates unary operation node that changes sign of value
785void 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
814void AddLogNotNode(const char* pos)

Callers 2

AddBinaryCommandNodeFunction · 0.85
ParseTerminalFunction · 0.85

Calls 7

AddFunctionCallNodeFunction · 0.85
ThrowErrorFunction · 0.85
GetDoubleMethod · 0.80
GetLongMethod · 0.80
GetIntegerMethod · 0.80
pop_backMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected