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

Function AddBinaryCommandNode

NULLC/Callbacks.cpp:900–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

898}
899
900void AddBinaryCommandNode(const char* pos, CmdID id)
901{
902 CodeInfo::lastKnownStartPos = pos;
903
904 const char *opNames[] = { "+", "-", "*", "/", "**", "%", "<", ">", "<=", ">=", "==", "!=", "<<", ">>", "&", "|", "^", "&&", "||", "^^", "in" };
905
906 if(id == cmdNop)
907 {
908 AddFunctionCallNode(CodeInfo::lastKnownStartPos, "in", 2);
909 return;
910 }
911 if(id == cmdEqual || id == cmdNEqual)
912 {
913 NodeZeroOP *left = CodeInfo::nodeList[CodeInfo::nodeList.size()-2];
914 NodeZeroOP *right = CodeInfo::nodeList[CodeInfo::nodeList.size()-1];
915
916 if(right->typeInfo == typeObject && right->typeInfo == left->typeInfo)
917 {
918 AddFunctionCallNode(pos, id == cmdEqual ? "__rcomp" : "__rncomp", 2);
919 return;
920 }
921 bool swapped = false;
922 if(left->typeInfo == typeVoid->refType)
923 {
924 CodeInfo::nodeList[CodeInfo::nodeList.size()-2] = right;
925 CodeInfo::nodeList[CodeInfo::nodeList.size()-1] = left;
926 NodeZeroOP *tmp = left; left = right; right = tmp;
927 swapped = true;
928 }
929 if(right->typeInfo == typeVoid->refType)
930 {
931 HandlePointerToObject(pos, left->typeInfo);
932 left = CodeInfo::nodeList[CodeInfo::nodeList.size()-2];
933 right = CodeInfo::nodeList[CodeInfo::nodeList.size()-1];
934 if(right->typeInfo == typeVoid->refType && swapped)
935 {
936 CodeInfo::nodeList[CodeInfo::nodeList.size()-2] = left;
937 CodeInfo::nodeList[CodeInfo::nodeList.size()-1] = right;
938 NodeZeroOP *tmp = left; left = right; right = tmp;
939 }
940 }
941 if(right->typeInfo->funcType && right->typeInfo->funcType == left->typeInfo->funcType)
942 {
943 CodeInfo::nodeList[CodeInfo::nodeList.size()-2]->typeInfo = CodeInfo::funcInfo[0]->funcType;
944 CodeInfo::nodeList[CodeInfo::nodeList.size()-1]->typeInfo = CodeInfo::funcInfo[0]->funcType;
945 AddFunctionCallNode(pos, id == cmdEqual ? "__pcomp" : "__pncomp", 2);
946 return;
947 }
948 if(right->typeInfo->arrLevel && right->typeInfo->arrSize == TypeInfo::UNSIZED_ARRAY && right->typeInfo == left->typeInfo)
949 {
950 if(!AddFunctionCallNode(CodeInfo::lastKnownStartPos, opNames[id - cmdAdd], 2, true))
951 AddFunctionCallNode(pos, id == cmdEqual ? "__acomp" : "__ancomp", 2);
952 return;
953 }
954 if(left->nodeType == typeNodeConvertPtr && left->typeInfo == typeTypeid && left->typeInfo == right->typeInfo && left->nodeType == right->nodeType)
955 {
956 CodeInfo::nodeList.pop_back();
957 CodeInfo::nodeList.pop_back();

Callers 3

ParseClassBodyFunction · 0.85
ParseEnumFunction · 0.85
ParseArithmeticFunction · 0.85

Calls 15

AddFunctionCallNodeFunction · 0.85
HandlePointerToObjectFunction · 0.85
ChooseBinaryOpResultTypeFunction · 0.85
assertFunction · 0.85
SwapFunction · 0.85
RemoveLastNodeFunction · 0.85
AddNegateNodeFunction · 0.85
WrapNodeToFunctionFunction · 0.85
ConvertToMethod · 0.80
GetDoubleMethod · 0.80
GetLongMethod · 0.80
GetIntegerMethod · 0.80

Tested by

no test coverage detected